@openchamber/web 1.11.1 → 1.11.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/{JsonTreeView-bLRkNPS9.js → JsonTreeView-9F0tH9yA.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-FSTq-eVA.js → MarkdownRendererImpl-C3QofAGm.js} +1 -1
- package/dist/assets/{MultiRunWindow-DezP_Pyy.js → MultiRunWindow-wnUGv0Dl.js} +1 -1
- package/dist/assets/{OnboardingScreen-CeZMVgH8.js → OnboardingScreen-17dAs0NH.js} +2 -2
- package/dist/assets/{SettingsWindow-Dlfk0yzA.js → SettingsWindow-BgyVY5gz.js} +1 -1
- package/dist/assets/TerminalView-D11XIZuz.js +1 -0
- package/dist/assets/{ToolOutputDialog-CePopKV7.js → ToolOutputDialog-DFG7ANVw.js} +6 -6
- package/dist/assets/es-Chl2Hu6K.js +15 -0
- package/dist/assets/index-0bVkxg-Z.css +1 -0
- package/dist/assets/{index-CKlDk4Io.js → index-BV2XTsJJ.js} +1 -1
- package/dist/assets/ko-BSrH3F9n.js +15 -0
- package/dist/assets/{main-BvaFBcXN.js → main-BHkNwOz1.js} +2 -2
- package/dist/assets/main-Bqf4fXgq.js +225 -0
- package/dist/assets/miniChat-BmB-E5xo.js +2 -0
- package/dist/assets/{modelPrefsAutoSave-HUPrH1r2.js → modelPrefsAutoSave-2uwW8uD9.js} +98 -96
- package/dist/assets/pl-YlGvPmFg.js +15 -0
- package/dist/assets/pt-BR-BonIMDN_.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-EXGwfTjq.js → renderElectronMiniChatApp-B_qrXCU2.js} +2 -2
- package/dist/assets/uk-lPqA3MHn.js +15 -0
- package/dist/assets/{vendor-.bun-BFTPeDgG.js → vendor-.bun-Boz6Tqcq.js} +20 -20
- package/dist/assets/zh-CN-C5nQQsUL.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/package.json +1 -1
- package/server/lib/git/DOCUMENTATION.md +1 -0
- package/server/lib/git/routes.js +26 -0
- package/server/lib/git/service.js +96 -10
- package/server/lib/git/service.test.js +39 -0
- package/server/lib/opencode/settings-helpers.js +10 -1
- package/server/lib/opencode/settings-helpers.test.js +35 -0
- package/server/lib/opencode/skill-routes.js +43 -49
- package/server/lib/opencode/skills.js +78 -10
- package/dist/assets/TerminalView-CdCfCaFq.js +0 -1
- package/dist/assets/es-CyjenLd8.js +0 -15
- package/dist/assets/index-NnYXwoao.css +0 -1
- package/dist/assets/ko-Cs7yF9Jn.js +0 -15
- package/dist/assets/main-DcpUnRRo.js +0 -225
- package/dist/assets/miniChat-Dmzb8Mwv.js +0 -2
- package/dist/assets/pl-XjTt7Hsk.js +0 -15
- package/dist/assets/pt-BR-knvpJ94d.js +0 -15
- package/dist/assets/uk-DUPvcQAj.js +0 -15
- package/dist/assets/zh-CN-DWiTG93s.js +0 -15
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-Boz6Tqcq.js","assets/vendor--V65Sl9C2.css","assets/modelPrefsAutoSave-2uwW8uD9.js","assets/index-BV2XTsJJ.js","assets/index-0bVkxg-Z.css","assets/TerminalView-D11XIZuz.js","assets/JsonTreeView-9F0tH9yA.js","assets/SettingsWindow-BgyVY5gz.js","assets/MultiRunWindow-wnUGv0Dl.js","assets/OnboardingScreen-17dAs0NH.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as at,R as l,u as Hi,a as ni,j as s,b as Nl,C as Sl,P as Gi,S as sl,d as Yg,D as nl,e as qi,f as Yi,g as ar,i as vi,r as ze,k as Jg,l as Qg,p as ro,m as kl,n as Xg,o as Zg,q as ex,_ as Sr,s as Bi,t as Ff,v as Hc,w as za,x as tx,W as sx,y as nx,V as rx,F as ax,z as ix,A as br,E as ox,B as tr,G as lx,H as wi,I as du,J as cx,K as dx,L as Hl,M as ux,N as mx,O as px,Q as uu,T as mu,U as fx,X as Lf,Y as Of,Z as hx,$ as pu,a0 as gx,a1 as xx,a2 as bx,a3 as yx,a4 as vx,a5 as wx,a6 as jx,a7 as $f,a8 as Nx,a9 as Gc,aa as Bf,ab as zf,ac as ei,ad as Ri,ae as qc,af as ot,ag as _f,ah as Vf,ai as Sx,aj as kx,ak as Cx,al as Ix,am as Px,an as Ax,ao as Dx,ap as Tx,aq as Mx,ar as Ex,as as fu,at as hu,au as Gl,av as Rx}from"./vendor-.bun-Boz6Tqcq.js";import{a as Fx,b as Lx,f as Ox}from"./index-BV2XTsJJ.js";import{u as mt,a as Te,b as an,c as me,I,d as Ms,i as un,g as hr,e as sa,s as ql,r as Yl,f as Jl,h as Ls,o as rn,j as Ws,T as It,k as Pt,l as At,m as Ma,n as Kr,p as gu,D as Vt,q as $x,t as rl,v as Rn,w as G,x as Bs,y as Tn,z as zs,A as _s,B as Uf,C as xu,E as Bx,F as zx,G as bu,H as _x,J as Vx,K as Ux,L as Wx,M as _n,N as yn,O as sr,P as Yc,Q as jn,R as zi,S as Kx,U as gt,V as _t,W as Hx,X as Wf,Y as Ia,Z as Dd,_ as Hn,$ as Td,a0 as Cl,a1 as Gx,a2 as yu,a3 as qx,a4 as Yx,a5 as Kf,a6 as Jx,a7 as Qx,a8 as Hf,a9 as Md,aa as al,ab as Gf,ac as Il,ad as Ur,ae as Ed,af as Vo,ag as Xx,ah as Zx,ai as Xs,aj as qf,ak as Yf,al as Wt,am as Es,an as Mr,ao as di,ap as eb,aq as Jf,ar as As,as as Ss,at as be,au as ys,av as vs,aw as Ea,ax as tb,ay as sb,az as yo,aA as Nn,aB as Qf,aC as Xf,aD as Pl,aE as nb,aF as Zf,aG as vu,aH as wu,aI as bn,aJ as fs,aK as rb,aL as ab,aM as ib,aN as ob,aO as lb,aP as cb,aQ as db,aR as Ks,aS as ub,aT as mb,aU as Fs,aV as pb,aW as fb,aX as hb,aY as gb,aZ as jr,a_ as ao,a$ as xb,b0 as Hs,b1 as Al,b2 as ti,b3 as ui,b4 as mi,b5 as ju,b6 as pi,b7 as bb,b8 as ds,b9 as us,ba as bs,bb as ms,bc as Lt,bd as yb,be as Ra,bf as vb,bg as Lr,bh as Rd,bi as Dl,bj as wb,bk as Fd,bl as jb,bm as Nb,bn as Ld,bo as Sb,bp as nn,bq as io,br as Nr,bs as kb,bt as Cb,bu as Ql,bv as Tl,bw as Od,bx as $d,by as Ml,bz as Bn,bA as Bd,bB as Fa,bC as il,bD as ol,bE as fi,bF as eh,bG as Ib,bH as Cr,bI as Pb,bJ as Nu,bK as ll,bL as El,bM as th,bN as Ab,bO as Db,bP as oo,bQ as Tb,bR as zd,bS as Mb,bT as si,bU as Ji,bV as sh,bW as hi,bX as nh,bY as Eb,bZ as Rb,b_ as _d,b$ as na,c0 as ri,c1 as Pa,c2 as Rl,c3 as lo,c4 as co,c5 as Jc,c6 as rh,c7 as Vd,c8 as ah,c9 as Qi,ca as Fb,cb as Lb,cc as Ob,cd as $b,ce as Bb,cf as ai,cg as Xl,ch as Su,ci as zb,cj as _b,ck as Vb,cl as Ub,cm as Qa,cn as Zl,co as Wb,cp as ku,cq as aa,cr as Kb,cs as Cu,ct as Iu,cu as Pu,cv as Au,cw as Uo,cx as Du,cy as Hb,cz as ec,cA as Gb,cB as qb,cC as Yb,cD as Jb,cE as Qb,cF as Xb,cG as Zb,cH as tc,cI as Tu,cJ as ey,cK as ty,cL as sy,cM as ny,cN as ry,cO as sc,cP as ay,cQ as Mu,cR as Fi,cS as iy,cT as ih,cU as oy,cV as Xa,cW as ly,cX as Eu,cY as cy,cZ as oh,c_ as vo,c$ as _i,d0 as dy,d1 as lh,d2 as uy,d3 as my,d4 as Ru,d5 as Fu,d6 as ch,d7 as dh,d8 as nc,d9 as wo,da as py,db as fy,dc as hy,dd as gy,de as uh,df as mh,dg as Qc,dh as Ud,di as xy,dj as Ps,dk as Xi,dl as gi,dm as ii,dn as Lu,dp as Xn,dq as by,dr as Vi,ds as yy,dt as ph,du as vy,dv as wy,dw as Xc,dx as jy,dy as Ny,dz as Ou,dA as Sy,dB as ky,dC as Wd,dD as fh,dE as Cy,dF as Iy,dG as Py,dH as Ay,dI as $u,dJ as Dy,dK as Ty,dL as My,dM as Ey,dN as rc,dO as Ry,dP as hh,dQ as Fy,dR as Ly,dS as Oy,dT as $y,dU as By,dV as zy,dW as _y,dX as Vy,dY as Uy,dZ as Wy,d_ as Ky,d$ as Hy,e0 as Gy,e1 as Bu,e2 as qy,e3 as gh,e4 as Yy,e5 as Jy,e6 as Qy,e7 as Xy,e8 as Gr,e9 as Zy,ea as zu,eb as ev,ec as Wo,ed as Ko,ee as tv,ef as sv,eg as nv,eh as rv,ei as _u,ej as av,ek as Vu,el as iv,em as Uu,en as ov,eo as lv,ep as cv,eq as Wu,er as Ku,es as Hu,et as dv,eu as xh,ev as bh,ew as uv,ex as mv,ey as pv,ez as fv,eA as hv,eB as gv,eC as xv,eD as bv,eE as yv,eF as vv,eG as wv}from"./modelPrefsAutoSave-2uwW8uD9.js";import{J as jv}from"./JsonTreeView-9F0tH9yA.js";const Nv=({transform:t})=>({...t,y:0}),Sv=t=>{const e=at.c(18),{id:n,children:r,className:a}=t;let i;e[0]!==n?(i={id:n},e[0]=n,e[1]=i):i=e[1];const{attributes:o,listeners:c,setNodeRef:d,transform:p,transition:m,isDragging:u}=Nl(i);let f;e[2]!==p?(f=Sl.Transform.toString(p),e[2]=p,e[3]=f):f=e[3];let b;e[4]!==f||e[5]!==m?(b={transform:f,transition:m},e[4]=f,e[5]=m,e[6]=b):b=e[6];const h=u&&"opacity-50";let v;e[7]!==a||e[8]!==h?(v=me("h-full rounded-md",a,h),e[7]=a,e[8]=h,e[9]=v):v=e[9];let x;return e[10]!==o||e[11]!==r||e[12]!==n||e[13]!==c||e[14]!==d||e[15]!==b||e[16]!==v?(x=s.jsx("div",{ref:d,"data-sortable-tab-id":n,style:b,className:v,...o,...c,children:r}),e[10]=o,e[11]=r,e[12]=n,e[13]=c,e[14]=d,e[15]=b,e[16]=v,e[17]=x):x=e[17],x},kv=t=>{const e=at.c(6),{id:n,children:r,className:a}=t;let i;e[0]!==a?(i=me("h-full",a),e[0]=a,e[1]=i):i=e[1];let o;return e[2]!==r||e[3]!==n||e[4]!==i?(o=s.jsx("div",{className:i,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=i,e[5]=o):o=e[5],o},Er=t=>{const e=at.c(121),{items:n,activeId:r,onSelect:a,onClose:i,onReorder:o,layoutMode:c,variant:d,activePillInsetClassName:p,activePillButtonClassName:m,inactiveTabsIconOnly:u,iconOnlyActiveTab:f,animateActivePill:b,activePillLowercase:h,className:v}=t,x=c===void 0?"scrollable":c,g=d===void 0?"default":d,w=u===void 0?!1:u,y=f===void 0?!1:f,k=h===void 0?!0:h,{t:D}=mt(),j=Te(Cv),{isTablet:S}=an(),A=j||S,E=l.useRef(null);let P;e[0]===Symbol.for("react.memo_cache_sentinel")?(P={left:!1,right:!1},e[0]=P):P=e[0];const[C,N]=l.useState(P);let T;e[1]!==n?(T=n.map(Iv),e[1]=n,e[2]=T):T=e[2];const M=T,R=x==="scrollable",O=g==="default",z=g==="active-pill",B=g==="animated",$=z||B,_=O,Q=$||_,W=z&&R,ne=$,re=b??B,ue=typeof o=="function",Y=ue?Sv:kv;let le;e[3]===Symbol.for("react.memo_cache_sentinel")?(le=new Map,e[3]=le):le=e[3];const J=l.useRef(le),[L,V]=l.useState(null);let K;e[4]===Symbol.for("react.memo_cache_sentinel")?(K={activationConstraint:{distance:8}},e[4]=K):K=e[4];const X=Hi(ni(Gi,K)),U=Pv;let ae;e[5]===Symbol.for("react.memo_cache_sentinel")?(ae=(rt,xe)=>{if(xe){J.current.set(rt,xe);return}J.current.delete(rt)},e[5]=ae):ae=e[5];const ve=ae;let ie;e[6]!==r||e[7]!==Q?(ie=()=>{if(!Q||!r){V(Av);return}const rt=E.current,xe=J.current.get(r);if(!rt||!xe){V(Dv);return}let Ye=0,_e=0,We=xe;for(;We&&We!==rt;)Ye=Ye+We.offsetLeft,_e=_e+We.offsetTop,We=We.offsetParent;const lt={left:Ye,top:_e,width:xe.offsetWidth,height:xe.offsetHeight};V(Je=>U(Je,lt)?Je:lt)},e[6]=r,e[7]=Q,e[8]=ie):ie=e[8];const fe=ie;let H;e[9]!==R?(H=()=>{if(!R){N({left:!1,right:!1});return}const rt=E.current;if(!rt){N({left:!1,right:!1});return}N({left:rt.scrollLeft>2,right:rt.scrollLeft+rt.clientWidth<rt.scrollWidth-2})},e[9]=R,e[10]=H):H=e[10];const ce=H;let se;e[11]!==R||e[12]!==ce?(se=()=>{if(!R){N({left:!1,right:!1});return}const rt=E.current;if(!rt)return;ce(),rt.addEventListener("scroll",ce,{passive:!0});const xe=new ResizeObserver(ce);return xe.observe(rt),()=>{rt.removeEventListener("scroll",ce),xe.disconnect()}},e[11]=R,e[12]=ce,e[13]=se):se=e[13];let oe;e[14]!==R||e[15]!==n.length||e[16]!==ce?(oe=[R,n.length,ce],e[14]=R,e[15]=n.length,e[16]=ce,e[17]=oe):oe=e[17],l.useEffect(se,oe);let te;e[18]!==r||e[19]!==fe||e[20]!==Q?(te=()=>{if(!Q){V(null);return}fe();const rt=E.current;if(!rt)return;const xe=new ResizeObserver(fe);if(xe.observe(rt),r){const Ye=J.current.get(r);Ye&&xe.observe(Ye)}return()=>{xe.disconnect()}},e[18]=r,e[19]=fe,e[20]=Q,e[21]=te):te=e[21];let ke;e[22]!==r||e[23]!==n.length||e[24]!==fe||e[25]!==Q?(ke=[r,n.length,fe,Q],e[22]=r,e[23]=n.length,e[24]=fe,e[25]=Q,e[26]=ke):ke=e[26],l.useEffect(te,ke);let Ne;e[27]!==fe?(Ne=()=>{fe()},e[27]=fe,e[28]=Ne):Ne=e[28],l.useLayoutEffect(Ne);let je;e[29]!==r||e[30]!==R||e[31]!==ce?(je=()=>{if(!R||!r)return;const rt=E.current;if(!rt)return;const xe=window.requestAnimationFrame(()=>{const Ye=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),_e=rt.querySelector(`[data-sortable-tab-id="${Ye}"]`);_e&&(_e.scrollIntoView({block:"nearest",inline:"nearest"}),ce())});return()=>{window.cancelAnimationFrame(xe)}},e[29]=r,e[30]=R,e[31]=ce,e[32]=je):je=e[32];let Se;e[33]!==r||e[34]!==R||e[35]!==n.length||e[36]!==ce?(Se=[r,R,n.length,ce],e[33]=r,e[34]=R,e[35]=n.length,e[36]=ce,e[37]=Se):Se=e[37],l.useEffect(je,Se);let De;e[38]!==o?(De=rt=>{if(!o)return;const{active:xe,over:Ye}=rt;!Ye||xe.id===Ye.id||o(String(xe.id),String(Ye.id))},e[38]=o,e[39]=De):De=e[39];const ye=De;let ge;e[40]!==v?(ge=me("relative flex h-full min-w-0 flex-1",v),e[40]=v,e[41]=ge):ge=e[41];let Me;e[42]!==R||e[43]!==C||e[44]!==$?(Me=R&&C.left?s.jsx("div",{className:me("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",$?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=R,e[43]=C,e[44]=$,e[45]=Me):Me=e[45];let Ue;e[46]!==R||e[47]!==C||e[48]!==$?(Ue=R&&C.right?s.jsx("div",{className:me("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",$?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=R,e[47]=C,e[48]=$,e[49]=Ue):Ue=e[49];const q=$?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Ie=$&&"@container/pill-tabs",Le=$&&"pill-tabs__track",Pe=$&&(p??"gap-0.5 py-0.5"),he=_&&"items-center overflow-y-hidden",F=ne&&"rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[color-mix(in_srgb,var(--foreground)_2%,transparent)] p-0.5 gap-0.5",ee=R?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let Ce;e[50]!==q||e[51]!==Ie||e[52]!==Le||e[53]!==Pe||e[54]!==he||e[55]!==F||e[56]!==ee?(Ce=me("relative flex h-full min-w-0 flex-1",q,Ie,Le,Pe,he,F,ee),e[50]=q,e[51]=Ie,e[52]=Le,e[53]=Pe,e[54]=he,e[55]=F,e[56]=ee,e[57]=Ce):Ce=e[57];let Fe;e[58]!==R?(Fe=R?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=R,e[59]=Fe):Fe=e[59];let we;e[60]!==D?(we=D("sortableTabsStrip.aria.tabs"),e[60]=D,e[61]=we):we=e[61];let Qe;e[62]!==L||e[63]!==re||e[64]!==$?(Qe=$&&L?s.jsx("div",{className:me("pointer-events-none absolute left-0 top-0 z-0 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[var(--surface-elevated)]","border border-border/60"),style:{transform:`translate3d(${L.left}px, ${L.top}px, 0)`,width:`${L.width}px`,height:`${L.height}px`,transition:re?"transform 300ms cubic-bezier(0.65, 0, 0.35, 1), width 300ms cubic-bezier(0.65, 0, 0.35, 1), height 300ms cubic-bezier(0.65, 0, 0.35, 1)":void 0}}):null,e[62]=L,e[63]=re,e[64]=$,e[65]=Qe):Qe=e[65];let pe;e[66]!==L||e[67]!==_?(pe=_&&L?s.jsx("div",{className:"pointer-events-none absolute left-0 -bottom-px z-10 h-[3px] rounded-t-[2px] bg-[var(--primary-base)]",style:{transform:`translate3d(${L.left}px, 0, 0)`,width:`${L.width}px`},"aria-hidden":!0}):null,e[66]=L,e[67]=_,e[68]=pe):pe=e[68];let Oe;if(e[69]!==Y||e[70]!==r||e[71]!==m||e[72]!==k||e[73]!==A||e[74]!==y||e[75]!==w||e[76]!==z||e[77]!==j||e[78]!==R||e[79]!==n||e[80]!==i||e[81]!==a||e[82]!==W||e[83]!==$){let rt;e[85]!==Y||e[86]!==r||e[87]!==m||e[88]!==k||e[89]!==A||e[90]!==y||e[91]!==w||e[92]!==z||e[93]!==j||e[94]!==R||e[95]!==i||e[96]!==a||e[97]!==W||e[98]!==$?(rt=xe=>{const Ye=xe.id===r,_e=w&&$&&!Ye&&!!xe.icon,We=!_e,lt=!!xe.icon&&(!y||Ye),Je=w&&$&&Ye&&!R&&!W,Ve=xe.closable!==!1&&!!i,yt=Ve&&!!xe.icon,$t=R||W?void 0:$?Je?"flex-none basis-auto":j?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0";return s.jsx(Y,{id:xe.id,className:$t,children:s.jsxs("div",{ref:Gt=>ve(xe.id,Gt),className:me("group flex h-full min-w-0 flex-nowrap items-center",R||W?"shrink-0":$?"w-full":"w-full min-w-0",$?"relative z-10 bg-transparent":Ye?"relative z-10 bg-transparent text-foreground":"relative z-10 bg-transparent text-muted-foreground hover:text-foreground"),children:[s.jsx("button",{type:"button",role:"tab","aria-selected":Ye,"aria-label":_e?xe.title??xe.label:void 0,onClick:()=>a(xe.id),className:me($?"animated-tabs__button pill-tabs__button relative z-10 flex flex-1 min-w-0 flex-nowrap items-center justify-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] text-sm font-medium transition-colors duration-150 !min-h-0":"flex h-full min-w-0 flex-nowrap items-center typography-micro",$&&k?"lowercase":null,$&&(_e?"gap-0":"gap-1.5"),$?W?"shrink-0 whitespace-nowrap px-3 text-center":R?"max-w-56 shrink-0 px-3 text-center":_e?"px-2 !min-w-0 text-center":Je?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":R?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",$?m??(z?j?"h-[38px]":"h-[31px]":"h-7"):null,$?Ye?"text-foreground":"text-muted-foreground hover:text-foreground":null,$?"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background":null),title:xe.title??xe.label,children:$?s.jsxs(s.Fragment,{children:[lt?s.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[s.jsx("span",{className:me("flex items-center justify-center transition-opacity",yt&&(A?"opacity-0":"group-hover:opacity-0")),children:xe.icon}),yt?s.jsx("span",{role:"button",tabIndex:-1,className:me("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",A?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Tv,onClick:Gt=>{Gt.stopPropagation(),i?.(xe.id)},"aria-label":xe.closeLabel??`Close ${xe.label} tab`,title:xe.closeLabel??`Close ${xe.label} tab`,children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,We?s.jsx("span",{className:"animated-tabs__label truncate",children:xe.label}):null]}):s.jsxs("span",{className:me("flex min-w-0 flex-nowrap items-center gap-1.5",!R&&"justify-center"),children:[lt?s.jsxs("span",{className:me("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",Ye?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:me("flex items-center justify-center transition-opacity",yt&&(A?"opacity-0":"group-hover:opacity-0")),children:xe.icon}),yt?s.jsx("span",{role:"button",tabIndex:-1,className:me("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",A?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Mv,onClick:Gt=>{Gt.stopPropagation(),i?.(xe.id)},"aria-label":xe.closeLabel??`Close ${xe.label} tab`,title:xe.closeLabel??`Close ${xe.label} tab`,children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:xe.label})]})}),Ve&&!yt?s.jsx("button",{type:"button",onPointerDown:Ev,onClick:Gt=>{Gt.stopPropagation(),i?.(xe.id)},className:me("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",$?"-ml-2.5 mr-1 h-[88%] w-5 self-center !aspect-auto rounded-md":"aspect-square h-[65%] min-h-4 max-h-5 rounded-sm mr-1",$?Ye?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":Ye?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":xe.closeLabel??`Close ${xe.label} tab`,title:xe.closeLabel??`Close ${xe.label} tab`,children:s.jsx(I,{name:"close",className:"h-3 w-3"})}):null]})},xe.id)},e[85]=Y,e[86]=r,e[87]=m,e[88]=k,e[89]=A,e[90]=y,e[91]=w,e[92]=z,e[93]=j,e[94]=R,e[95]=i,e[96]=a,e[97]=W,e[98]=$,e[99]=rt):rt=e[99],Oe=n.map(rt),e[69]=Y,e[70]=r,e[71]=m,e[72]=k,e[73]=A,e[74]=y,e[75]=w,e[76]=z,e[77]=j,e[78]=R,e[79]=n,e[80]=i,e[81]=a,e[82]=W,e[83]=$,e[84]=Oe}else Oe=e[84];let nt;e[100]!==Ce||e[101]!==Fe||e[102]!==we||e[103]!==Qe||e[104]!==pe||e[105]!==Oe?(nt=s.jsxs("div",{ref:E,className:Ce,style:Fe,role:"tablist","aria-label":we,children:[Qe,pe,Oe]}),e[100]=Ce,e[101]=Fe,e[102]=we,e[103]=Qe,e[104]=pe,e[105]=Oe,e[106]=nt):nt=e[106];let Re;e[107]!==ge||e[108]!==Me||e[109]!==Ue||e[110]!==nt?(Re=s.jsxs("div",{className:ge,children:[Me,Ue,nt]}),e[107]=ge,e[108]=Me,e[109]=Ue,e[110]=nt,e[111]=Re):Re=e[111];const de=Re;if(!ue)return de;let He;e[112]===Symbol.for("react.memo_cache_sentinel")?(He=[Nv],e[112]=He):He=e[112];let st;e[113]!==M||e[114]!==de?(st=s.jsx(sl,{items:M,strategy:Yg,children:de}),e[113]=M,e[114]=de,e[115]=st):st=e[115];let qe;e[116]===Symbol.for("react.memo_cache_sentinel")?(qe=s.jsx(nl,{dropAnimation:null}),e[116]=qe):qe=e[116];let et;return e[117]!==ye||e[118]!==X||e[119]!==st?(et=s.jsxs(qi,{sensors:X,collisionDetection:Yi,onDragEnd:ye,modifiers:He,children:[st,qe]}),e[117]=ye,e[118]=X,e[119]=st,e[120]=et):et=e[120],et};function Cv(t){return t.isMobile}function Iv(t){return t.id}function Pv(t,e){return!t||!e?t===e:Math.abs(t.left-e.left)<.5&&Math.abs(t.top-e.top)<.5&&Math.abs(t.width-e.width)<.5&&Math.abs(t.height-e.height)<.5}function Av(t){return t===null?t:null}function Dv(t){return t===null?t:null}function Tv(t){t.stopPropagation()}function Mv(t){t.stopPropagation()}function Ev(t){t.stopPropagation()}function Gu(t){const e=at.c(14);let n,r,a,i;e[0]!==t?({size:a,className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);const o=typeof a=="number"?`${a}px`:a,c=typeof a=="number"?`${a}px`:a;let d;e[5]!==i||e[6]!==o||e[7]!==c?(d={width:o,height:c,...i},e[5]=i,e[6]=o,e[7]=c,e[8]=d):d=e[8];let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p=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]=p):p=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:p}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const Fr=[{id:"claude",name:"Claude"},{id:"codex",name:"Codex"},{id:"github-copilot",name:"GitHub Copilot"},{id:"google",name:"Google"},{id:"kimi-for-coding",name:"Kimi for Coding"},{id:"nano-gpt",name:"NanoGPT"},{id:"openrouter",name:"OpenRouter"},{id:"zai-coding-plan",name:"z.ai"},{id:"zhipuai-coding-plan",name:"Zhipu AI Coding Plan"},{id:"minimax-cn-coding-plan",name:"MiniMax Coding Plan (minimaxi.com)"},{id:"minimax-coding-plan",name:"MiniMax Coding Plan (minimax.io)"},{id:"ollama-cloud",name:"Ollama Cloud"},{id:"zhipuai-coding-plan",name:"ZhipuAI"}];Fr.reduce((t,e)=>(t[e.id]=e,t),{});const Rv=t=>typeof t!="number"||Number.isNaN(t)?null:Math.max(0,Math.min(100,Math.round(t))),Fv=t=>typeof t!="number"||Number.isNaN(t)?"-":`${Math.round(t)}%`,Zi=(t,e)=>t??Fv(e),Kd=(t,e)=>{if(!t)return e??"";try{const n=new Date(t);if(!Number.isFinite(n.getTime()))return e??"";const r=new Date;return n.toDateString()===r.toDateString()?n.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}):n.toLocaleString(void 0,{month:"short",day:"numeric",weekday:"short",hour:"numeric",minute:"2-digit"})}catch{return e??""}},yh=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",Hd=t=>t==="5h"?"5-Hour":t==="7d"?"7-Day Limit":t==="7d-sonnet"?"7-Day Sonnet Limit":t==="7d-opus"?"7-Day Opus Limit":t==="weekly"?"Weekly Limit":t==="daily"?"Daily":t==="monthly"?"Monthly Limit":t==="credits"?"Credits":t==="session"?"Session":t==="premium"?"Premium Interactions":t==="chat"?"Chat Requests":t==="completions"?"Completions":t==="premium_interactions"?"Premium interactions":t,Lv=t=>{const e=t.toLowerCase().trim();if(e==="5h")return 5*3600;if(e==="7d"||e==="weekly"||e==="7d-sonnet"||e==="7d-opus")return 7*86400;if(e==="monthly")return 30*86400;if(e==="24h"||e==="daily")return 86400;if(e==="1h")return 3600;const n=e.match(/^(\d+)h$/);if(n)return parseInt(n[1],10)*3600;const r=e.match(/^(\d+)d$/);return r?parseInt(r[1],10)*86400:null},eo=(t,e,n,r)=>{let a=n;if(a===null&&r&&(a=Lv(r)),t===null||e===null||a===null||a<=0)return null;const i=Date.now(),o=Math.max(0,(e-i)/1e3),c=Math.max(0,Math.min(a,a-o)),d=Math.max(0,Math.min(1,c/a)),p=t/100,m=t>=100&&o>0;let u;d>.01?u=Math.min(999,p/d*100):u=t;let f;m?f="exhausted":p<=d?f="on-track":u<=130?f="slightly-fast":f="too-fast";const b=a>=120*3600,h=b?86400:3600,v=b?"d":"h",x=a/h,g=Math.max(c/h,x*.01),w=t/g,y=Number.isFinite(w)?`${Math.min(999.9,Math.max(0,w)).toFixed(1)}%/${v}`:"-",k=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`;let D=null;const j=a/86400;return j>=7&&(D=100/j),{elapsedRatio:d,usageRatio:p,predictedFinalPercent:u,remainingSeconds:o,isExhausted:m,elapsedSeconds:c,totalSeconds:a,status:f,paceRateText:y,predictText:k,dailyAllocationPercent:D}},Ov=t=>{switch(t){case"exhausted":case"too-fast":return"var(--status-error)";case"slightly-fast":return"var(--status-warning)";case"on-track":return"var(--status-success)"}},qu=t=>{const e=Math.max(0,Math.floor(t)),n=Math.floor(e/60),r=Math.floor(n/60),a=Math.floor(r/24),i=r%24,o=n%60;return a>0?`${a}d ${i}h`:r>0?`${r}h`:n===0?"<1m":`${o}m`},Wr=t=>Math.min(100,Math.max(0,t*100));function cl(t){const e=t.indexOf("/");if(e!==-1){const n=t.substring(0,e);if(n==="gemini"||n==="antigravity")return t.substring(e+1)}return t}const $v=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],vh={google:$v};function wh(t,e){const n=vh[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function jh(t){return vh[t]??[]}function Nh(t){return[...t].sort((e,n)=>e.order-n.order)}function Bv(t,e){const n=new Map;for(const r of Object.keys(t)){const i=wh(r,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(r)}return n}function zv(t,e,n){const r=new Map;for(const a of t){const i=e(a),c=wh(i,n)?.id??null;r.has(c)||r.set(c,[]),r.get(c).push(a)}return r}function _v(t,e){return e.filter(n=>{const r=n.toLowerCase(),a=r.includes("/")?r.split("/")[1]:r;return!!(a.startsWith("gemini-3-")||a.startsWith("claude-"))})}const Gd=6e4,Yu=t=>{const e=Fr.map(u=>u.id),n=typeof t?.usageAutoRefresh=="boolean"?t.usageAutoRefresh:!1,r=typeof t?.usageRefreshIntervalMs=="number"&&Number.isFinite(t.usageRefreshIntervalMs)?Math.max(3e4,Math.min(3e5,Math.round(t.usageRefreshIntervalMs))):Gd,a=t?.usageDisplayMode==="remaining"?"remaining":"usage",i=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,o=i?i.filter(u=>typeof u=="string"&&e.includes(u)):e,c={},d=t?.usageSelectedModels;if(d&&typeof d=="object")for(const[u,f]of Object.entries(d))Array.isArray(f)&&(c[u]=f.filter(b=>typeof b=="string"));const p={},m=t?.usageExpandedFamilies;if(m&&typeof m=="object")for(const[u,f]of Object.entries(m))Array.isArray(f)&&(p[u]=f.filter(b=>typeof b=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:a,dropdownProviderIds:o,selectedModels:c,expandedFamilies:p}},Vv=async()=>{const t=hr()?.settings;if(t)try{const n=(await t.load())?.settings;return Yu(n??null)}catch{}if(!un()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return Yu(n)}}return{autoRefresh:!1,refreshIntervalMs:Gd,displayMode:"usage",dropdownProviderIds:Fr.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},$s=ar()(vi((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Gd,displayMode:"usage",dropdownProviderIds:Fr.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Vv();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Fr.map(r=>r.id);try{await Promise.all(n.map(r=>e().fetchProviderQuota(r))),t({isLoading:!1,lastUpdated:Date.now()})}catch(r){const a=r instanceof Error?r.message:"Failed to fetch quotas";t({isLoading:!1,error:a})}},fetchProviderQuota:async n=>{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!0}}));try{const r=await fetch(`/api/quota/${encodeURIComponent(n)}`),a=await r.json().catch(()=>null);if(!r.ok)throw new Error(a?.error||"Failed to fetch quota");const i=a;t(o=>{const c=o.results.filter(d=>d.providerId!==n);return c.push(i),{results:c,error:null}})}catch(r){const a=r instanceof Error?r.message:"Failed to fetch quota",i={providerId:n,providerName:n,ok:!1,configured:!1,error:a,usage:null,fetchedAt:Date.now()};t(o=>{const c=o.results.filter(d=>d.providerId!==n);return c.push(i),{results:c,error:a}})}finally{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>t({selectedProviderId:n}),setAutoRefresh:n=>t({autoRefresh:n}),setRefreshInterval:n=>{const r=Math.max(3e4,Math.min(3e5,Math.round(n)));t({refreshIntervalMs:r})},setDisplayMode:n=>t({displayMode:n}),setDropdownProviderIds:n=>t({dropdownProviderIds:n}),setSelectedModels:(n,r)=>{t(a=>({selectedModels:{...a.selectedModels,[n]:r}}))},toggleModelSelected:(n,r)=>{t(a=>{const i=a.selectedModels[n]??[],c=i.includes(r)?i.filter(d=>d!==r):[...i,r];return{selectedModels:{...a.selectedModels,[n]:c}}})},setExpandedFamilies:(n,r)=>{t(a=>({expandedFamilies:{...a.expandedFamilies,[n]:r}})),Ms({usageExpandedFamilies:e().expandedFamilies})},toggleFamilyExpanded:(n,r)=>{t(a=>{const i=a.expandedFamilies[n]??[],c=i.includes(r)?i.filter(d=>d!==r):[...i,r];return{expandedFamilies:{...a.expandedFamilies,[n]:c}}}),Ms({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=_v(n,r);i.length!==0&&(t(o=>({selectedModels:{...o.selectedModels,[n]:i}})),Ms({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Sh=()=>{const t=at.c(5),e=$s(Uv),n=$s(Wv),r=$s(Kv);let a,i;t[0]!==e||t[1]!==r||t[2]!==n?(a=()=>{if(!e)return;const o=window.setInterval(()=>{r()},n);return()=>window.clearInterval(o)},i=[e,n,r],t[0]=e,t[1]=r,t[2]=n,t[3]=a,t[4]=i):(a=t[3],i=t[4]),l.useEffect(a,i)};function Uv(t){return t.autoRefresh}function Wv(t){return t.refreshIntervalMs}function Kv(t){return t.fetchAllQuotas}const dl=ze.forwardRef((t,e)=>{const n=at.c(11);let r,a;n[0]!==t?({className:r,...a}=t,n[0]=t,n[1]=r,n[2]=a):(r=n[1],a=n[2]);let i;n[3]!==r?(i=me("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]",r),n[3]=r,n[4]=i):i=n[4];let o;n[5]===Symbol.for("react.memo_cache_sentinel")?(o={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=o):o=n[5];let c;n[6]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Jg,{className:me("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[checked]:translate-x-4 data-[unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=c):c=n[6];let d;return n[7]!==a||n[8]!==e||n[9]!==i?(d=s.jsx(Qg,{className:i,style:o,...a,ref:e,children:c}),n[7]=a,n[8]=e,n[9]=i,n[10]=d):d=n[10],d});dl.displayName="Switch";const jo=()=>{try{const e=Ls.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=rn.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[McpConfigStore] Error resolving config directory:",t)}return null},Ju=t=>t?Object.entries(t).map(([e,n])=>({key:e,value:n})):[],Qu=t=>{const e=t.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},No=t=>typeof t!="string"?void 0:t.trim()||void 0,ac=800,Hv=5e3,Gv="__default__",Zc=new Map,ic=new Map,kh=t=>t?.trim()||Gv,oc=t=>{Zc.delete(kh(t))},to=ar()(vi(ro((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=jo(),a=kh(r),i=Date.now(),o=Zc.get(a)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&i-o<Hv)return!0;const d=ic.get(a);if(!n?.force&&d)return d;const p=(async()=>{t({isLoading:!0});try{const m=r?`?directory=${encodeURIComponent(r)}`:"",u=await fetch(`/api/config/mcp${m}`,{headers:r?{"x-opencode-directory":r}:void 0});if(!u.ok)throw new Error("Failed to load MCP configs");const f=await u.json();return t({mcpServers:f,isLoading:!1}),Zc.set(a,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();ic.set(a,p);try{return await p}finally{ic.delete(a)}},createMcp:async n=>{ql("Creating MCP server configuration…");let r=!1;try{const a=Xu(n),i=jo(),o=i?`?directory=${encodeURIComponent(i)}`:"",c=await fetch(`/api/config/mcp/${encodeURIComponent(n.name)}${o}`,{method:"POST",headers:{"Content-Type":"application/json",...i?{"x-opencode-directory":i}:{}},body:JSON.stringify(a)}),d=await c.json().catch(()=>null);if(!c.ok)throw new Error(d?.error||"Failed to create MCP server");return oc(i),d?.requiresReload?(r=!0,await Yl({message:d.message,delayMs:d.reloadDelayMs??ac,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning})}catch(a){return console.error("[McpConfigStore] Failed to create MCP:",a),{ok:!1}}finally{r||Jl()}},updateMcp:async(n,r)=>{ql("Updating MCP server configuration…");let a=!1;try{const i=Xu(r),o=jo(),c=o?`?directory=${encodeURIComponent(o)}`:"",d=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${c}`,{method:"PATCH",headers:{"Content-Type":"application/json",...o?{"x-opencode-directory":o}:{}},body:JSON.stringify(i)}),p=await d.json().catch(()=>null);if(!d.ok)throw new Error(p?.error||"Failed to update MCP server");return oc(o),p?.requiresReload?(a=!0,await Yl({message:p.message,delayMs:p.reloadDelayMs??ac,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:p?.reloadFailed===!0,message:p?.message,warning:p?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:p?.reloadFailed===!0,message:p?.message,warning:p?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{a||Jl()}},deleteMcp:async n=>{ql("Deleting MCP server configuration…");let r=!1;try{const a=jo(),i=a?`?directory=${encodeURIComponent(a)}`:"",o=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:a?{"x-opencode-directory":a}:void 0}),c=await o.json().catch(()=>null);if(!o.ok)throw new Error(c?.error||"Failed to delete MCP server");return oc(a),c?.requiresReload&&(r=!0,await Yl({message:c.message,delayMs:c.reloadDelayMs??ac,scopes:["all"]})),e().selectedMcpName===n&&t({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning}}catch(a){return console.error("[McpConfigStore] Failed to delete MCP:",a),{ok:!1}}finally{r||Jl()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:kl(()=>sa()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function Xu(t){const e={};if(t.scope!==void 0&&(e.scope=t.scope),t.type!==void 0&&(e.type=t.type),(t.type==="local"||t.command!==void 0)&&(e.command=(t.command??[]).filter(n=>n.trim())),(t.type==="remote"||t.url!==void 0)&&(e.url=t.url?.trim()??""),t.environment!==void 0&&(e.environment=Qu(t.environment)??{}),t.headers!==void 0&&(e.headers=Qu(t.headers)??{}),t.oauthEnabled!==void 0||t.oauthClientId!==void 0||t.oauthClientSecret!==void 0||t.oauthScope!==void 0||t.oauthRedirectUri!==void 0)if(t.oauthEnabled===!1)e.oauth=!1;else{const n={clientId:No(t.oauthClientId),clientSecret:No(t.oauthClientSecret),scope:No(t.oauthScope),redirectUri:No(t.oauthRedirectUri)};n.clientId||n.clientSecret||n.scope||n.redirectUri?e.oauth=n:t.oauthEnabled?e.oauth={}:e.oauth=!1}if(t.timeout!==void 0){const n=Number(t.timeout);Number.isFinite(n)&&n>0?e.timeout=n:e.timeout=null}return t.enabled!==void 0&&(e.enabled=t.enabled),e}const qv={},Yv={},Vr=t=>{if(typeof t!="string")return null;const e=t.trim();if(!e)return null;const n=e.replace(/\\/g,"/");return n.length>1?n.replace(/\/+$/,""):n},Ga=t=>Vr(t)??"__global__",ha=t=>{const e=Vr(t);return e?rn.getScopedApiClient(e):rn.getApiClient()},wn=ar()(vi((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=Ga(n??Ws.getState().currentDirectory);return e().byDirectory[r]??qv},getDiagnosticForDirectory:n=>{const r=Ga(n??Ws.getState().currentDirectory);return e().diagnosticsByDirectory[r]??Yv},getErrorForDirectory:n=>{const r=Ga(n??Ws.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=Vr(n?.directory??Ws.getState().currentDirectory),a=Ga(r);n?.silent||t(i=>({loadingKeys:{...i.loadingKeys,[a]:!0},lastErrorKeys:{...i.lastErrorKeys,[a]:null}}));try{const c=(await ha(r).mcp.status()).data??{};t(d=>({byDirectory:{...d.byDirectory,[a]:c},diagnosticsByDirectory:{...d.diagnosticsByDirectory,[a]:Object.fromEntries(Object.entries(d.diagnosticsByDirectory[a]??{}).filter(([p])=>!c[p]))},loadingKeys:{...d.loadingKeys,[a]:!1},lastErrorKeys:{...d.lastErrorKeys,[a]:null}}))}catch(i){const o=i instanceof Error?i.message:"Failed to load MCP status";t(c=>({loadingKeys:{...c.loadingKeys,[a]:!1},lastErrorKeys:{...c.lastErrorKeys,[a]:o}}))}},connect:async(n,r)=>{const a=Vr(r??Ws.getState().currentDirectory),i=Ga(a),o=ha(a);try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(c){const d=c instanceof Error?c.message:"Connection failed";throw t(p=>({diagnosticsByDirectory:{...p.diagnosticsByDirectory,[i]:{...p.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:d}}}})),c}await e().refresh({directory:a,silent:!0})},disconnect:async(n,r)=>{const a=Vr(r??Ws.getState().currentDirectory);await ha(a).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},startAuth:async(n,r)=>{const a=Vr(r??Ws.getState().currentDirectory),c=(await ha(a).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!c)throw new Error("Authorization URL was not returned");return c},completeAuth:async(n,r,a)=>{const i=Vr(a??Ws.getState().currentDirectory);await ha(i).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,r)=>{const a=Vr(r??Ws.getState().currentDirectory);await ha(a).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},testConnection:async(n,r)=>{const a=Vr(r??Ws.getState().currentDirectory),i=Ga(a),o=ha(a),d=e().getStatusForDirectory(a)[n]?.status==="connected";let p,m;try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(b){p=b instanceof Error?b.message:"Connection failed",t(h=>({diagnosticsByDirectory:{...h.diagnosticsByDirectory,[i]:{...h.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:p??"Connection failed"}}}}))}await e().refresh({directory:a,silent:!0});const u=e().getStatusForDirectory(a)[n],f=u;if(!d&&u?.status==="connected"){try{await o.mcp.disconnect({name:n},{throwOnError:!0})}catch(b){m=`Connection test succeeded, but cleanup disconnect failed: ${b instanceof Error?b.message:"Disconnect failed"}`}await e().refresh({directory:a,silent:!0})}return{status:f??e().getStatusForDirectory(a)[n],error:p,warning:m}}})));function Jv(t){const e=at.c(4);let n,r;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z"}),r=s.jsx("path",{d:"M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z"}),e[0]=n,e[1]=r):(n=e[0],r=e[1]);let a;return e[2]!==t?(a=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",fillRule:"evenodd",viewBox:"-0.5 -0.5 25 25",...t,children:[n,r]}),e[2]=t,e[3]=a):a=e[3],a}const Qv=(t,e)=>{if(!t)return e("mcpDropdown.status.unknown");switch(t.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:t.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:t.error||""});default:return t.status}},Xv=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Ch=({active:t,className:e})=>{const{t:n}=mt(),a=Ws(g=>g.currentDirectory)??null,i=wn(g=>g.getStatusForDirectory(a)),o=wn(g=>g.refresh),c=wn(g=>g.connect),d=wn(g=>g.disconnect),p=to(g=>g.mcpServers),m=to(g=>g.loadMcpConfigs),[u,f]=l.useState(!1),[b,h]=l.useState(null);l.useEffect(()=>{o({directory:a,silent:!0})},[o,a]),l.useEffect(()=>{m({force:!0})},[m]),l.useEffect(()=>{t&&Promise.all([o({directory:a,silent:!0}),m({force:!0})])},[t,o,a,m]);const v=l.useMemo(()=>{const g=new Set(Object.keys(i));for(const w of p)w?.name&&g.add(w.name);return Array.from(g).sort((w,y)=>w.localeCompare(y))},[p,i]),x=l.useCallback(g=>{if(g?.preventDefault(),u)return;f(!0);const w=new Promise(y=>setTimeout(y,500));Promise.all([o({directory:a}),w]).finally(()=>{f(!1)})},[u,o,a]);return s.jsxs("div",{className:me("w-full",e),children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:n("mcpDropdown.title")}),a&&s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:a.split("/").pop()||a})]}),s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:u,onClick:x,"aria-label":n("mcpDropdown.actions.refreshAria"),children:s.jsx(I,{name:"refresh",className:me("h-4 w-4",u&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[v.map(g=>{const w=i[g],y=Xv(w),k=w?.status==="connected",D=b===g,j=Qv(w,n);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:me("h-2 w-2 rounded-full flex-shrink-0",y==="success"&&"bg-status-success",y==="error"&&"bg-status-error",y==="warning"&&"bg-status-warning",y==="default"&&"bg-muted-foreground/40"),"aria-label":j})}),s.jsx(At,{side:"left",children:s.jsx("p",{children:j})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:g})]})}),s.jsx(dl,{checked:k,disabled:D,className:"data-[checked]:bg-status-info",onCheckedChange:async S=>{h(g);try{S?await c(g,a):await d(g,a)}finally{h(null)}}})]},g)}),v.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},so=t=>{const e=at.c(20),{percent:n,tonePercent:r,className:a,expectedMarkerPercent:i}=t;let o;e[0]!==n?(o=Rv(n)??0,e[0]=n,e[1]=o):o=e[1];const c=o,d=r??n;let p;e[2]!==d?(p=yh(d),e[2]=d,e[3]=p):p=e[3];const m=p,u=i!=null?Math.max(0,Math.min(100,i)):null;let f;e[4]!==m?(f=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=f):f=e[5];const b=f;let h;e[6]!==a?(h=me("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",a),e[6]=a,e[7]=h):h=e[7];const v=`${c}%`;let x;e[8]!==b||e[9]!==v?(x={...b,width:v},e[8]=b,e[9]=v,e[10]=x):x=e[10];let g;e[11]!==c||e[12]!==x?(g=s.jsx("div",{className:"h-full transition-all duration-300",style:x,role:"progressbar","aria-valuenow":c,"aria-valuemin":0,"aria-valuemax":100}),e[11]=c,e[12]=x,e[13]=g):g=e[13];let w;e[14]!==u?(w=u!=null&&u>0&&u<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${u}%`},title:`Expected usage if spread evenly: ${Math.round(u)}% of quota`,"aria-hidden":"true"}),e[14]=u,e[15]=w):w=e[15];let y;return e[16]!==h||e[17]!==g||e[18]!==w?(y=s.jsxs("div",{className:h,children:[g,w]}),e[16]=h,e[17]=g,e[18]=w,e[19]=y):y=e[19],y},no=t=>{const e=at.c(67),{paceInfo:n,className:r,compact:a}=t,i=a===void 0?!1:a,{t:o}=mt();let c;e[0]!==n.status?(c=Ov(n.status),e[0]=n.status,e[1]=c):c=e[1];const d=c;let p;e:{switch(n.status){case"on-track":{let S;e[2]!==o?(S=o("settings.usage.pace.status.onTrack"),e[2]=o,e[3]=S):S=e[3],p=S;break e}case"slightly-fast":{let S;e[4]!==o?(S=o("settings.usage.pace.status.slightlyFast"),e[4]=o,e[5]=S):S=e[5],p=S;break e}case"too-fast":{let S;e[6]!==o?(S=o("settings.usage.pace.status.tooFast"),e[6]=o,e[7]=S):S=e[7],p=S;break e}case"exhausted":{let S;e[8]!==o?(S=o("settings.usage.pace.status.usedUp"),e[8]=o,e[9]=S):S=e[9],p=S;break e}}p=void 0}const m=p;let u;e[10]!==n.predictText||e[11]!==o?(u=o("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=o,e[12]=u):u=e[12];const f=u;if(i){let S;e[13]!==r?(S=me("flex items-center gap-1.5",r),e[13]=r,e[14]=S):S=e[14];let A;e[15]!==d?(A={backgroundColor:d},e[15]=d,e[16]=A):A=e[16];let E;e[17]!==m||e[18]!==A?(E=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:A,title:m}),e[17]=m,e[18]=A,e[19]=E):E=e[19];let P;e[20]!==d?(P={color:d},e[20]=d,e[21]=P):P=e[21];const C=n.isExhausted?void 0:f;let N;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==o?(N=n.isExhausted?s.jsx(s.Fragment,{children:o("settings.usage.pace.wait",{duration:qu(n.remainingSeconds)})}):s.jsx(s.Fragment,{children:o("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=o,e[26]=N):N=e[26];let T;e[27]!==N||e[28]!==P||e[29]!==C?(T=s.jsx("span",{className:"typography-micro tabular-nums",style:P,title:C,children:N}),e[27]=N,e[28]=P,e[29]=C,e[30]=T):T=e[30];let M;return e[31]!==T||e[32]!==S||e[33]!==E?(M=s.jsxs("div",{className:S,children:[E,T]}),e[31]=T,e[32]=S,e[33]=E,e[34]=M):M=e[34],M}let b;e[35]!==r?(b=me("flex items-center justify-between gap-2",r),e[35]=r,e[36]=b):b=e[36];let h;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==o?(h=!n.isExhausted&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:o("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=o,e[40]=h):h=e[40];let v;e[41]!==h?(v=s.jsx("div",{className:"flex items-center gap-1.5",children:h}),e[41]=h,e[42]=v):v=e[42];let x;e[43]!==d?(x={color:d},e[43]=d,e[44]=x):x=e[44];let g;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==f||e[49]!==m||e[50]!==o?(g=n.isExhausted?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"font-medium",children:m}),s.jsx("span",{className:"text-muted-foreground",children:o("settings.usage.pace.waitSeparator")}),s.jsx("span",{className:"font-medium",children:qu(n.remainingSeconds)})]}):s.jsxs("span",{title:f,children:[s.jsx("span",{className:"text-muted-foreground",children:o("settings.usage.pace.predictionLabel")}),s.jsx("span",{className:"font-medium",children:n.predictText})]}),e[45]=n.isExhausted,e[46]=n.predictText,e[47]=n.remainingSeconds,e[48]=f,e[49]=m,e[50]=o,e[51]=g):g=e[51];let w;e[52]!==x||e[53]!==g?(w=s.jsx("span",{className:"typography-micro tabular-nums",style:x,children:g}),e[52]=x,e[53]=g,e[54]=w):w=e[54];let y;e[55]!==d?(y={backgroundColor:d},e[55]=d,e[56]=y):y=e[56];let k;e[57]!==m||e[58]!==y?(k=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:y,title:m}),e[57]=m,e[58]=y,e[59]=k):k=e[59];let D;e[60]!==w||e[61]!==k?(D=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,k]}),e[60]=w,e[61]=k,e[62]=D):D=e[62];let j;return e[63]!==D||e[64]!==b||e[65]!==v?(j=s.jsxs("div",{className:b,children:[v,D]}),e[63]=D,e[64]=b,e[65]=v,e[66]=j):j=e[66],j},gr=Xg,kr=t=>{const e=at.c(14);let n,r,a,i;e[0]!==t?({className:a,asChild:n,children:r,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);let o;e[5]!==n||e[6]!==r?(o=n&&ze.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=o):o=e[7];const c=o;let d;e[8]!==a?(d=me("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",a),e[8]=a,e[9]=d):d=e[9];let p;return e[10]!==i||e[11]!==c||e[12]!==d?(p=s.jsx(Zg,{className:d,...i,...c}),e[10]=i,e[11]=c,e[12]=d,e[13]=p):p=e[13],p},xr=t=>{const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=me("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(ex,{className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i},ra=[{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"}],ed="finder",td=new Set(["finder","terminal"]),sd=t=>t?ra.find(e=>e.id===t)??null:null,lc=()=>ra.filter(t=>td.has(t.id)).map(t=>({...t})),Zv=()=>{if(typeof window>"u")return ed;const t=window.localStorage.getItem("openInAppId");return t&&sd(t)?t:ed};let cc=!1,qa=!1,Xr=!1,Zr=0,Ui=null;const Zu=()=>{Ui&&(clearTimeout(Ui),Ui=null)},Dr=ar()((t,e)=>({selectedAppId:Zv(),availableApps:lc(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(cc||typeof window>"u")return;cc=!0;const n=(d,p=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:lc(),hasLoadedApps:p});return}const m=new Set(d.map(h=>h.name)),u=new Map(d.map(h=>[h.name,h.iconDataUrl??void 0])),b=ra.filter(h=>m.has(h.appName)||td.has(h.id)).map(h=>({...h,iconDataUrl:u.get(h.appName)}));t({availableApps:b,hasLoadedApps:!0})},r=async d=>{if(!Ma()||!Kr()||qa||e().hasLoadedApps&&!d)return;const m=ra.map(u=>u.appName);Zu(),qa=!0,Xr=!1,t({isScanning:!0});try{const{apps:u,success:f,hasCache:b,isCacheStale:h}=await gu(m,d),v=f&&!b&&u.length===0&&Zr<3;if(t({isCacheStale:b?h:!1}),n(u,f?!v:!1),f){if(v){const g=[800,1600,3200][Zr]??3200;Zr+=1,Xr=!0,Ui=setTimeout(()=>{r()},g);return}Zr=0,Xr=!1;return}if(Zr<3){const g=[1e3,3e3,7e3][Zr]??7e3;Zr+=1,Xr=!0,Ui=setTimeout(()=>{r()},g)}}finally{qa=!1,Xr||t({isScanning:!1})}};r();const a=d=>{const p=d.detail,m=p&&typeof p.openInAppId=="string"&&p.openInAppId.length>0&&sd(p.openInAppId)?p.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},i=()=>{r()},o=d=>{const p=d.detail;Array.isArray(p)&&(Zr=3,Xr=!1,t({isScanning:!1,isCacheStale:!1}),n(p))};window.addEventListener("openchamber:settings-synced",a),window.addEventListener("openchamber:app-ready",i),window.addEventListener("openchamber:installed-apps-updated",o),window.__openchamberAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(cc||e().initialize(),!Ma()||!Kr()||qa||e().hasLoadedApps&&!n)return;const a=ra.map(i=>i.appName);Zu(),n&&t({hasLoadedApps:!1}),qa=!0,Xr=!1,t({isScanning:!0});try{const{apps:i,hasCache:o,isCacheStale:c}=await gu(a,n),d=new Set(i.map(f=>f.name)),p=new Map(i.map(f=>[f.name,f.iconDataUrl??void 0])),u=ra.filter(f=>d.has(f.appName)||td.has(f.id)).map(f=>({...f,iconDataUrl:p.get(f.appName)}));t({availableApps:u.length>0?u:lc(),hasLoadedApps:u.length>0,isCacheStale:o?c:!1})}finally{qa=!1,Xr||t({isScanning:!1})}},selectApp:async n=>{sd(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await Ms({openInAppId:n}))}})),e1="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",t1="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",dc=t=>({...t,fallbackIconDataUrl:t.id==="finder"?e1:t.id==="terminal"?t1:void 0}),em=t=>{const e=at.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:a}=t,[i,o]=l.useState(!1);let c;e[0]!==n?(c=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=c):c=e[1];const d=c,p=r||a;if(p&&!i){let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f=()=>o(!0),e[2]=f):f=e[2];let b;return e[3]!==p?(b=s.jsx("img",{src:p,alt:"",className:"h-4 w-4 rounded-sm",onError:f}),e[3]=p,e[4]=b):b=e[4],b}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=me("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 u;return e[6]!==d?(u=s.jsx("span",{className:m,children:d}),e[6]=d,e[7]=u):u=e[7],u},s1=t=>{const e=at.c(82),{directory:n,className:r}=t,{t:a}=mt(),i=Dr(n1),o=Dr(r1),c=Dr(a1),d=Dr(i1),p=Dr(o1),m=Dr(l1),u=Dr(c1);let f,b;e[0]!==p?(f=()=>{p()},b=[p],e[0]=p,e[1]=f,e[2]=b):(f=e[1],b=e[2]),l.useEffect(f,b);const h=Ma()&&Kr();let v;e:{let U;e[3]!==o||e[4]!==i?(U=o.find(ie=>ie.id===i)??o.find(d1)??o[0]??ra[0],e[3]=o,e[4]=i,e[5]=U):U=e[5];const ae=U;if(ae){let ie;e[6]!==ae?(ie=dc(ae),e[6]=ae,e[7]=ie):ie=e[7],v=ie;break e}let ve;e[8]===Symbol.for("react.memo_cache_sentinel")?(ve=dc(ra[0]),e[8]=ve):ve=e[8],v=ve}const x=v;if(!h||!n||o.length===0)return null;let g;e[9]!==n?(g=async U=>{await $x(n,U.id,U.appName)||await rl(n,U.appName)},e[9]=n,e[10]=g):g=e[10];const w=g;let y;e[11]!==w||e[12]!==u?(y=async U=>{await u(U.id),await w(U)},e[11]=w,e[12]=u,e[13]=y):y=e[13];const k=y;let D;e[14]!==n||e[15]!==a?(D=async()=>{(await Rn(n)).ok&&G.success(a("openInApp.toast.pathCopied"))},e[14]=n,e[15]=a,e[16]=D):D=e[16];const j=D;let S;e[17]!==r?(S=me("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]=S):S=e[18];let A;e[19]!==w||e[20]!==x?(A=()=>{w(x)},e[19]=w,e[20]=x,e[21]=A):A=e[21];let E;e[22]===Symbol.for("react.memo_cache_sentinel")?(E=me("inline-flex h-full items-center gap-2 px-3 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors"),e[22]=E):E=e[22];let P;e[23]!==x.label||e[24]!==a?(P=a("openInApp.actions.openInAria",{app:x.label}),e[23]=x.label,e[24]=a,e[25]=P):P=e[25];let C;e[26]!==x.fallbackIconDataUrl||e[27]!==x.iconDataUrl||e[28]!==x.label?(C=s.jsx(em,{label:x.label,iconDataUrl:x.iconDataUrl,fallbackIconDataUrl:x.fallbackIconDataUrl}),e[26]=x.fallbackIconDataUrl,e[27]=x.iconDataUrl,e[28]=x.label,e[29]=C):C=e[29];const N=d?"animate-pulse text-muted-foreground":void 0;let T;e[30]!==N?(T=me("header-open-label",N),e[30]=N,e[31]=T):T=e[31];let M;e[32]!==a?(M=a("openInApp.actions.open"),e[32]=a,e[33]=M):M=e[33];let R;e[34]!==T||e[35]!==M?(R=s.jsx("span",{className:T,children:M}),e[34]=T,e[35]=M,e[36]=R):R=e[36];let O;e[37]!==P||e[38]!==C||e[39]!==R||e[40]!==A?(O=s.jsxs("button",{type:"button",onClick:A,className:E,"aria-label":P,children:[C,R]}),e[37]=P,e[38]=C,e[39]=R,e[40]=A,e[41]=O):O=e[41];let z;e[42]===Symbol.for("react.memo_cache_sentinel")?(z=me("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[42]=z):z=e[42];let B;e[43]!==a?(B=a("openInApp.actions.chooseAppAria"),e[43]=a,e[44]=B):B=e[44];let $;e[45]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4"}),e[45]=$):$=e[45];let _;e[46]!==B?(_=s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:z,"aria-label":B,children:$})}),e[46]=B,e[47]=_):_=e[47];let Q;e[48]===Symbol.for("react.memo_cache_sentinel")?(Q={translate:"-30px 0"},e[48]=Q):Q=e[48];let W;e[49]!==j?(W=()=>{j()},e[49]=j,e[50]=W):W=e[50];let ne;e[51]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsx(I,{name:"file-copy",className:"h-4 w-4"}),e[51]=ne):ne=e[51];let re;e[52]!==a?(re=a("openInApp.actions.copyPath"),e[52]=a,e[53]=re):re=e[53];let ue;e[54]!==re?(ue=s.jsx("span",{className:"typography-ui-label text-foreground",children:re}),e[54]=re,e[55]=ue):ue=e[55];let Y;e[56]!==W||e[57]!==ue?(Y=s.jsxs(Vt,{className:"flex items-center gap-2",onClick:W,children:[ne,ue]}),e[56]=W,e[57]=ue,e[58]=Y):Y=e[58];let le;e[59]===Symbol.for("react.memo_cache_sentinel")?(le=s.jsx(Tn,{}),e[59]=le):le=e[59];let J;if(e[60]!==o||e[61]!==k||e[62]!==x.id){let U;e[64]!==k||e[65]!==x.id?(U=ae=>{const ve=dc(ae);return s.jsxs(Vt,{className:"flex items-center gap-2",onClick:()=>{k(ae)},children:[s.jsx(em,{label:ae.label,iconDataUrl:ae.iconDataUrl,fallbackIconDataUrl:ve.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:ae.label}),x.id===ae.id?s.jsx(I,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},ae.id)},e[64]=k,e[65]=x.id,e[66]=U):U=e[66],J=o.map(U),e[60]=o,e[61]=k,e[62]=x.id,e[63]=J}else J=e[63];let L;e[67]!==c||e[68]!==m||e[69]!==a?(L=c?s.jsxs(Vt,{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:a("openInApp.actions.refreshApps")})]}):null,e[67]=c,e[68]=m,e[69]=a,e[70]=L):L=e[70];let V;e[71]!==Y||e[72]!==J||e[73]!==L?(V=s.jsxs(zs,{align:"center",className:"w-56 max-h-[70vh] overflow-y-auto",style:Q,children:[Y,le,J,L]}),e[71]=Y,e[72]=J,e[73]=L,e[74]=V):V=e[74];let K;e[75]!==_||e[76]!==V?(K=s.jsxs(_s,{children:[_,V]}),e[75]=_,e[76]=V,e[77]=K):K=e[77];let X;return e[78]!==O||e[79]!==K||e[80]!==S?(X=s.jsxs("div",{className:S,children:[O,K]}),e[78]=O,e[79]=K,e[80]=S,e[81]=X):X=e[81],X};function n1(t){return t.selectedAppId}function r1(t){return t.availableApps}function a1(t){return t.isCacheStale}function i1(t){return t.isScanning}function o1(t){return t.initialize}function l1(t){return t.loadInstalledApps}function c1(t){return t.selectApp}function d1(t){return t.id===ed}const u1=1e6,m1="terminal-store";let tm=!1;const uc=t=>typeof t=="object"&&t!==null,p1=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function Wn(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const mc=(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}),Ih=/\x1b\[[0-9;]*m/g,f1=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[\w\-./~%!$&'()*+,;=:@?#[\]]*)?)/i,h1=new Set([".",",",";",":","!","?"]),g1=t=>{let e=t;for(;e.length>0;){const n=e[e.length-1];if(n===")"||n==="]"||n==="}"||n===">"){const r=n===")"?"(":n==="]"?"[":n==="}"?"{":"<",a=e.slice(0,-1),i=(a.match(new RegExp(`\\${r}`,"g"))||[]).length,o=(a.match(new RegExp(`\\${n}`,"g"))||[]).length;if(i>o)break;e=a;continue}if(h1.has(n)){e=e.slice(0,-1);continue}break}return e},x1=t=>{if(!t)return null;const n=t.replace(Ih,"").match(f1);if(!n?.[1])return null;let r=g1(n[1]);return r=r.replace("0.0.0.0","127.0.0.1"),r=r.replace("[::1]","127.0.0.1"),r=r.replace("[::]","127.0.0.1"),r},b1=t=>{if(!t)return null;const n=t.replace(Ih,"").match(/Serving HTTP on .*? port (\d{2,5})/i);if(!n?.[1])return null;const r=Number.parseInt(n[1],10);return!Number.isFinite(r)||r<=0||r>65535?null:`http://127.0.0.1:${r}/`},pc=t=>({tabs:[t],activeTabId:t.id}),Pr=(t,e)=>t.tabs.findIndex(n=>n.id===e),ln=ar()(vi(ro((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=Wn(n);r&&t(a=>{if(a.sessions.has(r))return a;const i=new Map(a.sessions),o=`tab-${a.nextTabId}`,c=mc(o,"Terminal");return i.set(r,pc(c)),{sessions:i,nextTabId:a.nextTabId+1}})},getDirectoryState:n=>{const r=Wn(n);return e().sessions.get(r)},getActiveTab:n=>{const r=Wn(n),a=e().sessions.get(r);if(!a)return;const i=a.activeTabId;return i?a.tabs.find(o=>o.id===i)??a.tabs[0]:a.tabs[0]},createTab:n=>{const r=Wn(n);if(!r)return"tab-invalid";const a=`tab-${e().nextTabId}`;return t(i=>{const o=new Map(i.sessions),c=o.get(r),d=i.nextTabId+1,m=`Terminal ${(c?.tabs.length??0)+1}`,u=mc(a,m);return c?o.set(r,{...c,tabs:[...c.tabs,u]}):o.set(r,pc(u)),{sessions:o,nextTabId:d}}),a},setActiveTab:(n,r)=>{const a=Wn(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);return!c||c.activeTabId===r||Pr(c,r)<0?i:(o.set(a,{...c,activeTabId:r}),{sessions:o})})},setTabLabel:(n,r,a)=>{const i=Wn(n),o=a.trim();o&&t(c=>{const d=new Map(c.sessions),p=d.get(i);if(!p)return c;const m=Pr(p,r);if(m<0||p.tabs[m]?.label===o)return c;const u=[...p.tabs];return u[m]={...u[m],label:o},d.set(i,{...p,tabs:u}),{sessions:d}})},setTabIconKey:(n,r,a)=>{const i=Wn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Pr(d,r);if(p<0)return o;const m=a?.trim()||null;if(d.tabs[p]?.iconKey===m)return o;const u=[...d.tabs];return u[p]={...u[p],iconKey:m},c.set(i,{...d,tabs:u}),{sessions:c}})},closeTab:async(n,r)=>{const a=Wn(n),c=e().sessions.get(a)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(c)try{await Fx(c)}catch{}t(d=>{const p=new Map(d.sessions),m=p.get(a);if(!m)return d;const u=Pr(m,r);if(u<0)return d;const f=m.tabs.filter(x=>x.id!==r),b=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,x])=>!(x.directory===a&&x.tabId===r))),h=Object.keys(b).length!==Object.keys(d.projectActionRuns).length;if(f.length===0){const x=`tab-${d.nextTabId}`,g=mc(x,"Terminal");return p.set(a,pc(g)),{sessions:p,nextTabId:d.nextTabId+1,...h?{projectActionRuns:b}:{}}}let v=m.activeTabId;return m.activeTabId===r&&(v=f[Math.min(u,f.length-1)]?.id??f[0]?.id??null),p.set(a,{...m,tabs:f,activeTabId:v}),{sessions:p,...h?{projectActionRuns:b}:{}}})},setTabSessionId:(n,r,a)=>{const i=Wn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Pr(d,r);if(p<0)return o;const m=d.tabs[p],u=a!==null&&m.terminalSessionId!==a,f=a?"running":m.terminalSessionId?"exited":m.lifecycle,b={...m,terminalSessionId:a,lifecycle:f,isConnecting:!1,...u?{bufferChunks:[],bufferLength:0}:{}},h=[...d.tabs];return h[p]=b,c.set(i,{...d,tabs:h}),{sessions:c}})},setTabLifecycle:(n,r,a)=>{const i=Wn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Pr(d,r);if(p<0)return o;const m=[...d.tabs];return m[p]={...m[p],lifecycle:a,isConnecting:!1},c.set(i,{...d,tabs:m}),{sessions:c}})},setConnecting:(n,r,a)=>{const i=Wn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Pr(d,r);if(p<0)return o;const m=[...d.tabs];return m[p]={...m[p],isConnecting:a},c.set(i,{...d,tabs:m}),{sessions:c}})},appendToBuffer:(n,r,a)=>{if(!a)return;const i=Wn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Pr(d,r);if(p<0)return o;const m=d.tabs[p],u=o.nextChunkId,f={id:u,data:a},b=[...m.bufferChunks,f];let h=m.bufferLength+a.length;for(;h>u1&&b.length>1;){const w=b.shift();if(!w)break;h-=w.data.length}const v=m.previewUrlLocked?null:x1(a)??b1(a),x=!!(v&&v!==m.previewUrl),g=[...d.tabs];return g[p]={...m,bufferChunks:b,bufferLength:h,...x?{previewUrl:v,previewAutoOpened:!1}:null},c.set(i,{...d,tabs:g}),{sessions:c,nextChunkId:u+1}})},setTabPreviewUrl:(n,r,a,i={})=>{const o=Wn(n);t(c=>{const d=new Map(c.sessions),p=d.get(o);if(!p)return c;const m=Pr(p,r);if(m<0)return c;const u=p.tabs[m],f=i.autoOpened??u.previewAutoOpened,b=i.locked??u.previewUrlLocked;if(u.previewUrl===a&&u.previewAutoOpened===f&&u.previewUrlLocked===b)return c;const h=[...p.tabs];return h[m]={...u,previewUrl:a,previewAutoOpened:f,previewUrlLocked:b},d.set(o,{...p,tabs:h}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const a=Wn(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);if(!c)return i;const d=Pr(c,r);if(d<0)return i;const p=c.tabs[d];if(!p.previewUrl||p.previewAutoOpened)return i;const m=[...c.tabs];return m[d]={...p,previewAutoOpened:!0},o.set(a,{...c,tabs:m}),{sessions:o}})},setProjectActionRun:n=>{t(r=>{const a=r.projectActionRuns[n.key];return a&&a.directory===n.directory&&a.actionId===n.actionId&&a.tabId===n.tabId&&a.sessionId===n.sessionId&&a.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(a=>{const i=a.projectActionRuns[n];return!i||i.status===r?a:{projectActionRuns:{...a.projectActionRuns,[n]:{...i,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const a={...r.projectActionRuns};return delete a[n],{projectActionRuns:a}})},clearBuffer:(n,r)=>{const a=Wn(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);if(!c)return i;const d=Pr(c,r);if(d<0)return i;const p=[...c.tabs];return p[d]={...p[d],bufferChunks:[],bufferLength:0},o.set(a,{...c,tabs:p}),{sessions:o}})},removeDirectory:n=>{const r=Wn(n);t(a=>{const i=new Map(a.sessions);i.delete(r);const o=Object.fromEntries(Object.entries(a.projectActionRuns).filter(([,c])=>c.directory!==r));return{sessions:i,projectActionRuns:o}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:m1,storage:kl(()=>Uf()),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(!uc(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let a=0;for(const c of n){if(!Array.isArray(c)||c.length!==2)continue;const[d,p]=c;if(typeof d!="string"||!uc(p))continue;const m=Array.isArray(p.tabs)?p.tabs:[],u=[];for(const h of m){if(!uc(h))continue;const v=typeof h.id=="string"?h.id:null;if(!v)continue;const x=p1(v);x!==null&&(a=Math.max(a,x));const g=typeof h.terminalSessionId=="string"||h.terminalSessionId===null?h.terminalSessionId:null,w=h.lifecycle,y=w==="idle"||w==="running"||w==="exited"?w:g?"running":"idle";u.push({id:v,label:typeof h.label=="string"?h.label:"Terminal",iconKey:typeof h.iconKey=="string"?h.iconKey:null,terminalSessionId:g,lifecycle:y,createdAt:typeof h.createdAt=="number"?h.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(u.length===0)continue;const f=typeof p.activeTabId=="string"?p.activeTabId:null,b=f?u.some(h=>h.id===f):!1;r.set(d,{tabs:u,activeTabId:b?f:u[0].id})}const i=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,o=Math.max(e.nextTabId,i,a+1);return{...e,sessions:r,nextChunkId:1,nextTabId:o,hasHydrated:!0}}})));if(typeof window<"u"&&!tm){tm=!0;const t=ln.persist,e=()=>{ln.getState().hasHydrated||ln.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const sm=(t,e)=>e.updatedAtMs-t.updatedAtMs,Qs=ar((t,e)=>({instances:[],statusesById:{},importCandidates:[],isLoading:!1,isSaving:!1,isImportsLoading:!1,initialized:!1,listenerReady:!1,error:null,load:async()=>{if(!e().isLoading){t({isLoading:!0,error:null});try{const[n,r]=await Promise.all([Vx(),bu()]),a={};for(const i of r.sort(sm))a[i.id]=i;e().listenerReady||await Ux(i=>{t(o=>({statusesById:{...o.statusesById,[i.id]:i}}))}),t({instances:n.instances,statusesById:a,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){t({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){t({isImportsLoading:!0,error:null});try{const n=await _x();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await bu(),r={};for(const a of n.sort(sm))r[a.id]=a;t({statusesById:r})}catch(n){t({error:n instanceof Error?n.message:String(n)})}},setInstances:async n=>{t({isSaving:!0,error:null});try{await zx({instances:n}),t({instances:n,isSaving:!1}),await e().refreshStatuses()}catch(r){throw t({isSaving:!1,error:r instanceof Error?r.message:String(r)}),r}},upsertInstance:async n=>{const r=e().instances,a=r.some(i=>i.id===n.id)?r.map(i=>i.id===n.id?n:i):[n,...r];await e().setInstances(a)},createFromCommand:async(n,r,a)=>{const i=Wx(n,r);a&&a.trim()&&(i.nickname=a.trim()),await e().upsertInstance(i)},removeInstance:async n=>{await xu(n).catch(()=>{});const r=e().instances.filter(a=>a.id!==n);await e().setInstances(r),t(a=>{const i={...a.statusesById};return delete i[n],{statusesById:i}})},connect:async n=>{t({error:null});try{await Bx(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},disconnect:async n=>{t({error:null});try{await xu(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},retry:async n=>{await e().connect(n)},getStatus:n=>e().statusesById[n]||null,clearError:()=>t({error:null})})),Ph=[{key:"play",label:"Play",Icon:"play"},{key:"build",label:"Build",Icon:"hammer"},{key:"lint",label:"Lint",Icon:"checkbox-circle"},{key:"terminal",label:"Terminal",Icon:"terminal-box"},{key:"tools",label:"Tools",Icon:"tools"},{key:"bug",label:"Bug",Icon:"bug"},{key:"flask",label:"Flask",Icon:"flask"},{key:"rocket",label:"Rocket",Icon:"rocket"},{key:"code",label:"Code",Icon:"code"},{key:"server",label:"Server",Icon:"server"},{key:"branch",label:"Branch",Icon:"git-branch"},{key:"search",label:"Search",Icon:"search"},{key:"settings",label:"Settings",Icon:"settings-3"},{key:"brain",label:"Brain",Icon:"brain-ai-3"},{key:"stack",label:"Stack",Icon:"stack"},{key:"robot",label:"Robot",Icon:"robot-2"},{key:"command",label:"Command",Icon:"command"},{key:"file",label:"File",Icon:"file-text"}],Ho=Object.fromEntries(Ph.map(t=>[t.key,t.Icon])),nd="openchamber:project-actions-updated",Ah=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},ea=(t,e)=>`${Ah(t)}::${e}`,y1=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},nm=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},v1=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=nm(e.localPort),r=nm(e.remotePort);if(!n||!r)return null;const a=y1(e.localHost||t.localForward.bindHost||"127.0.0.1"),i=(e.remoteHost||"127.0.0.1").trim(),o=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${o} - ${a}:${n} -> ${i}:${r}`,url:`http://${a}:${n}`}},Dh=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const a=v1(n,r);a&&e.push(a)}return e},w1=(t,e)=>{const n=(t||"").trim();return n&&Dh(e).find(i=>i.id===n)?.url||null},j1=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],N1=["dev","start","preview","serve"];async function S1(t,e,n){if(!t)return null;const r=I1(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const a=P1(n);if(a){const i=await A1(t);return{command:`${i==="npm"?"npm run":i==="yarn"?"yarn":i==="pnpm"?"pnpm":i==="bun"?"bun run --shell=bun":"npm run"} ${a}`,label:`Start (${a})`}}}if(await k1(t)){const a=await C1(),i=typeof a=="number"&&Number.isFinite(a)&&a>0?a:8e3;return{command:`python3 -m http.server ${i}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${i}/`}}return null}async function k1(t){const e=`${t}/index.html`,n=await ul(e);return typeof n=="string"&&n.trim().length>0}async function C1(){try{const t=await fetch("/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 I1(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(N1.some(a=>n.includes(a)))return e}return null}function P1(t){for(const{pattern:e}of j1)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function A1(t){const e=await ul(`${t}/package.json`);if(e)try{const r=JSON.parse(e),a=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(a.startsWith("bun@"))return"bun";if(a.startsWith("pnpm@"))return"pnpm";if(a.startsWith("yarn@"))return"yarn";if(a.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,a]of n){const i=await ul(`${t}/${r}`);if(typeof i=="string"&&i.trim().length>0)return a}return"npm"}async function ul(t){const e=hr()?.files;if(e?.readFile)try{const n=await e.readFile(t,{optional:!0});return typeof n?.content=="string"?n.content:null}catch{return null}try{const n=await fetch(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return n.ok?n.text():null}catch{return null}}async function D1(t){try{const e=await ul(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const T1=t=>new Promise(e=>{window.setTimeout(e,t)}),M1="\x1B",E1=new RegExp(`${M1}\\[[0-9;?]*[ -/]*[@-~]`,"g"),R1=/https?:\/\/[^\s<>'"`]+/gi,cr="__openchamber_auto_discover_preview__",F1=15e3,L1=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},O1=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}},$1=t=>{const n=t.replace(E1,"").match(R1);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const a=[];for(const i of r)try{const o=new URL(i);o.port&&o.port.length>0&&a.push({raw:i,parsed:o})}catch{}if(a.length>0){const i=o=>{const{parsed:c}=o,d=c.hostname.toLowerCase(),p=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=c.pathname||"/",u=m.split("/").filter(Boolean).length,f=m==="/"||m==="",b=!!(c.search||c.hash);let h=0;return p&&(h+=50),f&&(h+=30),h-=Math.min(u*5,20),b&&(h-=10),h};return a.sort((o,c)=>i(c)-i(o)),a[0]?.parsed.origin??a[0]?.raw??null}return r[0]??null},B1=(t,e)=>{const n=t.trim();if(!n)return e;const r=n.split(/\s+/).filter(Boolean);if(r.length>=2){const a=r[0],i=r[1].slice(0,3),o=`${a} ${i}`.trim();return r.length>2||o.length<n.length?`${o}...`:o}return n.length>12?`${n.slice(0,9).trimEnd()}...`:n},rm=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:a=!1})=>{const{t:i}=mt(),{terminal:o,runtime:c}=_n(),{isMobile:d}=an(),p=l.useMemo(()=>yn(),[]),m=Qs(q=>q.instances),u=Qs(q=>q.load),f=Te(q=>q.setBottomTerminalOpen),b=Te(q=>q.setActiveMainTab),h=Te(q=>q.setSettingsPage),v=Te(q=>q.setSettingsDialogOpen),x=Te(q=>q.setSettingsProjectsSelectedId),g=Te(q=>q.openContextPreview),w=ln(q=>q.sessions),y=ln(q=>q.ensureDirectory),k=ln(q=>q.setTabLabel),D=ln(q=>q.setTabIconKey),j=ln(q=>q.setActiveTab),S=ln(q=>q.setConnecting),A=ln(q=>q.setTabSessionId),E=ln(q=>q.setTabPreviewUrl),P=ln(q=>q.projectActionRuns),C=ln(q=>q.setProjectActionRun),N=ln(q=>q.updateProjectActionRunStatus),T=ln(q=>q.removeProjectActionRun),[M,R]=l.useState([]),[O,z]=l.useState(null),[B,$]=l.useState(!1),_=l.useRef({}),Q=l.useRef({}),W=l.useRef({}),ne=l.useRef({}),re=l.useRef(0),ue=t?.id??null,Y=t?.path??"",le=l.useMemo(()=>ue?{id:ue,path:Y}:null,[ue,Y]);l.useEffect(()=>{p&&u().catch(()=>{})},[p,u]);const J=l.useCallback(async q=>{await sr(q)},[]),L=l.useCallback(async()=>{if(!le)return;const q=re.current+1;re.current=q,$(!0);try{const Ie=await Yc(le);if(re.current!==q)return;const Le=Ie.actions;R(Le),z(Pe=>Pe===cr||Pe&&Le.some(he=>he.id===Pe)?Pe:null)}catch{if(re.current!==q)return}finally{re.current===q&&$(!1)}},[le]),V=l.useMemo(()=>Ah(e||le?.path||""),[e,le?.path]),K=l.useMemo(()=>O?M.find(q=>q.id===O)??null:null,[M,O]),X=l.useMemo(()=>({id:cr,name:i("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[i]),U=!d,ae=l.useMemo(()=>U?[X,...M]:M,[M,X,U]);l.useEffect(()=>{L()},[L]),l.useEffect(()=>{if(typeof window>"u")return;const q=Ie=>{const Le=Ie.detail;ue&&(Le?.projectId&&Le.projectId!==ue||L())};return window.addEventListener(nd,q),()=>{window.removeEventListener(nd,q)}},[L,ue]),l.useEffect(()=>{O&&(O===cr&&U||M.some(q=>q.id===O)||z(null))},[M,U,O]),l.useEffect(()=>{for(const[q,Ie]of Object.entries(P)){const Pe=w.get(Ie.directory)?.tabs.find(he=>he.id===Ie.tabId);(!Pe||Pe.terminalSessionId!==Ie.sessionId)&&T(q)}},[P,T,w]),l.useEffect(()=>{for(const[q,Ie]of Object.entries(P)){const Le=Q.current[q]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};Q.current[q]=Le;const Pe=ae.find(pe=>pe.id===Ie.actionId);if(!Pe)continue;const F=w.get(Ie.directory)?.tabs.find(pe=>pe.id===Ie.tabId);if(!F||!Array.isArray(F.bufferChunks)||F.bufferChunks.length===0)continue;const ee=F.bufferChunks.filter(pe=>Le.lastSeenChunkId===null?!0:pe.id>Le.lastSeenChunkId);if(ee.length===0)continue;const Ce=ee.map(pe=>pe.data).join(""),Fe=`${Le.tail}${Ce}`,we=!Le.openedUrl&&Pe.autoOpenUrl===!0?$1(Fe):null,Qe=ee[ee.length-1]?.id??Le.lastSeenChunkId;if(Le.lastSeenChunkId=Qe,Le.tail=Fe.slice(-512),we)if(Le.openedUrl=!0,Le.openInPreview){const pe=P[q];pe&&(E(pe.directory,pe.tabId,we,{locked:!1,autoOpened:!1}),pe.status==="waiting-for-preview"&&N(q,"running"),window.clearTimeout(ne.current[q]),delete ne.current[q],g(pe.directory,we))}else J(we),G.success(i("projectActions.toast.openedUrlFromOutput"));Q.current[q]=Le}for(const q of Object.keys(Q.current))P[q]||(delete Q.current[q],window.clearTimeout(ne.current[q]),delete ne.current[q])},[ae,g,J,P,E,i,w,N]);const ve=l.useCallback(async(q,Ie={})=>{if(!V)throw new Error(i("projectActions.error.noActiveDirectory"));const Le=ea(V,q.id);y(V);const Pe=ln.getState(),he=Pe.getDirectoryState(V);let F=_.current[Le]||null;const ee=F?!!he?.tabs.some(we=>we.id===F):!1;(!F||!ee)&&(F=Pe.createTab(V),_.current[Le]=F),k(V,F,`Action: ${q.name}`),D(V,F,q.icon||"play"),Ie.revealTerminal!==!1&&(j(V,F),f(!0),b("terminal"));const Fe=ln.getState().getDirectoryState(V)?.tabs.find(we=>we.id===F);return{key:Le,tabId:F,sessionId:Fe?.terminalSessionId??null}},[y,V,b,j,f,D,k,i]),ie=l.useCallback(async q=>{if(c.isVSCode||!a&&d)return;if(!V){G.error(i("projectActions.error.noActiveDirectoryForAction"));return}const Ie=ea(V,q.id),Le=P[Ie];if(!(Le&&Le.status==="running"))try{const Pe=q.id===cr?await(async()=>{const[Re,de]=await Promise.all([Yc({id:le?.id??"",path:V}),D1(V)]),He=await S1(V,Re.actions,de);if(!He)throw new Error(i("contextPanel.preview.noDevServer"));return{id:cr,name:i("projectActions.actions.autoDiscover"),command:He.command,icon:"search",autoOpenUrl:!0,openUrl:He.previewUrlHint||""}})():q,he=Pe.autoOpenUrl===!0&&(Pe.openUrl||"").trim().length>0,{key:F,tabId:ee,sessionId:Ce}=await ve(Pe,{revealTerminal:!he&&q.id!==cr});let Fe=Ce,we=!1;if(!Fe){S(V,ee,!0);try{Fe=(await o.createSession({cwd:V})).sessionId,we=!0,A(V,ee,Fe)}finally{S(V,ee,!1)}}if(!Fe)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));we&&await T1(350),Pe.id===cr&&(W.current[F]?.(),S(V,ee,!0),W.current[F]=Lx(Fe,Re=>{Re.type==="data"&&typeof Re.data=="string"&&Re.data.length>0&&ln.getState().appendToBuffer(V,ee,Re.data),Re.type==="exit"&&(ln.getState().setTabLifecycle(V,ee,"exited"),ln.getState().setConnecting(V,ee,!1),ln.getState().removeProjectActionRun(F),delete Q.current[F],W.current[F]?.(),delete W.current[F],window.clearTimeout(ne.current[F]),delete ne.current[F])},()=>{ln.getState().setConnecting(V,ee,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const Qe=Pe.autoOpenUrl===!0&&p&&(Pe.desktopOpenSshForward||"").trim().length>0,pe=Pe.autoOpenUrl?O1(Pe.openUrl):null,Oe=Pe.autoOpenUrl&&p?w1(Pe.desktopOpenSshForward,m):null;C({key:F,directory:V,actionId:Pe.id,tabId:ee,sessionId:Fe,status:Pe.id===cr&&!pe?"waiting-for-preview":"running"}),window.clearTimeout(ne.current[F]),delete ne.current[F],Pe.id===cr&&!pe&&(ne.current[F]=window.setTimeout(()=>{ln.getState().updateProjectActionRunStatus(F,"running"),delete ne.current[F]},F1)),Oe?(E(V,ee,null,{locked:!0}),J(Oe),G.success(i("projectActions.toast.openedForwardedUrl"))):pe?(E(V,ee,pe,{locked:!0,autoOpened:!0}),g(V,pe),G.success(i("projectActions.toast.openedActionUrl"))):he?(E(V,ee,null,{locked:!0}),G.error(i("projectActions.error.invalidCustomUrlFormat"))):Qe?(E(V,ee,null,{locked:!0}),G.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):E(V,ee,null,{locked:!1,autoOpened:!1}),Q.current[F]={lastSeenChunkId:null,openedUrl:!!Oe||!!pe||he,tail:"",openInPreview:Pe.id===cr};const nt=L1(Pe.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
+
`));await o.sendInput(Fe,`${nt}\r`)}catch(Pe){T(Ie),delete Q.current[Ie],W.current[Ie]?.(),delete W.current[Ie],window.clearTimeout(ne.current[Ie]),delete ne.current[Ie],G.error(Pe instanceof Error?Pe.message:i("projectActions.error.failedToRunAction"))}},[m,ve,a,d,p,V,J,g,P,c.isVSCode,T,S,C,E,A,le?.id,i,o]),fe=l.useCallback(async q=>{const Ie=ea(V,q.id),Le=P[Ie];if(!Le)return;N(Ie,"stopping");try{await o.sendInput(Le.sessionId,"")}catch{}if(await new Promise(F=>{window.setTimeout(F,1e3)}),ln.getState().getDirectoryState(Le.directory)?.tabs.find(F=>F.id===Le.tabId)?.terminalSessionId===Le.sessionId){if(typeof o.forceKill=="function")try{await o.forceKill({sessionId:Le.sessionId})}catch{}else try{await o.close(Le.sessionId)}catch{}A(Le.directory,Le.tabId,null)}T(Ie),delete Q.current[Ie],W.current[Ie]?.(),delete W.current[Ie],window.clearTimeout(ne.current[Ie]),delete ne.current[Ie]},[V,P,T,A,o,N]),H=l.useCallback(()=>{const q=K??ae[0];if(!q)return;const Ie=ea(V,q.id),Le=P[Ie];if(Le?.status!=="stopping"){if(Le){fe(q);return}ie(q)}},[ae,V,ie,P,K,fe]),ce=l.useCallback((q,Ie=!1)=>{if(z(q.id),!Ie){ie(q);return}const Le=ea(V,q.id),Pe=P[Le];if(Pe?.status!=="stopping"){if(Pe){fe(q);return}ie(q)}},[V,ie,P,fe]),se=l.useCallback(()=>{le?.id&&(x(le.id),h("projects"),v(!0))},[v,h,x,le?.id]);if(c.isVSCode||!a&&d||!le||!V)return null;const oe=K??ae[0]??null;if(!oe)return null;const te=oe.icon||"play",ke=oe.id===cr?"search":Ho[te]||"play",Ne=B1(oe.name,i("projectActions.label.fallbackAction")),je=ea(V,oe.id),Se=P[je],De=Se?.status==="stopping",ye=Se?.status==="waiting-for-preview",ge=Se?w.get(Se.directory)?.tabs.find(q=>q.id===Se.tabId)?.previewUrl??null:null,Me=!!(Se&&ge),Ue=()=>{!Se||!ge||g(Se.directory,ge)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:B||De,className:me("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:H,"aria-label":Se?i("projectActions.actions.stopNamedAria",{name:oe.name}):i("projectActions.actions.runNamedAria",{name:oe.name}),children:De||ye?s.jsx(I,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):Se?s.jsx(I,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(I,{name:ke,className:"h-5 w-5"})}),Me?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.openPreview"),onClick:Ue,children:s.jsx(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(At,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(_s,{children:[s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(zs,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Vt,{className:"flex items-center gap-2",onClick:se,children:[s.jsx(I,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Tn,{}),ae.map(q=>{const Ie=q.icon||"play",Le=q.id===cr?"search":Ho[Ie]||"play",Pe=ea(V,q.id),he=P[Pe],F=!!he,ee=he?.status==="stopping";return s.jsxs(Vt,{className:"flex items-center gap-2",onClick:()=>{ce(q,!0)},children:[s.jsx(I,{name:Le,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q.name}),ee||he?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):F?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},q.id)})]})]})]}):s.jsxs("div",{className:me("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.jsxs("button",{type:"button",onClick:H,disabled:B||De,className:me("inline-flex h-full items-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 justify-center px-0":"gap-2 px-3","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":Se?i("projectActions.actions.stopNamedAria",{name:oe.name}):i("projectActions.actions.runNamedAria",{name:oe.name}),children:[s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:De||ye?s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):Se?s.jsx(I,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(I,{name:ke,className:"h-4 w-4"})}),r?null:s.jsx("span",{className:"header-open-label whitespace-nowrap",children:Ne})]}),Me?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ue,className:me(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.openPreview"),children:s.jsx(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(At,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(_s,{children:[s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:me(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(zs,{align:"center",className:"w-52 max-h-[70vh] overflow-y-auto",style:{translate:"-30px 0"},children:[s.jsxs(Vt,{className:"flex items-center gap-2",onClick:se,children:[s.jsx(I,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Tn,{}),ae.map(q=>{const Ie=q.icon||"play",Le=q.id===cr?"search":Ho[Ie]||"play",Pe=ea(V,q.id),he=P[Pe],F=!!he,ee=he?.status==="stopping";return s.jsxs(Vt,{className:"flex items-center gap-2",onClick:()=>{ce(q)},children:[s.jsx(I,{name:Le,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q.name}),ee||he?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):F?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},q.id)})]})]})]})},Fl="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",z1="app-region-no-drag inline-flex h-9 w-9 items-center justify-center gap-2 p-2 rounded-md typography-ui-label font-medium text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:text-foreground hover:bg-interactive-hover transition-colors",Ci=l.memo(function(e){const n=at.c(13),{visible:r,title:a,ariaLabel:i,onClick:o,className:c,Icon:d,iconClassName:p}=e;if(!(r===void 0?!0:r))return null;const u=c??Fl,f=p??"h-[18px] w-[18px]";let b;n[0]!==d||n[1]!==f?(b=s.jsx(I,{name:d,className:f}),n[0]=d,n[1]=f,n[2]=b):b=n[2];let h;n[3]!==i||n[4]!==o||n[5]!==u||n[6]!==b?(h=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,"aria-label":i,className:u,children:b})}),n[3]=i,n[4]=o,n[5]=u,n[6]=b,n[7]=h):h=n[7];let v;n[8]!==a?(v=s.jsx(At,{children:s.jsx("p",{children:a})}),n[8]=a,n[9]=v):v=n[9];let x;return n[10]!==h||n[11]!==v?(x=s.jsxs(It,{children:[h,v]}),n[10]=h,n[11]=v,n[12]=x):x=n[12],x}),_1=l.memo(function(e){const n=at.c(42),{isMobile:r,githubAuthStatus:a,githubAccounts:i,githubAvatarUrl:o,githubLogin:c,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:p}=e,{t:m}=mt();if(!a?.connected||r)return null;if(i.length>1){let h;n[0]===Symbol.for("react.memo_cache_sentinel")?(h=me(Fl,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=h):h=n[0];let v;n[1]!==c||n[2]!==m?(v=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[1]=c,n[2]=m,n[3]=v):v=n[3];let x;n[4]!==o||n[5]!==c||n[6]!==m?(x=o?s.jsx("img",{src:o,alt:c?m("header.github.avatarWithLogin",{login:c}):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]=o,n[5]=c,n[6]=m,n[7]=x):x=n[7];let g;n[8]!==d||n[9]!==v||n[10]!==x?(g=s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:h,title:v,disabled:d,children:x})}),n[8]=d,n[9]=v,n[10]=x,n[11]=g):g=n[11];let w;n[12]!==m?(w=m("header.github.accountsTitle"),n[12]=m,n[13]=w):w=n[13];let y;n[14]!==w?(y=s.jsx(zi,{className:"typography-ui-header font-semibold text-foreground",children:w}),n[14]=w,n[15]=y):y=n[15];let k;n[16]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(Tn,{}),n[16]=k):k=n[16];let D;if(n[17]!==i||n[18]!==p||n[19]!==d||n[20]!==m){let A;n[22]!==p||n[23]!==d||n[24]!==m?(A=E=>{const P=E.user,C=!!E.current;return s.jsxs(Vt,{className:"gap-2",disabled:C||d,onSelect:()=>{C||p(E.id)},children:[P?.avatarUrl?s.jsx("img",{src:P.avatarUrl,alt:P.login?m("header.github.avatarWithLogin",{login:P.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:P?.name?.trim()||P?.login||"GitHub"}),P?.login?s.jsx("span",{className:"truncate typography-micro font-mono text-muted-foreground",children:P.login}):null]}),C?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]},E.id)},n[22]=p,n[23]=d,n[24]=m,n[25]=A):A=n[25],D=i.map(A),n[17]=i,n[18]=p,n[19]=d,n[20]=m,n[21]=D}else D=n[21];let j;n[26]!==y||n[27]!==D?(j=s.jsxs(zs,{align:"end",className:"w-64",children:[y,k,D]}),n[26]=y,n[27]=D,n[28]=j):j=n[28];let S;return n[29]!==g||n[30]!==j?(S=s.jsxs(_s,{children:[g,j]}),n[29]=g,n[30]=j,n[31]=S):S=n[31],S}let u;n[32]!==c||n[33]!==m?(u=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[32]=c,n[33]=m,n[34]=u):u=n[34];let f;n[35]!==o||n[36]!==c||n[37]!==m?(f=o?s.jsx("img",{src:o,alt:c?m("header.github.avatarWithLogin",{login:c}):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]=o,n[36]=c,n[37]=m,n[38]=f):f=n[38];let b;return n[39]!==u||n[40]!==f?(b=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:u,children:f}),n[39]=u,n[40]=f,n[41]=b):b=n[41],b}),V1=l.memo(function(e){const n=at.c(76),{isDesktopApp:r,currentInstanceLabel:a,compactCurrentInstanceLabel:i,isDesktopServicesOpen:o,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,desktopServicesTab:p,setDesktopServicesTab:m,quotaResultsLength:u,fetchAllQuotas:f,servicesTabItems:b,quotaLastUpdated:h,quotaDisplayMode:v,quotaDisplayTabItems:x,handleDisplayModeChange:g,handleUsageRefresh:w,isQuotaLoading:y,isUsageRefreshSpinning:k,hasRateLimits:D,rateLimitGroups:j,expandedFamilies:S,toggleFamilyExpanded:A,shortcutLabel:E,showDevShutdown:P,isDevShutdownInFlight:C,onDevShutdown:N}=e,{t:T}=mt();let M;n[0]!==p||n[1]!==f||n[2]!==u||n[3]!==d||n[4]!==c?(M=X=>{c(X),X&&(d(),p==="usage"&&u===0&&f())},n[0]=p,n[1]=f,n[2]=u,n[3]=d,n[4]=c,n[5]=M):M=n[5];let R;n[6]!==a||n[7]!==r||n[8]!==T?(R=r?T("header.services.openWithCurrent",{current:a}):T("header.services.open"),n[6]=a,n[7]=r,n[8]=T,n[9]=R):R=n[9];const O=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let z;n[10]!==O?(z=me(Fl,O),n[10]=O,n[11]=z):z=n[11];let B;n[12]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(I,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=B):B=n[12];let $;n[13]!==i||n[14]!==r?($=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[13]=i,n[14]=r,n[15]=$):$=n[15];let _;n[16]!==R||n[17]!==z||n[18]!==$?(_=s.jsx(Pt,{asChild:!0,children:s.jsx(Bs,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":R,className:z,children:[B,$]})})}),n[16]=R,n[17]=z,n[18]=$,n[19]=_):_=n[19];let Q;n[20]!==a||n[21]!==r||n[22]!==E||n[23]!==T?(Q=r?T("header.services.tooltip.currentInstanceWithShortcuts",{current:a,toggle:E("toggle_services_menu"),nextTab:E("cycle_services_tab")}):T("header.services.tooltip.servicesWithShortcuts",{toggle:E("toggle_services_menu"),nextTab:E("cycle_services_tab")}),n[20]=a,n[21]=r,n[22]=E,n[23]=T,n[24]=Q):Q=n[24];let W;n[25]!==Q?(W=s.jsx(At,{children:s.jsx("p",{children:Q})}),n[25]=Q,n[26]=W):W=n[26];let ne;n[27]!==_||n[28]!==W?(ne=s.jsxs(It,{children:[_,W]}),n[27]=_,n[28]=W,n[29]=ne):ne=n[29];let re;n[30]!==f||n[31]!==u||n[32]!==m?(re=X=>{const U=X;m(U),U==="usage"&&u===0&&f()},n[30]=f,n[31]=u,n[32]=m,n[33]=re):re=n[33];let ue;n[34]!==p||n[35]!==b||n[36]!==re?(ue=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(Er,{items:b,activeId:p,onSelect:re,layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),n[34]=p,n[35]=b,n[36]=re,n[37]=ue):ue=n[37];let Y;n[38]!==p||n[39]!==r||n[40]!==o||n[41]!==c?(Y=r&&p==="instance"?s.jsx(Kx,{embedded:!0,open:o&&p==="instance",onOpenChange:K1,onHostSwitched:()=>c(!1)}):null,n[38]=p,n[39]=r,n[40]=o,n[41]=c,n[42]=Y):Y=n[42];let le;n[43]!==p||n[44]!==o?(le=p==="mcp"?s.jsx(Ch,{active:o&&p==="mcp"}):null,n[43]=p,n[44]=o,n[45]=le):le=n[45];let J;n[46]!==p||n[47]!==S||n[48]!==g||n[49]!==w||n[50]!==D||n[51]!==y||n[52]!==k||n[53]!==v||n[54]!==x||n[55]!==h||n[56]!==j||n[57]!==T||n[58]!==A?(J=p==="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:T("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Th(h)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(Er,{items:x,activeId:v,onSelect:X=>{g(X)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:me("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:y||k,"aria-label":T("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:me("h-4 w-4",k&&"animate-spin")})})]})]}),D?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:T("header.services.noRateLimits")})}),s.jsx("div",{className:"py-2",children:j.map((X,U)=>{const ae=S[X.providerId]??[];return s.jsxs(l.Fragment,{children:[U>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(jn,{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??T("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[X.entries.map(ve=>{const[ie,fe]=ve,H=v==="remaining"?fe.remainingPercent:fe.usedPercent,ce=eo(fe.usedPercent,fe.resetAt,fe.windowSeconds,ie),se=ce?.dailyAllocationPercent!=null?v==="remaining"?100-Wr(ce.elapsedRatio):Wr(ce.elapsedRatio):null,oe=Zi(fe.valueLabel,H),te=Kd(fe.resetAt,fe.resetAfterFormatted??fe.resetAtFormatted);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:Hd(ie)}),te?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:te}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:oe==="-"?"":oe})]}),s.jsx(so,{percent:H,tonePercent:fe.usedPercent,className:"h-1.5",expectedMarkerPercent:se}),ce?s.jsx(no,{paceInfo:ce,compact:!0}):null]},`${X.providerId}-${ie}`)}),X.modelFamilies&&X.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:X.modelFamilies.map(ve=>{const ie=ve.familyId??"other",fe=ae.includes(ie);return s.jsxs(gr,{open:fe,onOpenChange:()=>A(X.providerId,ie),children:[s.jsxs(kr,{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:ve.familyLabel}),fe?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(xr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:ve.models.map(H=>{const[ce,se]=H,oe=v==="remaining"?se.remainingPercent:se.usedPercent,te=eo(se.usedPercent,se.resetAt,se.windowSeconds),ke=te?.dailyAllocationPercent!=null?v==="remaining"?100-Wr(te.elapsedRatio):Wr(te.elapsedRatio):null,Ne=Zi(se.valueLabel,oe);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:cl(ce)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:Ne==="-"?"":Ne})]}),s.jsx(so,{percent:oe,tonePercent:se.usedPercent,className:"h-1.5",expectedMarkerPercent:ke}),te?s.jsx(no,{paceInfo:te,compact:!0}):null]},`${X.providerId}-${ce}`)})})})]},ie)})}):null]})]},X.providerId)})})]}):null,n[46]=p,n[47]=S,n[48]=g,n[49]=w,n[50]=D,n[51]=y,n[52]=k,n[53]=v,n[54]=x,n[55]=h,n[56]=j,n[57]=T,n[58]=A,n[59]=J):J=n[59];let L;n[60]!==C||n[61]!==N||n[62]!==P||n[63]!==T?(L=P?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}),s.jsx("div",{className:"px-2 pb-2",children:s.jsx(Vt,{disabled:C,onSelect:()=>{N()},children:T("header.services.shutdownDev")})})]}):null,n[60]=C,n[61]=N,n[62]=P,n[63]=T,n[64]=L):L=n[64];let V;n[65]!==ue||n[66]!==Y||n[67]!==le||n[68]!==J||n[69]!==L?(V=s.jsxs(zs,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[ue,Y,le,J,L]}),n[65]=ue,n[66]=Y,n[67]=le,n[68]=J,n[69]=L,n[70]=V):V=n[70];let K;return n[71]!==o||n[72]!==M||n[73]!==ne||n[74]!==V?(K=s.jsxs(_s,{open:o,onOpenChange:M,children:[ne,V]}),n[71]=o,n[72]=M,n[73]=ne,n[74]=V,n[75]=K):K=n[75],K}),U1=(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??""),W1=t=>{const e=t.trim();if(!e)return"";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],a=n[1].slice(0,3),i=`${r} ${a}`.trim();return n.length>2||i.length<e.length?`${i}...`:i}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},Th=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},dr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},So=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,am=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r,desktopRightSidebarActionsHost:a=null})=>{const{t:i}=mt(),o=Te(Be=>Be.setSessionSwitcherOpen),c=Te(Be=>Be.toggleSidebar),d=Te(Be=>Be.isSidebarOpen),p=Te(Be=>Be.isRightSidebarOpen),m=Te(Be=>Be.toggleBottomTerminal),u=Te(Be=>Be.toggleRightSidebar),f=Te(Be=>Be.openContextOverview),b=Te(Be=>Be.openContextPlan),h=Te(Be=>Be.openContextBrowser),v=Te(Be=>Be.closeContextPanel),x=Te(Be=>Be.contextPanelByDirectory),g=Te(Be=>Be.activeMainTab),w=Te(Be=>Be.setActiveMainTab),y=Te(Be=>Be.shortcutOverrides),k=gt(Be=>Be.getCurrentModel),D=_n(),[j,S]=l.useState(!1),A=_t(Be=>Be.getContextUsage),E=_t(Be=>Be.openNewSessionDraft),P=_t(Be=>!!Be.newSessionDraft?.open),C=_t(Be=>Be.currentSessionId),N=Hx(C??""),T=Wf(C??null),M=Ia(Be=>Be.activeSessions),R=Dd(),O=Ls(Be=>Be.activeProjectId?Be.projects.find(Et=>Et.id===Be.activeProjectId)??null:null),z=l.useMemo(()=>{if(!O)return null;const Be=O.label?.trim();if(Be)return Be;const Et=O.path.split(/[\\/]/).filter(Boolean);return Et[Et.length-1]??null},[O]),B=$s(Be=>Be.results),$=$s(Be=>Be.fetchAllQuotas),_=$s(Be=>Be.isLoading),Q=$s(Be=>Be.lastUpdated),W=$s(Be=>Be.displayMode),ne=$s(Be=>Be.dropdownProviderIds),re=$s(Be=>Be.loadSettings),ue=$s(Be=>Be.setDisplayMode),{isMobile:Y}=an(),le=Hn(Be=>Be.status),J=Hn(Be=>Be.setStatus),L=l.useRef(null),[V,K]=l.useState(()=>typeof window>"u"?!1:yn()),X=l.useMemo(()=>Td(),[]),U=Cl(),[ae,ve]=l.useState(!1),ie=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),fe=l.useMemo(()=>{if(typeof window>"u")return null;const Be=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Be=="number"&&Number.isFinite(Be)&&Be>0)return Be;if(typeof navigator>"u")return null;const Et=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Et)return null;const rs=Number.parseInt(Et[1],10),gs=Number.parseInt(Et[2],10);return Number.isNaN(rs)?null:rs===10?gs:rs},[]);ze.useEffect(()=>{typeof window>"u"||K(yn())},[]);const H=k(),ce=H&&typeof H.limit=="object"&&H.limit!==null?H.limit:null,se=ce&&typeof ce.context=="number"?ce.context:0,oe=ce&&typeof ce.output=="number"?ce.output:0,te=A(se,oe),[ke,Ne]=l.useState(null),je=!C||N;ze.useEffect(()=>{if(!C){Ne(Be=>Be===null?Be:null);return}if(te&&te.totalTokens>0){Ne(Be=>U1(Be,te)?Be:te);return}je&&Ne(Be=>Be===null?Be:null)},[te,C,je]);const Se=Te(Be=>Be.isSessionSwitcherOpen),De=le?.connected?le.user?.avatarUrl??null:null,ye=le?.connected?le.user?.login??null:null,ge=le?.accounts??[],[Me,Ue]=l.useState(!1),[q,Ie]=l.useState(!1),[Le,Pe]=l.useState(!1),[he,F]=l.useState(!1),[ee,Ce]=l.useState("Local"),Fe=l.useMemo(()=>W1(ee),[ee]),[we,Qe]=l.useState(V?"instance":"usage"),[pe,Oe]=l.useState("usage");ze.useEffect(()=>{!V&&we==="instance"&&Qe("usage")},[we,V]);const nt=l.useMemo(()=>un(),[]),Re=l.useMemo(()=>Y?typeof t=="function"?!!n:Se:d,[Y,Se,d,n,t]),de=!nt&&g==="chat"&&!!ke&&ke.totalTokens>0,He=ke&&ke.contextLimit>0?Math.min(999,ke.totalTokens/ke.contextLimit*100):0,st=l.useCallback(async()=>{if(!(typeof window>"u"||!V))try{const Be=await Gx(),Et=window.location.href,rs=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin;if(yu(Et,rs)){Ce("Local");return}const gs=Be.hosts.find(Ys=>yu(Et,Ys.url));if(gs?.label?.trim()){Ce(qx(gs.label.trim()));return}Ce("Instance")}catch{Ce("Local")}},[V]);ze.useEffect(()=>{st()},[st]),Sh();const qe=$s(Be=>Be.selectedModels),et=$s(Be=>Be.expandedFamilies),rt=$s(Be=>Be.toggleFamilyExpanded),xe=l.useMemo(()=>{const Be=[];for(const Et of Fr){if(!ne.includes(Et.id))continue;const rs=B.find(qs=>qs.providerId===Et.id),gs=rs?.usage?.windows??{},Ys=rs?.usage?.models,Gs=Object.entries(gs),Is={providerId:Et.id,providerName:Et.name,entries:Gs,error:rs&&!rs.ok&&rs.configured?rs.error:void 0};if(Ys&&Object.keys(Ys).length>0){const qs=qe[Et.id]??[],dn=qs.length>0,ir=Bv(Ys,Et.id),Ln=jh(Et.id),Gn=Nh(Ln);Is.modelFamilies=[];for(const En of Gn){const qn=ir.get(En.id)??[];if(qn.length===0)continue;const pn=dn?qn.filter(In=>qs.includes(In)):qn;if(pn.length===0)continue;const Yn=[];for(const In of pn){const Rr=Ys[In];if(Rr?.windows){const or=Object.entries(Rr.windows);or.length>0&&Yn.push([In,or[0][1]])}}Yn.length>0&&Is.modelFamilies.push({familyId:En.id,familyLabel:En.label,models:Yn})}const Or=ir.get(null)??[],Ir=dn?Or.filter(En=>qs.includes(En)):Or;if(Ir.length>0){const En=[];for(const qn of Ir){const pn=Ys[qn];if(pn?.windows){const Yn=Object.entries(pn.windows);Yn.length>0&&En.push([qn,Yn[0][1]])}}En.length>0&&Is.modelFamilies.push({familyId:null,familyLabel:i("header.services.modelFamily.other"),models:En})}}(Gs.length>0||Is.modelFamilies&&Is.modelFamilies.length>0||Is.error)&&Be.push(Is)}return Be},[ne,B,qe,i]),Ye=xe.length>0;l.useEffect(()=>{re()},[re]);const _e=l.useCallback(async Be=>{ue(Be);try{await Ms({usageDisplayMode:Be})}catch(Et){console.warn("Failed to update usage display mode:",Et)}},[ue]),We=l.useCallback(()=>{if(he)return;F(!0);const Be=new Promise(Et=>setTimeout(Et,500));Promise.all([$(),Be]).finally(()=>{F(!1)})},[$,he]),lt=l.useMemo(()=>C?R.find(Be=>Be.id===C)??M.find(Be=>Be.id===C)??T??Yx().find(Be=>Be.id===C)??null:null,[C,T,M,R]),Je=l.useRef(null),[Ve,yt]=l.useState(0);l.useEffect(()=>{if(!C){Je.current&&(Je.current=null,yt(gs=>gs+1));return}if(lt){Je.current={sessionId:C,session:lt,expiresAt:Date.now()+2e3};return}const Be=Je.current;if(!Be||Be.sessionId!==C)return;const Et=Be.expiresAt-Date.now();if(Et<=0){Je.current=null,yt(gs=>gs+1);return}const rs=window.setTimeout(()=>{Je.current?.sessionId===C&&(Je.current=null),yt(gs=>gs+1)},Et);return()=>{window.clearTimeout(rs)}},[C,lt]);const $t=(()=>{if(lt)return lt;if(!C)return null;const Be=Je.current;return Be&&Be.sessionId===C&&Be.expiresAt>Date.now()?Be.session:null})(),Gt=_t(Be=>C?Be.worktreeMetadata.get(C)?.path??"":""),ss=_t(Be=>C?Be.worktreeMetadata.get(C)?.branch?.trim()??null:null),wt=Kf(Be=>C?Be.getAttachment(C):void 0),Dt=l.useMemo(()=>wt?Jx(wt):null,[wt]),Xt=l.useMemo(()=>wt?wt.legacy?"legacy":wt.degraded?"degraded":wt.worktreeStatus==="missing"?"missing":wt.worktreeStatus==="invalid"?"invalid":wt.attentionReason?"attention":null:null,[wt]),Yt=l.useMemo(()=>dr(Gt||""),[Gt]),ts=l.useMemo(()=>{const Be=typeof $t?.directory=="string"?$t.directory:"";return dr(Be||"")},[$t?.directory]),dt=_t(Be=>Be.newSessionDraft?.open?dr(Be.newSessionDraft.bootstrapPendingDirectory??Be.newSessionDraft.directoryOverride??""):""),Rt=l.useMemo(()=>Yt||ts||dt,[dt,ts,Yt]),is=_t(Be=>{const Et=dr(Yt||ts||"");if(!Et)return null;for(const rs of Be.availableWorktreesByProject.values()){const Ys=rs.find(Gs=>dr(Gs.path)===Et)?.branch?.trim();if(Ys)return Ys}return null}),ps=Qx(Rt||null)||ss||is,ws=l.useMemo(()=>{if(!C)return z??"OpenChamber";const Be=$t?.title?.trim();return Be&&Be.length>0?Be:"Untitled Session"},[z,$t?.title,C]),qt=l.useMemo(()=>Hf($t?.summary),[$t?.summary]),Ge=l.useMemo(()=>qt||{additions:0,deletions:0},[qt]),St=Ge.additions>0||Ge.deletions>0,Mt=l.useMemo(()=>dr(Rt||O?.path||""),[O?.path,Rt]),Nt=l.useMemo(()=>O?{id:O.id,path:O.path}:null,[O]),Kt=l.useRef(null);l.useEffect(()=>{!Nt||!Mt||(Kt.current={projectRef:Nt,directory:Mt})},[Mt,Nt]);const ns=l.useMemo(()=>Nt&&Mt?{projectRef:Nt,directory:Mt}:Kt.current,[Mt,Nt]),js=Md(Be=>Be.planModeEnabled),ls=_t(Be=>Be.isSessionPlanAvailable),ks=js&&C?ls(C):!1,Os=ks,xt=l.useRef("");l.useEffect(()=>{if(!js){Te.getState().activeMainTab==="plan"&&Te.getState().setActiveMainTab("chat");return}if(!C)return;const Be=`${C||"none"}:${ts||"none"}:${$t?.time?.created||0}:${$t?.slug||"none"}`;xt.current!==Be&&(xt.current=Be),!ks&&Te.getState().activeMainTab==="plan"&&Te.getState().setActiveMainTab("chat")},[js,ks,$t?.slug,$t?.time?.created,C,ts]);const cs=l.useCallback(async Be=>{if(!(!Be||Me)){Ue(!0);try{const Et=D.github?await D.github.authActivate(Be):await(async()=>{const rs=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:Be})}),gs=await rs.json().catch(()=>null);if(!rs.ok||!gs)throw new Error(gs?.error||rs.statusText);return gs})();J(Et)}catch(Et){console.error("Failed to switch GitHub account:",Et)}finally{Ue(!1)}}},[Me,D.github,J]),jt=l.useCallback(()=>{if(typeof document>"u")return;const Be=document.activeElement;if(!Be)return;const Et=Be.tagName;(Et==="INPUT"||Et==="TEXTAREA"||Et==="SELECT"||Be.isContentEditable)&&Be.blur()},[]),Tt=l.useCallback(()=>{if(Y){jt(),o(!Se);return}c()},[jt,Y,Se,o,c]),Z=l.useCallback(()=>{w("chat"),o(!1),E()},[E,w,o]),ft=l.useCallback(()=>{al("desktop_open_draft_mini_chat_window",{directory:dr(Rt||O?.path||""),projectId:O?.id??null}).catch(Be=>{console.warn("[header] failed to open draft mini chat window",Be)})},[O?.id,O?.path,Rt]),kt=l.useCallback(()=>{if(P){ft();return}C&&al("desktop_open_session_mini_chat_window",{sessionId:C,directory:dr(Rt||O?.path||"")}).catch(Be=>{console.warn("[header] failed to open session mini chat window",Be)})},[O?.path,C,ft,P,Rt]),Ht=l.useCallback(()=>{const Be=dr(Rt||"");if(!Be)return;const Et=x[Be];if(So(Et)==="context"){v(Be);return}f(Be)},[v,x,f,Rt]),Ns=l.useMemo(()=>{const Be=dr(Rt||"");if(!Be)return!1;const Et=x[Be];return So(Et)==="context"},[x,Rt]),Cs=l.useCallback(()=>{const Be=dr(Rt||"");if(!Be)return;const Et=x[Be];if(So(Et)==="plan"){v(Be);return}b(Be)},[v,x,b,Rt]),Ke=l.useCallback(()=>{const Be=dr(Rt||"");Be&&h(Be)},[h,Rt]),bt=l.useMemo(()=>{const Be=dr(Rt||"");if(!Be)return!1;const Et=x[Be];return So(Et)==="plan"},[x,Rt]),Ct=Fl,Ft=z1,Zt=l.useMemo(()=>!d&&(V&&ie&&!ae||U)?"pl-[5.5rem]":"pl-3",[V,ae,ie,d,U]);ze.useEffect(()=>{if(!V||!ie){ve(!1);return}let Be=!1,Et=null;const rs=async()=>{try{const{getCurrentWindow:Ys}=await Sr(async()=>{const{getCurrentWindow:qs}=await import("./vendor-.bun-Boz6Tqcq.js").then(dn=>dn.bK);return{getCurrentWindow:qs}},__vite__mapDeps([0,1])),Is=await Ys().isFullscreen();Be||ve(Is)}catch{Be||ve(!1)}},gs=async()=>{try{const{getCurrentWindow:Ys}=await Sr(async()=>{const{getCurrentWindow:Is}=await import("./vendor-.bun-Boz6Tqcq.js").then(qs=>qs.bK);return{getCurrentWindow:Is}},__vite__mapDeps([0,1]));Et=await Ys().onResized(()=>{rs()})}catch{}};return rs(),gs(),()=>{Be=!0,Et&&Et()}},[V,ie]);const it=l.useMemo(()=>!V||!ie||fe===null?"":fe>=26?"h-12":fe<=15?"h-14":"",[V,ie,fe]),zt=l.useMemo(()=>{if(!(V||nt))return{paddingLeft:U&&!d?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",minHeight:"max(3rem, var(--oc-wco-titlebar-height, 0px))",height:"max(3rem, var(--oc-wco-titlebar-height, 0px))"}},[V,d,U,nt]),hs=l.useCallback(()=>{if(typeof document>"u")return;const Be=L.current?.getBoundingClientRect().height;Be&&document.documentElement.style.setProperty("--oc-header-height",`${Be}px`)},[]);ze.useEffect(()=>{if(typeof window>"u")return;hs();const Be=L.current;if(!Be||typeof ResizeObserver>"u")return()=>{};let Et=0;const rs=()=>{Et||(Et=requestAnimationFrame(()=>{Et=0,hs()}))},gs=new ResizeObserver(rs);return gs.observe(Be),window.addEventListener("resize",rs),window.addEventListener("orientationchange",rs),()=>{Et&&cancelAnimationFrame(Et),gs.disconnect(),window.removeEventListener("resize",rs),window.removeEventListener("orientationchange",rs)}},[hs]),ze.useEffect(()=>{hs()},[hs,Y,it]);const Jt=l.useCallback(async Be=>{const Et=Be.target;Et.closest(".app-region-no-drag")||Et.closest("button, a, input, select, textarea")||Be.button===0&&V&&await Gf()},[V]),Ut=l.useMemo(()=>{if(Y){const Be=[{id:"chat",label:i("layout.mainTab.chat"),icon:"chat-4"}];return Os&&Be.push({id:"plan",label:i("layout.mainTab.plan"),icon:"file-text"}),Be.push({id:"diff",label:i("layout.mainTab.diff"),icon:"diff"},{id:"files",label:i("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:i("layout.mainTab.terminal"),icon:"terminal-box"}),Be}return[]},[Y,Os,i]),os=l.useCallback(Be=>Il(Ur(Be,y)),[y]);ze.useEffect(()=>{!Y&&(g==="git"||g==="terminal"||g==="diff"||g==="files")&&w("chat")},[g,Y,w]);const tn=l.useMemo(()=>{const Be=[];return V&&Be.push({value:"instance",label:i("layout.services.instance"),icon:"server"}),Be.push({value:"usage",label:i("layout.services.usage"),icon:"timer"},{value:"mcp",label:"MCP",icon:Jv}),Be},[V,i]),Zs=l.useMemo(()=>tn.map(Be=>({id:Be.value,label:Be.label,icon:s.jsx(I,{name:Be.icon,className:"h-3.5 w-3.5"})})),[tn]),nr=l.useMemo(()=>{if(typeof window>"u"||V||nt)return!1;const Be=window.location.hostname;return Be==="localhost"||Be==="127.0.0.1"||Be==="::1"},[V,nt]),Vn=l.useCallback(async()=>{if(j)return;S(!0),Pe(!1);const Be=[];let Et=!1;try{try{for(const[,rs]of ln.getState().sessions.entries())for(const gs of rs.tabs)gs.previewUrl&&Be.push(gs.previewUrl)}catch{}try{await Ox({})}catch{}try{(await fetch("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:Be})})).ok?Et=!0:Et=(await fetch("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{Et||S(!1)}},[j,Pe]),Ds=l.useMemo(()=>[{value:"usage",label:i("header.services.used")},{value:"remaining",label:i("header.services.remaining")}],[i]),on=l.useMemo(()=>Ds.map(Be=>({id:Be.value,label:Be.label})),[Ds]),en=l.useMemo(()=>[{id:"usage",label:i("layout.services.usage"),icon:s.jsx(I,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(I,{name:"command",className:"h-3.5 w-3.5"})}],[i]);ze.useEffect(()=>{const Be=Et=>{if(Ed(Et)&&!Et.shiftKey&&!Et.altKey){const rs=parseInt(Et.key,10);rs>=1&&rs<=Ut.length&&(Et.preventDefault(),w(Ut[rs-1].id))}};return window.addEventListener("keydown",Be),()=>window.removeEventListener("keydown",Be)},[Ut,w]),ze.useEffect(()=>{const Be=Et=>{const rs=Ur("toggle_services_menu",y);if(Vo(Et,rs)){Et.preventDefault(),Le?Pe(!1):(Pe(!0),st(),we==="usage"&&B.length===0&&$());return}const gs=Ur("cycle_services_tab",y);if(Vo(Et,gs)){Et.preventDefault();const Gs=tn.map(ir=>ir.value);if(Gs.length===0)return;const Is=Gs.indexOf(we),qs=Is===-1?0:(Is+1)%Gs.length,dn=Gs[qs];Qe(dn),Pe(!0),st(),dn==="usage"&&B.length===0&&$();return}const Ys=Ur("toggle_context_plan",y);Vo(Et,Ys)&&(Et.preventDefault(),Cs())};return window.addEventListener("keydown",Be),()=>window.removeEventListener("keydown",Be)},[y,Le,we,tn,B.length,$,st,Cs]);const mn=Be=>{const Et=g===Be.id,rs=Be.icon==="diff",gs=rs?null:Be.icon,Ys=Be.id==="chat",Gs=qs=>rs?s.jsx(Gu,{size:qs}):gs?s.jsx(I,{name:gs,className:`h-${qs/4} w-${qs/4}`}):null,Is=s.jsxs("button",{type:"button",onClick:()=>w(Be.id),className:me("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",Ys&&!Y&&"min-w-[100px] justify-center"),"aria-label":Be.label,"aria-selected":Et,role:"tab",children:[Y?Gs(20):s.jsxs(s.Fragment,{children:[Gs(16),s.jsx("span",{className:"header-tab-label",children:Be.label})]}),Be.badge!==void 0&&Be.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:Be.badge})]});return s.jsx(l.Fragment,{children:Is},Be.id)},Sn=s.jsxs(s.Fragment,{children:[Os&&s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.actions.openPlanAria"),onClick:Cs,className:me(Ct,bt&&"bg-[var(--interactive-hover)]"),children:s.jsx(I,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(At,{children:s.jsx("p",{children:i("header.actions.planWithShortcut",{shortcut:os("toggle_context_plan")})})})]}),s.jsx(s1,{directory:Mt,className:"mr-1"}),s.jsx(V1,{isDesktopApp:V,currentInstanceLabel:ee,compactCurrentInstanceLabel:Fe,isDesktopServicesOpen:Le,setIsDesktopServicesOpen:Pe,refreshCurrentInstanceLabel:st,desktopServicesTab:we,setDesktopServicesTab:Qe,quotaResultsLength:B.length,fetchAllQuotas:$,servicesTabItems:Zs,quotaLastUpdated:Q,quotaDisplayMode:W,quotaDisplayTabItems:on,handleDisplayModeChange:_e,handleUsageRefresh:We,isQuotaLoading:_,isUsageRefreshSpinning:he,hasRateLimits:Ye,rateLimitGroups:xe,expandedFamilies:et,toggleFamilyExpanded:rt,shortcutLabel:os,showDevShutdown:nr,isDevShutdownInFlight:j,onDevShutdown:Vn}),s.jsx(Ci,{title:i("header.actions.terminalPanelWithShortcut",{shortcut:os("toggle_terminal")}),ariaLabel:i("header.actions.toggleTerminalPanelAria"),onClick:m,Icon:"terminal-box"}),X?s.jsx(Ci,{title:i("contextPanel.browser.open"),ariaLabel:i("contextPanel.browser.open"),onClick:Ke,Icon:"global"}):null,s.jsx(Ci,{title:i("header.actions.rightSidebarWithShortcut",{shortcut:os("toggle_right_sidebar")}),ariaLabel:i("header.actions.toggleRightSidebarAria"),onClick:u,Icon:"layout-right"}),s.jsx(_1,{isMobile:Y,githubAuthStatus:le,githubAccounts:ge,githubAvatarUrl:De,githubLogin:ye,isSwitchingGitHubAccount:Me,handleGitHubAccountSwitch:cs})]}),Fn=!p||!a,Mn=X&&(P||!!C),cn=()=>s.jsxs("div",{onMouseDown:Jt,className:me("app-region-drag relative flex h-12 select-none items-center pr-3",Zt,it),style:zt,role:"tablist","aria-label":i("header.navigation.mainAria"),children:[s.jsx(Ci,{visible:!d,title:i("header.actions.openSessionsWithShortcut",{shortcut:os("toggle_sidebar")}),ariaLabel:i("header.actions.openSessionsAria"),onClick:Tt,className:`${Ct} shrink-0`,Icon:"layout-left"}),s.jsxs("div",{className:me("flex min-w-0 flex-1 items-center",!d&&"pl-3"),children:[Re?null:s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.actions.newSessionAria"),onClick:Z,className:me(Ct,"mr-6 shrink-0"),children:s.jsx(I,{name:"chat-new",className:"h-[18px] w-[18px]"})})}),s.jsx(At,{children:s.jsx("p",{children:i("header.actions.newSessionWithShortcut",{shortcut:os("new_chat")})})})]}),ns&&s.jsx(rm,{projectRef:ns.projectRef,directory:ns.directory,className:"mr-2"}),s.jsx(Xx,{children:s.jsxs("button",{type:"button","aria-label":i("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:P?i("sessions.switcher.draftTitle"):ws}),z||ps||!P&&(St||Xt)?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:[z?s.jsx("span",{className:"truncate",children:z}):null,ps?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:ps})]}):null,!P&&St?s.jsxs("span",{className:"inline-flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",Ge.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Ge.deletions]})]}):null,!P&&Xt?s.jsxs("span",{className:me("inline-flex min-w-0 items-center gap-0.5",Xt==="attention"||Xt==="invalid"||Xt==="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:Dt})]}):null]}):null]})}),Ut.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:Ut.map(Be=>mn(Be))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[de&&ke?s.jsx(Zx,{totalTokens:ke.totalTokens,percentage:He,colorPercentage:ke.percentage,contextLimit:ke.contextLimit,outputLimit:ke.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:Ht,pressed:Ns,className:Fn&&!Mn?"mr-3.5":"",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,s.jsx(Ci,{visible:Mn,title:i(P?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:i(P?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:kt,className:me(Ct,Fn&&de?"mr-3.5":"mr-1"),Icon:"picture-in-picture-2"}),Fn?Sn:null,!Fn&&a?Bi.createPortal(Sn,a):null]})]})]}),kn=()=>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:t,className:me(Ft,n&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":i(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(I,{name:"layout-left",className:"h-5 w-5"})}):Se?s.jsx("button",{type:"button",onClick:()=>o(!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":i("header.actions.backAria"),children:s.jsx(I,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:Tt,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":i("header.actions.openSessionsAria"),children:s.jsx(I,{name:"play-list-add",className:"h-5 w-5"})}),Se&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:i("header.sessions.title")})]}),!Se&&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":i("header.navigation.mainAria"),children:Ut.map(Be=>{const Et=g===Be.id,rs=Be.icon==="diff",gs=rs?null:Be.icon;return s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{Y&&jt(),w(Be.id)},"aria-label":Be.label,"aria-selected":Et,role:"tab",className:me(Ft,"relative rounded-lg",Et&&"bg-interactive-selection text-interactive-selection-foreground"),children:[rs?s.jsx(Gu,{className:"h-5 w-5"}):gs?s.jsx(I,{name:gs,className:"h-5 w-5"}):null,Be.badge!==void 0&&Be.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:Be.badge}),Be.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":i("header.changes.availableAria")})]})}),s.jsx(At,{children:s.jsx("p",{children:Be.label})})]},Be.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[ns&&s.jsx(rm,{projectRef:ns.projectRef,directory:ns.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(_s,{open:q,onOpenChange:Be=>{Ie(Be),Be&&B.length===0&&$()},children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.services.viewAria"),className:Ft,children:s.jsx(I,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(At,{children:s.jsx("p",{children:i("header.services.title")})})]}),s.jsx(zs,{align:"end",sideOffset:0,className:"h-dvh w-[100vw] max-h-none rounded-none border-0 p-0 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(Er,{items:en,activeId:pe,onSelect:Be=>{const Et=Be;Oe(Et),Et==="usage"&&B.length===0&&$()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})}),s.jsx("button",{type:"button",onClick:()=>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":i("header.services.closeAria"),children:s.jsx(I,{name:"close",className:"h-5 w-5"})})]})}),pe==="mcp"&&s.jsx(Ch,{active:q&&pe==="mcp"}),pe==="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:i("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Th(Q)})]}),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:()=>_e("usage"),className:me("typography-ui-label px-1 pb-0.5 transition-colors",W==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:i("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>_e("remaining"),className:me("typography-ui-label px-1 pb-0.5 transition-colors",W==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:i("header.services.remaining")})]}),s.jsx("button",{type:"button",className:me("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:We,disabled:_||he,"aria-label":i("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:me("h-4 w-4",he&&"animate-spin")})})]})]})}),!Ye&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:i("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:xe.map((Be,Et)=>s.jsxs(l.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(jn,{providerId:Be.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Be.providerName})]}),Be.entries.length===0&&(!Be.modelFamilies||Be.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Be.error??i("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Be.entries.map(([rs,gs])=>{const Ys=W==="remaining"?gs.remainingPercent:gs.usedPercent,Gs=eo(gs.usedPercent,gs.resetAt,gs.windowSeconds,rs),Is=Gs?.dailyAllocationPercent!=null?W==="remaining"?100-Wr(Gs.elapsedRatio):Wr(Gs.elapsedRatio):null,qs=Zi(gs.valueLabel,Ys),dn=Kd(gs.resetAt,gs.resetAfterFormatted??gs.resetAtFormatted);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:Hd(rs)}),dn?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:dn}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:qs==="-"?"":qs})]}),s.jsx(so,{percent:Ys,tonePercent:gs.usedPercent,className:"h-1.5",expectedMarkerPercent:Is}),Gs?s.jsx(no,{paceInfo:Gs,compact:!0}):null]},`${Be.providerId}-${rs}`)}),Be.modelFamilies&&Be.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:Be.modelFamilies.map(rs=>{const Ys=(et[Be.providerId]??[]).includes(rs.familyId??"other");return s.jsxs(gr,{open:Ys,onOpenChange:()=>rt(Be.providerId,rs.familyId??"other"),children:[s.jsxs(kr,{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:rs.familyLabel}),Ys?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(xr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:rs.models.map(([Gs,Is])=>{const qs=W==="remaining"?Is.remainingPercent:Is.usedPercent,dn=eo(Is.usedPercent,Is.resetAt,Is.windowSeconds),ir=dn?.dailyAllocationPercent!=null?W==="remaining"?100-Wr(dn.elapsedRatio):Wr(dn.elapsedRatio):null,Ln=Zi(Is.valueLabel,qs);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:cl(Gs)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Ln==="-"?"":Ln})]}),s.jsx(so,{percent:qs,tonePercent:Is.usedPercent,className:"h-1.5",expectedMarkerPercent:ir}),dn?s.jsx(no,{paceInfo:dn,compact:!0}):null]},`${Be.providerId}-${Gs}`)})})})]},rs.familyId??"other")})})]})]},Be.providerId))})]})]})})]}),e?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:e,className:me(Ft,"relative",r&&"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(At,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Cn=me("header-safe-area relative z-10",Y&&"border-b border-border/50","bg-background");return s.jsx("header",{ref:L,className:Cn,style:{"--padding-scale":"1"},children:Y?kn():cn()})};function K1(){}const im=180,om=640,H1=110,G1=t=>{const e=at.c(44),{isOpen:n,isMobile:r,children:a}=t,{t:i}=mt(),o=Te(q1),c=Te(Y1),d=Te(J1),p=Te(Q1),[m,u]=l.useState(null),[f,b]=l.useState(!1),h=l.useRef(null),v=l.useRef(0),x=l.useRef(o||300),g=Math.min(om,Math.max(im,o||300));let w,y;e[0]!==n?(w=()=>{n||(u(null),b(!1))},y=[n],e[0]=n,e[1]=w,e[2]=y):(w=e[1],y=e[2]),l.useEffect(w,y);let k,D;e[3]!==c||e[4]!==r||e[5]!==n?(k=()=>{if(r||!n||!c)return;const re=()=>{const le=h.current?.parentElement?.getBoundingClientRect().height;if(!le||le<=0)return;const J=Math.max(0,Math.round(le));u(L=>L===J?L:J)};re();const ue=h.current?.parentElement;if(!ue)return;const Y=new ResizeObserver(re);return Y.observe(ue),()=>{Y.disconnect()}},D=[c,r,n],e[3]=c,e[4]=r,e[5]=n,e[6]=k,e[7]=D):(k=e[6],D=e[7]),l.useEffect(k,D);let j,S;if(e[8]!==c||e[9]!==r||e[10]!==f||e[11]!==d||e[12]!==p?(j=()=>{if(r||!f||c)return;const re=Y=>{const le=v.current-Y.clientY,J=Math.min(om,Math.max(im,x.current+le));d(J)},ue=()=>{b(!1),Te.getState().bottomTerminalHeight<=H1&&p(!1)};return window.addEventListener("pointermove",re),window.addEventListener("pointerup",ue,{once:!0}),()=>{window.removeEventListener("pointermove",re),window.removeEventListener("pointerup",ue)}},S=[c,r,f,d,p],e[8]=c,e[9]=r,e[10]=f,e[11]=d,e[12]=p,e[13]=j,e[14]=S):(j=e[13],S=e[14]),l.useEffect(j,S),r)return null;const A=n?c?Math.max(0,m??g):g:0,E=n&&c;let P;e[15]!==A||e[16]!==c||e[17]!==n?(P=re=>{!n||c||(b(!0),v.current=re.clientY,x.current=A,re.preventDefault())},e[15]=A,e[16]=c,e[17]=n,e[18]=P):P=e[18];const C=P,N=E?"absolute inset-x-0 bottom-0 z-40":"relative",T=f?"transition-none":"transition-[height] duration-300 ease-in-out",M=!n&&"border-t-0";let R;e[19]!==M||e[20]!==N||e[21]!==T?(R=me("flex overflow-hidden border-t border-border bg-sidebar",N,T,M),e[19]=M,e[20]=N,e[21]=T,e[22]=R):R=e[22];let O;e[23]!==A||e[24]!==E?(O=E?{top:"var(--oc-header-height, 48px)"}:{height:`${A}px`,minHeight:`${A}px`,maxHeight:`${A}px`},e[23]=A,e[24]=E,e[25]=O):O=e[25];const z=!n||!c&&A===0;let B;e[26]!==C||e[27]!==c||e[28]!==n||e[29]!==f||e[30]!==i?(B=n&&!c&&s.jsx("div",{className:me("absolute left-0 top-0 z-20 h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",f&&"bg-[var(--interactive-border)]"),onPointerDown:C,role:"separator","aria-orientation":"horizontal","aria-label":i("terminalView.bottomDock.resizeAria")}),e[26]=C,e[27]=c,e[28]=n,e[29]=f,e[30]=i,e[31]=B):B=e[31];const $=!n&&"pointer-events-none select-none opacity-0";let _;e[32]!==$?(_=me("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",$),e[32]=$,e[33]=_):_=e[33];const Q=!n;let W;e[34]!==a||e[35]!==_||e[36]!==Q?(W=s.jsx("div",{className:_,"aria-hidden":Q,children:a}),e[34]=a,e[35]=_,e[36]=Q,e[37]=W):W=e[37];let ne;return e[38]!==R||e[39]!==O||e[40]!==z||e[41]!==B||e[42]!==W?(ne=s.jsxs("section",{ref:h,className:R,style:O,"aria-hidden":z,children:[B,W]}),e[38]=R,e[39]=O,e[40]=z,e[41]=B,e[42]=W,e[43]=ne):ne=e[43],ne};function q1(t){return t.bottomTerminalHeight}function Y1(t){return t.isBottomTerminalExpanded}function J1(t){return t.setBottomTerminalHeight}function Q1(t){return t.setBottomTerminalOpen}const rd=280,lm=280,cm=500,X1=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:a}=mt(),i=Te(k=>k.sidebarWidth),o=Te(k=>k.setSidebarWidth),[c,d]=l.useState(!1),p=l.useRef(0),m=l.useRef(i||rd),u=l.useRef(null),f=l.useRef(null),b=l.useRef(null),h=l.useCallback(k=>Math.min(cm,Math.max(lm,k)),[]),v=l.useCallback(k=>{const D=b.current;D&&D.style.setProperty("--oc-left-sidebar-width",`${k}px`)},[]);if(l.useEffect(()=>{e&&c&&d(!1)},[e,c]),l.useEffect(()=>{c||(u.current=null,f.current=null)},[c]),e)return null;const x=t?Math.min(cm,Math.max(lm,i||rd)):0,g=k=>{if(t){try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}f.current=k.pointerId,d(!0),p.current=k.clientX,m.current=x,u.current=x,v(x),k.preventDefault()}},w=k=>{if(e||!c||f.current!==k.pointerId)return;const D=k.clientX-p.current,j=h(m.current+D);u.current!==j&&(u.current=j,v(j))},y=k=>{if(f.current!==k.pointerId||e)return;try{k.currentTarget.releasePointerCapture(k.pointerId)}catch{}const D=h(u.current??x);f.current=null,u.current=null,d(!1),o(D)};return s.jsxs("aside",{ref:b,className:me("relative flex h-full overflow-hidden border-r border-border/40","bg-sidebar",c?"transition-none":"transition-[width] duration-300 ease-in-out",!t&&"border-r-0",r),style:{width:"var(--oc-left-sidebar-width)",minWidth:"var(--oc-left-sidebar-width)",maxWidth:"var(--oc-left-sidebar-width)","--oc-left-sidebar-width":`${c?u.current??x:x}px`,overflowX:"clip"},"aria-hidden":!t||x===0,children:[t&&s.jsx("div",{className:me("absolute right-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:g,onPointerMove:w,onPointerUp:y,onPointerCancel:y,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.leftPanelAria")}),s.jsx("div",{className:me("relative z-10 flex h-full flex-col transition-opacity duration-300 ease-in-out",c&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Xs,{children:n})})})]})},Mh=420,dm=400,um=860,Z1=({isOpen:t,children:e,className:n,onTopActionsHostChange:r})=>{const{t:a}=mt(),i=Te(E=>E.rightSidebarWidth),o=Te(E=>E.setRightSidebarWidth),c=l.useMemo(()=>yn(),[]),d=l.useMemo(()=>un(),[]),p=Cl(),[m,u]=l.useState(!1),f=l.useRef(0),b=l.useRef(i||420),h=l.useRef(null),v=l.useRef(null),x=l.useRef(null),g=l.useCallback(E=>Math.min(um,Math.max(dm,E)),[]),w=l.useCallback(E=>{const P=x.current;P&&P.style.setProperty("--oc-right-sidebar-width",`${E}px`)},[]),y=t?Math.min(um,Math.max(dm,i||Mh)):0,k=E=>{if(t){try{E.currentTarget.setPointerCapture(E.pointerId)}catch{}v.current=E.pointerId,u(!0),f.current=E.clientX,b.current=y,h.current=y,w(y),E.preventDefault()}},D=E=>{if(!m||v.current!==E.pointerId)return;const P=f.current-E.clientX,C=g(b.current+P);h.current!==C&&(h.current=C,w(C))},j=E=>{if(v.current!==E.pointerId)return;try{E.currentTarget.releasePointerCapture(E.pointerId)}catch{}const P=g(h.current??y);v.current=null,h.current=null,u(!1),o(P)};l.useEffect(()=>{m||(h.current=null,v.current=null)},[m]),l.useEffect(()=>{t||r?.(null)},[t,r]);const S=l.useCallback(async E=>{const P=E.target;P.closest(".app-region-no-drag")||P.closest("button, a, input, select, textarea")||E.button===0&&c&&await Gf()},[c]),A=l.useMemo(()=>{if(!(c||d))return{paddingLeft:"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",...p?{paddingTop:"var(--oc-safe-area-top, 0px)"}:null}},[c,p,d]);return s.jsxs("aside",{ref:x,className:me("relative flex h-full overflow-hidden border-l border-border/40","bg-sidebar",m?"transition-none":"transition-[width] duration-300 ease-in-out",!t&&"border-l-0",n),style:{width:"var(--oc-right-sidebar-width)",minWidth:"var(--oc-right-sidebar-width)",maxWidth:"var(--oc-right-sidebar-width)","--oc-right-sidebar-width":`${m?h.current??y:y}px`,overflowX:"clip"},"aria-hidden":!t||y===0,children:[t?s.jsx("div",{onMouseDown:S,className:me("app-region-drag absolute inset-x-0 top-0 z-20 flex items-center justify-end px-3","h-[var(--oc-header-height,56px)]"),style:A,"aria-hidden":!0,children:s.jsx("div",{ref:r,className:"app-region-no-drag flex items-center gap-1"})}):null,t&&s.jsx("div",{className:me("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",m&&"bg-[var(--interactive-border)]"),onPointerDown:k,onPointerMove:D,onPointerUp:j,onPointerCancel:j,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.rightPanelAria")}),s.jsx("div",{className:me("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",m&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:t?{paddingTop:"var(--oc-header-height, 56px)"}:void 0,"aria-hidden":!t,children:t?e:null})]})},ew=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),tw=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=ew.format(t);return e.endsWith(".0")?e.slice(0,-2):e},uo=({providerId:t,modelId:e,onChange:n,className:r,allowedProviderIds:a,placeholder:i})=>{const{t:o}=mt(),{isReady:c,isUnavailable:d}=qf(),p=gt(L=>L.providers),m=gt(L=>L.modelsMetadata),u=Te(L=>L.isMobile),f=Te(L=>L.hiddenModels),b=Te(L=>L.toggleFavoriteModel),h=Te(L=>L.isFavoriteModel),v=Te(L=>L.addRecentModel),{favoriteModelsList:x,recentModelsList:g}=Yf(),{isMobile:w}=an(),y=u||w,[k,D]=l.useState(!1),[j,S]=l.useState(new Set),[A,E]=l.useState(!1),[P,C]=l.useState(""),[N,T]=l.useState(0),M=l.useRef([]),R=l.useMemo(()=>!Array.isArray(a)||a.length===0?null:new Set(a),[a]),O=l.useMemo(()=>(R?p.filter(V=>R.has(String(V.id))):p).map(V=>{const X=(Array.isArray(V.models)?V.models:[]).filter(U=>{const ae=typeof U?.id=="string"?U.id:"";return!f.some(ve=>ve.providerID===String(V.id)&&ve.modelID===ae)});return{...V,models:X}}).filter(V=>V.models.length>0),[p,R,f]),z=()=>D(!1),B=L=>{S(V=>{const K=new Set(V);return K.has(L)?K.delete(L):K.add(L),K})};l.useEffect(()=>{A||(C(""),T(0))},[A]),l.useEffect(()=>{T(0)},[P]);const $=L=>{const V=L?.name||L?.id||"",K=String(V);return K.length>40?K.substring(0,37)+"...":K},_=(L,V)=>{const K=`${L}/${V}`;return m.get(K)},Q=(L,V)=>{n(L,V),L&&V&&v(L,V),E(!1)},W=(L,V)=>{if(!P.trim())return!0;const K=P.toLowerCase();return L.toLowerCase().includes(K)||V.toLowerCase().includes(K)},ne=(L,V,K,X,U,ae)=>{const ve=_(V,K),ie=tw(ve?.limit?.context),fe=t===V&&e===K,H=h(V,K),ce=X==="fav"||X==="recent";return s.jsxs(Vt,{ref:se=>{M.current[U]=se},className:me("group flex items-center gap-2",ae&&"bg-interactive-selection"),onSelect:()=>Q(V,K),onMouseEnter:()=>T(U),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[ce&&s.jsx(jn,{providerId:V,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(L)}),ie?s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:ie}):null]}),s.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[fe&&s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}),s.jsx("button",{onClick:se=>{se.preventDefault(),se.stopPropagation(),b(V,K)},className:me("model-favorite-button flex h-4 w-4 items-center justify-center hover:text-primary/80",H?"text-primary":"text-muted-foreground"),"aria-label":o(H?"settings.agents.modelSelector.actions.unfavorite":"settings.agents.modelSelector.actions.favorite"),title:o(H?"settings.agents.modelSelector.actions.removeFromFavorites":"settings.agents.modelSelector.actions.addToFavorites"),children:H?s.jsx(I,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"star",className:"h-3.5 w-3.5"})})]})]},`${X}-${V}-${K}`)},re=x.filter(({model:L,providerID:V})=>{if(R&&!R.has(V))return!1;const X=p.find(ae=>ae.id===V)?.name||V,U=$(L);return W(U,X)}),ue=g.filter(({model:L,providerID:V})=>{if(R&&!R.has(V))return!1;const X=p.find(ae=>ae.id===V)?.name||V,U=$(L);return W(U,X)}),Y=O.map(L=>{const K=(Array.isArray(L.models)?L.models:[]).filter(X=>{const U=$(X);return W(U,L.name||L.id||"")});return{...L,models:K}}).filter(L=>L.models.length>0),le=re.length>0||ue.length>0||Y.length>0,J=()=>y?s.jsx(Mr,{open:k,onClose:z,title:o("settings.agents.modelSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[x.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:o("settings.agents.modelSelector.section.favorites")}),s.jsx("div",{className:"border-t border-border/20",children:x.map(({model:L,providerID:V,modelID:K})=>{const X=V===t&&K===e;return s.jsxs("div",{className:me("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",X?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{Q(V,K),z()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(jn,{providerId:V,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(L)})]})}),s.jsx("button",{onClick:U=>{U.preventDefault(),U.stopPropagation(),b(V,K)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-primary hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":o("settings.agents.modelSelector.actions.unfavorite"),children:s.jsx(I,{name:"star-fill",className:"h-4 w-4"})})]},`fav-mobile-${V}-${K}`)})})]}),g.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:o("settings.agents.modelSelector.section.recents")}),s.jsx("div",{className:"border-t border-border/20",children:g.map(({model:L,providerID:V,modelID:K})=>{const X=V===t&&K===e;return s.jsxs("div",{className:me("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",X?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{Q(V,K),z()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(jn,{providerId:V,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(L)})]})}),s.jsx("button",{onClick:U=>{U.preventDefault(),U.stopPropagation(),b(V,K)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-muted-foreground/50 hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":o("settings.agents.modelSelector.actions.favorite"),children:s.jsx(I,{name:"star",className:"h-4 w-4"})})]},`recent-mobile-${V}-${K}`)})})]}),O.map(L=>{const V=Array.isArray(L.models)?L.models:[];if(V.length===0)return null;const K=L.id===t,X=j.has(L.id);return s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)]",children:[s.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-1.5 px-2 py-1.5 text-left",onClick:()=>B(L.id),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(jn,{providerId:L.id,className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:L.name}),K&&s.jsx("span",{className:"typography-micro text-primary/80",children:o("settings.agents.modelSelector.badge.current")})]}),X?s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-3 w-3 text-muted-foreground"})]}),X&&s.jsx("div",{className:"border-t border-border/20",children:V.map(U=>{const ae=L.id===t&&U.id===e;return s.jsxs("div",{className:me("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",ae?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{Q(L.id,U.id),z()},children:s.jsx("span",{className:"font-medium truncate",children:$(U)})}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[s.jsx("button",{onClick:ve=>{ve.preventDefault(),ve.stopPropagation(),b(L.id,U.id)},className:me("flex h-8 w-8 items-center justify-center active:scale-95 touch-manipulation hover:text-primary/80",h(L.id,U.id)?"text-primary":"text-muted-foreground/50"),"aria-label":h(L.id,U.id)?o("settings.agents.modelSelector.actions.unfavorite"):o("settings.agents.modelSelector.actions.favorite"),children:h(L.id,U.id)?s.jsx(I,{name:"star-fill",className:"h-4 w-4"}):s.jsx(I,{name:"star",className:"h-4 w-4"})}),ae&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]})]},U.id)})})]},L.id)}),s.jsx("button",{type:"button",className:"flex w-full items-center justify-between rounded-lg border border-border/40 bg-[var(--surface-elevated)] px-2 py-1.5 text-left",onClick:()=>{Q("",""),z()},children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:i||o("settings.agents.modelSelector.noModelOptional")})})]})}):null;return s.jsxs(s.Fragment,{children:[y?s.jsxs("button",{type:"button",onClick:c?()=>D(!0):void 0,disabled:!c,className:me("flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-[var(--surface-elevated)] px-2 py-1.5 text-left",!c&&"opacity-60 cursor-not-allowed",r),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[c?t?s.jsx(jn,{providerId:t,className:"h-3.5 w-3.5"}):s.jsx(I,{name:"pencil-ai",className:"h-3 w-3 text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]}),c&&s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t&&e?`${t}/${e}`:i||o("settings.agents.modelSelector.selectPlaceholder")})]}),s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):s.jsxs(_s,{open:c&&A,onOpenChange:c?E:void 0,children:[s.jsx(Bs,{asChild:!0,children:s.jsxs("div",{className:me("border-input data-[placeholder]:text-muted-foreground flex items-center justify-between gap-2 rounded-lg border bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover data-[popup-open]:bg-interactive-active h-6 w-fit",r),children:[c?s.jsxs(s.Fragment,{children:[t?s.jsxs(s.Fragment,{children:[s.jsx(jn,{providerId:t,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx(I,{name:"pencil-ai",className:"h-3 w-3 text-primary/60 hidden"})]}):s.jsx(I,{name:"pencil-ai",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-foreground",children:t&&e?`${t}/${e}`:i||o("settings.agents.modelSelector.notSelected")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsx(zs,{className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",align:"start",children:(()=>{const L=[];re.forEach(({model:U,providerID:ae,modelID:ve})=>{L.push({model:U,providerID:ae,modelID:ve,section:"fav"})}),ue.forEach(({model:U,providerID:ae,modelID:ve})=>{L.push({model:U,providerID:ae,modelID:ve,section:"recent"})}),Y.forEach(U=>{U.models.forEach(ae=>{L.push({model:ae,providerID:U.id,modelID:ae.id,section:"provider"})})});const V=L.length,K=U=>{if(U.stopPropagation(),U.key==="ArrowDown"){U.preventDefault();const ae=(N+1)%Math.max(1,V);T(ae),setTimeout(()=>{M.current[ae]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(U.key==="ArrowUp"){U.preventDefault();const ae=(N-1+Math.max(1,V))%Math.max(1,V);T(ae),setTimeout(()=>{M.current[ae]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(U.key==="Enter"){U.preventDefault();const ae=L[N];ae&&Q(ae.providerID,ae.modelID)}else U.key==="Escape"&&(U.preventDefault(),E(!1))};let X=0;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"p-2 border-b border-border/40",children:s.jsxs("div",{className:"relative",children:[s.jsx(I,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Wt,{type:"text",placeholder:o("settings.agents.modelSelector.searchPlaceholder"),value:P,onChange:U=>C(U.target.value),onKeyDown:K,className:"pl-8 h-8 typography-meta",autoFocus:!0})]})}),s.jsx(Es,{outerClassName:"max-h-[min(400px,calc(100dvh-12rem))] flex-1",children:s.jsxs("div",{className:"p-1",children:[s.jsxs(Vt,{className:me("flex items-center gap-2"),onSelect:()=>Q("",""),children:[s.jsx(I,{name:"close",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-muted-foreground",children:i||o("settings.agents.modelSelector.notSelected")}),!t&&!e&&s.jsx(I,{name:"check",className:"h-4 w-4 text-primary ml-auto"})]}),s.jsx(Tn,{}),!le&&P&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:o("settings.agents.modelSelector.state.noModelsFound")}),re.length>0&&s.jsxs("div",{children:[s.jsxs(zi,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(I,{name:"star-fill",className:"h-4 w-4 text-primary"}),o("settings.agents.modelSelector.section.favorites")]}),re.map(({model:U,providerID:ae,modelID:ve})=>{const ie=X++;return ne(U,ae,ve,"fav",ie,N===ie)})]}),ue.length>0&&s.jsxs("div",{children:[re.length>0&&s.jsx(Tn,{}),s.jsxs(zi,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(I,{name:"time",className:"h-4 w-4"}),o("settings.agents.modelSelector.section.recent")]}),ue.map(({model:U,providerID:ae,modelID:ve})=>{const ie=X++;return ne(U,ae,ve,"recent",ie,N===ie)})]}),(re.length>0||ue.length>0)&&Y.length>0&&s.jsx(Tn,{}),Y.map((U,ae)=>s.jsxs("div",{children:[ae>0&&s.jsx(Tn,{}),s.jsxs(zi,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(jn,{providerId:U.id,className:"h-4 w-4 flex-shrink-0"}),U.name]}),U.models.map(ve=>{const ie=X++;return ne(ve,U.id,ve.id,"provider",ie,N===ie)})]},U.id))]})}),s.jsx("div",{className:"px-3 pt-1 pb-1.5 border-t border-border/40 typography-micro text-muted-foreground",children:o("settings.agents.modelSelector.keyboardHints")})]})})()})]}),J()]})},Ll=t=>{const e=at.c(34),{agentName:n,onChange:r,className:a,filter:i}=t,{t:o}=mt(),{isReady:c,isUnavailable:d}=qf(),p=gt(sw),m=di(nw),u=di(rw),f=gt(aw);let b;e:{if(Array.isArray(p)&&p.length>0){b=p;break e}let z;e[0]!==m?(z=Array.isArray(m)?m:[],e[0]=m,e[1]=z):z=e[1],b=z}const h=b;let v;if(e[2]!==i||e[3]!==h){const z=eb(h);v=i?z.filter(i):z,e[2]=i,e[3]=h,e[4]=v}else v=e[4];const x=v,g=Te(iw),{isMobile:w}=an(),y=g||w,[k,D]=l.useState(!1);let j,S;e[5]!==u||e[6]!==f||e[7]!==h.length?(j=()=>{h.length>0||(f(),u())},S=[h.length,f,u],e[5]=u,e[6]=f,e[7]=h.length,e[8]=j,e[9]=S):(j=e[8],S=e[9]),l.useEffect(j,S);let A;e[10]===Symbol.for("react.memo_cache_sentinel")?(A=()=>D(!1),e[10]=A):A=e[10];const E=A;let P;e[11]!==r?(P=z=>{r(z)},e[11]=r,e[12]=P):P=e[12];const C=P;let N;e[13]!==n||e[14]!==x||e[15]!==C||e[16]!==y||e[17]!==k||e[18]!==o?(N=()=>y?s.jsx(Mr,{open:k,onClose:E,title:o("settings.commands.agentSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",className:me("flex w-full items-center justify-between rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",n?"text-foreground":"bg-primary/10 text-primary"),onClick:()=>{C(""),E()},children:[s.jsx("span",{className:me("typography-meta",n?"text-muted-foreground":"font-medium"),children:o("settings.commands.agentSelector.notSelected")}),!n&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]}),x.map(z=>{const B=z.name===n;return s.jsxs("button",{type:"button",className:me("flex w-full items-center justify-between rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",B?"bg-primary/10 text-primary":"text-foreground"),onClick:()=>{C(z.name),E()},children:[s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-meta font-medium",children:z.name}),z.description&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:z.description})]}),B&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]},z.name)})]})}):null,e[13]=n,e[14]=x,e[15]=C,e[16]=y,e[17]=k,e[18]=o,e[19]=N):N=e[19];const T=N;let M;e[20]!==n||e[21]!==x||e[22]!==a||e[23]!==C||e[24]!==y||e[25]!==c||e[26]!==d||e[27]!==o?(M=y?s.jsxs("button",{type:"button",onClick:c?()=>D(!0):void 0,disabled:!c,className:me("flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",!c&&"opacity-60 cursor-not-allowed",a),children:[s.jsx("div",{className:"flex items-center gap-2",children:c?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"robot-2",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:n||o("settings.commands.agentSelector.selectAgentPlaceholder")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]})}),s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):c?s.jsxs(_s,{children:[s.jsx(Bs,{asChild:!0,children:s.jsxs("div",{className:me("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 cursor-pointer hover:bg-interactive-hover/30 h-6 w-fit",a),children:[s.jsx(I,{name:"robot-2",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap",children:n||o("settings.commands.agentSelector.notSelected")}),s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsxs(zs,{className:"max-w-[300px]",children:[s.jsx(Vt,{className:"typography-meta",onSelect:()=>C(""),children:s.jsx("span",{className:"text-muted-foreground",children:o("settings.commands.agentSelector.notSelected")})}),x.map(z=>s.jsx(Vt,{className:"typography-meta",onSelect:()=>C(z.name),children:s.jsx("span",{className:"font-medium",children:z.name})},z.name))]})]}):s.jsxs("div",{className:me("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 h-6 w-fit opacity-60",a),children:[s.jsx(I,{name:"loader-4",className:"h-3 w-3 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]}),e[20]=n,e[21]=x,e[22]=a,e[23]=C,e[24]=y,e[25]=c,e[26]=d,e[27]=o,e[28]=M):M=e[28];let R;e[29]!==T?(R=T(),e[29]=T,e[30]=R):R=e[30];let O;return e[31]!==M||e[32]!==R?(O=s.jsxs(s.Fragment,{children:[M,R]}),e[31]=M,e[32]=R,e[33]=O):O=e[33],O};function sw(t){return t.agents}function nw(t){return t.agents}function rw(t){return t.loadAgents}function aw(t){return t.loadAgents}function iw(t){return t.isMobile}const mm=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent}),ow=t=>{const e=at.c(38),{value:n,options:r,disabled:a,onChange:i}=t,{t:o}=mt();let c;e[0]!==o||e[1]!==n?(c=n||o("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[0]=o,e[1]=n,e[2]=c):c=e[2];const d=c,p=a?"cursor-not-allowed opacity-60":"cursor-pointer hover:bg-interactive-hover/30";let m;e[3]!==p?(m=me("flex h-6 w-fit items-center gap-1.5 rounded-lg border border-border/20 bg-interactive-selection/20 px-2",p),e[3]=p,e[4]=m):m=e[4];let u;e[5]!==d?(u=s.jsx("span",{className:"typography-micro whitespace-nowrap font-medium capitalize",children:d}),e[5]=d,e[6]=u):u=e[6];let f;e[7]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),e[7]=f):f=e[7];let b;e[8]!==m||e[9]!==u?(b=s.jsxs("div",{className:m,children:[u,f]}),e[8]=m,e[9]=u,e[10]=b):b=e[10];const h=b;if(a)return h;let v;e[11]!==h?(v=s.jsx(Bs,{asChild:!0,children:h}),e[11]=h,e[12]=v):v=e[12];let x;e[13]!==i?(x=()=>i(""),e[13]=i,e[14]=x):x=e[14];const g=!n&&"text-primary";let w;e[15]!==g?(w=me("font-medium",g),e[15]=g,e[16]=w):w=e[16];let y;e[17]!==o?(y=o("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[17]=o,e[18]=y):y=e[18];let k;e[19]!==w||e[20]!==y?(k=s.jsx("span",{className:w,children:y}),e[19]=w,e[20]=y,e[21]=k):k=e[21];let D;e[22]!==k||e[23]!==x?(D=s.jsx(Vt,{className:"typography-meta",onSelect:x,children:k}),e[22]=k,e[23]=x,e[24]=D):D=e[24];let j;if(e[25]!==i||e[26]!==r||e[27]!==n){let E;e[29]!==i||e[30]!==n?(E=P=>s.jsx(Vt,{className:"typography-meta",onSelect:()=>i(P),children:s.jsx("span",{className:me("font-medium capitalize",n===P&&"text-primary"),children:P})},P),e[29]=i,e[30]=n,e[31]=E):E=e[31],j=r.map(E),e[25]=i,e[26]=r,e[27]=n,e[28]=j}else j=e[28];let S;e[32]!==D||e[33]!==j?(S=s.jsxs(zs,{align:"start",className:"max-w-[220px]",children:[D,j]}),e[32]=D,e[33]=j,e[34]=S):S=e[34];let A;return e[35]!==S||e[36]!==v?(A=s.jsxs(_s,{children:[v,S]}),e[35]=S,e[36]=v,e[37]=A):A=e[37],A};function Eh(t){const e=at.c(99),{t:n}=mt(),{open:r,onOpenChange:a,target:i,projectDirectory:o,submitting:c,onConfirm:d}=t,p=c===void 0?!1:c,m=gt(xw),u=gt(gw),f=di(hw),b=gt(fw),h=gt(pw),v=gt(mw),x=gt(uw),g=gt(dw);let w;e[0]!==g||e[1]!==v||e[2]!==h||e[3]!==x?(w=()=>mm({providerID:h,modelID:v,variant:x,agent:g}),e[0]=g,e[1]=v,e[2]=h,e[3]=x,e[4]=w):w=e[4];const[y,k]=l.useState(w);let D,j;e[5]!==f||e[6]!==u||e[7]!==m||e[8]!==r||e[9]!==o?(D=()=>{r&&(m({directory:o}),u({directory:o}),f())},j=[r,m,u,f,o],e[5]=f,e[6]=u,e[7]=m,e[8]=r,e[9]=o,e[10]=D,e[11]=j):(D=e[10],j=e[11]),l.useEffect(D,j);let S,A;e[12]!==g||e[13]!==v||e[14]!==h||e[15]!==x||e[16]!==r?(S=()=>{r&&k(mm({providerID:h,modelID:v,variant:x,agent:g}))},A=[r,h,v,x,g],e[12]=g,e[13]=v,e[14]=h,e[15]=x,e[16]=r,e[17]=S,e[18]=A):(S=e[17],A=e[18]),l.useEffect(S,A);let E,P;e[19]!==y.modelID||e[20]!==y.providerID||e[21]!==r||e[22]!==b?(E=()=>{if(!r||b.length===0)return;const Se=b.find(Me=>Me.id===y.providerID)??b[0],De=Array.isArray(Se?.models)?Se.models:[],ye=De.some(Me=>Me.id===y.modelID),ge=De[0]?.id??"";Se?.id===y.providerID&&ye||k(Me=>({...Me,providerID:Se?.id??"",modelID:ye?Me.modelID:ge,variant:""}))},P=[r,b,y.providerID,y.modelID],e[19]=y.modelID,e[20]=y.providerID,e[21]=r,e[22]=b,e[23]=E,e[24]=P):(E=e[23],P=e[24]),l.useEffect(E,P);const C=cw;let N;if(e[25]!==y.modelID||e[26]!==y.providerID||e[27]!==b){let Se;e[29]!==y.providerID?(Se=ye=>ye.id===y.providerID,e[29]=y.providerID,e[30]=Se):Se=e[30],N=b.find(Se)?.models?.find(ye=>ye.id===y.modelID),e[25]=y.modelID,e[26]=y.providerID,e[27]=b,e[28]=N}else N=e[28];const T=N;let M;e[31]!==T?(M=T?.variants?Object.keys(T.variants):[],e[31]=T,e[32]=M):M=e[32];const R=M,O=R.length>0;let z,B;e[33]!==y.variant||e[34]!==O?(z=()=>{O||!y.variant||k(lw)},B=[O,y.variant],e[33]=y.variant,e[34]=O,e[35]=z,e[36]=B):(z=e[35],B=e[36]),l.useEffect(z,B);let $;e[37]!==y.modelID||e[38]!==y.providerID?($=y.providerID.trim().length>0&&y.modelID.trim().length>0,e[37]=y.modelID,e[38]=y.providerID,e[39]=$):$=e[39];const _=$;let Q;e[40]!==_||e[41]!==y||e[42]!==d||e[43]!==p?(Q=()=>{!_||p||d(y)},e[40]=_,e[41]=y,e[42]=d,e[43]=p,e[44]=Q):Q=e[44];const W=Q;let ne,re;e[45]!==W||e[46]!==r?(ne=()=>{if(!r)return;const Se=De=>{(De.metaKey||De.ctrlKey)&&De.key==="Enter"&&(De.preventDefault(),W())};return window.addEventListener("keydown",Se),()=>window.removeEventListener("keydown",Se)},re=[r,W],e[45]=W,e[46]=r,e[47]=ne,e[48]=re):(ne=e[47],re=e[48]),l.useEffect(ne,re);let ue;e[49]!==n||e[50]!==i?(ue=n(i==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=i,e[51]=ue):ue=e[51];const Y=ue;let le;e[52]!==a||e[53]!==p?(le=Se=>{p||a(Se)},e[52]=a,e[53]=p,e[54]=le):le=e[54];let J;e[55]!==Y?(J=s.jsx(As,{children:s.jsx(Ss,{children:Y})}),e[55]=Y,e[56]=J):J=e[56];let L;e[57]===Symbol.for("react.memo_cache_sentinel")?(L=(Se,De)=>{k(ye=>({...ye,providerID:Se,modelID:De,variant:""}))},e[57]=L):L=e[57];let V;e[58]!==y.modelID||e[59]!==y.providerID?(V=s.jsx(uo,{providerId:y.providerID,modelId:y.modelID,onChange:L}),e[58]=y.modelID,e[59]=y.providerID,e[60]=V):V=e[60];const K=!O;let X;e[61]===Symbol.for("react.memo_cache_sentinel")?(X=Se=>k(De=>({...De,variant:Se})),e[61]=X):X=e[61];let U;e[62]!==y.variant||e[63]!==K||e[64]!==R?(U=s.jsx(ow,{value:y.variant,options:R,disabled:K,onChange:X}),e[62]=y.variant,e[63]=K,e[64]=R,e[65]=U):U=e[65];let ae;e[66]===Symbol.for("react.memo_cache_sentinel")?(ae=Se=>k(De=>({...De,agent:Se})),e[66]=ae):ae=e[66];let ve;e[67]!==y.agent?(ve=s.jsx(Ll,{agentName:y.agent,filter:C,onChange:ae}),e[67]=y.agent,e[68]=ve):ve=e[68];let ie;e[69]!==V||e[70]!==U||e[71]!==ve?(ie=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[V,U,ve]}),e[69]=V,e[70]=U,e[71]=ve,e[72]=ie):ie=e[72];let fe;e[73]!==a?(fe=()=>a(!1),e[73]=a,e[74]=fe):fe=e[74];let H;e[75]!==n?(H=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[75]=n,e[76]=H):H=e[76];let ce;e[77]!==p||e[78]!==fe||e[79]!==H?(ce=s.jsx(be,{variant:"ghost",size:"sm",onClick:fe,disabled:p,children:H}),e[77]=p,e[78]=fe,e[79]=H,e[80]=ce):ce=e[80];const se=!_||p;let oe;e[81]!==p||e[82]!==n?(oe=n(p?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[81]=p,e[82]=n,e[83]=oe):oe=e[83];let te;e[84]!==W||e[85]!==se||e[86]!==oe?(te=s.jsx(be,{size:"sm",onClick:W,disabled:se,children:oe}),e[84]=W,e[85]=se,e[86]=oe,e[87]=te):te=e[87];let ke;e[88]!==ce||e[89]!==te?(ke=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[ce,te]}),e[88]=ce,e[89]=te,e[90]=ke):ke=e[90];let Ne;e[91]!==J||e[92]!==ie||e[93]!==ke?(Ne=s.jsxs(ys,{className:"max-w-lg",children:[J,ie,ke]}),e[91]=J,e[92]=ie,e[93]=ke,e[94]=Ne):Ne=e[94];let je;return e[95]!==r||e[96]!==le||e[97]!==Ne?(je=s.jsx(vs,{open:r,onOpenChange:le,children:Ne}),e[95]=r,e[96]=le,e[97]=Ne,e[98]=je):je=e[98],je}function lw(t){return{...t,variant:""}}function cw(t){return Jf(t.mode)}function dw(t){return t.currentAgentName||""}function uw(t){return t.currentVariant||""}function mw(t){return t.currentModelId}function pw(t){return t.currentProviderId}function fw(t){return t.providers}function hw(t){return t.loadAgents}function gw(t){return t.loadAgents}function xw(t){return t.loadProviders}const ad=5,Rh=15,Go=t=>{const e=Math.sqrt(t/100),n=12*e,r=24*e;return Math.ceil(n+r+1)},bw=(t,e)=>{const n=Go(e);return Math.max(n*ad,Math.min(n*Rh,n*t))},yw=async(t,e)=>{const n=await rb(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},vw=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,ww=t=>{const e=at.c(20),{id:n,children:r}=t;let a;e[0]!==n?(a={id:n},e[0]=n,e[1]=a):a=e[1];const{attributes:i,listeners:o,setNodeRef:c,setActivatorNodeRef:d,transform:p,transition:m,isDragging:u}=Nl(a);let f;e[2]!==p?(f=Sl.Transform.toString(p),e[2]=p,e[3]=f):f=e[3];let b;e[4]!==f||e[5]!==m?(b={transform:f,transition:m},e[4]=f,e[5]=m,e[6]=b):b=e[6];const h=u&&"opacity-60";let v;e[7]!==h?(v=me(h),e[7]=h,e[8]=v):v=e[8];let x;e[9]!==i||e[10]!==r||e[11]!==u||e[12]!==o||e[13]!==d?(x=r({attributes:i,listeners:o,setActivatorNodeRef:d,isDragging:u}),e[9]=i,e[10]=r,e[11]=u,e[12]=o,e[13]=d,e[14]=x):x=e[14];let g;return e[15]!==c||e[16]!==b||e[17]!==v||e[18]!==x?(g=s.jsx("li",{ref:c,style:b,className:v,children:x}),e[15]=c,e[16]=b,e[17]=v,e[18]=x,e[19]=g):g=e[19],g},jw=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:a})=>{const{t:i}=mt(),[o,c]=l.useState(!1),[d,p]=l.useState(""),[m,u]=l.useState([]),[f,b]=l.useState(""),[h,v]=l.useState(null),[x,g]=l.useState(()=>new Set),[w,y]=l.useState([]),[k,D]=l.useState(null),[j,S]=l.useState(!1),[A,E]=l.useState(0),P=l.useRef(!1),C=l.useRef(""),N=Te(F=>F.todoPanelHeight),T=Te(F=>F.setTodoPanelHeight),M=Te(F=>F.notesPanelHeight),R=Te(F=>F.setNotesPanelHeight),[O,z]=l.useState(!1),B=l.useRef(0),$=l.useRef(N),_=_t(F=>F.currentSessionId),Q=_t(F=>F.createSession),W=_t(F=>F.initializeNewOpenChamberSession),ne=_t(F=>F.sendMessage),re=_t(F=>F.setCurrentSession),ue=Ea(F=>F.setPendingInputText),Y=Ws(F=>F.currentDirectory),le=Te(F=>F.openContextPanelTab),J=Te(F=>F.setActiveMainTab),L=Te(F=>F.setSessionSwitcherOpen),V=Te(F=>F.padding),K=l.useCallback(async(F,ee)=>{if(!t)return!1;const Ce=await tb(t,{notes:F,todos:ee});return Ce||G.error(i("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),Ce},[t,i]);l.useEffect(()=>{if(!t){p(""),u([]),y([]),b(""),g(new Set);return}let F=!1;return c(!0),(async()=>{try{const ee=await sb(t),Ce=await Promise.all(ee.plans.map(Fe=>yw(Fe,i("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(F)return;p(ee.notes),u(ee.todos),y(Ce),C.current=ee.notes,P.current=!0,b(""),g(new Set)}catch{F||(G.error(i("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),p(""),u([]),y([]),C.current="",P.current=!0)}finally{F||c(!1)}})(),()=>{F=!0}},[A,t,i]),l.useEffect(()=>{if(!t)return;const F=ee=>{const Ce=ee.detail;Ce?.projectId&&Ce.projectId!==t.id||E(Fe=>Fe+1)};return window.addEventListener("openchamber:project-plan-saved",F),window.addEventListener("openchamber:project-notes-updated",F),()=>{window.removeEventListener("openchamber:project-plan-saved",F),window.removeEventListener("openchamber:project-notes-updated",F)}},[t]),l.useEffect(()=>{if(m.length<7)return;const F=bw(m.length,V),ee=Go(V)*ad;(N<ee||N>F)&&T(F)},[m.length,V,N,T]),l.useEffect(()=>{if(!O)return;const F=Ce=>{const Fe=Ce.clientY-B.current,we=Math.min(Go(V)*Rh,Math.max(Go(V)*ad,$.current+Fe));T(we)},ee=()=>{z(!1)};return window.addEventListener("pointermove",F),window.addEventListener("pointerup",ee,{once:!0}),window.addEventListener("pointercancel",ee,{once:!0}),()=>{window.removeEventListener("pointermove",F),window.removeEventListener("pointerup",ee),window.removeEventListener("pointercancel",ee)}},[O,V,T]);const X=l.useCallback(F=>{z(!0),B.current=F.clientY,$.current=N,F.preventDefault()},[N]),U=l.useCallback(()=>{C.current=d,K(d,m)},[d,K,m]);l.useEffect(()=>{if(!t||!P.current||d===C.current)return;const F=window.setTimeout(()=>{C.current=d,K(d,m)},400);return()=>{window.clearTimeout(F)}},[d,K,t,m]);const ae=l.useCallback(()=>{const F=f.trim();if(!F)return;const ee=[...m,{id:vw(),text:F.slice(0,yo),completed:!1,createdAt:Date.now()}];u(ee),b(""),K(d,ee)},[f,d,K,m]),ve=l.useCallback(F=>{g(ee=>{const Ce=new Set(ee);return Ce.has(F)?Ce.delete(F):Ce.add(F),Ce})},[]),ie=l.useCallback((F,ee)=>{const Ce=m.map(Fe=>Fe.id===F?{...Fe,completed:ee}:Fe);u(Ce),K(d,Ce)},[d,K,m]),fe=l.useCallback(F=>{const ee=m.filter(Ce=>Ce.id!==F);u(ee),K(d,ee)},[d,K,m]),H=l.useCallback(()=>{const F=m.filter(ee=>!ee.completed);F.length!==m.length&&(u(F),K(d,F))},[d,K,m]),ce=l.useCallback(F=>{const{active:ee,over:Ce}=F;if(!Ce||ee.id===Ce.id)return;const Fe=m.findIndex(pe=>pe.id===ee.id),we=m.findIndex(pe=>pe.id===Ce.id);if(Fe===-1||we===-1)return;const Qe=Ff(m,Fe,we);u(Qe),K(d,Qe)},[d,K,m]),se=Hi(ni(Gi,{activationConstraint:{distance:8}})),oe=f.slice(0,yo),te=m.reduce((F,ee)=>F+(ee.completed?1:0),0),ke=l.useCallback(()=>{J("chat"),L(!1)},[J,L]),Ne=l.useCallback((F,ee)=>{!t||h||D({kind:"session",todoId:F,todoText:ee})},[t,h]),je=l.useCallback(F=>{if(!_){G.error(i("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}ke();const ee=`\`\`\`md
|
|
4
|
+
${F}
|
|
5
|
+
\`\`\``;ue(ee,"append"),G.success(i("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[_,r,ke,ue,i]),Se=l.useCallback((F,ee)=>{if(!(!t||h)){if(!n){G.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}D({kind:"worktree",todoId:F,todoText:ee})}},[n,t,h,i]),De=l.useCallback(async F=>{if(!t||!k)return;const ee=await Nn("plan.todo.visible",{todo_text:k.todoText}),Fe=[{synthetic:!0,text:await Nn("plan.todo.instructions",{todo_text:k.todoText})}];S(!0),v(k.todoId);try{ke();let we=null,Qe=t.path;if(k.kind==="worktree"){if(!n){G.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const Oe=await Qf(t.path,Xf());if(!Oe?.id)return;we=Oe.id,Qe=null}else{const Oe=await Q(void 0,t.path,null);if(!Oe?.id){G.error(i("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}we=Oe.id,Qe=Oe.directory??t.path,W(Oe.id,gt.getState().agents??[])}if(!we)return;const pe=Pl.getState();pe.saveSessionModelSelection(we,F.providerID,F.modelID),F.agent.trim()&&(pe.saveSessionAgentSelection(we,F.agent),pe.saveAgentModelForSession(we,F.agent,F.providerID,F.modelID),pe.saveAgentModelVariantForSession(we,F.agent,F.providerID,F.modelID,F.variant||void 0)),re(we,Qe),await ne(ee,F.providerID,F.modelID,F.agent.trim()||void 0,void 0,void 0,Fe,F.variant||void 0),G.success(k.kind==="worktree"?i("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):i("rightSidebar.contextNotesTodo.toast.sentToNewSession")),D(null),r?.()}catch(we){const Qe=we instanceof Error?we.message:void 0;G.error(i("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),Qe?{description:Qe}:void 0)}finally{S(!1),v(null)}},[n,Q,W,r,k,t,ke,ne,re,i]),ye=l.useRef(null),[ge,Me]=l.useState(!1),[Ue,q]=l.useState(null),Ie=l.useCallback(async F=>{if(!(!t||Ue)){q(F);try{if(!await nb(t,F)){G.error(i("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}y(Ce=>Ce.filter(Fe=>Fe.id!==F)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}}))}finally{q(null)}}},[Ue,t,i]),Le=l.useCallback(async()=>{if(!t||ge)return;const F=await Zf({defaultPath:t.path,filters:[{name:"Plan files",extensions:["md","markdown","txt"]},{name:"All files",extensions:["*"]}]});if(F.success&&F.path){Me(!0);try{const ee=new URLSearchParams({path:F.path,allowOutsideWorkspace:"true"}),Ce=await fetch(`/api/fs/read?${ee.toString()}`,{cache:"no-store"});if(!Ce.ok){G.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"));return}const Fe=await Ce.text();if(!Fe.trim()){G.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const we=F.path.split("/").pop()?.replace(/\.(md|markdown|txt)$/i,"").trim()||"";if(!await vu(t,Fe,we)){G.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),G.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(ee){const Ce=ee instanceof Error?ee.message:void 0;G.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),Ce?{description:Ce}:void 0)}finally{Me(!1)}}else F.error==="Native file picker not available"&&ye.current?.click()},[ge,t,i]),Pe=l.useCallback(async F=>{if(!(!t||!F)){Me(!0);try{const ee=await F.text();if(!ee.trim()){G.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const Ce=F.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await vu(t,ee,Ce)){G.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),G.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(ee){const Ce=ee instanceof Error?ee.message:void 0;G.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),Ce?{description:Ce}:void 0)}finally{Me(!1)}}},[t,i]),he=l.useCallback(F=>{const ee=t?.path?.trim(),Ce=Y?.trim()||ee;Ce&&le(Ce,{mode:"plan",targetPath:F.path,dedupeKey:F.path,label:F.title})},[Y,le,t]);return t?s.jsxs("div",{className:me("w-full min-w-0 space-y-3 p-3",a),children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"min-w-0 truncate typography-ui-label font-semibold text-foreground",title:t.path,children:i("rightSidebar.contextNotesTodo.notes.title",{project:e?.trim()||t.path.split("/").filter(Boolean).pop()||t.path})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d.length,"/",wu]})]}),s.jsx(bn,{value:d,onChange:F=>p(F.target.value.slice(0,wu)),onBlur:U,placeholder:i("rightSidebar.contextNotesTodo.notes.placeholder"),resizedHeight:M,onResizeHeightChange:R,useScrollShadow:!0,scrollShadowSize:56,disabled:o})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:m.length===1?i("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:m.length}):i("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:m.length})}),s.jsx("button",{type:"button",onClick:H,disabled:o||te===0,className:"typography-meta rounded-md px-1.5 py-0.5 text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",children:i("rightSidebar.contextNotesTodo.todo.clearCompleted")})]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[oe.length,"/",yo]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Wt,{value:oe,onChange:F=>b(F.target.value.slice(0,yo)),onKeyDown:F=>{F.key==="Enter"&&(F.preventDefault(),ae())},placeholder:i("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:o,className:"h-8"}),s.jsx("button",{type:"button",onClick:ae,disabled:o||oe.trim().length===0,className:"inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.addAria"),title:i("rightSidebar.contextNotesTodo.todo.addAria"),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})]}),s.jsx("div",{className:me("overflow-y-auto rounded-lg border border-border/60 bg-background/40",O&&"transition-none"),style:m.length<7?void 0:{height:`${N}px`,maxHeight:`${N}px`},children:m.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.todo.empty")}):s.jsx(qi,{sensors:se,collisionDetection:Yi,onDragEnd:ce,children:s.jsx(sl,{items:m.map(F=>F.id),strategy:Hc,children:s.jsx("ul",{className:"divide-y divide-border/50",children:m.map(F=>{const ee=x.has(F.id);return s.jsx(ww,{id:F.id,children:Ce=>s.jsxs("div",{className:"flex items-start gap-1.5 px-2.5 py-1.5",children:[s.jsx("button",{type:"button",ref:Ce.setActivatorNodeRef,...Ce.attributes,...Ce.listeners,onClick:Fe=>{Fe.preventDefault(),Fe.stopPropagation()},className:"flex h-6 w-4 flex-shrink-0 touch-none items-center justify-center text-muted-foreground hover:text-foreground","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:F.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:F.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(fs,{checked:F.completed,onChange:Fe=>ie(F.id,Fe),ariaLabel:i("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:F.text})})}),s.jsx("button",{type:"button",onClick:()=>ve(F.id),className:me("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-6 text-foreground",ee?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",F.completed&&"text-muted-foreground line-through"),title:ee?void 0:F.text,"aria-label":ee?i("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:F.text}):i("rightSidebar.contextNotesTodo.todo.actions.expand",{text:F.text}),children:F.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>fe(F.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:F.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:F.text}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(_s,{children:[s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",disabled:h===F.id,className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.send",{text:F.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.send",{text:F.text}),children:s.jsx(I,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs(zs,{align:"end",className:"w-56",children:[s.jsx(Vt,{onClick:()=>je(F.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx(Vt,{onClick:()=>Ne(F.id,F.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx(Vt,{onClick:()=>{Se(F.id,F.text)},disabled:!n,children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]})},F.id)})})})})}),m.length>=7&&s.jsx("div",{className:me("h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",O&&"bg-[var(--interactive-border)]"),onPointerDown:X,role:"separator","aria-orientation":"horizontal","aria-label":i("rightSidebar.contextNotesTodo.todo.resizeAria")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.plans.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:w.length===1?i("rightSidebar.contextNotesTodo.plans.filesSingle",{count:w.length}):i("rightSidebar.contextNotesTodo.plans.filesPlural",{count:w.length})})]}),s.jsx("input",{ref:ye,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:F=>{const ee=F.target.files?.[0]??null;Pe(ee),F.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:Le,disabled:!t||ge,className:"inline-flex h-6 w-6 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.plans.importFromFile"),title:i("rightSidebar.contextNotesTodo.plans.importFromFile"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:w.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.plans.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:w.map(F=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>he(F),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:F.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(F.createdAt).toLocaleDateString()})]}),s.jsx("button",{type:"button",onClick:()=>{Ie(F.id)},disabled:Ue===F.id,className:"inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",title:i("rightSidebar.contextNotesTodo.plans.deletePlan"),"aria-label":i("rightSidebar.contextNotesTodo.plans.deletePlanWithTitle",{title:F.title}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},F.id))})})]}),s.jsx(Eh,{open:k!==null,onOpenChange:F=>{!F&&!j&&D(null)},target:k?.kind??"session",projectDirectory:t?.path??null,submitting:j,onConfirm:De})]}):s.jsx("div",{className:me("w-full min-w-0 p-3",a),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.empty.selectProject")})})},Fh=12,Nw=[{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"}],Sw=t=>{const e=at.c(18),{isActive:n,burstKey:r,className:a,durationMs:i,bursts:o,onComplete:c}=t,d=r===void 0?0:r,p=i===void 0?900:i,m=o===void 0?Nw:o,u=ze.useRef(!1);let f,b;e[0]!==n||e[1]!==c?(f=()=>{!n&&u.current&&c?.(),n&&(u.current=!0)},b=[n,c],e[0]=n,e[1]=c,e[2]=f,e[3]=b):(f=e[2],b=e[3]),ze.useEffect(f,b);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=Array.from({length:Fh},kw),e[4]=h):h=e[4];const v=h;if(!n)return null;let x;e[5]!==a?(x=me("fireworks-overlay pointer-events-none",a),e[5]=a,e[6]=x):x=e[6];let g;if(e[7]!==d||e[8]!==m||e[9]!==p){let y;e[11]!==d||e[12]!==p?(y=k=>{const D={"--burst-delay":`${k.delay}ms`,"--burst-x":`${k.x}%`,"--burst-y":`${k.y}%`,"--firework-color":`var(${k.colorVar})`,"--firework-duration":`${p}ms`};return s.jsx("div",{className:"firework-burst",style:D,children:v.map((j,S)=>{const A=j.x*k.radius,E=j.y*k.radius,P={"--translate-x":`${A}px`,"--translate-y":`${E}px`,"--particle-delay":`${j.delay}ms`,color:`var(${k.colorVar})`};return s.jsx("span",{className:"firework-particle",style:P},`${k.id}-${S}-${d}`)})},`${k.id}-${d}`)},e[11]=d,e[12]=p,e[13]=y):y=e[13],g=m.map(y),e[7]=d,e[8]=m,e[9]=p,e[10]=g}else g=e[10];let w;return e[14]!==d||e[15]!==x||e[16]!==g?(w=s.jsx("div",{className:x,"aria-hidden":"true","data-burst-key":d,children:g}),e[14]=d,e[15]=x,e[16]=g,e[17]=w):w=e[17],w};function kw(t,e){const n=Math.PI*2*e/Fh;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const Cw=t=>{const e=at.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,a=r===void 0?3400:r;let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={isActive:!1,cycle:0},e[2]=i):i=e[2];const[o,c]=ze.useState(i),d=ze.useRef(null);let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=p):p=e[3];const m=p;let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{m(),c(Iw)},e[4]=u):u=e[4];const f=u;let b;e[5]!==a?(b=()=>{m(),c(Pw),d.current=window.setTimeout(()=>{c(Aw),d.current=null},a)},e[5]=a,e[6]=b):b=e[6];const h=b;let v,x;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>()=>m(),x=[m],e[7]=v,e[8]=x):(v=e[7],x=e[8]),ze.useEffect(v,x);let g;return e[9]!==o.cycle||e[10]!==o.isActive||e[11]!==h?(g={isActive:o.isActive,burstKey:o.cycle,triggerFireworks:h,dismissFireworks:f},e[9]=o.cycle,e[10]=o.isActive,e[11]=h,e[12]=g):g=e[12],g};function Iw(t){return t.isActive?{...t,isActive:!1}:t}function Pw(t){return{isActive:!0,cycle:t.cycle+1}}function Aw(t){return t.isActive?{...t,isActive:!1}:t}const Lh=l.createContext(void 0),Dw=t=>{const e=at.c(10),{children:n}=t,{isActive:r,burstKey:a,triggerFireworks:i,dismissFireworks:o}=Cw();let c;e[0]!==o||e[1]!==i?(c={triggerFireworks:i,dismissFireworks:o},e[0]=o,e[1]=i,e[2]=c):c=e[2];const d=c;let p;e[3]!==a||e[4]!==r?(p=s.jsx(Sw,{isActive:r,burstKey:a}),e[3]=a,e[4]=r,e[5]=p):p=e[5];let m;return e[6]!==n||e[7]!==p||e[8]!==d?(m=s.jsxs(Lh.Provider,{value:d,children:[n,p]}),e[6]=n,e[7]=p,e[8]=d,e[9]=m):m=e[9],m},Tw=()=>{const t=l.useContext(Lh);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},Zn=ar()(vi(ro((t,e)=>({selectedProfileId:null,defaultGitIdentityId:null,profiles:[],globalIdentity:null,discoveredCredentials:[],isLoading:!1,setSelectedProfile:n=>{t({selectedProfileId:n})},loadProfiles:async()=>{t({isLoading:!0});const n=e().profiles;try{const r=await db();return t({profiles:r,isLoading:!1}),!0}catch(r){return console.error("Failed to load git identity profiles:",r),t({profiles:n,isLoading:!1}),!1}},loadGlobalIdentity:async()=>{try{const n=await cb();if(n&&n.userName&&n.userEmail){const r={id:"global",name:"Global Identity",userName:n.userName,userEmail:n.userEmail,authType:n.sshCommand?"ssh":void 0,sshKey:n.sshCommand?n.sshCommand.replace("ssh -i ",""):null,color:"info",icon:"house"};t({globalIdentity:r})}else t({globalIdentity:null});return!0}catch(n){return console.error("Failed to load global git identity:",n),t({globalIdentity:null}),!1}},loadDiscoveredCredentials:async()=>{try{const n=await lb();return t({discoveredCredentials:n}),!0}catch(n){return console.error("Failed to discover git credentials:",n),t({discoveredCredentials:[]}),!1}},loadDefaultGitIdentityId:async()=>{const n=r=>{if(typeof r!="string")return null;const a=r.trim();return a.length>0?a:null};try{let r=null;if(r===null){const a=hr()?.settings;if(a)try{const o=(await a.load())?.settings||{};r=n(o.defaultGitIdentityId)}catch{}}if(r===null)try{const a=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(a.ok){const i=await a.json().catch(()=>null);r=n(i?.defaultGitIdentityId)}}catch{}return t({defaultGitIdentityId:r}),!0}catch(r){return console.error("Failed to load default git identity setting:",r),!1}},setDefaultGitIdentityId:async n=>{try{const r=typeof n=="string"?n.trim():"",a=r.length>0?r:"";return await Ms({defaultGitIdentityId:a}),t({defaultGitIdentityId:a.length>0?a:null}),!0}catch(r){return console.error("Failed to save default git identity setting:",r),!1}},createProfile:async n=>{try{const r={...n,id:n.id||`profile-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,color:n.color||"keyword",icon:n.icon||"branch"};return await ob(r),await e().loadProfiles(),!0}catch(r){return console.error("Failed to create git identity profile:",r),!1}},updateProfile:async(n,r)=>{try{const a=e().profiles.find(o=>o.id===n);if(!a)throw new Error("Profile not found");const i={...a,...r};return await ib(n,i),await e().loadProfiles(),!0}catch(a){return console.error("Failed to update git identity profile:",a),!1}},deleteProfile:async n=>{try{return await ab(n),e().selectedProfileId===n&&t({selectedProfileId:null}),await e().loadProfiles(),!0}catch(r){return console.error("Failed to delete git identity profile:",r),!1}},getProfileById:n=>{const{profiles:r,globalIdentity:a}=e();return n==="global"?a||void 0:r.find(i=>i.id===n)},getUnimportedCredentials:()=>{const{profiles:n,discoveredCredentials:r}=e();return r.filter(a=>!n.some(i=>i.authType==="token"&&i.host===a.host))}}),{name:"git-identities-store",storage:kl(()=>sa()),partialize:t=>({selectedProfileId:t.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=Zn);function La(t){const e=at.c(12);let n,r,a;e[0]!==t?({className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a):(n=e[1],r=e[2],a=e[3]);let i;e[4]!==a?(i={color:"var(--surface-elevated-foreground)",...a},e[4]=a,e[5]=i):i=e[5];let o;e[6]!==n?(o=me("flex h-full w-full flex-col overflow-hidden rounded-xl",n),e[6]=n,e[7]=o):o=e[7];let c;return e[8]!==r||e[9]!==i||e[10]!==o?(c=s.jsx(za,{"data-slot":"command",style:i,className:o,...r}),e[8]=r,e[9]=i,e[10]=o,e[11]=c):c=e[11],c}const oa=ze.forwardRef((t,e)=>{const n=at.c(10);let r,a;n[0]!==t?({className:r,...a}=t,n[0]=t,n[1]=r,n[2]=a):(r=n[1],a=n[2]);let i;n[3]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(I,{name:"search",className:"size-4 shrink-0 opacity-50"}),n[3]=i):i=n[3];let o;n[4]!==r?(o=me("placeholder:text-muted-foreground flex h-8 w-full rounded-lg bg-transparent py-2 typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",r),n[4]=r,n[5]=o):o=n[5];let c;return n[6]!==a||n[7]!==e||n[8]!==o?(c=s.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-8 items-center gap-2 border-b px-3",children:[i,s.jsx(za.Input,{ref:e,"data-slot":"command-input",className:o,...a})]}),n[6]=a,n[7]=e,n[8]=o,n[9]=c):c=n[9],c});oa.displayName="CommandInput";function Oa(t){const e=at.c(14);let n,r,a,i,o;e[0]!==t?({className:r,children:n,scrollbarClassName:o,disableHorizontal:a,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i,e[5]=o):(n=e[1],r=e[2],a=e[3],i=e[4],o=e[5]);let c;e[6]!==r?(c=me("scroll-py-1 overflow-x-hidden h-full min-h-0",r),e[6]=r,e[7]=c):c=e[7];const d=o??"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",p=a??!0;let m;return e[8]!==n||e[9]!==i||e[10]!==c||e[11]!==d||e[12]!==p?(m=s.jsx(Es,{as:za.List,"data-slot":"command-list",outerClassName:"max-h-[min(600px,calc(100vh-10rem))] overflow-x-hidden p-0 w-full h-full min-h-0",className:c,scrollbarClassName:d,disableHorizontal:p,...i,children:n}),e[8]=n,e[9]=i,e[10]=c,e[11]=d,e[12]=p,e[13]=m):m=e[13],m}function $a(t){const e=at.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(za.Empty,{"data-slot":"command-empty",className:"py-6 text-center typography-ui-label",...n}),e[2]=n,e[3]=r):r=e[3],r}function zn(t){const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=me("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(za.Group,{"data-slot":"command-group",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function ka(t){const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=me("bg-border -mx-1 h-px",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(za.Separator,{"data-slot":"command-separator",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function Dn(t){const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=me("data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(za.Item,{"data-slot":"command-item",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function Mw(t){const e=at.c(12);let n,r,a,i;if(e[0]!==t){const{className:c,...d}=t,p=Rw,m=typeof d.children=="string"?d.children:"",u=m?m.split("+").map(Ew).filter(Boolean):[];n="command-shortcut",e[5]!==c?(r=me("text-muted-foreground ml-auto flex items-center gap-1 typography-meta",c),e[5]=c,e[6]=r):r=e[6],a=d,i=u.length>0?u.map((f,b)=>s.jsxs(ze.Fragment,{children:[b>0&&s.jsx("span",{className:"opacity-60 text-xs",children:"+"}),p(f)]},`${f}-${b}`)):d.children,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i}else n=e[1],r=e[2],a=e[3],i=e[4];let o;return e[7]!==n||e[8]!==r||e[9]!==a||e[10]!==i?(o=s.jsx("span",{"data-slot":n,className:r,...a,children:i}),e[7]=n,e[8]=r,e[9]=a,e[10]=i,e[11]=o):o=e[11],o}function Ew(t){return t.trim()}function Rw(t){const e=t.trim().toLowerCase();return e==="ctrl"||e==="control"?s.jsx("span",{className:"text-xs font-medium",children:"ctrl"}):e==="cmd"||e==="⌘"||e==="command"||e==="meta"?s.jsx(I,{name:"command",className:"size-3.5"}):e==="shift"||e==="⇧"?s.jsx(I,{name:"arrow-up",className:"size-3.5"}):s.jsx("span",{className:"text-xs font-medium",children:t})}const id=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Fw=t=>{const e=id(t);if(!e)return null;const r=e.indexOf("/.git/worktrees/");return r>0&&e.slice(0,r)||null};function Lw(t,e,n){const r=at.c(5),[a,i]=l.useState();let o,c;return r[0]!==n||r[1]!==t||r[2]!==e?(o=()=>{if(e){i(void 0);return}if(!t){i(void 0);return}i(void 0);let d=!1;return(async()=>{const[p,m]=await Promise.all([Ks("git rev-parse --absolute-git-dir",t),Ks("git rev-parse --show-toplevel",t)]);if(d||!p.success||!m.success)return;const u=id((p.stdout||"").trim()),f=Fw(u);if(!f)return;const b=id((m.stdout||"").trim());if(!b||b===f)return;const h=n||"",v=b.split("/").filter(Boolean).pop()||b;i({source:"sdk",path:b,projectDirectory:f,branch:h,label:h||v,name:v,worktreeRoot:b,worktreeStatus:"ready",headState:h?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},c=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=o,r[4]=c):(o=r[3],c=r[4]),l.useEffect(o,c),e??a}const er=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},xi=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),Hr=t=>!!t.success,Ol=t=>(t.stdout||"").trim(),Aa=t=>(t.stderr||"").trim();async function Ow(t){const n=((await Ks("git worktree list --porcelain",t)).stdout||"").split(/\r?\n/),r=[];let a=null;for(const i of n){if(i.startsWith("worktree ")){a&&r.push(a),a={path:i.slice(9).trim(),branchRef:null};continue}a&&i.startsWith("branch ")&&(a.branchRef=i.slice(7).trim())}return a&&r.push(a),r.filter(i=>!!i.path)}async function $w(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),a=(await Ow(t.repoRoot)).filter(o=>o.branchRef===e).map(o=>o.path).filter(o=>o&&!n.has(o)),i=[];for(const o of a){const c=await Ks("git status --porcelain",o);Ol(c)||i.push(o)}return i}async function Oh(t,e){for(const n of e)await Ks("git reset --hard",n).catch(()=>{})}async function Bw(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await Ks(`git show-ref --verify --quiet ${er(`refs/heads/${n}`)}`,t);if(Hr(r))return n;if(n.startsWith("remotes/")){const o=n.slice(8).split("/"),c=o[0]||"origin",d=o.slice(1).join("/");if(d)return await Ks(`git branch --track ${er(d)} ${er(`${c}/${d}`)}`,t),d}const a=await Ks(`git show-ref --verify --quiet ${er(`refs/remotes/origin/${n}`)}`,t);return Hr(a)&&await Ks(`git branch --track ${er(n)} ${er(`origin/${n}`)}`,t),n}async function Ii(t){const e=t.repoRoot,n=t.sourceBranch.trim(),r=t.targetBranch.trim();if(!n||!r)return{repoRoot:e,sourceBranch:n,targetBranch:r,commits:[]};const a=await Bw(e,r),i=await Ks(`git cherry ${er(a)} ${er(n)}`,e),o=xi(i.stdout),c=new Set;for(const u of o){const f=u.match(/^\+\s+([0-9a-f]{7,40})\b/i);f&&c.add(f[1])}const d=await Ks(`git rev-list --reverse ${er(`${a}..${n}`)}`,e),m=xi(d.stdout).filter(u=>c.has(u));return{repoRoot:e,sourceBranch:n,targetBranch:a,commits:m}}async function zw(t,e){const n=await Ks('mkdir -p "$HOME/.config/openchamber/tmp"',t);if(!Hr(n))throw new Error(Aa(n)||"Failed to create temp directory parent");const r=await Ks('mktemp -d "$HOME/.config/openchamber/tmp/oc-integrate-XXXXXX"',t),a=Ol(r);if(!a)throw new Error(Aa(r)||"Failed to create temp directory");const i=await Ks(`git worktree add --force ${er(a)} ${er(e)}`,t);if(!Hr(i))throw new Error(Aa(i)||"Failed to create temp worktree");return a}async function ml(t,e){await Ks(`git worktree remove --force ${er(e)}`,t).catch(()=>{}),await Ks("git worktree prune",t).catch(()=>{})}async function _w(t){const e=await Ks("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=Ol(e);if(!n)return;await Ks("git fetch",t);const r=await Ks(`git merge --ff-only ${er(n)}`,t);if(!Hr(r))throw new Error(Aa(r)||"Fast-forward failed")}async function pl(t){const e=await Ks("git status --porcelain",t),n=await Ks("git diff --name-only --diff-filter=U",t),r=await Ks("git diff",t),a=await Ks("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),i=await Ks("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:xi(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:a.stdout||a.stderr||"",currentPatch:i.stdout||i.stderr||""}}async function Vw(t){return pl(t)}async function Uw(t){const e=await Ks("git rev-parse --verify --quiet CHERRY_PICK_HEAD",t);return Hr(e)}async function Ww(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await zw(t.repoRoot,t.targetBranch);let n=[];try{await _w(e);const r=await Ks("git status --porcelain",e);if(Ol(r))throw new Error("Target branch has local changes; abort integration and retry");const a=await $w({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const i=n[0],o=await Ks(`git cherry-pick ${er(i)}`,e);if(Hr(o)){n.shift();continue}const c=await Ks("git diff --name-only --diff-filter=U",e);if(xi(c.stdout).length>0){const p=await pl(e);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:e,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:a,remainingCommits:n,currentCommit:i},details:p}}throw new Error(Aa(o)||"Cherry-pick failed")}return await ml(t.repoRoot,e),await Oh(t.repoRoot,a).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await ml(t.repoRoot,e).catch(()=>{}),r}}async function Kw(t){await Ks("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await ml(t.repoRoot,t.tempWorktreePath)}async function Hw(t){const e=await Ks("git cherry-pick --continue",t.tempWorktreePath);if(!Hr(e)){const i=await Ks("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(xi(i.stdout).length>0){const c=await pl(t.tempWorktreePath);return{kind:"conflict",state:t,details:c}}throw new Error(Aa(e)||"Cherry-pick continue failed")}const n=t.tempWorktreePath,r=[...t.remainingCommits];r.length>0&&r[0]===t.currentCommit&&r.shift();const a=[...r];for(;a.length>0;){const i=a[0],o=await Ks(`git cherry-pick ${er(i)}`,n);if(Hr(o)){a.shift();continue}const c=await Ks("git diff --name-only --diff-filter=U",n);if(xi(c.stdout).length>0){const p=await pl(n);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:n,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:t.cleanTargetWorktrees,remainingCommits:a,currentCommit:i},details:p}}throw new Error(Aa(o)||"Cherry-pick failed")}return await ml(t.repoRoot,t.tempWorktreePath),await Oh(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:t.remainingCommits.length}}const Gw=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:a,refreshKey:i,onRefresh:o})=>{const{t:c}=mt(),d=_t($=>$.currentSessionId),p=Te($=>$.setActiveMainTab),[m,u]=ze.useState(!1),f=ze.useRef(null),[b,h]=ze.useState(a);ze.useEffect(()=>{h(a)},[a]),ze.useEffect(()=>{if(m){const $=setTimeout(()=>{f.current?.focus()},0);return()=>clearTimeout($)}},[m]);const v=!!(t&&e&&b&&b!=="HEAD"&&e!==b),[x,g]=ze.useState({kind:"idle"}),[w,y]=ze.useState(!1),[k,D]=ze.useState([]),j=ze.useMemo(()=>d?`openchamber.integrate.conflict:${d}`:null,[d]);ze.useEffect(()=>{if(!j||typeof window>"u")return;const $=window.localStorage.getItem(j);if(!$)return;let _=!1;try{const Q=JSON.parse($);if(!Q?.tempWorktreePath||Q.repoRoot!==t){window.localStorage.removeItem(j);return}(async()=>{const W=await Uw(Q.tempWorktreePath).catch(()=>!1);if(_)return;if(!W){window.localStorage.removeItem(j);return}const ne=await Vw(Q.tempWorktreePath).catch(()=>null);_||ne&&g({kind:"conflict",state:Q,details:ne})})()}catch{window.localStorage.removeItem(j)}return()=>{_=!0}},[j,t]),ze.useEffect(()=>{if(!v){g({kind:"idle"});return}let $=!1;return g({kind:"loading"}),(async()=>{try{const _=await Ii({repoRoot:t,sourceBranch:e,targetBranch:b});if($)return;if(g({kind:"ready",plan:_}),_.commits.length>0){const ne=_.commits.slice(-50).reverse().map(le=>JSON.stringify(le)).join(" "),ue=((await Ks(`git show -s --format=%H%x09%h%x09%s ${ne}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),Y=[];for(const le of ue){const[J,L,V]=le.split(" ");!J||!L||Y.push({sha:J,short:L,subject:V||""})}$||(D(Y),y(!1))}else $||(D([]),y(!1))}catch{$||g({kind:"idle"})}})(),()=>{$=!0}},[v,t,e,b,i]);const S=ze.useCallback($=>{d&&_t.getState().setWorktreeMetadata(d,{...n,createdFromBranch:$})},[d,n]),A=_t($=>$.openNewSessionDraft),E=ze.useCallback(async $=>{const _=await Nn("git.integrate.cherrypick.resolve.visible",{current_commit:$.state.currentCommit,target_branch:$.state.targetBranch}),Q=await Nn("git.integrate.cherrypick.resolve.instructions",{repo_root:$.state.repoRoot,temp_worktree_path:$.state.tempWorktreePath,source_branch:$.state.sourceBranch,target_branch:$.state.targetBranch,current_commit:$.state.currentCommit}),W=`Cherry-pick conflict context (JSON)
|
|
6
|
+
${JSON.stringify({repoRoot:$.state.repoRoot,tempWorktreePath:$.state.tempWorktreePath,sourceBranch:$.state.sourceBranch,targetBranch:$.state.targetBranch,currentCommit:$.state.currentCommit,remainingCommits:$.state.remainingCommits,statusPorcelain:$.details.statusPorcelain,unmergedFiles:$.details.unmergedFiles,currentPatchMeta:$.details.currentPatchMeta,currentPatch:$.details.currentPatch,diff:$.details.diff},null,2)}`;return{visibleText:_,instructionsText:Q,payloadText:W}},[]),P=Ea($=>$.setPendingInputText),C=Ea($=>$.setPendingSyntheticParts),N=ze.useCallback(async($,_)=>{const Q=await E($);if(_){A({directoryOverride:$.state.tempWorktreePath,initialPrompt:Q.visibleText,syntheticParts:[{text:Q.instructionsText,synthetic:!0},{text:Q.payloadText,synthetic:!0}]}),p("chat");return}if(!d){G.error(c("gitView.integrate.noActiveSession"),{description:c("gitView.integrate.noActiveSessionDescription")});return}P(Q.visibleText,"replace"),C([{text:Q.instructionsText,synthetic:!0},{text:Q.payloadText,synthetic:!0}]),p("chat")},[d,p,E,A,P,C,c]),T=ze.useCallback(async()=>{if(x.kind==="ready"){if(x.plan.commits.length===0){G.message(c("gitView.integrate.noCommitsToMoveToast"));return}g({kind:"running",plan:x.plan});try{const $=await Ww(x.plan);if($.kind==="success"){G.success(c("gitView.integrate.commitsMovedToast"),{description:$.moved===1?c("gitView.integrate.commitsMovedDescriptionSingle",{count:$.moved,branch:x.plan.targetBranch}):c("gitView.integrate.commitsMovedDescriptionPlural",{count:$.moved,branch:x.plan.targetBranch})});const _=await Ii(x.plan);g({kind:"ready",plan:_}),o?.();return}$.kind==="conflict"&&(G.error(c("gitView.integrate.cherryPickConflictToast"),{description:c("gitView.integrate.cherryPickConflictDescription")}),g({kind:"conflict",state:$.state,details:$.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify($.state)))}catch($){const _=$ instanceof Error?$.message:String($);G.error(c("gitView.integrate.failedToMoveToast"),{description:_});const Q=await Ii({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(Q?{kind:"ready",plan:Q}:{kind:"idle"})}}},[x,o,t,e,b,j,c]),M=ze.useCallback(async()=>{if(x.kind==="conflict")try{await Kw(x.state),G.message(c("gitView.integrate.cherryPickAbortedToast")),j&&typeof window<"u"&&window.localStorage.removeItem(j)}finally{const $=await Ii({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g($?{kind:"ready",plan:$}:{kind:"idle"})}},[x,t,e,b,j,c]),R=ze.useCallback(async()=>{if(x.kind==="conflict")try{const $=await Hw(x.state);if($.kind==="success"){G.success(c("gitView.integrate.cherryPickFinishedToast"));const _=await Ii({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(_?{kind:"ready",plan:_}:{kind:"idle"}),j&&typeof window<"u"&&window.localStorage.removeItem(j),o?.();return}$.kind==="conflict"&&(g({kind:"conflict",state:$.state,details:$.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify($.state)))}catch($){const _=$ instanceof Error?$.message:String($);G.error(c("gitView.integrate.cherryPickContinueFailedToast"),{description:_})}},[x,t,e,b,o,j,c]);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:c("gitView.integrate.title")}),x.kind==="ready"&&x.plan.commits.length>0?s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:c("gitView.integrate.toMoveCount",{count:x.plan.commits.length})}):null]}),s.jsx("div",{className:"flex items-center gap-2",children:x.kind==="loading"||x.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:c("gitView.integrate.moveCommits")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",b]})]}),s.jsx("div",{className:"flex-1"}),s.jsxs(_s,{open:m,onOpenChange:u,children:[s.jsx(Bs,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"sm",className:"gap-1.5",children:[c("gitView.integrate.target"),s.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:b}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),s.jsx(zs,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(La,{className:"h-full min-h-0",children:[s.jsx(oa,{ref:f,placeholder:c("gitView.branch.searchPlaceholder"),onKeyDown:$=>$.stopPropagation()}),s.jsxs(Oa,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx($a,{children:c("gitView.branch.empty")}),s.jsx(zn,{heading:c("gitView.branch.localBranches"),children:r.map($=>s.jsx(Dn,{value:$,onSelect:()=>{h($),S($),u(!1)},children:$},$))})]})]})})]}),x.kind==="ready"?s.jsx(be,{size:"sm",onClick:()=>{T()},disabled:!v||x.plan.commits.length===0,children:c("gitView.integrate.move")}):x.kind==="loading"?s.jsx(be,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.checking")}):x.kind==="running"?s.jsx(be,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.moving")}):null]}),x.kind==="ready"&&x.plan.commits.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.noCommitsToMove")}),x.kind==="ready"&&x.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:[c("gitView.integrate.commitsToMove"),s.jsxs("span",{className:"text-muted-foreground",children:[" (",x.plan.commits.length,")"]})]}),k.length>0&&x.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>y($=>!$),className:"typography-micro text-muted-foreground hover:text-foreground",children:c(w?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),s.jsxs("div",{className:"space-y-1",children:[(w?k:k.slice(0,5)).map($=>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:$.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:$.subject||$.sha})]},$.sha)),k.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.previewUnavailable")}),x.plan.commits.length>k.length&&s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c("gitView.integrate.showingFirstCommits",{count:k.length})})]})]}),x.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:c("gitView.integrate.conflictsInFiles",{count:x.details.unmergedFiles.length})}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[c("gitView.integrate.currentCommit"),": ",s.jsx("span",{className:"font-mono",children:x.state.currentCommit.slice(0,7)})]}),s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[x.details.unmergedFiles.slice(0,6).map($=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:$},$)),x.details.unmergedFiles.length>6&&s.jsx("span",{className:"text-xs text-muted-foreground",children:c("gitView.integrate.moreFiles",{count:x.details.unmergedFiles.length-6})})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(be,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{M()},children:c("gitView.operation.abort")}),s.jsxs(be,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!d,onClick:()=>{N({state:x.state,details:x.details},!1)},children:[s.jsx(I,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.currentSession")]}),s.jsxs(be,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{N({state:x.state,details:x.details},!0)},children:[s.jsx(I,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.newSession")]}),s.jsx(be,{size:"sm",className:"typography-meta",onClick:()=>{R()},children:c("gitView.operation.continue")})]})]})]})]})},qw=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Yw=({currentBranch:t,localBranches:e,remoteBranches:n,branchInfo:r,onCheckout:a,onCreate:i,remotes:o=[],disabled:c=!1})=>{const{t:d}=mt(),[p,m]=l.useState(!1),[u,f]=l.useState(""),[b,h]=l.useState(!1),[v,x]=l.useState(!1),[g,w]=l.useState(""),[y,k]=l.useState(!1),D=l.useRef(null),j=l.useCallback(z=>{z.stopPropagation()},[]),S=o.length>1,A=l.useMemo(()=>qw(g),[g]),E=l.useMemo(()=>{const z=u.toLowerCase();return z?e.filter(B=>B.toLowerCase().includes(z)):e},[u,e]),P=l.useMemo(()=>{const z=u.toLowerCase();return z?n.filter(B=>B.toLowerCase().includes(z)):n},[u,n]),C=z=>{if(z===t){m(!1);return}a(z),m(!1),f("")},N=()=>{h(!0),setTimeout(()=>D.current?.focus(),50)},T=async()=>{if(!(!A||y)){if(S){x(!0);return}k(!0);try{await i(A,o[0]),w(""),h(!1),m(!1)}finally{k(!1)}}},M=async z=>{if(!(!A||y)){k(!0);try{await i(A,z),w(""),h(!1),x(!1),m(!1)}finally{k(!1)}}},R=()=>{x(!1)},O=()=>{w(""),h(!1),x(!1)};return l.useEffect(()=>{p||(f(""),h(!1),x(!1),w(""))},[p]),s.jsxs(_s,{open:p,onOpenChange:m,children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(Bs,{asChild:!0,children:s.jsxs(be,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1",disabled:c,children:[s.jsx(I,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("span",{className:"min-w-0 truncate font-medium text-left",children:t||d("gitView.branch.detachedHead")}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),s.jsx(At,{sideOffset:8,children:d("gitView.branch.currentBranchTooltip")})]}),s.jsx(zs,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:s.jsxs(La,{className:"h-full min-h-0",children:[s.jsx(oa,{placeholder:d("gitView.branch.searchPlaceholder"),value:u,onValueChange:f,onKeyDown:j}),s.jsxs(Oa,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx($a,{children:d("gitView.branch.empty")}),s.jsx(zn,{children:v?s.jsxs("div",{className:"px-2 py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[s.jsx("button",{type:"button",onClick:R,disabled:y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(I,{name:"arrow-left",className:"size-4"})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d("gitView.branch.pushToPrefix")," ",s.jsx("span",{className:"text-foreground font-medium",children:A})," ",d("gitView.branch.pushToSuffix")]})]}),s.jsx("div",{className:"flex flex-col gap-1",children:o.map(z=>s.jsxs("button",{type:"button",onClick:()=>M(z),disabled:y,className:"flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50",children:[s.jsxs("span",{className:"typography-ui-label text-foreground",children:[y?s.jsx(I,{name:"loader-4",className:"inline size-3 mr-1.5 animate-spin"}):null,z.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:z.pushUrl})]},z.name))})]}):b?s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[s.jsx("input",{ref:D,placeholder:d("gitView.branch.newBranchPlaceholder"),value:g,onChange:z=>w(z.target.value),onClick:z=>z.stopPropagation(),onKeyDown:z=>{j(z),z.key==="Enter"?(z.preventDefault(),T()):z.key==="Escape"&&(z.preventDefault(),O())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"button",onClick:T,disabled:!A||y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:y?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"add",className:"size-4"})}),s.jsx("button",{type:"button",onClick:O,disabled:y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(I,{name:"close",className:"size-4"})})]}):s.jsxs(Dn,{onSelect:N,children:[s.jsx(I,{name:"add",className:"size-4"}),s.jsx("span",{children:d("gitView.branch.create")})]})}),s.jsx(ka,{}),s.jsxs(zn,{heading:d("gitView.branch.localBranches"),children:[E.map(z=>s.jsxs(Dn,{onSelect:()=>C(z),children:[s.jsxs("span",{className:"flex flex-1 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:z}),(r?.[z]?.ahead||r?.[z]?.behind)&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[r[z].ahead||0," ahead ·"," ",r[z].behind||0," behind"]})]}),t===z&&s.jsx("span",{className:"typography-micro text-primary",children:d("gitView.branch.currentBadge")})]},`local-${z}`)),E.length===0&&s.jsx(Dn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noLocalBranches")})})]}),s.jsx(ka,{}),s.jsxs(zn,{heading:d("gitView.branch.remoteBranches"),children:[P.map(z=>s.jsx(Dn,{onSelect:()=>C(z),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:z})},`remote-${z}`)),P.length===0&&s.jsx(Dn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noRemoteBranches")})})]})]})]})})]})},Jw=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Qw=({currentBranch:t,onRename:e,showEditButton:n=!0})=>{const{t:r}=mt(),[a,i]=l.useState(!1),[o,c]=l.useState(t||""),[d,p]=l.useState(!1),m=l.useRef(null),u=()=>{!t||!e||(c(t),i(!0),setTimeout(()=>m.current?.focus(),0))},f=async()=>{if(!t||!e||!o.trim())return;const v=Jw(o);if(v===t){i(!1);return}p(!0);try{await e(t,v),i(!1),c("")}finally{p(!1)}},b=()=>{i(!1),c("")},h=v=>{v.key==="Enter"?(v.preventDefault(),f()):v.key==="Escape"&&(v.preventDefault(),b())};return a?s.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:v=>{v.preventDefault(),f()},children:[s.jsx(I,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("input",{ref:m,value:o,onChange:v=>c(v.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:r("gitView.branch.namePlaceholder"),onKeyDown:h,autoFocus:!0}),s.jsx("button",{type:"submit",disabled:d,"aria-label":r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),title:r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:d?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:b,disabled:d,"aria-label":r("gitView.branch.renameCancel"),title:r("gitView.branch.renameCancel"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(I,{name:"close",className:"size-4"})})]})}):s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1.5 px-2 py-1 h-8",children:[s.jsx(I,{name:"git-branch",className:"size-4 text-primary shrink-0"}),s.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:t||r("gitView.branch.detachedHead")}),n&&e&&t&&s.jsx(be,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:u,title:r("gitView.branch.renameTitle"),children:s.jsx(I,{name:"edit",className:"size-4"})})]})]})},Xw=t=>{const e=at.c(41),{syncAction:n,remotes:r,onFetch:a,onSync:i,onRemoveRemote:o,disabled:c,removingRemoteName:d,aheadCount:p,behindCount:m,trackingRemoteName:u,hasUncommittedChanges:f}=t,b=r===void 0?[]:r,h=d===void 0?null:d,v=p===void 0?0:p,x=m===void 0?0:m,g=f===void 0?!1:f,{t:w}=mt(),y=l.useRef(!1),k=!!h,D=b.find(H=>H.name===u)??b[0],j=x>0&&g,S=c||n!==null||k||!D||j,A=c||n!==null||k||b.length===0,E=v>0||x>0;let P;e[0]!==w?(P=w("gitView.sync.sync"),e[0]=w,e[1]=P):P=e[1];const C=x>0?`↓${x}`:null,N=v>0?`↑${v}`:null;let T;e[2]!==P||e[3]!==C||e[4]!==N?(T=[P,C,N].filter(Boolean),e[2]=P,e[3]=C,e[4]=N,e[5]=T):T=e[5];const M=T.join(" "),R=j?w("gitView.sync.commitOrStashTooltip"):D?E?w("gitView.sync.syncChangesTooltip",{ahead:v,behind:x}):w("gitView.sync.syncChanges"):w("gitView.sync.noRemoteTooltip"),O=()=>{D&&i(D)},z="inline-flex items-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] border border-border/60 bg-[var(--surface-elevated)] overflow-hidden";let B;e[6]===Symbol.for("react.memo_cache_sentinel")?(B=me("inline-flex h-7 items-center gap-1.5 px-2 typography-ui-label font-medium text-foreground","transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[6]=B):B=e[6];let $;e[7]!==w?($=w("gitView.sync.syncChanges"),e[7]=w,e[8]=$):$=e[8];let _;e[9]!==n?(_=n==="sync"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=_):_=e[10];let Q;e[11]!==M?(Q=s.jsx("span",{className:"whitespace-nowrap tabular-nums",children:M}),e[11]=M,e[12]=Q):Q=e[12];let W;e[13]!==O||e[14]!==S||e[15]!==$||e[16]!==_||e[17]!==Q?(W=s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:O,disabled:S,className:B,"aria-label":$,children:[_,Q]})}),e[13]=O,e[14]=S,e[15]=$,e[16]=_,e[17]=Q,e[18]=W):W=e[18];let ne;e[19]!==R?(ne=s.jsx(At,{sideOffset:8,children:R}),e[19]=R,e[20]=ne):ne=e[20];let re;e[21]!==W||e[22]!==ne?(re=s.jsxs(It,{children:[W,ne]}),e[21]=W,e[22]=ne,e[23]=re):re=e[23];const ue=_s;let Y;e[24]===Symbol.for("react.memo_cache_sentinel")?(Y=me("inline-flex h-7 w-6 items-center justify-center border-l border-[var(--interactive-border)] text-muted-foreground","transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[24]=Y):Y=e[24];let le;e[25]!==w?(le=w("gitView.sync.moreActionsAria"),e[25]=w,e[26]=le):le=e[26];let J;e[27]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(I,{name:"arrow-down-s",className:"size-4"}),e[27]=J):J=e[27];let L;e[28]!==A||e[29]!==le?(L=s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:Y,disabled:A,"aria-label":le,children:J})}),e[28]=A,e[29]=le,e[30]=L):L=e[30];const V=zs,K="start",X=-40,U="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",ae=b.map(H=>s.jsx(Vt,{onSelect:ce=>{if(y.current){ce.preventDefault(),y.current=!1;return}a(H)},children:s.jsxs("div",{className:"flex w-full items-center gap-2",children:[s.jsx(I,{name:"refresh",className:"size-4 text-muted-foreground"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:w("gitView.sync.fetchFromRemote",{name:H.name})}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:H.fetchUrl})]})}),o&&H.name!==u?s.jsx(be,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||k,onPointerDown:ce=>{y.current=!0,ce.preventDefault(),ce.stopPropagation()},onClick:ce=>{y.current=!0,ce.preventDefault(),ce.stopPropagation(),o(H)},"aria-label":w("gitView.header.removeRemoteAria",{name:H.name}),title:w("gitView.header.removeRemoteTitle",{name:H.name}),children:h===H.name?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"close",className:"size-3.5"})}):null]})},H.name));let ve;e[31]!==V||e[32]!==ae?(ve=s.jsx(V,{align:K,alignOffset:X,className:U,children:ae}),e[31]=V,e[32]=ae,e[33]=ve):ve=e[33];let ie;e[34]!==ue||e[35]!==L||e[36]!==ve?(ie=s.jsxs(ue,{children:[L,ve]}),e[34]=ue,e[35]=L,e[36]=ve,e[37]=ie):ie=e[37];let fe;return e[38]!==re||e[39]!==ie?(fe=s.jsxs("div",{className:z,children:[re,ie]}),e[38]=re,e[39]=ie,e[40]=fe):fe=e[40],fe},Zw={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},ej={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)",success:"var(--status-success)",info:"var(--status-info)",warning:"var(--status-warning)"};function $h(t){return t&&ej[t]||"var(--primary)"}const pm=t=>{const e=at.c(8),{icon:n,className:r,colorToken:a}=t,i=Zw[n??"branch"]??"user-3";let o;e[0]!==a?(o=$h(a),e[0]=a,e[1]=o):o=e[1];let c;e[2]!==o?(c={color:o},e[2]=o,e[3]=c):c=e[3];let d;return e[4]!==r||e[5]!==i||e[6]!==c?(d=s.jsx(I,{name:i,className:r,style:c}),e[4]=r,e[5]=i,e[6]=c,e[7]=d):d=e[7],d},Bh=t=>{const e=at.c(35),{activeProfile:n,identities:r,onSelect:a,isApplying:i,iconOnly:o}=t,c=o===void 0?!1:o,{t:d}=mt(),p=i||r.length===0,m=n?.color;let u;e[0]!==m?(u=$h(m),e[0]=m,e[1]=u):u=e[1];let f;e[2]!==u?(f={color:u},e[2]=u,e[3]=f):f=e[3];let b;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==i?(b=i?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(pm,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=i,e[7]=b):b=e[7];let h;e[8]!==n?.name||e[9]!==c||e[10]!==d?(h=!c&&s.jsx("span",{className:"git-identity-label min-w-0 flex-1 truncate text-left",children:n?.name||d("gitView.header.noIdentity")}),e[8]=n?.name,e[9]=c,e[10]=d,e[11]=h):h=e[11];let v;e[12]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=v):v=e[12];let x;e[13]!==p||e[14]!==f||e[15]!==b||e[16]!==h?(x=s.jsx(Pt,{asChild:!0,children:s.jsx(Bs,{asChild:!0,children:s.jsxs(be,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-[15rem] justify-start gap-1.5 px-2 py-1 typography-ui-label",style:f,disabled:p,children:[b,h,v]})})}),e[13]=p,e[14]=f,e[15]=b,e[16]=h,e[17]=x):x=e[17];let g;e[18]!==d?(g=d("gitView.header.identityTooltip"),e[18]=d,e[19]=g):g=e[19];let w;e[20]!==g?(w=s.jsx(At,{sideOffset:8,children:g}),e[20]=g,e[21]=w):w=e[21];let y;e[22]!==w||e[23]!==x?(y=s.jsxs(It,{children:[x,w]}),e[22]=w,e[23]=x,e[24]=y):y=e[24];let k;e[25]!==n?.id||e[26]!==r||e[27]!==a||e[28]!==d?(k=r.length===0?s.jsx("div",{className:"px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:d("gitView.header.noProfiles")})}):r.map(S=>{const A=n?.id===S.id;return s.jsx(Vt,{onSelect:()=>a(S),children:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(pm,{icon:S.icon,colorToken:S.color,className:"size-4"}),s.jsxs("span",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:S.name}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:S.userEmail})]}),A?s.jsx(I,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},S.id)}),e[25]=n?.id,e[26]=r,e[27]=a,e[28]=d,e[29]=k):k=e[29];let D;e[30]!==k?(D=s.jsx(zs,{align:"end",className:"w-64",children:k}),e[30]=k,e[31]=D):D=e[31];let j;return e[32]!==y||e[33]!==D?(j=s.jsxs(_s,{children:[y,D]}),e[32]=y,e[33]=D,e[34]=j):j=e[34],j},tj=t=>{const e=at.c(48),{status:n,localBranches:r,remoteBranches:a,branchInfo:i,syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,onCheckoutBranch:f,onCreateBranch:b,onRenameBranch:h,activeIdentityProfile:v,availableIdentities:x,onSelectIdentity:g,isApplyingIdentity:w,isWorktreeMode:y,onOpenHistory:k,actionTabItems:D,activeActionTab:j,onSelectActionTab:S}=t,{t:A}=mt();if(!n)return null;let E;e[0]!==k||e[1]!==A?(E=k?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0",onClick:k,children:s.jsx(I,{name:"history",className:"size-4"})})}),s.jsx(At,{sideOffset:8,children:A("gitView.history.title")})]}):null,e[0]=k,e[1]=A,e[2]=E):E=e[2];let P;e[3]!==E?(P=s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:E}),e[3]=E,e[4]=P):P=e[4];const C=P,N=!n;let T;e[5]!==n.tracking?(T=n.tracking?.split("/")[0],e[5]=n.tracking,e[6]=T):T=e[6];const M=(n.files?.length??0)>0;let R;e[7]!==d||e[8]!==m||e[9]!==p||e[10]!==c||e[11]!==u||e[12]!==n.ahead||e[13]!==n.behind||e[14]!==o||e[15]!==N||e[16]!==T||e[17]!==M?(R=s.jsx(Xw,{syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,disabled:N,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:T,hasUncommittedChanges:M}),e[7]=d,e[8]=m,e[9]=p,e[10]=c,e[11]=u,e[12]=n.ahead,e[13]=n.behind,e[14]=o,e[15]=N,e[16]=T,e[17]=M,e[18]=R):R=e[18];const O=R;let z;e[19]!==v||e[20]!==x||e[21]!==w||e[22]!==g?(z=s.jsx(Bh,{activeProfile:v,identities:x,onSelect:g,isApplying:w,iconOnly:!0}),e[19]=v,e[20]=x,e[21]=w,e[22]=g,e[23]=z):z=e[23];const B=z;let $;e[24]!==i||e[25]!==y||e[26]!==r||e[27]!==f||e[28]!==b||e[29]!==h||e[30]!==a||e[31]!==c||e[32]!==n.current?($=s.jsx("div",{className:"min-w-0 flex-1",children:y?s.jsx(Qw,{currentBranch:n.current,onRename:h}):s.jsx(Yw,{currentBranch:n.current,localBranches:r,remoteBranches:a,branchInfo:i,onCheckout:f,onCreate:b,remotes:c})}),e[24]=i,e[25]=y,e[26]=r,e[27]=f,e[28]=b,e[29]=h,e[30]=a,e[31]=c,e[32]=n.current,e[33]=$):$=e[33];let _;e[34]!==B||e[35]!==C?(_=s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[C,B]}),e[34]=B,e[35]=C,e[36]=_):_=e[36];let Q;e[37]!==$||e[38]!==_?(Q=s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[$,_]}),e[37]=$,e[38]=_,e[39]=Q):Q=e[39];let W;e[40]!==D||e[41]!==j||e[42]!==S||e[43]!==O?(W=D&&j&&S?s.jsxs("div",{className:"mt-3 flex h-8 min-w-0 items-center gap-2",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx(Er,{items:D,activeId:j,onSelect:S,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),s.jsx("div",{className:"shrink-0",children:O})]}):null,e[40]=D,e[41]=j,e[42]=S,e[43]=O,e[44]=W):W=e[44];let ne;return e[45]!==Q||e[46]!==W?(ne=s.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[Q,W]}),e[45]=Q,e[46]=W,e[47]=ne):ne=e[47],ne},sj=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,uncommittedFileCount:a,onChanged:i})=>{const{t:o}=mt(),[c,d]=l.useState([]),[p,m]=l.useState(!1),[u,f]=l.useState(""),[b,h]=l.useState(""),[v,x]=l.useState(null),[g,w]=l.useState({}),y=l.useCallback(async()=>{if(n){m(!0);try{const E=await ub(n);d(E.stashes),w({})}catch(E){G.error(E instanceof Error?E.message:o("gitView.stashes.toast.loadFailed"))}finally{m(!1)}}},[n,o]);l.useEffect(()=>{t&&y()},[y,t]),l.useEffect(()=>{if(!t||!n||c.length===0)return;let E=!1;const P=c.map(C=>C.ref);return mb(n,P).then(C=>{E||w(C.counts)}).catch(()=>{}),()=>{E=!0}},[n,t,c]);const k=l.useMemo(()=>{const E=u.trim().toLowerCase();return E?c.filter(P=>`${P.ref} ${P.message} ${P.relativeTime}`.toLowerCase().includes(E)):c},[u,c]),D=l.useCallback(async()=>{await y(),await i?.()},[y,i]),j=async()=>{if(!(!n||v)){x("create");try{(await pb(n,{message:b.trim()||void 0})).created?(G.success(o("gitView.stashes.toast.created")),h("")):G.info(o("gitView.stashes.toast.noChanges")),await D()}catch(E){G.error(E instanceof Error?E.message:o("gitView.stashes.toast.createFailed"))}finally{x(null)}}},S=async(E,P)=>{if(!(!n||v)&&!(P==="drop"&&!window.confirm(o("gitView.stashes.confirm.drop",{ref:E.ref})))){x(`${P}:${E.ref}`);try{P==="apply"&&await fb(n,{ref:E.ref}),P==="pop"&&await hb(n,{ref:E.ref}),P==="drop"&&await gb(n,{ref:E.ref});const C=P==="apply"?"gitView.stashes.toast.applySuccess":P==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";G.success(o(C)),await D()}catch(C){const N=P==="apply"?"gitView.stashes.toast.applyFailed":P==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";G.error(C instanceof Error?C.message:o(N)),await D()}finally{x(null)}}},A=v!==null;return s.jsx(vs,{open:t,onOpenChange:e,children:s.jsxs(ys,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(As,{children:[s.jsxs(Ss,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"archive-stack",className:"h-5 w-5"}),o("gitView.stashes.title")]}),s.jsx(Fs,{children:o("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(Wt,{value:b,onChange:E=>h(E.target.value),placeholder:o("gitView.stashes.messagePlaceholder"),disabled:A||!r,className:"flex-1"}),s.jsxs(be,{onClick:j,disabled:!r||A||!n,children:[v==="create"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"inbox-archive",className:"size-4"}),o("gitView.stashes.actions.stashCurrentWithCount",{count:a})]})]}),s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:o("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(Wt,{value:u,onChange:E=>f(E.target.value),placeholder:o("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:p?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"})}):k.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:o(u?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):k.map((E,P)=>s.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[s.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[s.jsx("p",{className:"typography-small truncate text-foreground",children:E.message||o("gitView.stashes.untitled")}),s.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{children:P===0&&!u.trim()?o("gitView.stashes.latestLabel"):o("gitView.stashes.itemNumber",{number:P+1})})}),s.jsx(At,{sideOffset:6,children:E.ref})]})," · ",E.relativeTime," · ",typeof g[E.ref]=="number"?o("gitView.stashes.fileCount",{count:g[E.ref]}):o("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(fc,{label:o("gitView.stashes.actions.apply"),loading:v===`apply:${E.ref}`,onClick:()=>S(E,"apply"),disabled:A,children:s.jsx(I,{name:"inbox-unarchive",className:"size-4"})}),s.jsx(fc,{label:o("gitView.stashes.actions.pop"),loading:v===`pop:${E.ref}`,onClick:()=>S(E,"pop"),disabled:A,children:s.jsx(I,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx(fc,{label:o("gitView.stashes.actions.drop"),loading:v===`drop:${E.ref}`,onClick:()=>S(E,"drop"),disabled:A,destructive:!0,children:s.jsx(I,{name:"delete-bin",className:"size-4"})})]})]},E.ref))})]})})},fc=t=>{const e=at.c(17),{label:n,loading:r,disabled:a,destructive:i,onClick:o,children:c}=t,d=r||void 0,p=i?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let m;e[0]!==p?(m=me("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",p),e[0]=p,e[1]=m):m=e[1];let u;e[2]!==c||e[3]!==r?(u=r?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):c,e[2]=c,e[3]=r,e[4]=u):u=e[4];let f;e[5]!==a||e[6]!==n||e[7]!==o||e[8]!==d||e[9]!==m||e[10]!==u?(f=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":n,"aria-busy":d,className:m,onClick:o,disabled:a,children:u})}),e[5]=a,e[6]=n,e[7]=o,e[8]=d,e[9]=m,e[10]=u,e[11]=f):f=e[11];let b;e[12]!==n?(b=s.jsx(At,{sideOffset:6,children:n}),e[12]=n,e[13]=b):b=e[13];let h;return e[14]!==f||e[15]!==b?(h=s.jsxs(It,{children:[f,b]}),e[14]=f,e[15]=b,e[16]=h):h=e[16],h},zh={"?":{code:"?",color:"var(--status-info)",description:"Untracked file"},A:{code:"A",color:"var(--status-success)",description:"New file"},D:{code:"D",color:"var(--status-error)",description:"Deleted file"},R:{code:"R",color:"var(--status-info)",description:"Renamed file"},C:{code:"C",color:"var(--status-info)",description:"Copied file"},M:{code:"M",color:"var(--status-warning)",description:"Modified file"}},nj=zh.M;function rj(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"}function aj(t){const e=rj(t);return zh[e]??nj}const fm=l.memo(function(e){const n=at.c(71),{file:r,checked:a,onToggle:i,onViewDiff:o,onRevert:c,isReverting:d,stats:p,rowPaddingClassName:m,indentPx:u}=e,f=u===void 0?0:u;let b;n[0]!==r?(b=aj(r),n[0]=r,n[1]=b):b=n[1];const h=b,{t:v}=mt(),x=h.description,g=p?.insertions??0,w=p?.deletions??0;let y;n[2]!==i||n[3]!==o?(y=L=>{L.key===" "?(L.preventDefault(),i()):L.key==="Enter"&&(L.preventDefault(),o())},n[2]=i,n[3]=o,n[4]=y):y=n[4];const k=y;let D;n[5]!==c?(D=L=>{L.preventDefault(),L.stopPropagation(),c()},n[5]=c,n[6]=D):D=n[6];const j=D,S=`group flex items-center gap-2 py-1.5 hover:bg-sidebar/40 cursor-pointer ${m??"px-3"}`;let A;n[7]!==f?(A=f>0?{paddingLeft:`${f}px`}:void 0,n[7]=f,n[8]=A):A=n[8];let E;n[9]!==i?(E=()=>i(),n[9]=i,n[10]=E):E=n[10];let P;n[11]!==r.path||n[12]!==v?(P=v("gitView.changes.selectFileAria",{path:r.path}),n[11]=r.path,n[12]=v,n[13]=P):P=n[13];let C;n[14]!==a||n[15]!==E||n[16]!==P?(C=s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",onClick:ij,children:s.jsx(fs,{size:"sm",checked:a,onChange:E,ariaLabel:P})}),n[14]=a,n[15]=E,n[16]=P,n[17]=C):C=n[17];let N;n[18]!==h.color?(N={color:h.color},n[18]=h.color,n[19]=N):N=n[19];let T;n[20]!==h.code||n[21]!==x||n[22]!==N?(T=s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:N,title:x,"aria-label":x,children:h.code}),n[20]=h.code,n[21]=x,n[22]=N,n[23]=T):T=n[23];let M;n[24]!==r.path?(M=s.jsx(jr,{filePath:r.path,className:"h-3.5 w-3.5 shrink-0"}),n[24]=r.path,n[25]=M):M=n[25];let R;if(n[26]!==r.path){e:{const L=r.path.lastIndexOf("/");if(L===-1){let ie;n[28]===Symbol.for("react.memo_cache_sentinel")?(ie={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[28]=ie):ie=n[28],R=s.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:ie,title:r.path,children:r.path});break e}const V=r.path.slice(0,L),K=r.path.slice(L);let X;n[29]===Symbol.for("react.memo_cache_sentinel")?(X={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[29]=X):X=n[29];let U;n[30]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx("span",{className:"text-muted-foreground",children:"/"}),n[30]=U):U=n[30];const ae=s.jsx("span",{className:"text-foreground",children:K.slice(1)});let ve;n[31]!==ae?(ve=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[U,ae]}),n[31]=ae,n[32]=ve):ve=n[32],R=s.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:r.path,children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:X,children:V}),ve]})}n[26]=r.path,n[27]=R}else R=n[27];let O;n[33]===Symbol.for("react.memo_cache_sentinel")?(O={color:"var(--status-success)"},n[33]=O):O=n[33];let z;n[34]!==g?(z=s.jsxs("span",{style:O,children:["+",g]}),n[34]=g,n[35]=z):z=n[35];let B,$;n[36]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),$={color:"var(--status-error)"},n[36]=B,n[37]=$):(B=n[36],$=n[37]);let _;n[38]!==w?(_=s.jsxs("span",{style:$,children:["-",w]}),n[38]=w,n[39]=_):_=n[39];let Q;n[40]!==z||n[41]!==_?(Q=s.jsxs("span",{className:"shrink-0 typography-micro",children:[z,B,_]}),n[40]=z,n[41]=_,n[42]=Q):Q=n[42];let W;n[43]!==r.path||n[44]!==v?(W=v("gitView.changes.revertFileAria",{path:r.path}),n[43]=r.path,n[44]=v,n[45]=W):W=n[45];let ne;n[46]!==d?(ne=d?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"arrow-go-back",className:"size-3.5"}),n[46]=d,n[47]=ne):ne=n[47];let re;n[48]!==j||n[49]!==d||n[50]!==W||n[51]!==ne?(re=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,disabled:d,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":W,children:ne})}),n[48]=j,n[49]=d,n[50]=W,n[51]=ne,n[52]=re):re=n[52];let ue;n[53]!==v?(ue=v("gitView.changes.revertFileTooltip"),n[53]=v,n[54]=ue):ue=n[54];let Y;n[55]!==ue?(Y=s.jsx(At,{sideOffset:8,children:ue}),n[55]=ue,n[56]=Y):Y=n[56];let le;n[57]!==re||n[58]!==Y?(le=s.jsxs(It,{children:[re,Y]}),n[57]=re,n[58]=Y,n[59]=le):le=n[59];let J;return n[60]!==k||n[61]!==o||n[62]!==T||n[63]!==M||n[64]!==R||n[65]!==Q||n[66]!==le||n[67]!==S||n[68]!==A||n[69]!==C?(J=s.jsxs("div",{className:S,role:"button",tabIndex:0,onClick:o,onKeyDown:k,style:A,children:[C,T,M,R,Q,le]}),n[60]=k,n[61]=o,n[62]=T,n[63]=M,n[64]=R,n[65]=Q,n[66]=le,n[67]=S,n[68]=A,n[69]=C,n[70]=J):J=n[70],J});function ij(t){t.stopPropagation()}const oj=1e3,lj=34,hm=14,_h=t=>t.replace(/\\/g,"/").replace(/^\/+/,"").trim(),gm=(t,e)=>({id:`dir:${t}`,path:t,name:e,children:new Map,directFiles:[],files:[]}),cj=t=>{const e=gm("","");for(const n of t){const r=_h(n.path);if(!r)continue;const i=r.split("/").filter(Boolean).slice(0,-1);let o=e;if(o.files.push(n),i.length>0){let c="";for(const d of i){c=c?`${c}/${d}`:d;const p=o.children.get(d);if(p){p.files.push(n),o=p;continue}const m=gm(c,d);m.files.push(n),o.children.set(d,m),o=m}}o.directFiles.push(n)}return e},dj=(t,e)=>{const n=[],r=(a,i)=>{const o=Array.from(a.children.values()).sort((d,p)=>d.path.localeCompare(p.path));for(const d of o)n.push({key:d.id,kind:"directory",depth:i,directory:d}),e.has(d.path)&&r(d,i+1);const c=[...a.directFiles].sort((d,p)=>d.path.localeCompare(p.path));for(const d of c)n.push({key:`file:${_h(d.path)}`,kind:"file",depth:i,file:d})};return r(t,0),n},xm=(t,e)=>{if(t.files.length===0)return"none";let n=0;for(const r of t.files)e.has(r.path)&&(n+=1);return n===0?"none":n===t.files.length?"all":"partial"},uj=({changeEntries:t,selectedPaths:e,diffStats:n,revertingPaths:r,onToggleFile:a,onSelectAll:i,onClearSelection:o,onRevertAll:c,onViewDiff:d,onRevertFile:p,isRevertingAll:m=!1,maxListHeightClassName:u,onVisiblePathsChange:f,onOpenStashes:b})=>{const{t:h}=mt(),v=l.useRef(null),g=Te(J=>J.gitChangesViewMode)==="tree",w=e.size,y=t.length,[k,D]=l.useState(!1),j=l.useMemo(()=>cj(t),[t]),[S,A]=l.useState(new Set),E=l.useMemo(()=>Array.from(j.children.values()).map(J=>J.path),[j]);l.useEffect(()=>{g&&A(J=>{const L=new Set,V=new Set(E);return J.forEach(K=>{if(K.includes("/")){L.add(K);return}V.has(K)&&L.add(K)}),E.forEach(K=>L.add(K)),L})},[g,E]);const P=l.useMemo(()=>dj(j,S),[S,j]),C=l.useMemo(()=>g?P:t,[t,g,P]),N=C.length,T=N>=oj,M=w>0,R=y>0&&w===y,O=M&&!R,z=tx({count:N,getScrollElement:()=>v.current,estimateSize:()=>lj,overscan:10,enabled:T});l.useEffect(()=>{if(!T)return;const J=v.current;if(!J)return;const L=new ResizeObserver(()=>{z.measure()});return L.observe(J),()=>L.disconnect()},[T,z]);const B=z.getTotalSize(),$=l.useMemo(()=>T&&B>=0?z.getVirtualItems():[],[T,z,B]);l.useEffect(()=>{if(!f)return;if(N===0){f([]);return}const J=L=>{if(!g)return L.path;const V=L;return V.kind==="file"?V.file.path:null};if(!T){f(C.slice(0,Math.min(30,N)).map(L=>J(L)).filter(L=>!!L));return}f($.map(L=>C[L.index]).map(L=>L?J(L):null).filter(L=>!!L))},[g,f,N,C,T,$]);const _="flex flex-col flex-1 min-h-0",Q="flex items-center justify-between gap-2 px-0 py-3 border-b border-border/40",W=`flex-1 min-h-0 pr-0 ${u??""}`.trim(),ne="pl-0 pr-2",re=l.useCallback(J=>{A(L=>{const V=new Set(L);return V.has(J)?V.delete(J):V.add(J),V})},[]),ue=l.useCallback(J=>{const V=xm(J,e)!=="all";for(const K of J.files){const X=e.has(K.path);(V&&!X||!V&&X)&&a(K.path)}},[a,e]),Y=l.useCallback(J=>{if(!g){const U=J;return s.jsx(fm,{file:U,checked:e.has(U.path),stats:n?.[U.path],onToggle:()=>a(U.path),onViewDiff:()=>d(U.path),onRevert:()=>p(U.path),isReverting:r.has(U.path)||m,rowPaddingClassName:ne})}const L=J;if(L.kind==="file"){const U=L.file;return s.jsx(fm,{file:U,checked:e.has(U.path),stats:n?.[U.path],onToggle:()=>a(U.path),onViewDiff:()=>d(U.path),onRevert:()=>p(U.path),isReverting:r.has(U.path)||m,rowPaddingClassName:ne,indentPx:L.depth*hm})}const V=L.directory,K=S.has(V.path),X=xm(V,e);return s.jsxs("div",{className:me("group flex items-center gap-2 py-1.5 hover:bg-sidebar/40",ne),style:{paddingLeft:`${L.depth*hm}px`},children:[s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",children:s.jsx(fs,{size:"sm",checked:X==="all",indeterminate:X==="partial",onChange:()=>ue(V),ariaLabel:h("gitView.changes.toggleDirectorySelectionAria",{path:V.path})})}),s.jsxs("button",{type:"button",onClick:()=>re(V.path),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":K?h("gitView.changes.collapseDirectoryAria",{path:V.path}):h("gitView.changes.expandDirectoryAria",{path:V.path}),children:[K?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"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:V.path,children:V.name}),s.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:V.files.length})]})]})},[n,S,m,g,p,a,d,r,ne,e,h,re,ue]),le=l.useCallback(async()=>{!c||m||t.length===0||(await c(t.map(J=>J.path)),D(!1))},[t,m,c]);return s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:_,children:[s.jsxs("header",{className:Q,children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:h("gitView.changes.title")}),y>0?s.jsxs("div",{className:me("inline-flex h-6 items-center gap-1 rounded px-1.5",m&&"cursor-not-allowed opacity-50"),children:[s.jsx(fs,{size:"sm",checked:M,indeterminate:O,disabled:m,onChange:()=>R?o():i(),ariaLabel:h(R?"gitView.changes.clearSelectionAria":"gitView.changes.selectAllAria")}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[w,"/",y]})]}):null,b?s.jsx(be,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-1.5",onClick:b,"aria-label":h("gitView.stashes.title"),title:h("gitView.stashes.title"),children:s.jsx(I,{name:"archive-stack",className:"size-4"})}):null]}),s.jsx("div",{className:"flex items-center gap-2 pr-1",children:y>0&&c?s.jsx(be,{variant:"destructive",size:"xs",onClick:()=>D(!0),disabled:m,children:h("gitView.changes.revertAll")}):null})]}),s.jsxs("div",{className:me("relative flex flex-col min-h-0 w-full overflow-hidden",W),children:[s.jsx(ao,{ref:v,className:"overlay-scrollbar-target overlay-scrollbar-container flex-1 min-h-0 w-full overflow-y-auto overflow-x-hidden",children:T?s.jsx("div",{className:"relative w-full",style:{height:`${z.getTotalSize()}px`},children:$.map(J=>{const L=C[J.index];if(!L)return null;const V=g?L.key:`file:${L.path}`;return s.jsx("div",{ref:z.measureElement,"data-index":J.index,className:me("absolute left-0 top-0 w-full",J.index>0&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),style:{transform:`translateY(${J.start}px)`},children:Y(L)},V)})}):s.jsx("div",{role:"list","aria-label":h("gitView.changes.changedFilesAria"),children:C.map((J,L)=>s.jsx("div",{className:me("relative",L>0&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:Y(J)},g?J.key:`file:${J.path}`))})}),s.jsx(xb,{containerRef:v,disableHorizontal:!0})]})]}),s.jsx(vs,{open:k,onOpenChange:J=>{m||D(J)},children:s.jsxs(ys,{className:"max-w-md",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:h("gitView.changes.revertAllDialogTitle")}),s.jsx(Fs,{children:y===1?h("gitView.changes.revertAllDescriptionSingle",{count:y}):h("gitView.changes.revertAllDescriptionPlural",{count:y})})]}),s.jsxs(Hs,{children:[s.jsx(be,{variant:"outline",size:"sm",onClick:()=>D(!1),disabled:m,children:h("gitView.common.cancel")}),s.jsx(be,{variant:"destructive",size:"sm",onClick:()=>{le()},disabled:m,children:h(m?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})})]})},hc=38,ko=200,mj=t=>{const e=at.c(20),{value:n,onChange:r,placeholder:a,disabled:i,hasTouchInput:o,isMobile:c}=t,d=i===void 0?!1:i,p=o===void 0?!1:o,m=c===void 0?!1:c,{t:u}=mt(),f=l.useRef(null),b=Te(pj);let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{const E=f.current;if(!E)return;const P=document.activeElement===E,C=()=>{E.style.height=`${hc}px`;const T=E.scrollHeight,M=Math.min(Math.max(T,hc),ko);E.style.height=`${M}px`,E.style.overflowY=T>ko?"auto":"hidden",T>ko&&!P&&(E.scrollTop=E.scrollHeight)};C();const N=window.requestAnimationFrame(C);return()=>{window.cancelAnimationFrame(N)}},e[0]=h):h=e[0];let v;e[1]!==n?(v=[n],e[1]=n,e[2]=v):v=e[2],l.useLayoutEffect(h,v);let x;e[3]!==r?(x=E=>r(E.target.value),e[3]=r,e[4]=x):x=e[4];let g;e[5]!==a||e[6]!==u?(g=a??u("gitView.commit.messagePlaceholder"),e[5]=a,e[6]=u,e[7]=g):g=e[7];const w=p?"on":"off",y=p?"sentences":"off",k=m||b,D=d&&"opacity-50";let j;e[8]!==D?(j=me("w-full rounded-lg border border-border/60 bg-surface-elevated px-3 py-2 typography-ui-label text-foreground placeholder:text-muted-foreground","resize-none outline-none transition-[border-color,box-shadow] duration-150","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",D),e[8]=D,e[9]=j):j=e[9];let S;e[10]===Symbol.for("react.memo_cache_sentinel")?(S={minHeight:hc,maxHeight:ko},e[10]=S):S=e[10];let A;return e[11]!==d||e[12]!==k||e[13]!==j||e[14]!==x||e[15]!==g||e[16]!==w||e[17]!==y||e[18]!==n?(A=s.jsx("textarea",{ref:f,value:n,onChange:x,placeholder:g,rows:1,disabled:d,autoCorrect:w,autoCapitalize:y,spellCheck:k,className:j,style:S}),e[11]=d,e[12]=k,e[13]=j,e[14]=x,e[15]=g,e[16]=w,e[17]=y,e[18]=n,e[19]=A):A=e[19],A};function pj(t){return t.inputSpellcheckEnabled}const fj=t=>{const e=at.c(30),{highlights:n,onInsert:r}=t,{t:a}=mt();if(n.length===0)return null;let i;e[0]!==n||e[1]!==r?(i=()=>{r(n)},e[0]=n,e[1]=r,e[2]=i):i=e[2];const o=i;let c;e[3]!==a?(c=a("gitView.commit.aiHighlights.title"),e[3]=a,e[4]=c):c=e[4];let d;e[5]!==c?(d=s.jsx("p",{className:"typography-micro text-muted-foreground",children:c}),e[5]=c,e[6]=d):d=e[6];let p;e[7]!==a?(p=a("gitView.commit.aiHighlights.insertAria"),e[7]=a,e[8]=p):p=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(I,{name:"arrow-down",className:"size-4"}),e[9]=m):m=e[9];let u;e[10]!==o||e[11]!==p?(u=s.jsx(Pt,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"icon",className:"size-6",onClick:o,"aria-label":p,children:m})}),e[10]=o,e[11]=p,e[12]=u):u=e[12];let f;e[13]!==a?(f=a("gitView.commit.aiHighlights.insertTooltip"),e[13]=a,e[14]=f):f=e[14];let b;e[15]!==f?(b=s.jsx(At,{sideOffset:8,children:f}),e[15]=f,e[16]=b):b=e[16];let h;e[17]!==u||e[18]!==b?(h=s.jsxs(It,{children:[u,b]}),e[17]=u,e[18]=b,e[19]=h):h=e[19];let v;e[20]!==d||e[21]!==h?(v=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d,h]}),e[20]=d,e[21]=h,e[22]=v):v=e[22];let x;e[23]!==n?(x=n.map(hj),e[23]=n,e[24]=x):x=e[24];let g;e[25]!==x?(g=s.jsx("ul",{className:"space-y-1",children:x}),e[25]=x,e[26]=g):g=e[26];let w;return e[27]!==v||e[28]!==g?(w=s.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[v,g]}),e[27]=v,e[28]=g,e[29]=w):w=e[29],w};function hj(t,e){return s.jsx("li",{className:"typography-meta text-foreground",children:t},`${t}-${e}`)}const gj=t=>{const e=at.c(72),{selectedCount:n,commitMessage:r,onCommitMessageChange:a,generatedHighlights:i,onInsertHighlights:o,onGenerateMessage:c,isGeneratingMessage:d,onCommit:p,onCommitAndPush:m,commitAction:u,gitmojiEnabled:f,onOpenGitmojiPicker:b}=t,{t:h}=mt(),v=n>0;let x;e[0]!==u||e[1]!==r||e[2]!==v?(x=r.trim()&&v&&u===null,e[0]=u,e[1]=r,e[2]=v,e[3]=x):x=e[3];const g=x,{isMobile:w,hasTouchInput:y}=an();let k;e[4]!==h?(k=h("gitView.commit.title"),e[4]=h,e[5]=k):k=e[5];let D;e[6]!==k?(D=s.jsx("div",{className:"flex w-full items-center justify-between px-0 pt-2 pb-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:k})}),e[6]=k,e[7]=D):D=e[7];let j;e[8]!==v||e[9]!==h?(j=v?null:s.jsx("p",{className:"typography-meta text-muted-foreground",children:h("gitView.commit.selectFilesHint")}),e[8]=v,e[9]=h,e[10]=j):j=e[10];let S;e[11]!==i||e[12]!==o?(S=s.jsx(fj,{highlights:i,onInsert:o}),e[11]=i,e[12]=o,e[13]=S):S=e[13];let A;e[14]!==h?(A=h("gitView.commit.messagePlaceholder"),e[14]=h,e[15]=A):A=e[15];const E=u!==null;let P;e[16]!==r||e[17]!==y||e[18]!==w||e[19]!==a||e[20]!==A||e[21]!==E?(P=s.jsx(mj,{value:r,onChange:a,placeholder:A,disabled:E,hasTouchInput:y,isMobile:w}),e[16]=r,e[17]=y,e[18]=w,e[19]=a,e[20]=A,e[21]=E,e[22]=P):P=e[22];let C;e[23]!==f||e[24]!==b||e[25]!==h?(C=f&&s.jsxs(be,{variant:"outline",size:"sm",onClick:b,className:"w-fit",type:"button",children:[s.jsx(I,{name:"emotion-happy",className:"size-4"}),h("gitView.commit.addGitmoji")]}),e[23]=f,e[24]=b,e[25]=h,e[26]=C):C=e[26];const N=d||u!==null||n===0;let T;e[27]!==h?(T=h("gitView.commit.generateAria"),e[27]=h,e[28]=T):T=e[28];let M;e[29]!==d?(M=d?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"ai-generate-2",className:"size-4 text-primary"}),e[29]=d,e[30]=M):M=e[30];let R;e[31]!==h?(R=h("gitView.commit.generate"),e[31]=h,e[32]=R):R=e[32];let O;e[33]!==R?(O=s.jsx("span",{className:"commit-actions__label",children:R}),e[33]=R,e[34]=O):O=e[34];let z;e[35]!==c||e[36]!==N||e[37]!==T||e[38]!==M||e[39]!==O?(z=s.jsxs(be,{variant:"outline",size:"sm",onClick:c,disabled:N,type:"button","aria-label":T,className:"commit-actions__btn",children:[M,O]}),e[35]=c,e[36]=N,e[37]=T,e[38]=M,e[39]=O,e[40]=z):z=e[40];let B;e[41]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx("div",{className:"flex-1"}),e[41]=B):B=e[41];const $=!g||d;let _;e[42]!==h?(_=h("gitView.commit.commitAria"),e[42]=h,e[43]=_):_=e[43];let Q;e[44]!==u||e[45]!==h?(Q=u==="commit"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.committing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-commit",className:"size-4"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.commit")})]}),e[44]=u,e[45]=h,e[46]=Q):Q=e[46];let W;e[47]!==p||e[48]!==$||e[49]!==_||e[50]!==Q?(W=s.jsx(be,{size:"sm",variant:"outline",onClick:p,disabled:$,className:"commit-actions__btn whitespace-nowrap","aria-label":_,children:Q}),e[47]=p,e[48]=$,e[49]=_,e[50]=Q,e[51]=W):W=e[51];let ne;e[52]!==g||e[53]!==u||e[54]!==d||e[55]!==w||e[56]!==m||e[57]!==h?(ne=w?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(be,{variant:"default",size:"sm",onClick:()=>m(),disabled:!g||d,className:"h-7 w-7 p-0","aria-label":h("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"arrow-up",className:"size-3.5"})})}),s.jsx(At,{side:"top",children:s.jsx("p",{children:h("gitView.commit.push")})})]}):s.jsx(be,{size:"sm",variant:"default",onClick:()=>m(),disabled:!g||d,className:"commit-actions__btn","aria-label":h("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.pushing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"arrow-up",className:"size-3.5"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.push")})]})}),e[52]=g,e[53]=u,e[54]=d,e[55]=w,e[56]=m,e[57]=h,e[58]=ne):ne=e[58];let re;e[59]!==z||e[60]!==W||e[61]!==ne?(re=s.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[z,B,W,ne]}),e[59]=z,e[60]=W,e[61]=ne,e[62]=re):re=e[62];let ue;e[63]!==re||e[64]!==j||e[65]!==S||e[66]!==P||e[67]!==C?(ue=s.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[j,S,P,C,re]}),e[63]=re,e[64]=j,e[65]=S,e[66]=P,e[67]=C,e[68]=ue):ue=e[68];let Y;return e[69]!==ue||e[70]!==D?(Y=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[D,ue]}),e[69]=ue,e[70]=D,e[71]=Y):Y=e[71],Y},xj=t=>{const e=at.c(16),{onOpenStashes:n}=t,{t:r}=mt();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(I,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=a):a=e[0];let i;e[1]!==r?(i=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=i):i=e[2];let o;e[3]!==i?(o=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:i}),e[3]=i,e[4]=o):o=e[4];let c;e[5]!==r?(c=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=c):c=e[6];let d;e[7]!==c?(d=s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:c}),e[7]=c,e[8]=d):d=e[8];let p;e[9]!==n||e[10]!==r?(p=n?s.jsxs(be,{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]=p):p=e[11];let m;return e[12]!==o||e[13]!==d||e[14]!==p?(m=s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[a,o,d,p]}),e[12]=o,e[13]=d,e[14]=p,e[15]=m):m=e[15],m};function Vh(t){const e=at.c(63),{draft:n,onEdit:r,onDelete:a,className:i,maxWidth:o}=t,{t:c}=mt(),p=Al()?.currentTheme,[m,u]=ze.useState(!1),f=typeof n.text=="string"?n.text:"";let b;e[0]!==f?(b=f.length>150||f.split(`
|
|
7
|
+
`).length>3,e[0]=f,e[1]=b):b=e[1];const h=b;let v;e[2]!==i?(v=me("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden transition-all duration-200",i),e[2]=i,e[3]=v):v=e[3];const x=p?.colors?.surface?.elevated,g=p?.colors?.interactive?.border,w=o?`${Math.max(200,Math.floor(o))}px`:void 0;let y;e[4]!==x||e[5]!==g||e[6]!==w?(y={backgroundColor:x,borderColor:g,maxWidth:w},e[4]=x,e[5]=g,e[6]=w,e[7]=y):y=e[7];let k;e[8]!==n.fileLabel?(k=s.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),e[8]=n.fileLabel,e[9]=k):k=e[9];let D;e[10]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx("span",{children:"•"}),e[10]=D):D=e[10];let j;e[11]!==n.endLine||e[12]!==n.startLine||e[13]!==c?(j=c("inlineComment.range.lines",{start:n.startLine,end:n.endLine}),e[11]=n.endLine,e[12]=n.startLine,e[13]=c,e[14]=j):j=e[14];let S;e[15]!==j?(S=s.jsx("span",{children:j}),e[15]=j,e[16]=S):S=e[16];let A;e[17]!==n.side?(A=n.side&&s.jsxs("span",{children:["(",n.side,")"]}),e[17]=n.side,e[18]=A):A=e[18];let E;e[19]!==S||e[20]!==A||e[21]!==k?(E=s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[k,D,S,A]}),e[19]=S,e[20]=A,e[21]=k,e[22]=E):E=e[22];const P=m||!h,C=!m&&h&&"line-clamp-3";let N;e[23]!==C?(N=me("text-sm whitespace-pre-wrap break-words leading-relaxed",C),e[23]=C,e[24]=N):N=e[24];let T;e[25]!==f||e[26]!==N?(T=s.jsx("div",{className:N,children:f}),e[25]=f,e[26]=N,e[27]=T):T=e[27];let M;e[28]!==h||e[29]!==m||e[30]!==c?(M=h&&s.jsx(kr,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"h-6 px-0 mt-1 text-xs text-muted-foreground hover:text-foreground w-full justify-start",children:m?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"arrow-up-s",className:"size-3 mr-1"}),c("inlineComment.actions.showLess")]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"arrow-down-s",className:"size-3 mr-1"}),c("inlineComment.actions.showMore")]})})}),e[28]=h,e[29]=m,e[30]=c,e[31]=M):M=e[31];let R;e[32]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(xr,{}),e[32]=R):R=e[32];let O;e[33]!==P||e[34]!==T||e[35]!==M?(O=s.jsxs(gr,{open:P,onOpenChange:u,children:[T,M,R]}),e[33]=P,e[34]=T,e[35]=M,e[36]=O):O=e[36];let z;e[37]!==E||e[38]!==O?(z=s.jsxs("div",{className:"flex-1 min-w-0",children:[E,O]}),e[37]=E,e[38]=O,e[39]=z):z=e[39];let B;e[40]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(Bs,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"more",className:"size-4"})})}),e[40]=B):B=e[40];let $;e[41]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(I,{name:"edit",className:"size-4 mr-2"}),e[41]=$):$=e[41];let _;e[42]!==c?(_=c("inlineComment.actions.editComment"),e[42]=c,e[43]=_):_=e[43];let Q;e[44]!==r||e[45]!==_?(Q=s.jsxs(Vt,{onClick:r,children:[$,_]}),e[44]=r,e[45]=_,e[46]=Q):Q=e[46];let W;e[47]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx(I,{name:"delete-bin",className:"size-4 mr-2"}),e[47]=W):W=e[47];let ne;e[48]!==c?(ne=c("inlineComment.actions.deleteComment"),e[48]=c,e[49]=ne):ne=e[49];let re;e[50]!==a||e[51]!==ne?(re=s.jsxs(Vt,{onClick:a,className:"text-destructive",children:[W,ne]}),e[50]=a,e[51]=ne,e[52]=re):re=e[52];let ue;e[53]!==Q||e[54]!==re?(ue=s.jsxs(_s,{children:[B,s.jsxs(zs,{align:"end",children:[Q,re]})]}),e[53]=Q,e[54]=re,e[55]=ue):ue=e[55];let Y;e[56]!==z||e[57]!==ue?(Y=s.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[z,ue]}),e[56]=z,e[57]=ue,e[58]=Y):Y=e[58];let le;return e[59]!==v||e[60]!==Y||e[61]!==y?(le=s.jsx("div",{className:v,style:y,"data-comment-card":"true",children:Y}),e[59]=v,e[60]=Y,e[61]=y,e[62]=le):le=e[62],le}function fl(t){const e=at.c(57),{initialText:n,onSave:r,onCancel:a,fileLabel:i,lineRange:o,isEditing:c,className:d,maxWidth:p}=t,m=n===void 0?"":n,u=c===void 0?!1:c,{t:f}=mt(),h=Al()?.currentTheme,{isMobile:v}=an(),[x,g]=l.useState(m),w=ze.useRef(null),y=ze.useRef(o);let k,D;e[0]!==o?(k=()=>{o&&(y.current=o)},D=[o],e[0]=o,e[1]=k,e[2]=D):(k=e[1],D=e[2]),ze.useEffect(k,D);const j=Sj,S=j(o);let A,E;e[3]!==v?(A=()=>{const ce=w.current;if(!ce)return;const se=ce.closest(".overlay-scrollbar-container"),oe=se?.scrollTop??window.scrollY,te=se?.scrollLeft??window.scrollX;if(v){ce.scrollIntoView({behavior:"auto",block:"nearest"});try{ce.focus({preventScroll:!0})}catch{ce.focus()}return}try{ce.focus({preventScroll:!0})}catch{ce.focus()}const ke=ce.value.length;try{ce.setSelectionRange(ke,ke)}catch{}requestAnimationFrame(()=>{se?(se.scrollTop=oe,se.scrollLeft=te):window.scrollTo({top:oe,left:te})})},E=[v],e[3]=v,e[4]=A,e[5]=E):(A=e[4],E=e[5]),ze.useEffect(A,E);let P;e[6]!==a||e[7]!==r||e[8]!==x?(P=ce=>{(ce.metaKey||ce.ctrlKey)&&ce.key==="Enter"?(ce.preventDefault(),x.trim()&&r(x,j(y.current))):ce.key==="Escape"&&(ce.preventDefault(),a())},e[6]=a,e[7]=r,e[8]=x,e[9]=P):P=e[9];const C=P;let N;e[10]!==r||e[11]!==x?(N=ce=>{ce.stopPropagation(),x.trim()&&r(x,j(y.current))},e[10]=r,e[11]=x,e[12]=N):N=e[12];const T=N;let M;e[13]!==d?(M=me("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden animate-in fade-in zoom-in-95 duration-200",d),e[13]=d,e[14]=M):M=e[14];const R=h?.colors?.surface?.elevated,O=h?.colors?.interactive?.border,z=p?`${Math.max(200,Math.floor(p))}px`:void 0;let B;e[15]!==R||e[16]!==O||e[17]!==z?(B={backgroundColor:R,borderColor:O,maxWidth:z},e[15]=R,e[16]=O,e[17]=z,e[18]=B):B=e[18];const $="true",_=Nj,Q=jj,W="p-3",ne=(i||o)&&s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2",children:[i&&s.jsx("span",{className:"truncate max-w-[200px]",children:i}),i&&o&&s.jsx("span",{children:"•"}),S&&s.jsx("span",{children:f("inlineComment.range.lines",{start:S.start,end:S.end})})]});let re;e[19]===Symbol.for("react.memo_cache_sentinel")?(re=ce=>g(ce.target.value),e[19]=re):re=e[19];let ue;e[20]!==f?(ue=f("inlineComment.input.placeholder"),e[20]=f,e[21]=ue):ue=e[21];let Y;e[22]!==C||e[23]!==ue||e[24]!==x?(Y=s.jsx(bn,{simple:!0,ref:w,value:x,onChange:re,onKeyDown:C,placeholder:ue,outerClassName:"rounded-[var(--radius-xl)] bg-[var(--surface-subtle)] ring-1 ring-inset ring-border/60 focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]",className:"min-h-[80px] px-3 py-2.5 text-sm resize-y"}),e[22]=C,e[23]=ue,e[24]=x,e[25]=Y):Y=e[25];let le;e[26]!==f?(le=f("inlineComment.actions.cancel"),e[26]=f,e[27]=le):le=e[27];let J;e[28]!==a||e[29]!==le?(J=s.jsx(be,{variant:"ghost",size:"sm",onClick:a,onPointerDown:wj,onTouchStart:vj,className:"h-8 text-muted-foreground hover:text-foreground",children:le}),e[28]=a,e[29]=le,e[30]=J):J=e[30];let L;e[31]!==x?(L=x.trim(),e[31]=x,e[32]=L):L=e[32];const V=!L,K=h?.colors?.status?.success,X=h?.colors?.status?.successForeground;let U;e[33]!==K||e[34]!==X?(U={backgroundColor:K,color:X},e[33]=K,e[34]=X,e[35]=U):U=e[35];let ae;e[36]!==u||e[37]!==f?(ae=f(u?"inlineComment.actions.save":"inlineComment.actions.comment"),e[36]=u,e[37]=f,e[38]=ae):ae=e[38];let ve;e[39]!==T||e[40]!==V||e[41]!==U||e[42]!==ae?(ve=s.jsx(be,{size:"sm",onClick:T,onPointerDown:yj,onTouchStart:bj,disabled:V,className:"h-8 min-w-[80px]",style:U,children:ae}),e[39]=T,e[40]=V,e[41]=U,e[42]=ae,e[43]=ve):ve=e[43];let ie;e[44]!==J||e[45]!==ve?(ie=s.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[J,ve]}),e[44]=J,e[45]=ve,e[46]=ie):ie=e[46];let fe;e[47]!==ne||e[48]!==Y||e[49]!==ie?(fe=s.jsxs("div",{className:W,children:[ne,Y,ie]}),e[47]=ne,e[48]=Y,e[49]=ie,e[50]=fe):fe=e[50];let H;return e[51]!==B||e[52]!==_||e[53]!==Q||e[54]!==fe||e[55]!==M?(H=s.jsx("div",{className:M,style:B,"data-comment-input":$,onPointerDown:_,onTouchStart:Q,children:fe}),e[51]=B,e[52]=_,e[53]=Q,e[54]=fe,e[55]=M,e[56]=H):H=e[56],H}function bj(t){return t.stopPropagation()}function yj(t){return t.stopPropagation()}function vj(t){return t.stopPropagation()}function wj(t){return t.stopPropagation()}function jj(t){return t.stopPropagation()}function Nj(t){return t.stopPropagation()}function Sj(t){if(!t)return;const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}}const kj=t=>{const e=Math.min(t.startLine,t.endLine),n=Math.max(t.startLine,t.endLine);return{...t,startLine:e,endLine:n}},hl=t=>{const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}};function qd(t){const e=at.c(40),{t:n}=mt(),{source:r,fileLabel:a,language:i,getCodeForRange:o,toStoreRange:c,fromDraftRange:d}=t,p=_t(Tj),m=_t(Dj),u=ti(Aj),f=ti(Pj),b=ti(Ij),h=ti(Cj),[v,x]=l.useState(null),[g,w]=l.useState(""),[y,k]=l.useState(null),D=p??(m?"draft":null);let j;e:{if(!D||!a){let W;e[0]===Symbol.for("react.memo_cache_sentinel")?(W=[],e[0]=W):W=e[0],j=W;break e}let $;e[1]!==h||e[2]!==D?($=h[D]??[],e[1]=h,e[2]=D,e[3]=$):$=e[3];const _=$;let Q;if(e[4]!==a||e[5]!==_||e[6]!==r){let W;e[8]!==a||e[9]!==r?(W=ne=>ne.source===r&&ne.fileLabel===a,e[8]=a,e[9]=r,e[10]=W):W=e[10],Q=_.filter(W),e[4]=a,e[5]=_,e[6]=r,e[7]=Q}else Q=e[7];j=Q}const S=j;let A;e[11]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{x(null),w(""),k(null)},e[11]=A):A=e[11];const E=A;let P;e[12]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{E()},e[12]=P):P=e[12];const C=P;let N;e[13]!==d?(N=$=>{const _=hl(d($));x(_),w($.text),k($.id)},e[13]=d,e[14]=N):N=e[14];const T=N;let M;e[15]!==y||e[16]!==b?(M=$=>{b($.sessionKey,$.id),y===$.id&&E()},e[15]=y,e[16]=b,e[17]=M):M=e[17];const R=M;let O;e[18]!==u||e[19]!==y||e[20]!==a||e[21]!==o||e[22]!==i||e[23]!==v||e[24]!==D||e[25]!==r||e[26]!==n||e[27]!==c||e[28]!==f?(O=($,_)=>{const Q=_??v,W=$.trim();if(!Q||!W||!a)return;if(!D){G.error(n("inlineComment.toast.selectSessionToSave"));return}const ne=hl(Q),re=kj(c(ne)),ue=o(ne);y?f(D,y,{fileLabel:a,startLine:re.startLine,endLine:re.endLine,side:re.side,code:ue,language:i,text:W}):u({sessionKey:D,source:r,fileLabel:a,startLine:re.startLine,endLine:re.endLine,side:re.side,code:ue,language:i,text:W}),E()},e[18]=u,e[19]=y,e[20]=a,e[21]=o,e[22]=i,e[23]=v,e[24]=D,e[25]=r,e[26]=n,e[27]=c,e[28]=f,e[29]=O):O=e[29];const z=O;let B;return e[30]!==g||e[31]!==R||e[32]!==S||e[33]!==y||e[34]!==d||e[35]!==z||e[36]!==v||e[37]!==D||e[38]!==T?(B={sessionKey:D,drafts:S,selection:v,setSelection:x,commentText:g,setCommentText:w,editingDraftId:y,setEditingDraftId:k,reset:E,cancel:C,startEdit:T,deleteDraft:R,saveComment:z,fromDraftRange:d},e[30]=g,e[31]=R,e[32]=S,e[33]=y,e[34]=d,e[35]=z,e[36]=v,e[37]=D,e[38]=T,e[39]=B):B=e[39],B}function Cj(t){return t.drafts}function Ij(t){return t.removeDraft}function Pj(t){return t.updateDraft}function Aj(t){return t.addDraft}function Dj(t){return t.newSessionDraft?.open}function Tj(t){return t.currentSessionId}function Uh(t){const{drafts:e,editingDraftId:n,commentText:r,selection:a,isDragging:i,fileLabel:o,newWidgetId:c,mapDraftToRange:d,onSave:p,onCancel:m,onEdit:u,onDelete:f}=t,b=[];for(const h of e){const v=d(h);if(h.id===n){b.push({afterLine:v.end,id:`edit-${h.id}`,content:s.jsx(fl,{initialText:r,fileLabel:o,lineRange:v,isEditing:!0,onSave:p,onCancel:m},`edit-${h.id}`)});continue}b.push({afterLine:v.end,id:`card-${h.id}`,content:s.jsx(Vh,{draft:h,onEdit:()=>u(h),onDelete:()=>f(h)},`card-${h.id}`)})}if(a&&!n&&!i){const h={...a,start:Math.min(a.start,a.end),end:Math.max(a.start,a.end)};b.push({afterLine:h.end,id:c,content:s.jsx(fl,{initialText:r,fileLabel:o,lineRange:h,isEditing:!1,onSave:p,onCancel:m},c)})}return b}const qo=t=>{if(t.type==="new"){const e=Math.min(t.selection.start,t.selection.end),n=Math.max(t.selection.start,t.selection.end);return`new-comment-${t.selection.side??"additions"}-${e}-${n}`}return`draft-${t.draft.id}`},Mj=t=>{const{drafts:e,editingDraftId:n,selection:r}=t,a=[];for(const i of e){if(!Number.isFinite(i.endLine))continue;const o=Math.max(1,Math.floor(i.endLine)),c=i.side==="original"?"deletions":"additions";a.push({lineNumber:o,side:c,metadata:{type:i.id===n?"edit":"saved",draft:i}})}return r&&!n&&a.push({lineNumber:Math.max(r.start,r.end),side:r.side??"additions",metadata:{type:"new",selection:r}}),a};function Ej(t){const e=t.trim();if(!e)return null;if(/^-?\d+(\.\d+)?$/.test(e)){const n=Number.parseFloat(e);return Number.isFinite(n)?n:null}if(e.endsWith("px")){const n=Number.parseFloat(e.slice(0,-2));return Number.isFinite(n)?n:null}return null}function bm(t){if(!(!t||t<=0))return Math.max(200,Math.floor(t))}function Rj(t){const{diffRootRef:e,drafts:n,selection:r,editingDraftId:a,commentText:i,fileLabel:o,onSave:c,onCancel:d,onEdit:p,onDelete:m}=t,[u,f]=l.useState(0),[b,h]=l.useState(null),v=l.useMemo(()=>!r||a?null:qo({type:"new",selection:r}),[a,r]),x=l.useMemo(()=>{const y=n.map(k=>qo({type:k.id===a?"edit":"saved",draft:k}));return v&&y.push(v),y},[n,a,v]),g=l.useCallback(y=>{const k=e.current;if(!k)return null;const D=k.querySelector("diffs-container");if(!(D instanceof HTMLElement))return null;const j=D.querySelector(`[data-annotation-id="${y}"]`);if(j instanceof HTMLElement)return j;const S=D.shadowRoot;return S?S.querySelector(`[data-annotation-id="${y}"]`):null},[e]);l.useEffect(()=>{if(x.length===0)return;let y=!1,k=0;const D=12,j=()=>{y||x.every(A=>!!g(A))||k>=D||(k+=1,requestAnimationFrame(()=>{y||(f(A=>A+1),j())}))};return j(),()=>{y=!0}},[x,g]),l.useEffect(()=>{const y=e.current;if(!y)return;const k=()=>{const j=getComputedStyle(y),S=Ej(j.getPropertyValue("--oc-context-panel-width")),A=y.getBoundingClientRect(),E=S??A.width;h(E>0?E:null)};k();const D=new ResizeObserver(()=>{k()});return D.observe(y),window.addEventListener("resize",k),()=>{D.disconnect(),window.removeEventListener("resize",k)}},[e]);const w=l.useCallback(y=>{const D=e.current?.getBoundingClientRect(),j=y.closest("[data-annotation-content]"),S=j instanceof HTMLElement?j.getBoundingClientRect():y.getBoundingClientRect(),A=[S.width];D&&A.push(D.right-S.left);const E=A.filter(P=>Number.isFinite(P)&&P>0);return E.length>0?bm(Math.min(...E)):bm(b)},[e,b]);return s.jsxs(s.Fragment,{children:[n.map(y=>{const k=qo({type:y.id===a?"edit":"saved",draft:y}),D=g(k);if(!D)return null;const j=w(D);return y.id===a?Bi.createPortal(s.jsx(fl,{initialText:i,fileLabel:o,lineRange:{start:y.startLine,end:y.endLine,side:y.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:d,maxWidth:j}),D,`draft-edit-${y.id}`):Bi.createPortal(s.jsx(Vh,{draft:y,onEdit:()=>p(y),onDelete:()=>m(y),maxWidth:j}),D,`draft-card-${y.id}`)}),r&&!a&&v&&(()=>{const y=g(v);if(!y)return null;const k=w(y);return Bi.createPortal(s.jsx(fl,{initialText:i,fileLabel:o,lineRange:r,isEditing:!1,onSave:c,onCancel:d,maxWidth:k}),y,v)})()]})}function Fj(){return new Worker(sx,{type:"module"})}const Lj=["typescript","javascript","tsx","jsx","json","markdown"],od={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let ym,vm;const wm=t=>{const e=od[t],n=new nx({workerFactory:Fj,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:Lj,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},Oj=t=>{if(!(typeof window>"u"))return t==="split"?(vm??=wm("split"),vm):(ym??=wm("unified"),ym)},$j=t=>{const e=at.c(7),{children:n,renderTheme:r}=t,a=ld("unified"),i=ld("split");let o,c;e[0]!==r||e[1]!==i||e[2]!==a?(o=()=>{a&&a.setRenderOptions({theme:r,lineDiffType:od.unified.lineDiffType}),i&&i.setRenderOptions({theme:r,lineDiffType:od.split.lineDiffType})},c=[r,i,a],e[0]=r,e[1]=i,e[2]=a,e[3]=o,e[4]=c):(o=e[3],c=e[4]),ze.useEffect(o,c);let d;return e[5]!==n?(d=s.jsx(s.Fragment,{children:n}),e[5]=n,e[6]=d):d=e[6],d},Bj=t=>{const e=at.c(11),{children:n}=t,r=Al();let a,i;if(e[0]!==r?.availableThemes||e[1]!==r?.darkThemeId||e[2]!==r?.lightThemeId){const p=ui(!1),m=ui(!0),u=r?.lightThemeId??p.metadata.id,f=r?.darkThemeId??m.metadata.id;i=r?.availableThemes.find(b=>b.metadata.id===u)??p,a=r?.availableThemes.find(b=>b.metadata.id===f)??m,mi(i),mi(a),e[0]=r?.availableThemes,e[1]=r?.darkThemeId,e[2]=r?.lightThemeId,e[3]=a,e[4]=i}else a=e[3],i=e[4];let o;e[5]!==a.metadata.id||e[6]!==i.metadata.id?(o={light:i.metadata.id,dark:a.metadata.id},e[5]=a.metadata.id,e[6]=i.metadata.id,e[7]=o):o=e[7];const c=o;let d;return e[8]!==n||e[9]!==c?(d=s.jsx($j,{renderTheme:c,children:n}),e[8]=n,e[9]=c,e[10]=d):d=e[10],d},ld=t=>{const e=at.c(2),n=t===void 0?"unified":t;let r;return e[0]!==n?(r=Oj(n),e[0]=n,e[1]=r):r=e[1],r},zj=5e5,_j=`
|
|
8
|
+
:host {
|
|
9
|
+
font-family: var(--font-mono);
|
|
10
|
+
font-size: var(--text-code);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
pre, [data-code] {
|
|
14
|
+
font-family: var(--font-mono);
|
|
15
|
+
font-size: var(--text-code);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* Mobile touch selection support */
|
|
19
|
+
[data-line-number] {
|
|
20
|
+
touch-action: manipulation;
|
|
21
|
+
-webkit-tap-highlight-color: transparent;
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* Ensure interactive line numbers work on touch */
|
|
26
|
+
pre[data-interactive-line-numbers] [data-line-number] {
|
|
27
|
+
touch-action: manipulation;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
[data-diff-header],
|
|
31
|
+
[data-diff] {
|
|
32
|
+
[data-separator] {
|
|
33
|
+
height: 24px !important;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`;function Vj(t){let e=2166136261;for(let n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=e+((e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24))>>>0;return e.toString(16)}function jm(t){const e=t.length>400?`${t.slice(0,200)}${t.slice(-200)}`:t;return`${t.length}:${Vj(e)}`}const Uj=(t,e,n)=>{const i=(n.side==="deletions"?t:e).split(`
|
|
37
|
+
`),o=Math.min(n.start,n.end),c=Math.max(n.start,n.end),d=Math.max(1,o),p=Math.min(i.length,c);return d>p?"":i.slice(d-1,p).join(`
|
|
38
|
+
`)},Wj=(t,e)=>t===e?!0:!t||!e?!1:t.start===e.start&&t.end===e.end&&t.side===e.side,Co=new WeakMap,Kj={lineHeight:24,hunkSeparatorHeight:24,fileGap:0};function Hj(t){const e=t.closest("[data-diff-virtual-root]");if(e instanceof HTMLElement){const n=e.querySelector("[data-diff-virtual-content]");return{key:e,root:e,content:n instanceof HTMLElement?n:void 0}}return{key:document,root:document,content:void 0}}function Gj(t){if(typeof document>"u")return null;const e=Hj(t);let n=Co.get(e.key);if(!n){const a=new ix;a.setup(e.root,e.content),n={virtualizer:a,refs:0},Co.set(e.key,n)}n.refs+=1;let r=!1;return{virtualizer:n.virtualizer,release:()=>{if(r)return;r=!0;const a=Co.get(e.key);a&&(a.refs-=1,!(a.refs>0)&&(a.virtualizer.cleanUp(),Co.delete(e.key)))}}}const Yd=({original:t,modified:e,language:n,fileName:r,renderSideBySide:a,wrapLines:i,layout:o="fill"})=>{const c=Al(),d=c?.currentTheme.metadata.variant==="dark",p=c?.availableThemes.find(K=>K.metadata.id===c.lightThemeId)??ui(!1),m=c?.availableThemes.find(K=>K.metadata.id===c.darkThemeId)??ui(!0),{isMobile:u}=an(),f=qd({source:"diff",fileLabel:r||"unknown",language:n,getCodeForRange:K=>Uj(t,e,K),toStoreRange:K=>({startLine:K.start,endLine:K.end,side:K.side==="deletions"?"original":"modified"}),fromDraftRange:K=>({start:K.startLine,end:K.endLine,side:K.side==="original"?"deletions":"additions"})}),{drafts:b,selection:h,setSelection:v,commentText:x,setCommentText:g,editingDraftId:w,saveComment:y,cancel:k,startEdit:D,deleteDraft:j}=f,S=ze.useRef(null),A=ze.useRef(null),E=ze.useRef(!1),P=ze.useRef(null);ze.useEffect(()=>{S.current=h},[h]),ze.useEffect(()=>{A.current=w},[w]);const C=ze.useCallback(K=>{if(E.current)return;const X=S.current;if(u&&X&&K&&K.side===X.side){const U=Math.min(X.start,K.start),ae=Math.max(X.end,K.end);v({...K,start:U,end:ae})}else v(K);K&&(A.current||g(""))},[u,g,v]),N=ze.useCallback(()=>{k()},[k]),T=ze.useCallback(K=>{const X=document.createElement("div");X.style.position="relative";const U=qo(K.metadata);return X.dataset.annotationId=U,X.dataset.annotationSide=K.side,X.dataset.annotationLine=String(K.lineNumber),X},[]),M=ze.useCallback((K,X)=>{y(K,X??h??void 0)},[y,h]),R=ze.useCallback(K=>{v(K);const X=_.current;if(X)try{E.current=!0,X.setSelectedLines(K),P.current=K}catch{}finally{E.current=!1}},[v]),O=ze.useCallback(K=>{const X=K.closest("[data-line-type]")?.getAttribute("data-line-type")??K.getAttribute("data-line-type");if(X==="change-deletion")return"deletions";if(X==="change-addition")return"additions";const U=K.getAttribute("data-column-side")??K.getAttribute("data-side")??K.closest("[data-column-side]")?.getAttribute("data-column-side");if(U==="deletions"||U==="left"||U==="original")return"deletions";if(U==="additions"||U==="right"||U==="modified")return"additions";const ae=K.closest("[data-line-type]");if(ae instanceof HTMLElement){const ve=ae.getBoundingClientRect(),ie=K.getBoundingClientRect(),fe=ve.left+ve.width/2;return ie.left+ie.width/2<fe?"deletions":"additions"}return"additions"},[]);mi(p),mi(m);const z=`${p.metadata.id}:${m.metadata.id}:${d?"dark":"light"}`,B=ze.useRef(null),$=ze.useRef(null),_=ze.useRef(null),Q=ze.useRef(null),[,W]=l.useReducer(K=>K+1,0),ne=ld(a?"split":"unified"),re=ze.useMemo(()=>ju(p),[p]),ue=ze.useMemo(()=>ju(m),[m]);l.useLayoutEffect(()=>{const K=B.current;if(!K)return;const X=K.querySelector("diffs-container");if(!X)return;const U=d?ue:re,ae=(je,Se)=>je.colors?.[Se],ve=ae(re,"terminal.ansiGreen"),ie=ae(re,"terminal.ansiRed"),fe=ae(re,"terminal.ansiBlue"),H=ae(ue,"terminal.ansiGreen"),ce=ae(ue,"terminal.ansiRed"),se=ae(ue,"terminal.ansiBlue");X.style.setProperty("--shiki-light",re.fg),X.style.setProperty("--shiki-light-bg",re.bg),ve&&X.style.setProperty("--shiki-light-addition-color",ve),ie&&X.style.setProperty("--shiki-light-deletion-color",ie),fe&&X.style.setProperty("--shiki-light-modified-color",fe),X.style.setProperty("--shiki-dark",ue.fg),X.style.setProperty("--shiki-dark-bg",ue.bg),H&&X.style.setProperty("--shiki-dark-addition-color",H),ce&&X.style.setProperty("--shiki-dark-deletion-color",ce),se&&X.style.setProperty("--shiki-dark-modified-color",se),X.style.setProperty("--diffs-bg",U.bg),X.style.setProperty("--diffs-fg",U.fg);const oe=d?H:ve,te=d?ce:ie,ke=d?se:fe;oe&&X.style.setProperty("--diffs-addition-color-override",oe),te&&X.style.setProperty("--diffs-deletion-color-override",te),ke&&X.style.setProperty("--diffs-modified-color-override",ke);const Ne=X.shadowRoot?.querySelector("pre");Ne&&(Ne.style.setProperty("--shiki-light",re.fg),Ne.style.setProperty("--shiki-light-bg",re.bg),ve&&Ne.style.setProperty("--shiki-light-addition-color",ve),ie&&Ne.style.setProperty("--shiki-light-deletion-color",ie),fe&&Ne.style.setProperty("--shiki-light-modified-color",fe),Ne.style.setProperty("--shiki-dark",ue.fg),Ne.style.setProperty("--shiki-dark-bg",ue.bg),H&&Ne.style.setProperty("--shiki-dark-addition-color",H),ce&&Ne.style.setProperty("--shiki-dark-deletion-color",ce),se&&Ne.style.setProperty("--shiki-dark-modified-color",se),Ne.style.setProperty("--diffs-bg",U.bg),Ne.style.setProperty("--diffs-fg",U.fg),oe&&Ne.style.setProperty("--diffs-addition-color-override",oe),te&&Ne.style.setProperty("--diffs-deletion-color-override",te),ke&&Ne.style.setProperty("--diffs-modified-color-override",ke))},[ue,z,d,re]);const Y=ze.useMemo(()=>Math.max(t.length,e.length)>zj,[t.length,e.length]),le=ze.useMemo(()=>({theme:{dark:m.metadata.id,light:p.metadata.id},themeType:d?"dark":"light",diffStyle:a?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:Y?0:1e3,maxLineLengthForHighlighting:Y?1:1e3,expansionLineCount:20,overflow:i?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:!0,enableHoverUtility:!1,onLineSelected:C,unsafeCSS:_j,renderAnnotation:T}),[m.metadata.id,d,Y,p.metadata.id,a,i,C,T]),J=ze.useMemo(()=>Mj({drafts:b,editingDraftId:w,selection:h}),[w,b,h]),L=ze.useRef(J);if(ze.useEffect(()=>{L.current=J},[J]),ze.useEffect(()=>{if(typeof window>"u")return;const K=$.current;if(!K||!ne)return;_.current?.cleanUp(),_.current=null,Q.current?.release(),Q.current=null,K.innerHTML="";const X=Gj(K);Q.current=X;const U=X?new rx(le,X.virtualizer,Kj,ne):new ax(le,ne);_.current=U,P.current=null;const ae={name:r||"",contents:t,lang:n,cacheKey:`old:${z}:${r}:${jm(t)}`},ve={name:r||"",contents:e,lang:n,cacheKey:`new:${z}:${r}:${jm(e)}`};return U.render({oldFile:ae,newFile:ve,lineAnnotations:L.current,containerWrapper:K}),requestAnimationFrame(()=>{W()}),()=>{U.cleanUp(),_.current===U&&(_.current=null),X?.release(),X&&Q.current===X&&(Q.current=null),K.innerHTML=""}},[z,r,n,e,le,t,ne]),ze.useEffect(()=>{const K=_.current;if(K){try{K.setLineAnnotations(J)}catch(X){console.error("Failed to apply diff line annotations",X);try{K.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(_.current===K){try{K.rerender()}catch{}W()}})}},[J]),ze.useEffect(()=>{const K=_.current;if(!K||h!==null)return;const X=P.current;if(!Wj(h,X))try{E.current=!0,K.setSelectedLines(h),P.current=h}catch{}finally{E.current=!1}},[h]),ze.useEffect(()=>{const K=$.current;if(!K)return;let X=null,U=()=>{};const ae=()=>{const ie=K.querySelector("diffs-container")?.shadowRoot;if(!ie){X=requestAnimationFrame(ae);return}const fe=H=>{if(!(H instanceof MouseEvent)||H.button!==0||!(H.target instanceof Element))return;const ce=H.target.closest("[data-column-number]");if(!(ce instanceof HTMLElement))return;const se=ce.getAttribute("data-column-number"),oe=se?parseInt(se,10):NaN;if(Number.isNaN(oe))return;const te=O(ce);C({start:oe,end:oe,side:te}),H.preventDefault(),H.stopPropagation()};ie.addEventListener("click",fe,!0),U=()=>{ie.removeEventListener("click",fe,!0)}};return ae(),()=>{X!==null&&cancelAnimationFrame(X),U()}},[z,r,C,O]),ze.useEffect(()=>{const K=$.current;if(!K)return;let X=null,U=null;const ve=setTimeout(()=>{const ie=K.querySelector("diffs-container");if(!(ie instanceof HTMLElement))return;const fe=ie.shadowRoot;X=new MutationObserver(()=>{U&&cancelAnimationFrame(U),U=requestAnimationFrame(()=>{W(),U=null})}),X.observe(ie,{childList:!0,subtree:!0}),fe&&X.observe(fe,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(ve),U&&cancelAnimationFrame(U),X?.disconnect()}},[z,r]),typeof window>"u")return null;const V=s.jsx(Rj,{diffRootRef:B,drafts:b,selection:h,editingDraftId:w,commentText:x,fileLabel:r?.split("/").pop()??"",onSave:M,onCancel:N,onEdit:K=>{R({start:K.startLine,end:K.endLine,side:K.side==="original"?"deletions":"additions"}),D(K)},onDelete:j});return o==="fill"?s.jsx("div",{className:me("flex flex-col relative","size-full"),"data-diff-virtual-root":!0,children:s.jsxs("div",{className:"flex-1 relative min-h-0",children:[s.jsx(Es,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:s.jsx("div",{ref:B,className:"size-full relative",children:s.jsx("div",{ref:$,className:"size-full"})})}),V]})}):s.jsxs("div",{className:me("relative","w-full"),children:[s.jsx("div",{ref:B,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:s.jsx("div",{ref:$,className:"w-full"})}),V]})},Nm=15e3,Sm=500,km=12,Cm=8*1024*1024,Im=t=>typeof t=="string"?0:(t.original?.length??0)+(t.modified?.length??0),Pm=t=>{if(t.size<=km){let a=0;for(const i of t.values())a+=Im(i);if(a<=Cm)return t}const e=Array.from(t.entries()).reverse(),n=new Map;let r=0;for(const[a,i]of e){if(n.size>=km)continue;const o=Im(i);r+o>Cm&&n.size>0||(n.set(a,i),r+=o)}return new Map(Array.from(n.entries()).reverse())};function Am(t){const e=new Date(t);return Number.isNaN(e.getTime())?t:e.toLocaleString(void 0,{hour12:!1,year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function qj(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"}}const Yj=l.memo(t=>{const e=at.c(71),{entry:n,isExpanded:r,onToggle:a,files:i,isLoadingFiles:o,onCopyHash:c,directory:d}=t,{t:p}=mt();let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=new Set,e[0]=m):m=e[0];const[u,f]=l.useState(m);let b;e[1]===Symbol.for("react.memo_cache_sentinel")?(b=new Map,e[1]=b):b=e[1];const[h,v]=l.useState(b);let x;e[2]===Symbol.for("react.memo_cache_sentinel")?(x=new Set,e[2]=x):x=e[2];const[g,w]=l.useState(x);let y;e[3]!==d||e[4]!==n.hash?(y=async K=>{const X=K.path;if(!d){v(U=>new Map(U).set(X,"error"));return}v(U=>Pm(new Map(U).set(X,"loading")));try{const U=bb(d,n.hash,K.path,!1),ae=new Promise(Jj),ve=await Promise.race([U,ae]);v(ie=>Pm(new Map(ie).set(X,ve)))}catch{v(U=>new Map(U).set(X,"error"))}},e[3]=d,e[4]=n.hash,e[5]=y):y=e[5];const k=y;let D;e[6]!==h||e[7]!==g||e[8]!==k||e[9]!==u?(D=async K=>{const X=K.path;if(K.changeType==="R"||K.isBinary){f(ie=>{const fe=new Set(ie);return fe.has(X)?fe.delete(X):fe.add(X),fe});return}const U=h.get(X);if(u.has(X)&&U&&U!=="error"){f(ie=>{const fe=new Set(ie);return fe.delete(X),fe});return}f(ie=>{const fe=new Set(ie);return fe.add(X),fe}),!(U&&U!=="error"||K.insertions+K.deletions>Sm&&!g.has(X))&&await k(K)},e[6]=h,e[7]=g,e[8]=k,e[9]=u,e[10]=D):D=e[10];const j=D,S=r?"bg-sidebar/90":"hover:bg-sidebar/40";let A;e[11]!==S?(A=me("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",S),e[11]=S,e[12]=A):A=e[12];let E;e[13]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),e[13]=E):E=e[13];let P;e[14]!==n.message?(P=s.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:n.message}),e[14]=n.message,e[15]=P):P=e[15];let C;e[16]!==n.author_name?(C=s.jsx("span",{className:"truncate min-w-[3ch]",title:n.author_name,children:n.author_name}),e[16]=n.author_name,e[17]=C):C=e[17];let N;e[18]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx("span",{className:"shrink-0",children:"·"}),e[18]=N):N=e[18];let T;e[19]!==n.date?(T=Am(n.date),e[19]=n.date,e[20]=T):T=e[20];let M;e[21]!==n.date?(M=Am(n.date),e[21]=n.date,e[22]=M):M=e[22];let R;e[23]!==T||e[24]!==M?(R=s.jsx("span",{className:"truncate min-w-0",title:T,children:M}),e[23]=T,e[24]=M,e[25]=R):R=e[25];let O;e[26]!==C||e[27]!==R?(O=s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[C,N,R]}),e[26]=C,e[27]=R,e[28]=O):O=e[28];let z;e[29]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx("span",{className:"shrink-0",children:"·"}),e[29]=z):z=e[29];let B;e[30]!==n.hash?(B=n.hash.slice(0,8),e[30]=n.hash,e[31]=B):B=e[31];let $;e[32]!==B?($=s.jsx("code",{className:"shrink-0 font-mono",children:B}),e[32]=B,e[33]=$):$=e[33];let _;e[34]!==n.hash||e[35]!==c?(_=K=>{K.stopPropagation(),c(n.hash)},e[34]=n.hash,e[35]=c,e[36]=_):_=e[36];let Q;e[37]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx(I,{name:"file-copy",className:"size-3"}),e[37]=Q):Q=e[37];let W;e[38]!==_?(W=s.jsx(Pt,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:_,children:Q})}),e[38]=_,e[39]=W):W=e[39];let ne;e[40]!==p?(ne=p("gitView.history.copySha"),e[40]=p,e[41]=ne):ne=e[41];let re;e[42]!==ne?(re=s.jsx(At,{sideOffset:8,children:ne}),e[42]=ne,e[43]=re):re=e[43];let ue;e[44]!==W||e[45]!==re?(ue=s.jsxs(It,{children:[W,re]}),e[44]=W,e[45]=re,e[46]=ue):ue=e[46];let Y;e[47]!==O||e[48]!==$||e[49]!==ue?(Y=s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[O,z,$,ue]}),e[47]=O,e[48]=$,e[49]=ue,e[50]=Y):Y=e[50];let le;e[51]!==Y||e[52]!==P?(le=s.jsxs("div",{className:"min-w-0 flex-1",children:[P,Y]}),e[51]=Y,e[52]=P,e[53]=le):le=e[53];let J;e[54]!==a||e[55]!==le||e[56]!==A?(J=s.jsxs("button",{type:"button",onClick:a,className:A,children:[E,le]}),e[54]=a,e[55]=le,e[56]=A,e[57]=J):J=e[57];let L;e[58]!==h||e[59]!==i||e[60]!==g||e[61]!==r||e[62]!==o||e[63]!==k||e[64]!==u||e[65]!==p||e[66]!==j?(L=r&&s.jsx("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:o?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:p("gitView.history.loadingFiles")})]}):i.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:p("gitView.history.noFiles")}):s.jsx("ul",{className:"space-y-0.5 py-2",children:i.map(K=>s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>j(K),className:me("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",u.has(K.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[s.jsx("span",{className:me("font-semibold w-3 text-center shrink-0",qj(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:p("gitView.history.binary")}),s.jsx(I,{name:u.has(K.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),u.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:p("gitView.history.renamedNoDiff")}):K.isBinary?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.binaryNoDiff")}):(()=>{const X=K.insertions+K.deletions;if(!g.has(K.path)&&X>Sm)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:p("gitView.history.largeDiffTitle",{count:X})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:p("gitView.history.largeDiffDescription")}),s.jsx(be,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{w(ae=>new Set(ae).add(K.path)),k(K)},children:p("gitView.history.renderDiffAnyway")})]});const U=h.get(K.path);return U==="loading"||U===void 0?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.loadingDiff")}):U==="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:p("gitView.history.diffError")}):s.jsx(Yd,{original:U.original,modified:U.modified,language:pi(K.path)||"",fileName:K.path,renderSideBySide:!1,layout:"inline"})})()})]},K.path))})}),e[58]=h,e[59]=i,e[60]=g,e[61]=r,e[62]=o,e[63]=k,e[64]=u,e[65]=p,e[66]=j,e[67]=L):L=e[67];let V;return e[68]!==J||e[69]!==L?(V=s.jsxs("li",{children:[J,L]}),e[68]=J,e[69]=L,e[70]=V):V=e[70],V});function Jj(t,e){setTimeout(()=>e(new Error(`Timed out after ${Nm}ms`)),Nm)}const Qj=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],Xj=t=>{const e=at.c(56),{log:n,isLogLoading:r,logMaxCount:a,onLogMaxCountChange:i,expandedCommitHashes:o,onToggleCommit:c,commitFilesMap:d,loadingCommitHashes:p,onCopyHash:m,directory:u,showHeader:f,contentMaxHeightClassName:b,branchDivider:h}=t,v=f===void 0?!0:f,x=b===void 0?"max-h-[50vh]":b,g=h===void 0?null:h,{t:w}=mt(),[y,k]=l.useState(!0);if(!n)return null;const D=g!==null&&g.insertBeforeIndex>0&&g.insertBeforeIndex<n.all.length,j=g!==null&&g.insertBeforeIndex===n.all.length,S=D||j;let A;e[0]!==g||e[1]!==D||e[2]!==j||e[3]!==n.all?(A=D?n.all.slice(0,g.insertBeforeIndex):j?n.all:[],e[0]=g,e[1]=D,e[2]=j,e[3]=n.all,e[4]=A):A=e[4];const E=A;let P;if(e[5]!==g||e[6]!==d||e[7]!==x||e[8]!==u||e[9]!==o||e[10]!==D||e[11]!==S||e[12]!==p||e[13]!==n.all||e[14]!==m||e[15]!==c||e[16]!==w||e[17]!==E){const _=D?n.all.slice(g.insertBeforeIndex):[];let Q;e[19]!==g?.direction?(Q=g?.direction==="down"?s.jsx(I,{name:"arrow-down-s",className:"size-3.5"}):s.jsx(I,{name:"arrow-up",className:"size-3.5"}),e[19]=g?.direction,e[20]=Q):Q=e[20];const W=Q;let ne;e[21]!==d||e[22]!==u||e[23]!==o||e[24]!==p||e[25]!==m||e[26]!==c?(ne=ue=>s.jsx("ul",{className:"divide-y divide-border/60",children:ue.map(Y=>s.jsx(Yj,{entry:Y,isExpanded:o.has(Y.hash),onToggle:()=>c(Y.hash),files:d.get(Y.hash)??[],isLoadingFiles:p.has(Y.hash),onCopyHash:m,directory:u},Y.hash))}),e[21]=d,e[22]=u,e[23]=o,e[24]=p,e[25]=m,e[26]=c,e[27]=ne):ne=e[27];const re=ne;P=s.jsx(Es,{outerClassName:`min-h-0 ${x}`,className:"h-full w-full",children:n.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:w("gitView.history.noCommits")})}):S&&g?s.jsxs("div",{className:"flex flex-col gap-0",children:[E.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:re(E)}):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:g.branchName,children:g.branchName}),W]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),_.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:re(_)}):null]}):re(n.all)}),e[5]=g,e[6]=d,e[7]=x,e[8]=u,e[9]=o,e[10]=D,e[11]=S,e[12]=p,e[13]=n.all,e[14]=m,e[15]=c,e[16]=w,e[17]=E,e[18]=P}else P=e[18];const C=P;if(!v){if(S){let Q;return e[28]!==C?(Q=s.jsx("section",{className:"h-full min-h-0",children:C}),e[28]=C,e[29]=Q):Q=e[29],Q}let _;return e[30]!==C?(_=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:C}),e[30]=C,e[31]=_):_=e[31],_}let N;e[32]!==w?(N=w("gitView.history.title"),e[32]=w,e[33]=N):N=e[33];let T;e[34]!==N?(T=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:N}),e[34]=N,e[35]=T):T=e[35];let M;e[36]!==r||e[37]!==y||e[38]!==a||e[39]!==i||e[40]!==w?(M=y&&s.jsx("div",{onClick:Zj,onPointerDown:e0,children:s.jsxs(ds,{value:String(a),onValueChange:_=>i(Number(_)),disabled:r,children:[s.jsx(us,{size:"sm",className:"data-[size=sm]:h-auto h-7 min-h-7 w-auto justify-between px-2 py-0",disabled:r,children:s.jsx(bs,{placeholder:w("gitView.history.commitsPlaceholder")})}),s.jsx(ms,{children:Qj.map(_=>s.jsx(Lt,{value:String(_.value),children:w(_.labelKey)},_.value))})]})}),e[36]=r,e[37]=y,e[38]=a,e[39]=i,e[40]=w,e[41]=M):M=e[41];let R;e[42]!==y?(R=y?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[42]=y,e[43]=R):R=e[43];let O;e[44]!==M||e[45]!==R?(O=s.jsxs("div",{className:"flex items-center gap-2",children:[M,R]}),e[44]=M,e[45]=R,e[46]=O):O=e[46];let z;e[47]!==O||e[48]!==T?(z=s.jsxs(kr,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[T,O]}),e[47]=O,e[48]=T,e[49]=z):z=e[49];let B;e[50]!==C?(B=s.jsx(xr,{children:C}),e[50]=C,e[51]=B):B=e[51];let $;return e[52]!==y||e[53]!==z||e[54]!==B?($=s.jsxs(gr,{open:y,onOpenChange:k,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[z,B]}),e[52]=y,e[53]=z,e[54]=B,e[55]=$):$=e[55],$};function Zj(t){return t.stopPropagation()}function e0(t){return t.stopPropagation()}const t0=9e4,s0=15e3,n0=5*6e4,r0=[2e3,5e3],a0=6e4,i0=2*6e4,o0=5*6e4,l0=720*6e4,c0="openchamber.github-pr-status",d0=t=>t==="closed"||t==="merged",u0=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},Wi=(t,e,n)=>`${t}::${e}`,Io=new Map,Po=new Map,Pi=new Set,Dm=new Map,Li=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),gl=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,Jd=t=>{const e=gl(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},Wh=(t,e)=>Object.entries(t).filter(([,n])=>Jd(n)===e).map(([n])=>n),m0=(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}}},Ao=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},p0=(t,e,n)=>{const r=Wh(t,e),a=r.map(d=>Ao(t[d])).filter(d=>!!d);if(a.length===0)return null;const i=Ao(t[n]);if(i&&Jd(t[n])===e)return i;const o=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&Ao(d)));if(o)return Ao(o);const c=a.find(d=>!!d.remoteName);return c||(a[0]??null)},f0=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:gl(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),h0=t=>({...Li(),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}),fr=ar()(ro((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:Li()}})},setParams:(n,r)=>{t(a=>{const i=a.entries[n]??Li();return{entries:{...a.entries,[n]:m0(i,r)}}})},startWatching:n=>{if(t(i=>{const o=i.entries[n]??Li();return{entries:{...i.entries,[n]:{...o,watchers:o.watchers+1}}}}),Io.has(n))return;const r=i=>{const o=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})},i),c=Po.get(n)??[];c.push(o),Po.set(n,c)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),r0.forEach(i=>r(i));const a=window.setInterval(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const i=e().entries[n];if(!i||i.watchers<=0)return;if(!!!i.status?.pr){const p=Date.now();if(p-i.lastDiscoveryPollAt<n0)return;t(m=>{const u=m.entries[n];return u?{entries:{...m.entries,[n]:{...u,lastDiscoveryPollAt:p}}}:m}),e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}if(d0(i.status?.pr?.state))return;const c=Date.now()-i.lastRefreshAt,d=u0(i.status)?a0:i.status?.checks&&i.status.checks.state!=="pending"?o0:i0;c<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},s0);Io.set(n,a)},stopWatching:n=>{t(o=>{const c=o.entries[n];if(!c)return o;const d=Math.max(0,c.watchers-1);return{entries:{...o.entries,[n]:{...c,watchers:d}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const a=Io.get(n);typeof a=="number"&&window.clearInterval(a),Io.delete(n);const i=Po.get(n);i&&i.length>0&&i.forEach(o=>{window.clearTimeout(o)}),Po.delete(n)},refresh:async(n,r)=>{const a=e(),i=a.entries[n],o=Jd(i);if(!i||!o)return;const c=Wh(a.entries,o),d=c.some(u=>!!a.entries[u]?.status?.pr);if(r?.onlyExistingPr&&!d)return;const p=Dm.get(o)??0;if(!r?.force&&Date.now()-p<t0||Pi.has(o))return;const m=p0(a.entries,o,n);if(m){if(Pi.add(o),Dm.set(o,Date.now()),t(u=>{const f={...u.entries};return c.forEach(b=>{const h=f[b];h&&(f[b]={...h,lastRefreshAt:Date.now(),isLoading:r?.silent?h.isLoading:!0,error:null})}),{entries:f}}),m.githubAuthChecked&&m.githubConnected===!1){t(u=>{const f={...u.entries};return c.forEach(b=>{const h=f[b];h&&(f[b]={...h,status:{connected:!1},error:null,isLoading:r?.silent?h.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?h.isInitialStatusResolved:!0})}),{entries:f}}),Pi.delete(o);return}if(!m.github?.prStatus){t(u=>{const f={...u.entries};return c.forEach(b=>{const h=f[b];h&&(f[b]={...h,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?h.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?h.isInitialStatusResolved:!0})}),{entries:f}}),Pi.delete(o);return}try{t(f=>({...f,activeRequestCount:f.activeRequestCount+1,totalRequestCount:f.totalRequestCount+1}));const u=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0,{force:r?.force});t(f=>{const b={...f.entries};return c.forEach(h=>{const v=b[h];if(!v)return;const x=v.status?.pr,g=u.pr,y=!!(g&&x&&g.number===x.number&&(!g.body||!g.body.trim())&&typeof x.body=="string"&&x.body.trim().length>0)&&g&&x?.body?{...u,pr:{...g,body:x.body}}:u,k=y.resolvedRemoteName??v.resolvedRemoteName??m.remoteName??null,D=gl(v)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};b[h]={...v,status:y,error:null,isLoading:r?.silent?v.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?v.isInitialStatusResolved:!0,resolvedRemoteName:k,identity:{...D,remoteName:k??D.remoteName??null}}}),{entries:b}})}catch(u){const f=u instanceof Error?u.message:String(u);t(b=>{const h={...b.entries};return c.forEach(v=>{const x=h[v];x&&(h[v]={...x,error:f||"Failed to load PR status",isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0})}),{entries:h}})}finally{Pi.delete(o),t(u=>({...u,activeRequestCount:Math.max(0,u.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const a=Array.from(new Set(n.map(i=>{const o=i.directory.trim(),c=i.branch.trim();return!o||!c?null:Wi(o,c,i.remoteName??null)}).filter(i=>!!i)));await Promise.all(a.map(i=>e().refresh(i,r)))},updateStatus:(n,r)=>{t(a=>{const i=a.entries[n]??Li();return{entries:{...a.entries,[n]:{...i,status:r(i.status)}}}})}}),{name:c0,storage:kl(()=>sa()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=gl(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<l0}).map(([e,n])=>[e,f0(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([a,i])=>[a,h0(i)]))}}})),g0=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:"",a=e.mergeable===!1||r==="blocked"||r==="dirty";return n||a?"blocked":"open"},x0=t=>{const e=g0(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}},b0=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 gc=new Map,Tm=new Map;const y0=t=>{const e=at.c(2);let n;return e[0]!==t?(n=r=>{const a=new Map,i=new Map;for(const o of t){const c=r.entries[o];if(!c)continue;const d=x0(c);if(!d)continue;const p=b0(d);a.set(o,p),i.set(o,d)}if(a.size===gc.size){let o=!0;for(const[c,d]of a)if(gc.get(c)!==d){o=!1;break}if(o)return Tm}return gc=a,Tm=i,i},e[0]=t,e[1]=n):n=e[1],fr(n)},v0=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"}},w0=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:"",a=e.mergeable===!1||r==="blocked"||r==="dirty";return n||a?"blocked":"open"},j0=[2e3,5e3],Mm=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),ta=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):""},N0=(t,e)=>{const n=ta(t);if(!n||n.includes("->"))return"";if(e){const a=`${e}/`;return n.startsWith(a)?n.slice(a.length).trim():""}const r=n.indexOf("/");return r>0?n.slice(r+1).trim():n},S0=(t,e)=>`${t}::${e}`,Qd=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},xc=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const i=t.find(o=>o.name===n);if(i)return i}const r=Qd(e.trackingBranch);if(r){const i=r==="origin"?t.find(c=>c.name==="upstream"):null;if(i)return i;const o=t.find(c=>c.name===r);if(o)return o}const a=t.find(i=>i.name==="origin");return a||(t[0]??null)},k0=t=>t.startsWith("pr-"),C0=(t,e)=>{const n=Qd(e),r=new Map(t.map(o=>[o.name,o])),a=[],i=o=>{o&&(a.some(c=>c.name===o.name)||a.push(o))};return n&&i(r.get(n)),i(r.get("upstream")),i(r.get("origin")),t.filter(o=>!k0(o.name)).forEach(o=>i(o)),t.forEach(o=>i(o)),a},bc=new Map,yc=sr;function I0(t,e){const[n,r]=l.useState(null),[a,i]=l.useState([]),o=l.useRef(null);return l.useEffect(()=>{r(null),i([])},[t]),l.useEffect(()=>{if(!t||!e?.repoUpstream||o.current===t)return;o.current=t;let c=!1;return(async()=>{try{const d=await e.repoUpstream(t);if(c||!d?.isFork||!d.upstream||(r(d.upstream),!e.repoBranches))return;try{const p=await e.repoBranches(d.upstream.owner,d.upstream.repo);c||i(p)}catch{}}catch{}})(),()=>{c=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:a}}const P0=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:a=[],remoteBranches:i=[],onGeneratedDescription:o})=>{const{t:c}=mt(),{github:d}=_n(),p=Hn(Ke=>Ke.status),m=Hn(Ke=>Ke.hasChecked),u=Te(Ke=>Ke.setSettingsDialogOpen),f=Te(Ke=>Ke.setSettingsPage),b=Te(Ke=>Ke.setActiveMainTab),h=_t(Ke=>Ke.currentSessionId),{isMobile:v,hasTouchInput:x}=an(),g=l.useCallback(()=>{f("github"),u(!0)},[u,f]),w=l.useMemo(()=>S0(t,e),[t,e]),y=l.useMemo(()=>bc.get(w)??null,[w]),k=fr(Ke=>Ke.ensureEntry),D=fr(Ke=>Ke.setParams),j=fr(Ke=>Ke.startWatching),S=fr(Ke=>Ke.stopWatching),A=fr(Ke=>Ke.refresh),E=fr(Ke=>Ke.updateStatus),[P,C]=l.useState(()=>y?.title??Mm(e)),[N,T]=l.useState(()=>y?.body??""),[M,R]=l.useState(()=>y?.draft??!1),[O,z]=l.useState(()=>y?.additionalContext??""),[B,$]=l.useState(()=>{const Ke=typeof y?.targetBaseBranch=="string"?ta(y.targetBaseBranch):"";return Ke||ta(n)}),[_,Q]=l.useState("squash"),[W,ne]=l.useState(!1),[re,ue]=l.useState(!1),[Y,le]=l.useState(!1),[J,L]=l.useState(!1),[V,K]=l.useState(!1),[X,U]=l.useState(!1),[ae,ve]=l.useState(null),[ie,fe]=l.useState(""),[H,ce]=l.useState(""),[se,oe]=l.useState(!1),[te,ke]=l.useState(!1),[Ne,je]=l.useState(()=>xc(a,{selectedRemoteName:y?.selectedRemoteName,trackingBranch:r})),[Se,De]=l.useState(!1),{detectedUpstream:ye,upstreamBranches:ge}=I0(t,d);l.useEffect(()=>{De(!1)},[t]);const Me=a.some(Ke=>Ke.name==="upstream"),q=!!(t&&e&&n&&(e!==n||(Me||ye!==null))),Ie=l.useMemo(()=>Wi(t,e),[t,e]),Le=fr(Ke=>Ke.entries[Ie]),Pe=Le?.isLoading??!1,he=Le?.status??null,F=Le?.error??null,ee=Le?.isInitialStatusResolved??!1,Ce=l.useMemo(()=>{const Ke=Se?null:Ne?.name?.trim()||null,bt=new Set;for(const Zt of i){const it=N0(Zt,Ke);!it||it==="HEAD"||bt.add(it)}if(Se)for(const Zt of ge)Zt&&Zt!=="HEAD"&&bt.add(Zt);const Ct=ta(n);Ct&&Ct!=="HEAD"&&bt.add(Ct);const Ft=ta(B);return Ft&&Ft!=="HEAD"&&bt.add(Ft),Array.from(bt).sort((Zt,it)=>Zt.localeCompare(it))},[n,i,Ne?.name,B,ge,Se]);l.useEffect(()=>{if(a.length===0){Ne&&je(null);return}(!Ne||!a.some(Ke=>Ke.name===Ne.name))&&je(xc(a,{selectedRemoteName:y?.selectedRemoteName,trackingBranch:r}))},[y?.selectedRemoteName,a,Ne,r]),l.useEffect(()=>{const Ke=ta(n);if(!B&&Ke){$(Ke);return}if(Ce.length!==0&&!Ce.includes(B)){const bt=Ce.includes(Ke)?Ke:Ce[0];bt&&$(bt)}},[Ce,n,B]);const[Fe,we]=l.useState(!1),[Qe,pe]=l.useState(null),[Oe,nt]=l.useState(!1),[Re,de]=l.useState(new Set),[He,st]=l.useState(!1),[qe,et]=l.useState(null),[rt,xe]=l.useState(!1),Ye=l.useRef(new Set),_e=l.useRef(null),We=l.useRef(!1),lt=l.useRef(new Set),Je=l.useRef([]);l.useEffect(()=>{ye&&!Me&&De(!0)},[ye,Me]),l.useEffect(()=>{Se&&ye?.defaultBranch&&$(ye.defaultBranch)},[Se,ye?.defaultBranch]);const Ve=he?.pr??null,yt=Ve?`${t}#${Ve.number}`:null,$t=!!(yt&&ae===yt);l.useEffect(()=>{if(!d?.prContext||!Ve||typeof Ve.body=="string"&&Ve.body.length>0)return;const Ke=`${t}#${Ve.number}`;if(Ye.current.has(Ke))return;Ye.current.add(Ke),ve(Ke);let bt=!1;return d.prContext(t,Ve.number,{includeDiff:!1,includeCheckDetails:!1}).then(Ct=>{if(bt)return;const Ft=Ct?.pr;Ft&&E(Ie,Zt=>!Zt?.pr||Zt.pr.number!==Ve.number?Zt:{...Zt,pr:{...Zt.pr,body:Ft.body||""}})}).catch(()=>{}).finally(()=>{bt||ve(Ct=>Ct===Ke?null:Ct)}),()=>{bt=!0}},[t,d,Ve,Ie,E]),l.useEffect(()=>{if(!Ve){U(!1),fe(""),ce(""),_e.current=null;return}const Ke=_e.current!==null&&_e.current!==Ve.number;Ke&&U(!1),(!X||Ke)&&(fe(Ve.title||""),ce(Ve.body||"")),_e.current=Ve.number},[X,Ve]);const Gt=l.useCallback(async()=>{if(!d?.prContext){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(Ve){we(!0),de(new Set),nt(!0);try{const Ke=await d.prContext(t,Ve.number,{includeDiff:!1,includeCheckDetails:!0});pe(Ke)}catch(Ke){const bt=Ke instanceof Error?Ke.message:String(Ke);G.error(c("gitView.pr.toast.loadCheckDetailsFailed"),{description:bt})}finally{nt(!1)}}},[t,d,Ve,c]),ss=l.useCallback(async()=>{if(!d?.prContext){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(Ve){st(!0),xe(!0);try{const Ke=await d.prContext(t,Ve.number,{includeDiff:!1,includeCheckDetails:!1});et(Ke)}catch(Ke){const bt=Ke instanceof Error?Ke.message:String(Ke);G.error(c("gitView.pr.toast.loadCommentsFailed"),{description:bt})}finally{xe(!1)}}},[t,d,Ve,c]),wt=l.useCallback(Ke=>{if(!Ke)return"";const bt=Date.parse(Ke);return Number.isFinite(bt)?new Date(bt).toLocaleString():Ke},[]),Dt=l.useMemo(()=>{const Ke=p?.user?.login;return typeof Ke=="string"?Ke.trim():""},[p]),Xt=l.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=l.useCallback(Ke=>{const bt=Dt.toLowerCase(),Ct=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return Ke.replace(Ct,(Ft,Zt,it)=>{const zt=`@${it}`,hs=it.toLowerCase();return`${Zt}[${zt}](https://github.com/${hs}${bt&&hs===bt?"?oc-self-mention=1":""})`})},[Dt]),ts=l.useMemo(()=>{const Ke=(qe?.issueComments??[]).map(Ft=>({id:`issue-${Ft.id}`,body:Ft.body||"",authorName:Ft.author?.name||Ft.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Ft.author?.login||null,avatarUrl:Ft.author?.avatarUrl||null,createdAt:Ft.createdAt,context:c("gitView.pr.comments.generalContext"),path:null,line:null})),bt=(qe?.reviewComments??[]).map(Ft=>({id:`review-${Ft.id}`,body:Ft.body||"",authorName:Ft.author?.name||Ft.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Ft.author?.login||null,avatarUrl:Ft.author?.avatarUrl||null,createdAt:Ft.createdAt,context:c("gitView.pr.comments.reviewContext"),path:Ft.path||null,line:Ft.line??null})),Ct=[...Ke,...bt];return Ct.sort((Ft,Zt)=>{const it=Ft.createdAt?Date.parse(Ft.createdAt):0,zt=Zt.createdAt?Date.parse(Zt.createdAt):0,hs=Number.isFinite(it)?it:0,Jt=Number.isFinite(zt)?zt:0;return hs-Jt}),Ct},[qe,c]),dt=l.useCallback(()=>{if(!h)return G.error(c("gitView.pr.toast.noActiveSession"),{description:c("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:Ke,currentModelId:bt,currentAgentName:Ct,currentVariant:Ft}=gt.getState(),Zt=Pl.getState().lastUsedProvider,it=Ke||Zt?.providerID,zt=bt||Zt?.modelID;return!it||!zt?(G.error(c("gitView.pr.toast.noModelSelected")),null):{sessionId:h,providerID:it,modelID:zt,currentAgentName:Ct??null,currentVariant:Ft??null}},[h,c]),Rt=l.useCallback((Ke,bt,Ct,Ft)=>{_t.getState().sendMessage(bt,Ke.providerID,Ke.modelID,Ke.currentAgentName??void 0,void 0,void 0,[{text:Ct,synthetic:!0},{text:Ft,synthetic:!0}],Ke.currentVariant??void 0).catch(Zt=>{const it=Zt instanceof Error?Zt.message:String(Zt);G.error(c("gitView.pr.toast.sendMessageFailed"),{description:it})})},[c]),is=l.useCallback(Ke=>{const bt=Ke.status||"unknown",Ct=Ke.conclusion??void 0,Ft=Ct?`${bt} / ${Ct}`:bt,Zt=Ke.app?.name||Ke.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:Ke.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:Zt?`${Zt} · ${Ft}`:Ft})]}),Ke.detailsUrl?s.jsx(be,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:Ke.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),Ke.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:Ke.output.title}):null,Ke.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap",children:Ke.output.summary}):null,Ke.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:Ke.output.text}):null,Array.isArray(Ke.annotations)&&Ke.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",Ke.annotations.length>20?` (showing 20/${Ke.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:Ke.annotations.slice(0,20).map((it,zt)=>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:[it.title||it.level||"Issue",it.path?` · ${it.path}`:"",typeof it.startLine=="number"?`:${it.startLine}`:"",typeof it.endLine=="number"&&it.endLine!==it.startLine?`-${it.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:it.message}),it.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:it.rawDetails}):null]},`${it.path||"file"}:${it.startLine||zt}:${zt}`))})]}):null,Ke.job?.steps&&Ke.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:Ke.job.steps.map((it,zt)=>{const hs=(it.conclusion||"").toLowerCase(),Jt=hs&&!["success","neutral","skipped"].includes(hs),Ut=`${Ke.id??"run"}:${Ke.job?.jobId??"job"}:${it.number??zt}:${it.name}`,os=Re.has(Ut);return Jt?s.jsxs(gr,{open:os,children:[s.jsxs("button",{type:"button",onClick:()=>{de(tn=>{const Zs=new Set(tn);return Zs.has(Ut)?Zs.delete(Ut):Zs.add(Ut),Zs})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(Jt?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[os?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:it.name}),it.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:it.conclusion}):null]}),s.jsx(xr,{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 it.number=="number"?s.jsxs("div",{children:[c("gitView.pr.checks.stepLabel"),": ",it.number]}):null,it.status?s.jsxs("div",{children:[c("gitView.pr.checks.statusLabel"),": ",it.status]}):null,it.conclusion?s.jsxs("div",{children:[c("gitView.pr.checks.conclusionLabel"),": ",it.conclusion]}):null,it.startedAt?s.jsxs("div",{children:[c("gitView.pr.checks.startedLabel"),": ",wt(it.startedAt)]}):null,it.completedAt?s.jsxs("div",{children:[c("gitView.pr.checks.completedLabel"),": ",wt(it.completedAt)]}):null]})})]},Ut):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:it.name}),it.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:it.conclusion}):null]},Ut)})})]}):null]})},[Re,wt,c]),xs=l.useCallback(async()=>{if(b("chat"),!d?.prContext){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Ve)return;const Ke=dt();if(Ke)try{const bt=await d.prContext(t,Ve.number,{includeDiff:!1,includeCheckDetails:!0}),Ft=(bt.checkRuns??[]).filter(Jt=>{const Ut=typeof Jt.conclusion=="string"?Jt.conclusion.toLowerCase():"";return Ut?!["success","neutral","skipped"].includes(Ut):!1});if(Ft.length===0){G.message(c("gitView.pr.toast.noFailedChecks"));return}const Zt=await Nn("github.pr.checks.review.visible"),it=await Nn("github.pr.checks.review.instructions"),zt=Ft.flatMap(Jt=>(Array.isArray(Jt.annotations)?Jt.annotations:[]).map(os=>({run:Jt.name,level:os.level,title:os.title,path:os.path,startLine:os.startLine,endLine:os.endLine,message:os.message,rawDetails:os.rawDetails}))),hs=`GitHub PR failed checks (JSON)
|
|
39
|
+
${JSON.stringify({repo:bt.repo??null,pr:bt.pr??null,failedChecks:Ft,failedAnnotations:zt},null,2)}`;Rt(Ke,Zt,it,hs)}catch(bt){const Ct=bt instanceof Error?bt.message:String(bt);G.error(c("gitView.pr.toast.loadChecksFailed"),{description:Ct})}},[t,Rt,d,Ve,dt,b,c]),ps=l.useCallback(async()=>{if(b("chat"),!d?.prContext){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Ve)return;const Ke=dt();if(Ke)try{const bt=await d.prContext(t,Ve.number,{includeDiff:!1,includeCheckDetails:!1}),Ct=bt.issueComments??[],Ft=bt.reviewComments??[];if(Ct.length+Ft.length===0){G.message(c("gitView.pr.toast.noPrComments"));return}const it=await Nn("github.pr.comments.review.visible"),zt=await Nn("github.pr.comments.review.instructions"),hs=`GitHub PR comments (JSON)
|
|
40
|
+
${JSON.stringify({repo:bt.repo??null,pr:bt.pr??null,issueComments:Ct,reviewComments:Ft},null,2)}`;Rt(Ke,it,zt,hs)}catch(bt){const Ct=bt instanceof Error?bt.message:String(bt);G.error(c("gitView.pr.toast.loadPrCommentsFailed"),{description:Ct})}},[t,Rt,d,Ve,dt,b,c]),ws=l.useCallback(async Ke=>{st(!1),b("chat");const bt=dt();if(!bt)return;const Ct=await Nn("github.pr.comment.single.visible"),Ft=await Nn("github.pr.comment.single.instructions"),Zt=`GitHub PR comment (JSON)
|
|
41
|
+
${JSON.stringify({repo:qe?.repo??null,pr:qe?.pr??Ve??null,comment:Ke},null,2)}`;Rt(bt,Ct,Ft,Zt)},[qe,Rt,Ve,dt,b]),qt=l.useCallback(async Ke=>{await A(Ie,Ke)},[Ie,A]),Ge=l.useCallback(()=>{Je.current.forEach(Ke=>{window.clearTimeout(Ke)}),Je.current=j0.map(Ke=>window.setTimeout(()=>{qt({force:!0,silent:!0,markInitialResolved:!0})},Ke))},[qt]);l.useEffect(()=>{if(!d?.prStatus||!q||a.length<=1||We.current||he?.pr)return;const Ke=`${w}::${Ne?.name??""}`;if(lt.current.has(Ke))return;lt.current.add(Ke);const bt=C0(a,r).filter(Zt=>Zt.name!==Ne?.name);if(bt.length===0)return;let Ct=!1;return(async()=>{for(const Zt of bt){if(Ct)return;try{if(!(await d.prStatus(t,e,Zt.name))?.pr)continue;if(Ct)return;je(zt=>zt?.name===Zt.name?zt:Zt);return}catch{}}})(),()=>{Ct=!0}},[e,q,t,d,a,Ne?.name,w,he?.pr,r]),l.useEffect(()=>{k(Ie),D(Ie,{directory:t,branch:e,remoteName:Ne?.name??null,canShow:q,github:d,githubAuthChecked:m,githubConnected:p?.connected??null})},[e,q,t,k,d,m,p?.connected,Ie,Ne?.name,D]),l.useEffect(()=>(j(Ie),()=>{S(Ie)}),[Ie,j,S]),l.useEffect(()=>{const Ke=bc.get(w)??null;C(Ke?.title??Mm(e)),T(Ke?.body??""),R(Ke?.draft??!1),$(Ke?.targetBaseBranch?ta(Ke.targetBaseBranch):ta(n));const bt=xc(a,{selectedRemoteName:Ke?.selectedRemoteName,trackingBranch:r});je(Ct=>Ct?.name===bt?.name?Ct:bt)},[n,e,a,w,r]),l.useEffect(()=>{qt({markInitialResolved:!0})},[Ie,qt]),l.useEffect(()=>{!q||!Ne?.name||qt({force:!0,silent:!0,markInitialResolved:!0})},[q,qt,Ne?.name]),l.useEffect(()=>{const Ke=he?.resolvedRemoteName?.trim();if(!Ke||We.current)return;const bt=a.find(Ct=>Ct.name===Ke);bt&&je(Ct=>Ct?.name===bt.name?Ct:bt)},[a,he?.resolvedRemoteName]),l.useEffect(()=>{const Ke=he?.pr?.state==="closed"||he?.pr?.state==="merged",bt=Le?.lastRefreshAt??0,Ct=Date.now()-bt>6e4,Ft=!Ke&&Ct,Zt=()=>{Ft&&qt({force:!0,silent:!0})},it=()=>{document.visibilityState==="visible"&&Ft&&qt({force:!0,silent:!0})};return window.addEventListener("focus",Zt),document.addEventListener("visibilitychange",it),()=>{window.removeEventListener("focus",Zt),document.removeEventListener("visibilitychange",it)}},[qt,he?.pr?.state,Le?.lastRefreshAt]),l.useEffect(()=>{m&&p?.connected===!1&&qt({force:!0,silent:!0,markInitialResolved:!0})},[m,p,qt]),l.useEffect(()=>{!t||!e||bc.set(w,{title:P,body:N,draft:M,additionalContext:O,targetBaseBranch:B,selectedRemoteName:Ne?.name})},[w,P,N,M,O,B,Ne?.name,t,e]),l.useEffect(()=>{const Ke=Je.current;return()=>{Ke.forEach(bt=>{window.clearTimeout(bt)}),Je.current=[]}},[]);const St=l.useCallback(async()=>{if(!W&&t){ne(!0);try{const bt={base:Se&&ye?.defaultBranchSha?ye.defaultBranchSha:B,head:e};O&&(bt.context=O);const Ct=await yb(t,bt);Ct.title?.trim()&&C(Ct.title.trim()),Ct.body?.trim()&&T(Ct.body.trim()),o?.()}catch(Ke){const bt=Ke instanceof Error?Ke.message:String(Ke);G.error(c("gitView.pr.toast.generateDescriptionFailed"),{description:bt})}finally{ne(!1)}}},[O,e,ye?.defaultBranchSha,t,W,o,B,c,Se]),Mt=l.useCallback(async()=>{if(!d?.prCreate){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}const Ke=P.trim();if(!Ke){G.error(c("gitView.pr.toast.titleRequired"));return}const bt=B.trim();if(!bt){G.error(c("gitView.pr.toast.baseBranchRequired"));return}if(!Se&&bt===e){G.error(c("gitView.pr.toast.baseMustDifferFromHead"));return}ue(!0);try{const Ct=Qd(r),Ft=Se&&ye,Zt=await d.prCreate({directory:t,title:Ke,head:e,base:bt,...N.trim()?{body:N}:{},draft:M,...Ft?{targetRepo:{owner:ye.owner,repo:ye.repo},headRemote:"origin"}:{...Ne?{remote:Ne.name}:{},...Ct&&Ct!==Ne?.name?{headRemote:Ct}:{}}});G.success(c("gitView.pr.toast.prCreated")),E(Ie,it=>it&&{...it,pr:Zt}),await qt({force:!0}),Ge()}catch(Ct){const Ft=Ct instanceof Error?Ct.message:String(Ct);G.error(c("gitView.pr.toast.createPrFailed"),{description:Ft})}finally{ue(!1)}},[N,e,ye,t,M,d,Ie,qt,Ge,Ne,B,P,r,E,Se,c]),Nt=l.useCallback(async Ke=>{if(!d?.prMerge){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}L(!0);try{const bt=await d.prMerge({directory:t,number:Ke.number,method:_});bt.merged?G.success(c("gitView.pr.toast.prMerged")):G.message(c("gitView.pr.toast.prNotMerged"),{description:bt.message||c("gitView.pr.notMergeable")}),await qt({force:!0}),Ge()}catch(bt){const Ct=bt instanceof Error?bt.message:String(bt);G.error(c("gitView.pr.toast.mergeFailed"),{description:Ct}),Ke.url&&yc(Ke.url)}finally{L(!1)}},[t,d,_,qt,Ge,c]),Kt=l.useCallback(async Ke=>{if(!d?.prReady){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}K(!0);try{await d.prReady({directory:t,number:Ke.number}),G.success(c("gitView.pr.toast.markedReady")),await qt({force:!0}),Ge()}catch(bt){const Ct=bt instanceof Error?bt.message:String(bt);G.error(c("gitView.pr.toast.markReadyFailed"),{description:Ct}),Ke.url&&yc(Ke.url)}finally{K(!1)}},[t,d,qt,Ge,c]),ns=l.useCallback(async Ke=>{if(!d?.prUpdate){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}const bt=ie.trim();if(!bt){G.error(c("gitView.pr.toast.titleRequired"));return}le(!0);try{const Ct=await d.prUpdate({directory:t,number:Ke.number,title:bt,body:H});E(Ie,Ft=>Ft&&{...Ft,pr:{...Ft.pr??Ke,...Ct}}),U(!1),G.success(c("gitView.pr.toast.prUpdated")),await qt({force:!0}),Ge()}catch(Ct){const Ft=Ct instanceof Error?Ct.message:String(Ct);G.error(c("gitView.pr.toast.updatePrFailed"),{description:Ft})}finally{le(!1)}},[t,H,ie,d,Ie,qt,Ge,E,c]);if(!q)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:c("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pullRequest.availableOnFeatureBranches")})]})});const js=he?.repo?.url||null,ls=Se&&ye?.url?ye.url:js,ks=he?.checks??null,Os=!!he?.canMerge,xt=!!he?.connected,cs=m&&he?.connected===!1,jt=w0(he),Tt=jt?`var(--pr-${jt})`:"var(--status-info)",Z=jt==="draft"?"git-pr-draft":jt==="merged"?"git-merge":jt==="closed"?"git-close-pull-request":"git-pull-request",ft=Ve?[`${Ve.state}${Ve.draft?" (draft)":""}`,Ve.mergeable===!1?c("gitView.pr.notMergeable"):null,Ve.state==="open"&&typeof Ve.mergeableState=="string"&&Ve.mergeableState&&Ve.mergeableState!=="unknown"?Ve.mergeableState:null].filter(Boolean).join(" · "):"",kt=ks?ks.total>0?`${ks.success}/${ks.total} ${c("gitView.pr.checks.label")}`:`${ks.state} ${c("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:[Ve?s.jsxs(It,{children:[s.jsx(Pt,{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:()=>{yc(Ve.url)},"aria-label":c("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(I,{name:Z,className:"size-4 shrink-0",style:{color:Tt}})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(I,{name:Z,className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:c("gitView.pullRequest.title")}),Ve?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",Ve.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Pe?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(It,{children:[s.jsx(Pt,{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:Pe,onClick:()=>{qt({force:!0})},"aria-label":c("gitView.pr.actions.refreshAria"),children:s.jsx(I,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.refresh")})})]})]})]}),Ve?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:Tt},children:ft}),ks?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${v0(ks.state)}`}),kt]}):null,r&&Ne&&r.split("/")[0]!==Ne.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",Ne.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[cs?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.githubNotConnected")}),s.jsx(be,{variant:"outline",size:"sm",onClick:g,className:"w-fit",children:c("gitView.pr.actions.openSettings")})]}):null,F?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:c("gitView.pr.statusUnavailable")}),s.jsx("div",{className:"typography-meta text-muted-foreground break-words",children:F}),ls?s.jsx(be,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:ls,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!Ve&&!ee&&!F&&!cs?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"}),c("gitView.pr.checkingStatus")]}):Ve?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:[X?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Wt,{value:ie,onChange:Ke=>fe(Ke.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x}),s.jsx(bn,{value:H,onChange:Ke=>ce(Ke.target.value),className:"min-h-[120px] bg-background/80",placeholder:c("gitView.pr.placeholder.description"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:Ve.title}),Ve.body?.trim()?s.jsx(Ra,{content:Ve.body,className:"typography-markdown-body text-muted-foreground break-words mt-1"}):s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:c($t?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),Os&&Ve.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.draftMustBeReady")}):null,Os?null:s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("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:[Ve.state==="open"?X?s.jsxs(s.Fragment,{children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{U(!1),fe(Ve.title||""),ce(Ve.body||"")},disabled:Y,"aria-label":c("gitView.pr.actions.cancelEditingAria"),children:s.jsx(I,{name:"close",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(be,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>ns(Ve),disabled:Y||!ie.trim(),"aria-label":c("gitView.pr.actions.savePrAria"),children:Y?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"check",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.savePr")})})]})]}):s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>U(!0),"aria-label":c("gitView.pr.actions.editPrAria"),children:s.jsx(I,{name:"edit",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.editPr")})})]}):null,ks?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Gt,disabled:Oe,"aria-label":c("gitView.pr.actions.openChecksAria"),children:Oe?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"information",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.openChecks")})})]}):null,ks?.failure?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(be,{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:xs,"aria-label":c("gitView.pr.actions.resolveFailedChecksAria"),children:s.jsx(I,{name:"error-warning",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.resolveFailedChecks")})})]}):null,s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:ss,"aria-label":c("gitView.pr.actions.openCommentsAria"),children:s.jsx(I,{name:"chat-4",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.openComments")})})]}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(be,{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:ps,"aria-label":c("gitView.pr.actions.shareCommentsAria"),children:s.jsx(I,{name:"ai-generate-2",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.shareComments")})})]}),Os&&Ve.draft&&Ve.state==="open"?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Kt(Ve),disabled:V||J||Y||X,"aria-label":c("gitView.pr.actions.markReadyAria"),children:V?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.markReady")})})]}):null]}),s.jsx("div",{className:"ml-auto flex items-center gap-2",children:Os?s.jsxs(s.Fragment,{children:[s.jsxs(ds,{value:_,onValueChange:Ke=>Q(Ke),disabled:J||Ve.state!=="open",children:[s.jsx(us,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(bs,{})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"squash",children:c("gitView.pr.mergeMethod.squash")}),s.jsx(Lt,{value:"merge",children:c("gitView.pr.mergeMethod.merge")}),s.jsx(Lt,{value:"rebase",children:c("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(be,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>Nt(Ve),disabled:J||V||Ve.state!=="open"||Ve.draft||Y||X,"aria-label":c("gitView.pr.actions.mergePrAria"),children:J?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-merge",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("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:c("gitView.pr.createTitle")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," ",s.jsx("span",{className:"opacity-60",children:"(local)"})," → ",B," ",s.jsxs("span",{className:"opacity-60",children:["(",Se&&ye?"upstream":"remote",")"]})]})]}),ls?s.jsx(be,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:ls,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),c("gitView.pr.actions.repo")]})}):null]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.title")}),s.jsx(Wt,{value:P,onChange:Ke=>C(Ke.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.baseBranch")}),Ce.length>0?s.jsxs(ds,{value:B,onValueChange:$,children:[s.jsx(us,{className:"h-9",children:s.jsx(bs,{placeholder:c("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(ms,{children:Ce.map(Ke=>s.jsx(Lt,{value:Ke,children:Ke},Ke))})]}):s.jsx(Wt,{value:B,onChange:Ke=>$(Ke.target.value),placeholder:c("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.description")}),s.jsx(bn,{value:N,onChange:Ke=>T(Ke.target.value),className:"min-h-[110px]",placeholder:c("gitView.pr.placeholder.whatChanged"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":M,onClick:()=>R(Ke=>!Ke),onKeyDown:Ke=>{(Ke.key===" "||Ke.key==="Enter")&&(Ke.preventDefault(),R(bt=>!bt))},children:[s.jsx(fs,{size:"sm",checked:M,onChange:Ke=>R(Ke),ariaLabel:c("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:c("gitView.pr.field.draft")})]}),v?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:c("gitView.pr.additionalContext.optional")}),s.jsx(be,{variant:"outline",size:"sm",onClick:()=>ke(!0),children:O.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),O.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:c("gitView.pr.additionalContext.added")})})]}):s.jsxs(gr,{open:se,onOpenChange:oe,children:[s.jsxs(kr,{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:c("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:se?c("gitView.pr.actions.hide"):O.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),s.jsx(xr,{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(bn,{value:O,onChange:Ke=>z(Ke.target.value),className:"min-h-[100px] bg-transparent",placeholder:c("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.hint")})]})})]}),s.jsx(Mr,{open:te,onClose:()=>ke(!1),title:c("gitView.pr.additionalContext.title"),footer:s.jsx(be,{size:"sm",onClick:()=>ke(!1),className:"w-full",children:c("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(bn,{value:O,onChange:Ke=>z(Ke.target.value),className:"min-h-[200px] bg-transparent",placeholder:c("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(be,{variant:"outline",size:"sm",onClick:St,disabled:W||re,children:[W?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"ai-generate-2",className:"size-4 text-primary"}),c("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(be,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Mt,disabled:re||!xt||!B.trim()||!Se&&B.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:c("gitView.pr.actions.createPr")})]})]})]})]}),s.jsx(vs,{open:Fe,onOpenChange:we,children:s.jsxs(ys,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(As,{children:[s.jsxs(Ss,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-pull-request",className:"h-5 w-5"}),c("gitView.pr.checkDetails.title")]}),s.jsx(Fs,{children:Ve?c("gitView.pr.numberLabel",{number:Ve.number}):c("gitView.pullRequest.title")})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto mt-2",children:[Oe?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"}),c("gitView.loading.loading")]}):null,Oe?null:s.jsx("div",{className:"space-y-3",children:Array.isArray(Qe?.checkRuns)&&Qe?.checkRuns.length>0?Qe.checkRuns.map((Ke,bt)=>{const Ct=`${Ke.id??"run"}:${Ke.job?.jobId??"job"}:${Ke.name}:${bt}`;return s.jsx("div",{className:"p-1",children:is(Ke)},Ct)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(vs,{open:He,onOpenChange:st,children:s.jsxs(ys,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(As,{children:s.jsxs(Ss,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-pull-request",className:"h-5 w-5"}),c("gitView.pr.comments.title"),Ve?s.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.numberLabel",{number:Ve.number})}):null]})}),s.jsxs(ao,{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"}),c("gitView.loading.loading")]}):null,rt?null:s.jsx("div",{className:"space-y-4",children:ts.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:ts.map((Ke,bt)=>{const Ct=(Ke.authorName||"?").charAt(0).toUpperCase(),Ft=bt===ts.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[Ft?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:Ke.avatarUrl?s.jsx("img",{src:Ke.avatarUrl,alt:Ke.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:Ct})}),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:[Ke.authorName,Ke.authorLogin&&Ke.authorLogin!==Ke.authorName?` · @${Ke.authorLogin}`:""]}),Ke.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:wt(Ke.createdAt)}):null,s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs(be,{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:()=>{ws(Ke)},"aria-label":c("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(I,{name:"ai-generate-2",className:"size-3.5"}),c("gitView.pr.actions.sendToAgent")]})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Ke.context,Ke.path?` · ${Ke.path}`:"",Ke.line?`:${Ke.line}`:""]}),s.jsx(Ra,{content:Yt(Ke.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",Xt].filter(Boolean).join(" ")})]})]},Ke.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.comments.empty")})})]})]})})]})},A0=t=>{const e=at.c(150),{open:n,onOpenChange:r,conflictFiles:a,directory:i,operation:o,onAbort:c,onClearState:d}=t;let p;e[0]!==a?(p=a===void 0?[]:a,e[0]=a,e[1]=p):p=e[1];const m=p,{t:u}=mt(),f=_t(D0),b=_t(T0),h=Ea(M0),v=Ea(E0),x=Te(R0),[g,w]=l.useState(!1),[y,k]=l.useState(null),[D,j]=l.useState(null);let S,A;e[2]!==i||e[3]!==n||e[4]!==u?(S=()=>{!n||!i||(w(!0),j(null),k(null),vb(i).then(De=>{k(De)}).catch(De=>{const ye=De instanceof Error?De.message:u("gitView.conflict.loadFailed");j(ye)}).finally(()=>{w(!1)}))},A=[n,i,u],e[2]=i,e[3]=n,e[4]=u,e[5]=S,e[6]=A):(S=e[5],A=e[6]),l.useEffect(S,A);let E;e[7]!==y||e[8]!==i||e[9]!==o?(E=async()=>{if(!y)return null;const De=o==="merge"?"merge":"rebase",ye=y.headInfo||(o==="merge"?"MERGE_HEAD":"REBASE_HEAD"),ge=o==="merge"?"git commit --no-edit":"git rebase --continue",Me=await Nn("git.conflict.resolve.visible",{operation_label:De,head_ref:ye}),Ue=await Nn("git.conflict.resolve.instructions",{operation_label:De,directory:i,operation:o,head_info:y.headInfo||"N/A",continue_cmd:ge}),q=`${De} conflict context (JSON)
|
|
42
|
+
${JSON.stringify({directory:i,operation:y.operation,headInfo:y.headInfo,statusPorcelain:y.statusPorcelain,unmergedFiles:y.unmergedFiles,diff:y.diff},null,2)}`;return{visibleText:Me,instructionsText:Ue,payloadText:q}},e[7]=y,e[8]=i,e[9]=o,e[10]=E):E=e[10];const P=E;let C;e[11]!==c||e[12]!==r?(C=()=>{c(),r(!1)},e[11]=c,e[12]=r,e[13]=C):C=e[13];const N=C;let T;e[14]!==d||e[15]!==r?(T=()=>{d?.(),r(!1)},e[14]=d,e[15]=r,e[16]=T):T=e[16];const M=T;let R;e[17]!==P||e[18]!==b||e[19]!==d||e[20]!==r||e[21]!==x||e[22]!==h||e[23]!==v||e[24]!==u?(R=async()=>{const De=await P();if(!De){G.error(u("gitView.conflict.noDetailsAvailable"));return}if(!b){G.error(u("gitView.conflict.noActiveSession"),{description:u("gitView.conflict.noActiveSessionDescription")});return}h(De.visibleText,"replace"),v([{text:De.instructionsText,synthetic:!0},{text:De.payloadText,synthetic:!0}]),x("chat"),d?.(),r(!1)},e[17]=P,e[18]=b,e[19]=d,e[20]=r,e[21]=x,e[22]=h,e[23]=v,e[24]=u,e[25]=R):R=e[25];const O=R;let z;e[26]!==P||e[27]!==i||e[28]!==d||e[29]!==r||e[30]!==f||e[31]!==x||e[32]!==u?(z=async()=>{const De=await P();if(!De){G.error(u("gitView.conflict.noDetailsAvailable"));return}f({directoryOverride:i,initialPrompt:De.visibleText,syntheticParts:[{text:De.instructionsText,synthetic:!0},{text:De.payloadText,synthetic:!0}]}),x("chat"),d?.(),r(!1)},e[26]=P,e[27]=i,e[28]=d,e[29]=r,e[30]=f,e[31]=x,e[32]=u,e[33]=z):z=e[33];const B=z;let $,_,Q,W,ne,re,ue,Y,le,J,L,V,K,X,U,ae,ve,ie,fe,H,ce,se;if(e[34]!==y||e[35]!==m||e[36]!==b||e[37]!==N||e[38]!==M||e[39]!==O||e[40]!==B||e[41]!==g||e[42]!==D||e[43]!==r||e[44]!==n||e[45]!==o||e[46]!==u){const De=u(o==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),ye=y?.unmergedFiles||m;Q=vs,ce=n,se=r,_=ys,H="max-w-md w-[calc(100vw-2rem)]",X="flex flex-col gap-4 overflow-hidden";let ge;e[69]===Symbol.for("react.memo_cache_sentinel")?(ge=s.jsx(I,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=ge):ge=e[69];const Me=s.jsxs("div",{className:"flex items-center gap-2",children:[ge,s.jsx(Ss,{children:u("gitView.conflict.detectedTitle",{operation:De})})]});let Ue;e[70]!==o||e[71]!==u?(Ue=u("gitView.conflict.detectedDescription",{operation:o}),e[70]=o,e[71]=u,e[72]=Ue):Ue=e[72];let q;e[73]!==Ue?(q=s.jsx(Fs,{children:Ue}),e[73]=Ue,e[74]=q):q=e[74],e[75]!==Me||e[76]!==q?(U=s.jsxs(As,{children:[Me,q]}),e[75]=Me,e[76]=q,e[77]=U):U=e[77],e[78]!==g||e[79]!==u?(ae=g&&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:u("gitView.conflict.loading")})]}),e[78]=g,e[79]=u,e[80]=ae):ae=e[80],e[81]!==D||e[82]!==u?(ve=D&&s.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:u("gitView.conflict.errorLoadingDetails",{message:D})}),e[81]=D,e[82]=u,e[83]=ve):ve=e[83],e[84]!==ye||e[85]!==u?(ie=ye.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:u("gitView.conflict.conflictedFiles")}),s.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:ye.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:ye.map(F0)})})]}),e[84]=ye,e[85]=u,e[86]=ie):ie=e[86],e[87]!==y||e[88]!==u?(fe=y?.headInfo&&s.jsxs("div",{className:"space-y-1 overflow-hidden",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:u("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:y.headInfo})]}),e[87]=y,e[88]=u,e[89]=fe):fe=e[89],L="flex flex-col gap-2 pt-2";let Ie;e[90]!==B?(Ie=()=>{B()},e[90]=B,e[91]=Ie):Ie=e[91];const Le=g||!y;let Pe;e[92]!==g?(Pe=g?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"add",className:"size-4"}),e[92]=g,e[93]=Pe):Pe=e[93];let he;e[94]!==u?(he=u("gitView.conflict.resolveNewSession"),e[94]=u,e[95]=he):he=e[95],e[96]!==Ie||e[97]!==Le||e[98]!==Pe||e[99]!==he?(V=s.jsxs(be,{variant:"default",onClick:Ie,disabled:Le,className:"w-full gap-2",children:[Pe,he]}),e[96]=Ie,e[97]=Le,e[98]=Pe,e[99]=he,e[100]=V):V=e[100];let F;e[101]!==O?(F=()=>{O()},e[101]=O,e[102]=F):F=e[102];const ee=g||!y||!b;let Ce;e[103]!==g?(Ce=g?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"chat-1",className:"size-4"}),e[103]=g,e[104]=Ce):Ce=e[104];let Fe;e[105]!==u?(Fe=u("gitView.conflict.resolveCurrentSession"),e[105]=u,e[106]=Fe):Fe=e[106],e[107]!==F||e[108]!==ee||e[109]!==Ce||e[110]!==Fe?(K=s.jsxs(be,{variant:"outline",onClick:F,disabled:ee,className:"w-full gap-2",children:[Ce,Fe]}),e[107]=F,e[108]=ee,e[109]=Ce,e[110]=Fe,e[111]=K):K=e[111],le="flex gap-2 pt-1";let we;e[112]!==u?(we=u("gitView.conflict.continueLater"),e[112]=u,e[113]=we):we=e[113],e[114]!==M||e[115]!==we?(J=s.jsx(be,{variant:"ghost",size:"sm",onClick:M,className:"flex-1",children:we}),e[114]=M,e[115]=we,e[116]=J):J=e[116],$=be,W="destructive",ne="sm",re=N,ue="flex-1",Y=u("gitView.conflict.abortOperation",{operation:De}),e[34]=y,e[35]=m,e[36]=b,e[37]=N,e[38]=M,e[39]=O,e[40]=B,e[41]=g,e[42]=D,e[43]=r,e[44]=n,e[45]=o,e[46]=u,e[47]=$,e[48]=_,e[49]=Q,e[50]=W,e[51]=ne,e[52]=re,e[53]=ue,e[54]=Y,e[55]=le,e[56]=J,e[57]=L,e[58]=V,e[59]=K,e[60]=X,e[61]=U,e[62]=ae,e[63]=ve,e[64]=ie,e[65]=fe,e[66]=H,e[67]=ce,e[68]=se}else $=e[47],_=e[48],Q=e[49],W=e[50],ne=e[51],re=e[52],ue=e[53],Y=e[54],le=e[55],J=e[56],L=e[57],V=e[58],K=e[59],X=e[60],U=e[61],ae=e[62],ve=e[63],ie=e[64],fe=e[65],H=e[66],ce=e[67],se=e[68];let oe;e[117]!==$||e[118]!==W||e[119]!==ne||e[120]!==re||e[121]!==ue||e[122]!==Y?(oe=s.jsx($,{variant:W,size:ne,onClick:re,className:ue,children:Y}),e[117]=$,e[118]=W,e[119]=ne,e[120]=re,e[121]=ue,e[122]=Y,e[123]=oe):oe=e[123];let te;e[124]!==le||e[125]!==J||e[126]!==oe?(te=s.jsxs("div",{className:le,children:[J,oe]}),e[124]=le,e[125]=J,e[126]=oe,e[127]=te):te=e[127];let ke;e[128]!==L||e[129]!==V||e[130]!==K||e[131]!==te?(ke=s.jsxs("div",{className:L,children:[V,K,te]}),e[128]=L,e[129]=V,e[130]=K,e[131]=te,e[132]=ke):ke=e[132];let Ne;e[133]!==X||e[134]!==U||e[135]!==ae||e[136]!==ve||e[137]!==ie||e[138]!==fe||e[139]!==ke?(Ne=s.jsxs("div",{className:X,children:[U,ae,ve,ie,fe,ke]}),e[133]=X,e[134]=U,e[135]=ae,e[136]=ve,e[137]=ie,e[138]=fe,e[139]=ke,e[140]=Ne):Ne=e[140];let je;e[141]!==_||e[142]!==H||e[143]!==Ne?(je=s.jsx(_,{className:H,children:Ne}),e[141]=_,e[142]=H,e[143]=Ne,e[144]=je):je=e[144];let Se;return e[145]!==Q||e[146]!==ce||e[147]!==se||e[148]!==je?(Se=s.jsx(Q,{open:ce,onOpenChange:se,children:je}),e[145]=Q,e[146]=ce,e[147]=se,e[148]=je,e[149]=Se):Se=e[149],Se};function D0(t){return t.openNewSessionDraft}function T0(t){return t.currentSessionId}function M0(t){return t.setPendingInputText}function E0(t){return t.setPendingSyntheticParts}function R0(t){return t.setActiveMainTab}function F0(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const L0=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:a})=>{const{t:i}=mt(),[o,c]=l.useState(!0),[d,p]=l.useState(!1),m=i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),u=async()=>{p(!0);try{await a(o),e(!1)}catch(b){const h=b instanceof Error?b.message:`Failed to ${n}`;G.error(h)}finally{p(!1)}},f=()=>{d||e(!1)};return s.jsx(vs,{open:t,onOpenChange:d?void 0:e,children:s.jsxs(ys,{className:"max-w-md",children:[s.jsxs(As,{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(Ss,{children:i("gitView.stash.title")})]}),s.jsx(Fs,{children:i("gitView.stash.description",{operation:n})})]}),s.jsxs("div",{className:"py-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:i("gitView.stash.thisWill")}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[s.jsx("li",{children:i("gitView.stash.stepStash")}),s.jsxs("li",{children:[i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",i(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",s.jsx("span",{className:"font-mono text-primary",children:r})]}),o&&s.jsx("li",{children:i("gitView.stash.stepRestore")})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(fs,{checked:o,onChange:c,disabled:d,ariaLabel:i("gitView.stash.restoreAria")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!d&&c(!o),children:i("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(Hs,{className:"gap-2",children:[s.jsx(be,{variant:"ghost",size:"sm",onClick:f,disabled:d,children:i("gitView.common.cancel")}),s.jsx(be,{variant:"default",size:"sm",onClick:u,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),i("gitView.common.processing")]}):i("gitView.stash.confirmButton",{operation:m})})]})]})})},O0=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:a,hasUnresolvedConflicts:i=!1,isLoading:o=!1})=>{const{t:c}=mt(),[d,p]=l.useState(null),m=t&&t.head,u=e&&(e.headName||e.onto),f=m?"merge":u?"rebase":null;if(!f)return null;const b=async()=>{p("continue");try{await n()}finally{p(null)}},h=async()=>{p("abort");try{await r()}finally{p(null)}},v=d!==null,x=c(f==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),g=f==="merge"?"git-merge":"git-branch";let w="";return t?w=t.message?c("gitView.operation.mergingMessage",{message:t.message}):c("gitView.operation.mergeInProgressWithHead",{head:t.head}):e&&(w=e.headName?c("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):c("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:g,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:c("gitView.operation.inProgressTitle",{operation:x})}),w&&s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:w})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i&&a&&s.jsxs(be,{variant:"outline",size:"sm",onClick:a,disabled:v||o,className:"gap-1.5",children:[s.jsx(I,{name:"sparkling",className:"size-4"}),c("gitView.operation.resolveWithAi")]}),d!=="continue"&&s.jsxs(be,{variant:"ghost",size:"sm",onClick:h,disabled:v||o,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"}),c("gitView.operation.abort")]}),!i&&s.jsxs(be,{variant:"default",size:"sm",onClick:b,disabled:v||o,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"}),c("gitView.operation.continue")]})]}),i&&s.jsx("p",{className:"typography-micro text-[var(--status-warning)]",children:c("gitView.operation.resolveConflictsHint")})]})})},$0=t=>{const e=at.c(104),{currentBranch:n,localBranches:r,remoteBranches:a,onMerge:i,onRebase:o,disabled:c,isOperating:d,operationLogs:p,onOperationComplete:m,mode:u,defaultTargetBranch:f}=t,b=c===void 0?!1:c,h=d===void 0?!1:d,v=p===void 0?[]:p,x=u===void 0?"dialog":u,{t:g}=mt(),[w,y]=l.useState(!1),[k,D]=l.useState("merge"),[j,S]=l.useState(null),[A,E]=l.useState(!1),[P,C]=l.useState(""),N=l.useRef(null),T=l.useRef(null),M=b||h,R=n||g("gitView.branch.currentBranchFallback"),O=v.length>0&&v.every(B0),z=v.some(z0);let B;e[0]===Symbol.for("react.memo_cache_sentinel")?(B=()=>{T.current&&(T.current.scrollTop=T.current.scrollHeight)},e[0]=B):B=e[0],l.useEffect(B,[v]);let $;if(e[1]!==P||e[2]!==n||e[3]!==r||e[4]!==a){e:{const F=P.toLowerCase();let ee;e[6]!==a?(ee=new Set(a.map(_0).filter(Boolean)),e[6]=a,e[7]=ee):ee=e[7];const Ce=ee;let Fe;e[8]!==n||e[9]!==Ce?(Fe=Qe=>Qe!==n&&!Ce.has(Qe),e[8]=n,e[9]=Ce,e[10]=Fe):Fe=e[10];const we=r.filter(Fe);if(!F){$=we;break e}$=we.filter(Qe=>Qe.toLowerCase().includes(F))}e[1]=P,e[2]=n,e[3]=r,e[4]=a,e[5]=$}else $=e[5];const _=$;let Q;if(e[11]!==P||e[12]!==a){e:{const F=P.toLowerCase();if(!F){Q=a;break e}Q=a.filter(ee=>ee.toLowerCase().includes(F))}e[11]=P,e[12]=a,e[13]=Q}else Q=e[13];const W=Q;let ne;e[14]!==f||e[15]!==r||e[16]!==a?(ne=()=>f&&(a.includes(f)||r.includes(f))?f:null,e[14]=f,e[15]=r,e[16]=a,e[17]=ne):ne=e[17];const re=ne;let ue;e[18]!==re||e[19]!==y?(ue=()=>{y(!0),S(re()),D("merge"),C("")},e[18]=re,e[19]=y,e[20]=ue):ue=e[20];const Y=ue;let le;e[21]===Symbol.for("react.memo_cache_sentinel")?(le=F=>{S(F),E(!1),C("")},e[21]=le):le=e[21];const J=le;let L;e[22]!==i||e[23]!==o||e[24]!==k||e[25]!==j?(L=()=>{j&&(k==="merge"?i(j):o(j))},e[22]=i,e[23]=o,e[24]=k,e[25]=j,e[26]=L):L=e[26];const V=L;let K;e[27]!==h||e[28]!==y?(K=()=>{h||(S(null),D("merge"),C(""),y(!1))},e[27]=h,e[28]=y,e[29]=K):K=e[29];const X=K,U=()=>{h&&!O||(O&&m?.(),S(null),D("merge"),C(""),y(!1))};let ae,ve;e[30]!==A?(ae=()=>{A||C("")},ve=[A],e[30]=A,e[31]=ae,e[32]=ve):(ae=e[31],ve=e[32]),l.useEffect(ae,ve);let ie,fe;e[33]!==x||e[34]!==re||e[35]!==j?(ie=()=>{x!=="inline"||j||S(re())},fe=[x,re,j],e[33]=x,e[34]=re,e[35]=j,e[36]=ie,e[37]=fe):(ie=e[36],fe=e[37]),l.useEffect(ie,fe);const se=h?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:T,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:v.map(V0)})}),O?x==="dialog"?s.jsx(Hs,{children:s.jsx(be,{variant:"default",size:"sm",onClick:U,children:g(z?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(be,{variant:"default",size:"sm",onClick:U,children:g(z?"gitView.common.close":"gitView.common.done")})}):null]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:g("gitView.branch.operation")}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>D("merge"),className:me("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",k==="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:me("size-4",k==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:me("typography-ui-label",k==="merge"?"text-foreground":"text-muted-foreground"),children:g("gitView.operation.merge")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:g("gitView.branch.mergeDescription")})]}),s.jsxs("button",{type:"button",onClick:()=>D("rebase"),className:me("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",k==="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:me("size-4",k==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:me("typography-ui-label",k==="rebase"?"text-foreground":"text-muted-foreground"),children:g("gitView.operation.rebase")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:g("gitView.branch.rebaseDescription")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:k==="merge"?g("gitView.branch.branchToMergeInto",{branch:R}):g("gitView.branch.branchToRebaseOnto")}),s.jsxs(_s,{open:A,onOpenChange:E,modal:!1,children:[s.jsx(Bs,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"lg",className:"w-full justify-between",children:[s.jsx("span",{className:me("truncate",!j&&"text-muted-foreground"),children:j||g("gitView.branch.selectBranch")}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),s.jsx(zs,{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(La,{className:"h-full min-h-0",children:[s.jsx(oa,{ref:N,placeholder:g("gitView.branch.searchPlaceholder"),value:P,onValueChange:C,onKeyDown:U0}),s.jsxs(Oa,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx($a,{children:g("gitView.branch.empty")}),_.length>0&&s.jsx(zn,{heading:g("gitView.branch.localBranches"),children:_.map(F=>s.jsx(Dn,{onSelect:()=>J(F),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:F})},`local-${F}`))}),_.length>0&&W.length>0?s.jsx(ka,{}):null,W.length>0&&s.jsx(zn,{heading:g("gitView.branch.remoteBranches"),children:W.map(F=>s.jsx(Dn,{onSelect:()=>J(F),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:F})},`remote-${F}`))})]})]})})]})]}),j?s.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:k==="merge"?s.jsxs(s.Fragment,{children:[g("gitView.branch.summaryMergePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})," ",g("gitView.branch.summaryMergeInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R})]}):s.jsxs(s.Fragment,{children:[g("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R})," ",g("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})]})})}):null,x==="dialog"?s.jsxs(Hs,{className:"gap-2 pt-1",children:[s.jsx(be,{variant:"ghost",size:"sm",onClick:X,children:g("gitView.common.cancel")}),s.jsx(be,{variant:"default",size:"sm",onClick:V,disabled:!j,className:"gap-1.5",children:k==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-merge",className:"size-4"}),g("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-branch",className:"size-4"}),g("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(be,{variant:"destructive",size:"sm",onClick:X,disabled:M,children:g("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(be,{variant:"default",size:"sm",onClick:V,disabled:M||!j,children:g(k==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(x==="inline"){let F;e[38]!==g?(F=g("gitView.branch.updateTitle"),e[38]=g,e[39]=F):F=e[39];let ee;e[40]!==F?(ee=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:F}),e[40]=F,e[41]=ee):ee=e[41];let Ce;e[42]!==g?(Ce=g("gitView.branch.updateDescriptionPrefix"),e[42]=g,e[43]=Ce):Ce=e[43];let Fe;e[44]!==R?(Fe=s.jsx("span",{className:"font-mono text-foreground",children:R}),e[44]=R,e[45]=Fe):Fe=e[45];let we;e[46]!==Ce||e[47]!==Fe?(we=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Ce," ",Fe,"."]}),e[46]=Ce,e[47]=Fe,e[48]=we):we=e[48];let Qe;e[49]!==ee||e[50]!==we?(Qe=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[ee,we]})}),e[49]=ee,e[50]=we,e[51]=Qe):Qe=e[51];let pe;e[52]!==se?(pe=s.jsx("div",{className:"pt-3",children:se}),e[52]=se,e[53]=pe):pe=e[53];let Oe;return e[54]!==Qe||e[55]!==pe?(Oe=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[Qe,pe]}),e[54]=Qe,e[55]=pe,e[56]=Oe):Oe=e[56],Oe}let oe;e[57]!==h?(oe=h?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-merge",className:"size-4"}),e[57]=h,e[58]=oe):oe=e[58];let te;e[59]!==g?(te=g("gitView.branch.mergeRebase"),e[59]=g,e[60]=te):te=e[60];let ke;e[61]!==te?(ke=s.jsx("span",{children:te}),e[61]=te,e[62]=ke):ke=e[62];let Ne;e[63]!==Y||e[64]!==M||e[65]!==oe||e[66]!==ke?(Ne=s.jsx(Pt,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"sm",className:"gap-1.5",onClick:Y,disabled:M,children:[oe,ke]})}),e[63]=Y,e[64]=M,e[65]=oe,e[66]=ke,e[67]=Ne):Ne=e[67];let je;e[68]!==g?(je=g("gitView.branch.mergeRebaseTooltip"),e[68]=g,e[69]=je):je=e[69];let Se;e[70]!==je?(Se=s.jsx(At,{sideOffset:8,children:je}),e[70]=je,e[71]=Se):Se=e[71];let De;e[72]!==Ne||e[73]!==Se?(De=s.jsxs(It,{children:[Ne,Se]}),e[72]=Ne,e[73]=Se,e[74]=De):De=e[74];let ye;e[75]!==U||e[76]!==y?(ye=F=>{F?y(!0):U()},e[75]=U,e[76]=y,e[77]=ye):ye=e[77];let ge;e[78]!==g?(ge=g("gitView.branch.updateTitle"),e[78]=g,e[79]=ge):ge=e[79];let Me;e[80]!==ge?(Me=s.jsx(Ss,{children:ge}),e[80]=ge,e[81]=Me):Me=e[81];let Ue;e[82]!==z||e[83]!==h||e[84]!==k||e[85]!==O||e[86]!==g||e[87]!==R?(Ue=h?g(O?z?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":k==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):s.jsxs(s.Fragment,{children:[g("gitView.branch.dialogDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R}),"."]}),e[82]=z,e[83]=h,e[84]=k,e[85]=O,e[86]=g,e[87]=R,e[88]=Ue):Ue=e[88];let q;e[89]!==Ue?(q=s.jsx(Fs,{children:Ue}),e[89]=Ue,e[90]=q):q=e[90];let Ie;e[91]!==Me||e[92]!==q?(Ie=s.jsxs(As,{children:[Me,q]}),e[91]=Me,e[92]=q,e[93]=Ie):Ie=e[93];let Le;e[94]!==se||e[95]!==Ie?(Le=s.jsxs(ys,{className:"max-w-md",children:[Ie,se]}),e[94]=se,e[95]=Ie,e[96]=Le):Le=e[96];let Pe;e[97]!==w||e[98]!==ye||e[99]!==Le?(Pe=s.jsx(vs,{open:w,onOpenChange:ye,children:Le}),e[97]=w,e[98]=ye,e[99]=Le,e[100]=Pe):Pe=e[100];let he;return e[101]!==De||e[102]!==Pe?(he=s.jsxs(s.Fragment,{children:[De,Pe]}),e[101]=De,e[102]=Pe,e[103]=he):he=e[103],he};function B0(t){return t.status==="done"||t.status==="error"}function z0(t){return t.status==="error"}function _0(t){return t.slice(t.indexOf("/")+1)}function V0(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:me("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 U0(t){return t.stopPropagation()}const Em="oc.git.actionTab",W0=t=>t==="commit"||t==="branch"||t==="pr",Kh="gitmojiCache",K0=1e3*60*60*24*7,Hh="1",H0=40,G0=20,q0="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",Rm={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:"},Gh=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Y0=()=>{if(typeof window>"u")return null;try{const t=localStorage.getItem(Kh);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==Hh||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(Gh),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},J0=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:Hh};localStorage.setItem(Kh,JSON.stringify(e))}catch{return}},Q0=t=>Date.now()-t.fetchedAt<K0,X0=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,a=n.match(r);if(a){const c=a[1],d=Rm[c];if(d)return e.find(p=>p.code===d)||null}const i=n.split(" ")[0],o=Rm[i];return o&&e.find(c=>c.code===o)||null},Fm=new Map,ga=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),qh=()=>{const{t}=mt(),{git:e}=_n(),n=Lr(),[r,a]=l.useState(null),[i,o]=l.useState(!1),c=_t($e=>$e.currentSessionId),d=_t($e=>$e.newSessionDraft),p=_t($e=>$e.setDraftBootstrapPendingDirectory),m=_t($e=>$e.worktreeMetadata),u=_t($e=>$e.availableWorktrees),f=ga(n),b=l.useMemo(()=>{if(!f)return;const $e=u.find(Ze=>ga(Ze.path)===f);if($e)return $e;for(const Ze of m.values())if(ga(Ze.path)===f)return Ze},[u,f,m]),h=l.useMemo(()=>{if(c)return m.get(c)??b;if(d?.open)return b},[c,b,d?.open,m]),{profiles:v,globalIdentity:x,defaultGitIdentityId:g,loadProfiles:w,loadGlobalIdentity:y,loadDefaultGitIdentityId:k}=Zn(br($e=>({profiles:$e.profiles,globalIdentity:$e.globalIdentity,defaultGitIdentityId:$e.defaultGitIdentityId,loadProfiles:$e.loadProfiles,loadGlobalIdentity:$e.loadGlobalIdentity,loadDefaultGitIdentityId:$e.loadDefaultGitIdentityId}))),D=Rd(n??null),j=Dl(n??null),S=Kf($e=>c?$e.getAttachment(c):void 0),A=S?wb(S):[],E=S&&!S.degraded&&!S.legacy?S.worktreeRoot??void 0:void 0,P=Lw(n,h,j?.current??void 0),C=Fd(n??null),N=jb(n??null),T=Nb(n??null),M=Ld(n??null),R=Sb(n??null),O=nn($e=>$e.setActiveDirectory),z=nn($e=>$e.fetchAll),B=nn($e=>$e.ensureAll),$=nn($e=>$e.fetchStatus),_=nn($e=>$e.fetchBranches),Q=nn($e=>$e.fetchLog),W=nn($e=>$e.fetchIdentity),ne=nn($e=>$e.prefetchDiffs),re=nn($e=>$e.setLogMaxCount),ue=Te($e=>$e.isMobile),Y=Te($e=>$e.openContextDiff),le=Te($e=>$e.navigateToDiff),J=Te($e=>$e.setRightSidebarOpen),L=l.useRef(null);l.useEffect(()=>{if(!n){a(null),o(!1);return}let $e=!1,Ze=null;const tt=async()=>{try{const ct=await Cb(n);if($e)return;a(ct.status),ct.status==="pending"&&(Ze=window.setTimeout(()=>{tt()},500))}catch{$e||a(null)}};return tt(),()=>{$e=!0,Ze!==null&&window.clearTimeout(Ze)}},[n]),l.useEffect(()=>{const $e=L.current;L.current=r,!(!n||!e)&&($e==="pending"&&r==="ready"&&(o(!0),z(n,e).finally(()=>{window.setTimeout(()=>{o(!1)},1200)})),r==="failed"&&(p(null),o(!1)))},[n,z,e,p,r]);const V=ga(d?.bootstrapPendingDirectory??null),K=!!(n&&V&&V===ga(n)),U=!!(n&&(r==="pending"||K))||i,ae=l.useMemo(()=>n?Fm.get(n)??null:null,[n]),ve=gt($e=>$e.settingsGitmojiEnabled),[ie,fe]=l.useState(null);l.useEffect(()=>{const $e=E||P?.projectDirectory;if(!$e){fe(null);return}let Ze=!1;return io($e).then(tt=>{if(Ze)return;const ct=tt.trim();fe(ct&&ct!=="HEAD"?ct:null)}).catch(()=>{Ze||fe(null)}),()=>{Ze=!0}},[E,P?.projectDirectory]);const[H,ce]=l.useState(ae?.commitMessage??""),[se,oe]=l.useState([]),[te,ke]=l.useState(!1),Ne=l.useRef(null),[je,Se]=l.useState(null),[De,ye]=l.useState(!1),[ge,Me]=l.useState(null),[Ue,q]=l.useState(25),[Ie,Le]=l.useState(!1),{triggerFireworks:Pe}=Tw(),he=l.useRef(new Map),F=l.useRef(0),ee=l.useCallback(()=>{F.current+=1,Le(!0)},[]),Ce=l.useCallback(()=>{F.current=Math.max(0,F.current-1),F.current===0&&Le(!1)},[]),[Fe,we]=l.useState(()=>new Set(ae?.selectedPaths??[])),[Qe,pe]=l.useState(!1),[Oe,nt]=l.useState(new Set),[Re,de]=l.useState(!1),[He,st]=l.useState(0),[qe,et]=l.useState(!1),[rt,xe]=l.useState(ae?.generatedHighlights??[]),Ye=l.useCallback(()=>{const $e=Ne.current;$e&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{$e.scrollTo({top:$e.scrollHeight,behavior:"smooth"})})})},[]),_e=E||P?.projectDirectory||null,We=j?.current||null,lt=l.useMemo(()=>{const $e=j?.tracking;return $e?$e.startsWith("origin/"):!0},[j?.tracking]),Je=l.useMemo(()=>{const $e=P?.createdFromBranch,Ze=typeof $e=="string"?$e.trim():"",tt=typeof j?.current=="string"?j.current.trim():"",ct=typeof ie=="string"?ie.trim():"";return Ze?Ze===tt&&Ze.startsWith("opencode/")&&ct.length>0&&ct!==Ze?ct:Ze:ct||tt||"HEAD"},[P?.createdFromBranch,j,ie]),Ve=l.useCallback(()=>{xe([])},[]),[yt,$t]=l.useState(new Set),[Gt,ss]=l.useState(new Map),[wt,Dt]=l.useState(new Set),[Xt,Yt]=l.useState(null),[ts,dt]=l.useState(null),[Rt,is]=l.useState([]),[xs,ps]=l.useState(""),[ws,qt]=l.useState(!1),Ge=l.useMemo(()=>[{id:"commit",label:t("gitView.tabs.commit"),icon:s.jsx(I,{name:"git-commit",className:"h-3.5 w-3.5"})},{id:"branch",label:t("gitView.tabs.update"),icon:s.jsx(I,{name:"git-merge",className:"h-3.5 w-3.5"})},{id:"pr",label:t("gitView.tabs.pr"),icon:s.jsx(I,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],[t]),[St,Mt]=l.useState(()=>{if(typeof window>"u")return"commit";const $e=window.localStorage.getItem(Em);return $e==="worktree"?"branch":W0($e)?$e:"commit"}),[Nt,Kt]=l.useState([]),[ns,js]=l.useState(null),[ls,ks]=l.useState(null),[Os,xt]=l.useState([]),[cs,jt]=l.useState(!1),[Tt,Z]=l.useState([]),[ft,kt]=l.useState("merge"),Ht=l.useMemo(()=>c?`openchamber.conflict:${c}`:null,[c]),Ns=l.useCallback(($e,Ze,tt)=>{if(!Ht||typeof window>"u")return;const ct={directory:$e,conflictFiles:Ze,operation:tt};window.localStorage.setItem(Ht,JSON.stringify(ct))},[Ht]),Cs=l.useCallback(()=>{!Ht||typeof window>"u"||window.localStorage.removeItem(Ht)},[Ht]);l.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(Em,St)},[St]),l.useEffect(()=>{if(!Ht||typeof window>"u"||!n)return;const $e=window.localStorage.getItem(Ht);if($e)try{const Ze=JSON.parse($e);if(Ze.directory!==n){window.localStorage.removeItem(Ht);return}Z(Ze.conflictFiles??[]),kt(Ze.operation??"merge"),jt(!0)}catch{window.localStorage.removeItem(Ht)}},[Ht,n]);const[Ke,bt]=l.useState(!1),[Ct,Ft]=l.useState("merge"),[Zt,it]=l.useState(""),zt=l.useCallback($e=>{Rn($e).then(Ze=>{if(Ze.ok){G.success(t("gitView.toast.commitHashCopied"));return}G.error(t("gitView.toast.copyFailed"))})},[t]),hs=l.useCallback($e=>{$t(Ze=>{const tt=new Set(Ze);return tt.has($e)?tt.delete($e):tt.add($e),tt})},[]);l.useEffect(()=>{if(!n||!e)return;const $e=Array.from(yt).filter(Ze=>!Gt.has(Ze)&&!wt.has(Ze));if($e.length!==0){Dt(Ze=>{const tt=new Set(Ze);for(const ct of $e)tt.add(ct);return tt});for(const Ze of $e)e.getCommitFiles(n,Ze).then(tt=>{ss(ct=>new Map(ct).set(Ze,tt.files))}).catch(tt=>{console.error("Failed to fetch commit files:",tt),ss(ct=>new Map(ct).set(Ze,[]))}).finally(()=>{Dt(tt=>{const ct=new Set(tt);return ct.delete(Ze),ct})})}},[yt,n,e,Gt,wt]),l.useEffect(()=>{n&&Fm.set(n,{directory:n,selectedPaths:Array.from(Fe),commitMessage:H,generatedHighlights:rt})},[H,n,Fe,rt]),l.useEffect(()=>{w(),y(),k()},[w,y,k]),l.useEffect(()=>{if(!n||!e?.getRemoteUrl){dt(null);return}e.getRemoteUrl(n).then(dt).catch(()=>dt(null))},[n,e]);const Jt=l.useCallback(async()=>{if(!n||!e?.getRemotes){Kt([]);return}try{const $e=await e.getRemotes(n);Kt($e)}catch{Kt([])}},[n,e]);l.useEffect(()=>{Jt()},[Jt]),l.useEffect(()=>{if(!ve){is([]);return}let $e=!1;const Ze=Y0();return Ze&&(is(Ze.gitmojis),Q0(Ze))?()=>{$e=!0}:((async()=>{try{const ct=await fetch(q0);if(!ct.ok)throw new Error(`Failed to load gitmojis: ${ct.statusText}`);const Bt=await ct.json(),as=Array.isArray(Bt.gitmojis)?Bt.gitmojis.filter(Gh):[];$e||(is(as),J0(as))}catch(ct){$e||console.warn("Failed to load gitmoji list:",ct)}})(),()=>{$e=!0})},[ve]),l.useEffect(()=>{n&&(O(n),B(n,e))},[n,O,B,e]),l.useEffect(()=>{if(n)return Nr.onGitRefreshHint($e=>{ga($e.directory)===ga(n)&&$(n,e)})},[n,$,e]);const Ut=l.useCallback(async($e=!0)=>{if(n)try{await Promise.all([$(n,e),_(n,e)])}catch(Ze){if($e){const tt=Ze instanceof Error?Ze.message:t("gitView.toast.refreshRepositoryFailed");G.error(tt)}}},[n,e,$,_,t]),os=l.useCallback(async()=>{n&&await Q(n,e,Ue)},[n,e,Q,Ue]),tn=l.useCallback(async()=>{n&&await W(n,e)},[n,e,W]);l.useEffect(()=>{if(!n||!e?.hasLocalIdentity||D!==!0)return;const $e=typeof g=="string"?g.trim():"";if(!$e||$e==="global"||he.current.get(n)===$e)return;let tt=!1;return(async()=>{try{const Bt=await e.hasLocalIdentity?.(n);if(tt||Bt===!0)return;ee(),await e.setGitIdentity(n,$e),he.current.set(n,$e),await tn()}catch(Bt){console.warn("Failed to auto-apply default git identity:",Bt)}finally{tt||Ce()}})(),()=>{tt=!0}},[ee,n,g,Ce,e,D,tn]);const Zs=l.useMemo(()=>{if(!j)return[];const $e=j.files??[],Ze=new Map;for(const tt of $e)Ze.set(tt.path,tt);return Array.from(Ze.values()).sort((tt,ct)=>tt.path.localeCompare(ct.path))},[j]);l.useEffect(()=>{if(!n||Zs.length===0)return;const $e=[],Ze=new Set,tt=Bt=>{!Bt||Ze.has(Bt)||(Ze.add(Bt),$e.push(Bt))};if(Array.from(Fe).forEach(tt),se.forEach(tt),Zs.slice(0,G0).forEach(Bt=>tt(Bt.path)),$e.length===0)return;const ct=window.setTimeout(()=>{ne(n,e,$e,{maxFiles:H0})},120);return()=>{window.clearTimeout(ct)}},[Zs,n,e,ne,Fe,se]),l.useEffect(()=>{if(!j||Zs.length===0){we(new Set),pe(!1);return}we($e=>{const Ze=new Set,tt=$e??new Set;for(const ct of Zs)tt.has(ct.path)?Ze.add(ct.path):Qe||Ze.add(ct.path);return Ze})},[j,Zs,Qe]);const nr=async($e,Ze)=>{if(n){Se($e);try{const tt=ct=>{const Bt=`${ct.name}/`,as=j?.tracking?.startsWith(Bt)?j.tracking.slice(Bt.length):void 0;return{remote:ct.name,branch:as,rebase:!0}};if($e==="fetch"){if(!Ze)throw new Error("No remote available for fetch");await e.gitFetch(n,{remote:Ze.name}),G.success(t("gitView.toast.fetchedFromRemote",{name:Ze.name}))}else if($e==="pull"){if(!Ze)throw new Error("No remote available for pull");const ct=await e.gitPull(n,tt(Ze));G.success(ct.files.length===1?t("gitView.toast.pulledFilesSingle",{count:ct.files.length,name:Ze.name}):t("gitView.toast.pulledFilesPlural",{count:ct.files.length,name:Ze.name}))}else if($e==="push")await e.gitPush(n),G.success(t("gitView.toast.pushedToUpstream"));else if($e==="sync"){if(!Ze)throw new Error("No remote available for sync");let ct=0,Bt=!1;await e.gitFetch(n,{remote:Ze.name});const as=await e.getGitStatus(n);if((as.behind??0)>0){if((as.files?.length??0)>0){G.error(t("gitView.toast.commitOrStashBeforeSync"));return}ct=(await e.gitPull(n,tt(Ze))).files.length}((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),Bt=!0),ct>0&&Bt?G.success(ct===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:ct,name:Ze.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:ct,name:Ze.name})):ct>0?G.success(ct===1?t("gitView.toast.pulledFilesSingle",{count:ct,name:Ze.name}):t("gitView.toast.pulledFilesPlural",{count:ct,name:Ze.name})):Bt?G.success(t("gitView.toast.pushedToUpstream")):G.success(t("gitView.toast.alreadyUpToDate"))}await Ut(!1),await os()}catch(tt){const ct=tt instanceof Error?tt.message:t("gitView.toast.syncActionFailed",{action:$e==="sync"?t("gitView.sync.syncChanges"):$e==="pull"?t("gitView.sync.pull"):$e});G.error(ct)}finally{Se(null)}}},Vn=l.useCallback(async $e=>{if(!n)return;const Ze=$e.name.trim();if(!Ze){G.error(t("gitView.toast.remoteNameRequired"));return}if(Ze==="origin"){G.error(t("gitView.toast.cannotRemoveOriginRemote"));return}js(Ze);try{await e.removeRemote(n,{remote:Ze}),G.success(t("gitView.toast.removedRemote",{name:Ze})),await Promise.all([Ut(!1),Jt()])}catch(tt){const ct=tt instanceof Error?tt.message:`Failed to remove ${Ze}`;G.error(ct)}finally{js(null)}},[n,e,Jt,Ut,t]),Ds=async($e={})=>{if(!n)return;if(!H.trim()){G.error(t("gitView.toast.enterCommitMessage"));return}const Ze=Array.from(Fe).sort();if(Ze.length===0){G.error(t("gitView.toast.selectFileToCommit"));return}const tt=$e.pushAfter?"commitAndPush":"commit";Me(tt);try{if(await e.createGitCommit(n,H.trim(),{files:Ze}),G.success(t("gitView.toast.commitCreated")),ce(""),we(new Set),pe(!1),Ve(),await Ut(),$e.pushAfter){Se("sync");const ct=j?.tracking?.split("/")[0],Bt=Cn.find($r=>$r.name===ct)??Cn[0];if(!Bt)throw new Error("No remote available for sync");const as=`${Bt.name}/`,Vs=j?.tracking?.startsWith(as)?j.tracking.slice(as.length):void 0;let Us=0,Qn=!1;await e.gitFetch(n,{remote:Bt.name}),((await e.getGitStatus(n)).behind??0)>0&&(Us=(await e.gitPull(n,{remote:Bt.name,branch:Vs,rebase:!0})).files.length),((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),Qn=!0),Us>0&&Qn?G.success(Us===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:Us,name:Bt.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:Us,name:Bt.name})):Us>0?G.success(Us===1?t("gitView.toast.pulledFilesSingle",{count:Us,name:Bt.name}):t("gitView.toast.pulledFilesPlural",{count:Us,name:Bt.name})):Qn?G.success(t("gitView.toast.pushedToUpstream")):G.success(t("gitView.toast.alreadyUpToDate")),Pe(),await Ut(!1)}else await Ut(!1);await os(),st(ct=>ct+1)}catch(ct){const Bt=ct instanceof Error?ct.message:t("gitView.toast.createCommitFailed");G.error(Bt)}finally{Me(null),$e.pushAfter&&Se(null)}},on=l.useCallback(async()=>{if(n){if(Fe.size===0){G.error(t("gitView.toast.selectFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:n,selectedFiles:Fe.size}),et(!0);try{const{message:$e}=await kb(n,Array.from(Fe)),Ze=$e.subject?.trim()??"",tt=Array.isArray($e.highlights)?$e.highlights:[];if(Ze){let ct=Ze;if(ve&&Rt.length>0){const Bt=X0(Ze,Rt);if(Bt){const{code:as,emoji:Vs}=Bt;!Ze.startsWith(as)&&!Ze.startsWith(Vs)&&(ct=`${as} ${Ze}`)}}ce(ct)}xe(tt),Ye()}catch($e){console.error("[git-generation][browser] GitView generate handler failed",{message:$e instanceof Error?$e.message:String($e),error:$e});const Ze=$e instanceof Error?$e.message:t("gitView.toast.generateCommitMessageFailed");G.error(Ze)}finally{et(!1)}}},[n,Fe,ve,Rt,Ye,t]),en=$e=>$e.reason==="attention"?`${$e.attentionReason} in progress`:$e.reason==="missing"?"worktree is missing":"worktree is invalid",mn=async($e,Ze)=>{if(!n||!j)return;const tt=Ql(S);if(tt.length>0){G.error(t("gitView.toast.cannotCreateBranch",{reason:en(tt[0])}));return}const ct=j.current??null,Bt=Ze?.name??"origin";try{await e.createBranch(n,$e,ct??"HEAD"),G.success(t("gitView.toast.createdBranch",{name:$e})),await e.checkoutBranch(n,$e);let as=!1;try{await e.gitPush(n,{remote:Bt,branch:$e,options:["--set-upstream"]}),as=!0}catch(Vs){const Us=Vs instanceof Error?Vs.message:`Unable to push new branch to ${Bt}.`;G.warning(t("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",Us]})})}await Ut(),await os(),as&&G.success(t("gitView.toast.upstreamSet",{branch:$e,remote:Bt}))}catch(as){const Vs=as instanceof Error?as.message:t("gitView.toast.createBranchFailed");throw G.error(Vs),as}},Sn=async($e,Ze)=>{if(!n)return;const tt=Ql(S);if(tt.length>0){G.error(t("gitView.toast.cannotRenameBranch",{reason:en(tt[0])}));return}try{await e.renameBranch(n,$e,Ze),G.success(t("gitView.toast.renamedBranch",{oldName:$e,newName:Ze})),await Ut(),await os()}catch(ct){const Bt=ct instanceof Error?ct.message:t("gitView.toast.renameBranchFailed",{oldName:$e,newName:Ze});G.error(Bt)}},Fn=async $e=>{if(!n)return;const Ze=Ql(S);if(Ze.length>0){G.error(t("gitView.toast.cannotCheckout",{reason:en(Ze[0])}));return}const tt=$e.replace(/^remotes\//,"");if(j?.current!==tt)try{await e.checkoutBranch(n,tt),G.success(t("gitView.toast.checkedOut",{name:tt})),await Ut(),await os()}catch(ct){const Bt=ct instanceof Error?ct.message:t("gitView.toast.checkoutFailed",{name:tt});G.error(Bt)}},Mn=async $e=>{if(n){ee();try{await e.setGitIdentity(n,$e.id),G.success(t("gitView.toast.appliedIdentity",{name:$e.name})),await tn()}catch(Ze){const tt=Ze instanceof Error?Ze.message:t("gitView.toast.applyIdentityFailed");G.error(tt)}finally{Ce()}}},cn=l.useMemo(()=>C?.all?C.all.filter($e=>!$e.startsWith("remotes/")).sort():[],[C]),kn=l.useMemo(()=>C?.all?C.all.filter($e=>$e.startsWith("remotes/")).map($e=>$e.replace(/^remotes\//,"")).sort():[],[C]),Cn=l.useMemo(()=>{if(Nt.length>0)return Nt;const $e=new Set,Ze=j?.tracking?.trim();Ze&&Ze.includes("/")&&$e.add(Ze.split("/")[0]);for(const tt of kn){const ct=tt.indexOf("/");ct>0&&$e.add(tt.slice(0,ct))}return $e.size===0&&ts&&$e.add("origin"),Array.from($e).map(tt=>({name:tt,fetchUrl:ts??"",pushUrl:ts??""}))},[Nt,kn,ts,j?.tracking]),Be=l.useMemo(()=>{const $e=new Set(Cn.map(Bt=>Bt.name)),Ze=Bt=>{if(!Bt)return"";let as=Bt.trim();if(!as||as==="HEAD")return"";if(cn.includes(as))return as;as.startsWith("refs/heads/")&&(as=as.slice(11)),as.startsWith("heads/")&&(as=as.slice(6)),as.startsWith("remotes/")&&(as=as.slice(8));const Vs=as.indexOf("/");if(Vs>0){const Us=as.slice(0,Vs);if($e.has(Us)){const Qn=as.slice(Vs+1).trim();Qn&&(as=Qn)}}return as},tt=Ze(typeof P?.createdFromBranch=="string"?P.createdFromBranch:"");if(tt)return tt;const ct=Ze(typeof ie=="string"?ie:"");return ct||(cn.includes("main")?"main":cn.includes("master")?"master":cn.includes("develop")?"develop":"main")},[Cn,cn,ie,P?.createdFromBranch]),Et=l.useMemo(()=>Cn.map(tt=>tt.name).map(tt=>`${tt}/${Be}`).find(tt=>kn.includes(tt))??Be,[Be,Cn,kn]),rs=l.useMemo(()=>{const $e=new Map;x&&$e.set(x.id,x);let Ze=null;if(ts)try{let tt=ts.trim();tt.startsWith("git@")&&(tt=`https://${tt.slice(4).replace(":","/")}`),tt.endsWith(".git")&&(tt=tt.slice(0,-4));const ct=new URL(tt);Ze=ct.hostname+ct.pathname}catch{}for(const tt of v){if(tt.authType!=="token"){$e.set(tt.id,tt);continue}const ct=tt.host;if(!ct){$e.set(tt.id,tt);continue}if(!ct.includes("/")){$e.set(tt.id,tt);continue}Ze&&Ze===ct&&$e.set(tt.id,tt)}return Array.from($e.values())},[v,x,ts]),gs=l.useMemo(()=>{if(T?.userName&&T?.userEmail){const $e=v.find(Ze=>Ze.userName===T.userName&&Ze.userEmail===T.userEmail);return $e||(x&&x.userName===T.userName&&x.userEmail===T.userEmail?x:{id:"local-config",name:T.userName,userName:T.userName,userEmail:T.userEmail,sshKey:T.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return x??null},[T,v,x]),Ys=Fe.size,Gs=M||je!==null||ge!==null,Is=j?.current??null,qs=!!(P&&_e&&We&<),dn=!!(n&&Is),ir=!!Is,Ln=qs&&_e&&We&&P?{repoRoot:_e,sourceBranch:We,worktreeMetadata:P}:null,Gn=l.useMemo(()=>!dn||!n||!Is?null:{directory:n,branch:Is},[dn,Is,n]);l.useEffect(()=>{if(!n||!e||!N?.all?.length||!Is||!Be||Is===Be){Yt(null);return}let $e=!1;return(async()=>{try{const tt=await e.getGitLog(n,{from:Be,to:"HEAD",maxCount:Ue});if($e)return;const ct=new Set((tt?.all??[]).map(as=>as.hash).filter(as=>typeof as=="string"&&as.length>0));if(ct.size===0){Yt(null);return}const Bt=N.all.findIndex(as=>!ct.has(as.hash));if(Bt===0){Yt(null);return}if(Bt===-1){Yt({insertBeforeIndex:N.all.length,branchName:Is,direction:"up"});return}Yt({insertBeforeIndex:Bt,branchName:Is,direction:"up"})}catch{$e||Yt(null)}})(),()=>{$e=!0}},[Be,Is,n,e,N,Ue]);const Or=$e=>{we(Ze=>{const tt=new Set(Ze);return tt.has($e)?tt.delete($e):tt.add($e),tt}),pe(!0)},Ir=()=>{const $e=new Set(Zs.map(Ze=>Ze.path));we($e),pe(!0)},En=()=>{we(new Set),pe(!0)},qn=l.useCallback(async $e=>{if(n){nt(Ze=>{const tt=new Set(Ze);return tt.add($e),tt});try{await e.revertGitFile(n,$e),G.success(t("gitView.toast.revertedFile",{path:$e})),await Ut(!1)}catch(Ze){const tt=Ze instanceof Error?Ze.message:t("gitView.toast.revertFailed");G.error(tt)}finally{nt(Ze=>{const tt=new Set(Ze);return tt.delete($e),tt})}}},[n,Ut,e,t]),pn=l.useCallback(async $e=>{if(!n||$e.length===0||Re)return;const Ze=Array.from(new Set($e));de(!0),nt(ct=>{const Bt=new Set(ct);return Ze.forEach(as=>Bt.add(as)),Bt});const tt=[];try{if(await Promise.all(Ze.map(async ct=>{try{await e.revertGitFile(n,ct)}catch(Bt){tt.push({path:ct,message:Bt instanceof Error?Bt.message:t("gitView.toast.revertFailed")})}})),await Ut(!1),tt.length===0)G.success(Ze.length===1?t("gitView.toast.revertedFilesSingle",{count:Ze.length}):t("gitView.toast.revertedFilesPlural",{count:Ze.length}));else if(tt.length===Ze.length)G.error(tt[0]?.message||t("gitView.toast.revertFailed"));else{const ct=Ze.length-tt.length;G.warning(ct===1?t("gitView.toast.revertedSomeSingle",{success:ct,failed:tt.length}):t("gitView.toast.revertedSomePlural",{success:ct,failed:tt.length}))}}finally{nt(ct=>{const Bt=new Set(ct);return Ze.forEach(as=>Bt.delete(as)),Bt}),de(!1)}},[n,e,Re,Ut,t]),Yn=l.useCallback($e=>{if($e.length===0)return;const Ze=$e.map(tt=>tt.trim()).filter(Boolean);if(Ze.length===0){Ve();return}ce(tt=>{const ct=tt.trim(),Bt=ct.length>0?`
|
|
43
|
+
|
|
44
|
+
`:"";return`${ct}${Bt}${Ze.join(`
|
|
45
|
+
`)}`.trim()}),Ve()},[Ve]),In=l.useCallback(($e,Ze)=>{const tt=Ze||$e;ce(ct=>{const Bt=ct.trimStart();return Bt.startsWith($e)||Ze&&Bt.startsWith(Ze)?ct:`${tt.endsWith(" ")?tt:`${tt} `}${ct}`.trimStart()}),ps(""),ke(!1)},[]),Rr=l.useCallback($e=>{q($e),n&&(re(n,$e),Q(n,e,$e))},[n,re,Q,e]),or=l.useCallback($e=>{const Ze=$e instanceof Error?$e.message.toLowerCase():"";return Ze.includes("uncommitted changes")||Ze.includes("local changes")||Ze.includes("your local changes would be overwritten")||Ze.includes("please commit your changes or stash them")||Ze.includes("cannot rebase: you have unstaged changes")||Ze.includes("error: cannot pull with rebase")},[]),yr=l.useCallback(($e,Ze)=>{xt(tt=>[...tt,{message:$e,status:Ze,timestamp:Date.now()}])},[]),Pn=l.useCallback(($e,Ze)=>{xt(tt=>{if(tt.length===0)return tt;const ct=[...tt];return ct[ct.length-1]={...ct[ct.length-1],status:$e,...Ze?{message:Ze}:{}},ct})},[]),Jn=l.useCallback(()=>{xt([])},[]),rr=l.useCallback(()=>{xt([]),ks(null)},[]),fn=l.useCallback($e=>{const Ze=$e.trim(),tt=new Set(Cn.map(Bt=>Bt.name)),ct=Ze.indexOf("/");if(ct>0){const Bt=Ze.slice(0,ct),as=Ze.slice(ct+1);if(tt.has(Bt)&&as)return{branch:Ze,remote:Bt,remoteBranch:as}}for(const Bt of Cn){const as=`${Bt.name}/${Ze}`;if(kn.includes(as))return{branch:as,remote:Bt.name,remoteBranch:Ze}}return{branch:Ze,remote:null,remoteBranch:null}},[Cn,kn]),lr=l.useCallback(async $e=>{if(!n)return;ks("merge"),Jn();const Ze=j?.current,tt=fn($e);try{tt.remote&&tt.remoteBranch&&(yr(`Fetching ${tt.remote}/${tt.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:tt.remote,branch:tt.remoteBranch}),Pn("done",`Fetched ${tt.remote}/${tt.remoteBranch}`)),yr(`Merging ${tt.branch} into ${Ze}...`,"running");const ct=await e.merge(n,{branch:tt.branch});ct.conflict?(Pn("error","Merge conflicts detected"),Z(ct.conflictFiles??[]),kt("merge"),jt(!0),Ns(n,ct.conflictFiles??[],"merge")):(Pn("done",`Merged ${tt.branch} into ${Ze}`),Cs(),yr("Refreshing repository status...","running"),await Ut(),await os(),Pn("done","Repository status updated"))}catch(ct){if(or(ct))Pn("error","Uncommitted changes detected"),Ft("merge"),it(tt.branch),bt(!0);else{const Bt=ct instanceof Error?ct.message:`Failed to merge ${tt.branch}`;Pn("error",Bt)}}},[n,e,j,fn,Ut,os,or,Ns,Cs,yr,Pn,Jn]),Ni=l.useCallback(async $e=>{if(!n)return;ks("rebase"),Jn();const Ze=j?.current,tt=fn($e);try{tt.remote&&tt.remoteBranch&&(yr(`Fetching ${tt.remote}/${tt.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:tt.remote,branch:tt.remoteBranch}),Pn("done",`Fetched ${tt.remote}/${tt.remoteBranch}`)),yr(`Rebasing ${Ze} onto ${tt.branch}...`,"running");const ct=await e.rebase(n,{onto:tt.branch});ct.conflict?(Pn("error","Rebase conflicts detected"),Z(ct.conflictFiles??[]),kt("rebase"),jt(!0),Ns(n,ct.conflictFiles??[],"rebase")):(Pn("done",`Rebased ${Ze} onto ${tt.branch}`),Cs(),yr("Refreshing repository status...","running"),await Ut(),await os(),Pn("done","Repository status updated"))}catch(ct){if(or(ct))Pn("error","Uncommitted changes detected"),Ft("rebase"),it(tt.branch),bt(!0);else{const Bt=ct instanceof Error?ct.message:`Failed to rebase onto ${tt.branch}`;Pn("error",Bt)}}},[n,e,j,fn,Ut,os,or,Ns,Cs,yr,Pn,Jn]),_a=l.useCallback(async()=>{if(n)try{ft==="merge"?(await e.abortMerge(n),G.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),G.success(t("gitView.toast.rebaseAborted"))),Cs(),await Ut(),await os()}catch($e){const Ze=$e instanceof Error?$e.message:`Failed to abort ${ft}`;G.error(Ze)}},[n,e,ft,Ut,os,Cs,t]),qr=l.useMemo(()=>j?.files?j.files.some($e=>$e.index==="U"||$e.working_dir==="U"||$e.index==="A"&&$e.working_dir==="A"||$e.index==="D"&&$e.working_dir==="D"):!1,[j?.files]),la=l.useCallback(async()=>{if(n)try{const $e=!!j?.mergeInProgress?.head,Ze=!!(j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto);if($e){const tt=await e.continueMerge(n);tt.conflict?(Z(tt.conflictFiles??[]),kt("merge"),jt(!0),Ns(n,tt.conflictFiles??[],"merge"),G.error(t("gitView.toast.mergeConflictsDetected"))):(Cs(),G.success(t("gitView.toast.mergeCompleted")),await Ut(),await os())}else if(Ze){const tt=await e.continueRebase(n);tt.conflict?(Z(tt.conflictFiles??[]),kt("rebase"),jt(!0),Ns(n,tt.conflictFiles??[],"rebase"),G.error(t("gitView.toast.rebaseConflictsDetected"))):(Cs(),G.success(t("gitView.toast.rebaseStepCompleted")),await Ut(),await os())}}catch($e){const Ze=$e instanceof Error?$e.message:t("gitView.toast.continueOperationFailed");G.error(Ze)}},[n,e,j,Ut,os,Ns,Cs,t]),vn=l.useCallback(async()=>{if(n)try{!!j?.mergeInProgress?.head?(await e.abortMerge(n),G.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),G.success(t("gitView.toast.rebaseAborted"))),Cs(),await Ut(),await os()}catch($e){const Ze=$e instanceof Error?$e.message:t("gitView.toast.abortOperationFailed");G.error(Ze)}},[n,e,j,Ut,os,Cs,t]),ca=l.useCallback(()=>{if(!n)return;const Ze=!!j?.mergeInProgress?.head?"merge":"rebase",tt=j?.files?.filter(ct=>ct.index==="U"||ct.working_dir==="U").map(ct=>ct.path)??[];tt.length>0&&Z(tt),kt(Ze),jt(!0)},[n,j]),Va=l.useCallback(async $e=>{if(!n)return;const Ze=j?.current,tt=Ct,ct=Zt;try{await e.stash(n,{message:`Auto-stash before ${tt} with ${ct}`,includeUntracked:!0})}catch(Vs){const Us=Vs instanceof Error?Vs.message:"Failed to stash changes";G.error(Us);return}let Bt=!1,as=!1;try{if(tt==="merge"){const Vs=await e.merge(n,{branch:ct});Vs.conflict?(as=!0,Z(Vs.conflictFiles??[]),kt("merge"),jt(!0)):(Bt=!0,G.success(t("gitView.toast.mergedIntoBranch",{branch:ct,currentBranch:Ze||""})))}else{const Vs=await e.rebase(n,{onto:ct});Vs.conflict?(as=!0,Z(Vs.conflictFiles??[]),kt("rebase"),jt(!0)):(Bt=!0,G.success(t("gitView.toast.rebasedOntoBranch",{currentBranch:Ze||"",branch:ct})))}if($e&&Bt)try{await e.stashPop(n),G.success(t("gitView.toast.stashedRestored"))}catch(Vs){const Us=Vs instanceof Error?Vs.message:t("gitView.toast.restoreStashFailed");G.error(Us)}else $e&&as&&G.info(t("gitView.toast.restoreStashManually"));await Ut(),await os()}catch(Vs){if($e)try{await e.stashPop(n)}catch{}throw Vs}},[n,e,j,Ct,Zt,Ut,os,t]);return n?M&&D===null?s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:t("gitView.loading.checkingRepository")})]})}):D===!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:t("gitView.empty.worktreeSetupInProgress")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.worktreeSetupDescription")})]}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(I,{name:"git-branch",className:"mb-3 size-6 text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t("gitView.empty.notGitRepository")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.notGitRepositoryDescription")}),A.includes("open-without-worktree-features")?s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:t("gitView.empty.worktreeFeaturesUnavailable")}):null]}):s.jsxs("div",{className:me("flex h-full flex-col overflow-hidden","bg-sidebar"),children:[s.jsx(tj,{status:j,localBranches:cn,remoteBranches:kn,branchInfo:C?.branches,syncAction:je,remotes:Cn,onFetch:$e=>nr("fetch",$e),onSync:$e=>nr("sync",$e),onRemoveRemote:Vn,removingRemoteName:ns,onCheckoutBranch:Fn,onCreateBranch:mn,onRenameBranch:Sn,activeIdentityProfile:gs,availableIdentities:rs,onSelectIdentity:Mn,isApplyingIdentity:Ie,isWorktreeMode:!!P,onOpenHistory:()=>qt(!0),actionTabItems:Ge,activeActionTab:St,onSelectActionTab:$e=>Mt($e)}),n&&(j?.mergeInProgress?.head||j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto)&&s.jsx(O0,{mergeInProgress:j?.mergeInProgress,rebaseInProgress:j?.rebaseInProgress,onContinue:la,onAbort:vn,onResolveWithAI:ca,hasUnresolvedConflicts:qr,isLoading:M}),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:me("min-w-0 min-h-0 h-full flex flex-col","bg-sidebar"),children:s.jsxs(Es,{as:ao,ref:Ne,outerClassName:"flex-1 min-h-0",className:me("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:[St==="commit"?s.jsx("div",{className:"space-y-4",children:(Zs?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx(uj,{maxListHeightClassName:"max-h-[40vh]",changeEntries:Zs,onVisiblePathsChange:oe,selectedPaths:Fe,diffStats:j?.diffStats,revertingPaths:Oe,onToggleFile:Or,onSelectAll:Ir,onClearSelection:En,onRevertAll:pn,onViewDiff:$e=>{if(n&&!ue){Y(n,$e);return}le($e),ue&&J(!1)},onRevertFile:qn,isRevertingAll:Re,onOpenStashes:()=>ye(!0)}),s.jsx(gj,{selectedCount:Ys,commitMessage:H,onCommitMessageChange:ce,generatedHighlights:rt,onInsertHighlights:Yn,onGenerateMessage:on,isGeneratingMessage:qe,onCommit:()=>Ds({pushAfter:!1}),onCommitAndPush:()=>Ds({pushAfter:!0}),commitAction:ge,gitmojiEnabled:ve,onOpenGitmojiPicker:()=>ke(!0)})]}):s.jsx(xj,{onOpenStashes:()=>ye(!0)})}):null,St==="branch"?s.jsx("div",{className:"space-y-4",children:ir?s.jsxs(s.Fragment,{children:[s.jsx($0,{mode:"inline",currentBranch:j?.current,localBranches:cn,remoteBranches:kn,defaultTargetBranch:Et,onMerge:lr,onRebase:Ni,disabled:Gs,isOperating:ls!==null,operationLogs:Os,onOperationComplete:rr}),Ln?s.jsx(Gw,{repoRoot:Ln.repoRoot,sourceBranch:Ln.sourceBranch,worktreeMetadata:Ln.worktreeMetadata,localBranches:cn,defaultTargetBranch:Je,refreshKey:He,onRefresh:()=>{n&&($(n,e),_(n,e),Q(n,e,Ue))}},Ln.worktreeMetadata.path):null]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("gitView.branch.actionsUnavailable")})}):null,St==="pr"?s.jsx("div",{className:"space-y-4",children:Gn?s.jsx(P0,{directory:Gn.directory,branch:Gn.branch,baseBranch:Be,trackingBranch:j?.tracking??void 0,remotes:Nt,remoteBranches:kn,onGeneratedDescription:Ye}):s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:t("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("gitView.pullRequest.createHint")})]})}):null]})})})}),s.jsx(vs,{open:ws,onOpenChange:qt,children:s.jsxs(ys,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:t("gitView.history.title")}),s.jsx(Fs,{children:t("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(Xj,{log:N,isLogLoading:R,logMaxCount:Ue,onLogMaxCountChange:Rr,expandedCommitHashes:yt,onToggleCommit:hs,commitFilesMap:Gt,loadingCommitHashes:wt,onCopyHash:zt,directory:n??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:Xt})})]})}),s.jsx(sj,{open:De,onOpenChange:ye,directory:n,hasUncommittedChanges:(j?.files?.length??0)>0,uncommittedFileCount:j?.files?.length??0,onChanged:async()=>{await Ut(!1),await os()}}),s.jsx(vs,{open:te,onOpenChange:ke,children:s.jsxs(ys,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(As,{className:"px-4 pt-4",children:s.jsx(Ss,{children:t("gitView.gitmoji.title")})}),s.jsxs(La,{className:"h-[420px]",children:[s.jsx(oa,{placeholder:t("gitView.gitmoji.searchPlaceholder"),value:xs,onValueChange:ps}),s.jsxs(Oa,{children:[s.jsx($a,{children:t("gitView.gitmoji.empty")}),s.jsx(zn,{children:(Rt.length===0?[]:Rt.filter($e=>{const Ze=xs.trim().toLowerCase();return Ze?$e.emoji.includes(Ze)||$e.code.toLowerCase().includes(Ze)||$e.description.toLowerCase().includes(Ze):!0})).map($e=>s.jsxs(Dn,{onSelect:()=>In($e.emoji,$e.code),children:[s.jsx("span",{className:"text-lg",children:$e.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:$e.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:$e.description})]},$e.code))})]})]})]})}),n&&s.jsx(A0,{open:cs,onOpenChange:jt,conflictFiles:Tt,directory:n,operation:ft,onAbort:_a,onClearState:Cs}),s.jsx(L0,{open:Ke,onOpenChange:bt,operation:Ct,targetBranch:Zt,onConfirm:Va})]}):s.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:t("gitView.empty.selectSessionOrDirectory")})})},Z0=Object.freeze(Object.defineProperty({__proto__:null,GitView:qh},Symbol.toStringTag,{value:"Module"})),cd=5e3,eN=(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},tN=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"},sN=async(t,e)=>{if(t.readFile)return(await t.readFile(e,{allowOutsideWorkspace:!0,optional:!0})).content??"";const n=new URLSearchParams({path:e,allowOutsideWorkspace:"true",optional:"true"}),r=await fetch(`/api/fs/read?${n.toString()}`,{cache:"no-store"});if(!r.ok){const a=await r.json().catch(()=>({error:r.statusText}));throw new Error(a.error||"Failed to read file")}return r.text()},Xd=async(t,e)=>{try{const n=await sN(t,e);return eN(n,cd)>cd?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:tN(n)}}},Zd=t=>t==="too-large"?`File is too large to open (>${cd.toLocaleString()} lines)`:t==="missing"?"File not found":"Failed to open file",nN=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Kn=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},Yh=(t,e)=>{const n=Kn(e),r=Kn(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},rN=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),aN=new Set(["node_modules"]),iN=t=>aN.has(t),oN=t=>{const e=Kn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Jh=(t,e)=>s.jsx(jr,{filePath:t,extension:e}),lN=t=>{const e=at.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 a=r[n];let i;return e[1]!==a?(i=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:a}}),e[1]=a,e[2]=i):i=e[2],i},cN=t=>{const e=at.c(63),{node:n,root:r,isExpanded:a,isActive:i,status:o,badge:c,permissions:d,downloadFile:p,contextMenuPath:m,setContextMenuPath:u,onSelect:f,onToggle:b,onRevealPath:h,onOpenDialog:v}=t,{t:x}=mt(),g=n.type==="directory",{canRename:w,canCreateFile:y,canCreateFolder:k,canDelete:D,canReveal:j}=d;let S;e[0]!==y||e[1]!==k||e[2]!==D||e[3]!==w||e[4]!==j||e[5]!==n.path||e[6]!==u?(S=re=>{!w&&!y&&!k&&!D&&!j||(re?.preventDefault(),u(n.path))},e[0]=y,e[1]=k,e[2]=D,e[3]=w,e[4]=j,e[5]=n.path,e[6]=u,e[7]=S):S=e[7];const A=S;let E;e[8]!==g||e[9]!==n||e[10]!==f||e[11]!==b?(E=()=>{g?b(n.path):f(n)},e[8]=g,e[9]=n,e[10]=f,e[11]=b,e[12]=E):E=e[12];const P=E;let C;e[13]!==n.path||e[14]!==u?(C=re=>{re.stopPropagation(),u(n.path)},e[13]=n.path,e[14]=u,e[15]=C):C=e[15];const N=C;let T;e[16]!==n.path||e[17]!==r?(T=re=>{const ue=Yh(r,n.path);!ue||ue==="."||(re.dataTransfer.setData("application/x-openchamber-file-path",ue),re.dataTransfer.effectAllowed="copy")},e[16]=n.path,e[17]=r,e[18]=T):T=e[18];const M=T,R=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let O;e[19]!==R?(O=me("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",R,"cursor-grab active:cursor-grabbing"),e[19]=R,e[20]=O):O=e[20];let z;e[21]!==g||e[22]!==a||e[23]!==n.extension||e[24]!==n.path?(z=g?a?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"}):Jh(n.path,n.extension),e[21]=g,e[22]=a,e[23]=n.extension,e[24]=n.path,e[25]=z):z=e[25];let B;e[26]!==n.name||e[27]!==n.path?(B=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[26]=n.name,e[27]=n.path,e[28]=B):B=e[28];let $;e[29]!==g||e[30]!==o?($=!g&&o&&s.jsx(lN,{status:o}),e[29]=g,e[30]=o,e[31]=$):$=e[31];let _;e[32]!==c||e[33]!==g?(_=g&&c&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[c.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",c.modified]}),c.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",c.added]})]}),e[32]=c,e[33]=g,e[34]=_):_=e[34];let Q;e[35]!==A||e[36]!==M||e[37]!==P||e[38]!==_||e[39]!==O||e[40]!==z||e[41]!==B||e[42]!==$?(Q=s.jsxs("button",{type:"button",onClick:P,onContextMenu:A,draggable:!0,onDragStart:M,className:O,children:[z,B,$,_]}),e[35]=A,e[36]=M,e[37]=P,e[38]=_,e[39]=O,e[40]=z,e[41]=B,e[42]=$,e[43]=Q):Q=e[43];let W;e[44]!==y||e[45]!==k||e[46]!==D||e[47]!==w||e[48]!==j||e[49]!==m||e[50]!==p||e[51]!==N||e[52]!==g||e[53]!==n||e[54]!==v||e[55]!==h||e[56]!==u||e[57]!==x?(W=(w||y||k||D||j)&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(_s,{open:m===n.path,onOpenChange:re=>u(re?n.path:null),children:[s.jsx(Bs,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:N,children:s.jsx(I,{name:"more-2-fill",className:"h-4 w-4"})})}),s.jsxs(zs,{align:"end",side:"bottom",onCloseAutoFocus:()=>u(null),children:[w&&s.jsxs(Vt,{onClick:re=>{re.stopPropagation(),v("rename",n)},children:[s.jsx(I,{name:"edit",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.rename")]}),s.jsxs(Vt,{onClick:re=>{re.stopPropagation(),Rn(n.path).then(ue=>{if(ue.ok){G.success(x("sidebarFilesTree.toast.pathCopied"));return}G.error(x("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.copyPath")]}),!g&&p&&s.jsxs(Vt,{onClick:re=>{re.stopPropagation(),p(n.path)},children:[s.jsx(I,{name:"download",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.save")]}),j&&s.jsxs(Vt,{onClick:re=>{re.stopPropagation(),h(n.path)},children:[s.jsx(I,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",x(Bd())]}),g&&(y||k)&&s.jsxs(s.Fragment,{children:[s.jsx(Tn,{}),y&&s.jsxs(Vt,{onClick:re=>{re.stopPropagation(),v("createFile",n)},children:[s.jsx(I,{name:"file-add",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFile")]}),k&&s.jsxs(Vt,{onClick:re=>{re.stopPropagation(),v("createFolder",n)},children:[s.jsx(I,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFolder")]})]}),D&&s.jsxs(s.Fragment,{children:[s.jsx(Tn,{}),s.jsxs(Vt,{onClick:re=>{re.stopPropagation(),v("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.delete")]})]})]})]})}),e[44]=y,e[45]=k,e[46]=D,e[47]=w,e[48]=j,e[49]=m,e[50]=p,e[51]=N,e[52]=g,e[53]=n,e[54]=v,e[55]=h,e[56]=u,e[57]=x,e[58]=W):W=e[58];let ne;return e[59]!==A||e[60]!==Q||e[61]!==W?(ne=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:A,children:[Q,W]}),e[59]=A,e[60]=Q,e[61]=W,e[62]=ne):ne=e[62],ne},dN=()=>{const t=at.c(240),{t:e}=mt(),{files:n,runtime:r}=_n(),a=Lr()??"";let i;t[0]!==a?(i=Kn(a.trim()),t[0]=a,t[1]=i):i=t[1];const o=i,c=Tl(),d=Od(),p=$d(uN),m=Te(mN),u=Dl(a),[f,b]=l.useState(""),h=Ml(f,200),v=l.useRef(null);let x;t[2]===Symbol.for("react.memo_cache_sentinel")?(x=[],t[2]=x):x=t[2];const[g,w]=l.useState(x),[y,k]=l.useState(!1);let D;t[3]===Symbol.for("react.memo_cache_sentinel")?(D={},t[3]=D):D=t[3];const[j,S]=l.useState(D);let A;t[4]===Symbol.for("react.memo_cache_sentinel")?(A=new Set,t[4]=A):A=t[4];const E=l.useRef(A);let P;t[5]===Symbol.for("react.memo_cache_sentinel")?(P=new Set,t[5]=P):P=t[5];const C=l.useRef(P);let N;t[6]===Symbol.for("react.memo_cache_sentinel")?(N=[],t[6]=N):N=t[6];const T=N;let M;t[7]===Symbol.for("react.memo_cache_sentinel")?(M=[],t[7]=M):M=t[7];const R=M;let O;t[8]!==o?(O=jt=>o?jt.byRoot[o]?.expandedPaths??T:T,t[8]=o,t[9]=O):O=t[9];const z=Bn(O);let B;t[10]!==o?(B=jt=>o?jt.byRoot[o]?.selectedPath??null:null,t[10]=o,t[11]=B):B=t[11];const $=Bn(B),_=Bn(pN),Q=Bn(fN),W=Bn(hN),ne=Bn(gN);let re;t[12]!==o?(re=jt=>o?jt.contextPanelByDirectory[o]?.tabs??R:R,t[12]=o,t[13]=re):re=t[13];const ue=Te(re);let Y;t[14]!==ue?(Y=new Set(ue.map(xN).filter(bN).map(yN)),t[14]=ue,t[15]=Y):Y=t[15];const le=Y,[J,L]=l.useState(null),[V,K]=l.useState(null),[X,U]=l.useState(null),[ae,ve]=l.useState(""),[ie,fe]=l.useState(!1),H=!!n.writeFile,ce=!!n.createDirectory,se=!!n.rename,oe=!!n.delete,te=!!n.revealPath;let ke;t[16]!==H||t[17]!==ce||t[18]!==oe||t[19]!==se||t[20]!==te?(ke={canRename:se,canCreateFile:H,canCreateFolder:ce,canDelete:oe,canReveal:te},t[16]=H,t[17]=ce,t[18]=oe,t[19]=se,t[20]=te,t[21]=ke):ke=t[21];const Ne=ke;let je;t[22]!==n||t[23]!==e?(je=jt=>{n.revealPath&&n.revealPath(jt).catch(()=>{G.error(e("sidebarFilesTree.toast.revealFailed"))})},t[22]=n,t[23]=e,t[24]=je):je=t[24];const Se=je;let De;t[25]===Symbol.for("react.memo_cache_sentinel")?(De=(jt,Tt)=>{K(jt),U(Tt),ve(jt==="rename"&&Tt.name||""),fe(!1)},t[25]=De):De=t[25];const ye=De;let ge;t[26]!==d||t[27]!==c?(ge=(jt,Tt)=>{const Z=Tt.filter(vN).filter(ft=>c||!ft.name.startsWith(".")).filter(ft=>d||!iN(ft.name)).map(ft=>{const kt=ft.name,Ht=Kn(ft.path||""),Ns=Ht?rN(Ht)?Ht:Kn(`${jt}/${Ht}`):Kn(`${jt}/${kt}`),Cs=ft.isDirectory?"directory":"file",Ke=Cs==="file"&&kt.includes(".")?kt.split(".").pop()?.toLowerCase():void 0;return{name:kt,path:Ns,type:Cs,extension:Ke}});return nN(Z)},t[26]=d,t[27]=c,t[28]=ge):ge=t[28];const Me=ge;let Ue;t[29]!==n||t[30]!==Me||t[31]!==r.isDesktop||t[32]!==d?(Ue=async jt=>{const Tt=Kn(jt.trim());if(!Tt||E.current.has(Tt)||C.current.has(Tt))return;C.current=new Set(C.current),C.current.add(Tt);const Z=!d;await(r.isDesktop?n.listDirectory(Tt,{respectGitignore:Z}).then(jN):rn.listLocalDirectory(Tt,{respectGitignore:Z}).then(SN)).then(kt=>{const Ht=Me(Tt,kt);E.current=new Set(E.current),E.current.add(Tt),S(Ns=>({...Ns,[Tt]:Ht}))}).catch(()=>{S(kt=>({...kt,[Tt]:kt[Tt]??[]}))}).finally(()=>{C.current=new Set(C.current),C.current.delete(Tt)})},t[29]=n,t[30]=Me,t[31]=r.isDesktop,t[32]=d,t[33]=Ue):Ue=t[33];const q=Ue;let Ie;t[34]!==q||t[35]!==o?(Ie=async()=>{o&&(E.current=new Set,C.current=new Set,S(kN),await q(o))},t[34]=q,t[35]=o,t[36]=Ie):Ie=t[36];const Le=Ie;let Pe;t[37]!==q||t[38]!==Le?(Pe=async jt=>{if(!jt){await Le();return}const Tt=Kn(jt);E.current=new Set(E.current),E.current.delete(Tt),C.current=new Set(C.current),C.current.delete(Tt),await q(Tt)},t[37]=q,t[38]=Le,t[39]=Pe):Pe=t[39];const he=Pe;let F;t[40]!==q||t[41]!==o?(F=()=>{o&&(E.current=new Set,C.current=new Set,S(CN),q(o))},t[40]=q,t[41]=o,t[42]=F):F=t[42];let ee;t[43]!==q||t[44]!==o||t[45]!==d||t[46]!==c?(ee=[q,o,c,d],t[43]=q,t[44]=o,t[45]=d,t[46]=c,t[47]=ee):ee=t[47],l.useEffect(F,ee);let Ce,Fe;t[48]!==z||t[49]!==q||t[50]!==o?(Ce=()=>{if(!o||z.length===0)return;const jt=z.map(IN).filter(Z=>!!Z&&Z!==o&&Z.startsWith(`${o}/`)&&!E.current.has(Z)&&!C.current.has(Z)).sort(PN);if(jt.length===0)return;let Tt=!1;return(async()=>{for(let Z=0;Z<jt.length&&!Tt;Z=Z+3,Z){const ft=jt.slice(Z,Z+3);await Promise.all(ft.map(kt=>q(kt)))}})(),()=>{Tt=!0}},Fe=[z,q,o],t[48]=z,t[49]=q,t[50]=o,t[51]=Ce,t[52]=Fe):(Ce=t[51],Fe=t[52]),l.useEffect(Ce,Fe);let we,Qe;t[53]!==a||t[54]!==h||t[55]!==p||t[56]!==d||t[57]!==c?(we=()=>{if(!a){w([]),k(!1);return}const jt=h.trim();if(!jt){w([]),k(!1);return}let Tt=!1;return k(!0),p(a,jt,150,{includeHidden:c,respectGitignore:!d,type:"file"}).then(Z=>{if(Tt)return;const kt=Z.filter(Ht=>d||!oN(Ht.path)).map(AN);w(kt)}).catch(()=>{Tt||w([])}).finally(()=>{Tt||k(!1)}),()=>{Tt=!0}},Qe=[a,h,p,c,d],t[53]=a,t[54]=h,t[55]=p,t[56]=d,t[57]=c,t[58]=we,t[59]=Qe):(we=t[58],Qe=t[59]),l.useEffect(we,Qe);let pe;t[60]!==u||t[61]!==le||t[62]!==o?(pe=jt=>{if(le.has(jt))return"open";if(u?.files){const Tt=jt.startsWith(o+"/")?jt.slice(o.length+1):jt,Z=u.files.find(ft=>ft.path===Tt);if(Z){if(Z.index==="A"||Z.working_dir==="?")return"git-added";if(Z.index==="D")return"git-deleted";if(Z.index==="M"||Z.working_dir==="M")return"git-modified"}}return null},t[60]=u,t[61]=le,t[62]=o,t[63]=pe):pe=t[63];const Oe=pe;let nt;t[64]!==u||t[65]!==o?(nt=jt=>{if(!u?.files)return null;const Tt=jt.startsWith(o+"/")?jt.slice(o.length+1):jt,Z=Tt?`${Tt}/`:"";let ft=0,kt=0;for(const Ht of u.files)Ht.path.startsWith(Z)&&((Ht.index==="M"||Ht.working_dir==="M")&&ft++,(Ht.index==="A"||Ht.working_dir==="?")&&kt++);return ft+kt>0?{modified:ft,added:kt}:null},t[64]=u,t[65]=o,t[66]=nt):nt=t[66];const Re=nt;let de;t[67]!==Q||t[68]!==n||t[69]!==m||t[70]!==o||t[71]!==_?(de=async jt=>{if(!o)return;const Tt=await Xd(n,jt.path);if(!Tt.ok){G.error(Zd(Tt.reason));return}_(o,jt.path),Q(o,jt.path),m(o,jt.path)},t[67]=Q,t[68]=n,t[69]=m,t[70]=o,t[71]=_,t[72]=de):de=t[72];const He=de;let st;t[73]!==q||t[74]!==o||t[75]!==ne?(st=async jt=>{const Tt=Kn(jt);o&&(ne(o,Tt),E.current.has(Tt)||await q(Tt))},t[73]=q,t[74]=o,t[75]=ne,t[76]=st):st=t[76];const qe=st;let et;t[77]!==V||t[78]!==X||t[79]!==ae||t[80]!==n||t[81]!==he||t[82]!==W||t[83]!==o||t[84]!==$||t[85]!==_||t[86]!==e?(et=async jt=>{if(jt?.preventDefault(),!X||!V)return;fe(!0);const Tt=()=>fe(!1),Z=()=>K(null);if(V==="createFile"){if(!ae.trim()){G.error(e("sidebarFilesTree.toast.filenameRequired")),Tt();return}if(!n.writeFile){G.error(e("sidebarFilesTree.toast.writeNotSupported")),Tt();return}const ft=X.path,kt=ft?`${ft}/`:"",Ht=Kn(`${kt}${ae.trim()}`);await n.writeFile(Ht,"").then(async Ns=>{Ns.success&&(G.success(e("sidebarFilesTree.toast.fileCreated")),await he(ft)),Z()}).catch(()=>G.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Tt);return}if(V==="createFolder"){if(!ae.trim()){G.error(e("sidebarFilesTree.toast.folderNameRequired")),Tt();return}const ft=X.path,kt=ft?`${ft}/`:"",Ht=Kn(`${kt}${ae.trim()}`);await n.createDirectory(Ht).then(async Ns=>{Ns.success&&(G.success(e("sidebarFilesTree.toast.folderCreated")),await he(ft)),Z()}).catch(()=>G.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Tt);return}if(V==="rename"){if(!ae.trim()){G.error(e("sidebarFilesTree.toast.nameRequired")),Tt();return}if(!n.rename){G.error(e("sidebarFilesTree.toast.renameNotSupported")),Tt();return}const ft=X.path,kt=ft.split("/").slice(0,-1).join("/"),Ht=kt?`${kt}/`:"",Ns=Kn(`${Ht}${ae.trim()}`);await n.rename(ft,Ns).then(async Cs=>{Cs.success&&(G.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await he(kt),o&&W(o,ft),($===ft||$&&$.startsWith(`${ft}/`))&&_(o,null)),Z()}).catch(()=>G.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Tt);return}if(V==="delete"){if(!n.delete){G.error(e("sidebarFilesTree.toast.deleteNotSupported")),Tt();return}const ft=X.path,kt=ft.split("/").slice(0,-1).join("/");await n.delete(ft).then(async Ht=>{Ht.success&&(G.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await he(kt),o&&W(o,ft),($===ft||$&&$.startsWith(ft+"/"))&&_(o,null)),Z()}).catch(()=>G.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Tt);return}Tt()},t[77]=V,t[78]=X,t[79]=ae,t[80]=n,t[81]=he,t[82]=W,t[83]=o,t[84]=$,t[85]=_,t[86]=e,t[87]=et):et=t[87];const rt=et;let xe,Ye,_e,We,lt,Je,Ve;if(t[88]!==H||t[89]!==ce||t[90]!==j||t[91]!==J||t[92]!==a||t[93]!==z||t[94]!==Ne||t[95]!==n.downloadFile||t[96]!==Oe||t[97]!==Re||t[98]!==He||t[99]!==Se||t[100]!==Le||t[101]!==o||t[102]!==f||t[103]!==g||t[104]!==y||t[105]!==$||t[106]!==e||t[107]!==qe){let jt=function(zt,hs){const Jt=j[zt]??[];return Jt.map((Ut,os)=>{const tn=Ut.type==="directory",Zs=tn&&z.includes(Ut.path),nr=$===Ut.path,Vn=os===Jt.length-1;return s.jsxs("li",{className:"relative",children:[hs>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Vn&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(cN,{node:Ut,root:o,isExpanded:Zs,isActive:nr,status:tn?void 0:Oe(Ut.path),badge:tn?Re(Ut.path):void 0,permissions:Ne,downloadFile:n.downloadFile,contextMenuPath:J,setContextMenuPath:L,onSelect:He,onToggle:qe,onRevealPath:Se,onOpenDialog:ye}),tn&&Zs&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:jt(Ut.path,hs+1)})]},Ut.path)})};const Tt=!!(o&&j[o]);Je="flex h-full min-h-0 flex-col overflow-hidden bg-sidebar";let Z;t[115]===Symbol.for("react.memo_cache_sentinel")?(Z=s.jsx(I,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),t[115]=Z):Z=t[115];let ft;t[116]===Symbol.for("react.memo_cache_sentinel")?(ft=zt=>b(zt.target.value),t[116]=ft):ft=t[116];let kt;t[117]!==e?(kt=e("sidebarFilesTree.search.placeholder"),t[117]=e,t[118]=kt):kt=t[118];let Ht;t[119]!==f||t[120]!==kt?(Ht=s.jsx(Wt,{ref:v,value:f,onChange:ft,placeholder:kt,className:"h-8 pl-8 pr-8 typography-meta"}),t[119]=f,t[120]=kt,t[121]=Ht):Ht=t[121];let Ns;t[122]!==f||t[123]!==e?(Ns=f.trim().length>0?s.jsx("button",{type:"button","aria-label":e("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{b(""),v.current?.focus()},children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null,t[122]=f,t[123]=e,t[124]=Ns):Ns=t[124];let Cs;t[125]!==Ht||t[126]!==Ns?(Cs=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Z,Ht,Ns]}),t[125]=Ht,t[126]=Ns,t[127]=Cs):Cs=t[127];let Ke;t[128]!==H||t[129]!==a||t[130]!==e?(Ke=H&&s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>ye("createFile",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(I,{name:"file-add",className:"h-4 w-4"})}),t[128]=H,t[129]=a,t[130]=e,t[131]=Ke):Ke=t[131];let bt;t[132]!==ce||t[133]!==a||t[134]!==e?(bt=ce&&s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>ye("createFolder",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(I,{name:"folder-add",className:"h-4 w-4"})}),t[132]=ce,t[133]=a,t[134]=e,t[135]=bt):bt=t[135];let Ct;t[136]!==Le?(Ct=()=>{Le()},t[136]=Le,t[137]=Ct):Ct=t[137];let Ft;t[138]!==e?(Ft=e("sidebarFilesTree.actions.refreshTitle"),t[138]=e,t[139]=Ft):Ft=t[139];let Zt;t[140]===Symbol.for("react.memo_cache_sentinel")?(Zt=s.jsx(I,{name:"refresh",className:"h-4 w-4"}),t[140]=Zt):Zt=t[140];let it;t[141]!==Ct||t[142]!==Ft?(it=s.jsx(be,{variant:"ghost",size:"sm",onClick:Ct,className:"h-8 w-8 p-0 flex-shrink-0",title:Ft,children:Zt}),t[141]=Ct,t[142]=Ft,t[143]=it):it=t[143],t[144]!==Cs||t[145]!==Ke||t[146]!==bt||t[147]!==it?(Ve=s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[Cs,Ke,bt,it]}),t[144]=Cs,t[145]=Ke,t[146]=bt,t[147]=it,t[148]=Ve):Ve=t[148],xe=Es,We="flex-1 min-h-0",lt="p-2",Ye="flex flex-col",_e=y?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("sidebarFilesTree.state.searching")]}):g.length>0?g.map(zt=>{const hs=$===zt.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>He(zt),draggable:!0,onDragStart:Jt=>{const Ut=zt.relativePath||Yh(o??"",zt.path);!Ut||Ut==="."||(Jt.dataTransfer.setData("application/x-openchamber-file-path",Ut),Jt.dataTransfer.effectAllowed="copy")},className:me("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",hs?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:zt.path,children:[Jh(zt.path,zt.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:zt.relativePath??zt.path})]})},zt.path)}):Tt&&o?jt(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("sidebarFilesTree.state.loading")}),t[88]=H,t[89]=ce,t[90]=j,t[91]=J,t[92]=a,t[93]=z,t[94]=Ne,t[95]=n.downloadFile,t[96]=Oe,t[97]=Re,t[98]=He,t[99]=Se,t[100]=Le,t[101]=o,t[102]=f,t[103]=g,t[104]=y,t[105]=$,t[106]=e,t[107]=qe,t[108]=xe,t[109]=Ye,t[110]=_e,t[111]=We,t[112]=lt,t[113]=Je,t[114]=Ve}else xe=t[108],Ye=t[109],_e=t[110],We=t[111],lt=t[112],Je=t[113],Ve=t[114];let yt;t[149]!==Ye||t[150]!==_e?(yt=s.jsx("ul",{className:Ye,children:_e}),t[149]=Ye,t[150]=_e,t[151]=yt):yt=t[151];let $t;t[152]!==xe||t[153]!==We||t[154]!==lt||t[155]!==yt?($t=s.jsx(xe,{outerClassName:We,className:lt,children:yt}),t[152]=xe,t[153]=We,t[154]=lt,t[155]=yt,t[156]=$t):$t=t[156];const Gt=!!V;let ss;t[157]===Symbol.for("react.memo_cache_sentinel")?(ss=jt=>!jt&&K(null),t[157]=ss):ss=t[157];let wt;t[158]!==V||t[159]!==e?(wt=V==="createFile"&&e("sidebarFilesTree.dialog.createFile.title"),t[158]=V,t[159]=e,t[160]=wt):wt=t[160];let Dt;t[161]!==V||t[162]!==e?(Dt=V==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.title"),t[161]=V,t[162]=e,t[163]=Dt):Dt=t[163];let Xt;t[164]!==V||t[165]!==e?(Xt=V==="rename"&&e("sidebarFilesTree.dialog.rename.title"),t[164]=V,t[165]=e,t[166]=Xt):Xt=t[166];let Yt;t[167]!==V||t[168]!==e?(Yt=V==="delete"&&e("sidebarFilesTree.dialog.delete.title"),t[167]=V,t[168]=e,t[169]=Yt):Yt=t[169];let ts;t[170]!==wt||t[171]!==Dt||t[172]!==Xt||t[173]!==Yt?(ts=s.jsxs(Ss,{children:[wt,Dt,Xt,Yt]}),t[170]=wt,t[171]=Dt,t[172]=Xt,t[173]=Yt,t[174]=ts):ts=t[174];let dt;t[175]!==V||t[176]!==X?.path||t[177]!==e?(dt=V==="createFile"&&e("sidebarFilesTree.dialog.createFile.description",{path:X?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[175]=V,t[176]=X?.path,t[177]=e,t[178]=dt):dt=t[178];let Rt;t[179]!==V||t[180]!==X?.path||t[181]!==e?(Rt=V==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.description",{path:X?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[179]=V,t[180]=X?.path,t[181]=e,t[182]=Rt):Rt=t[182];let is;t[183]!==V||t[184]!==X?.name||t[185]!==e?(is=V==="rename"&&e("sidebarFilesTree.dialog.rename.description",{name:X?.name??""}),t[183]=V,t[184]=X?.name,t[185]=e,t[186]=is):is=t[186];let xs;t[187]!==V||t[188]!==X?.name||t[189]!==e?(xs=V==="delete"&&e("sidebarFilesTree.dialog.delete.description",{name:X?.name??""}),t[187]=V,t[188]=X?.name,t[189]=e,t[190]=xs):xs=t[190];let ps;t[191]!==dt||t[192]!==Rt||t[193]!==is||t[194]!==xs?(ps=s.jsxs(Fs,{children:[dt,Rt,is,xs]}),t[191]=dt,t[192]=Rt,t[193]=is,t[194]=xs,t[195]=ps):ps=t[195];let ws;t[196]!==ts||t[197]!==ps?(ws=s.jsxs(As,{children:[ts,ps]}),t[196]=ts,t[197]=ps,t[198]=ws):ws=t[198];let qt;t[199]!==V||t[200]!==ae||t[201]!==rt||t[202]!==e?(qt=V!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Wt,{value:ae,onChange:jt=>ve(jt.target.value),placeholder:e(V==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:jt=>{jt.key==="Enter"&&rt()},autoFocus:!0})}),t[199]=V,t[200]=ae,t[201]=rt,t[202]=e,t[203]=qt):qt=t[203];let Ge;t[204]===Symbol.for("react.memo_cache_sentinel")?(Ge=()=>K(null),t[204]=Ge):Ge=t[204];let St;t[205]!==e?(St=e("sidebarFilesTree.dialog.cancel"),t[205]=e,t[206]=St):St=t[206];let Mt;t[207]!==ie||t[208]!==St?(Mt=s.jsx(be,{variant:"outline",onClick:Ge,disabled:ie,children:St}),t[207]=ie,t[208]=St,t[209]=Mt):Mt=t[209];const Nt=V==="delete"?"destructive":"default";let Kt;t[210]!==rt?(Kt=()=>{rt()},t[210]=rt,t[211]=Kt):Kt=t[211];let ns;t[212]!==V||t[213]!==ae||t[214]!==ie?(ns=ie||V!=="delete"&&!ae.trim(),t[212]=V,t[213]=ae,t[214]=ie,t[215]=ns):ns=t[215];let js;t[216]!==V||t[217]!==ie||t[218]!==e?(js=ie?s.jsx(I,{name:"loader-4",className:"animate-spin"}):e(V==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm"),t[216]=V,t[217]=ie,t[218]=e,t[219]=js):js=t[219];let ls;t[220]!==Nt||t[221]!==Kt||t[222]!==ns||t[223]!==js?(ls=s.jsx(be,{variant:Nt,onClick:Kt,disabled:ns,children:js}),t[220]=Nt,t[221]=Kt,t[222]=ns,t[223]=js,t[224]=ls):ls=t[224];let ks;t[225]!==Mt||t[226]!==ls?(ks=s.jsxs(Hs,{children:[Mt,ls]}),t[225]=Mt,t[226]=ls,t[227]=ks):ks=t[227];let Os;t[228]!==ws||t[229]!==qt||t[230]!==ks?(Os=s.jsxs(ys,{children:[ws,qt,ks]}),t[228]=ws,t[229]=qt,t[230]=ks,t[231]=Os):Os=t[231];let xt;t[232]!==Gt||t[233]!==Os?(xt=s.jsx(vs,{open:Gt,onOpenChange:ss,children:Os}),t[232]=Gt,t[233]=Os,t[234]=xt):xt=t[234];let cs;return t[235]!==Je||t[236]!==Ve||t[237]!==$t||t[238]!==xt?(cs=s.jsxs("section",{className:Je,children:[Ve,$t,xt]}),t[235]=Je,t[236]=Ve,t[237]=$t,t[238]=xt,t[239]=cs):cs=t[239],cs};function uN(t){return t.searchFiles}function mN(t){return t.openContextFile}function pN(t){return t.setSelectedPath}function fN(t){return t.addOpenPath}function hN(t){return t.removeOpenPathsByPrefix}function gN(t){return t.toggleExpandedPath}function xN(t){return t.mode==="file"?t.targetPath:null}function bN(t){return typeof t=="string"&&t.length>0}function yN(t){return Kn(t)}function vN(t){return t&&typeof t.name=="string"&&t.name.length>0}function wN(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function jN(t){return t.entries.map(wN)}function NN(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function SN(t){return t.map(NN)}function kN(t){return Object.keys(t).length===0?t:{}}function CN(t){return Object.keys(t).length===0?t:{}}function IN(t){return Kn(t)}function PN(t,e){return t.split("/").length-e.split("/").length}function AN(t){return{name:t.name,path:Kn(t.path),type:"file",extension:t.extension,relativePath:t.relativePath}}function DN(t,e){const n=at.c(6),{git:r}=_n(),a=nn(TN);let i,o;n[0]!==t||n[1]!==a||n[2]!==r||n[3]!==e?(i=()=>{if(!t||!r||!e)return;a(t,r);const c=setInterval(()=>{typeof document<"u"&&document.hidden||a(t,r)},1e4);return()=>clearInterval(c)},o=[t,r,e,a],n[0]=t,n[1]=a,n[2]=r,n[3]=e,n[4]=i,n[5]=o):(i=n[4],o=n[5]),l.useEffect(i,o)}function TN(t){return t.ensureStatus}const MN=()=>{const t=at.c(17),e=Ls(RN),n=Ls(FN),r=Ws(LN),a=nn(ON);let i;e:{if(e){let h;t[0]!==e||t[1]!==n?(h=n.find(v=>v.id===e)??n[0]??null,t[0]=e,t[1]=n,t[2]=h):h=t[2],i=h;break e}i=n[0]??null}const o=i;let c;e:{if(!o){c=null;break e}let h;t[3]!==o.id||t[4]!==o.path?(h={id:o.id,path:o.path},t[3]=o.id,t[4]=o.path,t[5]=h):h=t[5],c=h}const d=c;let p;e:{if(!o){p=null;break e}let h;t[6]!==o.label||t[7]!==o.path||t[8]!==r?(h=o.label?.trim()||Fa(o.path,r)||o.path,t[6]=o.label,t[7]=o.path,t[8]=r,t[9]=h):h=t[9],p=h}const m=p;let u;e:{if(!o){u=!1;break e}let h;t[10]!==o.path||t[11]!==a?(h=a.get(o.path)?.isGitRepo,t[10]=o.path,t[11]=a,t[12]=h):h=t[12],u=h===!0}const f=u;let b;return t[13]!==f||t[14]!==m||t[15]!==d?(b=s.jsx("div",{className:"h-full min-h-0 overflow-auto bg-sidebar",children:s.jsx(jw,{projectRef:d,projectLabel:m,canCreateWorktree:f})}),t[13]=f,t[14]=m,t[15]=d,t[16]=b):b=t[16],b},EN=()=>{const t=at.c(38),{t:e}=mt(),n=Te($N),r=Te(BN),a=Te(zN),i=Lr();DN(i,a);let o;t[0]!==e?(o=e("layout.rightSidebar.git"),t[0]=e,t[1]=o):o=t[1];let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"}),t[2]=c):c=t[2];let d;t[3]!==o?(d={id:"git",label:o,icon:c},t[3]=o,t[4]=d):d=t[4];let p;t[5]!==e?(p=e("layout.rightSidebar.files"),t[5]=e,t[6]=p):p=t[6];let m;t[7]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(I,{name:"folder-3",className:"h-3.5 w-3.5"}),t[7]=m):m=t[7];let u;t[8]!==p?(u={id:"files",label:p,icon:m},t[8]=p,t[9]=u):u=t[9];let f;t[10]!==e?(f=e("layout.rightSidebar.context"),t[10]=e,t[11]=f):f=t[11];let b;t[12]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(I,{name:"booklet",className:"h-3.5 w-3.5"}),t[12]=b):b=t[12];let h;t[13]!==f?(h={id:"context",label:f,icon:b},t[13]=f,t[14]=h):h=t[14];let v;t[15]!==d||t[16]!==u||t[17]!==h?(v=[d,u,h],t[15]=d,t[16]=u,t[17]=h,t[18]=v):v=t[18];const x=v;let g;t[19]!==r?(g=A=>r(A),t[19]=r,t[20]=g):g=t[20];let w;t[21]!==n||t[22]!==g||t[23]!==x?(w=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx(Er,{items:x,activeId:n,onSelect:g,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[21]=n,t[22]=g,t[23]=x,t[24]=w):w=t[24];let y;t[25]!==n?(y=n==="git"&&s.jsx(qh,{}),t[25]=n,t[26]=y):y=t[26];let k;t[27]!==n?(k=n==="files"&&s.jsx(dN,{}),t[27]=n,t[28]=k):k=t[28];let D;t[29]!==n?(D=n==="context"&&s.jsx(MN,{}),t[29]=n,t[30]=D):D=t[30];let j;t[31]!==y||t[32]!==k||t[33]!==D?(j=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[y,k,D]}),t[31]=y,t[32]=k,t[33]=D,t[34]=j):j=t[34];let S;return t[35]!==w||t[36]!==j?(S=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[w,j]}),t[35]=w,t[36]=j,t[37]=S):S=t[37],S};function RN(t){return t.activeProjectId}function FN(t){return t.projects}function LN(t){return t.homeDirectory}function ON(t){return t.directories}function $N(t){return t.rightSidebarTab}function BN(t){return t.setRightSidebarTab}function zN(t){return t.isRightSidebarOpen}const _N=1100,dd=15e3,Lm=500,VN=t=>t<=6?t:t<=12?6:t<=25?4:2,Qh=l.memo(()=>{const t=at.c(4),{t:e}=mt();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}),Xh={"?":{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"}},UN=Xh.M,Yo=[{value:"single",labelKey:"diffView.mode.single.label",descriptionKey:"diffView.mode.single.description"},{value:"stacked",labelKey:"diffView.mode.stacked.label",descriptionKey:"diffView.mode.stacked.description"}],WN=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"},Zh=t=>{const e=WN(t);return Xh[e]??UN},KN=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},HN=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),GN=(t,e)=>{const n=t.replace(/\\/g,"/").replace(/\/+$/g,""),r=e.replace(/\\/g,"/");if(HN(r))return r;const a=r.replace(/^\/+/,"");return n?`${n}/${a}`:a},Om=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),$m=(t,e)=>{const n=t.split(`
|
|
46
|
+
`),r=e.split(`
|
|
47
|
+
`),a=Math.min(n.length,r.length);for(let i=0;i<a;i+=1)if(n[i]!==r[i])return i+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},qN=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},xl=(t,e)=>{const n=t??0,r=e??0;return!n&&!r?null:s.jsxs("span",{className:"typography-meta flex flex-shrink-0 items-center gap-1 text-xs whitespace-nowrap",children:[n?s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",n]}):null,r?s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",r]}):null]})},YN=l.memo(t=>{const e=at.c(29),{changedFiles:n,selectedFile:r,selectedFileEntry:a,onSelectFile:i,isMobile:o,showModeSelector:c,mode:d,onModeChange:p}=t,m=c===void 0?!1:c,{t:u}=mt();let f;e[0]!==o?(f=S=>{if(!o)return S;const A=S.lastIndexOf("/");return A>=0?S.slice(A+1):S},e[0]=o,e[1]=f):f=e[1];const b=f;if(n.length===0)return null;let h;e[2]!==b||e[3]!==a||e[4]!==u?(h=a?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx(jr,{filePath:a.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:b(a.path)}),xl(a.insertions,a.deletions)]}):s.jsx("span",{className:"text-muted-foreground",children:u("diffView.selector.selectFile")}),e[2]=b,e[3]=a,e[4]=u,e[5]=h):h=e[5];let v;e[6]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[6]=v):v=e[6];let x;e[7]!==h?(x=s.jsx(Bs,{asChild:!0,children:s.jsxs("button",{className:"flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",children:[h,v]})}),e[7]=h,e[8]=x):x=e[8];let g;e[9]!==d||e[10]!==p||e[11]!==m||e[12]!==u?(g=m&&d&&p?s.jsxs(s.Fragment,{children:[s.jsx(zi,{className:"typography-meta text-muted-foreground",children:u("diffView.selector.viewMode")}),s.jsx(il,{value:d,onValueChange:S=>p(S),children:Yo.map(S=>s.jsx(ol,{value:S.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:u(S.labelKey)})},S.value))}),s.jsx(Tn,{})]}):null,e[9]=d,e[10]=p,e[11]=m,e[12]=u,e[13]=g):g=e[13];const w=r??"";let y;if(e[14]!==n||e[15]!==b){let S;e[17]!==b?(S=A=>s.jsx(ol,{value:A.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(jr,{filePath:A.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:b(A.path)}),s.jsx("span",{className:"ml-auto",children:xl(A.insertions,A.deletions)})]})},A.path),e[17]=b,e[18]=S):S=e[18],y=n.map(S),e[14]=n,e[15]=b,e[16]=y}else y=e[16];let k;e[19]!==i||e[20]!==w||e[21]!==y?(k=s.jsx(il,{value:w,onValueChange:i,children:y}),e[19]=i,e[20]=w,e[21]=y,e[22]=k):k=e[22];let D;e[23]!==g||e[24]!==k?(D=s.jsxs(zs,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[g,k]}),e[23]=g,e[24]=k,e[25]=D):D=e[25];let j;return e[26]!==D||e[27]!==x?(j=s.jsxs(_s,{children:[x,D]}),e[26]=D,e[27]=x,e[28]=j):j=e[28],j}),JN=l.memo(t=>{const e=at.c(31),{mode:n,onModeChange:r}=t,{t:a}=mt();let i,o,c,d,p,m;if(e[0]!==n||e[1]!==a){const y=Yo.find(k=>k.value===n)??Yo[0];o=_s,i=Bs,m=!0,p="flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",c="min-w-0 truncate typography-meta",d=a(y.labelKey),e[0]=n,e[1]=a,e[2]=i,e[3]=o,e[4]=c,e[5]=d,e[6]=p,e[7]=m}else i=e[2],o=e[3],c=e[4],d=e[5],p=e[6],m=e[7];let u;e[8]!==c||e[9]!==d?(u=s.jsx("span",{className:c,children:d}),e[8]=c,e[9]=d,e[10]=u):u=e[10];let f;e[11]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[11]=f):f=e[11];let b;e[12]!==p||e[13]!==u?(b=s.jsxs("button",{className:p,children:[u,f]}),e[12]=p,e[13]=u,e[14]=b):b=e[14];let h;e[15]!==i||e[16]!==m||e[17]!==b?(h=s.jsx(i,{asChild:m,children:b}),e[15]=i,e[16]=m,e[17]=b,e[18]=h):h=e[18];let v;e[19]!==r?(v=y=>r(y),e[19]=r,e[20]=v):v=e[20];let x;e[21]!==a?(x=Yo.map(y=>s.jsx(ol,{value:y.value,children:s.jsx("span",{className:"typography-meta text-foreground",children:a(y.labelKey)})},y.value)),e[21]=a,e[22]=x):x=e[22];let g;e[23]!==n||e[24]!==x||e[25]!==v?(g=s.jsx(zs,{className:"min-w-[140px]",children:s.jsx(il,{value:n,onValueChange:v,children:x})}),e[23]=n,e[24]=x,e[25]=v,e[26]=g):g=e[26];let w;return e[27]!==o||e[28]!==g||e[29]!==h?(w=s.jsxs(o,{children:[h,g]}),e[27]=o,e[28]=g,e[29]=h,e[30]=w):w=e[30],w}),QN=l.memo(t=>{const e=at.c(11),{changedFiles:n,selectedFile:r,onSelectFile:a}=t,{t:i}=mt();if(n.length===0)return null;let o;if(e[0]!==n||e[1]!==a||e[2]!==r||e[3]!==i){let d;e[5]!==a||e[6]!==r||e[7]!==i?(d=p=>{const m=Zh(p),u=r===p.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>a(p.path),className:me("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",u?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[s.jsx(jr,{filePath:p.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:i(m.descriptionKey),"aria-label":i(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:p.path,children:p.path}),xl(p.insertions,p.deletions)]})},p.path)},e[5]=a,e[6]=r,e[7]=i,e[8]=d):d=e[8],o=n.map(d),e[0]=n,e[1]=a,e[2]=r,e[3]=i,e[4]=o}else o=e[4];let c;return e[9]!==o?(c=s.jsx(Es,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:o})}),e[9]=o,e[10]=c):c=e[10],c}),XN=l.memo(t=>{const e=at.c(21),{filePath:n,diff:r,isVisible:a,renderSideBySide:i}=t,{t:o}=mt(),c=r.original.length>0,d=r.modified.length>0;if(!a){let v;return e[0]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"absolute inset-0 hidden"}),e[0]=v):v=e[0],v}const p=i?"flex flex-row gap-6 items-start justify-center h-full":"flex flex-col gap-4 items-center",m=i?"flex flex-col items-center gap-2 flex-1 min-w-0 h-full":"flex flex-col items-center gap-2";let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={contain:"size layout"},e[1]=u):u=e[1];let f;e[2]!==r.original||e[3]!==n||e[4]!==c||e[5]!==m||e[6]!==i||e[7]!==o?(f=c&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:o("diffView.image.original")}),s.jsx("img",{src:r.original,alt:o("diffView.image.originalAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[2]=r.original,e[3]=n,e[4]=c,e[5]=m,e[6]=i,e[7]=o,e[8]=f):f=e[8];let b;e[9]!==r.modified||e[10]!==n||e[11]!==d||e[12]!==c||e[13]!==m||e[14]!==i||e[15]!==o?(b=d&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:o(c?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:o("diffView.image.modifiedAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[9]=r.modified,e[10]=n,e[11]=d,e[12]=c,e[13]=m,e[14]=i,e[15]=o,e[16]=b):b=e[16];let h;return e[17]!==p||e[18]!==f||e[19]!==b?(h=s.jsx("div",{className:"absolute inset-0 overflow-auto p-4",style:u,children:s.jsxs("div",{className:p,children:[f,b]})}),e[17]=p,e[18]=f,e[19]=b,e[20]=h):h=e[20],h}),ZN=l.memo(t=>{const e=at.c(20),{filePath:n,diff:r,renderSideBySide:a}=t,{t:i}=mt(),o=r.original.length>0,c=r.modified.length>0,d=a?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",p=a?"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 u;e[1]!==r.original||e[2]!==n||e[3]!==o||e[4]!==p||e[5]!==a||e[6]!==i?(u=o&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i("diffView.image.original")}),s.jsx("img",{src:r.original,alt:i("diffView.image.originalAlt",{path:n}),className:a?"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]=o,e[4]=p,e[5]=a,e[6]=i,e[7]=u):u=e[7];let f;e[8]!==r.modified||e[9]!==n||e[10]!==c||e[11]!==o||e[12]!==p||e[13]!==a||e[14]!==i?(f=c&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i(o?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:i("diffView.image.modifiedAlt",{path:n}),className:a?"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]=c,e[11]=o,e[12]=p,e[13]=a,e[14]=i,e[15]=f):f=e[15];let b;return e[16]!==d||e[17]!==u||e[18]!==f?(b=s.jsx("div",{className:"w-full overflow-auto p-4",style:m,children:s.jsxs("div",{className:d,children:[u,f]})}),e[16]=d,e[17]=u,e[18]=f,e[19]=b):b=e[19],b}),e2=l.memo(t=>{const e=at.c(15),{filePath:n,diff:r,renderSideBySide:a,wrapLines:i}=t;let o;e[0]!==n?(o=pi(n)||"text",e[0]=n,e[1]=o):o=e[1];const c=o;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Qh,{}),e[2]=m):m=e[2],m}if(fi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a?(m=s.jsx(ZN,{filePath:n,diff:r,renderSideBySide:a}),e[3]=r,e[4]=n,e[5]=a,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 p;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==c||e[12]!==a||e[13]!==i?(p=s.jsx("div",{className:"w-full",style:d,children:s.jsx(Yd,{original:r.original,modified:r.modified,language:c,fileName:n,renderSideBySide:a,wrapLines:i,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=c,e[12]=a,e[13]=i,e[14]=p):p=e[14],p}),t2=l.memo(t=>{const e=at.c(15),{filePath:n,diff:r,isVisible:a,renderSideBySide:i,wrapLines:o}=t;let c;e[0]!==n?(c=pi(n)||"text",e[0]=n,e[1]=c):c=e[1];const d=c;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Qh,{}),e[2]=m):m=e[2],m}if(!a)return null;if(fi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a||e[6]!==i?(m=s.jsx(XN,{filePath:n,diff:r,isVisible:a,renderSideBySide:i}),e[3]=r,e[4]=n,e[5]=a,e[6]=i,e[7]=m):m=e[7],m}let p;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==d||e[12]!==i||e[13]!==o?(p=s.jsx(Es,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(Yd,{original:r.original,modified:r.modified,language:d,fileName:n,renderSideBySide:i,wrapLines:o,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=d,e[12]=i,e[13]=o,e[14]=p):p=e[14],p}),s2=l.memo(t=>{const e=at.c(122),{directory:n,file:r,layout:a,wrapLines:i,scrollRootRef:o,isSelected:c,onSelect:d,registerSectionRef:p,defaultCollapsed:m,expandRequestPath:u,expandRequestNonce:f,showOpenInEditorAction:b,isOpeningInEditor:h,onOpenInEditor:v}=t,x=m===void 0?!1:m,g=u===void 0?null:u,w=f===void 0?0:f,y=b===void 0?!1:b,k=h===void 0?!1:h,{t:D}=mt(),{git:j}=_n();let S;e[0]!==n||e[1]!==r.path?(S=He=>He.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=S):S=e[2];const A=nn(S),E=nn(r2),P=Te(a2),[C,N]=l.useState(!x),[T,M]=l.useState(!1),[R,O]=l.useState(0),[z,B]=l.useState(null),[$,_]=l.useState(!1),[Q,W]=l.useState(!1),ne=l.useRef(null),re=l.useRef(null);let ue;e[3]!==r?(ue=Zh(r),e[3]=r,e[4]=ue):ue=e[4];const Y=ue,le=a==="side-by-side";let J;e:{if(!A){J=null;break e}let He;e[5]!==A.isBinary||e[6]!==A.modified||e[7]!==A.original?(He={original:A.original,modified:A.modified,isBinary:A.isBinary},e[5]=A.isBinary,e[6]=A.modified,e[7]=A.original,e[8]=He):He=e[8],J=He}const L=J;let V;e[9]!==r.path||e[10]!==p?(V=He=>{re.current=He,p(r.path,He)},e[9]=r.path,e[10]=p,e[11]=V):V=e[11];const K=V;let X;e[12]===Symbol.for("react.memo_cache_sentinel")?(X=He=>{N(He),He&&M(!0)},e[12]=X):X=e[12];const U=X;let ae;e[13]!==r.path||e[14]!==d?(ae=()=>{d(r.path)},e[13]=r.path,e[14]=d,e[15]=ae):ae=e[15];const ve=ae;let ie,fe;e[16]!==T||e[17]!==C||e[18]!==o?(ie=()=>{if(!C||T)return;const He=re.current;if(!He)return;if(!o.current||typeof IntersectionObserver>"u"){M(!0);return}const st=new IntersectionObserver(qe=>{qe.some(i2)&&(M(!0),st.disconnect())},{root:o.current,rootMargin:"200px 0px",threshold:.1});return st.observe(He),()=>st.disconnect()},fe=[T,C,o],e[16]=T,e[17]=C,e[18]=o,e[19]=ie,e[20]=fe):(ie=e[19],fe=e[20]),l.useEffect(ie,fe);let H,ce;e[21]!==w||e[22]!==g||e[23]!==r.path?(H=()=>{w<=0||g!==r.path||(N(!0),M(!0))},ce=[w,g,r.path],e[21]=w,e[22]=g,e[23]=r.path,e[24]=H,e[25]=ce):(H=e[24],ce=e[25]),l.useEffect(H,ce);let se,oe;e[26]!==L||e[27]!==R||e[28]!==n||e[29]!==r.path||e[30]!==j||e[31]!==T||e[32]!==C||e[33]!==E?(se=()=>{if(!C||!T)return;if(!n||L){ne.current=null,_(!1);return}const He=`${n}::${r.path}::${R}`;if(ne.current===He)return;ne.current=He,B(null),_(!0);let st=!1;const qe=j.getGitFileDiff(n,{path:r.path}),et=new Promise(o2);return Promise.race([qe,et]).then(rt=>{st||(E(n,r.path,{original:rt.original??"",modified:rt.modified??"",isBinary:rt.isBinary}),_(!1))}).catch(rt=>{if(st)return;const xe=rt instanceof Error?rt.message:String(rt);B(xe),_(!1)}),()=>{st=!0,ne.current===He&&(ne.current=null)}},oe=[n,L,R,r.path,j,T,C,E],e[26]=L,e[27]=R,e[28]=n,e[29]=r.path,e[30]=j,e[31]=T,e[32]=C,e[33]=E,e[34]=se,e[35]=oe):(se=e[34],oe=e[35]),l.useEffect(se,oe);let te;e[36]!==ve||e[37]!==C?(te=()=>{U(!C),ve()},e[36]=ve,e[37]=C,e[38]=te):te=e[38];const ke=te,Ne=C?"rounded-b-none":"rounded-b-xl",je=c?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let Se;e[39]!==Ne||e[40]!==je?(Se=me("group/header relative flex w-full items-center gap-2 px-3 py-1.5 rounded-t-xl border border-border/60 overflow-hidden","bg-background",Ne,"text-muted-foreground hover:text-foreground",je),e[39]=Ne,e[40]=je,e[41]=Se):Se=e[41];let De;e[42]===Symbol.for("react.memo_cache_sentinel")?(De=s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-interactive-hover"}),e[42]=De):De=e[42];let ye;e[43]!==C?(ye=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:C?s.jsx(I,{name:"arrow-down-s",className:"size-4"}):s.jsx(I,{name:"arrow-right-s",className:"size-4"})}),e[43]=C,e[44]=ye):ye=e[44];let ge;e[45]!==Y.color?(ge={color:Y.color},e[45]=Y.color,e[46]=ge):ge=e[46];let Me;e[47]!==Y.descriptionKey||e[48]!==D?(Me=D(Y.descriptionKey),e[47]=Y.descriptionKey,e[48]=D,e[49]=Me):Me=e[49];let Ue;e[50]!==Y.descriptionKey||e[51]!==D?(Ue=D(Y.descriptionKey),e[50]=Y.descriptionKey,e[51]=D,e[52]=Ue):Ue=e[52];let q;e[53]!==Y.code||e[54]!==ge||e[55]!==Me||e[56]!==Ue?(q=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:ge,title:Me,"aria-label":Ue,children:Y.code}),e[53]=Y.code,e[54]=ge,e[55]=Me,e[56]=Ue,e[57]=q):q=e[57];const Ie=r.path;let Le;e[58]!==r.path?(Le=s.jsx(jr,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[58]=r.path,e[59]=Le):Le=e[59];let Pe;if(e[60]!==r.path){e:{const He=r.path.lastIndexOf("/");if(He===-1){let We;e[62]===Symbol.for("react.memo_cache_sentinel")?(We={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[62]=We):We=e[62],Pe=s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:We,children:r.path});break e}const st=r.path.slice(0,He),qe=r.path.slice(He+1);let et;e[63]===Symbol.for("react.memo_cache_sentinel")?(et={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[63]=et):et=e[63];let rt;e[64]!==st?(rt=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:et,children:st}),e[64]=st,e[65]=rt):rt=e[65];let xe;e[66]===Symbol.for("react.memo_cache_sentinel")?(xe=s.jsx("span",{className:"text-muted-foreground",children:"/"}),e[66]=xe):xe=e[66];let Ye;e[67]!==qe?(Ye=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[xe,s.jsx("span",{className:"text-foreground",children:qe})]}),e[67]=qe,e[68]=Ye):Ye=e[68];let _e;e[69]!==rt||e[70]!==Ye?(_e=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[rt,Ye]}),e[69]=rt,e[70]=Ye,e[71]=_e):_e=e[71],Pe=_e}e[60]=r.path,e[61]=Pe}else Pe=e[61];let he;e[72]!==Le||e[73]!==Pe?(he=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[Le,Pe]}),e[72]=Le,e[73]=Pe,e[74]=he):he=e[74];let F;e[75]!==r.path||e[76]!==he?(F=s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:Ie,children:he}),e[75]=r.path,e[76]=he,e[77]=F):F=e[77];let ee;e[78]!==ye||e[79]!==q||e[80]!==F?(ee=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[ye,q,F]}),e[78]=ye,e[79]=q,e[80]=F,e[81]=ee):ee=e[81];let Ce;e[82]!==r.deletions||e[83]!==r.insertions?(Ce=xl(r.insertions,r.deletions),e[82]=r.deletions,e[83]=r.insertions,e[84]=Ce):Ce=e[84];let Fe;e[85]!==L||e[86]!==r.path||e[87]!==k||e[88]!==v||e[89]!==y||e[90]!==D?(Fe=y&&v?s.jsx(be,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:D("diffView.actions.openFileInEditorAtChange"),onClick:He=>{He.stopPropagation(),v(r.path,L)},disabled:k,children:k?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"edit",className:"size-3.5"})}):null,e[85]=L,e[86]=r.path,e[87]=k,e[88]=v,e[89]=y,e[90]=D,e[91]=Fe):Fe=e[91];const we=le?"side-by-side":"unified";let Qe;e[92]!==r.path||e[93]!==P?(Qe=He=>{const st=He==="side-by-side"?"side-by-side":"inline";P(r.path,st)},e[92]=r.path,e[93]=P,e[94]=Qe):Qe=e[94];let pe;e[95]!==we||e[96]!==Qe?(pe=s.jsx(eh,{mode:we,onModeChange:Qe,className:"opacity-70"}),e[95]=we,e[96]=Qe,e[97]=pe):pe=e[97];let Oe;e[98]!==Ce||e[99]!==Fe||e[100]!==pe?(Oe=s.jsxs("div",{className:"relative flex items-center gap-2",children:[Ce,Fe,pe]}),e[98]=Ce,e[99]=Fe,e[100]=pe,e[101]=Oe):Oe=e[101];let nt;e[102]!==ke||e[103]!==Se||e[104]!==ee||e[105]!==Oe?(nt=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:ke,className:Se,children:[De,ee,Oe]})}),e[102]=ke,e[103]=Se,e[104]=ee,e[105]=Oe,e[106]=nt):nt=e[106];let Re;e[107]!==L||e[108]!==z||e[109]!==r.deletions||e[110]!==r.insertions||e[111]!==r.path||e[112]!==Q||e[113]!==C||e[114]!==$||e[115]!==le||e[116]!==i?(Re=C&&s.jsxs("div",{className:"relative border border-t-0 border-border/60 bg-background rounded-b-xl overflow-hidden",children:[z?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:z}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>O(l2),children:"Retry"})]}):null,$&&!L&&!z?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"animate-spin"}),"Loading diff…"]}):null,L&&!Q&&r.insertions+r.deletions>Lm?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsxs("div",{className:"typography-ui-label font-semibold text-foreground",children:["Large diff (",r.insertions+r.deletions," changed lines)"]}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:"Rendering may be slow. You can still view the diff by clicking below."}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>W(!0),children:"Render anyway"})]}):null,L&&(Q||r.insertions+r.deletions<=Lm)?s.jsx(e2,{filePath:r.path,diff:L,renderSideBySide:le,wrapLines:i}):null]}),e[107]=L,e[108]=z,e[109]=r.deletions,e[110]=r.insertions,e[111]=r.path,e[112]=Q,e[113]=C,e[114]=$,e[115]=le,e[116]=i,e[117]=Re):Re=e[117];let de;return e[118]!==K||e[119]!==nt||e[120]!==Re?(de=s.jsxs("div",{ref:K,className:"scroll-mt-4",children:[nt,Re]}),e[118]=K,e[119]=nt,e[120]=Re,e[121]=de):de=e[121],de}),eg=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:a=!1})=>{const{t:i}=mt(),{git:o,files:c}=_n(),d=Lr(),{screenWidth:p,isMobile:m}=an(),u=Rd(d??null),f=Dl(d??null),b=Ld(d??null),h=nn(ee=>ee.setActiveDirectory),v=nn(ee=>ee.ensureStatus),x=nn(ee=>ee.fetchStatus),g=nn(ee=>ee.setDiff),[w,y]=l.useState(null),[k,D]=l.useState(null),[j,S]=l.useState(0),[A,E]=l.useState(null),[P,C]=l.useState(0),[N,T]=l.useState(null),M=l.useRef(null),R=Te(ee=>ee.pendingDiffFile),O=Te(ee=>ee.setPendingDiffFile),z=Te(ee=>ee.diffLayoutPreference),B=Te(ee=>ee.diffFileLayout),$=Te(ee=>ee.setDiffFileLayout),_=Te(ee=>ee.diffWrapLines),Q=Te(ee=>ee.setDiffWrapLines),W=Te(ee=>ee.diffViewMode),ne=Te(ee=>ee.setDiffViewMode),re=Te(ee=>ee.openContextFileAtLine),ue=_,Y=W==="stacked",le=m||p<=768,J=!t&&!le&&p>=1024,L=l.useRef(null),V=l.useRef(new Map),K=l.useRef(null),X=l.useRef(null),U=l.useRef(!1);l.useEffect(()=>{if(!r||!Y||!A)return;const ee=L.current;if(!ee)return;let Ce=null,Fe=!1,we=0;const Qe=Date.now()+1200;let pe=0;const Oe=()=>{Fe||(Fe=!0,E(null))},nt=()=>{Oe()},Re=()=>{if(pe>0){pe-=1;return}Oe()};window.addEventListener("wheel",nt,{passive:!0,capture:!0}),window.addEventListener("touchstart",nt,{passive:!0,capture:!0}),window.addEventListener("pointerdown",nt,{capture:!0}),window.addEventListener("keydown",nt,{capture:!0}),ee.addEventListener("scroll",Re,{passive:!0});const de=()=>{if(Fe||Date.now()>Qe){Oe();return}const He=L.current,st=V.current.get(A);if(!He||!st){Oe();return}const qe=He.getBoundingClientRect(),rt=st.getBoundingClientRect().top-qe.top;if(Math.abs(rt)<=1){if(we+=1,we>=2){Oe();return}}else{we=0;const xe=Math.max(0,He.scrollHeight-He.clientHeight),Ye=Math.min(xe,Math.max(0,He.scrollTop+rt));if(Math.abs(Ye-He.scrollTop)<=.5){Oe();return}pe+=1,He.scrollTop=Ye}Ce=window.requestAnimationFrame(de)};return Ce=window.requestAnimationFrame(de),()=>{Fe=!0,Ce!==null&&window.cancelAnimationFrame(Ce),window.removeEventListener("wheel",nt,!0),window.removeEventListener("touchstart",nt,!0),window.removeEventListener("pointerdown",nt,!0),window.removeEventListener("keydown",nt,!0),ee.removeEventListener("scroll",Re)}},[Y,r,A]);const ae=l.useMemo(()=>{if(!f?.files)return[];const ee=f.diffStats??{};return f.files.map(Ce=>({...Ce,insertions:ee[Ce.path]?.insertions??0,deletions:ee[Ce.path]?.deletions??0,isNew:KN(Ce)})).sort((Ce,Fe)=>Ce.path.localeCompare(Fe.path))},[f]),ve=l.useMemo(()=>w?ae.find(ee=>ee.path===w)??null:null,[ae,w]),ie=l.useCallback(ee=>{const Ce=B[ee.path];if(Ce)return Ce;if(z==="inline")return"inline";if(z==="side-by-side")return"side-by-side";const Fe=p<_N;return ee.isNew||Fe?"inline":"side-by-side"},[B,z,p]),fe=l.useMemo(()=>ve?ie(ve):null,[ie,ve]);l.useEffect(()=>{d&&(h(d),v(d,o))},[d,h,v,o]),l.useEffect(()=>{if(d)return Nr.onGitRefreshHint(ee=>{Om(ee.directory)===Om(d)&&x(d,o)})},[d,x,o]),l.useEffect(()=>{R&&(y(R),O(null),Y&&(U.current=!0,K.current=R,D(R),S(ee=>ee+1)))},[Y,R,O]),l.useEffect(()=>{!w&&!R&&ae.length>0&&y(ae[0].path)},[ae,w,R]),l.useEffect(()=>{w&&ae.length>0&&(ae.some(Ce=>Ce.path===w)||y(ae[0]?.path??null))},[ae,w]);const H=l.useCallback((ee,Ce)=>{const Fe=V.current;Ce?Fe.set(ee,Ce):Fe.delete(ee)},[]),ce=l.useCallback(ee=>{const Ce=V.current.get(ee),Fe=L.current;if(!Ce||!Fe)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const we=Fe.getBoundingClientRect(),pe=Ce.getBoundingClientRect().top-we.top,Oe=Math.max(0,Fe.scrollHeight-Fe.clientHeight),nt=Fe.scrollTop+pe,Re=Math.min(Oe,Math.max(0,nt)),de=Math.abs(Re-Fe.scrollTop)>.5;Fe.scrollTop=Re;const He=Math.abs(pe)<=1,st=Re<=.5||Re>=Oe-.5;return{ok:!0,aligned:He,didMove:de,atScrollLimit:st,delta:pe}},[]);l.useEffect(()=>{if(!Y){K.current=null,U.current=!1,X.current!==null&&(window.cancelAnimationFrame(X.current),X.current=null);return}if(!K.current)return;let Ce=0;const Fe=120;let we=!1,Qe=0,pe=!1,Oe=0;const nt=Date.now()+2e3,Re=()=>{pe||(pe=!0,window.removeEventListener("wheel",He,!0),window.removeEventListener("touchstart",He,!0),window.removeEventListener("pointerdown",He,!0),window.removeEventListener("keydown",He,!0),qe?.removeEventListener("scroll",st))},de=()=>{we||(we=!0,Re(),K.current=null,U.current=!1,X.current!==null&&(window.cancelAnimationFrame(X.current),X.current=null))},He=()=>{de()},st=()=>{if(Qe>0){Qe-=1;return}de()},qe=L.current;window.addEventListener("wheel",He,{passive:!0,capture:!0}),window.addEventListener("touchstart",He,{passive:!0,capture:!0}),window.addEventListener("pointerdown",He,{capture:!0}),window.addEventListener("keydown",He,{capture:!0}),qe?.addEventListener("scroll",st,{passive:!0});const et=()=>{if(Date.now()>nt){de(),X.current=null;return}if(we){X.current=null;return}const rt=K.current;if(!rt){de(),X.current=null;return}Qe+=1;const xe=ce(rt);if(!xe.ok){Qe=Math.max(0,Qe-1),Ce+=1,Ce<Fe?X.current=window.requestAnimationFrame(et):(de(),X.current=null);return}if(!xe.aligned){if(Ce+=1,xe.didMove){if(Oe=0,Ce<Fe){X.current=window.requestAnimationFrame(et);return}}else if(Oe+=1,Oe<6&&(xe.atScrollLimit||Math.abs(xe.delta)>1)){X.current=window.requestAnimationFrame(et);return}}r&&U.current&&E(rt),de()};return X.current=window.requestAnimationFrame(et),()=>{we=!0,Re(),X.current!==null&&(window.cancelAnimationFrame(X.current),X.current=null)}},[Y,r,ce,w,j]);const se=l.useCallback(ee=>{y(ee)},[]),oe=l.useCallback(ee=>{if(X.current!==null&&(window.cancelAnimationFrame(X.current),X.current=null),K.current=null,y(ee),!Y){U.current=!1;return}U.current=!0,K.current=ee,ce(ee)},[Y,ce]),te=l.useCallback(ee=>{ne(ee),ee==="stacked"&&w&&(ce(w).aligned||(K.current=w))},[ce,w,ne]),ke=l.useCallback(ee=>{const Ce=ee==="side-by-side"?"side-by-side":"inline";if(Y){ae.forEach(Fe=>{$(Fe.path,Ce)});return}ve&&$(ve.path,Ce)},[ae,Y,ve,$]),Ne=(fe??"side-by-side")==="side-by-side",je=!n&&(!Y||!J),Se=nn(l.useCallback(ee=>!d||!w?null:ee.directories.get(d)?.diffCache.get(w)??null,[d,w])),De=l.useMemo(()=>Se?{original:Se.original,modified:Se.modified,isBinary:Se.isBinary}:null,[Se]),[ye,ge]=l.useState(null),Me=l.useCallback(async(ee,Ce)=>{if(!(!d||!ee)){ge(ee);try{let Fe=null;if(Ce&&!Ce.isBinary&&!fi(ee)&&(Fe=$m(Ce.original,Ce.modified)),Fe===null)try{const nt=await o.getGitDiff(d,{path:ee,contextLines:3});Fe=qN(nt.diff)}catch{Fe=null}let we=Ce;if(Fe===null||!we){const nt=await o.getGitFileDiff(d,{path:ee});we={original:nt.original??"",modified:nt.modified??"",isBinary:nt.isBinary},g(d,ee,we)}const Qe=Fe??(we.isBinary||fi(ee)?1:$m(we.original,we.modified)),pe=GN(d,ee),Oe=await Xd(c,pe);if(!Oe.ok){G.error(Zd(Oe.reason));return}re(d,pe,Qe,1)}finally{ge(Fe=>Fe===ee?null:Fe)}}},[d,c,o,re,g]),Ue=l.useCallback(async()=>{w&&await Me(w,De)},[Me,De,w]),q=!!(w&&ye===w),Ie=!!Se,Le=!Y&&!!w&&!Ie;l.useEffect(()=>{if(Y)return;if(T(null),!d||!w){M.current=null;return}if(Se){M.current=null;return}const ee=`${d}::${w}::${P}`;if(M.current===ee)return;M.current=ee;let Ce=!1;const Fe=o.getGitFileDiff(d,{path:w}),we=dd,Qe=new Promise((pe,Oe)=>{setTimeout(()=>Oe(new Error(`Timed out after ${we}ms`)),we)});return Promise.race([Fe,Qe]).then(pe=>{Ce||g(d,w,{original:pe.original??"",modified:pe.modified??"",isBinary:pe.isBinary})}).catch(pe=>{if(Ce)return;const Oe=pe instanceof Error?pe.message:String(pe);T(Oe)}),()=>{Ce=!0,M.current===ee&&(M.current=null)}},[d,Y,w,Se,o,g,P]);const Pe=()=>!d||!w||!De?null:s.jsx(t2,{filePath:w,diff:De,isVisible:!0,renderSideBySide:Ne,wrapLines:ue},w),he=()=>{if(!d)return null;const ee=VN(ae.length);return s.jsxs("div",{className:"flex flex-1 min-h-0 h-full gap-3 px-3 pb-3 pt-2",children:[J&&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:i("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:ae.length})]}),s.jsx(QN,{changedFiles:ae,selectedFile:w,onSelectFile:oe})]}),s.jsx(Es,{ref:L,outerClassName:"flex-1 min-h-0 h-full",className:"pr-2",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx("div",{className:"flex flex-col gap-3",children:ae.map((Ce,Fe)=>s.jsx(s2,{directory:d,file:Ce,layout:ie(Ce),wrapLines:ue,scrollRootRef:L,isSelected:Ce.path===w,onSelect:se,registerSectionRef:H,defaultCollapsed:e?!0:Fe>=ee,expandRequestPath:k,expandRequestNonce:j,showOpenInEditorAction:a,isOpeningInEditor:ye===Ce.path,onOpenInEditor:(we,Qe)=>{Me(we,Qe)}},Ce.path))})})]})},F=()=>d?b&&!f?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:"animate-spin"}),i("diffView.state.loadingRepositoryStatus")]}):u===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.notGitRepository")}):ae.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.cleanWorkingTree")}):Y?he():s.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden px-3 py-3 relative","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:[Pe(),Le&&!Ie&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted-foreground",children:N?s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:i("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:N}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>{T(null),C(ee=>ee+1)},children:i("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"animate-spin"}),i("diffView.state.loadingDiff")]})})]}):s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 bg-background",children:[!m&&s.jsxs("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:[s.jsx(I,{name:"git-commit",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:b&&!f?i("diffView.state.loadingChanges"):ae.length===1?i("diffView.summary.changedFilesSingle",{count:ae.length}):i("diffView.summary.changedFilesPlural",{count:ae.length})})]}),!le&&s.jsx(JN,{mode:W,onModeChange:te}),je&&s.jsx(YN,{changedFiles:ae,selectedFile:w,selectedFileEntry:ve,onSelectFile:oe,isMobile:le,showModeSelector:le,mode:W,onModeChange:te}),s.jsx("div",{className:"flex-1"}),ve&&s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>Q(!_),className:me("h-5 w-5 p-0 transition-opacity",ue?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:i(ue?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(I,{name:"text-wrap",className:"size-4"})}),a&&ve&&!Y&&s.jsx(be,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{Ue()},disabled:q,title:i("diffView.actions.openFileAtFirstChangedLine"),children:q?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"edit",className:"size-3.5"})}),ve&&fe&&s.jsx(eh,{mode:fe==="side-by-side"?"side-by-side":"unified",onModeChange:ke})]}),F()]})},n2=()=>{const t=at.c(6),{git:e}=_n(),n=Lr(),r=nn(c2),a=nn(d2),i=Ib(n??null);let o,c;return t[0]!==n||t[1]!==a||t[2]!==e||t[3]!==r?(o=()=>{n&&(r(n),a(n,e))},c=[n,r,a,e],t[0]=n,t[1]=a,t[2]=e,t[3]=r,t[4]=o,t[5]=c):(o=t[4],c=t[5]),l.useEffect(o,c),i};function r2(t){return t.setDiff}function a2(t){return t.setDiffFileLayout}function i2(t){return t.isIntersecting}function o2(t,e){setTimeout(()=>e(new Error(`Timed out after ${dd}ms`)),dd)}function l2(t){return t+1}function c2(t){return t.setActiveDirectory}function d2(t){return t.ensureStatus}const u2=Object.freeze(Object.defineProperty({__proto__:null,DiffView:eg,useDiffFileCount:n2},Symbol.toStringTag,{value:"Module"})),m2={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},p2={case:"Match case",re:"Regular expression",word:"Match whole word"};function f2(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(m2)){const a=e.querySelector(`button[name="${n}"]`);a&&!a.title&&(a.title=r)}for(const[n,r]of Object.entries(p2)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=r)}}}const Bm=new wi,zm=new wi,_m=new wi,Vm=new wi,Um=new wi,Wm=new wi,Km=t=>t,vc=gx,h2=xx,g2=bx;class x2 extends yx{constructor(e,n){super(),this.id=e,this.containerMap=n}toDOM(){let e=this.containerMap.get(this.id);return e||(e=document.createElement("div"),e.className="oc-block-widget",e.dataset.widgetId=this.id,this.containerMap.set(this.id,e)),e}eq(e){return e.id===this.id}destroy(){}}const Hm=(t,e)=>!t||t.length===0?[]:hx.define({create(n){const r=new Lf,a=[...t].sort((i,o)=>i.afterLine-o.afterLine);for(const i of a){const o=n.doc.lines;if(i.afterLine>o)continue;const c=n.doc.line(i.afterLine);r.add(c.to,c.to,Of.widget({widget:new x2(i.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>tr.decorations.from(n)}),Gm=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return fx.fromClass(class{decorations;constructor(r){this.decorations=this.build(r)}update(r){(r.docChanged||r.viewportChanged)&&(this.decorations=this.build(r.view))}build(r){const a=new Lf;for(let i=e;i<=n&&i<=r.state.doc.lines;i+=1){const o=r.state.doc.line(i);a.add(o.from,o.from,Of.line({class:"oc-cm-selected-line"}))}return a.finish()}},{decorations:r=>r.decorations})};function ud({value:t,onChange:e,extensions:n,className:r,readOnly:a,lineNumbersConfig:i,highlightLines:o,onViewReady:c,onViewDestroy:d,blockWidgets:p,enableSearch:m,searchOpen:u,onSearchOpenChange:f}){const b=l.useRef(null),h=l.useRef(null),v=l.useRef(t),x=l.useRef(e),g=l.useRef(c),w=l.useRef(d),y=l.useRef(f),k=l.useRef(p),D=l.useRef(new Map),[j,S]=l.useState([]),A=l.useCallback(P=>{const C=(P??[]).map(N=>{const T=D.current.get(N.id);return T?{id:N.id,content:N.content,container:T}:null}).filter(N=>N!==null);S(N=>N.length===C.length&&N.every((T,M)=>{const R=C[M];return T.id===R.id&&T.content===R.content&&T.container===R.container})?N:C)},[]),E=l.useCallback(P=>{const C=b.current,N=P??h.current;if(!C||!N)return;const T=N.dom.querySelector(".cm-gutters"),M=T instanceof HTMLElement?T.getBoundingClientRect().width:0;C.style.setProperty("--oc-editor-gutter-width",`${M}px`)},[]);return l.useEffect(()=>{v.current=t},[t]),l.useEffect(()=>{x.current=e},[e]),l.useEffect(()=>{g.current=c,w.current=d},[c,d]),l.useEffect(()=>{y.current=f},[f]),l.useEffect(()=>{k.current=p,A(p)},[p,A]),l.useEffect(()=>{if(!b.current)return;const P=(()=>{if(typeof document>"u")return null;const N=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(N)return N;const T=window.__OPENCHAMBER_CSP_NONCE__;return typeof T=="string"&&T.length>0?T:null})(),C=ox.create({doc:v.current,extensions:[...P?[tr.cspNonce.of(P)]:[],lx({fixed:!0}),Bm.of(du(i)),cx(),dx.of(" "),Hl.of([ux,...mx,...px]),tr.updateListener.of(N=>{E(N.view),(N.viewportChanged||N.geometryChanged)&&A(k.current);const T=uu(N.startState),M=uu(N.state);if(T!==M&&y.current?.(M),!N.docChanged)return;const R=N.state.doc.toString();v.current=R,x.current(R),A(k.current)}),zm.of(tr.editable.of(!a)),_m.of(n??[]),Vm.of(Gm(o)),Um.of(Hm(p,D.current)),Wm.of(m?[mu({top:!0}),Hl.of(Km(pu))]:[])]});return h.current=new tr({state:C,parent:b.current}),vc(h.current,h.current.state.doc.length,200),h.current.requestMeasure(),requestAnimationFrame(()=>{E(h.current),A(k.current)}),h.current&&g.current?.(h.current),()=>{w.current?.(),h.current?.destroy(),h.current=null,S([])}},[k,E,A]),l.useEffect(()=>{const P=h.current;P&&(P.dispatch({effects:[Bm.reconfigure(du(i)),zm.reconfigure(tr.editable.of(!a)),_m.reconfigure(n??[]),Vm.reconfigure(Gm(o)),Um.reconfigure(Hm(p,D.current)),Wm.reconfigure(m?[mu({top:!0}),Hl.of(Km(pu))]:[])]}),vc(P,P.state.doc.length,200),P.requestMeasure(),requestAnimationFrame(()=>{E(P),A(k.current)}))},[n,o,i,a,p,m,E,A]),l.useEffect(()=>{const P=h.current;!P||m===!1||(u?(h2(P),requestAnimationFrame(()=>{f2(P.dom)})):g2(P))},[u,m]),l.useEffect(()=>{const P=h.current;if(!P)return;const C=P.state.doc.toString();C!==t&&(P.dispatch({changes:{from:0,to:C.length,insert:t}}),vc(P,P.state.doc.length,300),P.requestMeasure(),requestAnimationFrame(()=>E(P)))},[t,E]),s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:b,className:me("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",r)}),j.map(P=>Bi.createPortal(P.content,P.container,P.id))]})}const b2=(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)},qm=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},Ym=(t,e,n)=>{const r=t.state.doc.line(e),a=Math.max(1,Math.min(n,r.length+1)),i=r.from+a-1;t.dispatch({selection:vx.cursor(i),effects:tr.scrollIntoView(i,{y:"center"})})};function y2({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:a}=mt(),[i,o]=l.useState(""),c=l.useRef(null),d=l.useRef(!1),p=l.useRef(null),m=l.useRef(null),u=l.useMemo(()=>b2(i,n),[i,n]);l.useEffect(()=>{!t||!n||(d.current=!1,c.current=qm(n,n.state.selection),o(""))},[t,n]),l.useEffect(()=>{t&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[t]),l.useEffect(()=>{if(!(!t||!n||!c.current)){if(u===null){const{selection:x}=c.current;n.dispatch({selection:x,effects:tr.scrollIntoView(x.main.from,{y:"center"})});return}Ym(n,u,c.current.character)}},[u,t,n]);const f=l.useCallback(()=>{if(!n||d.current||!c.current)return;const{selection:x}=c.current;n.dispatch({selection:x,effects:tr.scrollIntoView(x.main.from,{y:"center"})})},[n]),b=l.useCallback(x=>{x||f(),e(x)},[e,f]),h=l.useCallback(()=>{!n||u===null||!c.current||(d.current=!0,Ym(n,u,c.current.character),e(!1),n.focus())},[u,e,n]);l.useEffect(()=>{if(!t)return;const x=w=>{const y=p.current,k=w.target;!y||!(k instanceof Node)||y.contains(k)||b(!1)},g=w=>{w.key==="Escape"&&(w.preventDefault(),b(!1))};return document.addEventListener("pointerdown",x,!0),document.addEventListener("keydown",g,!0),()=>{document.removeEventListener("pointerdown",x,!0),document.removeEventListener("keydown",g,!0)}},[b,t,r]);const v=l.useMemo(()=>{if(!n)return a("goToLineDialog.helper.editorUnavailable");if(u===null){const x=c.current??qm(n,n.state.selection);return a("goToLineDialog.helper.currentLineRange",{current:x.lineNumber,max:n.state.doc.lines})}return a("goToLineDialog.helper.goToLine",{line:u})},[u,a,n]);return r==="inline"?t?s.jsxs("div",{ref:p,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(Wt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),h())},placeholder:a("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(be,{variant:"outline",size:"xs",onClick:h,disabled:!n||u===null,className:"h-6 px-2",children:a("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:p,className:me("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(Wt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),h())},placeholder:a("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:v})]})})}const md=t=>{const e=at.c(11),{currentMode:n,onToggle:r}=t,a=n==="preview",i=a?"Switch to edit mode":"Switch to preview mode",o=a?"Edit":"Preview";let c;e[0]!==a?(c=a?s.jsx(I,{name:"eye",className:"size-4","aria-hidden":"true"}):s.jsx(I,{name:"eye-off",className:"size-4","aria-hidden":"true"}),e[0]=a,e[1]=c):c=e[1];let d;e[2]!==i||e[3]!==r||e[4]!==c?(d=s.jsx(Pt,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",onClick:r,"aria-label":i,className:"h-5 w-5 p-0",children:c})}),e[2]=i,e[3]=r,e[4]=c,e[5]=d):d=e[5];let p;e[6]!==o?(p=s.jsx(At,{sideOffset:8,children:o}),e[6]=o,e[7]=p):p=e[7];let m;return e[8]!==d||e[9]!==p?(m=s.jsxs(It,{children:[d,p]}),e[8]=d,e[9]=p,e[10]=m):m=e[10],m},pd=wx.define(jx);function v2(t){const e=t.trim().toLowerCase();switch(e){case"bash":case"sh":case"zsh":case"shell":case"shellsession":case"console":return pd;case"json":case"jsonc":case"json5":return zf().language;case"js":case"javascript":return ei().language;case"jsx":return ei({jsx:!0}).language;case"ts":case"typescript":return ei({typescript:!0}).language;case"tsx":return ei({typescript:!0,jsx:!0}).language;case"html":return Gc().language;case"css":return Bf().language;case"py":case"python":return $f().language;case"heex":case"eex":case"leex":return Gc().language;default:return _f.matchLanguageName(Vf,e,!0)}}const tg=t=>t.split("/").pop()?.toLowerCase()??"",w2=t=>{const e=tg(t);return e?_f.matchFilename(Vf,e):null},j2=()=>Ri(qc.define([{tag:[ot.heading1,ot.heading2,ot.heading3,ot.heading4,ot.heading5,ot.heading6],fontWeight:"600"},{tag:ot.strong,fontWeight:"600"},{tag:ot.emphasis,fontStyle:"italic"},{tag:ot.strikethrough,textDecoration:"line-through"},{tag:[ot.link,ot.url],color:"var(--markdown-link, currentColor)",textDecoration:"underline"},{tag:ot.monospace,color:"var(--markdown-inline-code, currentColor)",backgroundColor:"var(--markdown-inline-code-bg, transparent)"},{tag:ot.quote,color:"var(--markdown-blockquote, currentColor)",fontStyle:"italic"},{tag:ot.list,color:"color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)"},{tag:ot.heading,color:"var(--markdown-heading1, currentColor)"}]));function sg(t){const e=t.toLowerCase();switch(tg(e)){case"makefile":case"gnumakefile":return pd}const r=e.lastIndexOf("."),a=r>=0?e.slice(r+1):"";switch(a){case"ts":case"tsx":case"mts":case"cts":return ei({typescript:!0,jsx:a==="tsx"});case"js":case"jsx":case"mjs":case"cjs":return ei({typescript:!1,jsx:a==="jsx"});case"json":case"jsonc":case"json5":case"jsonl":case"ndjson":case"geojson":return zf();case"css":case"scss":case"sass":case"less":return Bf();case"html":case"htm":return Gc();case"md":case"mdx":case"markdown":case"mdown":case"mkd":return[Nx({codeLanguages:v2}),j2()];case"sh":case"bash":case"zsh":case"fish":case"env":return pd;case"py":case"pyw":case"pyi":return $f();default:return null}}async function N2(t){const e=w2(t);if(!e)return null;if(e.support)return e.support;try{return await e.load()}catch{return null}}function fd(t){const e=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",r=t.colors.syntax.highlights||{},a=t.colors.syntax.tokens||{},i=tr.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:"var(--text-code)",lineHeight:"1.5rem",position:"relative"},".cm-scroller":{fontFamily:n,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:a.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:a.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:a.boolean||t.colors.syntax.base.number},".cm-builtin":{color:a.functionCall||t.colors.syntax.base.function},".cm-def":{color:a.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:a.variableOther||a.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:a.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:a.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:a.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:a.tag||t.colors.syntax.base.keyword},".cm-link":{color:a.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:r.lineNumber||t.colors.syntax.base.comment,borderRight:`1px solid ${t.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:r.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${t.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:t.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:t.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:t.colors.interactive.hover,color:t.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:e}),o=qc.define([{tag:[ot.comment,ot.docComment,ot.meta,ot.documentMeta],class:"cm-comment"},{tag:[ot.keyword,ot.controlKeyword,ot.moduleKeyword,ot.definitionKeyword,ot.modifier],class:"cm-keyword"},{tag:[ot.operatorKeyword,ot.operator,ot.derefOperator,ot.updateOperator,ot.definitionOperator,ot.typeOperator,ot.controlOperator,ot.logicOperator,ot.bitwiseOperator,ot.arithmeticOperator,ot.compareOperator],class:"cm-operator"},{tag:[ot.punctuation,ot.separator,ot.bracket,ot.paren,ot.brace,ot.squareBracket,ot.angleBracket],class:"cm-punctuation"},{tag:[ot.string,ot.regexp,ot.attributeValue,ot.special(ot.string),ot.monospace],class:"cm-string"},{tag:ot.escape,class:"cm-string-2"},{tag:[ot.number,ot.bool,ot.atom,ot.null,ot.self],class:"cm-number"},{tag:[ot.function(ot.variableName),ot.function(ot.definition(ot.variableName)),ot.function(ot.propertyName),ot.standard(ot.variableName),ot.special(ot.variableName)],class:"cm-builtin"},{tag:ot.definition(ot.variableName),class:"cm-def"},{tag:[ot.variableName,ot.local(ot.variableName),ot.constant(ot.variableName),ot.literal],class:"cm-variable"},{tag:ot.propertyName,class:"cm-property"},{tag:ot.attributeName,class:"cm-attribute"},{tag:[ot.className,ot.typeName,ot.namespace],class:"cm-variable-3"},{tag:[ot.tagName,ot.labelName,ot.annotation,ot.macroName],class:"cm-tag"},{tag:ot.link,class:"cm-link"},{tag:[ot.heading,ot.heading1,ot.heading2,ot.heading3,ot.heading4,ot.heading5,ot.heading6],class:"cm-keyword"}]),c=qc.define([{tag:[ot.comment,ot.docComment,ot.meta,ot.documentMeta],color:t.colors.syntax.base.comment},{tag:[ot.keyword,ot.controlKeyword,ot.moduleKeyword,ot.definitionKeyword,ot.modifier],color:t.colors.syntax.base.keyword},{tag:[ot.operatorKeyword,ot.operator,ot.derefOperator,ot.updateOperator,ot.definitionOperator,ot.typeOperator,ot.controlOperator,ot.logicOperator,ot.bitwiseOperator,ot.arithmeticOperator,ot.compareOperator],color:t.colors.syntax.base.operator},{tag:[ot.string,ot.regexp,ot.attributeValue,ot.special(ot.string),ot.monospace],color:t.colors.syntax.base.string},{tag:ot.escape,color:a.stringEscape||t.colors.syntax.base.string},{tag:[ot.number,ot.bool,ot.atom,ot.null,ot.self],color:t.colors.syntax.base.number},{tag:[ot.function(ot.variableName),ot.function(ot.definition(ot.variableName)),ot.function(ot.propertyName),ot.standard(ot.variableName),ot.special(ot.variableName)],color:t.colors.syntax.base.function},{tag:ot.definition(ot.variableName),color:a.variableGlobal||t.colors.syntax.base.variable},{tag:[ot.variableName,ot.local(ot.variableName),ot.constant(ot.variableName),ot.literal],color:t.colors.syntax.base.variable},{tag:ot.propertyName,color:a.variableProperty||t.colors.syntax.base.variable},{tag:ot.attributeName,color:a.variableOther||t.colors.syntax.base.variable},{tag:[ot.className,ot.typeName,ot.namespace],color:t.colors.syntax.base.type},{tag:[ot.tagName,ot.labelName,ot.annotation,ot.macroName],color:a.tag||t.colors.syntax.base.keyword},{tag:ot.link,color:a.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[ot.punctuation,ot.separator,ot.bracket,ot.paren,ot.brace,ot.squareBracket,ot.angleBracket],color:a.punctuation||t.colors.syntax.base.comment}]);return[i,Ri(Sx,{fallback:!0}),Ri(kx),Ri(o),Ri(c)]}const S2=t=>{const e=gn(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},k2=t=>{const e=at.c(8),{label:n,iconDataUrl:r}=t,[a,i]=l.useState(!1);let o;e[0]!==n?(o=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=o):o=e[1];const c=o;if(r&&!a){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>i(!0),e[2]=m):m=e[2];let u;return e[3]!==r?(u=s.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=r,e[4]=u):u=e[4],u}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=me("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 p;return e[6]!==c?(p=s.jsx("span",{className:d,children:c}),e[6]=c,e[7]=p):p=e[7],p},C2=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),gn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const a=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!a&&!i&&(r=r.replace(/\/+$/,"")),r},I2=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Jm=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,bl=(t,e)=>{const n=gn(e),r=gn(t);if(!n||!r)return!1;const a=Jm(n),i=Jm(r);return i===a||i.startsWith(`${a}/`)},Qm=(t,e)=>{const n=gn(e),r=gn(t);if(!bl(r,n))return[];const i=r.slice(n.length).replace(/^\//,"").split("/"),o=[];let c=n;for(let d=0;d<i.length-1;d++)c=c?`${c}/${i[d]}`:i[d],o.push(c);return o},hd=(t,e)=>{if(!e)return"";const n=gn(e);if(!t||!bl(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},P2=new Set(["node_modules"]),A2=t=>{const e=at.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 a=r[n];let i;return e[1]!==a?(i=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:a}}),e[1]=a,e[2]=i):i=e[2],i},D2=t=>P2.has(t),T2=t=>{const e=gn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},M2=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},Ai=2e5,ng="openchamber:files:auto-save-enabled",E2=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(ng)!=="false"}catch{return!0}},rg=(t,e)=>s.jsx(jr,{filePath:t,extension:e}),R2=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},F2=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},wc=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},L2=t=>{const e=at.c(62),{node:n,root:r,isExpanded:a,isActive:i,isMobile:o,alwaysShowActions:c,status:d,badge:p,permissions:m,downloadFile:u,contextMenuPath:f,setContextMenuPath:b,onSelect:h,onToggle:v,onRevealPath:x,onOpenDialog:g}=t,{t:w}=mt(),y=n.type==="directory",{canRename:k,canCreateFile:D,canCreateFolder:j,canDelete:S,canReveal:A}=m;let E;e[0]!==D||e[1]!==j||e[2]!==S||e[3]!==k||e[4]!==A||e[5]!==n.path||e[6]!==b?(E=Y=>{!k&&!D&&!j&&!S&&!A||(Y?.preventDefault(),b(n.path))},e[0]=D,e[1]=j,e[2]=S,e[3]=k,e[4]=A,e[5]=n.path,e[6]=b,e[7]=E):E=e[7];const P=E;let C;e[8]!==y||e[9]!==n||e[10]!==h||e[11]!==v?(C=()=>{y?v(n.path):h(n)},e[8]=y,e[9]=n,e[10]=h,e[11]=v,e[12]=C):C=e[12];const N=C;let T;e[13]!==n.path||e[14]!==b?(T=Y=>{Y.stopPropagation(),b(n.path)},e[13]=n.path,e[14]=b,e[15]=T):T=e[15];const M=T,R=o?void 0:P,O=o?void 0:P,z=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let B;e[16]!==z?(B=me("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",z),e[16]=z,e[17]=B):B=e[17];let $;e[18]!==y||e[19]!==a||e[20]!==n.extension||e[21]!==n.path?($=y?a?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"}):rg(n.path,n.extension),e[18]=y,e[19]=a,e[20]=n.extension,e[21]=n.path,e[22]=$):$=e[22];let _;e[23]!==n.name||e[24]!==n.path?(_=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[23]=n.name,e[24]=n.path,e[25]=_):_=e[25];let Q;e[26]!==y||e[27]!==d?(Q=!y&&d&&s.jsx(A2,{status:d}),e[26]=y,e[27]=d,e[28]=Q):Q=e[28];let W;e[29]!==p||e[30]!==y?(W=y&&p&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[p.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",p.modified]}),p.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",p.added]})]}),e[29]=p,e[30]=y,e[31]=W):W=e[31];let ne;e[32]!==N||e[33]!==Q||e[34]!==W||e[35]!==O||e[36]!==B||e[37]!==$||e[38]!==_?(ne=s.jsxs("button",{type:"button",onClick:N,onContextMenu:O,className:B,children:[$,_,Q,W]}),e[32]=N,e[33]=Q,e[34]=W,e[35]=O,e[36]=B,e[37]=$,e[38]=_,e[39]=ne):ne=e[39];let re;e[40]!==c||e[41]!==D||e[42]!==j||e[43]!==S||e[44]!==k||e[45]!==A||e[46]!==f||e[47]!==u||e[48]!==M||e[49]!==y||e[50]!==o||e[51]!==n||e[52]!==g||e[53]!==x||e[54]!==r||e[55]!==b||e[56]!==w?(re=(k||D||j||S||A)&&s.jsx("div",{className:me("absolute right-1 top-1/2 -translate-y-1/2",c?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(_s,{open:f===n.path,onOpenChange:Y=>b(Y?n.path:null),children:[s.jsx(Bs,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"icon",className:"size-6",onClick:M,children:s.jsx(I,{name:"more-2-fill",className:"size-4"})})}),s.jsxs(zs,{align:"end",side:"bottom",onCloseAutoFocus:()=>b(null),children:[k&&s.jsxs(Vt,{onClick:Y=>{Y.stopPropagation(),g("rename",n)},children:[s.jsx(I,{name:"edit",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.rename")]}),s.jsxs(Vt,{onClick:Y=>{Y.stopPropagation(),Rn(n.path).then(le=>{if(le.ok){G.success(w("sidebarFilesTree.toast.pathCopied"));return}G.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.copyPath")]}),s.jsxs(Vt,{onClick:Y=>{Y.stopPropagation();const le=hd(r,n.path)||n.path;Rn(le).then(J=>{if(J.ok){G.success(w("filesView.toast.relativePathCopied"));return}G.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy-2",className:"mr-2 size-4"})," ",w("filesView.tree.menu.copyRelativePath")]}),!y&&u&&s.jsxs(Vt,{onClick:Y=>{Y.stopPropagation(),u(n.path)},children:[s.jsx(I,{name:"download",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.save")]}),A&&s.jsxs(Vt,{onClick:Y=>{Y.stopPropagation(),x(n.path)},children:[s.jsx(I,{name:"folder-received",className:"mr-2 size-4"})," ",w(Bd())]}),y&&(D||j)&&s.jsxs(s.Fragment,{children:[s.jsx(Tn,{}),D&&s.jsxs(Vt,{onClick:Y=>{Y.stopPropagation(),g("createFile",n)},children:[s.jsx(I,{name:"file-add",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.newFile")]}),j&&s.jsxs(Vt,{onClick:Y=>{Y.stopPropagation(),g("createFolder",n)},children:[s.jsx(I,{name:"folder-add",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.newFolder")]})]}),S&&s.jsxs(s.Fragment,{children:[s.jsx(Tn,{}),s.jsxs(Vt,{onClick:Y=>{Y.stopPropagation(),g("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=c,e[41]=D,e[42]=j,e[43]=S,e[44]=k,e[45]=A,e[46]=f,e[47]=u,e[48]=M,e[49]=y,e[50]=o,e[51]=n,e[52]=g,e[53]=x,e[54]=r,e[55]=b,e[56]=w,e[57]=re):re=e[57];let ue;return e[58]!==ne||e[59]!==re||e[60]!==R?(ue=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:R,children:[ne,re]}),e[58]=ne,e[59]=re,e[60]=R,e[61]=ue):ue=e[61],ue},O2=t=>{const e=at.c(83),{activeDialog:n,dialogData:r,dialogInputValue:a,onDialogInputChange:i,isDialogSubmitting:o,onDialogSubmit:c,onClose:d,inputRef:p}=t,{t:m}=mt(),u=!!n;let f;e[0]!==d?(f=$=>!$&&d(),e[0]=d,e[1]=f):f=e[1];let b;e[2]!==n||e[3]!==m?(b=n==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=n,e[3]=m,e[4]=b):b=e[4];let h;e[5]!==n||e[6]!==m?(h=n==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=n,e[6]=m,e[7]=h):h=e[7];let v;e[8]!==n||e[9]!==m?(v=n==="rename"&&m("filesView.dialog.rename.title"),e[8]=n,e[9]=m,e[10]=v):v=e[10];let x;e[11]!==n||e[12]!==m?(x=n==="delete"&&m("filesView.dialog.delete.title"),e[11]=n,e[12]=m,e[13]=x):x=e[13];let g;e[14]!==b||e[15]!==h||e[16]!==v||e[17]!==x?(g=s.jsxs(Ss,{children:[b,h,v,x]}),e[14]=b,e[15]=h,e[16]=v,e[17]=x,e[18]=g):g=e[18];let w;e[19]!==n||e[20]!==r?.path||e[21]!==m?(w=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]=w):w=e[22];let y;e[23]!==n||e[24]!==r?.path||e[25]!==m?(y=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]=y):y=e[26];let k;e[27]!==n||e[28]!==r?.name||e[29]!==m?(k=n==="rename"&&m("filesView.dialog.rename.description",{name:r?.name??""}),e[27]=n,e[28]=r?.name,e[29]=m,e[30]=k):k=e[30];let D;e[31]!==n||e[32]!==r?.name||e[33]!==m?(D=n==="delete"&&m("filesView.dialog.delete.description",{name:r?.name??""}),e[31]=n,e[32]=r?.name,e[33]=m,e[34]=D):D=e[34];let j;e[35]!==k||e[36]!==D||e[37]!==w||e[38]!==y?(j=s.jsxs(Fs,{children:[w,y,k,D]}),e[35]=k,e[36]=D,e[37]=w,e[38]=y,e[39]=j):j=e[39];let S;e[40]!==j||e[41]!==g?(S=s.jsxs(As,{children:[g,j]}),e[40]=j,e[41]=g,e[42]=S):S=e[42];let A;e[43]!==n||e[44]!==a||e[45]!==p||e[46]!==i||e[47]!==c||e[48]!==m?(A=n!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Wt,{value:a,onChange:$=>i($.target.value),placeholder:m(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:$=>{$.key==="Enter"&&c()},ref:p})}),e[43]=n,e[44]=a,e[45]=p,e[46]=i,e[47]=c,e[48]=m,e[49]=A):A=e[49];let E;e[50]!==m?(E=m("filesView.dialog.cancel"),e[50]=m,e[51]=E):E=e[51];let P;e[52]!==o||e[53]!==d||e[54]!==E?(P=s.jsx(be,{variant:"outline",onClick:d,disabled:o,children:E}),e[52]=o,e[53]=d,e[54]=E,e[55]=P):P=e[55];const C=n==="delete"?"destructive":"default";let N;e[56]!==c?(N=()=>{c()},e[56]=c,e[57]=N):N=e[57];let T;e[58]!==n||e[59]!==a||e[60]!==o?(T=o||n!=="delete"&&!a.trim(),e[58]=n,e[59]=a,e[60]=o,e[61]=T):T=e[61];let M;e[62]!==n||e[63]!==o||e[64]!==m?(M=o?s.jsx(I,{name:"loader-4",className:"animate-spin"}):m(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=o,e[64]=m,e[65]=M):M=e[65];let R;e[66]!==C||e[67]!==N||e[68]!==T||e[69]!==M?(R=s.jsx(be,{variant:C,onClick:N,disabled:T,children:M}),e[66]=C,e[67]=N,e[68]=T,e[69]=M,e[70]=R):R=e[70];let O;e[71]!==P||e[72]!==R?(O=s.jsxs(Hs,{children:[P,R]}),e[71]=P,e[72]=R,e[73]=O):O=e[73];let z;e[74]!==p||e[75]!==S||e[76]!==A||e[77]!==O?(z=s.jsxs(ys,{initialFocus:p,children:[S,A,O]}),e[74]=p,e[75]=S,e[76]=A,e[77]=O,e[78]=z):z=e[78];let B;return e[79]!==u||e[80]!==f||e[81]!==z?(B=s.jsx(vs,{open:u,onOpenChange:f,children:z}),e[79]=u,e[80]=f,e[81]=z,e[82]=B):B=e[82],B},ag=({mode:t="full"})=>{const{t:e}=mt(),{files:n,runtime:r}=_n(),{currentTheme:a,availableThemes:i,lightThemeId:o,darkThemeId:c}=Cr(),{isMobile:d,isTablet:p,screenWidth:m}=an(),u=d||p,f=Tl(),b=Od(),h=Lr()??"",v=gn(h.trim()),x=d||t!=="editor-only",g=t==="editor-only"&&!d,w=$d(Ae=>Ae.searchFiles),y=Dl(h),[k,D]=l.useState(""),j=Ml(k,200),S=l.useRef(null),[A,E]=l.useState(!1),[P,C]=l.useState(!0),[N,T]=l.useState(!1),[M,R]=l.useState(!1),[O,z]=l.useState(!1),B=l.useRef(null),$=l.useRef(0),_=l.useCallback(Ae=>{$.current=Math.max(0,$.current+(Ae?1:-1))},[]),Q=l.useCallback(Ae=>Ae instanceof Element?Ae.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);l.useEffect(()=>{if(!O)return;const Ae=Xe=>{$.current>0||Q(Xe.target)||B.current&&!B.current.contains(Xe.target)&&z(!1)};return document.addEventListener("mousedown",Ae),()=>document.removeEventListener("mousedown",Ae)},[Q,O]);const[W,ne]=l.useState("edit"),[re,ue]=l.useState("edit"),[Y,le]=l.useState("tree"),[J,L]=l.useState("edit"),V=l.useRef({}),K=l.useRef({}),X=l.useRef({}),U=l.useMemo(()=>i.find(Ae=>Ae.metadata.id===o)??ui(!1),[i,o]),ae=l.useMemo(()=>i.find(Ae=>Ae.metadata.id===c)??ui(!0),[i,c]);l.useEffect(()=>{mi(U),mi(ae)},[U,ae]);const ve=l.useMemo(()=>[],[]),ie=Bn(Ae=>v?Ae.byRoot[v]?.openPaths??ve:ve),fe=Bn(Ae=>v?Ae.byRoot[v]?.selectedPath??null:null),H=Bn(Ae=>v?Ae.byRoot[v]?.expandedPaths??ve:ve),ce=Bn(Ae=>Ae.addOpenPath),se=Bn(Ae=>Ae.removeOpenPath),oe=Bn(Ae=>Ae.removeOpenPathsByPrefix),te=Bn(Ae=>Ae.setSelectedPath),ke=Bn(Ae=>Ae.toggleExpandedPath),Ne=Bn(Ae=>Ae.expandPaths),je=l.useCallback(Ae=>{const Xe=gn(Ae),ut=Xe.split("/"),ht=ut[ut.length-1]||Xe,Ot=ht.includes(".")?ht.split(".").pop()?.toLowerCase():void 0;return{name:ht,path:Xe,type:"file",extension:Ot}},[]),Se=l.useMemo(()=>ie.map(je),[ie,je]),De=l.useMemo(()=>fe??ie[0]??null,[ie,fe]),ye=l.useMemo(()=>De?je(De):null,[De,je]),ge=ye?.path??"",Me=!!(v&&ge&&!bl(ge,v)),Ue=l.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&Me}),[t,Me]),q=l.useRef(null),[Ie,Le]=l.useState({left:!1,right:!1}),Pe=l.useCallback(()=>{const Ae=q.current;Ae&&Le({left:Ae.scrollLeft>2,right:Ae.scrollLeft+Ae.clientWidth<Ae.scrollWidth-2})},[]),he=l.useRef(Pe);he.current=Pe,l.useEffect(()=>{const Ae=q.current;if(!Ae)return;const Xe=()=>he.current();Xe(),Ae.addEventListener("scroll",Xe,{passive:!0});const ut=new ResizeObserver(Xe);return ut.observe(Ae),()=>{Ae.removeEventListener("scroll",Xe),ut.disconnect()}},[Se.length]);const[F,ee]=l.useState({}),Ce=l.useRef(new Set),Fe=l.useRef(new Set),we=l.useRef(new Map),Qe=l.useRef(0),[pe,Oe]=l.useState([]),[nt,Re]=l.useState(!1),[de,He]=l.useState(""),[st,qe]=l.useState(!1),[et,rt]=l.useState(null),[xe,Ye]=l.useState(""),[_e,We]=l.useState(null),[lt,Je]=l.useState(""),[Ve,yt]=l.useState(!1),$t=l.useRef(null),Gt=l.useRef(null),ss=l.useRef(null),wt=l.useRef(0),[Dt,Xt]=l.useState("idle"),[Yt,ts]=l.useState(E2),[dt,Rt]=l.useState(!1),is=l.useRef(null),xs=l.useRef(null),ps=l.useRef(null),ws=l.useRef(!1),qt=l.useRef(null),Ge=l.useRef(null),St=l.useRef(null),Mt=l.useRef(null),[Nt,Kt]=l.useState(0),ns=l.useRef(null),js=l.useRef({key:"",attempts:0});l.useEffect(()=>()=>{ns.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(ns.current),ns.current=null)},[]);const[ls,ks]=l.useState(null),[Os,xt]=l.useState(null),[cs,jt]=l.useState(""),[Tt,Z]=l.useState(!1),[ft,kt]=l.useState(null),[Ht,Ns]=l.useState(!1),[Cs,Ke]=l.useState(!1),[bt,Ct]=l.useState(!1),Ft=!!n.writeFile,Zt=!!n.createDirectory,it=!!n.rename,zt=!!n.delete,hs=!!n.revealPath,Jt=Dr(Ae=>Ae.availableApps),Ut=Dr(Ae=>Ae.isCacheStale),os=Dr(Ae=>Ae.initialize),tn=Dr(Ae=>Ae.loadInstalledApps);l.useEffect(()=>{os()},[os]);const Zs=l.useCallback(Ae=>{n.revealPath&&n.revealPath(Ae).catch(()=>{G.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),nr=l.useCallback(async Ae=>{if(!ye?.path||await Pb(ye.path,Ae.id,Ae.appName)||await rl(ye.path,Ae.appName))return;const ht=S2(ye.path)||v;ht&&await rl(ht,Ae.appName)||G.error(e("filesView.toast.openInAppFailed",{app:Ae.appName}))},[v,ye?.path,e]),Vn=l.useCallback((Ae,Xe)=>{ks(Ae),xt(Xe),jt(Ae==="rename"&&Xe.name||""),Z(!1)},[]),[Ds,on]=l.useState(null),en=l.useRef(!1),mn=l.useRef(null),[Sn,Fn]=l.useState(!1),Mn=Te(Ae=>Ae.setMainTabGuard),cn=Te(Ae=>Ae.pendingFileNavigation),kn=Te(Ae=>Ae.setPendingFileNavigation),Cn=Te(Ae=>Ae.pendingFileFocusPath),Be=Te(Ae=>Ae.setPendingFileFocusPath),Et=Te(Ae=>Ae.shortcutOverrides),rs=gt(Ae=>Ae.settingsDefaultFileViewerPreview);l.useEffect(()=>{const Ae=()=>{en.current=!1,mn.current=null,Fn(!1)};return document.addEventListener("mouseup",Ae),()=>document.removeEventListener("mouseup",Ae)},[]),l.useEffect(()=>()=>{qt.current!==null&&window.clearTimeout(qt.current),Ge.current!==null&&window.clearTimeout(Ge.current)},[]);const gs=l.useCallback((Ae,Xe)=>{const ut=Ae.split(`
|
|
48
|
+
`),ht=Math.max(1,Xe.start),Ot=Math.min(ut.length,Xe.end);return ht>Ot?"":ut.slice(ht-1,Ot).join(`
|
|
49
|
+
`)},[]),Ys=qd({source:"file",fileLabel:ye?.path??null,language:ye?.path&&pi(ye.path)||"text",getCodeForRange:Ae=>gs(de,hl(Ae)),toStoreRange:Ae=>({startLine:Ae.start,endLine:Ae.end}),fromDraftRange:Ae=>({start:Ae.startLine,end:Ae.endLine})}),{drafts:Gs,commentText:Is,editingDraftId:qs,setSelection:dn,saveComment:ir,cancel:Ln,reset:Gn,startEdit:Or,deleteDraft:Ir}=Ys;l.useEffect(()=>{on(null),Gn(),Mn(null),Je(""),yt(!1)},[ye?.path,Gn,Mn]),l.useEffect(()=>{dn(Ds)},[Ds,dn]),l.useEffect(()=>{if(!Ds&&!qs)return;const Ae=ut=>{const ht=ut.target;ht.closest('[data-comment-input="true"]')||ht.closest('[data-comment-card="true"]')||ht.closest(".cm-gutterElement")||ht.closest("[data-sonner-toast]")||ht.closest("[data-sonner-toaster]")||(on(null),Ln())},Xe=setTimeout(()=>{document.addEventListener("click",Ae)},100);return()=>{clearTimeout(Xe),document.removeEventListener("click",Ae)}},[Ln,qs,Ds]);const En=l.useCallback((Ae,Xe)=>{const ut=Xe??Ds??void 0;Xe&&on(Xe),ir(Ae,ut),on(null)},[Ds,ir]),qn=l.useCallback((Ae,Xe)=>{const ut=[];for(const ht of Xe){if(!(ht&&typeof ht.name=="string"&&ht.name.length>0)||!f&&ht.name.startsWith(".")||!b&&D2(ht.name))continue;const Ot=ht.name,es=gn(ht.path||""),Rs=es?I2(es)?es:gn(`${Ae}/${es}`):gn(`${Ae}/${Ot}`),Js=ht.isDirectory?"directory":"file",Un=Js==="file"&&Ot.includes(".")?Ot.split(".").pop()?.toLowerCase():void 0;ut.push({name:Ot,path:Rs,type:Js,extension:Un})}return C2(ut)},[b,f]),pn=l.useCallback(async Ae=>{const Xe=gn(Ae.trim());if(!Xe||Ce.current.has(Xe)||Fe.current.has(Xe))return;Fe.current=new Set(Fe.current),Fe.current.add(Xe);const ut=Qe.current+1;Qe.current=ut,we.current=new Map(we.current),we.current.set(Xe,ut);const ht=()=>we.current.get(Xe)===ut,Ot=!b;await(r.isDesktop?n.listDirectory(Xe,{respectGitignore:Ot}).then(Rs=>Rs.entries.map(Js=>({name:Js.name,path:Js.path,isDirectory:Js.isDirectory}))):rn.listLocalDirectory(Xe,{respectGitignore:Ot}).then(Rs=>Rs.map(Js=>({name:Js.name,path:Js.path,isDirectory:Js.isDirectory})))).then(Rs=>{if(!ht())return;const Js=qn(Xe,Rs);Ce.current=new Set(Ce.current),Ce.current.add(Xe),ee(Un=>({...Un,[Xe]:Js}))}).catch(()=>{ht()&&ee(Rs=>({...Rs,[Xe]:Rs[Xe]??[]}))}).finally(()=>{ht()&&(we.current=new Map(we.current),we.current.delete(Xe),Fe.current=new Set(Fe.current),Fe.current.delete(Xe))})},[n,qn,r.isDesktop,b]),Yn=l.useCallback(async()=>{v&&(Ce.current=new Set,Fe.current=new Set,we.current=new Map,ee(Ae=>Object.keys(Ae).length===0?Ae:{}),await pn(v))},[pn,v]),In=l.useCallback(async Ae=>{if(!Ae){await Yn();return}const Xe=gn(Ae);Ce.current=new Set(Ce.current),Ce.current.delete(Xe),Fe.current=new Set(Fe.current),Fe.current.delete(Xe),await pn(Xe)},[pn,Yn]),Rr=l.useRef(""),or=l.useRef("");l.useEffect(()=>{if(!v)return;const Ae=`${v}|h${f?"1":"0"}|g${b?"1":"0"}`,Xe=Rr.current!==v,ut=or.current!==Ae;!Xe&&!ut||(Xe&&(Rr.current=v,He(""),rt(null),Ye(""),We(null),E(!1)),ut&&(or.current=Ae,Ce.current=new Set,Fe.current=new Set,we.current=new Map,ee(ht=>Object.keys(ht).length===0?ht:{}),pn(v)))},[pn,v,b,f]),l.useEffect(()=>{if(!n.listDirectory)return;const Ae=()=>{if(!document.hidden&&H.length>0)for(const Xe of H)In(Xe)};return document.addEventListener("visibilitychange",Ae),()=>document.removeEventListener("visibilitychange",Ae)},[H,n.listDirectory,In]),l.useEffect(()=>{if(!n.listDirectory||H.length===0)return;const Ae=setInterval(()=>{if(!document.hidden)for(const Xe of H)In(Xe)},8e3);return()=>clearInterval(Ae)},[H,n.listDirectory,In]);const yr=l.useCallback(async Ae=>{if(Ae?.preventDefault(),!Os||!ls)return;Z(!0);const Xe=()=>{ks(null)},ut=Ot=>{G.error(Ot)},ht=()=>{Z(!1)};if(ls==="createFile"){if(!cs.trim()){ut(e("sidebarFilesTree.toast.filenameRequired")),ht();return}if(!n.writeFile){ut(e("sidebarFilesTree.toast.writeNotSupported")),ht();return}const Ot=Os.path,es=Ot?`${Ot}/`:"",Rs=gn(`${es}${cs.trim()}`);await n.writeFile(Rs,"").then(async Js=>{Js.success&&(G.success(e("sidebarFilesTree.toast.fileCreated")),await In(Ot)),Xe()}).catch(()=>ut(e("sidebarFilesTree.toast.operationFailed"))).finally(ht);return}if(ls==="createFolder"){if(!cs.trim()){ut(e("sidebarFilesTree.toast.folderNameRequired")),ht();return}const Ot=Os.path,es=Ot?`${Ot}/`:"",Rs=gn(`${es}${cs.trim()}`);await n.createDirectory(Rs).then(async Js=>{Js.success&&(G.success(e("sidebarFilesTree.toast.folderCreated")),await In(Ot)),Xe()}).catch(()=>ut(e("sidebarFilesTree.toast.operationFailed"))).finally(ht);return}if(ls==="rename"){if(!cs.trim()){ut(e("sidebarFilesTree.toast.nameRequired")),ht();return}if(!n.rename){ut(e("sidebarFilesTree.toast.renameNotSupported")),ht();return}const Ot=Os.path,es=Ot.split("/").slice(0,-1).join("/"),Rs=es?`${es}/`:"",Js=gn(`${Rs}${cs.trim()}`);await n.rename(Ot,Js).then(async Un=>{Un.success&&(G.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await In(es),v&&oe(v,Ot),(ye?.path===Ot||ye?.path.startsWith(`${Ot}/`))&&(v&&te(v,null),He(""),rt(null),Ye(""),We(null),d&&E(!1))),Xe()}).catch(()=>ut(e("sidebarFilesTree.toast.operationFailed"))).finally(ht);return}if(ls==="delete"){if(!n.delete){ut(e("sidebarFilesTree.toast.deleteNotSupported")),ht();return}const Ot=Os.path,es=Ot.split("/").slice(0,-1).join("/");await n.delete(Ot).then(async Rs=>{Rs.success&&(G.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await In(es),v&&oe(v,Ot),(ye?.path===Ot||ye?.path.startsWith(`${Ot}/`))&&(v&&te(v,null),He(""),rt(null),Ye(""),We(null),d&&E(!1))),Xe()}).catch(()=>ut(e("sidebarFilesTree.toast.operationFailed"))).finally(ht);return}ht()},[ls,Os,cs,n,In,d,oe,v,ye?.path,te,e]);l.useEffect(()=>{if(!h){Oe([]),Re(!1);return}const Ae=j.trim();if(!Ae){Oe([]),Re(!1);return}let Xe=!1;return Re(!0),w(h,Ae,150,{includeHidden:f,respectGitignore:!b,type:"file"}).then(ut=>{if(Xe)return;const Ot=ut.filter(es=>b||!T2(es.path)).map(es=>({name:es.name,path:gn(es.path),type:"file",extension:es.extension,relativePath:es.relativePath}));Oe(Ot)}).catch(()=>{Xe||Oe([])}).finally(()=>{Xe||Re(!1)}),()=>{Xe=!0}},[h,j,w,f,b]);const Pn=l.useCallback(async(Ae,Xe)=>{if(n.readFile)return(await n.readFile(Ae,Xe)).content??"";const ut=new URLSearchParams({path:Ae});Xe?.allowOutsideWorkspace&&ut.set("allowOutsideWorkspace","true"),Xe?.optional&&ut.set("optional","true");const ht=await fetch(`/api/fs/read?${ut.toString()}`,{cache:Xe?.optional?"no-store":"default"});if(!ht.ok){const Ot=await ht.json().catch(()=>({error:ht.statusText}));throw new Error(Ot.error||e("filesView.error.readFileFailed"))}return ht.text()},[n,e]),Jn=l.useCallback(async(Ae,Xe)=>{if(n.statFile){const ut=await n.statFile(Ae,Xe);return{path:ut.path,size:ut.size,mtimeMs:ut.mtimeMs}}return null},[n]),rr=l.useMemo(()=>de.length>Ai?`${de.slice(0,Ai)}
|
|
50
|
+
|
|
51
|
+
… truncated …`:de,[de]),fn=lt!==rr,lr=l.useCallback(async()=>{if(!ye||!n.writeFile)return G.error(e("filesView.toast.savingNotSupported")),!1;if(!fn)return!0;yt(!0);try{return(await n.writeFile(ye.path,lt))?.success?(He(lt),Jn(ye.path).then(Xe=>{Xe&&(ss.current=Xe)}).catch(()=>{}),!0):(G.error(e("filesView.toast.writeFileFailed")),!1)}catch(Ae){return G.error(Ae instanceof Error?Ae.message:e("filesView.toast.saveFailed")),!1}finally{yt(!1)}},[lt,n,fn,Jn,ye,e]);l.useEffect(()=>{if(!fn){Mn(null);return}const Ae=Xe=>ws.current?(ws.current=!1,!0):(Rt(!0),xs.current=Xe,!1);return Mn(Ae),()=>{Te.getState().mainTabGuard===Ae&&Mn(null)}},[fn,Mn]),l.useEffect(()=>{try{window.localStorage.setItem(ng,Yt?"true":"false")}catch{}},[Yt]),l.useEffect(()=>{Yt||(Xt("idle"),Gt.current&&(clearTimeout(Gt.current),Gt.current=null))},[Yt]);const Ni=1500;l.useEffect(()=>{const Ae=!!(ye&&n.writeFile);if(!(!Yt||!fn||!Ae||Ve))return Gt.current=setTimeout(()=>{lr().then(Xe=>{Xe&&(Xt("saved"),setTimeout(()=>Xt("idle"),2e3))})},Ni),()=>{Gt.current&&(clearTimeout(Gt.current),Gt.current=null)}},[Yt,lt,fn,ye,n.writeFile,Ve,lr]),l.useEffect(()=>{Xt("idle")},[ye?.path]),l.useEffect(()=>{const Ae=Xe=>{Ed(Xe)&&(Xe.key.toLowerCase()==="s"?(Xe.preventDefault(),Gt.current&&(clearTimeout(Gt.current),Gt.current=null),Ve||lr().then(ut=>{ut&&(Xt("saved"),setTimeout(()=>Xt("idle"),2e3))})):Xe.key.toLowerCase()==="f"&&(Xe.preventDefault(),R(!0)))};return window.addEventListener("keydown",Ae),()=>window.removeEventListener("keydown",Ae)},[Ve,lr]);const _a=l.useCallback(async Ae=>{const Xe=wt.current+1;wt.current=Xe;const ut=()=>{if(!v)return!1;const Rs=Bn.getState().byRoot[v],Js=Rs?.selectedPath??Rs?.openPaths[0]??null;return wt.current===Xe&&Js===Ae.path};rt(null),Ye(""),We(null);const ht=fi(Ae.path),Ot=Ae.path.toLowerCase().endsWith(".svg");if(d&&E(!0),r.isDesktop&&ht&&!Ot){He(""),Je(""),qe(!0);return}if(!r.isDesktop&&ht&&!Ot){He(""),Je(""),We(Ae.path),qe(!1);return}qe(!0);const es={allowOutsideWorkspace:t==="editor-only"&&!!v&&!bl(Ae.path,v)};await Pn(Ae.path,es).then(Rs=>{ut()&&(He(Rs),Je(Rs.length>Ai?`${Rs.slice(0,Ai)}
|
|
52
|
+
|
|
53
|
+
… truncated …`:Rs),We(Ae.path),Jn(Ae.path,es).then(Js=>{Js&&ut()&&(ss.current=Js)}).catch(()=>{}))}).catch(Rs=>{if(ut()){if(M2(Rs)){if(qe(!1),v&&te(v,null),rt(null),He(""),Je(""),We(null),ss.current=null,k.trim().length>0&&D(""),d&&E(!1),v){const Un=[...Qm(Ae.path,v),Ae.path];Un.length>0&&Ne(v,Un);for(const bo of Un)Ce.current.has(bo)||pn(bo)}return}He(""),Je(""),rt(Rs instanceof Error?Rs.message:e("filesView.error.readFileFailed")),ss.current=null}}).finally(()=>{ut()&&qe(!1)})},[Ne,d,pn,t,Pn,Jn,v,r.isDesktop,k,te,e]),qr=l.useCallback(async(Ae,Xe)=>{if(!v)return;const ut=Qm(Ae,v),ht=Xe?[...ut,Ae]:ut;ht.length>0&&Ne(v,ht);const Ot=ht.map(es=>{if(!Ce.current.has(es))return pn(es)}).filter(Boolean);await Promise.all(Ot)},[Ne,pn,v]),la=l.useCallback((Ae,Xe)=>{const ut=Xe.findIndex(ht=>ht.path===Ae);return ut===-1||Xe.length<=1?null:Xe[ut+1]??Xe[ut-1]??null},[]),vn=l.useCallback(async Ae=>{if(ws.current)ws.current=!1;else if(fn){Rt(!0),is.current=Ae;return}v&&(te(v,Ae.path),ce(v,Ae.path),qr(Ae.path,!1)),rt(null),Ye(""),He(""),Je(""),We(null),d&&E(!0)},[ce,qr,fn,d,v,te]);l.useEffect(()=>{ye?.path&&qr(ye.path,!1)},[qr,ye?.path]),l.useEffect(()=>{if(!ye){wt.current+=1,qe(!1);return}_e!==ye.path&&_a(ye)},[_a,_e,ye]);const ca=l.useRef(fn);ca.current=fn,l.useEffect(()=>{if(!ye?.path||_e!==ye.path)return;let Ae=!1;const Xe=window.setInterval(()=>{document.hidden||Jn(ye.path,Ue).then(ut=>{if(Ae||!ut)return;const ht=ss.current;if(!ht||ht.path!==ye.path){ss.current=ut;return}const Ot=ut.mtimeMs!==void 0&&ht.mtimeMs!==void 0&&ut.mtimeMs!==ht.mtimeMs,es=ut.size!==ht.size;!Ot&&!es||ca.current||(ss.current=ut,We(null))}).catch(()=>{})},2e3);return()=>{Ae=!0,window.clearInterval(Xe)}},[_e,Jn,ye?.path,Ue]);const Va=l.useCallback(()=>{const Ae=is.current,Xe=xs.current,ut=ps.current;if(is.current=null,xs.current=null,ps.current=null,ws.current=!0,Rt(!1),Je(rr),ut){v&&se(v,ut),ye?.path===ut&&(Ae?vn(Ae):(v&&te(v,null),He(""),rt(null),Ye(""),We(null),d&&E(!1)));return}if(Ae){vn(Ae);return}Xe&&(Mn(null),Te.getState().setActiveMainTab(Xe))},[rr,vn,d,se,v,ye?.path,Mn,te]),$e=l.useCallback(async()=>{const Ae=is.current,Xe=xs.current,ut=ps.current;if(!await lr()){ws.current=!1;return}if(is.current=null,xs.current=null,ps.current=null,ws.current=!0,Rt(!1),ut){v&&se(v,ut),ye?.path===ut&&(Ae?await vn(Ae):(v&&te(v,null),He(""),rt(null),Ye(""),We(null),d&&E(!1)));return}if(Ae){await vn(Ae);return}Xe&&(Mn(null),Te.getState().setActiveMainTab(Xe))},[vn,d,se,v,lr,ye?.path,Mn,te]),Ze=l.useCallback(Ae=>{const Xe=ye?.path===Ae,ut=la(Ae,Se);if(Xe&&fn){Rt(!0),is.current=ut,ps.current=Ae;return}if(v&&se(v,Ae),!!Xe){if(ut){vn(ut);return}v&&te(v,null),He(""),rt(null),Ye(""),We(null),d&&E(!1)}},[la,vn,fn,d,Se,se,v,ye?.path,te]),tt=l.useCallback(Ae=>{if(ie.includes(Ae))return"open";if(y?.files){const Xe=Ae.startsWith(v+"/")?Ae.slice(v.length+1):Ae,ut=y.files.find(ht=>ht.path===Xe);if(ut){if(ut.index==="A"||ut.working_dir==="?")return"git-added";if(ut.index==="D")return"git-deleted";if(ut.index==="M"||ut.working_dir==="M")return"git-modified"}}return null},[ie,y,v]),ct=l.useCallback(Ae=>{if(!y?.files)return null;const Xe=Ae.startsWith(v+"/")?Ae.slice(v.length+1):Ae,ut=Xe?`${Xe}/`:"";let ht=0,Ot=0;for(const es of y.files)es.path.startsWith(ut)&&((es.index==="M"||es.working_dir==="M")&&ht++,(es.index==="A"||es.working_dir==="?")&&Ot++);return ht+Ot>0?{modified:ht,added:Ot}:null},[y,v]),Bt=l.useCallback(async Ae=>{const Xe=gn(Ae);v&&(ke(v,Xe),Ce.current.has(Xe)||await pn(Xe))},[pn,v,ke]),as=l.useMemo(()=>({canRename:it,canCreateFile:Ft,canCreateFolder:Zt,canDelete:zt,canReveal:hs}),[it,Ft,Zt,zt,hs]);function Vs(Ae,Xe){const ut=F[Ae]??[];return ut.map((ht,Ot)=>{const es=ht.type==="directory",Rs=es&&H.includes(ht.path),Js=ye?.path===ht.path,Un=Ot===ut.length-1;return s.jsxs("li",{className:"relative",children:[Xe>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Un&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(L2,{node:ht,root:v,isExpanded:Rs,isActive:Js,isMobile:d,alwaysShowActions:u,status:es?void 0:tt(ht.path),badge:es?ct(ht.path):void 0,permissions:as,downloadFile:n.downloadFile,contextMenuPath:ft,setContextMenuPath:kt,onSelect:vn,onToggle:Bt,onRevealPath:Zs,onOpenDialog:Vn}),es&&Rs&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Vs(ht.path,Xe+1)})]},ht.path)})}const Us=!!(ye?.path&&fi(ye.path)),Qn=!!(ye?.path&&ye.path.toLowerCase().endsWith(".svg")),po=l.useMemo(()=>gn(cn?.path??""),[cn?.path]),Yr=!!(cn&&po&&ge&&ge===po&&!st&&!et&&!Us),$r=l.useMemo(()=>hd(v,ge),[ge,v]),Bl=!!(ye&&(!Us||Qn)&&de.length>0),zl=!!(ye&&$r.length>0),On=!!(ye&&!Me&&!Us&&n.writeFile&&de.length<=Ai),Jr=!!(ye?.path&&R2(ye.path)),Ua=!!(ye?.path&&F2(ye.path)),Si=!!(ye?.path&&wc(ye.path)),da=!!(ye&&!Us)&&!Jr&&!(Si&&J==="preview"),Br=l.useMemo(()=>ge?sg(ge):null,[ge]),[sn,ua]=l.useState(null);l.useEffect(()=>{let Ae=!1;const Xe=ye?.path;if(!Xe||Br){ua(null);return}return ua(null),N2(Xe).then(ut=>{Ae||ua(ut)}),()=>{Ae=!0}},[ye?.path,Br]),l.useEffect(()=>{!On&&W==="edit"&&ne("view")},[On,W]);const Wa="openchamber:files:md-viewer-mode",fo="openchamber:files:html-viewer-mode",ho="openchamber:files:json-viewer-mode";l.useEffect(()=>{const Ae=ye?.path;if(!Ae)return;const Xe=rs?"view":"edit";ne(V.current[Ae]??Xe);let ut=rs?"preview":"edit";try{const es=localStorage.getItem(Wa);(es==="preview"||es==="edit")&&(ut=es)}catch{}ue(K.current[Ae]??ut);let ht=rs?"preview":"edit";try{const es=localStorage.getItem(fo);(es==="preview"||es==="edit")&&(ht=es)}catch{}L(X.current[Ae]??ht);let Ot=rs?"tree":"text";try{const es=localStorage.getItem(ho);(es==="tree"||es==="text")&&(Ot=es)}catch{}le(Ot)},[ye?.path,rs]);const ma=l.useCallback(Ae=>{const Xe=ye?.path;Xe&&(V.current[Xe]=Ae),ne(Ae)},[ye?.path]),An=l.useCallback(Ae=>{const Xe=ye?.path;Xe&&(K.current[Xe]=Ae),ue(Ae);try{localStorage.setItem(Wa,Ae)}catch{}},[ye?.path]),Ka=l.useCallback(()=>re,[re]),_l=l.useCallback(Ae=>{le(Ae);try{localStorage.setItem(ho,Ae)}catch{}},[]),Vl=l.useCallback(Ae=>{const Xe=ye?.path;Xe&&(X.current[Xe]=Ae),L(Ae);try{localStorage.setItem(fo,Ae)}catch{}},[ye?.path]),go=l.useCallback(()=>J,[J]);l.useEffect(()=>{if(!cn||!v)return;const Ae=()=>{typeof window>"u"||ns.current===null&&(ns.current=window.requestAnimationFrame(()=>{ns.current=null,Kt(zr=>zr+1)}))},Xe=(zr,fa)=>{if(zr.state.doc.length!==fa.length)return!1;if(fa.length===0)return!0;const Kl=Math.min(128,fa.length);if(zr.state.sliceDoc(0,Kl)!==fa.slice(0,Kl))return!1;const cu=Math.max(0,fa.length-Kl);return zr.state.sliceDoc(cu,fa.length)===fa.slice(cu)},ut=gn(cn.path);if(!ut){kn(null),js.current={key:"",attempts:0};return}const ht=`${ut}:${cn.line}:${cn.column??1}`;if(js.current.key!==ht&&(js.current={key:ht,attempts:0}),ye?.path!==ut){if(dt)return;vn(je(ut));return}if(st||_e!==ut)return;if(et||Us){kn(null),js.current={key:"",attempts:0};return}if(!On)return;if(W!=="edit"){ne("edit");return}const Ot=St.current;if(!Ot){Ae();return}if(!Xe(Ot,lt)){Ae();return}const es=Math.max(1,Math.min(cn.line,Ot.state.doc.lines)),Rs=Ot.state.doc.line(es),Js=Math.max(1,cn.column||1),Un=Math.max(0,Rs.to-Rs.from),bo=Math.min(Un,Js-1),ki=Rs.from+bo;if(!(Ot.state.selection.main.head===ki)||js.current.attempts===0){js.current.attempts+=1,Ot.dispatch({selection:{anchor:ki},effects:tr.scrollIntoView(ki,{y:"center"})}),Ot.focus(),Ae();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const zr=St.current;zr&&(zr.dispatch({selection:{anchor:ki},effects:tr.scrollIntoView(ki,{y:"center"})}),zr.focus())}),kn(null),js.current={key:"",attempts:0}},[On,dt,lt,Nt,et,st,Us,_e,vn,cn,v,ye?.path,kn,W,je]),l.useEffect(()=>{if(!Cn||!v)return;const Ae=gn(Cn);if(!Ae){Be(null);return}if(ye?.path!==Ae){if(dt)return;vn(je(Ae));return}if(!(st||_e!==Ae||et||Us)){if(On&&W==="edit"){const Xe=St.current;if(!Xe)return;Xe.focus()}Be(null)}},[On,dt,et,st,vn,Us,_e,Cn,v,ye?.path,Be,W,je]);const Qr=l.useCallback(Ae=>{if(!d||!Ae||!Ae.hasFocus||typeof window>"u")return;const Xe=window.visualViewport;if(!Xe)return;const ut=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,ut-(Xe.offsetTop+Xe.height))<=0)return;const Ot=Ae.state.selection.main.head,es=Ae.coordsAtPos(Ot);if(!es)return;const Rs=Math.round(Xe.offsetTop+Xe.height),Un=es.bottom+20-Rs;Un<=0||(Ae.scrollDOM.scrollTop+=Un)},[d]);l.useEffect(()=>{if(!d||typeof window>"u")return;const Ae=()=>{window.requestAnimationFrame(()=>{Qr(St.current)})},Xe=window.visualViewport;return Xe?.addEventListener("resize",Ae),Xe?.addEventListener("scroll",Ae,{passive:!0}),document.addEventListener("selectionchange",Ae),()=>{Xe?.removeEventListener("resize",Ae),Xe?.removeEventListener("scroll",Ae),document.removeEventListener("selectionchange",Ae)}},[d,Qr]),l.useEffect(()=>{if(!On||W!=="edit"||d)return;const Ae=Ur("open_go_to_line",Et),Xe=ut=>{const ht=ut.target;if(ht?.closest('[role="dialog"]'))return;const Ot=!!ht?.closest(".cm-editor");ht?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!Ot||!document.activeElement?.closest(".cm-editor")||Vo(ut,Ae)&&(ut.preventDefault(),Ct(!0))};return window.addEventListener("keydown",Xe),()=>window.removeEventListener("keydown",Xe)},[On,d,Et,W]);const pa=l.useMemo(()=>{if(!ye?.path)return[fd(a)];const Ae=[fd(a)],Xe=Br??sn;return Xe&&Ae.push(Xe),P&&Ae.push(tr.lineWrapping),d&&Ae.push(tr.updateListener.of(ut=>{ut.view.hasFocus&&(ut.selectionSet||ut.focusChanged||ut.viewportChanged||ut.geometryChanged)&&window.requestAnimationFrame(()=>{Qr(ut.view)})})),Ae},[a,ye?.path,Br,sn,P,d,Qr]),Ha=l.useMemo(()=>({light:U.metadata.id,dark:ae.metadata.id}),[U.metadata.id,ae.metadata.id]),xo=ye?.path&&Us?r.isDesktop?Qn?`data:${Nu(ye.path)};utf8,${encodeURIComponent(de)}`:xe:Qn?`data:${Nu(ye.path)};utf8,${encodeURIComponent(de)}`:`/api/fs/raw?${new URLSearchParams({path:ye.path,...Ue.allowOutsideWorkspace?{allowOutsideWorkspace:"true"}:{}}).toString()}`:"";l.useEffect(()=>{let Ae=!1;return(async()=>{if(!r.isDesktop||!ye?.path||!Us||Qn){Ye("");return}rt(null),await(n.readFileBinary?n.readFileBinary(ye.path,Ue).then(ht=>ht.dataUrl):Promise.resolve(Ix(ye.path,"asset"))).then(ht=>{Ae||(Ye(ht),We(ye.path))}).catch(ht=>{Ae||(Ye(""),rt(ht instanceof Error?ht.message:e("filesView.error.readFileFailed")),We(null))}).finally(()=>{Ae||qe(!1)})})(),()=>{Ae=!0}},[n,Us,Qn,r.isDesktop,ye?.path,Ue,e]);const Ul=l.useCallback(()=>ks(null),[]),Wl=l.useMemo(()=>Uh({drafts:Gs,editingDraftId:qs,commentText:Is,selection:Ds,isDragging:Sn,fileLabel:ye?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:Ae=>({start:Ae.startLine,end:Ae.endLine}),onSave:En,onCancel:()=>{on(null),Ln()},onEdit:Ae=>{Or(Ae),on({start:Ae.startLine,end:Ae.endLine})},onDelete:Ir}),[Ln,Is,Ir,qs,Gs,En,Sn,Ds,ye?.path,Or]),Ee=l.useCallback((Ae,Xe)=>s.jsx("div",{className:"h-full",children:s.jsx(Cx,{file:{name:Ae.name,contents:Xe,lang:pi(Ae.path)||void 0},options:{disableFileHeader:!0,overflow:P?"wrap":"scroll",theme:Ha,themeType:a.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[a.metadata.variant,Ha,P]),vt=({exitFullscreenOnly:Ae=!1}={})=>ye?s.jsxs("div",{className:"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",children:[On&&W==="edit"&&s.jsxs(s.Fragment,{children:[Ve?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")]}):Yt&&Dt==="saved"&&!fn?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")]}):fn?s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{lr()},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(Yt?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${ll()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${ll()}+S`}),children:s.jsx(I,{name:"save-3",className:"size-4"})}):null,s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>ts(Xe=>!Xe),className:me("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",Yt?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(Yt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(Yt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:Yt?s.jsx(I,{name:"file-check-fill",className:"size-4"}):s.jsx(I,{name:"file-check",className:"size-4"})})]}),s.jsxs(_s,{onOpenChange:_,children:[s.jsx(Bs,{asChild:!0,children:s.jsx(be,{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.jsxs(zs,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Jt.map(Xe=>s.jsxs(Vt,{className:"flex items-center gap-2",onClick:()=>{nr(Xe)},children:[s.jsx(k2,{label:Xe.label,iconDataUrl:Xe.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Xe.label})]},Xe.id)),Ut?s.jsxs(Vt,{className:"flex items-center gap-2",onClick:()=>{tn(!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]})]}),!Us&&s.jsxs(s.Fragment,{children:[s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>C(!P),className:me("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",P?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(P?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(I,{name:"text-wrap",className:"size-4"})}),W==="edit"&&s.jsxs(s.Fragment,{children:[s.jsx(be,{variant:"ghost",size:"sm",onClick:Xe=>{R(!M),Xe.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"})}),s.jsx(be,{variant:"ghost",size:"sm",onClick:Xe=>{Ct(ut=>!ut),Xe.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(y2,{open:bt,onOpenChange:Ct,view:St.current,variant:"inline"})]})]}),da&&On&&!Ua&&!Si&&s.jsx(md,{currentMode:W==="view"?"preview":"edit",onToggle:()=>{ma(W==="view"?"edit":"view")}}),(Jr||wc(ye?.path??""))&&s.jsx(md,{currentMode:Jr?Ka():go(),onToggle:()=>{wc(ye?.path??"")?Vl(go()==="preview"?"edit":"preview"):An(Ka()==="preview"?"edit":"preview")}}),Ua&&s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>_l(Y==="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(Y==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:Y==="tree"?s.jsx(I,{name:"code-sslash",className:"size-4"}):s.jsx(I,{name:"node-tree",className:"size-4"})}),Bl&&s.jsx(be,{variant:"ghost",size:"sm",onClick:async()=>{(await Rn(de)).ok?(Ns(!0),qt.current!==null&&window.clearTimeout(qt.current),qt.current=window.setTimeout(()=>{Ns(!1)},1200)):G.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:Ht?s.jsx(I,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"clipboard",className:"size-4"})}),zl&&s.jsx(be,{variant:"ghost",size:"sm",onClick:async()=>{(await Rn($r)).ok?(Ke(!0),Ge.current!==null&&window.clearTimeout(Ge.current),Ge.current=window.setTimeout(()=>{Ke(!1)},1200)):G.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:$r}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:$r}),children:Cs?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&&s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{const Xe=n.downloadFile;Xe&&Xe(ye.path)},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(I,{name:"download",className:"size-4"})}),Ae?s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>T(!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"&&s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>T(!N),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:N?s.jsx(I,{name:"fullscreen-exit",className:"size-4"}):s.jsx(I,{name:"fullscreen",className:"size-4"})})]}):null,pt=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(vs,{open:dt,onOpenChange:Ae=>{Ae||Rt(!0)},children:s.jsxs(ys,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:e("filesView.unsaved.title")}),s.jsx(Fs,{children:e("filesView.unsaved.description")})]}),s.jsxs(Hs,{children:[s.jsx(be,{variant:"outline",onClick:()=>{$e()},disabled:Ve,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(be,{variant:"destructive",onClick:Va,children:e("filesView.unsaved.discard")})]})]})}),s.jsx("div",{className:me("flex flex-col flex-shrink-0",x&&"border-b border-border/40"),children:x?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[d&&A&&s.jsx("button",{type:"button",onClick:()=>E(!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?ye?s.jsxs(_s,{children:[s.jsx(Bs,{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(jr,{filePath:ye.path,extension:ye.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:ye.name}),s.jsx(I,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(zs,{align:"start",className:"min-w-[16rem]",children:Se.map(Ae=>{const Xe=ye?.path===Ae.path;return s.jsxs(Vt,{onSelect:ut=>{if(ut.target.closest("[data-close-open-file]")){ut.preventDefault();return}Xe||vn(Ae)},className:me("flex items-center justify-between gap-2",Xe&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 truncate",children:[s.jsx(jr,{filePath:Ae.path,extension:Ae.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Ae.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:ut=>{ut.preventDefault(),ut.stopPropagation()},onClick:ut=>{ut.preventDefault(),ut.stopPropagation(),Ze(Ae.path)},className:"inline-flex size-6 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:Ae.name}),children:s.jsx(I,{name:"close",className:"size-3.5"})})]},Ae.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Se.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Ie.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"}),Ie.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:q,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Se.map(Ae=>{const Xe=ye?.path===Ae.path;return s.jsxs("div",{title:hd(v,Ae.path),className:me("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",Xe?"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(jr,{filePath:Ae.path,extension:Ae.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{Xe||vn(Ae)},className:"max-w-[12rem] truncate text-left",children:Ae.name}),s.jsx("button",{type:"button",onClick:ut=>{ut.stopPropagation(),Ze(Ae.path)},className:me("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!Xe&&!u&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:Ae.name}),children:s.jsx(I,{name:"close",className:"size-3.5"})})]},Ae.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[ye&&!M&&s.jsx("div",{ref:B,className:"absolute right-3 top-3 z-30",onMouseEnter:()=>z(!0),onMouseLeave:()=>{$.current>0||z(!1)},children:O?vt():s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>z(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(I,{name:"more-2-fill",className:"size-4"})})}),s.jsx(Es,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:ye?st?g?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")]}):et?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:et}):Us?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:xo,alt:ye?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"})}):ye&&Ua&&Y==="tree"?s.jsx(Xs,{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(jv,{jsonString:de,maxHeight:"100%",initiallyExpandedDepth:2})})}):ye&&Jr&&Ka()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[de.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(de.length/1024)})}),s.jsx(Xs,{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(Ra,{content:de,className:"typography-markdown-body",stripFrontmatter:!0})})]}):ye&&Si&&J==="preview"?s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{srcDoc:(()=>{const Ae=ye.path.substring(0,ye.path.lastIndexOf("/")+1);if(!Ae)return de;const Xe=`<base href="${r.isDesktop,Ae}">`;return de.replace(/<head([^>]*)>/i,`<head$1>${Xe}`)})(),className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")})}):ye&&da&&W==="view"?Ee(ye,lt):s.jsxs("div",{className:me("relative h-full",Yr&&"overflow-hidden"),ref:Mt,children:[s.jsx("div",{className:me("h-full",Yr&&"invisible"),children:s.jsx(ud,{value:lt,onChange:Je,readOnly:!On,extensions:pa,className:"h-full",blockWidgets:Wl,onViewReady:Ae=>{St.current=Ae,Kt(Xe=>Xe+1),window.requestAnimationFrame(()=>{Qr(Ae)})},onViewDestroy:()=>{St.current&&(St.current=null),Kt(Ae=>Ae+1)},enableSearch:!0,searchOpen:M,onSearchOpenChange:R,highlightLines:Ds?{start:Math.min(Ds.start,Ds.end),end:Math.max(Ds.start,Ds.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(Ae,Xe,ut)=>{if(!(ut instanceof MouseEvent)||ut.button!==0)return!1;ut.preventDefault();const ht=Ae.state.doc.lineAt(Xe.from).number;if(d&&Ds&&!ut.shiftKey){const Ot=Math.min(Ds.start,Ds.end,ht),es=Math.max(Ds.start,Ds.end,ht);return on({start:Ot,end:es}),en.current=!1,mn.current=null,Fn(!1),!0}if(en.current=!0,mn.current=ht,Fn(!0),Ds&&ut.shiftKey){const Ot=Math.min(Ds.start,ht),es=Math.max(Ds.end,ht);on({start:Ot,end:es})}else on({start:ht,end:ht});return!0},mouseover:(Ae,Xe,ut)=>{if(!(ut instanceof MouseEvent)||ut.buttons!==1||!en.current||mn.current===null)return!1;const ht=Ae.state.doc.lineAt(Xe.from).number,Ot=Math.min(mn.current,ht),es=Math.max(mn.current,ht);return on({start:Ot,end:es}),Fn(!0),!1},mouseup:()=>(en.current=!1,mn.current=null,Fn(!1),!1)}}})}),Yr&&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")})})]})]}),Qt=!!(v&&F[v]),Ts=s.jsxs("section",{className:me("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:me("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(Wt,{ref:S,value:k,onChange:Ae=>D(Ae.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),k.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:()=>{D(""),S.current?.focus()},children:s.jsx(I,{name:"close",className:"size-4"})})]}),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>Vn("createFile",{path:h,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),children:s.jsx(I,{name:"file-add",className:"size-4"})}),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>Vn("createFolder",{path:h,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),children:s.jsx(I,{name:"folder-add",className:"size-4"})}),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{Yn()},className:"size-8 p-0 flex-shrink-0",children:s.jsx(I,{name:"refresh",className:"size-4"})})]})}),s.jsx(Es,{outerClassName:"flex-1 min-h-0",className:me("py-2",d?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:nt?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")]}):pe.length>0?pe.map(Ae=>{const Xe=ye?.path===Ae.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{vn(Ae)},className:me("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",Xe?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[rg(Ae.path,Ae.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:Ae.path,children:Ae.relativePath??Ae.path})]})},Ae.path)}):Qt?Vs(v,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),hn=t==="full"&&N&&ye&&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:vt({exitFullscreenOnly:!0})}),s.jsx(Es,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:st?g?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…"]}):et?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:et}):Us?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:xo,alt:ye.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"})}):Jr&&Ka()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[de.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(de.length/1024)})}),s.jsx(Xs,{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(Ra,{content:de,className:"typography-markdown-body",stripFrontmatter:!0})})]}):da&&W==="view"?Ee(ye,lt):s.jsxs("div",{className:me("relative h-full",Yr&&"overflow-hidden"),children:[s.jsx("div",{className:me("h-full",Yr&&"invisible"),children:s.jsx(ud,{value:lt,onChange:Je,readOnly:!On,extensions:pa,className:"h-full",onViewReady:Ae=>{St.current=Ae,window.requestAnimationFrame(()=>{Qr(Ae)})},onViewDestroy:()=>{St.current&&(St.current=null)}})}),Yr&&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(O2,{activeDialog:ls,dialogData:Os,dialogInputValue:cs,onDialogInputChange:jt,isDialogSubmitting:Tt,onDialogSubmit:yr,onClose:Ul,inputRef:$t}),hn,d?A?pt:Ts: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:pt})}):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:Ts}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:pt})]})]})},$2=Object.freeze(Object.defineProperty({__proto__:null,FilesView:ag},Symbol.toStringTag,{value:"Module"})),Tr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},jc=(t,e)=>{const n=Tr(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},B2=(t,e,n)=>jc(jc(jc(t,".opencode"),"plans"),`${e}-${n}.md`),z2=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,_2=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},V2=(t,e)=>{const n=Tr(e.currentDirectory),r=Tr(e.homeDirectory),a=Tr(t);return n&&a.startsWith(n+"/")?a.slice(n.length+1):r&&a===r?"~":r&&a.startsWith(r+"/")?`~${a.slice(r.length)}`:a},U2=(t,e,n)=>{const r=Tr(t.trim());if(!r)return null;const a=n?e.find(o=>o.id===n)??null:null;if(a?.path){const o=Tr(a.path);if(r===o||r.startsWith(`${o}/`))return{id:a.id,path:a.path}}const i=e.filter(o=>{const c=Tr(o.path);return r===c||r.startsWith(`${c}/`)}).sort((o,c)=>Tr(c.path).length-Tr(o.path).length)[0];return i?{id:i.id,path:i.path}:null},ig=({targetPath:t=null})=>{const{t:e}=mt(),n=_t(he=>he.currentSessionId),r=_t(he=>he.createSession),a=_t(he=>he.initializeNewOpenChamberSession),i=_t(he=>he.sendMessage),o=_t(he=>he.setCurrentSession),c=El(),d=Ws(he=>he.homeDirectory),p=Md(he=>he.planModeEnabled),m=Ls(he=>he.projects),u=Ls(he=>he.activeProjectId),f=nn(he=>he.directories),b=Lr()??"",h=Te(he=>he.setActiveMainTab),v=Te(he=>he.setSessionSwitcherOpen),x=_n(),{isMobile:g}=an(),{currentTheme:w}=Cr();l.useMemo(()=>th(w),[w]);const y=l.useMemo(()=>n?c.find(he=>he.id===n)??null:null,[n,c]),k=l.useMemo(()=>{const he=typeof y?.directory=="string"?y.directory:"";return Tr(he||"")},[y?.directory]),D=l.useMemo(()=>Tr(b||k),[b,k]),j=l.useMemo(()=>U2(D,m,u),[u,D,m]),S=l.useMemo(()=>j?f.get(j.path)?.isGitRepo===!0:!1,[j,f]),[A,E]=l.useState(null),[P,C]=l.useState(!1),[N,T]=l.useState(null),M=l.useMemo(()=>!N||!k||!d?N:V2(N,{currentDirectory:k,homeDirectory:d}),[N,k,d]),[R,O]=l.useState(""),[z,B]=l.useState(null),$=l.useMemo(()=>M&&M.split("/").pop()||e("planView.file.defaultName"),[M,e]),_=l.useMemo(()=>R.trim()&&Ab(R).title||e("planView.title.default"),[R,e]),Q=l.useMemo(()=>_.trim()||e("planView.title.default"),[_,e]),[W,ne]=l.useState(!1),[re,ue]=l.useState(!1),[Y,le]=l.useState("edit"),J=l.useRef(null),[L,V]=l.useState(null),K=l.useRef(null),X=l.useRef(null),U="openchamber:plan:md-viewer-mode";l.useEffect(()=>{try{const he=localStorage.getItem(U);if(!he)return;const F=JSON.parse(he);(F==="preview"||F==="edit")&&le(F)}catch{}},[]);const ae=l.useCallback(he=>{le(he);try{localStorage.setItem(U,JSON.stringify(he))}catch{}},[]),ve=l.useRef(!1),ie=l.useRef(null),[fe,H]=l.useState(!1);l.useEffect(()=>{const he=()=>{ve.current=!1,ie.current=null,H(!1)};return document.addEventListener("mouseup",he),()=>document.removeEventListener("mouseup",he)},[]);const ce=l.useCallback((he,F)=>{const ee=he.split(`
|
|
54
|
+
`),Ce=Math.max(1,F.start),Fe=Math.min(ee.length,F.end);return Ce>Fe?"":ee.slice(Ce-1,Fe).join(`
|
|
55
|
+
`)},[]),se=qd({source:"plan",fileLabel:$,language:N&&pi(N)||"markdown",getCodeForRange:he=>ce(R,hl(he)),toStoreRange:he=>({startLine:he.start,endLine:he.end}),fromDraftRange:he=>({start:he.startLine,end:he.endLine})}),{drafts:oe,commentText:te,editingDraftId:ke,setSelection:Ne,saveComment:je,cancel:Se,reset:De,startEdit:ye,deleteDraft:ge}=se;l.useEffect(()=>{V(null),De()},[R,De]),l.useEffect(()=>{Ne(L)},[L,Ne]);const Me=l.useCallback(()=>{V(null),Se()},[Se]),Ue=l.useCallback((he,F)=>{F&&V(F),je(he,F??L??void 0),V(null)},[L,je]);l.useEffect(()=>{if(!L)return;const he=ee=>{const Ce=ee.target;Ce.closest('[data-comment-card="true"]')||Ce.closest('[data-comment-input="true"]')||Ce.closest(".oc-block-widget")||Ce.closest(".cm-gutterElement")||Ce.closest("[data-sonner-toast]")||Ce.closest("[data-sonner-toaster]")||(V(null),Se())},F=window.setTimeout(()=>{document.addEventListener("click",he)},100);return()=>{window.clearTimeout(F),document.removeEventListener("click",he)}},[Se,ke,g,L]);const q=l.useMemo(()=>{const he=[fd(w)],F=sg(N||"plan.md");return F&&he.push(F),he.push(tr.lineWrapping),he},[w,N]);l.useEffect(()=>{if(!p&&!t){T(null),O(""),ne(!1);return}let he=!1;const F=async Ce=>{if(x.files?.readFile)return(await x.files.readFile(Ce))?.content??"";const Fe=hr()?.files;if(Fe?.readFile)return(await Fe.readFile(Ce,{optional:!0}))?.content??"";const we=await fetch(`/api/fs/read?path=${encodeURIComponent(Ce)}&optional=true`,{cache:"no-store"});if(!we.ok)throw new Error(`Failed to read plan file (${we.status})`);return we.text()};return(async()=>{if(T(null),O(""),B(null),t){ne(!0);try{const Ce=await F(t);if(he)return;T(t),O(Ce)}catch{if(he)return;T(null),O("")}finally{he||ne(!1)}return}if(!y?.slug||!y?.time?.created||!k){T(null),O("");return}ne(!0);try{const Ce=B2(k,y.time.created,y.slug),Fe=_2(z2(y.time.created,y.slug),d||null);let we=null,Qe=null;try{Qe=await F(Ce),we=Ce}catch{}if(!we)try{Qe=await F(Fe),we=Fe}catch{}if(he)return;if(!we||Qe===null){T(null),O("");return}T(we),O(Qe)}catch{if(he)return;T(null),O("")}finally{he||ne(!1)}})(),()=>{he=!0}},[d,p,x.files,k,y?.slug,y?.time?.created,t]),l.useEffect(()=>{if(!N){B(null);return}const he=window.setTimeout(async()=>{B(null);try{if(x.files?.writeFile){if(!(await x.files.writeFile(N,R))?.success)throw new Error(e("planView.error.writeFailed"))}else{const F=await fetch("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:N,content:R})});if(!F.ok)throw new Error(e("planView.error.writePlanFileFailed",{status:F.status}))}}catch(F){B(F instanceof Error?F.message:e("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(he)}},[R,N,x.files,e]),l.useEffect(()=>()=>{J.current!==null&&window.clearTimeout(J.current)},[]);const Ie=l.useCallback(()=>{h("chat"),v(!1)},[h,v]),Le=l.useCallback(async he=>{if(!j||!A)return;const F=await Nn(A.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:Q}),Ce=[{synthetic:!0,text:await Nn(A.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:Q,plan_path:N??""})}];C(!0);try{Ie();let Fe=null,we=j.path;if(A.target==="worktree"){if(!S)return;const pe=await Qf(j.path,Xf());if(!pe?.id)return;Fe=pe.id,we=null}else{const pe=await r(void 0,j.path,null);if(!pe?.id)return;Fe=pe.id,we=pe.directory??j.path,a(pe.id,gt.getState().agents??[])}if(!Fe)return;const Qe=Pl.getState();Qe.saveSessionModelSelection(Fe,he.providerID,he.modelID),he.agent.trim()&&(Qe.saveSessionAgentSelection(Fe,he.agent),Qe.saveAgentModelForSession(Fe,he.agent,he.providerID,he.modelID),Qe.saveAgentModelVariantForSession(Fe,he.agent,he.providerID,he.modelID,he.variant||void 0)),o(Fe,we),await i(F,he.providerID,he.modelID,he.agent.trim()||void 0,void 0,void 0,Ce,he.variant||void 0),E(null)}finally{C(!1)}},[S,r,j,a,A,N,Ie,i,Q,o]),Pe=l.useMemo(()=>Uh({drafts:oe,editingDraftId:ke,commentText:te,selection:L,isDragging:fe,fileLabel:$,newWidgetId:"plan-new-comment-input",mapDraftToRange:he=>({start:he.startLine,end:he.endLine}),onSave:Ue,onCancel:Me,onEdit:he=>{ye(he),V({start:he.startLine,end:he.endLine})},onDelete:ge}),[te,ge,ke,Me,Ue,fe,L,oe,$,ye]);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?s.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:z,children:e("planView.error.saveFailed")}):null]}),N?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(_s,{children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(Bs,{asChild:!0,children:s.jsx(be,{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(At,{sideOffset:8,children:e("planView.actions.improve")})]}),s.jsxs(zs,{align:"end",children:[s.jsx(Vt,{onClick:()=>E({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(Vt,{onClick:()=>E({action:"improve",target:"worktree"}),disabled:!S,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsxs(_s,{children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(Bs,{asChild:!0,children:s.jsx(be,{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(At,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs(zs,{align:"end",children:[s.jsx(Vt,{onClick:()=>E({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(Vt,{onClick:()=>E({action:"implement",target:"worktree"}),disabled:!S,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(md,{currentMode:Y,onToggle:()=>ae(Y==="preview"?"edit":"preview")}),s.jsx(be,{variant:"ghost",size:"sm",onClick:async()=>{(await Rn(R)).ok&&(ue(!0),J.current!==null&&window.clearTimeout(J.current),J.current=window.setTimeout(()=>{ue(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:re?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(Eh,{open:A!==null,onOpenChange:he=>{!he&&!P&&E(null)},target:A?.target??"session",projectDirectory:j?.path??null,submitting:P,onConfirm:Le}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(Es,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:W?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(Xs,{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(Ra,{content:R,className:"typography-markdown-body"})})}):s.jsx("div",{className:"relative h-full",ref:X,children:s.jsx(ud,{value:R,onChange:O,readOnly:!1,className:"h-full",extensions:q,onViewReady:he=>{K.current=he},onViewDestroy:()=>{K.current=null},blockWidgets:Pe,highlightLines:L?{start:Math.min(L.start,L.end),end:Math.max(L.start,L.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(he,F,ee)=>{if(!(ee instanceof MouseEvent)||ee.button!==0)return!1;ee.preventDefault();const Ce=he.state.doc.lineAt(F.from).number;if(g&&L&&!ee.shiftKey){const Fe=Math.min(L.start,L.end,Ce),we=Math.max(L.start,L.end,Ce);return V({start:Fe,end:we}),ve.current=!1,ie.current=null,H(!1),!0}if(ve.current=!0,ie.current=Ce,H(!0),L&&ee.shiftKey){const Fe=Math.min(L.start,Ce),we=Math.max(L.end,Ce);V({start:Fe,end:we})}else V({start:Ce,end:Ce});return!0},mouseover:(he,F,ee)=>{if(!(ee instanceof MouseEvent)||ee.buttons!==1||!ve.current||ie.current===null)return!1;const Ce=he.state.doc.lineAt(F.from).number,Fe=Math.min(ie.current,Ce),we=Math.max(ie.current,Ce);return V({start:Fe,end:we}),H(!0),!1},mouseup:()=>(ve.current=!1,ie.current=null,H(!1),!1)}}})})})})})})]})},W2=Object.freeze(Object.defineProperty({__proto__:null,PlanView:ig},Symbol.toStringTag,{value:"Module"})),gd={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},Jo={user:0,assistant:0,tool:0,other:0},wa=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,Xm=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(p=>p.tokens!==void 0)?.tokens;if(typeof n=="number")return{...gd,total:wa(n)};if(!n||typeof n!="object")return gd;const r=n,a=wa(r.input),i=wa(r.output),o=wa(r.reasoning),c=wa(r.cache?.read),d=wa(r.cache?.write);return{input:a,output:i,reasoning:o,cacheRead:c,cacheWrite:d,total:a+i+o+c+d}},K2=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},ur=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+ur(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+ur(n),0):0,H2=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...Jo,assistant:ur(n.text)+ur(n.content)};const a=K2(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:ur(n.input)+ur(n.output)+ur(n.error)+ur(n.call?.input)+ur(n.call?.output)+ur(n.call?.error)+ur(n.raw)+Math.round(ur(n.metadata)*.25)+Math.round(ur(n.state)*.1),other:0}:e==="user"?{user:a.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:a.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:a.length}},Zm=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),G2=t=>{const e=oo(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},q2=(t,e)=>{if(t.length===0)return{...Jo};const n=t.reduce((r,a)=>{const i=G2(a);let o={...Jo};for(const c of a.parts)o=Zm(o,H2(c,i));return Zm(r,o)},{...Jo});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)}},Za=t=>t.toLocaleString(),Y2=t=>!Number.isFinite(t)||t<=0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`,J2=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),Q2=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),X2=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,Z2=(t,e,n)=>{const r=t.find(i=>i.id===e),a=r?.models?.find(i=>i.id===n);return{providerName:r?.name||e||"-",modelName:a?.name||n||"-",contextLimit:typeof a?.limit?.context=="number"?a.limit.context:null}},eS=()=>{const t=at.c(199),{t:e}=mt(),{currentTheme:n}=Cr();let r;t[0]!==n?(r=th(n),t[0]=n,t[1]=r):r=t[1];const a=r;let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i={},t[2]=i):i=t[2];const[o,c]=l.useState(i),[d,p]=l.useState(null),m=l.useRef(null),u=_t(tS),f=El(),b=Db(u??""),h=gt(sS);let v;t[3]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null),c(nS),p(null)},t[3]=v):v=t[3];let x;t[4]!==u?(x=[u],t[4]=u,t[5]=x):x=t[5],l.useEffect(v,x);let g,w;t[6]===Symbol.for("react.memo_cache_sentinel")?(g=()=>()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},w=[],t[6]=g,t[7]=w):(g=t[6],w=t[7]),l.useEffect(g,w);let y;t[8]===Symbol.for("react.memo_cache_sentinel")?(y=async(wt,Dt)=>{(await Rn(Dt)).ok?(p(wt),m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{p(Yt=>Yt===wt?null:Yt),m.current=null},2e3)):p(null)},t[8]=y):y=t[8];const k=y;let D;t[9]!==u||t[10]!==f?(D=u?f.find(wt=>wt.id===u)??null:null,t[9]=u,t[10]=f,t[11]=D):D=t[11];const j=D;let S,A,E,P,C;if(t[12]!==h||t[13]!==b){S=b.filter(rS);let wt;t[19]!==b?(wt=b.filter(aS),t[19]=b,t[20]=wt):wt=t[20],C=wt;let Dt=null;for(let Yt=S.length-1;Yt>=0;Yt=Yt-1,Yt){const ts=S[Yt];if(Xm(ts).total>0){Dt=ts;break}}E=Dt?Xm(Dt):gd,P=S.reduce(iS,0);const Xt=Dt?.info??null;A=Z2(h,Xt?.providerID||"",Xt?.modelID||""),t[12]=h,t[13]=b,t[14]=S,t[15]=A,t[16]=E,t[17]=P,t[18]=C}else S=t[14],A=t[15],E=t[16],P=t[17],C=t[18];const N=A,T=N.contextLimit,M=T&&T>0?Math.min(999,E.total/T*100):0;let R;if(t[21]!==b){const wt=[...b].reverse().find(oS)?.info?.system||"";R=q2(b,wt),t[21]=b,t[22]=R}else R=t[22];const O=R,z=O.user,B=O.assistant,$=O.tool,_=Math.max(0,E.input-z-B-$),Q=z+B+$+_,W=b[0]?.info?.time?.created,ne=b.length>0?b[b.length-1]?.info?.time?.created:null;let re;t[23]!==j?.title||t[24]!==e?(re=j?.title||e("contextSidebar.session.untitled"),t[23]=j?.title,t[24]=e,t[25]=re):re=t[25];const ue=j?.time?.created??W??null,Y=ne??j?.time?.created??null;let le;t[26]!==B||t[27]!==_||t[28]!==$||t[29]!==z?(le={user:z,assistant:B,tool:$,other:_},t[26]=B,t[27]=_,t[28]=$,t[29]=z,t[30]=le):le=t[30];let J;t[31]!==S.length||t[32]!==Q||t[33]!==T||t[34]!==N||t[35]!==b.length||t[36]!==re||t[37]!==ue||t[38]!==Y||t[39]!==le||t[40]!==E||t[41]!==P||t[42]!==M||t[43]!==C.length?(J={sessionTitle:re,messagesCount:b.length,userMessagesCount:C.length,assistantMessagesCount:S.length,createdAt:ue,lastActivityAt:Y,providerModel:N,tokenBreakdown:E,usagePercent:M,totalAssistantCost:P,contextLimit:T,breakdown:le,breakdownTotal:Q},t[31]=S.length,t[32]=Q,t[33]=T,t[34]=N,t[35]=b.length,t[36]=re,t[37]=ue,t[38]=Y,t[39]=le,t[40]=E,t[41]=P,t[42]=M,t[43]=C.length,t[44]=J):J=t[44];const L=J;if(!u){let wt;t[45]!==e?(wt=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=wt):wt=t[46];let Dt;return t[47]!==wt?(Dt=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:wt}),t[47]=wt,t[48]=Dt):Dt=t[48],Dt}let V;t[49]!==e?(V=e("contextSidebar.breakdown.user"),t[49]=e,t[50]=V):V=t[50];let K;t[51]!==V||t[52]!==L.breakdown.user?(K={key:"user",label:V,value:L.breakdown.user,color:"var(--status-success)"},t[51]=V,t[52]=L.breakdown.user,t[53]=K):K=t[53];let X;t[54]!==e?(X=e("contextSidebar.breakdown.assistant"),t[54]=e,t[55]=X):X=t[55];let U;t[56]!==X||t[57]!==L.breakdown.assistant?(U={key:"assistant",label:X,value:L.breakdown.assistant,color:"var(--primary-base)"},t[56]=X,t[57]=L.breakdown.assistant,t[58]=U):U=t[58];let ae;t[59]!==e?(ae=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=ae):ae=t[60];let ve;t[61]!==ae||t[62]!==L.breakdown.tool?(ve={key:"tool",label:ae,value:L.breakdown.tool,color:"var(--status-warning)"},t[61]=ae,t[62]=L.breakdown.tool,t[63]=ve):ve=t[63];let ie;t[64]!==e?(ie=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=ie):ie=t[65];let fe;t[66]!==ie||t[67]!==L.breakdown.other?(fe={key:"other",label:ie,value:L.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=ie,t[67]=L.breakdown.other,t[68]=fe):fe=t[68];let H;t[69]!==K||t[70]!==U||t[71]!==ve||t[72]!==fe?(H=[K,U,ve,fe],t[69]=K,t[70]=U,t[71]=ve,t[72]=fe,t[73]=H):H=t[73];const ce=H;let se;t[74]!==L.sessionTitle?(se=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:L.sessionTitle}),t[74]=L.sessionTitle,t[75]=se):se=t[75];let oe;t[76]!==L.providerModel.modelName||t[77]!==L.providerModel.providerName?(oe=s.jsxs("span",{children:[L.providerModel.providerName," / ",L.providerModel.modelName]}),t[76]=L.providerModel.modelName,t[77]=L.providerModel.providerName,t[78]=oe):oe=t[78];let te;t[79]!==L.createdAt?(te=L.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:J2(L.createdAt)})]}),t[79]=L.createdAt,t[80]=te):te=t[80];let ke;t[81]!==oe||t[82]!==te?(ke=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:[oe,te]}),t[81]=oe,t[82]=te,t[83]=ke):ke=t[83];let Ne;t[84]!==se||t[85]!==ke?(Ne=s.jsxs("div",{className:"mb-6",children:[se,ke]}),t[84]=se,t[85]=ke,t[86]=Ne):Ne=t[86];let je;t[87]!==e?(je=e("contextSidebar.section.context"),t[87]=e,t[88]=je):je=t[88];let Se;t[89]!==je?(Se=s.jsx("span",{className:"typography-micro text-muted-foreground",children:je}),t[89]=je,t[90]=Se):Se=t[90];let De;t[91]!==L.tokenBreakdown.total?(De=Za(L.tokenBreakdown.total),t[91]=L.tokenBreakdown.total,t[92]=De):De=t[92];let ye;t[93]!==L.contextLimit?(ye=L.contextLimit?` / ${Za(L.contextLimit)}`:"",t[93]=L.contextLimit,t[94]=ye):ye=t[94];let ge;t[95]!==De||t[96]!==ye?(ge=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[De,ye]}),t[95]=De,t[96]=ye,t[97]=ge):ge=t[97];let Me;t[98]!==Se||t[99]!==ge?(Me=s.jsxs("div",{className:"flex items-baseline justify-between",children:[Se,ge]}),t[98]=Se,t[99]=ge,t[100]=Me):Me=t[100];let Ue;t[101]!==L.usagePercent?(Ue=L.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,L.usagePercent)}%`,backgroundColor:L.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[101]=L.usagePercent,t[102]=Ue):Ue=t[102];let q;t[103]!==Ue?(q=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:Ue}),t[103]=Ue,t[104]=q):q=t[104];let Ie;t[105]!==e||t[106]!==L.usagePercent?(Ie=e("contextSidebar.context.percentUsed",{percent:L.usagePercent.toFixed(1)}),t[105]=e,t[106]=L.usagePercent,t[107]=Ie):Ie=t[107];let Le;t[108]!==Ie?(Le=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Ie}),t[108]=Ie,t[109]=Le):Le=t[109];let Pe;t[110]!==Me||t[111]!==q||t[112]!==Le?(Pe=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Me,q,Le]}),t[110]=Me,t[111]=q,t[112]=Le,t[113]=Pe):Pe=t[113];let he;t[114]!==e?(he=e("contextSidebar.stats.messages"),t[114]=e,t[115]=he):he=t[115];let F;t[116]!==L.messagesCount?(F=Za(L.messagesCount),t[116]=L.messagesCount,t[117]=F):F=t[117];let ee;t[118]!==he||t[119]!==F?(ee={label:he,value:F},t[118]=he,t[119]=F,t[120]=ee):ee=t[120];let Ce;t[121]!==e?(Ce=e("contextSidebar.stats.user"),t[121]=e,t[122]=Ce):Ce=t[122];let Fe;t[123]!==L.userMessagesCount?(Fe=Za(L.userMessagesCount),t[123]=L.userMessagesCount,t[124]=Fe):Fe=t[124];let we;t[125]!==Ce||t[126]!==Fe?(we={label:Ce,value:Fe},t[125]=Ce,t[126]=Fe,t[127]=we):we=t[127];let Qe;t[128]!==e?(Qe=e("contextSidebar.stats.assistant"),t[128]=e,t[129]=Qe):Qe=t[129];let pe;t[130]!==L.assistantMessagesCount?(pe=Za(L.assistantMessagesCount),t[130]=L.assistantMessagesCount,t[131]=pe):pe=t[131];let Oe;t[132]!==Qe||t[133]!==pe?(Oe={label:Qe,value:pe},t[132]=Qe,t[133]=pe,t[134]=Oe):Oe=t[134];let nt;t[135]!==e?(nt=e("contextSidebar.stats.cost"),t[135]=e,t[136]=nt):nt=t[136];let Re;t[137]!==L.totalAssistantCost?(Re=Y2(L.totalAssistantCost),t[137]=L.totalAssistantCost,t[138]=Re):Re=t[138];let de;t[139]!==nt||t[140]!==Re?(de={label:nt,value:Re},t[139]=nt,t[140]=Re,t[141]=de):de=t[141];let He;t[142]!==ee||t[143]!==we||t[144]!==Oe||t[145]!==de?(He=[ee,we,Oe,de],t[142]=ee,t[143]=we,t[144]=Oe,t[145]=de,t[146]=He):He=t[146];const st=He;let qe;t[147]!==st?(qe=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:st.map(lS)}),t[147]=st,t[148]=qe):qe=t[148];let et;t[149]!==e?(et=e("contextSidebar.section.lastAssistantMessage"),t[149]=e,t[150]=et):et=t[150];let rt;t[151]!==et?(rt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:et}),t[151]=et,t[152]=rt):rt=t[152];let xe;t[153]!==e||t[154]!==L.tokenBreakdown.cacheRead||t[155]!==L.tokenBreakdown.cacheWrite||t[156]!==L.tokenBreakdown.input||t[157]!==L.tokenBreakdown.output||t[158]!==L.tokenBreakdown.reasoning?(xe=s.jsx("div",{className:"mt-2.5 grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:L.tokenBreakdown.input},{label:e("contextSidebar.tokens.output"),value:L.tokenBreakdown.output},{label:e("contextSidebar.tokens.reasoning"),value:L.tokenBreakdown.reasoning},{label:e("contextSidebar.tokens.cacheRead"),value:L.tokenBreakdown.cacheRead},{label:e("contextSidebar.tokens.cacheWrite"),value:L.tokenBreakdown.cacheWrite}].map(cS)}),t[153]=e,t[154]=L.tokenBreakdown.cacheRead,t[155]=L.tokenBreakdown.cacheWrite,t[156]=L.tokenBreakdown.input,t[157]=L.tokenBreakdown.output,t[158]=L.tokenBreakdown.reasoning,t[159]=xe):xe=t[159];let Ye;t[160]!==rt||t[161]!==xe?(Ye=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[rt,xe]}),t[160]=rt,t[161]=xe,t[162]=Ye):Ye=t[162];let _e;t[163]!==ce||t[164]!==L.breakdownTotal?(_e=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ce.map(wt=>wt.value<=0||L.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${wt.value/L.breakdownTotal*100}%`,backgroundColor:wt.color}},wt.key))}),t[163]=ce,t[164]=L.breakdownTotal,t[165]=_e):_e=t[165];let We;t[166]!==ce||t[167]!==L.breakdownTotal?(We=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:ce.map(wt=>{const Dt=L.breakdownTotal>0?wt.value/L.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:wt.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[wt.label," ",s.jsxs("span",{className:"tabular-nums",children:[Dt.toFixed(0),"%"]})]})]},wt.key)})}),t[166]=ce,t[167]=L.breakdownTotal,t[168]=We):We=t[168];let lt;t[169]!==_e||t[170]!==We?(lt=s.jsxs("div",{className:"mb-6",children:[_e,We]}),t[169]=_e,t[170]=We,t[171]=lt):lt=t[171];let Je;t[172]!==e?(Je=e("contextSidebar.section.rawMessages"),t[172]=e,t[173]=Je):Je=t[173];let Ve;t[174]!==Je?(Ve=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Je}),t[174]=Je,t[175]=Ve):Ve=t[175];let yt;if(t[176]!==d||t[177]!==o||t[178]!==b||t[179]!==a||t[180]!==e){let wt;t[182]!==d||t[183]!==o||t[184]!==a||t[185]!==e?(wt=Dt=>{const Xt=oo(Dt.info).role,Yt=o[Dt.info.id]===!0,ts=d===Dt.info.id,dt=Dt.info.time?.created??null,Rt=Yt?JSON.stringify({info:Dt.info,parts:Dt.parts},null,2):"";return s.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[s.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":Yt,onClick:()=>{c(is=>({...is,[Dt.info.id]:is[Dt.info.id]!==!0}))},children:s.jsxs("div",{className:"flex items-center justify-between gap-2 whitespace-nowrap overflow-hidden",children:[s.jsxs("span",{className:"min-w-0 inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:X2(Xt)}),s.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground",children:Dt.info.id})]}),s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:Q2(dt)})]})}),Yt&&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:is=>{is.stopPropagation(),k(Dt.info.id,Rt)},"aria-label":e(ts?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(ts?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:ts?s.jsx(I,{name:"check",className:"size-3.5"}):s.jsx(I,{name:"file-copy",className:"size-3.5"})})}),s.jsx(Px,{language:"json",style:a,PreTag:"div",customStyle:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},codeTagProps:{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",overflowWrap:"break-word"}},wrapLongLines:!0,children:Rt})]})})]},Dt.info.id)},t[182]=d,t[183]=o,t[184]=a,t[185]=e,t[186]=wt):wt=t[186],yt=[...b].reverse().map(wt),t[176]=d,t[177]=o,t[178]=b,t[179]=a,t[180]=e,t[181]=yt}else yt=t[181];let $t;t[187]!==yt?($t=s.jsx("div",{className:"mt-2.5 space-y-1",children:yt}),t[187]=yt,t[188]=$t):$t=t[188];let Gt;t[189]!==Ve||t[190]!==$t?(Gt=s.jsxs("div",{children:[Ve,$t]}),t[189]=Ve,t[190]=$t,t[191]=Gt):Gt=t[191];let ss;return t[192]!==Ne||t[193]!==Pe||t[194]!==qe||t[195]!==Ye||t[196]!==lt||t[197]!==Gt?(ss=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:[Ne,Pe,qe,Ye,lt,Gt]})}),t[192]=Ne,t[193]=Pe,t[194]=qe,t[195]=Ye,t[196]=lt,t[197]=Gt,t[198]=ss):ss=t[198],ss};function tS(t){return t.currentSessionId}function sS(t){return t.providers}function nS(t){return Object.keys(t).length>0?{}:t}function rS(t){return oo(t.info).role==="assistant"}function aS(t){return oo(t.info).isUser}function iS(t,e){const n=wa(e.info.cost);return t+n}function oS(t){return oo(t.info).isUser&&typeof t.info.system=="string"}function lS(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 cS(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:Za(t.value)})]},t.label)}const dS=360,uS=1400,og=600,mS=24,ep=200,pS=(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",xd=t=>{if(!t||typeof t!="object")return!1;const e=t,n=e.bounds;return typeof e.tag=="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"},lg=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:a,intro:i})=>{const o=r.text.trim(),c=Object.entries(r.attributes).map(([b,h])=>`${b}="${h}"`).join(" "),d=r.computedStyle,p=r.bounds,m=r.center,u=i.replace(/[.:]+$/g,""),f=r.ancestry.map(b=>b.selectorPart).join(" > ");return[`${u}:`,`Page: ${t||"preview"}`,`Viewport: ${e.width}x${e.height}, DPR ${n}`,`Screenshot: ${a?"attached":"not attached"}`,`Element: ${r.tag}`,o?`Text: ${o}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,f?`- Ancestry: ${f}`:null,c?`- Attributes: ${c}`:null,`- Bounds: x=${Math.round(p.x)}, y=${Math.round(p.y)}, width=${Math.round(p.width)}, height=${Math.round(p.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(b=>typeof b=="string").join(`
|
|
56
|
+
`)},fS=async(t,e)=>{const n=typeof window<"u"?window.__TAURI__:void 0;if(typeof n?.core?.invoke=="function")try{const r=t.getBoundingClientRect(),a=await n.core.invoke("desktop_capture_page_rect",{x:r.left,y:r.top,width:r.width,height:r.height}),i=new Image;await new Promise((v,x)=>{i.onload=()=>v(),i.onerror=()=>x(new Error("Failed to load desktop preview screenshot")),i.src=`data:${a.mime};base64,${a.base64}`});const o=Math.max(1,i.naturalWidth||a.width||Math.floor(r.width)),c=Math.max(1,i.naturalHeight||a.height||Math.floor(r.height)),p=Math.min(1,1200/o),m=document.createElement("canvas");m.width=Math.floor(o*p),m.height=Math.floor(c*p);const u=m.getContext("2d");if(!u)return null;u.scale(p,p),u.drawImage(i,0,0,o,c);const f=o/Math.max(1,r.width),b=c/Math.max(1,r.height);u.fillStyle="rgba(37, 99, 235, 0.28)",u.strokeStyle="rgb(37, 99, 235)",u.lineWidth=Math.max(2,2*f),u.fillRect(e.bounds.x*f,e.bounds.y*b,e.bounds.width*f,e.bounds.height*b),u.strokeRect(e.bounds.x*f,e.bounds.y*b,e.bounds.width*f,e.bounds.height*b);const h=await new Promise(v=>m.toBlob(v,"image/jpeg",.82));return h?new File([h],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(r){return console.warn("[preview] failed to capture annotation screenshot:",r),null}return null},hS=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},tp=t=>Number.isFinite(t)?Math.min(uS,Math.max(dS,Math.round(t))):og,gS=(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},xS=(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"),bS=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},yS=(t,e)=>{if(t.label)return t.label;if(t.mode==="file")return bS(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 xS(t.mode,e)},vS=t=>{if(t.mode==="file")return t.targetPath?s.jsx(jr,{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"})},wS=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,jS=`new Promise((resolve) => {
|
|
57
|
+
const existing = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
58
|
+
if (existing) existing.remove();
|
|
59
|
+
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
60
|
+
try { window.__openchamberDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
|
|
61
|
+
}
|
|
62
|
+
const overlay = document.createElement('div');
|
|
63
|
+
overlay.id = '__openchamber_desktop_browser_overlay';
|
|
64
|
+
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;';
|
|
65
|
+
document.documentElement.appendChild(overlay);
|
|
66
|
+
const cssEscape = (value) => {
|
|
67
|
+
try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
|
|
68
|
+
};
|
|
69
|
+
const selectorPart = (element) => {
|
|
70
|
+
const tag = element.tagName.toLowerCase();
|
|
71
|
+
if (element.id) return tag + '#' + cssEscape(element.id);
|
|
72
|
+
const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
|
|
73
|
+
return tag + className;
|
|
74
|
+
};
|
|
75
|
+
const metadata = (element) => {
|
|
76
|
+
const rect = element.getBoundingClientRect();
|
|
77
|
+
const style = getComputedStyle(element);
|
|
78
|
+
const ancestry = [];
|
|
79
|
+
let current = element;
|
|
80
|
+
while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
|
|
81
|
+
ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
|
|
82
|
+
current = current.parentElement;
|
|
83
|
+
}
|
|
84
|
+
const attrs = {};
|
|
85
|
+
for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
|
|
86
|
+
const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
|
|
87
|
+
return {
|
|
88
|
+
frame: 'top',
|
|
89
|
+
tag: element.tagName.toLowerCase(),
|
|
90
|
+
text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
|
|
91
|
+
selector: element.id ? '#' + cssEscape(element.id) : path,
|
|
92
|
+
path,
|
|
93
|
+
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
94
|
+
center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
|
|
95
|
+
attributes: attrs,
|
|
96
|
+
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 },
|
|
97
|
+
ancestry,
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
const move = (event) => {
|
|
101
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
102
|
+
if (!element || element === overlay || element === document.documentElement || element === document.body) return;
|
|
103
|
+
const rect = element.getBoundingClientRect();
|
|
104
|
+
overlay.style.display = 'block';
|
|
105
|
+
overlay.style.left = rect.left + 'px';
|
|
106
|
+
overlay.style.top = rect.top + 'px';
|
|
107
|
+
overlay.style.width = rect.width + 'px';
|
|
108
|
+
overlay.style.height = rect.height + 'px';
|
|
109
|
+
};
|
|
110
|
+
const cleanup = () => {
|
|
111
|
+
window.removeEventListener('mousemove', move, true);
|
|
112
|
+
window.removeEventListener('click', click, true);
|
|
113
|
+
window.removeEventListener('keydown', keydown, true);
|
|
114
|
+
if (window.__openchamberDesktopBrowserCancelInspect === cancel) {
|
|
115
|
+
delete window.__openchamberDesktopBrowserCancelInspect;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const cancel = () => {
|
|
119
|
+
cleanup();
|
|
120
|
+
overlay.remove();
|
|
121
|
+
resolve(null);
|
|
122
|
+
};
|
|
123
|
+
const click = (event) => {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
event.stopPropagation();
|
|
126
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
127
|
+
const result = element ? metadata(element) : null;
|
|
128
|
+
cleanup();
|
|
129
|
+
overlay.remove();
|
|
130
|
+
resolve(result);
|
|
131
|
+
};
|
|
132
|
+
const keydown = (event) => {
|
|
133
|
+
if (event.key !== 'Escape') return;
|
|
134
|
+
cancel();
|
|
135
|
+
};
|
|
136
|
+
window.__openchamberDesktopBrowserCancelInspect = cancel;
|
|
137
|
+
window.addEventListener('mousemove', move, true);
|
|
138
|
+
window.addEventListener('click', click, true);
|
|
139
|
+
window.addEventListener('keydown', keydown, true);
|
|
140
|
+
});`,Nc=`(() => {
|
|
141
|
+
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
142
|
+
window.__openchamberDesktopBrowserCancelInspect();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
146
|
+
if (overlay) overlay.remove();
|
|
147
|
+
})()`,Sc=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"}},NS=async(t,e,n,r,a,i)=>{if(!t)return null;try{const o=new Image;await new Promise((x,g)=>{o.onload=()=>x(),o.onerror=()=>g(new Error("Failed to load desktop browser screenshot")),o.src=`data:image/jpeg;base64,${t}`});const c=Math.max(1,o.naturalWidth||e),d=Math.max(1,o.naturalHeight||n),m=Math.min(1,1200/c),u=document.createElement("canvas");u.width=Math.floor(c*m),u.height=Math.floor(d*m);const f=u.getContext("2d");if(!f)return null;f.scale(m,m),f.drawImage(o,0,0,c,d);const b=c/Math.max(1,r||c),h=d/Math.max(1,a||d);f.fillStyle="rgba(37, 99, 235, 0.14)",f.strokeStyle="rgb(37, 99, 235)",f.lineWidth=Math.max(2,2*b),f.fillRect(i.bounds.x*b,i.bounds.y*h,i.bounds.width*b,i.bounds.height*h),f.strokeRect(i.bounds.x*b,i.bounds.y*h,i.bounds.width*b,i.bounds.height*h);const v=await new Promise(x=>u.toBlob(x,"image/jpeg",.82));return v?new File([v],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},SS=(t,e,n)=>{if(typeof window>"u")return"";const r=new URL(window.location.pathname,window.location.origin);return r.searchParams.set("ocPanel","session-chat"),r.searchParams.set("sessionId",t),n?r.searchParams.set("readOnly","1"):r.searchParams.delete("readOnly"),e&&e.trim().length>0?r.searchParams.set("directory",e):r.searchParams.delete("directory"),r.hash="",r.toString()},kS=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,Na=new Map,CS=3e4,IS=t=>{const e=Na.get(t);return e?e.expiresAt-Date.now()<=CS?(Na.delete(t),null):e:null},PS=({rawUrl:t,onNavigate:e})=>{const{t:n}=mt(),{currentTheme:r}=Cr(),[a,i]=l.useReducer(ie=>ie+1,0),[o,c]=l.useReducer(ie=>ie+1,0),[d,p]=l.useState({status:"idle"}),m=l.useRef(null),u=l.useRef(1),[f,b]=l.useState(!1),[h,v]=l.useState(!1),[x,g]=l.useState("all"),[w,y]=l.useState([]),[k,D]=l.useState(!1),[j,S]=l.useState(null),A=_t(ie=>ie.currentSessionId),E=_t(ie=>ie.newSessionDraft?.open),P=ti(ie=>ie.addDraft),C=Ea(ie=>ie.addAttachedFile);let N=null;try{N=t?new URL(t):null}catch{N=null}const T=N?N.hostname==="localhost"||N.hostname==="127.0.0.1"||N.hostname==="::1"||N.hostname==="[::1]"||N.hostname==="0.0.0.0":!1,M=N?N.hostname==="0.0.0.0"?new URL(N.toString().replace("0.0.0.0","127.0.0.1")):N:null,R=M?M.toString():"",O=r.metadata.variant;l.useEffect(()=>{if(!R||!T){p({status:"idle"});return}const ie=IS(R);if(ie){p({status:"ready",proxyBasePath:ie.proxyBasePath,expiresAt:ie.expiresAt});return}let fe=!1;return p({status:"loading"}),(async()=>{try{const H=await fetch("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:R})});if(!H.ok){Na.delete(R);const te=await H.json().catch(()=>({})),ke=typeof te?.error=="string"?te.error:`HTTP ${H.status}`;fe||p({status:"error",message:ke});return}const ce=await H.json(),se=typeof ce.proxyBasePath=="string"?ce.proxyBasePath:"",oe=typeof ce.expiresAt=="number"?ce.expiresAt:0;if(!se){Na.delete(R),fe||p({status:"error",message:n("contextPanel.preview.proxyError")});return}Na.set(R,{proxyBasePath:se,expiresAt:oe}),fe||p({status:"ready",proxyBasePath:se,expiresAt:oe})}catch(H){if(Na.delete(R),!fe){const ce=H instanceof Error?H.message:String(H);p({status:"error",message:ce})}}})(),()=>{fe=!0}},[T,o,n,R]);const z=M&&(M.protocol==="http:"||M.protocol==="https:")?M.toString():"",B=T&&d.status==="ready"&&M?(()=>{const ie=M.pathname||"/",fe=new URLSearchParams(M.search);fe.set("ocPreview",String(a));const H=fe.toString(),ce=M.hash||"";return`${d.proxyBasePath}${ie}${H?`?${H}`:""}${ce}`})():"",$=T?B:z,_=$||z,Q=T&&(d.status==="loading"||d.status==="idle"),W=T&&d.status==="error",ne=l.useCallback(ie=>{const fe=A??(E?"draft":null);if(!fe){G.error(n("contextPanel.preview.inspect.attachNoSession"));return}const H=t||$||"",ce=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},se=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let oe=!1;try{const te=m.current,ke=te?await fS(te,ie):null;ke&&(await C(ke),oe=!0)}catch{oe=!1}P({sessionKey:fe,source:"preview-annotation",fileLabel:H||"preview",startLine:1,endLine:1,code:lg({pageUrl:H,viewport:ce,devicePixelRatio:se,target:ie,screenshotAttached:oe,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),G.success(n("contextPanel.preview.inspect.attached"))})()},[C,P,A,$,E,t,n]);l.useEffect(()=>{b(!1),y([]),v(!1),g("all"),D(!1),S(null),u.current=1},[$]),l.useEffect(()=>{const ie=m.current?.contentWindow;!f||!ie||ie.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:k},window.location.origin)},[f,k]),l.useEffect(()=>{const ie=m.current?.contentWindow;!f||!ie||ie.postMessage({source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:O},window.location.origin)},[f,O]),l.useEffect(()=>{if(!k||typeof window>"u")return;const ie=fe=>{fe.key==="Escape"&&(fe.preventDefault(),fe.stopImmediatePropagation(),D(!1))};return window.addEventListener("keydown",ie,!0),()=>window.removeEventListener("keydown",ie,!0)},[k]),l.useEffect(()=>{if(!T||typeof window>"u")return;const ie=ce=>{if(typeof ce=="string")return ce;if(ce==null)return"";try{return JSON.stringify(ce)}catch{return String(ce)}},fe=ce=>{const se=u.current;u.current+=1,y(oe=>{const te=[...oe,{...ce,id:se}];return te.length>ep?te.slice(te.length-ep):te})},H=ce=>{if(ce.source!==m.current?.contentWindow)return;const se=ce.data;if(!(!se||se.source!=="openchamber-preview-bridge"||se.version!==1)){if(se.type==="ready"){b(!0);return}if(se.type==="console"){const oe=se.level==="error"||se.level==="warn"||se.level==="info"||se.level==="debug"?se.level:"log",te=Array.isArray(se.args)?se.args.map(ie).filter(Boolean):[];fe({level:oe,message:te.join(" "),ts:typeof se.ts=="number"?se.ts:Date.now()});return}if(se.type==="runtime-error"){const oe=ie(se.filename),te=typeof se.line=="number"?se.line:null,ke=typeof se.column=="number"?se.column:null,Ne=oe?`${oe}${te!==null?`:${te}${ke!==null?`:${ke}`:""}`:""}`:"",je=ie(se.stack);fe({level:"runtime",message:ie(se.message)||n("contextPanel.preview.console.runtimeError"),details:[Ne,je].filter(Boolean).join(`
|
|
148
|
+
`),ts:typeof se.ts=="number"?se.ts:Date.now()});return}if(se.type==="resource-error"){const oe=ie(se.tag)||"resource",te=ie(se.url);fe({level:"resource",message:te?`${oe}: ${te}`:oe,details:ie(se.outerHTML),ts:typeof se.ts=="number"?se.ts:Date.now()});return}if(se.type==="hover"){S(xd(se.target)?se.target:null);return}if(se.type==="select"&&xd(se.target)){S(se.target),D(!1),ne(se.target);return}if(se.type==="navigate-preview"){const oe=typeof se.url=="string"?se.url:"",te=se.navigation==="external"?"external":"proxy";if(oe&&te==="external"){sr(oe);return}oe&&e(oe)}}};return window.addEventListener("message",H),()=>{window.removeEventListener("message",H)}},[ne,T,e,n]);const re=w.filter(ie=>ie.level==="error"||ie.level==="runtime"||ie.level==="resource").length,ue=w.filter(ie=>pS(ie,x)),Y=l.useCallback(()=>{const ie=[`Preview URL: ${t||$||""}`,`Events: ${w.length}`,""].join(`
|
|
149
|
+
`),fe=w.map(H=>{const ce=new Date(H.ts).toISOString(),se=H.details?`
|
|
150
|
+
${H.details}`:"";return`[${ce}] [${H.level}] ${H.message}${se}`}).join(`
|
|
151
|
+
`);Rn(`${ie}${fe}`).then(H=>{H.ok?G.success(n("contextPanel.preview.console.copied")):G.error(n("contextPanel.preview.console.copyFailed"))})},[w,$,t,n]),le=l.useCallback(()=>{const ie=A??(E?"draft":null);if(!ie){G.error(n("contextPanel.preview.console.attachNoSession"));return}const fe=[`Preview URL: ${t||$||""}`,`Events: ${w.length}`,""].join(`
|
|
152
|
+
`),H=w.map(ce=>{const se=new Date(ce.ts).toISOString(),oe=ce.details?`
|
|
153
|
+
${ce.details}`:"";return`[${se}] [${ce.level}] ${ce.message}${oe}`}).join(`
|
|
154
|
+
`);P({sessionKey:ie,source:"preview-console",fileLabel:t||$||"preview",startLine:1,endLine:Math.max(1,w.length),code:`${fe}${H}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),G.success(n("contextPanel.preview.console.attached"))},[P,w,A,$,E,t,n]),[J,L]=l.useState("unknown"),V=l.useRef(0),K=l.useRef(0),X=15e3;l.useEffect(()=>{if(!B){L("unknown"),V.current=0,K.current=0;return}let ie=!1;return V.current||(V.current=Date.now(),K.current=0),L("unknown"),(async()=>{const H=await(async()=>{try{return await fetch(B,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(ie)return;if(!H){L("unreachable");return}if(H.status===403||H.status===404){Na.delete(R),p({status:"loading"}),c();return}if(H.status!==502){L("reachable");return}const ce=V.current||Date.now();if(Date.now()-ce<X){L("starting"),K.current+=1;const oe=K.current,te=Math.min(2e3,250*Math.pow(2,Math.min(4,oe)));setTimeout(()=>{ie||i()},te).unref?.();return}L("unreachable")})(),()=>{ie=!0}},[B,a,R]);const U=T&&d.status==="ready"&&(J==="unknown"||J==="starting"),ae=T&&d.status==="ready"&&J==="unreachable",ve=l.useCallback(ie=>{if(!T||d.status!=="ready"||typeof window>"u")return;const fe=ie.currentTarget.contentWindow;if(fe)try{const H=fe.location;if(H.origin!==window.location.origin||H.pathname.startsWith(d.proxyBasePath))return;const ce=`${d.proxyBasePath}${H.pathname}${H.search}${H.hash}`;fe.location.replace(ce)}catch{}},[T,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:_||t,children:_||t||n("contextPanel.preview.empty")}),s.jsx(be,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>i(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!$,children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(be,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{z&&sr(z)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!z,children:s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"})}),T?s.jsx(be,{type:"button",size:"sm",variant:k?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>D(ie=>!ie),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!f,children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}):null,T?s.jsxs(be,{type:"button",size:"sm",variant:h?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>v(ie=>!ie),title:n(f?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),"aria-label":n(f?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),disabled:!f&&w.length===0,children:[s.jsx(I,{name:"terminal-box",className:"h-3.5 w-3.5"}),re>0?s.jsx("span",{className:"typography-micro text-status-error",children:re}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[U?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")})]}):ae?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(be,{type:"button",size:"sm",variant:"outline",onClick:()=>i(),children:n("contextPanel.preview.actions.retry")})]}):$&&(!T||J==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:m,src:$,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:O},onLoad:ve,sandbox:T?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${$}:${a}`),k&&j?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:j.bounds.x,top:j.bounds.y,width:j.bounds.width,height:j.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[j.tag,j.text?` · ${j.text}`:""]})}):null]}):Q?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):W?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")}),h?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(be,{type:"button",size:"xs",variant:"ghost",onClick:le,disabled:w.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(be,{type:"button",size:"xs",variant:"ghost",onClick:Y,disabled:w.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(be,{type:"button",size:"xs",variant:"ghost",onClick:()=>y([]),disabled:w.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(ie=>s.jsx(be,{type:"button",size:"xs",variant:x===ie?"secondary":"ghost",onClick:()=>g(ie),children:n(ie==="all"?"contextPanel.preview.console.filter.all":ie==="errors"?"contextPanel.preview.console.filter.errors":ie==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},ie))}),s.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:w.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.empty")}):ue.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):ue.map(ie=>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:me("shrink-0 uppercase",ie.level==="error"||ie.level==="runtime"||ie.level==="resource"?"text-status-error":ie.level==="warn"?"text-status-warning":"text-muted-foreground"),children:ie.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:ie.message})]})},ie.id))})]}):null]})]})},AS=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=mt(),a=l.useRef(null),i=Te(E=>E.setContextPanelTabTargetPath),o=Sc(t),c=o!=="about:blank"?o:"",[d,p]=l.useState(c),[m,u]=l.useState(c),[f,b]=l.useState(!1),[h,v]=l.useState(!0),x=l.useRef(null),g=h,w=l.useCallback(E=>{!E||E==="about:blank"||!e||!n||i(e,n,E)},[e,n,i]),y=_t(E=>E.currentSessionId),k=_t(E=>E.newSessionDraft?.open),D=ti(E=>E.addDraft),j=Ea(E=>E.addAttachedFile);l.useEffect(()=>{const E=a.current;if(!E)return;const P=()=>{try{const R=E.getURL();R&&R!=="about:blank"&&(u(R),p(R),w(R))}catch{}},C=R=>{const O=R.detail;typeof O?.url=="string"&&O.url&&(u(O.url),p(O.url),w(O.url))},N=()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>v(!0),200)},T=()=>{x.current&&clearTimeout(x.current),v(!1),P()},M=R=>{const O=R.detail;if(O?.disposition==="new-window"||O?.disposition==="foreground-tab"||O?.disposition==="background-tab"){R.preventDefault();const z=a.current;typeof z?.loadURL=="function"&&O.url&&z.loadURL(O.url)}};E.addEventListener("did-navigate",C),E.addEventListener("did-navigate-in-page",C),E.addEventListener("did-start-loading",N),E.addEventListener("did-stop-loading",T),E.addEventListener("new-window",M);try{E.isLoading()||(v(!1),P())}catch{}return()=>{x.current&&clearTimeout(x.current),E.removeEventListener("did-navigate",C),E.removeEventListener("did-navigate-in-page",C),E.removeEventListener("did-start-loading",N),E.removeEventListener("did-stop-loading",T),E.removeEventListener("new-window",M)}},[w]),l.useEffect(()=>{const E=setTimeout(()=>v(!1),3e4);return()=>clearTimeout(E)},[]),l.useEffect(()=>{if(!f)return;const E=P=>{if(P.key!=="Escape")return;P.preventDefault(),P.stopImmediatePropagation(),b(!1);const C=a.current;try{C?.executeJavaScript?.(Nc).catch(()=>{})}catch{}};return window.addEventListener("keydown",E,!0),()=>window.removeEventListener("keydown",E,!0)},[f]),l.useEffect(()=>{const E=a.current;return()=>{try{const P=E?.getURL?.();P&&P!=="about:blank"&&i(e,n,P)}catch{}try{E?.executeJavaScript?.(Nc).catch(()=>{})}catch{}}},[e,n,i]);const S=l.useCallback(E=>{const P=a.current;if(typeof P?.loadURL!="function")return;const C=Sc(E);try{P.loadURL(C)}catch{}},[]),A=l.useCallback(()=>{const E=a.current;if(E){if(f){b(!1);try{E.executeJavaScript?.(Nc).catch(()=>{})}catch{}return}b(!0),E.executeJavaScript?.(jS,!0).then(async P=>{if(b(!1),!P||!xd(P))return;const C=y??(k?"draft":null);if(!C){G.error(r("contextPanel.preview.inspect.attachNoSession"));return}const N=typeof E.getWebContentsId=="function"?E.getWebContentsId():null;if(N==null)return;const T=await Tb("desktop_browser_capture_page",{webContentsId:N}),M=await E.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),R=Number.isFinite(M?.width)?M.width:T.width,O=Number.isFinite(M?.height)?M.height:T.height,z=await NS(T.base64,T.width,T.height,R,O,P),B=!!z;z&&await j(z),D({sessionKey:C,source:"preview-annotation",fileLabel:m||"browser",startLine:1,endLine:1,code:lg({pageUrl:m,viewport:{width:R,height:O},devicePixelRatio:window.devicePixelRatio||1,target:P,screenshotAttached:B,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),G.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>b(!1))}},[j,D,y,m,f,k,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(be,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.goBack?.()}catch{}},children:s.jsx(I,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(be,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.goForward?.()}catch{}},children:s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(be,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.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:E=>{E.preventDefault(),S(d)},children:s.jsx("input",{value:d,onChange:E=>p(E.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(be,{type:"button",variant:f?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:A,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(be,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{sr(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:a,src:Sc(t),partition:"persist:openchamber-browser",style:{width:"100%",height:"100%",border:"none"}}),(!m||m==="about:blank")&&!h?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(zd,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")})]}):null,g?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]})]})},DS=()=>{const{t}=mt(),e=Lr()??"",n=l.useMemo(()=>hS(e),[e]),r=Te(U=>n?U.contextPanelByDirectory[n]:void 0),a=Te(U=>U.closeContextPanel),i=Te(U=>U.closeContextPanelTab),o=Te(U=>U.toggleContextPanelExpanded),c=Te(U=>U.setContextPanelWidth),d=Te(U=>U.setActiveContextPanelTab),p=Te(U=>U.reorderContextPanelTabs),m=Te(U=>U.setPendingDiffFile),u=Bn(U=>U.setSelectedPath),f=Te(U=>U.openContextPreview),{themeMode:b,lightThemeId:h,darkThemeId:v,currentTheme:x}=Cr(),g=l.useMemo(()=>r?.tabs??[],[r?.tabs]),w=g.find(U=>U.id===r?.activeTabId)??g[g.length-1]??null,y=!!(r?.isOpen&&w),k=!!(y&&r?.expanded),D=tp(r?.width??og),[j,S]=l.useState(!1),A=l.useRef(0),E=l.useRef(D),P=l.useRef(null),C=l.useRef(null),N=l.useRef(null),T=l.useRef(new Map),M=l.useRef(!1);l.useEffect(()=>{if(!y||M.current){M.current=y;return}const U=window.requestAnimationFrame(()=>{N.current?.focus({preventScroll:!0})});return M.current=!0,()=>window.cancelAnimationFrame(U)},[y]);const R=l.useCallback(U=>{const ae=N.current;ae&&ae.style.setProperty("--oc-context-panel-width",`${U}px`)},[]),O=l.useCallback(U=>{if(!(!y||k||!n)){try{U.currentTarget.setPointerCapture(U.pointerId)}catch{}C.current=U.pointerId,S(!0),A.current=U.clientX,E.current=D,P.current=D,R(D),U.preventDefault()}},[R,n,k,y,D]),z=l.useCallback(U=>{if(!j||C.current!==U.pointerId)return;const ae=A.current-U.clientX,ve=tp(E.current+ae);P.current!==ve&&(P.current=ve,R(ve))},[R,j]),B=l.useCallback(U=>{if(C.current!==U.pointerId||!n)return;try{U.currentTarget.releasePointerCapture(U.pointerId)}catch{}const ae=P.current??D;S(!1),C.current=null,P.current=null,c(n,ae)},[n,c,D]);l.useEffect(()=>{j||(P.current=null)},[j]);const $=l.useCallback(()=>{n&&a(n)},[a,n]),_=l.useCallback(()=>{n&&o(n)},[n,o]),Q=l.useCallback(U=>{U.key==="Escape"&&(U.preventDefault(),U.stopPropagation(),$())},[$]);l.useEffect(()=>{if(!(!n||!w)){if(w.mode==="file"&&w.targetPath){u(n,w.targetPath);return}w.mode==="diff"&&w.targetPath&&m(w.targetPath)}},[w,n,m,u]);const W=w?.mode==="chat"?w.id:null,ne=l.useCallback(()=>{if(typeof window>"u")return;const U={themeMode:b,lightThemeId:h,darkThemeId:v,currentTheme:x};for(const ae of T.current.values()){const ve=ae.contentWindow;if(!ve)continue;const ie=ve.__openchamberApplyThemeSync;if(typeof ie=="function")try{ie(U);continue}catch{}ve.postMessage({type:"openchamber:theme-sync",payload:U},window.location.origin)}},[x,v,h,b]),re=l.useCallback(()=>{if(!(typeof window>"u"))for(const[U,ae]of T.current.entries()){const ve=ae.contentWindow;if(!ve)continue;const ie={visible:W===U},fe=ve.__openchamberSetEmbeddedVisibility;if(typeof fe=="function")try{fe(ie);continue}catch{}ve.postMessage({type:"openchamber:embedded-visibility",payload:ie},window.location.origin)}},[W]);l.useLayoutEffect(()=>{g.some(ae=>ae.mode==="chat")&&(ne(),re())},[v,h,re,ne,g,b]);const ue=l.useMemo(()=>g.map(U=>{const ae=yS(U,t),ve=kS(ae,mS),ie=gS(U.targetPath,e);return{id:U.id,label:ve,icon:vS(U),title:ie?`${ae}: ${ie}`:ae,closeLabel:t("contextPanel.tab.closeTabAria",{label:ve})}}),[e,t,g]),Y=w?.mode==="diff"?s.jsx(eg,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,hideFileSelector:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0}):w?.mode==="context"?s.jsx(eS,{}):w?.mode==="plan"?s.jsx(ig,{targetPath:w.targetPath}):w?.mode==="preview"?s.jsx(PS,{rawUrl:w.targetPath??"",onNavigate:U=>f(e,U)}):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")})]}),le=l.useMemo(()=>g.filter(U=>U.mode==="chat"),[g]),J=l.useMemo(()=>g.filter(U=>U.mode==="browser"),[g]),L=l.useMemo(()=>g.some(U=>U.mode==="file"),[g]),V=w?.mode==="file",K=s.jsxs("header",{className:"flex h-8 items-stretch border-b border-transparent",children:[s.jsx(Er,{items:ue,activeId:w?.id??null,onSelect:U=>{n&&d(n,U)},onClose:U=>{n&&i(n,U)},onReorder:(U,ae)=>{n&&p(n,U,ae)},layoutMode:"scrollable",variant:"default"}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[s.jsx(be,{type:"button",variant:"ghost",size:"sm",onClick:_,className:"h-7 w-7 p-0",title:t(k?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(k?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:k?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(be,{type:"button",variant:"ghost",size:"sm",onClick:$,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"})})]})]});if(!y)return null;const X=k?{"--oc-context-panel-width":"100%",width:"100%",minWidth:"100%",maxWidth:"100%"}:{width:"var(--oc-context-panel-width)",minWidth:"var(--oc-context-panel-width)",maxWidth:"var(--oc-context-panel-width)","--oc-context-panel-width":`${j?P.current??D:D}px`};return s.jsxs("aside",{ref:N,"data-context-panel":"true",tabIndex:-1,className:me("flex min-h-0 flex-col overflow-hidden bg-background",!k&&"border-l border-border/40",k?"absolute inset-0 z-20 min-w-0":"relative h-full flex-shrink-0",j?"transition-none":"transition-[width] duration-200 ease-in-out"),onKeyDownCapture:Q,style:X,children:[!k&&s.jsx("div",{className:me("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",j&&"bg-[var(--interactive-border)]"),onPointerDown:O,onPointerMove:z,onPointerUp:B,onPointerCancel:B,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),K,s.jsxs("div",{className:me("relative min-h-0 flex-1 overflow-hidden",j&&"pointer-events-none"),children:[L?s.jsx("div",{className:me("absolute inset-0",V?"block":"hidden"),children:s.jsx(ag,{mode:"editor-only"})}):null,le.map(U=>{const ae=wS(U.dedupeKey);if(!ae)return null;const ve=SS(ae,n||null,U.readOnly);return ve?s.jsx("iframe",{ref:ie=>{if(!ie){T.current.delete(U.id);return}T.current.set(U.id,ie)},src:ve,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:ae}),className:me("absolute inset-0 h-full w-full border-0 bg-background",W===U.id?"block":"hidden"),onLoad:()=>{ne(),re()}},U.id):null}),J.map(U=>s.jsx("div",{className:me("absolute inset-0",w?.mode!=="browser"&&"hidden"),children:s.jsx(AS,{initialUrl:U.targetPath??"",directory:n,tabID:U.id})},U.id)),w?.mode!=="chat"&&!V&&w?.mode!=="browser"?Y:null]})]})},eu=[{slug:"home",title:"Settings",group:"general",kind:"single",description:"Search and jump to common pages.",keywords:["search","settings"]},{slug:"projects",title:"Projects",group:"projects",kind:"split",keywords:["project","projects","worktree","worktrees","repo","repository","directory"]},{slug:"remote-instances",title:"Remote Instances",group:"projects",kind:"split",keywords:["ssh","remote","instances","tunnels","forwarding","connection"],isAvailable:t=>t.isDesktop&&!t.isWeb&&!t.isVSCode},{slug:"providers",title:"Providers",group:"opencode",kind:"split",keywords:["provider","providers","models","model","api key","api keys","openai","anthropic","ollama","credentials"]},{slug:"usage",title:"Usage",group:"usage",kind:"split",keywords:["quota","billing","tokens","usage","limits"]},{slug:"agents",title:"Agents",group:"opencode",kind:"split",keywords:["agent","agents","prompts","tools","permissions"]},{slug:"behavior",title:"Behavior",group:"opencode",kind:"single",keywords:["behavior","agents.md","system prompt","global rules","instructions","override"]},{slug:"commands",title:"Commands",group:"opencode",kind:"split",keywords:["command","commands","slash","macros","automation"]},{slug:"mcp",title:"MCP",group:"opencode",kind:"split",keywords:["mcp","model context protocol","servers","tools","remote","stdio"]},{slug:"skills.installed",title:"Skills",group:"skills",kind:"split",keywords:["skill","skills","instructions","install","catalog"]},{slug:"skills.catalog",title:"Skills Catalog",group:"skills",kind:"single",keywords:["install","catalog","external","repository","skills catalog"]},{slug:"git",title:"Git",group:"git",kind:"single",keywords:["git","github","identity","identities","ssh","profiles","credentials","keys","commit","gitmoji","oauth","prs","issues"],isAvailable:t=>!t.isVSCode},{slug:"appearance",title:"Appearance",group:"appearance",kind:"single",keywords:["theme","font","spacing","padding","corner radius","radius","input bar","keyboard","viewport","mobile","terminal","pwa","install name","app shortcuts"]},{slug:"chat",title:"Chat",group:"general",kind:"single",keywords:["tools","diff","reasoning","dotfiles","draft","queue","output","copy","image","split messages","message actions"]},{slug:"shortcuts",title:"Shortcuts",group:"general",kind:"single",keywords:["keyboard","hotkeys","shortcuts","bindings"],isAvailable:t=>!t.isVSCode},{slug:"sessions",title:"Sessions",group:"general",kind:"single",keywords:["defaults","default agent","default model","retention","memory","limits","zen"]},{slug:"magic-prompts",title:"Magic Prompts",group:"general",kind:"split",keywords:["prompts","templates","git","github","review","commit","pull request"],isAvailable:t=>!t.isVSCode},{slug:"notifications",title:"Notifications",group:"general",kind:"single",keywords:["alerts","native","summary","summarization"]},{slug:"voice",title:"Voice",group:"advanced",kind:"single",keywords:["tts","speech","voice"],isAvailable:t=>!t.isVSCode},{slug:"tunnel",title:"Remote Tunnel",group:"advanced",kind:"single",keywords:["tunnel","cloudflare","qr","remote","mobile","share"],isAvailable:t=>!t.isVSCode}],TS={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function Oi(t){const e=t.trim().toLowerCase();return eu.find(n=>n.slug===e)??null}function cg(t){const e=(t??"").trim().toLowerCase();if(!e)return"home";const n=TS[e];if(n)return n;const r=Oi(e);return r?r.slug:"home"}const dg=t=>t.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),mo=t=>{const e=at.c(39),{className:n}=t,{t:r}=mt(),a=Ls(MS),i=Ls(ES),o=Ls(RS),c=un();let d;e[0]!==a?(d=[...a].sort(FS),e[0]=a,e[1]=d):d=e[1];const p=d;let m;e:{if(p.length===0){m=null;break e}let M;e[2]!==i||e[3]!==p?(M=p.find(R=>R.id===i)??p[0],e[2]=i,e[3]=p,e[4]=M):M=e[4],m=M}const u=m;if(c||p.length===0)return null;let f;e[5]!==u||e[6]!==r?(f=u?.label&&u.label.trim().length>0?u.label:u?.path.split("/").filter(Boolean).pop()||u?.path||r("settings.shared.projectSelector.fallbackProject"),e[5]=u,e[6]=r,e[7]=f):f=e[7];const b=f;let h;e[8]!==b?(h=dg(b),e[8]=b,e[9]=h):h=e[9];const v=h;let x;e[10]!==n?(x=me(n),e[10]=n,e[11]=x):x=e[11];let g;e[12]!==r?(g=r("settings.shared.projectSelector.switchProjectAria"),e[12]=r,e[13]=g):g=e[13];let w;e[14]!==r?(w=r("settings.shared.projectSelector.switchProjectTitle"),e[14]=r,e[15]=w):w=e[15];let y,k;e[16]===Symbol.for("react.memo_cache_sentinel")?(y=me("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),k=s.jsx(I,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=y,e[17]=k):(y=e[16],k=e[17]);let D;e[18]!==v?(D=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:v}),e[18]=v,e[19]=D):D=e[19];let j;e[20]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=j):j=e[20];let S;e[21]!==D||e[22]!==g||e[23]!==w?(S=s.jsx(Bs,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":g,title:w,className:y,children:[k,D,j]})}),e[21]=D,e[22]=g,e[23]=w,e[24]=S):S=e[24];const A=u?.id??"";let E;e[25]!==o?(E=M=>{M&&o(M)},e[25]=o,e[26]=E):E=e[26];let P;e[27]!==p?(P=p.map(LS),e[27]=p,e[28]=P):P=e[28];let C;e[29]!==A||e[30]!==E||e[31]!==P?(C=s.jsx(zs,{align:"start",className:"w-auto",children:s.jsx(il,{value:A,onValueChange:E,children:P})}),e[29]=A,e[30]=E,e[31]=P,e[32]=C):C=e[32];let N;e[33]!==S||e[34]!==C?(N=s.jsxs(_s,{children:[S,C]}),e[33]=S,e[34]=C,e[35]=N):N=e[35];let T;return e[36]!==N||e[37]!==x?(T=s.jsx("div",{className:x,children:N}),e[36]=N,e[37]=x,e[38]=T):T=e[38],T};function MS(t){return t.projects}function ES(t){return t.activeProjectId}function RS(t){return t.setActiveProject}function FS(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function LS(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,n=dg(e);return s.jsx(ol,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},t.id)}function OS(t,e){return`opencode:sidebar-group:${t}:${e}`}const bd=t=>{const e=at.c(33),{label:n,count:r,storageKey:a,defaultExpanded:i,children:o}=t,c=i===void 0?!0:i;let d;e[0]!==n||e[1]!==a?(d=OS(a,n),e[0]=n,e[1]=a,e[2]=d):d=e[2];const p=d,m=l.useId();let u;e[3]!==c||e[4]!==p?(u=()=>{try{const C=localStorage.getItem(p);if(C!==null)return C==="true"}catch{}return c},e[3]=c,e[4]=p,e[5]=u):u=e[5];const[f,b]=ze.useState(u);let h,v;e[6]!==f||e[7]!==p?(h=()=>{try{localStorage.setItem(p,String(f))}catch{}},v=[p,f],e[6]=f,e[7]=p,e[8]=h,e[9]=v):(h=e[8],v=e[9]),ze.useEffect(h,v);let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=()=>b($S),e[10]=x):x=e[10];let g;e[11]===Symbol.for("react.memo_cache_sentinel")?(g=me("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=g):g=e[11];const w=!f&&"-rotate-90";let y;e[12]!==w?(y=me("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",w),e[12]=w,e[13]=y):y=e[13];let k;e[14]!==y?(k=s.jsx(I,{name:"arrow-down-s",className:y}),e[14]=y,e[15]=k):k=e[15];let D;e[16]!==n?(D=s.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=D):D=e[17];let j;e[18]!==r?(j=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:r}),e[18]=r,e[19]=j):j=e[19];let S;e[20]!==m||e[21]!==f||e[22]!==k||e[23]!==D||e[24]!==j?(S=s.jsxs("button",{type:"button",onClick:x,"aria-expanded":f,"aria-controls":m,className:g,children:[k,D,j]}),e[20]=m,e[21]=f,e[22]=k,e[23]=D,e[24]=j,e[25]=S):S=e[25];const A=!f;let E;e[26]!==o||e[27]!==m||e[28]!==A?(E=s.jsx("div",{id:m,hidden:A,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:o}),e[26]=o,e[27]=m,e[28]=A,e[29]=E):E=e[29];let P;return e[30]!==S||e[31]!==E?(P=s.jsxs("div",{children:[S,E]}),e[30]=S,e[31]=E,e[32]=P):P=e[32],P};function $S(t){return!t}const BS=t=>{if(!Array.isArray(t))return[];const e=[];for(const n of t){if(!n||typeof n!="object")continue;const r=n;typeof r.permission!="string"||typeof r.pattern!="string"||typeof r.action!="string"||r.action!=="allow"&&r.action!=="ask"&&r.action!=="deny"||e.push({permission:r.permission,pattern:r.pattern,action:r.action})}return e},zS=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&e.set(`${n.permission}::${n.pattern}`,n);return Array.from(e.values())},sp=t=>{const e=zS(BS(t));if(e.length===0)return;const n={};for(const a of e)a.permission&&((n[a.permission]||={})[a.pattern]=a.action);const r={};for(const[a,i]of Object.entries(n)){const o=Object.keys(i);if(o.length===1&&o[0]==="*"){r[a]=i["*"];continue}r[a]=i}return Object.keys(r).length>0?r:void 0},_S=({onItemSelect:t})=>{const{t:e}=mt(),[n,r]=l.useState(null),[a,i]=l.useState(""),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(!1),[f,b]=l.useState(null),{selectedAgentName:h,agents:v,setSelectedAgent:x,setAgentDraft:g,createAgent:w,deleteAgent:y,loadAgents:k}=di(br(_=>({selectedAgentName:_.selectedAgentName,agents:_.agents,setSelectedAgent:_.setSelectedAgent,setAgentDraft:_.setAgentDraft,createAgent:_.createAgent,deleteAgent:_.deleteAgent,loadAgents:_.loadAgents})));l.useEffect(()=>{k()},[k]);const D="bg-background",j=()=>{const _="new-agent";let Q=_,W=1;for(;v.some(ne=>ne.name===Q);)Q=`${_}-${W}`,W++;g({name:Q,scope:"user"}),x(Q),t?.()},S=async _=>{if(si(_)){G.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}c(_),p("delete")},A=async _=>{si(_)&&(c(_),p("reset"))},E=()=>{c(null),p(null)},P=async()=>{if(!o||!d)return;u(!0),await y(o.name)?(d==="delete"?G.success(e("settings.agents.sidebar.toast.agentDeleted",{name:o.name})):G.success(e("settings.agents.sidebar.toast.agentReset",{name:o.name})),E()):d==="delete"?G.error(e("settings.agents.sidebar.toast.deleteFailed")):G.error(e("settings.agents.sidebar.toast.resetFailed")),u(!1)},C=_=>{const Q=_.name;let W=1,ne=`${Q}-copy`;for(;v.some(le=>le.name===ne);)W++,ne=`${Q}-copy-${W}`;const re=_,ue=_.model?.providerID&&_.model?.modelID?`${_.model.providerID}/${_.model.modelID}`:null,Y=_;g({name:ne,scope:re.scope||"user",description:_.description,model:ue,temperature:_.temperature,top_p:_.topP,prompt:_.prompt,mode:_.mode,permission:sp(_.permission),disable:Y.disable}),x(ne)},N=_=>{i(_.name),r(_)},T=async()=>{if(!n)return;const _=a.trim().replace(/\s+/g,"-");if(!_){G.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(_===n.name){r(null);return}if(v.some(re=>re.name===_)){G.error(e("settings.agents.sidebar.toast.agentExists"));return}const Q=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,W=n;await w({name:_,description:n.description,model:Q,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:sp(n.permission),disable:W.disable,scope:W.scope})?await y(n.name)?(G.success(`Agent renamed to "${_}"`),x(_)):G.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):G.error(e("settings.agents.sidebar.toast.renameFailed")),r(null)},M=_=>{switch(_){case"primary":return s.jsx(I,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(I,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(I,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},R=v.filter(_=>!Mb(_)),O=R.filter(si),z=R.filter(_=>!si(_)),{groupedCustomAgents:B,ungroupedCustomAgents:$}=ze.useMemo(()=>{const _={},Q=[];for(const ne of z){const re=ne;re.group?(_[re.group]||(_[re.group]=[]),_[re.group].push(ne)):Q.push(ne)}return{groupedCustomAgents:Object.keys(_).sort((ne,re)=>ne.localeCompare(re)).map(ne=>({name:ne,agents:_[ne]})),ungroupedCustomAgents:Q}},[z]);return s.jsxs("div",{className:me("flex h-full flex-col",D),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.agents.sidebar.title")}),s.jsx(mo,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:R.length})}),s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Es,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:R.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(I,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[O.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.builtIn")}),O.map(_=>s.jsx(kc,{agent:_,isSelected:h===_.name,onSelect:()=>{x(_.name),t?.()},onReset:()=>A(_),onDuplicate:()=>C(_),getAgentModeIcon:M,isMenuOpen:f===_.name,onMenuOpenChange:Q=>b(Q?_.name:null)},_.name))]}),z.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),B.map(({name:_,agents:Q})=>s.jsx(bd,{label:_,count:Q.length,storageKey:"agents",children:Q.map(W=>s.jsx(kc,{agent:W,isSelected:h===W.name,onSelect:()=>{x(W.name),t?.()},onRename:()=>N(W),onDelete:()=>S(W),onDuplicate:()=>C(W),getAgentModeIcon:M,isMenuOpen:f===W.name,onMenuOpenChange:ne=>b(ne?W.name:null)},W.name))},_)),$.map(_=>s.jsx(kc,{agent:_,isSelected:h===_.name,onSelect:()=>{x(_.name),t?.()},onRename:()=>N(_),onDelete:()=>S(_),onDuplicate:()=>C(_),getAgentModeIcon:M,isMenuOpen:f===_.name,onMenuOpenChange:Q=>b(Q?_.name:null)},_.name))]})]})}),s.jsx(vs,{open:o!==null&&d!==null,onOpenChange:_=>{!_&&!m&&E()},children:s.jsxs(ys,{className:"max-w-md",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Fs,{children:d==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:o?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:o?.name??""})})]}),s.jsxs(Hs,{children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:E,disabled:m,children:e("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",onClick:P,disabled:m,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(vs,{open:n!==null,onOpenChange:_=>!_&&r(null),children:s.jsxs(ys,{children:[s.jsxs(As,{children:[s.jsx(Ss,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Fs,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),s.jsx(Wt,{value:a,onChange:_=>i(_.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:_=>{_.key==="Enter"&&T()}}),s.jsxs(Hs,{children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>r(null),children:e("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",onClick:T,children:e("settings.common.actions.rename")})]})]})})]})},kc=t=>{const e=at.c(58),{agent:n,isSelected:r,onSelect:a,onDelete:i,onReset:o,onRename:c,onDuplicate:d,getAgentModeIcon:p,isMenuOpen:m,onMenuOpenChange:u}=t,{t:f}=mt(),b=n;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=Ji(),e[0]=h):h=e[0];const v=h,x=r?"bg-interactive-selection":"hover:bg-interactive-hover";let g;e[1]!==x?(g=me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",x),e[1]=x,e[2]=g):g=e[2];let w;e[3]!==u?(w=v?void 0:Q=>{Q.preventDefault(),u(!0)},e[3]=u,e[4]=w):w=e[4];let y;e[5]!==n.name?(y=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=y):y=e[6];let k;e[7]!==n.mode||e[8]!==p?(k=p(n.mode),e[7]=n.mode,e[8]=p,e[9]=k):k=e[9];let D;e[10]!==n||e[11]!==b.scope||e[12]!==f?(D=(b.scope||si(n))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:si(n)?f("settings.agents.sidebar.badge.system"):b.scope}),e[10]=n,e[11]=b.scope,e[12]=f,e[13]=D):D=e[13];let j;e[14]!==y||e[15]!==k||e[16]!==D?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[y,k,D]}),e[14]=y,e[15]=k,e[16]=D,e[17]=j):j=e[17];let S;e[18]!==n.description?(S=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[18]=n.description,e[19]=S):S=e[19];let A;e[20]!==a||e[21]!==j||e[22]!==S?(A=s.jsxs("button",{onClick:a,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[j,S]}),e[20]=a,e[21]=j,e[22]=S,e[23]=A):A=e[23];let E;e[24]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(Bs,{asChild:!0,children:s.jsx(be,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[24]=E):E=e[24];let P;e[25]!==c||e[26]!==f?(P=c&&s.jsxs(Vt,{onClick:Q=>{Q.stopPropagation(),c()},children:[s.jsx(I,{name:"edit",className:"h-4 w-4 mr-px"}),f("settings.common.actions.rename")]}),e[25]=c,e[26]=f,e[27]=P):P=e[27];let C;e[28]!==d?(C=Q=>{Q.stopPropagation(),d()},e[28]=d,e[29]=C):C=e[29];let N;e[30]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(I,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[30]=N):N=e[30];let T;e[31]!==f?(T=f("settings.common.actions.duplicate"),e[31]=f,e[32]=T):T=e[32];let M;e[33]!==C||e[34]!==T?(M=s.jsxs(Vt,{onClick:C,children:[N,T]}),e[33]=C,e[34]=T,e[35]=M):M=e[35];let R;e[36]!==o||e[37]!==f?(R=o&&s.jsxs(Vt,{onClick:Q=>{Q.stopPropagation(),o()},children:[s.jsx(I,{name:"restart",className:"h-4 w-4 mr-px"}),f("settings.common.actions.reset")]}),e[36]=o,e[37]=f,e[38]=R):R=e[38];let O;e[39]!==i||e[40]!==f?(O=i&&s.jsxs(Vt,{onClick:Q=>{Q.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]}),e[39]=i,e[40]=f,e[41]=O):O=e[41];let z;e[42]!==P||e[43]!==M||e[44]!==R||e[45]!==O?(z=s.jsxs(zs,{align:"end",className:"w-fit min-w-20",children:[P,M,R,O]}),e[42]=P,e[43]=M,e[44]=R,e[45]=O,e[46]=z):z=e[46];let B;e[47]!==m||e[48]!==u||e[49]!==z?(B=s.jsxs(_s,{open:m,onOpenChange:u,children:[E,z]}),e[47]=m,e[48]=u,e[49]=z,e[50]=B):B=e[50];let $;e[51]!==A||e[52]!==B?($=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[A,B]}),e[51]=A,e[52]=B,e[53]=$):$=e[53];let _;return e[54]!==$||e[55]!==g||e[56]!==w?(_=s.jsx("div",{className:g,onContextMenu:w,children:$}),e[54]=$,e[55]=g,e[56]=w,e[57]=_):_=e[57],_};function np(t,e,n){return Math.min(n,Math.max(e,t))}function VS(t){if(!Number.isFinite(t))return 0;const e=String(t);if(e.includes("e-")){const[,r]=e.split("e-");return Number(r)||0}const n=e.split(".");return n.length===2?n[1].length:0}function rp(t,e){const n=VS(e);return n<=0?t:Number(t.toFixed(n))}const xn=ze.forwardRef((t,e)=>{const n=at.c(125);let r,a,i,o,c,d,p,m,u,f,b,h,v;n[0]!==t?({value:v,onValueChange:p,min:u,max:f,step:b,className:r,containerClassName:a,onBlur:c,disabled:i,fallbackValue:o,onClear:d,emptyLabel:h,...m}=t,n[0]=t,n[1]=r,n[2]=a,n[3]=i,n[4]=o,n[5]=c,n[6]=d,n[7]=p,n[8]=m,n[9]=u,n[10]=f,n[11]=b,n[12]=h,n[13]=v):(r=n[1],a=n[2],i=n[3],o=n[4],c=n[5],d=n[6],p=n[7],m=n[8],u=n[9],f=n[10],b=n[11],h=n[12],v=n[13]);const x=u===void 0?-1/0:u,g=f===void 0?1/0:f,w=b===void 0?1:b,y=h===void 0?"—":h,{t:k}=mt();let D;n[14]!==v?(D=()=>v===void 0?"":String(v),n[14]=v,n[15]=D):D=n[15];const[j,S]=ze.useState(D),{isMobile:A}=an(),E=ze.useRef(!1),P=ze.useRef(null);let C;n[16]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{if(typeof document>"u"||typeof window>"u")return;P.current?.();const De=Me=>{Me.preventDefault(),Me.stopPropagation(),Me.stopImmediatePropagation?.(),P.current?.()},ye=window.setTimeout(()=>{P.current?.()},700),ge=()=>{window.clearTimeout(ye),document.removeEventListener("click",De,!0),P.current=null};P.current=ge,document.addEventListener("click",De,!0)},n[16]=C):C=n[16];const N=C;let T,M;n[17]===Symbol.for("react.memo_cache_sentinel")?(T=()=>()=>{P.current?.()},M=[],n[17]=T,n[18]=M):(T=n[17],M=n[18]),ze.useEffect(T,M);let R,O;n[19]!==v?(O=()=>{S(v===void 0?"":String(v))},R=[v],n[19]=v,n[20]=R,n[21]=O):(R=n[20],O=n[21]),ze.useEffect(O,R);let z;e:{if(v!==void 0){z=v;break e}if(o!==void 0){z=o;break e}if(Number.isFinite(x)){z=x;break e}z=0}const B=z;let $;n[22]!==g||n[23]!==x||n[24]!==p||n[25]!==w?($=De=>{const ye=np(De,x,g);p(rp(ye,w))},n[22]=g,n[23]=x,n[24]=p,n[25]=w,n[26]=$):$=n[26];const _=$;let Q;n[27]!==_||n[28]!==d?(Q=De=>{const ye=De.target.value;if(S(ye),ye.trim()===""){d?.();return}const ge=Number(ye);Number.isFinite(ge)&&_(ge)},n[27]=_,n[28]=d,n[29]=Q):Q=n[29];const W=Q;let ne;n[30]!==j||n[31]!==g||n[32]!==x||n[33]!==c||n[34]!==d||n[35]!==p||n[36]!==w||n[37]!==v?(ne=De=>{if(j.trim()===""){d||S(v===void 0?"":String(v)),c?.(De);return}const ye=Number(j);if(!Number.isFinite(ye))S(v===void 0?"":String(v));else{const ge=np(ye,x,g),Me=rp(ge,w);Me!==v&&p(Me),S(String(Me))}c?.(De)},n[30]=j,n[31]=g,n[32]=x,n[33]=c,n[34]=d,n[35]=p,n[36]=w,n[37]=v,n[38]=ne):ne=n[38];const re=ne,ue=!!(i||B>=g),Y=!!(i||B<=x);let le;n[39]!==B||n[40]!==_||n[41]!==Y||n[42]!==w?(le=()=>{Y||_(B-w)},n[39]=B,n[40]=_,n[41]=Y,n[42]=w,n[43]=le):le=n[43];const J=le;let L;n[44]!==B||n[45]!==_||n[46]!==ue||n[47]!==w?(L=()=>{ue||_(B+w)},n[44]=B,n[45]=_,n[46]=ue,n[47]=w,n[48]=L):L=n[48];const V=L;let K;if(n[49]!==r||n[50]!==a||n[51]!==Y||n[52]!==j||n[53]!==y||n[54]!==J||n[55]!==V||n[56]!==ue||n[57]!==A||n[58]!==k||n[59]!==v){K=Symbol.for("react.early_return_sentinel");e:{const De=ge=>Me=>{Me.preventDefault(),Me.stopPropagation(),E.current=!0,N(),ge()},ye=ge=>Me=>{if(E.current){E.current=!1,Me.preventDefault(),Me.stopPropagation();return}ge()};if(A){let ge;n[61]!==a?(ge=me("flex h-9 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent select-none overscroll-contain","[-webkit-user-select:none] [-webkit-touch-callout:none]","disabled:pointer-events-none disabled:opacity-50",a),n[61]=a,n[62]=ge):ge=n[62];let Me;n[63]!==k?(Me=k("numberInput.actions.decreaseAria"),n[63]=k,n[64]=Me):Me=n[64];const Ue=De(J),q=ye(J),Ie=!Y&&"active:bg-interactive-hover";let Le;n[65]!==Ie?(Le=me("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",Ie),n[65]=Ie,n[66]=Le):Le=n[66];let Pe;n[67]===Symbol.for("react.memo_cache_sentinel")?(Pe=s.jsx(I,{name:"subtract",className:"block h-4 w-4"}),n[67]=Pe):Pe=n[67];const he=s.jsx("button",{type:"button","aria-label":Me,disabled:Y,onTouchStart:Ue,onClick:q,className:Le,children:Pe});let F;n[68]!==r?(F=me("flex h-full min-w-0 w-14 items-center justify-center bg-transparent px-1.5","text-center text-[16px] leading-none text-foreground [font-variant-numeric:tabular-nums]",r),n[68]=r,n[69]=F):F=n[69];const ee=v===void 0?y:j;let Ce;n[70]!==F||n[71]!==ee?(Ce=s.jsx("div",{className:F,"aria-live":"polite",children:ee}),n[70]=F,n[71]=ee,n[72]=Ce):Ce=n[72];let Fe;n[73]!==k?(Fe=k("numberInput.actions.increaseAria"),n[73]=k,n[74]=Fe):Fe=n[74];const we=De(V),Qe=ye(V),pe=!ue&&"active:bg-interactive-hover";let Oe;n[75]!==pe?(Oe=me("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",pe),n[75]=pe,n[76]=Oe):Oe=n[76];let nt;n[77]===Symbol.for("react.memo_cache_sentinel")?(nt=s.jsx(I,{name:"add",className:"block h-4 w-4"}),n[77]=nt):nt=n[77];const Re=s.jsx("button",{type:"button","aria-label":Fe,disabled:ue,onTouchStart:we,onClick:Qe,className:Oe,children:nt});let de;n[78]!==ge||n[79]!==he||n[80]!==Ce||n[81]!==Re?(de=s.jsxs("div",{className:ge,children:[he,Ce,Re]}),n[78]=ge,n[79]=he,n[80]=Ce,n[81]=Re,n[82]=de):de=n[82],K=de;break e}}n[49]=r,n[50]=a,n[51]=Y,n[52]=j,n[53]=y,n[54]=J,n[55]=V,n[56]=ue,n[57]=A,n[58]=k,n[59]=v,n[60]=K}else K=n[60];if(K!==Symbol.for("react.early_return_sentinel"))return K;let X;n[83]!==a?(X=me("flex h-7 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent","disabled:pointer-events-none disabled:opacity-50",a),n[83]=a,n[84]=X):X=n[84];let U;n[85]!==k?(U=k("numberInput.actions.decreaseAria"),n[85]=k,n[86]=U):U=n[86];let ae;n[87]!==B||n[88]!==_||n[89]!==w?(ae=()=>_(B-w),n[87]=B,n[88]=_,n[89]=w,n[90]=ae):ae=n[90];let ve,ie;n[91]===Symbol.for("react.memo_cache_sentinel")?(ve=me("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),ie=s.jsx(I,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=ve,n[92]=ie):(ve=n[91],ie=n[92]);let fe;n[93]!==Y||n[94]!==U||n[95]!==ae?(fe=s.jsx("button",{type:"button","aria-label":U,disabled:Y,onClick:ae,className:ve,children:ie}),n[93]=Y,n[94]=U,n[95]=ae,n[96]=fe):fe=n[96];const H=m.inputMode??"numeric";let ce;n[97]!==r?(ce=me("h-full min-w-0 w-14 bg-transparent px-1.5 text-center typography-ui-label leading-none text-foreground [font-variant-numeric:tabular-nums]","placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground","appearance-none outline-none [appearance:textfield] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","disabled:pointer-events-none disabled:cursor-not-allowed",r),n[97]=r,n[98]=ce):ce=n[98];let se;n[99]!==i||n[100]!==j||n[101]!==re||n[102]!==W||n[103]!==m||n[104]!==e||n[105]!==H||n[106]!==ce?(se=s.jsx("input",{...m,ref:e,type:"text",inputMode:H,value:j,onChange:W,onBlur:re,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:ce}),n[99]=i,n[100]=j,n[101]=re,n[102]=W,n[103]=m,n[104]=e,n[105]=H,n[106]=ce,n[107]=se):se=n[107];let oe;n[108]!==k?(oe=k("numberInput.actions.increaseAria"),n[108]=k,n[109]=oe):oe=n[109];let te;n[110]!==B||n[111]!==_||n[112]!==w?(te=()=>_(B+w),n[110]=B,n[111]=_,n[112]=w,n[113]=te):te=n[113];let ke,Ne;n[114]===Symbol.for("react.memo_cache_sentinel")?(ke=me("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),Ne=s.jsx(I,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=ke,n[115]=Ne):(ke=n[114],Ne=n[115]);let je;n[116]!==ue||n[117]!==oe||n[118]!==te?(je=s.jsx("button",{type:"button","aria-label":oe,disabled:ue,onClick:te,className:ke,children:Ne}),n[116]=ue,n[117]=oe,n[118]=te,n[119]=je):je=n[119];let Se;return n[120]!==X||n[121]!==fe||n[122]!==se||n[123]!==je?(Se=s.jsxs("div",{className:X,children:[fe,se,je]}),n[120]=X,n[121]=fe,n[122]=se,n[123]=je,n[124]=Se):Se=n[124],Se});xn.displayName="NumberInput";const ap=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],Qo=t=>t==="allow"||t==="ask"||t==="deny",Sa=(t,e)=>`${t}::${e}`,Ba=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&Qo(n.action)&&e.set(Sa(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},Do=t=>{const e=new Map;for(const n of Ba(t))e.set(Sa(n.permission,n.pattern),n);return e},ip=t=>[...t].sort((e,n)=>{const r=e.permission.localeCompare(n.permission);return r!==0?r:e.pattern.localeCompare(n.pattern)}),US=(t,e)=>{const n=ip(Ba(t)),r=ip(Ba(e));return n.length!==r.length?!1:n.every((a,i)=>{const o=r[i];return a.permission===o.permission&&a.pattern===o.pattern&&a.action===o.action})},WS=t=>t.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",KS=(t,e)=>Ba(t).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),HS=t=>{if(Qo(t))return[{permission:"*",pattern:"*",action:t}];if(!t||typeof t!="object"||Array.isArray(t))return[];const e=[];for(const[n,r]of Object.entries(t))if(n!=="__originalKeys"){if(Qo(r)){e.push({permission:n,pattern:"*",action:r});continue}if(r&&typeof r=="object"&&!Array.isArray(r))for(const[a,i]of Object.entries(r))Qo(i)&&e.push({permission:n,pattern:a,action:i})}return e},GS=(t,e)=>{const n=Ba(e),r={};for(const i of n)(r[i.permission]||={})[i.pattern]=i.action;const a={"*":t};for(const[i,o]of Object.entries(r))if(i!=="*"){if(Object.keys(o).length===1&&o["*"]){a[i]=o["*"];continue}a[i]=o}return a},qS=()=>{const{t}=mt(),{isMobile:e}=an(),{selectedAgentName:n,getAgentByName:r,createAgent:a,updateAgent:i,agents:o,agentDraft:c,setAgentDraft:d}=di(br(ge=>({selectedAgentName:ge.selectedAgentName,getAgentByName:ge.getAgentByName,createAgent:ge.createAgent,updateAgent:ge.updateAgent,agents:ge.agents,agentDraft:ge.agentDraft,setAgentDraft:ge.setAgentDraft}))),p=n?r(n):null,m=!!(c&&c.name===n&&!p),[u,f]=l.useState(""),[b,h]=l.useState("user"),[v,x]=l.useState(""),[g,w]=l.useState("subagent"),[y,k]=l.useState(""),[D,j]=l.useState(void 0),[S,A]=l.useState(void 0),[E,P]=l.useState(""),[C,N]=l.useState("allow"),[T,M]=l.useState([]),[R,O]=l.useState([]),[z,B]=l.useState(""),[$,_]=l.useState("*"),[Q,W]=l.useState(!1),[ne,re]=l.useState(!1),ue=l.useRef(null),Y=Ws(ge=>ge.currentDirectory??null),[le,J]=l.useState([]),L=sh(ge=>ge.permission);l.useEffect(()=>{let ge=!1;return(async()=>{const Ue=await rn.listToolIds({directory:Y});if(ge)return;const q=new Set(["write","patch","multiedit"]),Ie=Ue.map(Le=>typeof Le=="string"?Le.trim():"").filter(Boolean).filter(Le=>Le!=="*").filter(Le=>Le!=="invalid").filter(Le=>!q.has(Le));J(Array.from(new Set(Ie)).sort((Le,Pe)=>Le.localeCompare(Pe)))})(),()=>{ge=!0}},[Y]);const V=l.useMemo(()=>{const ge=new Set;for(const Me of o){const Ue=Ba(Array.isArray(Me.permission)?Me.permission:[]);for(const q of Ue)q.permission&&q.permission!=="*"&&q.permission!=="invalid"&&ge.add(q.permission)}for(const Me of Object.values(L))for(const Ue of Me){const q=Ue.permission?.trim();q&&q!=="invalid"&&ge.add(q)}for(const Me of le)ge.add(Me);return Array.from(ge).sort((Me,Ue)=>Me.localeCompare(Ue))},[o,L,le]),K=l.useMemo(()=>Do(T),[T]),X=l.useMemo(()=>Do(R),[R]),U=l.useCallback(ge=>X.get(Sa(ge,"*"))?.action,[X]),ae=l.useCallback(ge=>R.filter(Me=>Me.permission===ge&&Me.pattern!=="*").sort((Me,Ue)=>Me.pattern.localeCompare(Ue.pattern)),[R]),ve=l.useMemo(()=>{const ge=new Set;for(const Me of ap)ge.add(Me);for(const Me of V)ge.add(Me);return Array.from(ge).sort((Me,Ue)=>Me.localeCompare(Ue))},[V]),ie=l.useCallback(ge=>{const Me=ge==="*"?C:U(ge)??C,Ue=ae(ge),q=!1,Ie=Ue.reduce((Pe,he)=>(Pe[he.action]=(Pe[he.action]??0)+1,Pe),{allow:0,ask:0,deny:0}),Le=["allow","ask","deny"].filter(Pe=>Ie[Pe]>0).map(Pe=>`${Ie[Pe]} ${Pe}`).join(", ");return{defaultAction:Me,patternRulesCount:Ue.length,patternSummary:Le,hasDefaultHint:q}},[ae,U,C]),fe=l.useCallback(ge=>t(ge==="allow"?"settings.common.permission.allow":ge==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[t]),H=l.useCallback(ge=>ge==="global"?t("settings.common.scope.global"):fe(ge),[fe,t]),ce=l.useMemo(()=>{const ge=new Set;for(const Me of ap)ge.add(Me);for(const Me of V)ge.add(Me);return Array.from(ge).sort((Me,Ue)=>Me.localeCompare(Ue))},[V]),se=l.useCallback((ge,Me,Ue)=>{O(q=>{const Ie=Do(q);return Ie.set(Sa(ge,Me),{permission:ge,pattern:Me,action:Ue}),Array.from(Ie.values())})},[]),oe=l.useCallback((ge,Me)=>{O(Ue=>{const q=Do(Ue);return q.delete(Sa(ge,Me)),Array.from(q.values())})},[]),te=l.useCallback((ge,Me)=>{const Ue=K.get(Sa(ge,Me));if(Ue){se(ge,Me,Ue.action);return}oe(ge,Me)},[K,oe,se]),ke=l.useCallback((ge,Me,Ue)=>{se(ge,Me,Ue)},[se]),Ne=l.useCallback(ge=>{N(ge),O(Me=>Me.filter(Ue=>!(Ue.pattern==="*"&&Ue.action===ge)))},[]),je=l.useCallback(ge=>{const Me=z.trim();if(!Me){G.error(t("settings.agents.page.toast.permissionNameRequired"));return}const Ue=$.trim()||"*";if(Me==="*"&&Ue==="*"){Ne(ge),B(""),_("*");return}Ue==="*"&&Me!=="*"&&ge===C?oe(Me,"*"):se(Me,Ue,ge),B(""),_("*")},[C,z,$,oe,Ne,t,se]),Se=l.useCallback(ge=>ge==="*"?t("settings.agents.page.permissions.defaultLabel"):ge==="webfetch"?"WebFetch":ge==="websearch"?"WebSearch":ge==="codesearch"?"CodeSearch":ge==="doom_loop"?"Doom Loop":ge==="external_directory"?"External Directory":ge==="todowrite"?"TodoWrite":ge==="todoread"?"TodoRead":ge.split(/[_-]+/g).filter(Boolean).map(Me=>Me.charAt(0).toUpperCase()+Me.slice(1)).join(" "),[t]);l.useEffect(()=>{B(""),_("*");const ge=Me=>{const Ue=Ba(Me),q=WS(Ue),Ie=KS(Ue,q);return N(q),M(Ie),O(Ie),{global:q,rules:Ie}};if(m&&c){const Me=c.name||"",Ue=c.scope||"user",q=c.description||"",Ie=c.mode||"subagent",Le=c.model||"",Pe=c.temperature,he=c.top_p,F=c.prompt||"";f(Me),h(Ue),x(q),w(Ie),k(Le),j(Pe),A(he),P(F);const ee=HS(c.permission),Ce=ge(ee);ue.current={draftName:Me,draftScope:Ue,description:q,mode:Ie,model:Le,temperature:Pe,topP:he,prompt:F,globalPermission:Ce.global,permissionRules:Ce.rules};return}if(p&&n===p.name){const Me=p.description||"",Ue=p.mode||"subagent",q=p.model?.providerID&&p.model?.modelID?`${p.model.providerID}/${p.model.modelID}`:"",Ie=p.temperature,Le=p.topP,Pe=p.prompt||"";x(Me),w(Ue),k(q),j(Ie),A(Le),P(Pe);const he=ge(Array.isArray(p.permission)?p.permission:[]);ue.current={draftName:"",draftScope:"user",description:Me,mode:Ue,model:q,temperature:Ie,topP:Le,prompt:Pe,globalPermission:he.global,permissionRules:he.rules}}},[c,m,p,n]);const De=l.useMemo(()=>{const ge=ue.current;return ge?!!(m&&(u!==ge.draftName||b!==ge.draftScope)||v!==ge.description||g!==ge.mode||y!==ge.model||D!==ge.temperature||S!==ge.topP||E!==ge.prompt||C!==ge.globalPermission||!US(R,ge.permissionRules)):!1},[v,u,b,C,m,g,y,R,E,D,S]),ye=async()=>{const ge=m?u.trim().replace(/\s+/g,"-"):n?.trim();if(!ge){G.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&o.some(Me=>Me.name===ge)){G.error(t("settings.agents.sidebar.toast.agentExists"));return}re(!0);try{const Me=y.trim(),Ue=GS(C,R),q={name:ge,description:v.trim()||void 0,mode:g,model:Me===""?null:Me,temperature:D,top_p:S,prompt:E.trim()||void 0,permission:Ue,scope:m?b:void 0};let Ie;m?(Ie=await a(q),Ie&&d(null)):Ie=await i(ge,q),Ie?G.success(t(m?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):G.error(t(m?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(Me){console.error("Error saving agent:",Me);const Ue=Me instanceof Error&&Me.message?Me.message:t("settings.agents.page.toast.saveUnexpectedError");G.error(Ue)}finally{re(!1)}};return n?s.jsx(Es,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:m?t("settings.agents.page.title.new"):n}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t(m?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.identityRole")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[m&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.agentName")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),s.jsx(Wt,{value:u,onChange:ge=>f(ge.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(ds,{value:b,onValueChange:ge=>h(ge),children:[s.jsx(us,{className:"w-fit min-w-[100px]",children:s.jsx(bs,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(ms,{align:"end",children:[s.jsx(Lt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Lt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(bn,{value:v,onChange:ge=>x(ge.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]}),s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.mode")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.modeTooltip")})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(be,{variant:"chip",size:"xs","aria-pressed":g==="primary",onClick:()=>w("primary"),className:"!font-normal",children:t("settings.agents.page.mode.primary")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":g==="subagent",onClick:()=>w("subagent"),className:"!font-normal",children:t("settings.agents.page.mode.subagent")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":g==="all",onClick:()=>w("all"),className:"!font-normal",children:t("settings.agents.page.mode.all")})]})]})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.modelParameters")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.overrideModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(uo,{providerId:hi(y)?.providerId??"",modelId:hi(y)?.modelId??"",onChange:(ge,Me)=>{k(ge&&Me?`${ge}/${Me}`:"")}})})]}),s.jsxs("div",{className:me("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:me("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.temperature")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.temperatureTooltip")})]})]}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.agents.page.field.temperatureRange")})]}),s.jsxs("div",{className:me("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(xn,{value:D,fallbackValue:.7,onValueChange:j,onClear:()=>j(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),D!==void 0&&s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:me("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:me("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.topP")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.topPTooltip")})]})]}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.agents.page.field.topPRange")})]}),s.jsxs("div",{className:me("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(xn,{value:S,fallbackValue:.9,onValueChange:A,onClear:()=>A(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),S!==void 0&&s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>A(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.systemPrompt")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(bn,{value:E,onChange:ge=>P(ge.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-4",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.toolPermissions")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>W(ge=>!ge),children:t(Q?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),Q?s.jsxs("div",{className:"space-y-6 px-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4 py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.permissions.globalDefault")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:"*"})]}),s.jsxs(ds,{value:C,onValueChange:ge=>Ne(ge),children:[s.jsx(us,{className:"w-[100px]",children:s.jsx(bs,{children:fe(C)})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Lt,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Lt,{value:"deny",children:t("settings.common.permission.deny")})]})]})]}),s.jsx("div",{className:"space-y-4",children:ve.filter(ge=>ge!=="*").map(ge=>{const Me=Se(ge),{defaultAction:Ue,patternRulesCount:q}=ie(ge),Ie=U(ge),Le=Ie??"global",Pe=ae(ge),he=["allow","ask","deny"].filter(F=>F!==C);return s.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-2",children:[s.jsxs("div",{className:"flex items-center justify-between py-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:Me}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:ge})]}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:q>0?t("settings.agents.page.permissions.globalSummary",{summary:Ue}):Ue})]}),s.jsxs("div",{className:"space-y-1 pl-2 mt-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t("settings.agents.page.permissions.pattern")}),s.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:"*"}),Ie&&s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>te(ge,"*"),className:"px-1.5 py-0 h-5",children:s.jsx(I,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(ds,{value:Le,onValueChange:F=>{if(F==="global"){oe(ge,"*");return}se(ge,"*",F)},children:[s.jsx(us,{className:"w-[90px]",children:s.jsx(bs,{children:H(Le)})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"global",children:t("settings.common.scope.global")}),he.map(F=>s.jsx(Lt,{value:F,className:"capitalize",children:fe(F)},F))]})]})]}),Pe.map(F=>{const ee=Sa(F.permission,F.pattern),Ce=K.get(ee),Fe=!Ce,we=!!(Ce&&Ce.action!==F.action);return s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5 border-t border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t("settings.agents.page.permissions.pattern")}),s.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:F.pattern}),Fe&&s.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:t("settings.common.badge.new")}),we&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:t("settings.common.badge.modified")}),(Fe||we)&&s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>Fe?oe(F.permission,F.pattern):te(F.permission,F.pattern),className:"px-1.5 py-0 h-5",children:s.jsx(I,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(ds,{value:F.action,onValueChange:Qe=>ke(F.permission,F.pattern,Qe),children:[s.jsx(us,{className:"w-[90px]",children:s.jsx(bs,{children:fe(F.action)})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Lt,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Lt,{value:"deny",children:t("settings.common.permission.deny")})]})]})]},ee)})]})]},ge)})}),s.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-3",children:[s.jsx("h4",{className:"typography-ui-label text-foreground mb-2",children:t("settings.agents.page.permissions.addCustomRule")}),s.jsxs("div",{className:"flex flex-col sm:flex-row items-end sm:items-center gap-2",children:[s.jsxs(ds,{value:z,onValueChange:B,children:[s.jsx(us,{className:"w-full sm:w-[160px]",children:z?s.jsx("span",{className:"truncate",children:Se(z)}):s.jsx("span",{className:"text-muted-foreground",children:t("settings.agents.page.permissions.permissionPlaceholder")})}),s.jsx(ms,{children:ce.map(ge=>s.jsx(Lt,{value:ge,children:s.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:s.jsx("span",{children:Se(ge)})})},ge))})]}),s.jsx(Wt,{value:$,onChange:ge=>_(ge.target.value),placeholder:t("settings.agents.page.permissions.patternPlaceholder"),className:"h-7 flex-1 font-mono text-xs"}),s.jsxs("div",{className:"flex gap-1",children:[s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>je("allow"),children:t("settings.common.permission.allow")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>je("ask"),children:t("settings.common.permission.ask")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>je("deny"),children:t("settings.common.permission.deny")})]})]})]})]}):s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:ve.map((ge,Me)=>{const{defaultAction:Ue,patternRulesCount:q,patternSummary:Ie,hasDefaultHint:Le}=ie(ge),Pe=Se(ge),he=Le?`${Ue} (env blocked)`:Ue;return s.jsxs("div",{className:me("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",Me>0&&"border-t border-[var(--surface-subtle)]"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:Pe}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:ge})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[q>0?s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:t("settings.agents.page.permissions.globalSummary",{summary:he})}):s.jsx("span",{className:me("typography-micro capitalize px-1.5 py-0.5 rounded",he==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":he==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:he}),q>0&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:t("settings.agents.page.permissions.rulesSummary",{summary:Ie})})]})]},ge)})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(be,{onClick:ye,disabled:ne||!De,size:"xs",className:"!font-normal",children:t(ne?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(I,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})},YS="~/.config/opencode/AGENTS.md",ug=async(t,e)=>{const n=await t.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},JS=t=>t.length>0&&!t.endsWith(`
|
|
155
|
+
`)?`${t}
|
|
156
|
+
`:t,To={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},QS=(t,e)=>t==="custom"?e:Rb(t),XS=t=>t==="custom"?"custom":nh(t)?t:"concise",op={concise:"settings.behavior.page.responseStyle.option.concise",detailed:"settings.behavior.page.responseStyle.option.detailed",mentor:"settings.behavior.page.responseStyle.option.mentor",pushback:"settings.behavior.page.responseStyle.option.pushback",noFiller:"settings.behavior.page.responseStyle.option.noFiller",matchEnergy:"settings.behavior.page.responseStyle.option.matchEnergy",warmPeer:"settings.behavior.page.responseStyle.option.warmPeer"},lp=async(t,e)=>{const n=await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(await ug(n,e))},ZS=()=>{const{t}=mt(),[e,n]=l.useState(""),[r,a]=l.useState(To.responseStyleEnabled),[i,o]=l.useState(To.responseStylePreset),[c,d]=l.useState(To.responseStyleCustomInstructions),[p,m]=l.useState(!0),[u,f]=l.useState(!1),[b,h]=l.useState(""),v=l.useRef(null);l.useEffect(()=>{const y=new AbortController;return(async()=>{try{const[D,j]=await Promise.all([fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:y.signal}),fetch("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:y.signal})]);let S=To;if(D.ok){const A=await D.json();S={...S,responseStyleEnabled:A.responseStyleEnabled===!0,responseStylePreset:XS(A.responseStylePreset),responseStyleCustomInstructions:typeof A.responseStyleCustomInstructions=="string"?A.responseStyleCustomInstructions:""},typeof A.globalBehaviorPrompt=="string"&&(S={...S,prompt:A.globalBehaviorPrompt})}if(!S.prompt.trim()&&j.ok){const A=await j.json();typeof A.content=="string"&&(S={...S,prompt:A.content})}n(S.prompt),a(S.responseStyleEnabled),o(S.responseStylePreset),d(S.responseStyleCustomInstructions),h(S.prompt),v.current={enabled:S.responseStyleEnabled,preset:S.responseStylePreset,custom:S.responseStyleCustomInstructions}}catch(D){D.name!=="AbortError"&&console.warn("Failed to load behavior settings:",D)}finally{m(!1)}})(),()=>y.abort()},[]),l.useEffect(()=>{if(p)return;const y=v.current;if(y&&y.enabled===r&&y.preset===i&&y.custom===c)return;const k={enabled:r,preset:i,custom:c},D=setTimeout(async()=>{try{await lp({responseStyleEnabled:k.enabled,responseStylePreset:k.preset,responseStyleCustomInstructions:k.custom},t("settings.behavior.page.toast.saveFailed")),v.current=k}catch(j){const S=j instanceof Error?j.message:t("settings.behavior.page.toast.saveFailed");G.error(S)}},400);return()=>clearTimeout(D)},[r,i,c,p,t]);const x=QS(i,c),g=e!==b,w=async()=>{f(!0);try{const y=JS(e),k=await fetch("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:y})});if(!k.ok)throw new Error(await ug(k,t("settings.behavior.page.toast.saveFailed")));await lp({globalBehaviorPrompt:y},t("settings.behavior.page.toast.saveFailed")),n(y),h(y),G.success(t("settings.behavior.page.toast.saved"))}catch(y){console.error("Failed to save behavior:",y);const k=y instanceof Error?y.message:t("settings.behavior.page.toast.saveFailed");G.error(k)}finally{f(!1)}};return s.jsx(Es,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8 space-y-6",children:[s.jsx("div",{className:"space-y-1",children:s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:t("settings.behavior.page.title")})}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.behavior.page.section.systemPrompt")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:YS})})]})})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsx(bn,{value:e,onChange:y=>n(y.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:p,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(be,{onClick:w,disabled:u||!g||p,size:"xs",className:"!font-normal",children:t(u?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]})]}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.behavior.page.section.responseStyle")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.behavior.page.responseStyle.tooltip")})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label text-foreground",children:[s.jsx(fs,{checked:r,onChange:a,disabled:p,ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),t("settings.behavior.page.responseStyle.enable")]}),s.jsxs(ds,{value:i,onValueChange:y=>o(y),disabled:p||!r,children:[s.jsx(us,{className:"w-full sm:w-56",size:"lg",children:s.jsx(bs,{children:y=>y==="custom"?t("settings.behavior.page.responseStyle.option.custom"):nh(y)?t(op[y]):null})}),s.jsxs(ms,{children:[Eb.map(y=>s.jsx(Lt,{value:y,children:t(op[y])},y)),s.jsx(Lt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]}),s.jsx(bn,{value:x,onChange:y=>d(y.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:p||!r||i!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},ek=t=>{const e=at.c(169),{onItemSelect:n}=t,{t:r}=mt(),[a,i]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(null),[f,b]=l.useState(!1),[h,v]=l.useState(null),{selectedCommandName:x,commands:g,setSelectedCommand:w,setCommandDraft:y,createCommand:k,deleteCommand:D,loadCommands:j}=_d(br(tk)),S=na(sk),A=na(nk);let E,P;e[0]!==j||e[1]!==A?(E=()=>{j(),A()},P=[j,A],e[0]=j,e[1]=A,e[2]=E,e[3]=P):(E=e[2],P=e[3]),l.useEffect(E,P);let C;e[4]!==S?(C=new Set(S.map(rk)),e[4]=S,e[5]=C):C=e[5];const N=C;let T;if(e[6]!==g||e[7]!==N){let _e;e[9]!==N?(_e=We=>!N.has(We.name),e[9]=N,e[10]=_e):_e=e[10],T=g.filter(_e),e[6]=g,e[7]=N,e[8]=T}else T=e[8];const M=T;let R,O;e[11]!==x||e[12]!==w||e[13]!==N?(R=()=>{x&&N.has(x)&&w(null)},O=[x,w,N],e[11]=x,e[12]=w,e[13]=N,e[14]=R,e[15]=O):(R=e[14],O=e[15]),l.useEffect(R,O);let z;e[16]!==g||e[17]!==n||e[18]!==y||e[19]!==w?(z=()=>{let _e="new-command",We=1;for(;g.some(lt=>lt.name===_e);)_e=`new-command-${We}`,We++;y({name:_e,scope:"user"}),w(_e),n?.()},e[16]=g,e[17]=n,e[18]=y,e[19]=w,e[20]=z):z=e[20];const B=z;let $;e[21]!==r?($=async _e=>{if(ri(_e)){G.error(r("settings.commands.sidebar.toast.builtInCannotDelete"));return}p(_e),u("delete")},e[21]=r,e[22]=$):$=e[22];const _=$;let Q;e[23]===Symbol.for("react.memo_cache_sentinel")?(Q=async _e=>{ri(_e)&&(p(_e),u("reset"))},e[23]=Q):Q=e[23];const W=Q;let ne;e[24]===Symbol.for("react.memo_cache_sentinel")?(ne=()=>{p(null),u(null)},e[24]=ne):ne=e[24];const re=ne;let ue;e[25]!==d||e[26]!==m||e[27]!==D||e[28]!==r?(ue=async()=>{if(!d||!m)return;b(!0),await D(d.name)?(m==="delete"?G.success(r("settings.commands.sidebar.toast.commandDeleted",{name:d.name})):G.success(r("settings.commands.sidebar.toast.commandReset",{name:d.name})),re()):m==="delete"?G.error(r("settings.commands.sidebar.toast.deleteFailed")):G.error(r("settings.commands.sidebar.toast.resetFailed")),b(!1)},e[25]=d,e[26]=m,e[27]=D,e[28]=r,e[29]=ue):ue=e[29];const Y=ue;let le;e[30]!==g||e[31]!==y||e[32]!==w?(le=_e=>{const We=_e.name;let lt=1,Je=`${We}-copy`;for(;g.some(Ve=>Ve.name===Je);)lt++,Je=`${We}-copy-${lt}`;y({name:Je,scope:_e.scope||"user",description:_e.description,template:_e.template,agent:_e.agent,model:_e.model}),w(Je)},e[30]=g,e[31]=y,e[32]=w,e[33]=le):le=e[33];const J=le;let L;e[34]===Symbol.for("react.memo_cache_sentinel")?(L=_e=>{c(_e.name),i(_e)},e[34]=L):L=e[34];const V=L;let K;e[35]!==g||e[36]!==k||e[37]!==D||e[38]!==a||e[39]!==o||e[40]!==w||e[41]!==r?(K=async()=>{if(!a)return;const _e=o.trim().replace(/\s+/g,"-");if(!_e){G.error(r("settings.commands.sidebar.toast.commandNameRequired"));return}if(_e===a.name){i(null);return}if(g.some(lt=>lt.name===_e)){G.error(r("settings.commands.sidebar.toast.commandExists"));return}await k({name:_e,description:a.description,template:a.template,agent:a.agent,model:a.model})?await D(a.name)?(G.success(`Command renamed to "${_e}"`),w(_e)):G.error(r("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):G.error(r("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=g,e[36]=k,e[37]=D,e[38]=a,e[39]=o,e[40]=w,e[41]=r,e[42]=K):K=e[42];const X=K;let U,ae,ve,ie,fe,H;if(e[43]!==M||e[44]!==B||e[45]!==_||e[46]!==J||e[47]!==n||e[48]!==h||e[49]!==x||e[50]!==w||e[51]!==r){const _e=M.filter(ri),We=M.filter(ak);e[58]===Symbol.for("react.memo_cache_sentinel")?(fe=me("flex h-full flex-col","bg-background"),e[58]=fe):fe=e[58];let lt;e[59]!==r?(lt=r("settings.commands.sidebar.title"),e[59]=r,e[60]=lt):lt=e[60];let Je;e[61]!==lt?(Je=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:lt}),e[61]=lt,e[62]=Je):Je=e[62];let Ve;e[63]===Symbol.for("react.memo_cache_sentinel")?(Ve=s.jsx(mo,{className:"mb-3"}),e[63]=Ve):Ve=e[63];let yt;e[64]!==M.length||e[65]!==r?(yt=r("settings.commands.sidebar.total",{count:M.length}),e[64]=M.length,e[65]=r,e[66]=yt):yt=e[66];let $t;e[67]!==yt?($t=s.jsx("span",{className:"typography-meta text-muted-foreground",children:yt}),e[67]=yt,e[68]=$t):$t=e[68];let Gt;e[69]===Symbol.for("react.memo_cache_sentinel")?(Gt=s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),e[69]=Gt):Gt=e[69];let ss;e[70]!==B?(ss=s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:B,children:Gt}),e[70]=B,e[71]=ss):ss=e[71];let wt;e[72]!==$t||e[73]!==ss?(wt=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[$t,ss]}),e[72]=$t,e[73]=ss,e[74]=wt):wt=e[74],e[75]!==Je||e[76]!==wt?(H=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Je,Ve,wt]}),e[75]=Je,e[76]=wt,e[77]=H):H=e[77],U=Es,ae="flex-1 min-h-0",ve="space-y-1 px-3 py-2",ie=M.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(I,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[_e.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.commands.sidebar.section.builtIn")}),[..._e].sort(ik).map(Dt=>s.jsx(cp,{command:Dt,isSelected:x===Dt.name,onSelect:()=>{w(Dt.name),n?.()},onReset:()=>W(Dt),onDuplicate:()=>J(Dt),isMenuOpen:h===Dt.name,onMenuOpenChange:Xt=>v(Xt?Dt.name:null)},Dt.name))]}),We.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.commands.sidebar.section.custom")}),[...We].sort(ok).map(Dt=>s.jsx(cp,{command:Dt,isSelected:x===Dt.name,onSelect:()=>{w(Dt.name),n?.()},onRename:()=>V(Dt),onDelete:()=>_(Dt),onDuplicate:()=>J(Dt),isMenuOpen:h===Dt.name,onMenuOpenChange:Xt=>v(Xt?Dt.name:null)},Dt.name))]})]}),e[43]=M,e[44]=B,e[45]=_,e[46]=J,e[47]=n,e[48]=h,e[49]=x,e[50]=w,e[51]=r,e[52]=U,e[53]=ae,e[54]=ve,e[55]=ie,e[56]=fe,e[57]=H}else U=e[52],ae=e[53],ve=e[54],ie=e[55],fe=e[56],H=e[57];let ce;e[78]!==U||e[79]!==ae||e[80]!==ve||e[81]!==ie?(ce=s.jsx(U,{outerClassName:ae,className:ve,children:ie}),e[78]=U,e[79]=ae,e[80]=ve,e[81]=ie,e[82]=ce):ce=e[82];const se=d!==null&&m!==null;let oe;e[83]!==f?(oe=_e=>{!_e&&!f&&re()},e[83]=f,e[84]=oe):oe=e[84];let te;e[85]!==m||e[86]!==r?(te=r(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=r,e[87]=te):te=e[87];let ke;e[88]!==te?(ke=s.jsx(Ss,{children:te}),e[88]=te,e[89]=ke):ke=e[89];let Ne;e[90]!==d?.name||e[91]!==m||e[92]!==r?(Ne=m==="delete"?r("settings.commands.sidebar.dialog.deleteDescription",{name:d?.name??""}):r("settings.commands.sidebar.dialog.resetDescription",{name:d?.name??""}),e[90]=d?.name,e[91]=m,e[92]=r,e[93]=Ne):Ne=e[93];let je;e[94]!==Ne?(je=s.jsx(Fs,{children:Ne}),e[94]=Ne,e[95]=je):je=e[95];let Se;e[96]!==ke||e[97]!==je?(Se=s.jsxs(As,{children:[ke,je]}),e[96]=ke,e[97]=je,e[98]=Se):Se=e[98];let De;e[99]!==r?(De=r("settings.common.actions.cancel"),e[99]=r,e[100]=De):De=e[100];let ye;e[101]!==f||e[102]!==De?(ye=s.jsx(be,{size:"sm",variant:"ghost",onClick:re,disabled:f,children:De}),e[101]=f,e[102]=De,e[103]=ye):ye=e[103];let ge;e[104]!==m||e[105]!==r?(ge=r(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=r,e[106]=ge):ge=e[106];let Me;e[107]!==Y||e[108]!==f||e[109]!==ge?(Me=s.jsx(be,{size:"sm",onClick:Y,disabled:f,children:ge}),e[107]=Y,e[108]=f,e[109]=ge,e[110]=Me):Me=e[110];let Ue;e[111]!==ye||e[112]!==Me?(Ue=s.jsxs(Hs,{children:[ye,Me]}),e[111]=ye,e[112]=Me,e[113]=Ue):Ue=e[113];let q;e[114]!==Se||e[115]!==Ue?(q=s.jsxs(ys,{className:"max-w-md",children:[Se,Ue]}),e[114]=Se,e[115]=Ue,e[116]=q):q=e[116];let Ie;e[117]!==se||e[118]!==oe||e[119]!==q?(Ie=s.jsx(vs,{open:se,onOpenChange:oe,children:q}),e[117]=se,e[118]=oe,e[119]=q,e[120]=Ie):Ie=e[120];const Le=a!==null;let Pe;e[121]===Symbol.for("react.memo_cache_sentinel")?(Pe=_e=>!_e&&i(null),e[121]=Pe):Pe=e[121];let he;e[122]!==r?(he=r("settings.commands.sidebar.renameDialog.title"),e[122]=r,e[123]=he):he=e[123];let F;e[124]!==he?(F=s.jsx(Ss,{children:he}),e[124]=he,e[125]=F):F=e[125];const ee=a?.name??"";let Ce;e[126]!==r||e[127]!==ee?(Ce=r("settings.commands.sidebar.renameDialog.description",{name:ee}),e[126]=r,e[127]=ee,e[128]=Ce):Ce=e[128];let Fe;e[129]!==Ce?(Fe=s.jsx(Fs,{children:Ce}),e[129]=Ce,e[130]=Fe):Fe=e[130];let we;e[131]!==F||e[132]!==Fe?(we=s.jsxs(As,{children:[F,Fe]}),e[131]=F,e[132]=Fe,e[133]=we):we=e[133];let Qe;e[134]===Symbol.for("react.memo_cache_sentinel")?(Qe=_e=>c(_e.target.value),e[134]=Qe):Qe=e[134];let pe;e[135]!==r?(pe=r("settings.commands.sidebar.renameDialog.placeholder"),e[135]=r,e[136]=pe):pe=e[136];let Oe;e[137]!==X?(Oe=_e=>{_e.key==="Enter"&&X()},e[137]=X,e[138]=Oe):Oe=e[138];let nt;e[139]!==o||e[140]!==pe||e[141]!==Oe?(nt=s.jsx(Wt,{value:o,onChange:Qe,placeholder:pe,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Oe}),e[139]=o,e[140]=pe,e[141]=Oe,e[142]=nt):nt=e[142];let Re;e[143]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>i(null),e[143]=Re):Re=e[143];let de;e[144]!==r?(de=r("settings.common.actions.cancel"),e[144]=r,e[145]=de):de=e[145];let He;e[146]!==de?(He=s.jsx(be,{size:"sm",variant:"ghost",onClick:Re,children:de}),e[146]=de,e[147]=He):He=e[147];let st;e[148]!==r?(st=r("settings.common.actions.rename"),e[148]=r,e[149]=st):st=e[149];let qe;e[150]!==X||e[151]!==st?(qe=s.jsx(be,{size:"sm",onClick:X,children:st}),e[150]=X,e[151]=st,e[152]=qe):qe=e[152];let et;e[153]!==He||e[154]!==qe?(et=s.jsxs(Hs,{children:[He,qe]}),e[153]=He,e[154]=qe,e[155]=et):et=e[155];let rt;e[156]!==we||e[157]!==nt||e[158]!==et?(rt=s.jsxs(ys,{children:[we,nt,et]}),e[156]=we,e[157]=nt,e[158]=et,e[159]=rt):rt=e[159];let xe;e[160]!==Le||e[161]!==rt?(xe=s.jsx(vs,{open:Le,onOpenChange:Pe,children:rt}),e[160]=Le,e[161]=rt,e[162]=xe):xe=e[162];let Ye;return e[163]!==fe||e[164]!==H||e[165]!==ce||e[166]!==Ie||e[167]!==xe?(Ye=s.jsxs("div",{className:fe,children:[H,ce,Ie,xe]}),e[163]=fe,e[164]=H,e[165]=ce,e[166]=Ie,e[167]=xe,e[168]=Ye):Ye=e[168],Ye},cp=t=>{const e=at.c(53),{command:n,isSelected:r,onSelect:a,onDelete:i,onReset:o,onRename:c,onDuplicate:d,isMenuOpen:p,onMenuOpenChange:m}=t,{t:u}=mt();let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Ji(),e[0]=f):f=e[0];const b=f,h=r?"bg-interactive-selection":"hover:bg-interactive-hover";let v;e[1]!==h?(v=me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",h),e[1]=h,e[2]=v):v=e[2];let x;e[3]!==m?(x=b?void 0:B=>{B.preventDefault(),m(!0)},e[3]=m,e[4]=x):x=e[4];let g;e[5]!==n.name?(g=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[5]=n.name,e[6]=g):g=e[6];let w;e[7]!==n||e[8]!==u?(w=(n.scope||ri(n))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:ri(n)?u("settings.agents.sidebar.badge.system"):n.scope}),e[7]=n,e[8]=u,e[9]=w):w=e[9];let y;e[10]!==g||e[11]!==w?(y=s.jsxs("div",{className:"flex items-center gap-2",children:[g,w]}),e[10]=g,e[11]=w,e[12]=y):y=e[12];let k;e[13]!==n.description?(k=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[13]=n.description,e[14]=k):k=e[14];let D;e[15]!==a||e[16]!==y||e[17]!==k?(D=s.jsxs("button",{onClick:a,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[y,k]}),e[15]=a,e[16]=y,e[17]=k,e[18]=D):D=e[18];let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Bs,{asChild:!0,children:s.jsx(be,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[19]=j):j=e[19];let S;e[20]!==c||e[21]!==u?(S=c&&s.jsxs(Vt,{onClick:B=>{B.stopPropagation(),c()},children:[s.jsx(I,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),e[20]=c,e[21]=u,e[22]=S):S=e[22];let A;e[23]!==d?(A=B=>{B.stopPropagation(),d()},e[23]=d,e[24]=A):A=e[24];let E;e[25]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(I,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[25]=E):E=e[25];let P;e[26]!==u?(P=u("settings.common.actions.duplicate"),e[26]=u,e[27]=P):P=e[27];let C;e[28]!==A||e[29]!==P?(C=s.jsxs(Vt,{onClick:A,children:[E,P]}),e[28]=A,e[29]=P,e[30]=C):C=e[30];let N;e[31]!==o||e[32]!==u?(N=o&&s.jsxs(Vt,{onClick:B=>{B.stopPropagation(),o()},children:[s.jsx(I,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),e[31]=o,e[32]=u,e[33]=N):N=e[33];let T;e[34]!==i||e[35]!==u?(T=i&&s.jsxs(Vt,{onClick:B=>{B.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]}),e[34]=i,e[35]=u,e[36]=T):T=e[36];let M;e[37]!==S||e[38]!==C||e[39]!==N||e[40]!==T?(M=s.jsxs(zs,{align:"end",className:"w-fit min-w-20",children:[S,C,N,T]}),e[37]=S,e[38]=C,e[39]=N,e[40]=T,e[41]=M):M=e[41];let R;e[42]!==p||e[43]!==m||e[44]!==M?(R=s.jsxs(_s,{open:p,onOpenChange:m,children:[j,M]}),e[42]=p,e[43]=m,e[44]=M,e[45]=R):R=e[45];let O;e[46]!==R||e[47]!==D?(O=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[D,R]}),e[46]=R,e[47]=D,e[48]=O):O=e[48];let z;return e[49]!==O||e[50]!==v||e[51]!==x?(z=s.jsx("div",{className:v,onContextMenu:x,children:O}),e[49]=O,e[50]=v,e[51]=x,e[52]=z):z=e[52],z};function tk(t){return{selectedCommandName:t.selectedCommandName,commands:t.commands,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function sk(t){return t.skills}function nk(t){return t.loadSkills}function rk(t){return t.name}function ak(t){return!ri(t)}function ik(t,e){return t.name.localeCompare(e.name)}function ok(t,e){return t.name.localeCompare(e.name)}const lk=()=>{const{t}=mt(),{selectedCommandName:e,getCommandByName:n,createCommand:r,updateCommand:a,commands:i,commandDraft:o,setCommandDraft:c}=_d(br(C=>({selectedCommandName:C.selectedCommandName,getCommandByName:C.getCommandByName,createCommand:C.createCommand,updateCommand:C.updateCommand,commands:C.commands,commandDraft:C.commandDraft,setCommandDraft:C.setCommandDraft}))),d=e?n(e):null,p=!!(o&&o.name===e&&!d),[m,u]=l.useState(""),[f,b]=l.useState("user"),[h,v]=l.useState(""),[x,g]=l.useState(""),[w,y]=l.useState(""),[k,D]=l.useState(""),[j,S]=l.useState(!1),A=l.useRef(null);l.useEffect(()=>{if(p&&o){const C=o.name||"",N=o.scope||"user",T=o.description||"",M=o.agent||"",R=o.model||"",O=o.template||"";u(C),b(N),v(T),g(M),y(R),D(O),A.current={draftName:C,draftScope:N,description:T,agent:M,model:R,template:O}}else if(d){const C=d.description||"",N=d.agent||"",T=d.model||"",M=d.template||"";v(C),g(N),y(T),D(M),A.current={draftName:"",draftScope:"user",description:C,agent:N,model:T,template:M}}},[d,p,e,i,o]);const E=l.useMemo(()=>{const C=A.current;return C?!!(p&&(m!==C.draftName||f!==C.draftScope)||h!==C.description||x!==C.agent||w!==C.model||k!==C.template):!1},[x,h,m,f,p,w,k]),P=async()=>{const C=p?m.trim().replace(/\s+/g,"-"):e?.trim();if(!C){G.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!k.trim()){G.error(t("settings.commands.page.toast.templateRequired"));return}if(p&&i.some(N=>N.name===C)){G.error(t("settings.commands.sidebar.toast.commandExists"));return}S(!0);try{const N=x.trim(),T=w.trim(),M=k.trim(),R={name:C,description:h.trim()||void 0,agent:N===""?null:N,model:T===""?null:T,template:M,scope:p?f:void 0};let O;p?(O=await r(R),O&&c(null)):O=await a(C,R),O?G.success(t(p?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):G.error(t(p?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(N){console.error("Error saving command:",N),G.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{S(!1)}};return e?s.jsx(Es,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:p?t("settings.commands.page.title.new"):`/${e}`}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t(p?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.identity")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[p&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.commands.page.field.commandName")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),s.jsx(Wt,{value:m,onChange:C=>u(C.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(ds,{value:f,onValueChange:C=>b(C),children:[s.jsx(us,{className:"w-fit min-w-[100px]",children:s.jsx(bs,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(ms,{align:"end",children:[s.jsx(Lt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Lt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(bn,{value:h,onChange:C=>v(C.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.executionContext")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.commands.page.field.overrideAgent")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(Ll,{agentName:x,onChange:C=>g(C)})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.overrideModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(uo,{providerId:hi(w)?.providerId??"",modelId:hi(w)?.modelId??"",onChange:(C,N)=>{y(C&&N?`${C}/${N}`:"")}})})]})]})]}),s.jsxs("div",{className:"mb-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.template")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(bn,{value:k,onChange:C=>D(C.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"})}),s.jsx("div",{className:"mt-2 px-2",children:s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(be,{onClick:P,disabled:j||!E,size:"xs",className:"!font-normal",children:t(j?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(I,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.commands.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.commands.page.empty.description")})]})})},dp=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},up=t=>{const e=at.c(5),{tone:n,enabled:r}=t;if(!r){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=o):o=e[0],o}let a;e[1]!==n?(a=me("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[n]),e[1]=n,e[2]=a):a=e[2];let i;return e[3]!==a?(i=s.jsx("span",{className:a}),e[3]=a,e[4]=i):i=e[4],i},ck=t=>{const e=at.c(116),{onItemSelect:n}=t,{t:r}=mt(),{mcpServers:a,selectedMcpName:i,setSelectedMcp:o,setMcpDraft:c,loadMcpConfigs:d,deleteMcp:p}=to(br(dk)),m=Ws(uk);let u;e[0]!==m?(u=he=>he.getStatusForDirectory(m??null),e[0]=m,e[1]=u):u=e[1];const f=wn(u),b=wn(mk),h=wn(pk),[v,x]=l.useState(null),[g,w]=l.useState(!1),[y,k]=l.useState(null),[D,j]=l.useState(!1);let S;e[2]!==a?(S=a.filter(fk),e[2]=a,e[3]=S):S=e[3];const A=S;let E;e[4]!==a?(E=a.filter(hk),e[4]=a,e[5]=E):E=e[5];const P=E;let C,N;e[6]!==d?(C=()=>{d()},N=[d],e[6]=d,e[7]=C,e[8]=N):(C=e[7],N=e[8]),l.useEffect(C,N);let T;e[9]!==m||e[10]!==h||e[11]!==D||e[12]!==b?(T=()=>{if(D)return;j(!0);const he=new Promise(gk);Promise.all([b({directory:m,silent:!0}),he]).then(()=>{const F=h(m);F&&G.error(F)}).finally(()=>{j(!1)})},e[9]=m,e[10]=h,e[11]=D,e[12]=b,e[13]=T):T=e[13];const M=T;let R;e[14]!==a||e[15]!==n||e[16]!==c||e[17]!==o?(R=()=>{let he="new-mcp-server",F=1;for(;a.some(Ce=>Ce.name===he);)he=`new-mcp-server-${F}`,F++;c({name:he,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),o(he),n?.()},e[14]=a,e[15]=n,e[16]=c,e[17]=o,e[18]=R):R=e[18];const O=R;let z;e[19]!==p||e[20]!==v||e[21]!==r?(z=async()=>{if(!v)return;w(!0);const he=await p(v.name);he.ok?he.reloadFailed?G.warning(he.message||`MCP server "${v.name}" deleted, but OpenCode reload failed`,{description:he.warning||r("settings.mcp.sidebar.toast.refreshListIfStale")}):G.success(he.message||r("settings.mcp.sidebar.toast.serverDeleted",{name:v.name})):G.error(r("settings.mcp.sidebar.toast.deleteFailed")),x(null),w(!1)},e[19]=p,e[20]=v,e[21]=r,e[22]=z):z=e[22];const B=z;let $;e[23]===Symbol.for("react.memo_cache_sentinel")?($=me("flex h-full flex-col","bg-background"),e[23]=$):$=e[23];let _;e[24]!==r?(_=r("settings.mcp.sidebar.title"),e[24]=r,e[25]=_):_=e[25];let Q;e[26]!==_?(Q=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:_}),e[26]=_,e[27]=Q):Q=e[27];let W;e[28]!==r?(W=r("settings.mcp.sidebar.actions.refreshStatusAria"),e[28]=r,e[29]=W):W=e[29];let ne;e[30]!==r?(ne=r("settings.mcp.sidebar.actions.refreshStatusTitle"),e[30]=r,e[31]=ne):ne=e[31];const re=D&&"animate-spin";let ue;e[32]!==re?(ue=me("h-4 w-4",re),e[32]=re,e[33]=ue):ue=e[33];let Y;e[34]!==ue?(Y=s.jsx(I,{name:"refresh",className:ue}),e[34]=ue,e[35]=Y):Y=e[35];let le;e[36]!==M||e[37]!==D||e[38]!==W||e[39]!==ne||e[40]!==Y?(le=s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:D,onClick:M,"aria-label":W,title:ne,children:Y}),e[36]=M,e[37]=D,e[38]=W,e[39]=ne,e[40]=Y,e[41]=le):le=e[41];let J;e[42]!==Q||e[43]!==le?(J=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[Q,le]}),e[42]=Q,e[43]=le,e[44]=J):J=e[44];let L;e[45]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(mo,{className:"mb-3"}),e[45]=L):L=e[45];let V;e[46]!==a.length||e[47]!==r?(V=r("settings.mcp.sidebar.total",{count:a.length}),e[46]=a.length,e[47]=r,e[48]=V):V=e[48];let K;e[49]!==V?(K=s.jsx("span",{className:"typography-meta text-muted-foreground",children:V}),e[49]=V,e[50]=K):K=e[50];let X;e[51]!==r?(X=r("settings.mcp.sidebar.actions.addServerTitle"),e[51]=r,e[52]=X):X=e[52];let U;e[53]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),e[53]=U):U=e[53];let ae;e[54]!==O||e[55]!==X?(ae=s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:O,title:X,children:U}),e[54]=O,e[55]=X,e[56]=ae):ae=e[56];let ve;e[57]!==K||e[58]!==ae?(ve=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[K,ae]}),e[57]=K,e[58]=ae,e[59]=ve):ve=e[59];let ie;e[60]!==J||e[61]!==ve?(ie=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[J,L,ve]}),e[60]=J,e[61]=ve,e[62]=ie):ie=e[62];let fe;e[63]!==a.length||e[64]!==f||e[65]!==n||e[66]!==y||e[67]!==A||e[68]!==i||e[69]!==c||e[70]!==o||e[71]!==r||e[72]!==P?(fe=s.jsx(Es,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:a.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(I,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[A.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.mcp.sidebar.group.projectServers")}),A.map(he=>{const F=f[he.name],ee=dp(F?.status),Ce=i===he.name,Fe=Ji();return s.jsxs("div",{className:me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Ce?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Fe?void 0:we=>{we.preventDefault(),k(he.name)},children:[s.jsxs("button",{onClick:()=>{o(he.name),c(null),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(up,{tone:ee,enabled:he.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:he.name}),s.jsx("span",{title:he.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:he.type==="local"?s.jsx(I,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(I,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:he.type==="local"?he.command?.join(" ")??"":he.url??""})]}),s.jsxs(_s,{open:y===he.name,onOpenChange:we=>k(we?he.name:null),children:[s.jsx(Bs,{asChild:!0,children:s.jsx(be,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(zs,{align:"end",className:"w-fit min-w-20",children:s.jsxs(Vt,{onClick:we=>{we.stopPropagation(),x(he)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},he.name)})]}),P.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.mcp.sidebar.group.userServers")}),P.map(he=>{const F=f[he.name],ee=dp(F?.status),Ce=i===he.name,Fe=Ji();return s.jsxs("div",{className:me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Ce?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Fe?void 0:we=>{we.preventDefault(),k(he.name)},children:[s.jsxs("button",{onClick:()=>{o(he.name),c(null),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(up,{tone:ee,enabled:he.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:he.name}),s.jsx("span",{title:he.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:he.type==="local"?s.jsx(I,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(I,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:he.type==="local"?he.command?.join(" ")??"":he.url??""})]}),s.jsxs(_s,{open:y===he.name,onOpenChange:we=>k(we?he.name:null),children:[s.jsx(Bs,{asChild:!0,children:s.jsx(be,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(zs,{align:"end",className:"w-fit min-w-20",children:s.jsxs(Vt,{onClick:we=>{we.stopPropagation(),x(he)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},he.name)})]})]})}),e[63]=a.length,e[64]=f,e[65]=n,e[66]=y,e[67]=A,e[68]=i,e[69]=c,e[70]=o,e[71]=r,e[72]=P,e[73]=fe):fe=e[73];const H=v!==null;let ce;e[74]!==g?(ce=he=>{!he&&!g&&x(null)},e[74]=g,e[75]=ce):ce=e[75];let se;e[76]!==r?(se=r("settings.mcp.sidebar.deleteDialog.title"),e[76]=r,e[77]=se):se=e[77];let oe;e[78]!==se?(oe=s.jsx(Ss,{children:se}),e[78]=se,e[79]=oe):oe=e[79];const te=v?.name||"";let ke;e[80]!==r||e[81]!==te?(ke=r("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:te}),e[80]=r,e[81]=te,e[82]=ke):ke=e[82];let Ne;e[83]===Symbol.for("react.memo_cache_sentinel")?(Ne=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[83]=Ne):Ne=e[83];let je;e[84]!==ke?(je=s.jsxs(Fs,{children:[ke," ",Ne,"."]}),e[84]=ke,e[85]=je):je=e[85];let Se;e[86]!==oe||e[87]!==je?(Se=s.jsxs(As,{children:[oe,je]}),e[86]=oe,e[87]=je,e[88]=Se):Se=e[88];let De;e[89]===Symbol.for("react.memo_cache_sentinel")?(De=()=>x(null),e[89]=De):De=e[89];let ye;e[90]!==r?(ye=r("settings.common.actions.cancel"),e[90]=r,e[91]=ye):ye=e[91];let ge;e[92]!==g||e[93]!==ye?(ge=s.jsx(be,{size:"sm",variant:"ghost",onClick:De,disabled:g,children:ye}),e[92]=g,e[93]=ye,e[94]=ge):ge=e[94];let Me;e[95]!==g||e[96]!==r?(Me=r(g?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[95]=g,e[96]=r,e[97]=Me):Me=e[97];let Ue;e[98]!==B||e[99]!==g||e[100]!==Me?(Ue=s.jsx(be,{size:"sm",onClick:B,disabled:g,children:Me}),e[98]=B,e[99]=g,e[100]=Me,e[101]=Ue):Ue=e[101];let q;e[102]!==ge||e[103]!==Ue?(q=s.jsxs(Hs,{children:[ge,Ue]}),e[102]=ge,e[103]=Ue,e[104]=q):q=e[104];let Ie;e[105]!==Se||e[106]!==q?(Ie=s.jsxs(ys,{className:"max-w-md",children:[Se,q]}),e[105]=Se,e[106]=q,e[107]=Ie):Ie=e[107];let Le;e[108]!==H||e[109]!==ce||e[110]!==Ie?(Le=s.jsx(vs,{open:H,onOpenChange:ce,children:Ie}),e[108]=H,e[109]=ce,e[110]=Ie,e[111]=Le):Le=e[111];let Pe;return e[112]!==ie||e[113]!==fe||e[114]!==Le?(Pe=s.jsxs("div",{className:$,children:[ie,fe,Le]}),e[112]=ie,e[113]=fe,e[114]=Le,e[115]=Pe):Pe=e[115],Pe};function dk(t){return{mcpServers:t.mcpServers,selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function uk(t){return t.currentDirectory}function mk(t){return t.refresh}function pk(t){return t.getErrorForDirectory}function fk(t){return t.scope==="project"}function hk(t){return t.scope!=="project"}function gk(t){return setTimeout(t,500)}function ia(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Di(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function xa(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Cc(t,e,n){const r=xk(n),a=typeof n.url=="string"?n.url.trim():"",i=mp(n,"env","environment"),o=mp(n,"headers"),c=bk(n),d=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientId??"").trim():"",p=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientSecret??"").trim():"",m=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.scope??"").trim():"",u=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.redirectUri??"").trim():"",f=yk(n),b=vk(n);return{ok:!0,name:t,type:e,command:r,url:a,environment:i,headers:o,oauthEnabled:c,oauthClientId:d,oauthClientSecret:p,oauthScope:m,oauthRedirectUri:u,timeout:f,enabled:b}}function xk(t){const e=t.command,n=t.args;if(Di(e)&&Di(n))return[...e,...n];if(Di(e))return e;if(typeof e=="string"&&e.trim()){const r=e.trim().split(/\s+/);return Di(n)?[...r,...n]:r}return Di(n)?n:[]}function mp(t,...e){for(const n of e){const r=t[n];if(!ia(r))continue;const a=Object.entries(r).filter(([i,o])=>i&&typeof o=="string");if(a.length>0)return a.map(([i,o])=>({key:i,value:String(o)}))}return[]}function bk(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!ia(t.oauth))return!1;const e=t.oauth;return!!(typeof e.clientId=="string"&&e.clientId.trim()||typeof e.clientSecret=="string"&&e.clientSecret.trim()||typeof e.scope=="string"&&e.scope.trim()||typeof e.redirectUri=="string"&&e.redirectUri.trim())}function yk(t){const e=t.timeout;if(typeof e=="number"&&Number.isFinite(e)&&e>0)return String(Math.floor(e));if(typeof e=="string"&&e.trim()){const n=Number(e);if(Number.isFinite(n)&&n>0)return String(Math.floor(n))}return""}function vk(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function wk(t){const e=t.mcpServers;if(ia(e)){const r=Object.keys(e);if(r.length===1){const a=r[0],i=e[a];if(ia(i))return{name:a,entry:i}}if(r.length>1)return null}const n=Object.keys(t).filter(r=>{const a=t[r];return r!=="mcpServers"&&ia(a)});if(n.length===1){const r=n[0],a=t[r];if(mg(a))return{name:r,entry:a}}return null}function mg(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function jk(t,e){let n;try{const o=t.trim();if(!o)return xa("No JSON content provided");n=JSON.parse(o)}catch(o){return xa(o instanceof Error?`Invalid JSON: ${o.message}`:"Invalid JSON")}if(!ia(n))return xa("Expected a JSON object, not an array or primitive");const r=n,a=r.mcpServers;if(ia(a)){const o=Object.keys(a);if(o.length===0)return xa("mcpServers object is empty",n);if(o.length>1)return xa("Paste one server at a time. Found "+o.length+" servers in mcpServers",n);const c=o[0],d=a[c];return ia(d)?Cc(c,Ic(d),d):xa("Server entry is not a valid object",n)}const i=wk(r);if(i)return Cc(i.name,Ic(i.entry),i.entry);if(mg(r)){const o=Ic(r),c=typeof r.name=="string"&&r.name.trim()?r.name.trim():e?.fallbackName;return Cc(c,o,r)}return xa("No recognizable MCP server configuration found in JSON",n)}function Ic(t){return t.type==="remote"?"remote":t.type==="local"?"local":typeof t.url=="string"&&t.url.trim()?"remote":(Array.isArray(t.command)||typeof t.command=="string"||Array.isArray(t.args),"local")}function Nk(t,e,n){const r=n?.isNewServer??!1,a=t.name,i=r&&a?a:e.name??"";return{...e,name:i,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",timeout:t.type==="remote"?t.timeout:"",enabled:t.enabled}}const pg="/mcp/oauth/callback",Sk=t=>{if(typeof window>"u")return null;try{const e=t.replace(/-/g,"+").replace(/_/g,"/"),n=e.length%4===0?"":"=".repeat(4-e.length%4),r=window.atob(e+n),a=Uint8Array.from(r,i=>i.charCodeAt(0));return new TextDecoder().decode(a)}catch{return null}},fg=t=>{const e=kk(t.get("state"));if(e)return e;const n=t.get("server");if(typeof n!="string"||!n.trim())return null;const r=t.get("directory");return{name:n.trim(),directory:typeof r=="string"&&r.trim()?r.trim():null}},tu=t=>{const e=t.get("state");return typeof e!="string"?null:e.trim()||null},kk=t=>{if(typeof t!="string"||!t.trim())return null;const e=Sk(t.trim());if(!e)return null;try{const n=JSON.parse(e);return n?.v!==1||typeof n.n!="string"||!n.n.trim()?null:{name:n.n.trim(),directory:typeof n.d=="string"&&n.d.trim()?n.d.trim():null}}catch{return null}};function Ck(t){const e=[];let n="",r=!1,a=!1;for(let i=0;i<t.length;i++){const o=t[i];if(o==="'"&&!a){r=!r;continue}if(o==='"'&&!r){a=!a;continue}if((o===" "||o===" ")&&!r&&!a){n&&(e.push(n),n="");continue}n+=o}return n&&e.push(n),e}function Ik(t){const e=t.trim();if(!e)return{code:null,context:null,stateKey:null};try{const n=new URL(e),r=n.searchParams.get("code");if(typeof r=="string"&&r.trim())return{code:r.trim(),context:fg(n.searchParams),stateKey:tu(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const Pk=({value:t,onChange:e,pasteCommandTitle:n,pasteCommandLabel:r,pasteSuccess:a,clipboardReadFailed:i,preview:o})=>{const[c,d]=l.useState(()=>t.join(`
|
|
157
|
+
`)),p=l.useRef(t);l.useEffect(()=>{JSON.stringify(p.current)!==JSON.stringify(t)&&(p.current=t,d(t.join(`
|
|
158
|
+
`)))},[t]);const m=f=>{const b=f.split(`
|
|
159
|
+
`).filter(h=>h.trim().length>0);e(b)},u=async()=>{try{const b=(await navigator.clipboard.readText()).trim(),h=b.includes(`
|
|
160
|
+
`)?b.split(`
|
|
161
|
+
`).filter(v=>v.trim()):Ck(b);d(h.join(`
|
|
162
|
+
`)),e(h),G.success(a(h.length))}catch{G.error(i)}};return s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[s.jsx("div",{className:"flex items-center justify-end gap-2",children:s.jsxs(be,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:u,type:"button",title:n,children:[s.jsx(I,{name:"clipboard",className:"h-3 w-3"}),r]})}),s.jsx(bn,{value:c,onChange:f=>{d(f.target.value),m(f.target.value)},onBlur:()=>{const f=c.split(`
|
|
163
|
+
`).map(b=>b.trimEnd()).join(`
|
|
164
|
+
`);d(f),m(f)},placeholder:`npx
|
|
165
|
+
-y
|
|
166
|
+
@modelcontextprotocol/server-postgres
|
|
167
|
+
postgresql://user:pass@host/db`,rows:Math.max(4,t.length+1),className:"font-mono typography-meta resize-y min-h-[80px]",spellCheck:!1}),t.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:o(t.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:t.map((f,b)=>s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",b,"]"]}),f]},b))})})]})]})},Ak=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),pp=({value:t,onChange:e,keyTransform:n=Ak,keyPlaceholder:r="API_KEY",keyInputClassName:a="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:i="Paste .env",pasteTitle:o="Paste KEY=VALUE lines from clipboard",noPairsFoundError:c,importSuccess:d,clipboardReadFailed:p,keyLabel:m,valueLabel:u,valuePlaceholder:f,hideValueTitle:b,showValueTitle:h,addVariable:v,plainTextWarning:x,removeVariableAria:g})=>{const[w,y]=l.useState(new Set),k=()=>e([...t,{key:"",value:""}]),D=P=>{e(t.filter((C,N)=>N!==P)),y(C=>{const N=new Set(C);return N.delete(P),N})},j=(P,C,N)=>{const T=[...t];T[P]={...T[P],[C]:N},e(T)},S=P=>{y(C=>{const N=new Set(C);return N.has(P)?N.delete(P):N.add(P),N})},A=async()=>{try{const P=await navigator.clipboard.readText(),C=[];for(const T of P.split(`
|
|
168
|
+
`)){const M=T.trim();if(!M||M.startsWith("#"))continue;const R=M.indexOf("=");if(R===-1)continue;const O=M.slice(0,R).trim();let z=M.slice(R+1).trim();(z.startsWith('"')&&z.endsWith('"')||z.startsWith("'")&&z.endsWith("'"))&&(z=z.slice(1,-1)),O&&C.push({key:O,value:z})}if(C.length===0){G.error(c);return}const N=[...t];for(const T of C){const M=N.findIndex(R=>R.key===T.key);M!==-1?N[M]=T:N.push(T)}e(N),G.success(d(C.length))}catch{G.error(p)}},E=t.some(P=>P.value.length>0);return 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-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:m}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:u})]}),s.jsxs(be,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:A,type:"button",title:o,children:[s.jsx(I,{name:"clipboard",className:"h-3 w-3"}),i]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((P,C)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Wt,{value:P.key,onChange:N=>j(C,"key",n(N.target.value)),placeholder:r,className:a,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(Wt,{type:w.has(C)?"text":"password",value:P.value,onChange:N=>j(C,"value",N.target.value),placeholder:f,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>S(C),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:w.has(C)?b:h,children:w.has(C)?s.jsx(I,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>D(C),"aria-label":g,children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},C))}),s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:k,type:"button",children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),v]}),E&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:x})]})},fp=t=>{const e=at.c(14),{status:n,enabled:r,getStatusLabel:a,variant:i}=t,o=i===void 0?"compact":i;if(!r||!n)return null;let c,d;if(e[0]!==a||e[1]!==n||e[2]!==o){d=Symbol.for("react.early_return_sentinel");e:{const f={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[n]??{text:"text-muted-foreground",bg:""};if(o==="pill"){const b=me("typography-micro font-medium rounded-full px-2 py-0.5",f.text,f.bg);let h;e[5]!==a||e[6]!==n?(h=a(n),e[5]=a,e[6]=n,e[7]=h):h=e[7],d=s.jsxs("span",{className:b,children:["● ",h]});break e}c=me("typography-micro font-medium",f.text)}e[0]=a,e[1]=n,e[2]=o,e[3]=c,e[4]=d}else c=e[3],d=e[4];if(d!==Symbol.for("react.early_return_sentinel"))return d;let p;e[8]!==a||e[9]!==n?(p=a(n),e[8]=a,e[9]=n,e[10]=p):p=e[10];let m;return e[11]!==c||e[12]!==p?(m=s.jsxs("span",{className:c,children:["● ",p]}),e[11]=c,e[12]=p,e[13]=m):m=e[13],m},Dk=(t,e,n)=>{switch(t){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return n?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return e("settings.mcp.page.status.description.needsAuth");case"needs_client_registration":return n?.trim()||e("settings.mcp.page.status.description.needsClientRegistrationDefault");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},Tk=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":case"needs_client_registration":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},Mk=(t,e,n,r)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||n||r),hp=(t,e)=>{if(typeof window>"u")return null;const n=new URL(pg,window.location.origin);return typeof t=="string"&&t.trim()&&n.searchParams.set("server",t.trim()),typeof e=="string"&&e.trim()&&n.searchParams.set("directory",e.trim()),n.toString()},Ek=async t=>{const e=await fetch("/api/mcp/auth/pending",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({state:t.state,name:t.name,directory:typeof t.directory=="string"&&t.directory.trim()?t.directory.trim():null})});if(!e.ok){const n=await e.json().catch(()=>null);throw new Error(n?.error||"Failed to prepare MCP authorization callback")}},Rk=async t=>{const e=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t)}`);if(!e.ok)return null;const n=await e.json().catch(()=>null);return n?.name?.trim()?{name:n.name.trim(),directory:typeof n.directory=="string"&&n.directory.trim()?n.directory.trim():null}:null},Ti=async t=>{typeof t!="string"||!t.trim()||await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},Pc=(t,e,n)=>{const r=t instanceof Error?t.message:e;return/oauth state required/i.test(r)?n("settings.mcp.page.toast.authSessionExpired"):r},Fk=(t,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${n}`},Lk=()=>{const{t}=mt(),e=l.useCallback((Ge,St)=>t(Ge,St),[t]),{selectedMcpName:n,mcpServers:r,mcpDraft:a,setMcpDraft:i,setSelectedMcp:o,getMcpByName:c,createMcp:d,updateMcp:p,deleteMcp:m}=to(br(Ge=>({selectedMcpName:Ge.selectedMcpName,mcpServers:Ge.mcpServers,mcpDraft:Ge.mcpDraft,setMcpDraft:Ge.setMcpDraft,setSelectedMcp:Ge.setSelectedMcp,getMcpByName:Ge.getMcpByName,createMcp:Ge.createMcp,updateMcp:Ge.updateMcp,deleteMcp:Ge.deleteMcp}))),u=Ws(Ge=>Ge.currentDirectory),f=l.useMemo(()=>un(),[]),b=wn(Ge=>Ge.getStatusForDirectory(u??null)),h=wn(Ge=>Ge.getDiagnosticForDirectory(u??null)),v=wn(Ge=>Ge.refresh),x=wn(Ge=>Ge.connect),g=wn(Ge=>Ge.disconnect),w=wn(Ge=>Ge.startAuth),y=wn(Ge=>Ge.completeAuth),k=wn(Ge=>Ge.clearAuth),D=wn(Ge=>Ge.testConnection),j=n?c(n):null,S=!!(a&&a.name===n&&!j),[A,E]=l.useState(""),[P,C]=l.useState("user"),[N,T]=l.useState("local"),[M,R]=l.useState([]),[O,z]=l.useState(""),[B,$]=l.useState([]),[_,Q]=l.useState([]),[W,ne]=l.useState(!0),[re,ue]=l.useState(""),[Y,le]=l.useState(""),[J,L]=l.useState(""),[V,K]=l.useState(""),[X,U]=l.useState(""),[ae,ve]=l.useState(!0),[ie,fe]=l.useState(!1),[H,ce]=l.useState(!1),[se,oe]=l.useState(!1),[te,ke]=l.useState(!1),[Ne,je]=l.useState(!1),[Se,De]=l.useState(!1),[ye,ge]=l.useState(!1),[Me,Ue]=l.useState(!1),[q,Ie]=l.useState(null),[Le,Pe]=l.useState(null),[he,F]=l.useState(""),[ee,Ce]=l.useState(!1),Fe=l.useRef(0),we=l.useRef(!1),[Qe,pe]=l.useState(!1),[Oe,nt]=l.useState(!1),[Re,de]=l.useState(""),[He,st]=l.useState(null),qe=l.useMemo(()=>Fk(n,u),[u,n]),et=l.useRef(qe),rt=l.useRef(null),xe=l.useCallback(()=>{Ie(null),Pe(null),F(""),Ce(!1),Fe.current=0,Ue(!1),je(!1),De(!1),we.current=!1},[]),Ye=l.useCallback(()=>{de(""),st(null),nt(!0)},[]),_e=l.useCallback(async()=>{try{const Ge=await navigator.clipboard.readText();de(Ge),st(null)}catch{G.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),We=l.useCallback(()=>{const Ge=jk(Re,{fallbackName:A});if(!Ge.ok){st(Ge.error);return}const Mt=Nk(Ge,{name:A,scope:P,type:N,command:M,url:O,environment:B,headers:_,oauthEnabled:W,oauthClientId:re,oauthClientSecret:Y,oauthScope:J,oauthRedirectUri:V,timeout:X,enabled:ae},{isNewServer:S});E(Mt.name),T(Mt.type),R(Mt.command??[]),z(Mt.url??""),$(Mt.environment??[]),Q(Mt.headers??[]),ne(Mt.oauthEnabled??!1),ue(Mt.oauthClientId??""),le(Mt.oauthClientSecret??""),L(Mt.oauthScope??""),K(Mt.oauthRedirectUri??""),U(Mt.timeout??""),ve(Mt.enabled??!0),nt(!1),de(""),st(null),G.success(t("settings.mcp.page.toast.configImported"))},[Re,A,P,N,M,O,B,_,W,re,Y,J,V,X,ae,S,t]);l.useEffect(()=>{if(S&&a){E(a.name),C(a.scope||"user"),T(a.type),R(a.command),z(a.url),$(a.environment),Q(a.headers),ne(a.oauthEnabled),ue(a.oauthClientId),le(a.oauthClientSecret),L(a.oauthScope),K(a.oauthRedirectUri),U(a.timeout),ve(a.enabled),pe(!1),rt.current={mcpType:a.type,command:a.command,url:a.url,envEntries:a.environment,headerEntries:a.headers,oauthEnabled:a.oauthEnabled,oauthClientId:a.oauthClientId,oauthClientSecret:a.oauthClientSecret,oauthScope:a.oauthScope,oauthRedirectUri:a.oauthRedirectUri,timeout:a.timeout,enabled:a.enabled};return}if(j){C(j.scope==="project"?"project":"user");const Ge=Ju(j.environment),St=j.type==="remote"?j:null,Mt=Ju(St?.headers),Nt=St?.oauth,Kt=Nt&&typeof Nt=="object"?Nt:null,ns=Nt!==!1,js=j.type,ls=js==="local"?j.command??[]:[],ks=js==="remote"?j.url??"":"",Os=typeof St?.timeout=="number"&&Number.isFinite(St.timeout)?String(St.timeout):"";T(js),R(ls),z(ks),$(Ge),Q(Mt),ne(ns),ue(ns?Kt?.clientId??"":""),le(ns?Kt?.clientSecret??"":""),L(ns?Kt?.scope??"":""),K(ns?Kt?.redirectUri??"":""),U(Os),ve(j.enabled),pe(!1),rt.current={mcpType:js,command:ls,url:ks,envEntries:Ge,headerEntries:Mt,oauthEnabled:ns,oauthClientId:ns?Kt?.clientId??"":"",oauthClientSecret:ns?Kt?.clientSecret??"":"",oauthScope:ns?Kt?.scope??"":"",oauthRedirectUri:ns?Kt?.redirectUri??"":"",timeout:Os,enabled:j.enabled}}},[j,S,a]);const lt=l.useMemo(()=>{const Ge=rt.current;return Ge?N!==Ge.mcpType||ae!==Ge.enabled||JSON.stringify(M)!==JSON.stringify(Ge.command)||O!==Ge.url||JSON.stringify(B)!==JSON.stringify(Ge.envEntries)||JSON.stringify(_)!==JSON.stringify(Ge.headerEntries)||W!==Ge.oauthEnabled||re!==Ge.oauthClientId||Y!==Ge.oauthClientSecret||J!==Ge.oauthScope||V!==Ge.oauthRedirectUri||X!==Ge.timeout:!1},[N,M,O,B,_,W,re,Y,J,V,X,ae]),Je=async()=>{const Ge=S?A.trim():n??"";if(!Ge){G.error(t("settings.mcp.page.toast.nameRequired"));return}if(S&&r.some(Mt=>Mt.name===Ge)){G.error(t("settings.mcp.page.toast.serverNameExists"));return}if(N==="local"&&M.filter(Boolean).length===0){G.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(N==="remote"&&!O.trim()){G.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const St={name:Ge,scope:P,type:N,command:M,url:O,environment:B,headers:_,oauthEnabled:W,oauthClientId:re,oauthClientSecret:Y,oauthScope:J,oauthRedirectUri:V,timeout:X,enabled:ae};fe(!0);try{const Mt=S?await d(St):await p(Ge,St);Mt.ok?(await Ti(Le),xe(),S&&(i(null),o(Ge)),await v({directory:u,silent:!0}),Mt.reloadFailed?G.warning(Mt.message||t(S?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:Mt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):G.success(Mt.message||t(S?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):G.error(t("settings.mcp.page.toast.saveFailed"))}catch(Mt){G.error(Mt instanceof Error?Mt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{fe(!1)}},Ve=async()=>{if(!n)return;oe(!0);const Ge=await m(n);Ge.ok?(await Ti(Le),xe(),Ge.reloadFailed?G.warning(Ge.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:Ge.warning||t("settings.mcp.page.toast.refreshListIfStale")}):G.success(Ge.message||t("settings.mcp.page.toast.serverDeleted",{name:n})),ce(!1)):G.error(t("settings.mcp.page.toast.deleteFailed")),oe(!1)},yt=async()=>{if(n){ke(!0);try{if(b[n]?.status==="connected")await g(n,u),G.success(t("settings.mcp.page.toast.disconnected"));else{await x(n,u),await v({directory:u,silent:!0});const St=wn.getState().getStatusForDirectory(u??null)[n];St?.status==="connected"?G.success(t("settings.mcp.page.toast.connected")):St?.status==="needs_auth"?G.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):St?.status==="needs_client_registration"?G.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):St?.status==="failed"?G.error(St.error||t("settings.mcp.page.toast.connectionFailed")):G.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await v({directory:u,silent:!0})}catch(Ge){G.error(Ge instanceof Error?Ge.message:t("settings.mcp.page.toast.connectionFailed"))}finally{ke(!1)}}},$t=l.useCallback(()=>S?(G.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):lt?(G.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[lt,S,t]),Gt=l.useCallback(async(Ge=!1)=>{try{await v({directory:u,silent:Ge})}catch(St){Ge||G.error(St instanceof Error?St.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[u,v,t]);l.useEffect(()=>{Gt(!0)},[Gt]),l.useEffect(()=>{et.current=qe,ke(!1),ge(!1),xe()},[xe,qe]);const ss=l.useCallback(async()=>{if(!n||N!=="remote"||!$t())return;je(!0);const Ge=qe;let St=null;try{const Mt=wn.getState().getStatusForDirectory(u??null)[n]?.status;we.current=Mt==="needs_auth"||Mt==="needs_client_registration";const Nt=hp(n,u);if(!Nt)throw new Error(t("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!V.trim()&&!f){const ls=await p(n,{oauthEnabled:W,oauthClientId:re,oauthClientSecret:Y,oauthScope:J,oauthRedirectUri:Nt});if(!ls.ok)throw new Error(t("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(ls.reloadFailed)throw new Error(ls.warning||ls.message||t("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(et.current!==Ge)return;K(Nt),rt.current=rt.current?{...rt.current,oauthRedirectUri:Nt}:rt.current}const Kt=await w(n,u),ns=tu(new URL(Kt).searchParams);if(ns&&(St=ns,await Ek({state:ns,name:n,directory:u})),et.current!==Ge)return;Ie(Kt),Pe(ns??null),Ce(!0),Fe.current=0;const js=await sr(Kt);if(et.current!==Ge)return;js?G.message(t(f?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):G.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(Mt){await Ti(St),et.current===Ge&&G.error(Pc(Mt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{et.current===Ge&&je(!1)}},[u,f,N,re,Y,W,V,J,$t,qe,n,w,t,e,p]),wt=l.useCallback(async()=>{if(!n||!$t())return;De(!0);const Ge=qe;try{if(await k(n,u),et.current!==Ge)return;Ie(null),Pe(null),F(""),Ce(!1),Fe.current=0,await Ti(Le),G.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(St){et.current===Ge&&G.error(Pc(St,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{et.current===Ge&&De(!1)}},[Le,k,u,$t,qe,n,t,e]),Dt=l.useCallback(async()=>{if(!q)return;if((await Rn(q)).ok){G.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}G.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[q,t]),Xt=l.useCallback(async()=>{const Ge=Ik(he);if(!Ge.code){G.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const St=Ge.stateKey?await Rk(Ge.stateKey):null,Mt=Ge.context??St,Nt=Mt?.name??n,Kt=Mt?.directory??u;if(!Nt){G.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!Mt&&!$t())return;Ue(!0);const ns=qe;try{if(await y(Nt,Ge.code,Kt),await Ti(Ge.stateKey??Le),et.current!==ns)return;F(""),Ie(null),Pe(null),Ce(!1),Fe.current=0,G.success(Nt===n?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:Nt}))}catch(js){et.current===ns&&G.error(Pc(js,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{et.current===ns&&Ue(!1)}},[he,Le,y,u,$t,qe,n,t,e]),Yt=l.useCallback(async()=>{if(!(!n||!$t())){if(!ae){G.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}ge(!0);try{const Ge=await D(n,u),St=Ge.status?.status;Ge.warning?G.warning(Ge.warning):St==="connected"?G.success(t("settings.mcp.page.toast.connectionTestSucceeded")):St==="needs_auth"?G.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):St==="needs_client_registration"?G.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):St==="failed"?G.error(Ge.status?.error||Ge.error||t("settings.mcp.page.toast.connectionTestFailed")):Ge.error?G.error(Ge.error):G.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(Ge){G.error(Ge instanceof Error?Ge.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{ge(!1)}}},[u,ae,$t,n,t,D]);if(l.useEffect(()=>{if(!ee||!n)return;const Ge=window.setInterval(()=>{(async()=>{Fe.current+=1,await v({directory:u,silent:!0});const St=wn.getState().getStatusForDirectory(u??null)[n];if(St){if(we.current&&St.status!=="needs_auth"&&St.status!=="needs_client_registration"){Ce(!1),Fe.current=0,we.current=!1,Ie(null),F(""),St.status==="connected"&&G.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!we.current&&St.status==="failed"){Ce(!1),Fe.current=0,we.current=!1,G.error(St.error||t("settings.mcp.page.toast.authorizationFailed"));return}Fe.current>=30&&(Ce(!1),Fe.current=0,we.current=!1,G.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(Ge)}},[u,ee,v,n,t]),!n)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(I,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const ts=b[n],dt=n?h[n]:void 0,Rt=ts??dt,is=ts?.status==="connected",xs=ts?.status==="needs_auth"||ts?.status==="needs_client_registration",ps=f?null:hp(n,u),ws=Dk(Rt?.status,e,Rt&&"error"in Rt?Rt.error:void 0),qt=Ge=>{switch(Ge){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return t("settings.mcp.page.status.label.needsRegistration");default:return Ge}};return s.jsxs(Es,{outerClassName:"h-full",className:"w-full",children:[s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"min-w-0",children:[S?s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.mcp.page.header.newServer")}):s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:n}),s.jsx(fp,{status:Rt?.status,enabled:ae,getStatusLabel:qt,variant:"pill"})]}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:S?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(N==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")})}),!S&&s.jsxs(s.Fragment,{children:[s.jsx(be,{variant:is?"outline":"default",size:"xs",className:"!font-normal",onClick:yt,disabled:te||!ae,children:t(te?"settings.mcp.page.actions.working":is?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),N==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(be,{variant:xs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{ss()},disabled:Ne||!ae,children:t(Ne?"settings.mcp.page.actions.starting":xs?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{wt()},disabled:Se||!ae,children:t(Se?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),is&&s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{Yt()},disabled:ye||!ae,children:t(ye?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!S&&Mk(Rt?.status,q,xs,ee)&&s.jsx("div",{className:"mb-6 px-2",children:s.jsxs("div",{className:me("rounded-lg border p-3",Tk(Rt?.status)),children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(fp,{status:Rt?.status,enabled:ae,getStatusLabel:qt})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:ws}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:P==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:u??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!is&&s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Yt()},disabled:ye||!ae,children:t(ye?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),q&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.authorizationUrl")}),s.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:q}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{sr(q)},children:[s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Dt()},children:[s.jsx(I,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),N==="remote"&&(xs||ee||q)&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.auth.manualFallbackTitle")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.manualFallbackDescription")})]}),s.jsx(bn,{value:he,onChange:Ge=>F(Ge.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta resize-y","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Xt()},disabled:Me,children:t(Me?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),ee&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.mcp.page.server.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[S&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.name")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx(Wt,{value:A,onChange:Ge=>E(Ge.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 font-mono px-2",autoFocus:!0}),s.jsxs(ds,{value:P,onValueChange:Ge=>C(Ge),children:[s.jsx(us,{className:"!h-7 !w-7 !min-w-0 !px-0 !py-0 justify-center [&>svg:last-child]:hidden",title:t(P==="user"?"settings.common.scope.global":"settings.common.scope.project"),children:P==="user"?s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"})}),s.jsxs(ms,{align:"end",children:[s.jsx(Lt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Lt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),S&&s.jsx("div",{className:"py-1.5",children:s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:Ye,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(I,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]})}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ae,onClick:()=>ve(!ae),onKeyDown:Ge=>{(Ge.key===" "||Ge.key==="Enter")&&(Ge.preventDefault(),ve(!ae))},children:[s.jsx(fs,{checked:ae,onChange:ve,ariaLabel:t("settings.mcp.page.server.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.enable")})]}),s.jsx("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:s.jsxs("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.transportMode")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(be,{variant:"chip",size:"xs","aria-pressed":N==="local",onClick:()=>T("local"),className:"!font-normal",children:t("settings.mcp.page.transport.local")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":N==="remote",onClick:()=>T("remote"),className:"!font-normal",children:t("settings.mcp.page.transport.remote")})]})]})})]})]}),s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t(N==="local"?"settings.mcp.page.connection.command":"settings.mcp.page.connection.serverUrl")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:N==="local"?s.jsx(Pk,{value:M,onChange:R,pasteCommandTitle:t("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:t("settings.mcp.page.connection.pasteCommand"),pasteSuccess:Ge=>t("settings.mcp.page.toast.pastedArgumentsCount",{count:Ge}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),preview:Ge=>t("settings.mcp.page.connection.previewArgs",{count:Ge})}):s.jsx(Wt,{value:O,onChange:Ge=>z(Ge.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"})})]}),N==="remote"&&s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.mcp.page.advanced.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs(gr,{open:Qe,onOpenChange:pe,children:[s.jsxs(kr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.mcp.page.advanced.configure")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",t(W?"settings.mcp.page.advanced.autoDetect":"settings.mcp.page.advanced.custom")," · ",_.length," ",t("settings.mcp.page.advanced.headers"),X?` · ${X}ms`:"",")"]})]}),Qe?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(xr,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.advanced.timeoutMs")})}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(Wt,{type:"number",min:"1",step:"1",value:X,onChange:Ge=>U(Ge.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]}),s.jsx("p",{className:"typography-micro text-muted-foreground sm:pl-64",children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"mb-2 typography-ui-label text-foreground",children:[t("settings.mcp.page.advanced.requestHeaders"),_.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",_.length,")"]})]}),s.jsx(pp,{value:_,onChange:Q,keyTransform:Ge=>Ge.trimStart(),keyPlaceholder:t("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:t("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:t("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Ge=>t("settings.mcp.page.toast.importedVariablesCount",{count:Ge}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":W,onClick:()=>ne(!W),onKeyDown:Ge=>{(Ge.key===" "||Ge.key==="Enter")&&(Ge.preventDefault(),ne(!W))},children:[s.jsx(fs,{checked:W,onChange:ne,ariaLabel:t("settings.mcp.page.advanced.oauthAutoDetectionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.advanced.oauthAutoDetection")})]}),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[s.jsx(Wt,{value:re,onChange:Ge=>ue(Ge.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientIdPlaceholder"),className:"font-mono typography-meta",disabled:!W,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Wt,{value:Y,onChange:Ge=>le(Ge.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientSecretPlaceholder"),className:"font-mono typography-meta",disabled:!W,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Wt,{value:J,onChange:Ge=>L(Ge.target.value),placeholder:t("settings.mcp.page.advanced.oauthScopesPlaceholder"),className:"font-mono typography-meta",disabled:!W,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Wt,{value:V,onChange:Ge=>K(Ge.target.value),placeholder:t("settings.mcp.page.advanced.oauthRedirectUriPlaceholder"),className:"font-mono typography-meta",disabled:!W,"data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.advanced.oauthHint")}),ps&&s.jsxs("p",{className:"typography-micro text-muted-foreground",children:[t("settings.mcp.page.advanced.oauthCallbackHint"),s.jsx("span",{className:"mt-1 block break-all font-mono text-foreground/80",children:ps})]})]})]})})]})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[t("settings.mcp.page.env.title"),B.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",B.length,")"]})]})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:B.length===0?s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>$([{key:"",value:""}]),children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(pp,{value:B,onChange:$,keyPlaceholder:t("settings.mcp.page.env.keyPlaceholder"),pasteLabel:t("settings.mcp.page.env.pasteEnv"),pasteTitle:t("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Ge=>t("settings.mcp.page.toast.importedVariablesCount",{count:Ge}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})})]}),s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[s.jsx(be,{onClick:Je,disabled:ie||!lt&&!S,size:"xs",className:"!font-normal",children:t(ie?"settings.common.actions.saving":S?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!S&&s.jsx(be,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ce(!0),children:t("settings.common.actions.delete")})]})]}),s.jsx(vs,{open:Oe,onOpenChange:Ge=>{Ge||(nt(!1),de(""),st(null))},children:s.jsxs(ys,{className:"max-w-md",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Fs,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(bn,{value:Re,onChange:Ge=>{de(Ge.target.value),st(null)},placeholder:`{
|
|
169
|
+
"mcpServers": {
|
|
170
|
+
"postgres": {
|
|
171
|
+
"command": "npx",
|
|
172
|
+
"args": ["-y", "@modelcontextprotocol/server-postgres"]
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}`,rows:8,className:"font-mono typography-meta resize-y",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),He&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:He}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:_e,type:"button",children:[s.jsx(I,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(Hs,{children:[s.jsx(be,{variant:"outline",onClick:()=>{nt(!1),de(""),st(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(be,{onClick:We,disabled:!Re.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(vs,{open:H,onOpenChange:Ge=>{!Ge&&!se&&ce(!1)},children:s.jsxs(ys,{className:"max-w-md",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:t("settings.mcp.page.deleteDialog.title",{name:n??""})}),s.jsxs(Fs,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(Hs,{children:[s.jsx(be,{variant:"outline",onClick:()=>ce(!1),disabled:se,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(be,{variant:"destructive",size:"sm",onClick:Ve,disabled:se,children:t(se?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},Ok=t=>{const e=at.c(150),{onItemSelect:n}=t,{t:r}=mt(),[a,i]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(!1),[f,b]=l.useState(null),{selectedSkillName:h,skills:v,setSelectedSkill:x,setSkillDraft:g,createSkill:w,deleteSkill:y,getSkillDetail:k}=na(br($k));let D;e[0]!==n||e[1]!==x||e[2]!==g||e[3]!==v?(D=()=>{let _e="new-skill",We=1;for(;v.some(lt=>lt.name===_e);)_e=`new-skill-${We}`,We++;g({name:_e,scope:"user",source:"opencode",description:""}),x(_e),n?.()},e[0]=n,e[1]=x,e[2]=g,e[3]=v,e[4]=D):D=e[4];const j=D;let S;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=async _e=>{p(_e)},e[5]=S):S=e[5];const A=S;let E;e[6]!==d||e[7]!==y||e[8]!==r?(E=async()=>{if(!d)return;u(!0),await y(d.name)?(G.success(r("settings.skills.sidebar.toast.skillDeleted",{name:d.name})),p(null)):G.error(r("settings.skills.sidebar.toast.deleteSkillFailed")),u(!1)},e[6]=d,e[7]=y,e[8]=r,e[9]=E):E=e[9];const P=E;let C;e[10]!==k||e[11]!==x||e[12]!==g||e[13]!==v||e[14]!==r?(C=async _e=>{const We=_e.name;let lt=1,Je=`${We}-copy`;for(;v.some(yt=>yt.name===Je);)lt++,Je=`${We}-copy-${lt}`;const Ve=await k(_e.name);if(!Ve){G.error(r("settings.skills.sidebar.toast.duplicateLoadFailed"));return}g({name:Je,scope:_e.scope||"user",source:_e.source||"opencode",description:(Ve.sources.md.fields.includes("description"),""),instructions:""}),x(Je)},e[10]=k,e[11]=x,e[12]=g,e[13]=v,e[14]=r,e[15]=C):C=e[15];const N=C;let T;e[16]===Symbol.for("react.memo_cache_sentinel")?(T=_e=>{c(_e.name),i(_e)},e[16]=T):T=e[16];const M=T;let R;e[17]!==w||e[18]!==y||e[19]!==k||e[20]!==a||e[21]!==o||e[22]!==x||e[23]!==v||e[24]!==r?(R=async()=>{if(!a)return;const _e=o.trim().replace(/\s+/g,"-").toLowerCase();if(!_e){G.error(r("settings.skills.page.toast.skillNameRequired"));return}if(_e===a.name){i(null);return}if(v.some(Je=>Je.name===_e)){G.error(r("settings.skills.page.toast.skillExists"));return}if(!await k(a.name)){G.error(r("settings.skills.sidebar.toast.renameLoadFailed")),i(null);return}await w({name:_e,description:"Renamed skill",scope:a.scope,source:a.source})?await y(a.name)?(G.success(`Skill renamed to "${_e}"`),x(_e)):G.error(r("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):G.error(r("settings.skills.sidebar.toast.renameFailed")),i(null)},e[17]=w,e[18]=y,e[19]=k,e[20]=a,e[21]=o,e[22]=x,e[23]=v,e[24]=r,e[25]=R):R=e[25];const O=R;let z;e[26]!==v?(z=v.filter(Bk),e[26]=v,e[27]=z):z=e[27];const B=z;let $;e[28]!==v?($=v.filter(zk),e[28]=v,e[29]=$):$=e[29];const _=$;let Q;e[30]===Symbol.for("react.memo_cache_sentinel")?(Q=function(We){const lt={},Je=[];for(const yt of We)yt.group?(lt[yt.group]||(lt[yt.group]=[]),lt[yt.group].push(yt)):Je.push(yt);const Ve=Object.keys(lt).sort(_k).map(yt=>({name:yt,skills:[...lt[yt]].sort(Vk)}));return Je.sort(Uk),{sortedGroups:Ve,ungrouped:Je}},e[30]=Q):Q=e[30];const W=Q;let ne;e[31]!==B?(ne=W(B),e[31]=B,e[32]=ne):ne=e[32];const re=ne;let ue;e[33]!==_?(ue=W(_),e[33]=_,e[34]=ue):ue=e[34];const Y=ue;let le;e[35]===Symbol.for("react.memo_cache_sentinel")?(le=me("flex h-full flex-col","bg-background"),e[35]=le):le=e[35];let J;e[36]!==r?(J=r("settings.skills.sidebar.title"),e[36]=r,e[37]=J):J=e[37];let L;e[38]!==J?(L=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:J}),e[38]=J,e[39]=L):L=e[39];let V;e[40]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(mo,{className:"mb-3"}),e[40]=V):V=e[40];let K;e[41]!==v.length||e[42]!==r?(K=r("settings.skills.sidebar.total",{count:v.length}),e[41]=v.length,e[42]=r,e[43]=K):K=e[43];let X;e[44]!==K?(X=s.jsx("span",{className:"typography-meta text-muted-foreground",children:K}),e[44]=K,e[45]=X):X=e[45];let U;e[46]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),e[46]=U):U=e[46];let ae;e[47]!==j?(ae=s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:U}),e[47]=j,e[48]=ae):ae=e[48];let ve;e[49]!==X||e[50]!==ae?(ve=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[X,ae]}),e[49]=X,e[50]=ae,e[51]=ve):ve=e[51];let ie;e[52]!==L||e[53]!==ve?(ie=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[L,V,ve]}),e[52]=L,e[53]=ve,e[54]=ie):ie=e[54];let fe;e[55]!==re||e[56]!==Y||e[57]!==N||e[58]!==n||e[59]!==f||e[60]!==B||e[61]!==h||e[62]!==x||e[63]!==v.length||e[64]!==r||e[65]!==_?(fe=s.jsx(Es,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:v.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(I,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.skills.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[B.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.skills.sidebar.section.project")}),re.sortedGroups.map(_e=>{const{name:We,skills:lt}=_e;return s.jsx(bd,{label:We,count:lt.length,storageKey:"project-skills",children:lt.map(Je=>s.jsx(Mo,{skill:Je,isSelected:h===Je.name,onSelect:()=>{x(Je.name),n?.()},onRename:()=>M(Je),onDelete:()=>A(Je),onDuplicate:()=>N(Je),isMenuOpen:f===Je.name,onMenuOpenChange:Ve=>b(Ve?Je.name:null)},Je.name))},We)}),re.ungrouped.map(_e=>s.jsx(Mo,{skill:_e,isSelected:h===_e.name,onSelect:()=>{x(_e.name),n?.()},onRename:()=>M(_e),onDelete:()=>A(_e),onDuplicate:()=>N(_e),isMenuOpen:f===_e.name,onMenuOpenChange:We=>b(We?_e.name:null)},_e.name))]}),_.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.skills.sidebar.section.user")}),Y.sortedGroups.map(_e=>{const{name:We,skills:lt}=_e;return s.jsx(bd,{label:We,count:lt.length,storageKey:"user-skills",children:lt.map(Je=>s.jsx(Mo,{skill:Je,isSelected:h===Je.name,onSelect:()=>{x(Je.name),n?.()},onRename:()=>M(Je),onDelete:()=>A(Je),onDuplicate:()=>N(Je),isMenuOpen:f===Je.name,onMenuOpenChange:Ve=>b(Ve?Je.name:null)},Je.name))},We)}),Y.ungrouped.map(_e=>s.jsx(Mo,{skill:_e,isSelected:h===_e.name,onSelect:()=>{x(_e.name),n?.()},onRename:()=>M(_e),onDelete:()=>A(_e),onDuplicate:()=>N(_e),isMenuOpen:f===_e.name,onMenuOpenChange:We=>b(We?_e.name:null)},_e.name))]})]})}),e[55]=re,e[56]=Y,e[57]=N,e[58]=n,e[59]=f,e[60]=B,e[61]=h,e[62]=x,e[63]=v.length,e[64]=r,e[65]=_,e[66]=fe):fe=e[66];const H=d!==null;let ce;e[67]!==m?(ce=_e=>{!_e&&!m&&p(null)},e[67]=m,e[68]=ce):ce=e[68];let se;e[69]!==r?(se=r("settings.skills.sidebar.deleteDialog.title"),e[69]=r,e[70]=se):se=e[70];let oe;e[71]!==se?(oe=s.jsx(Ss,{children:se}),e[71]=se,e[72]=oe):oe=e[72];const te=d?.name??"";let ke;e[73]!==r||e[74]!==te?(ke=r("settings.skills.sidebar.deleteDialog.description",{name:te}),e[73]=r,e[74]=te,e[75]=ke):ke=e[75];let Ne;e[76]!==ke?(Ne=s.jsx(Fs,{children:ke}),e[76]=ke,e[77]=Ne):Ne=e[77];let je;e[78]!==oe||e[79]!==Ne?(je=s.jsxs(As,{children:[oe,Ne]}),e[78]=oe,e[79]=Ne,e[80]=je):je=e[80];let Se;e[81]===Symbol.for("react.memo_cache_sentinel")?(Se=()=>p(null),e[81]=Se):Se=e[81];let De;e[82]!==r?(De=r("settings.common.actions.cancel"),e[82]=r,e[83]=De):De=e[83];let ye;e[84]!==m||e[85]!==De?(ye=s.jsx(be,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Se,disabled:m,children:De}),e[84]=m,e[85]=De,e[86]=ye):ye=e[86];let ge;e[87]!==r?(ge=r("settings.common.actions.delete"),e[87]=r,e[88]=ge):ge=e[88];let Me;e[89]!==P||e[90]!==m||e[91]!==ge?(Me=s.jsx(be,{size:"sm",onClick:P,disabled:m,children:ge}),e[89]=P,e[90]=m,e[91]=ge,e[92]=Me):Me=e[92];let Ue;e[93]!==ye||e[94]!==Me?(Ue=s.jsxs(Hs,{children:[ye,Me]}),e[93]=ye,e[94]=Me,e[95]=Ue):Ue=e[95];let q;e[96]!==je||e[97]!==Ue?(q=s.jsxs(ys,{className:"max-w-md",children:[je,Ue]}),e[96]=je,e[97]=Ue,e[98]=q):q=e[98];let Ie;e[99]!==H||e[100]!==ce||e[101]!==q?(Ie=s.jsx(vs,{open:H,onOpenChange:ce,children:q}),e[99]=H,e[100]=ce,e[101]=q,e[102]=Ie):Ie=e[102];const Le=a!==null;let Pe;e[103]===Symbol.for("react.memo_cache_sentinel")?(Pe=_e=>!_e&&i(null),e[103]=Pe):Pe=e[103];let he;e[104]!==r?(he=r("settings.skills.sidebar.renameDialog.title"),e[104]=r,e[105]=he):he=e[105];let F;e[106]!==he?(F=s.jsx(Ss,{children:he}),e[106]=he,e[107]=F):F=e[107];const ee=a?.name??"";let Ce;e[108]!==r||e[109]!==ee?(Ce=r("settings.skills.sidebar.renameDialog.description",{name:ee}),e[108]=r,e[109]=ee,e[110]=Ce):Ce=e[110];let Fe;e[111]!==Ce?(Fe=s.jsx(Fs,{children:Ce}),e[111]=Ce,e[112]=Fe):Fe=e[112];let we;e[113]!==F||e[114]!==Fe?(we=s.jsxs(As,{children:[F,Fe]}),e[113]=F,e[114]=Fe,e[115]=we):we=e[115];let Qe;e[116]===Symbol.for("react.memo_cache_sentinel")?(Qe=_e=>c(_e.target.value),e[116]=Qe):Qe=e[116];let pe;e[117]!==r?(pe=r("settings.skills.sidebar.renameDialog.placeholder"),e[117]=r,e[118]=pe):pe=e[118];let Oe;e[119]!==O?(Oe=_e=>{_e.key==="Enter"&&O()},e[119]=O,e[120]=Oe):Oe=e[120];let nt;e[121]!==o||e[122]!==pe||e[123]!==Oe?(nt=s.jsx(Wt,{value:o,onChange:Qe,placeholder:pe,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Oe}),e[121]=o,e[122]=pe,e[123]=Oe,e[124]=nt):nt=e[124];let Re;e[125]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>i(null),e[125]=Re):Re=e[125];let de;e[126]!==r?(de=r("settings.common.actions.cancel"),e[126]=r,e[127]=de):de=e[127];let He;e[128]!==de?(He=s.jsx(be,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Re,children:de}),e[128]=de,e[129]=He):He=e[129];let st;e[130]!==r?(st=r("settings.common.actions.rename"),e[130]=r,e[131]=st):st=e[131];let qe;e[132]!==O||e[133]!==st?(qe=s.jsx(be,{size:"sm",onClick:O,children:st}),e[132]=O,e[133]=st,e[134]=qe):qe=e[134];let et;e[135]!==He||e[136]!==qe?(et=s.jsxs(Hs,{children:[He,qe]}),e[135]=He,e[136]=qe,e[137]=et):et=e[137];let rt;e[138]!==we||e[139]!==nt||e[140]!==et?(rt=s.jsxs(ys,{children:[we,nt,et]}),e[138]=we,e[139]=nt,e[140]=et,e[141]=rt):rt=e[141];let xe;e[142]!==Le||e[143]!==rt?(xe=s.jsx(vs,{open:Le,onOpenChange:Pe,children:rt}),e[142]=Le,e[143]=rt,e[144]=xe):xe=e[144];let Ye;return e[145]!==ie||e[146]!==fe||e[147]!==Ie||e[148]!==xe?(Ye=s.jsxs("div",{className:le,children:[ie,fe,Ie,xe]}),e[145]=ie,e[146]=fe,e[147]=Ie,e[148]=xe,e[149]=Ye):Ye=e[149],Ye},Mo=t=>{const e=at.c(61),{skill:n,isSelected:r,onSelect:a,onDelete:i,onRename:o,onDuplicate:c,isMenuOpen:d,onMenuOpenChange:p}=t,{t:m}=mt();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=Ji(),e[0]=u):u=e[0];const f=u;let b;e[1]!==n.source||e[2]!==m?(b=n.source==="claude"?m("settings.skills.sidebar.badge.claude"):n.source==="agents"?m("settings.skills.sidebar.badge.agents"):m("settings.skills.sidebar.badge.opencode"),e[1]=n.source,e[2]=m,e[3]=b):b=e[3];const h=b,v=r?"bg-interactive-selection":"hover:bg-interactive-hover";let x;e[4]!==v?(x=me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",v),e[4]=v,e[5]=x):x=e[5];let g;e[6]!==p?(g=f?void 0:re=>{re.preventDefault(),p(!0)},e[6]=p,e[7]=g):g=e[7];let w;e[8]!==n.name?(w=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[8]=n.name,e[9]=w):w=e[9];let y;e[10]!==n.scope?(y=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:n.scope}),e[10]=n.scope,e[11]=y):y=e[11];let k;e[12]!==h?(k=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:h}),e[12]=h,e[13]=k):k=e[13];let D;e[14]!==w||e[15]!==y||e[16]!==k?(D=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,y,k]}),e[14]=w,e[15]=y,e[16]=k,e[17]=D):D=e[17];let j;e[18]!==a||e[19]!==D?(j=s.jsx("button",{onClick:a,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:D}),e[18]=a,e[19]=D,e[20]=j):j=e[20];let S;e[21]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(Bs,{asChild:!0,children:s.jsx(be,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[21]=S):S=e[21];let A;e[22]!==o?(A=re=>{re.stopPropagation(),o()},e[22]=o,e[23]=A):A=e[23];let E;e[24]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(I,{name:"edit",className:"h-4 w-4 mr-px"}),e[24]=E):E=e[24];let P;e[25]!==m?(P=m("settings.common.actions.rename"),e[25]=m,e[26]=P):P=e[26];let C;e[27]!==A||e[28]!==P?(C=s.jsxs(Vt,{onClick:A,children:[E,P]}),e[27]=A,e[28]=P,e[29]=C):C=e[29];let N;e[30]!==c?(N=re=>{re.stopPropagation(),c()},e[30]=c,e[31]=N):N=e[31];let T;e[32]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(I,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[32]=T):T=e[32];let M;e[33]!==m?(M=m("settings.common.actions.duplicate"),e[33]=m,e[34]=M):M=e[34];let R;e[35]!==N||e[36]!==M?(R=s.jsxs(Vt,{onClick:N,children:[T,M]}),e[35]=N,e[36]=M,e[37]=R):R=e[37];let O;e[38]!==i?(O=re=>{re.stopPropagation(),i()},e[38]=i,e[39]=O):O=e[39];let z;e[40]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),e[40]=z):z=e[40];let B;e[41]!==m?(B=m("settings.common.actions.delete"),e[41]=m,e[42]=B):B=e[42];let $;e[43]!==O||e[44]!==B?($=s.jsxs(Vt,{onClick:O,className:"text-destructive focus:text-destructive",children:[z,B]}),e[43]=O,e[44]=B,e[45]=$):$=e[45];let _;e[46]!==C||e[47]!==R||e[48]!==$?(_=s.jsxs(zs,{align:"end",className:"w-fit min-w-20",children:[C,R,$]}),e[46]=C,e[47]=R,e[48]=$,e[49]=_):_=e[49];let Q;e[50]!==d||e[51]!==p||e[52]!==_?(Q=s.jsxs(_s,{open:d,onOpenChange:p,children:[S,_]}),e[50]=d,e[51]=p,e[52]=_,e[53]=Q):Q=e[53];let W;e[54]!==j||e[55]!==Q?(W=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[j,Q]}),e[54]=j,e[55]=Q,e[56]=W):W=e[56];let ne;return e[57]!==W||e[58]!==x||e[59]!==g?(ne=s.jsx("div",{className:x,onContextMenu:g,children:W}),e[57]=W,e[58]=x,e[59]=g,e[60]=ne):ne=e[60],ne};function $k(t){return{selectedSkillName:t.selectedSkillName,skills:t.skills,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,createSkill:t.createSkill,deleteSkill:t.deleteSkill,getSkillDetail:t.getSkillDetail}}function Bk(t){return t.scope==="project"}function zk(t){return t.scope==="user"}function _k(t,e){return t.localeCompare(e)}function Vk(t,e){return t.name.localeCompare(e.name)}function Uk(t,e){return t.name.localeCompare(e.name)}const Wk=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Kk=t=>{const e=t.trim(),n=e.startsWith("https://")?"https":e.startsWith("git@")?"ssh":"shorthand";if(n==="ssh")return`${e.split(":")[1].replace(/\.git$/i,"")}`;if(n==="https")return e.split("/").slice(3).filter(Boolean).join("/").replace(/\.git$/i,"");const r=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return r?`${r[1]}/${r[2].replace(/\.git$/i,"")}`:e},Hk=async()=>{try{const t=hr()?.settings;if(t)return(await t.load())?.settings||{};const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},Gk=t=>{const e=at.c(158),{open:n,onOpenChange:r}=t,{t:a}=mt(),i=Pa(qk),o=Pa(Yk),c=Pa(Jk),d=Zn(Qk),p=Zn(Xk),[m,u]=l.useState(""),[f,b]=l.useState(""),[h,v]=l.useState("");let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=[],e[0]=x):x=e[0];const[g,w]=l.useState(x),[y,k]=l.useState(null),[D,j]=l.useState(!1);let S;e[1]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[1]=S):S=e[1];const[A,E]=l.useState(S),[P,C]=l.useState(null),N=l.useRef(0);let T;e[2]===Symbol.for("react.memo_cache_sentinel")?(T=xe=>{N.current=N.current+1,j(!1),k(null),xe?.clearIdentity&&(E([]),C(null))},e[2]=T):T=e[2];const M=T;let R,O;e[3]!==p||e[4]!==n?(R=()=>{n&&(N.current=N.current+1,u(""),b(""),v(""),k(null),j(!1),E([]),C(null),p(),(async()=>{const xe=await Hk(),Ye=Array.isArray(xe?.skillCatalogs)?xe?.skillCatalogs:[];w(Ye||[])})())},O=[n,p],e[3]=p,e[4]=n,e[5]=R,e[6]=O):(R=e[5],O=e[6]),l.useEffect(R,O);let z;e[7]!==f?(z=f.trim(),e[7]=f,e[8]=z):z=e[8];const B=z;let $;e[9]!==h?($=h.trim(),e[9]=h,e[10]=$):$=e[10];const _=$;let Q;if(e[11]!==g||e[12]!==B||e[13]!==_){let xe;e[15]!==B||e[16]!==_?(xe=Ye=>{const _e=(Ye.source||"").trim(),We=(Ye.subpath||"").trim();return _e===B&&We===_},e[15]=B,e[16]=_,e[17]=xe):xe=e[17],Q=g.some(xe),e[11]=g,e[12]=B,e[13]=_,e[14]=Q}else Q=e[14];const W=Q;let ne;e[18]!==d||e[19]!==P||e[20]!==m||e[21]!==i||e[22]!==f||e[23]!==h||e[24]!==a?(ne=async()=>{const xe=f.trim();if(!xe){G.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||u(Kk(xe)),j(!1),k(null);const Ye=N.current+1;N.current=Ye;const _e=await i({source:xe,subpath:h.trim()||void 0,gitIdentityId:P||void 0});if(N.current!==Ye)return;if(!_e.ok){if(_e.error?.kind==="authRequired"){if(un()){G.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const lt=_e.error.identities||[];if(E(lt),!P&<.length>0){const Je=d&&d!=="global"&<.some(Ve=>Ve.id===d)?d:lt[0].id;C(Je)}G.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}G.error(_e.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const We=_e.items?.length||0;if(k(We),We===0){G.error(a("settings.skills.catalog.add.toast.noSkillsFound")),j(!1);return}E([]),j(!0),G.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:We}))},e[18]=d,e[19]=P,e[20]=m,e[21]=i,e[22]=f,e[23]=h,e[24]=a,e[25]=ne):ne=e[25];const re=ne;let ue;e[26]!==g||e[27]!==P||e[28]!==W||e[29]!==m||e[30]!==o||e[31]!==r||e[32]!==D||e[33]!==f||e[34]!==h||e[35]!==a?(ue=async()=>{const xe=m.trim(),Ye=f.trim(),_e=h.trim();if(!xe){G.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!Ye){G.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!D){G.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(W){G.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const We={id:Wk(),label:xe,source:Ye,..._e?{subpath:_e}:{},...P?{gitIdentityId:P}:{}},lt=[...g,We];try{await Ms({skillCatalogs:lt}),w(lt),G.success(a("settings.skills.catalog.add.toast.catalogAdded")),await o({refresh:!0}),r(!1)}catch(Je){const Ve=Je;G.error(Ve instanceof Error?Ve.message:a("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=g,e[27]=P,e[28]=W,e[29]=m,e[30]=o,e[31]=r,e[32]=D,e[33]=f,e[34]=h,e[35]=a,e[36]=ue):ue=e[36];const Y=ue;let le;e[37]!==a?(le=a("settings.skills.catalog.add.title"),e[37]=a,e[38]=le):le=e[38];let J;e[39]!==le?(J=s.jsx(Ss,{children:le}),e[39]=le,e[40]=J):J=e[40];let L;e[41]!==a?(L=a("settings.skills.catalog.add.descriptionPrefix"),e[41]=a,e[42]=L):L=e[42];let V;e[43]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[43]=V):V=e[43];let K;e[44]!==a?(K=a("settings.skills.catalog.add.descriptionSuffix"),e[44]=a,e[45]=K):K=e[45];let X;e[46]!==L||e[47]!==K?(X=s.jsxs(Fs,{children:[L," ",V,K]}),e[46]=L,e[47]=K,e[48]=X):X=e[48];let U;e[49]!==J||e[50]!==X?(U=s.jsxs(As,{children:[J,X]}),e[49]=J,e[50]=X,e[51]=U):U=e[51];let ae;e[52]!==a?(ae=a("settings.skills.catalog.add.field.catalogName"),e[52]=a,e[53]=ae):ae=e[53];let ve;e[54]!==ae?(ve=s.jsx("label",{className:"typography-ui-label text-foreground",children:ae}),e[54]=ae,e[55]=ve):ve=e[55];let ie;e[56]===Symbol.for("react.memo_cache_sentinel")?(ie=xe=>u(xe.target.value),e[56]=ie):ie=e[56];let fe;e[57]!==a?(fe=a("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[57]=a,e[58]=fe):fe=e[58];let H;e[59]!==m||e[60]!==fe?(H=s.jsx(Wt,{value:m,onChange:ie,placeholder:fe}),e[59]=m,e[60]=fe,e[61]=H):H=e[61];let ce;e[62]!==ve||e[63]!==H?(ce=s.jsxs("div",{className:"space-y-2",children:[ve,H]}),e[62]=ve,e[63]=H,e[64]=ce):ce=e[64];let se;e[65]!==a?(se=a("settings.skills.catalog.add.field.repository"),e[65]=a,e[66]=se):se=e[66];let oe;e[67]!==se?(oe=s.jsx("label",{className:"typography-ui-label text-foreground",children:se}),e[67]=se,e[68]=oe):oe=e[68];let te;e[69]===Symbol.for("react.memo_cache_sentinel")?(te=xe=>{b(xe.target.value),M({clearIdentity:!0})},e[69]=te):te=e[69];let ke;e[70]!==a?(ke=a("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[70]=a,e[71]=ke):ke=e[71];let Ne;e[72]!==f||e[73]!==ke?(Ne=s.jsx(Wt,{value:f,onChange:te,placeholder:ke}),e[72]=f,e[73]=ke,e[74]=Ne):Ne=e[74];let je;e[75]!==a?(je=a("settings.skills.catalog.add.field.repositoryHint"),e[75]=a,e[76]=je):je=e[76];let Se;e[77]!==je?(Se=s.jsx("p",{className:"typography-micro text-muted-foreground",children:je}),e[77]=je,e[78]=Se):Se=e[78];let De;e[79]!==oe||e[80]!==Ne||e[81]!==Se?(De=s.jsxs("div",{className:"space-y-2",children:[oe,Ne,Se]}),e[79]=oe,e[80]=Ne,e[81]=Se,e[82]=De):De=e[82];let ye;e[83]!==a?(ye=a("settings.skills.catalog.add.field.optionalSubpath"),e[83]=a,e[84]=ye):ye=e[84];let ge;e[85]!==ye?(ge=s.jsx("label",{className:"typography-ui-label text-foreground",children:ye}),e[85]=ye,e[86]=ge):ge=e[86];let Me;e[87]===Symbol.for("react.memo_cache_sentinel")?(Me=xe=>{v(xe.target.value),M({clearIdentity:!0})},e[87]=Me):Me=e[87];let Ue;e[88]!==a?(Ue=a("settings.skills.catalog.shared.field.subpathPlaceholder"),e[88]=a,e[89]=Ue):Ue=e[89];let q;e[90]!==h||e[91]!==Ue?(q=s.jsx(Wt,{value:h,onChange:Me,placeholder:Ue}),e[90]=h,e[91]=Ue,e[92]=q):q=e[92];let Ie;e[93]!==ge||e[94]!==q?(Ie=s.jsxs("div",{className:"space-y-2",children:[ge,q]}),e[93]=ge,e[94]=q,e[95]=Ie):Ie=e[95];let Le;e[96]!==P||e[97]!==A||e[98]!==a?(Le=A.length>0&&!un()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:a("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:a("settings.skills.catalog.shared.auth.description")})]}),s.jsxs(ds,{value:P||"",onValueChange:xe=>{C(xe),M()},children:[s.jsx(us,{className:"w-fit",children:s.jsx("span",{children:A.find(xe=>xe.id===P)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(ms,{align:"start",children:A.map(Zk)})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[96]=P,e[97]=A,e[98]=a,e[99]=Le):Le=e[99];let Pe;e[100]!==y||e[101]!==a?(Pe=y!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:y})}):null,e[100]=y,e[101]=a,e[102]=Pe):Pe=e[102];let he;e[103]!==W||e[104]!==a?(he=W?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null,e[103]=W,e[104]=a,e[105]=he):he=e[105];let F;e[106]!==ce||e[107]!==De||e[108]!==Ie||e[109]!==Le||e[110]!==Pe||e[111]!==he?(F=s.jsxs("div",{className:"space-y-4",children:[ce,De,Ie,Le,Pe,he]}),e[106]=ce,e[107]=De,e[108]=Ie,e[109]=Le,e[110]=Pe,e[111]=he,e[112]=F):F=e[112];let ee;e[113]!==r?(ee=()=>r(!1),e[113]=r,e[114]=ee):ee=e[114];let Ce;e[115]!==a?(Ce=a("settings.common.actions.cancel"),e[115]=a,e[116]=Ce):Ce=e[116];let Fe;e[117]!==ee||e[118]!==Ce?(Fe=s.jsx(be,{size:"sm",variant:"ghost",onClick:ee,children:Ce}),e[117]=ee,e[118]=Ce,e[119]=Fe):Fe=e[119];let we;e[120]!==re?(we=()=>{re()},e[120]=re,e[121]=we):we=e[121];let Qe;e[122]!==c||e[123]!==f?(Qe=c||!f.trim(),e[122]=c,e[123]=f,e[124]=Qe):Qe=e[124];let pe;e[125]===Symbol.for("react.memo_cache_sentinel")?(pe=s.jsx(I,{name:"git-repository",className:"h-4 w-4"}),e[125]=pe):pe=e[125];let Oe;e[126]!==c||e[127]!==a?(Oe=a(c?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[126]=c,e[127]=a,e[128]=Oe):Oe=e[128];let nt;e[129]!==we||e[130]!==Qe||e[131]!==Oe?(nt=s.jsxs(be,{size:"sm",className:"gap-2",variant:"ghost",onClick:we,disabled:Qe,children:[pe,Oe]}),e[129]=we,e[130]=Qe,e[131]=Oe,e[132]=nt):nt=e[132];let Re;e[133]!==Y?(Re=()=>{Y()},e[133]=Y,e[134]=Re):Re=e[134];let de;e[135]!==W||e[136]!==m||e[137]!==D||e[138]!==f?(de=!D||W||!m.trim()||!f.trim(),e[135]=W,e[136]=m,e[137]=D,e[138]=f,e[139]=de):de=e[139];let He;e[140]!==a?(He=a("settings.skills.catalog.add.actions.addCatalog"),e[140]=a,e[141]=He):He=e[141];let st;e[142]!==Re||e[143]!==de||e[144]!==He?(st=s.jsx(be,{size:"sm",onClick:Re,disabled:de,children:He}),e[142]=Re,e[143]=de,e[144]=He,e[145]=st):st=e[145];let qe;e[146]!==Fe||e[147]!==nt||e[148]!==st?(qe=s.jsxs(Hs,{children:[Fe,nt,st]}),e[146]=Fe,e[147]=nt,e[148]=st,e[149]=qe):qe=e[149];let et;e[150]!==U||e[151]!==F||e[152]!==qe?(et=s.jsxs(ys,{className:"max-w-xl",children:[U,F,qe]}),e[150]=U,e[151]=F,e[152]=qe,e[153]=et):et=e[153];let rt;return e[154]!==r||e[155]!==n||e[156]!==et?(rt=s.jsx(vs,{open:n,onOpenChange:r,children:et}),e[154]=r,e[155]=n,e[156]=et,e[157]=rt):rt=e[157],rt};function qk(t){return t.scanRepo}function Yk(t){return t.loadCatalog}function Jk(t){return t.isScanning}function Qk(t){return t.defaultGitIdentityId}function Xk(t){return t.loadDefaultGitIdentityId}function Zk(t){return s.jsx(Lt,{value:t.id,children:t.name},t.id)}const e3=t=>{const e=at.c(85),{open:n,onOpenChange:r,conflicts:a,onConfirm:i}=t,{t:o}=mt();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={},e[0]=c):c=e[0];const[d,p]=l.useState(c);let m,u;e[1]!==a||e[2]!==n?(m=()=>{if(!n)return;const J={};for(const L of a)J[L.skillName]="skip";p(J)},u=[n,a],e[1]=a,e[2]=n,e[3]=m,e[4]=u):(m=e[3],u=e[4]),l.useEffect(m,u);let f;e[5]!==a?(f=J=>{const L={};for(const V of a)L[V.skillName]=J;p(L)},e[5]=a,e[6]=f):f=e[6];const b=f;let h;e[7]!==a||e[8]!==d?(h=a.length>0&&a.every(J=>d[J.skillName]),e[7]=a,e[8]=d,e[9]=h):h=e[9];const v=h;let x;e[10]!==o?(x=o("settings.skills.catalog.conflicts.title"),e[10]=o,e[11]=x):x=e[11];let g;e[12]!==x?(g=s.jsx(Ss,{children:x}),e[12]=x,e[13]=g):g=e[13];let w;e[14]!==o?(w=o("settings.skills.catalog.conflicts.description"),e[14]=o,e[15]=w):w=e[15];let y;e[16]!==w?(y=s.jsx(Fs,{children:w}),e[16]=w,e[17]=y):y=e[17];let k;e[18]!==g||e[19]!==y?(k=s.jsxs(As,{children:[g,y]}),e[18]=g,e[19]=y,e[20]=k):k=e[20];let D;e[21]!==a.length||e[22]!==o?(D=o("settings.skills.catalog.conflicts.count",{count:a.length}),e[21]=a.length,e[22]=o,e[23]=D):D=e[23];let j;e[24]!==D?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:D}),e[24]=D,e[25]=j):j=e[25];let S;e[26]!==b?(S=()=>b("skip"),e[26]=b,e[27]=S):S=e[27];let A;e[28]!==o?(A=o("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=o,e[29]=A):A=e[29];let E;e[30]!==S||e[31]!==A?(E=s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:S,children:A}),e[30]=S,e[31]=A,e[32]=E):E=e[32];let P;e[33]!==b?(P=()=>b("overwrite"),e[33]=b,e[34]=P):P=e[34];let C;e[35]!==o?(C=o("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=o,e[36]=C):C=e[36];let N;e[37]!==P||e[38]!==C?(N=s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:P,children:C}),e[37]=P,e[38]=C,e[39]=N):N=e[39];let T;e[40]!==E||e[41]!==N?(T=s.jsxs("div",{className:"flex items-center gap-2",children:[E,N]}),e[40]=E,e[41]=N,e[42]=T):T=e[42];let M;e[43]!==j||e[44]!==T?(M=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,T]}),e[43]=j,e[44]=T,e[45]=M):M=e[45];let R;if(e[46]!==a||e[47]!==d||e[48]!==o){let J;e[50]!==d||e[51]!==o?(J=L=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label truncate",children:L.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:o("settings.skills.catalog.conflicts.installedIn",{scope:L.scope==="project"?o("settings.skills.catalog.conflicts.scope.project"):o("settings.skills.catalog.conflicts.scope.user"),source:L.source==="agents"?o("settings.skills.catalog.conflicts.source.agents"):o("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(ds,{value:d[L.skillName]||"skip",onValueChange:V=>p(K=>({...K,[L.skillName]:V})),children:[s.jsx(us,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(d[L.skillName]||"skip")==="overwrite"?o("settings.skills.catalog.conflicts.decision.overwrite"):o("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(ms,{align:"end",children:[s.jsx(Lt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(Lt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},L.skillName),e[50]=d,e[51]=o,e[52]=J):J=e[52],R=a.map(J),e[46]=a,e[47]=d,e[48]=o,e[49]=R}else R=e[49];let O;e[53]!==R?(O=s.jsx("div",{className:"space-y-2",children:R}),e[53]=R,e[54]=O):O=e[54];let z;e[55]!==M||e[56]!==O?(z=s.jsxs("div",{className:"space-y-3",children:[M,O]}),e[55]=M,e[56]=O,e[57]=z):z=e[57];let B;e[58]!==r?(B=()=>r(!1),e[58]=r,e[59]=B):B=e[59];let $;e[60]!==o?($=o("settings.common.actions.cancel"),e[60]=o,e[61]=$):$=e[61];let _;e[62]!==B||e[63]!==$?(_=s.jsx(be,{size:"sm",variant:"ghost",onClick:B,children:$}),e[62]=B,e[63]=$,e[64]=_):_=e[64];let Q;e[65]!==d||e[66]!==i?(Q=()=>i(d),e[65]=d,e[66]=i,e[67]=Q):Q=e[67];const W=!v;let ne;e[68]!==o?(ne=o("settings.skills.catalog.conflicts.actions.continue"),e[68]=o,e[69]=ne):ne=e[69];let re;e[70]!==Q||e[71]!==W||e[72]!==ne?(re=s.jsx(be,{size:"sm",onClick:Q,disabled:W,children:ne}),e[70]=Q,e[71]=W,e[72]=ne,e[73]=re):re=e[73];let ue;e[74]!==_||e[75]!==re?(ue=s.jsxs(Hs,{children:[_,re]}),e[74]=_,e[75]=re,e[76]=ue):ue=e[76];let Y;e[77]!==k||e[78]!==z||e[79]!==ue?(Y=s.jsxs(ys,{className:"max-w-2xl",children:[k,z,ue]}),e[77]=k,e[78]=z,e[79]=ue,e[80]=Y):Y=e[80];let le;return e[81]!==r||e[82]!==n||e[83]!==Y?(le=s.jsx(vs,{open:n,onOpenChange:r,children:Y}),e[81]=r,e[82]=n,e[83]=Y,e[84]=le):le=e[84],le},su=[{value:"user-opencode",scope:"user",source:"opencode",label:"User / OpenCode",description:"Global OpenCode config location"},{value:"project-opencode",scope:"project",source:"opencode",label:"Project / OpenCode",description:"Current project .opencode location"},{value:"user-agents",scope:"user",source:"agents",label:"User / Agents",description:"Global .agents compatibility location"},{value:"project-agents",scope:"project",source:"agents",label:"Project / Agents",description:"Current project .agents compatibility location"}];function Ki(t,e){return t==="project"&&e==="claude"?"project-claude":t==="project"&&e==="agents"?"project-agents":e==="claude"?"user-claude":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function hg(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=su.find(n=>n.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const t3=t=>{const e=at.c(124),{open:n,onOpenChange:r,item:a}=t,{t:i}=mt(),o=Pa(s3),c=Pa(n3),[d,p]=l.useState("user"),[m,u]=l.useState("opencode"),f=Ls(r3),b=Ls(a3),[h,v]=l.useState(null),[x,g]=l.useState(!1);let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=[],e[0]=w):w=e[0];const[y,k]=l.useState(w),[D,j]=l.useState(null);let S,A;e[1]!==b||e[2]!==n?(S=()=>{n&&(p("user"),u("opencode"),v(b),g(!1),k([]),j(null))},A=[n,b],e[1]=b,e[2]=n,e[3]=S,e[4]=A):(S=e[3],A=e[4]),l.useEffect(S,A);let E;e[5]!==i?(E=Pe=>{switch(Pe){case"project-opencode":return i("settings.skills.location.option.projectOpencode.label");case"user-agents":return i("settings.skills.location.option.userAgents.label");case"project-agents":return i("settings.skills.location.option.projectAgents.label");default:return i("settings.skills.location.option.userOpencode.label")}},e[5]=i,e[6]=E):E=e[6];const P=E;let C;e[7]!==i?(C=Pe=>{switch(Pe){case"project-opencode":return i("settings.skills.location.option.projectOpencode.description");case"user-agents":return i("settings.skills.location.option.userAgents.description");case"project-agents":return i("settings.skills.location.option.projectAgents.description");default:return i("settings.skills.location.option.userOpencode.description")}},e[7]=i,e[8]=C):C=e[8];const N=C;let T;e:{if(f.length===0){T=null;break e}if(h&&f.some(Pe=>Pe.id===h)){T=h;break e}if(b&&f.some(Pe=>Pe.id===b)){T=b;break e}T=f[0]?.id??null}const M=T;let R;e:{if(d!=="project"){R=null;break e}const Pe=M;if(!Pe){R=null;break e}let he;if(e[9]!==Pe||e[10]!==f){let ee;e[12]!==Pe?(ee=Ce=>Ce.id===Pe,e[12]=Pe,e[13]=ee):ee=e[13],he=f.find(ee),e[9]=Pe,e[10]=f,e[11]=he}else he=e[11];R=he?.path??null}const O=R;let z;e[14]!==o||e[15]!==a||e[16]!==r||e[17]!==i?(z=async Pe=>{const he={skillDir:Pe.skillDir};a?.clawdhub&&(he.clawdhub={slug:a.clawdhub.slug,version:a.clawdhub.version});const F=await o({source:Pe.source,subpath:Pe.subpath,gitIdentityId:a?.gitIdentityId,scope:Pe.scope,targetSource:Pe.targetSource,selections:[he],conflictPolicy:"prompt",conflictDecisions:Pe.conflictDecisions},{directory:Pe.directoryOverride??null});if(F.ok){G.success(i("settings.skills.catalog.installSkill.toast.installed")),r(!1);return}if(F.error?.kind==="conflicts"){j({source:Pe.source,subpath:Pe.subpath,scope:Pe.scope,targetSource:Pe.targetSource,skillDir:Pe.skillDir,directoryOverride:Pe.directoryOverride??null}),k(F.error.conflicts),g(!0);return}if(F.error?.kind==="authRequired"){G.error(F.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}G.error(F.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=o,e[15]=a,e[16]=r,e[17]=i,e[18]=z):z=e[18];const B=z;if(!a)return null;let $;e[19]!==i?($=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=$):$=e[20];let _;e[21]!==$?(_=s.jsx(Ss,{children:$}),e[21]=$,e[22]=_):_=e[22];let Q;e[23]!==i?(Q=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=Q):Q=e[24];let W;e[25]!==a.skillName?(W=s.jsx("span",{className:"font-semibold text-foreground",children:a.skillName}),e[25]=a.skillName,e[26]=W):W=e[26];let ne;e[27]!==i?(ne=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=ne):ne=e[28];let re;e[29]!==Q||e[30]!==W||e[31]!==ne?(re=s.jsxs(Fs,{children:[Q," ",W," ",ne]}),e[29]=Q,e[30]=W,e[31]=ne,e[32]=re):re=e[32];let ue;e[33]!==_||e[34]!==re?(ue=s.jsxs(As,{children:[_,re]}),e[33]=_,e[34]=re,e[35]=ue):ue=e[35];let Y;e[36]!==i?(Y=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=Y):Y=e[37];let le;e[38]!==Y?(le=s.jsx("span",{className:"typography-ui-label text-foreground",children:Y}),e[38]=Y,e[39]=le):le=e[39];let J;e[40]!==d||e[41]!==m?(J=Ki(d,m),e[40]=d,e[41]=m,e[42]=J):J=e[42];let L;e[43]===Symbol.for("react.memo_cache_sentinel")?(L=Pe=>{const he=hg(Pe);p(he.scope),u(he.source==="agents"?"agents":"opencode")},e[43]=L):L=e[43];let V;e[44]!==d?(V=d==="user"?s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=d,e[45]=V):V=e[45];let K;e[46]!==m?(K=m==="agents"?s.jsx(I,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=K):K=e[47];let X;e[48]!==P||e[49]!==d||e[50]!==m?(X=P(Ki(d,m)),e[48]=P,e[49]=d,e[50]=m,e[51]=X):X=e[51];let U;e[52]!==X?(U=s.jsx("span",{children:X}),e[52]=X,e[53]=U):U=e[53];let ae;e[54]!==V||e[55]!==K||e[56]!==U?(ae=s.jsxs(us,{className:"w-fit gap-1.5",children:[V,K,U]}),e[54]=V,e[55]=K,e[56]=U,e[57]=ae):ae=e[57];let ve;e[58]!==N||e[59]!==P?(ve=su.map(Pe=>s.jsx(Lt,{value:Pe.value,className:"pr-2 [&>span:first-child]:hidden",children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[Pe.scope==="user"?s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),Pe.source==="agents"?s.jsx(I,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:P(Pe.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:N(Pe.value)})]})},Pe.value)),e[58]=N,e[59]=P,e[60]=ve):ve=e[60];let ie;e[61]!==ve?(ie=s.jsx(ms,{align:"start",children:ve}),e[61]=ve,e[62]=ie):ie=e[62];let fe;e[63]!==J||e[64]!==ae||e[65]!==ie?(fe=s.jsxs(ds,{value:J,onValueChange:L,children:[ae,ie]}),e[63]=J,e[64]=ae,e[65]=ie,e[66]=fe):fe=e[66];let H;e[67]!==le||e[68]!==fe?(H=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[le,fe]}),e[67]=le,e[68]=fe,e[69]=H):H=e[69];let ce;e[70]!==f||e[71]!==M||e[72]!==d||e[73]!==i?(ce=d==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.skills.catalog.installSkill.field.project")}),f.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(ds,{value:M??"",onValueChange:Pe=>v(Pe),disabled:f.length===1,children:[s.jsx(us,{className:"w-fit",children:s.jsx(bs,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(ms,{align:"start",children:f.map(i3)})]})]}),e[70]=f,e[71]=M,e[72]=d,e[73]=i,e[74]=ce):ce=e[74];let se;e[75]!==a.warnings?(se=a.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:a.warnings.join(" · ")}):null,e[75]=a.warnings,e[76]=se):se=e[76];let oe;e[77]!==H||e[78]!==ce||e[79]!==se?(oe=s.jsxs("div",{className:"mt-2 space-y-3",children:[H,ce,se]}),e[77]=H,e[78]=ce,e[79]=se,e[80]=oe):oe=e[80];let te;e[81]!==r?(te=()=>r(!1),e[81]=r,e[82]=te):te=e[82];let ke;e[83]!==i?(ke=i("settings.common.actions.cancel"),e[83]=i,e[84]=ke):ke=e[84];let Ne;e[85]!==te||e[86]!==ke?(Ne=s.jsx(be,{size:"sm",variant:"ghost",onClick:te,children:ke}),e[85]=te,e[86]=ke,e[87]=Ne):Ne=e[87];const je=c||!a.installable||d==="project"&&!O;let Se;e[88]!==O||e[89]!==B||e[90]!==a.repoSource||e[91]!==a.repoSubpath||e[92]!==a.skillDir||e[93]!==d||e[94]!==m?(Se=()=>{B({source:a.repoSource,subpath:a.repoSubpath,scope:d,targetSource:m,skillDir:a.skillDir,directoryOverride:O})},e[88]=O,e[89]=B,e[90]=a.repoSource,e[91]=a.repoSubpath,e[92]=a.skillDir,e[93]=d,e[94]=m,e[95]=Se):Se=e[95];let De;e[96]!==c||e[97]!==i?(De=i(c?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=c,e[97]=i,e[98]=De):De=e[98];let ye;e[99]!==je||e[100]!==Se||e[101]!==De?(ye=s.jsx(be,{size:"sm",disabled:je,onClick:Se,children:De}),e[99]=je,e[100]=Se,e[101]=De,e[102]=ye):ye=e[102];let ge;e[103]!==Ne||e[104]!==ye?(ge=s.jsxs(Hs,{children:[Ne,ye]}),e[103]=Ne,e[104]=ye,e[105]=ge):ge=e[105];let Me;e[106]!==ue||e[107]!==oe||e[108]!==ge?(Me=s.jsxs(ys,{className:"max-w-md",children:[ue,oe,ge]}),e[106]=ue,e[107]=oe,e[108]=ge,e[109]=Me):Me=e[109];let Ue;e[110]!==r||e[111]!==n||e[112]!==Me?(Ue=s.jsx(vs,{open:n,onOpenChange:r,children:Me}),e[110]=r,e[111]=n,e[112]=Me,e[113]=Ue):Ue=e[113];let q;e[114]!==D||e[115]!==B?(q=Pe=>{D&&(B({source:D.source,subpath:D.subpath,scope:D.scope,targetSource:D.targetSource,skillDir:D.skillDir,conflictDecisions:Pe,directoryOverride:D.directoryOverride??null}),g(!1))},e[114]=D,e[115]=B,e[116]=q):q=e[116];let Ie;e[117]!==y||e[118]!==x||e[119]!==q?(Ie=s.jsx(e3,{open:x,onOpenChange:g,conflicts:y,onConfirm:q}),e[117]=y,e[118]=x,e[119]=q,e[120]=Ie):Ie=e[120];let Le;return e[121]!==Ue||e[122]!==Ie?(Le=s.jsxs(s.Fragment,{children:[Ue,Ie]}),e[121]=Ue,e[122]=Ie,e[123]=Le):Le=e[123],Le};function s3(t){return t.installSkills}function n3(t){return t.isInstalling}function r3(t){return t.projects}function a3(t){return t.activeProjectId}function i3(t){return s.jsx(Lt,{value:t.id,children:t.label||t.path},t.id)}const o3=async()=>{try{const t=hr()?.settings;if(t)return(await t.load())?.settings||{};const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},l3=({mode:t,onModeChange:e,showModeTabs:n=!0})=>{const{t:r}=mt(),{sources:a,itemsBySource:i,selectedSourceId:o,setSelectedSource:c,loadCatalog:d,loadSource:p,loadMoreClawdHub:m,isLoadingCatalog:u,isLoadingSource:f,isLoadingMore:b,loadedSourceIds:h,clawdhubHasMoreBySource:v,lastCatalogError:x}=Pa(br(_=>({sources:_.sources,itemsBySource:_.itemsBySource,selectedSourceId:_.selectedSourceId,setSelectedSource:_.setSelectedSource,loadCatalog:_.loadCatalog,loadSource:_.loadSource,loadMoreClawdHub:_.loadMoreClawdHub,isLoadingCatalog:_.isLoadingCatalog,isLoadingSource:_.isLoadingSource,isLoadingMore:_.isLoadingMore,loadedSourceIds:_.loadedSourceIds,clawdhubHasMoreBySource:_.clawdhubHasMoreBySource,lastCatalogError:_.lastCatalogError}))),[g,w]=l.useState(""),[y,k]=l.useState(!1),[D,j]=l.useState(!1),[S,A]=l.useState(null),[E,P]=l.useState(!1),[C,N]=l.useState(!1);l.useEffect(()=>{d()},[d]),l.useEffect(()=>{o&&(h[o]||p(o))},[o,h,p]);const T=l.useMemo(()=>o?i[o]||[]:[],[i,o]),M=l.useMemo(()=>{const _=g.trim().toLowerCase();return _?T.filter(Q=>{const W=Q.skillName.toLowerCase(),ne=(Q.description||"").toLowerCase(),re=(Q.frontmatterName||"").toLowerCase();return W.includes(_)||ne.includes(_)||re.includes(_)}):T},[T,g]),R=l.useMemo(()=>a.find(_=>_.id===o)||null,[a,o]),O=!!(o&&o.startsWith("custom:")),z=R?.source==="clawdhub:registry"||R?.sourceType==="clawdhub",B=!!(o&&(v[o]??!0)),$=async()=>{if(!(!o||!O)){P(!0);try{const _=await o3(),W=(Array.isArray(_?.skillCatalogs)?_?.skillCatalogs:[]).filter(ne=>ne.id!==o);await Ms({skillCatalogs:W}),await d({refresh:!0}),N(!1)}finally{P(!1)}}};return s.jsx(Es,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsxs("div",{className:"mb-4",children:[n&&s.jsx("div",{className:"mb-4",children:s.jsx("div",{className:"h-10",children:s.jsx(Er,{items:[{id:"manual",label:r("settings.skills.catalog.page.mode.manual")},{id:"external",label:r("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:_=>e(_),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground px-1",children:r("settings.skills.catalog.page.title")})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:r("settings.skills.catalog.page.section.sourceRepository")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsxs(ds,{value:o||"",onValueChange:_=>c(_),children:[s.jsx(us,{className:"w-fit",children:s.jsx(bs,{placeholder:r("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:R?.label})}),s.jsx(ms,{align:"start",children:a.map(_=>s.jsx(Lt,{value:_.id,children:_.label},_.id))})]}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{o?p(o,{refresh:!0}):d({refresh:!0})},disabled:u||f,title:r("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(I,{name:"refresh",className:me("h-3.5 w-3.5",(u||f)&&"animate-spin")})}),O&&s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>N(!0),disabled:E,title:r("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(be,{size:"xs",className:"!font-normal gap-1",onClick:()=>k(!0),children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})," ",r("settings.skills.catalog.page.actions.addCatalog")]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsxs("div",{className:"relative",children:[s.jsx(I,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Wt,{value:g,onChange:_=>w(_.target.value),placeholder:r("settings.skills.catalog.shared.field.searchSkillsPlaceholder"),className:"h-7 pl-8 w-full sm:w-64"})]}),s.jsx("span",{className:"typography-meta text-muted-foreground mt-1 block",children:u?r("settings.skills.catalog.page.loading.catalog"):r("settings.skills.catalog.page.foundCount",{count:M.length})})]})]})]}),x&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:r("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:x.message})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("section",{className:"px-2 pb-2 pt-0",children:M.length===0&&!f?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:r("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.skills.catalog.page.empty.noSkillsDescription")})]}):f?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(I,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:r("settings.skills.catalog.page.loading.skills")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:M.map(_=>{const Q=_.installed?.isInstalled,W=_.installed?.scope;return s.jsx("div",{className:"py-2",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:_.skillName}),Q&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:r("settings.skills.catalog.page.badge.installed",{scope:W||r("settings.skills.catalog.page.badge.unknown")})}),!_.installable&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:r("settings.skills.catalog.page.badge.notInstallable")})]}),_.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:_.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:r("settings.skills.catalog.shared.noDescription")}),_.clawdhub&&s.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[_.clawdhub.owner&&s.jsxs("span",{children:[r("settings.skills.catalog.page.byOwnerPrefix")," ",s.jsx("span",{className:"font-medium text-foreground/80",children:_.clawdhub.owner})]}),s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(I,{name:"download",className:"h-3 w-3"}),_.clawdhub.downloads?.toLocaleString()??0]}),(_.clawdhub.stars??0)>0&&s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(I,{name:"star",className:"h-3 w-3"}),_.clawdhub.stars]}),s.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",_.clawdhub.version]})]}),_.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] mt-1.5 bg-[var(--status-warning)]/10 px-2 py-1 rounded w-fit",children:_.warnings.join(" · ")}):null]}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!_.installable,onClick:()=>{A(_),j(!0)},children:r("settings.skills.catalog.shared.actions.install")})]})},`${_.sourceId}:${_.skillDir}`)})})}),z&&B&&!f&&M.length>0&&s.jsx("div",{className:"flex justify-center mt-2 px-2",children:s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:b,children:r(b?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]}),s.jsx(Gk,{open:y,onOpenChange:k}),s.jsx(t3,{open:D,onOpenChange:j,item:S}),s.jsx(vs,{open:C,onOpenChange:_=>{E||N(_)},children:s.jsxs(ys,{className:"max-w-md",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:r("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Fs,{children:r("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(Hs,{children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>N(!1),disabled:E,children:r("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",variant:"destructive",onClick:()=>{$()},disabled:E,children:r("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})},c3=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(l3,{mode:"external",onModeChange:u3,showModeTabs:!1}),t[0]=e):e=t[0],e},d3=()=>{const{t}=mt(),{selectedSkillName:e,getSkillByName:n,getSkillDetail:r,createSkill:a,updateSkill:i,skills:o,skillDraft:c,setSkillDraft:d,setSelectedSkill:p}=na(br(je=>({selectedSkillName:je.selectedSkillName,getSkillByName:je.getSkillByName,getSkillDetail:je.getSkillDetail,createSkill:je.createSkill,updateSkill:je.updateSkill,skills:je.skills,skillDraft:je.skillDraft,setSkillDraft:je.setSkillDraft,setSelectedSkill:je.setSelectedSkill}))),m=e?n(e):null,u=!!(c&&c.name===e&&!m),f=!!(e&&!m&&!c);l.useEffect(()=>{f&&p(null)},[f,p]);const[b,h]=l.useState(""),[v,x]=l.useState("user"),[g,w]=l.useState("opencode"),[y,k]=l.useState(""),[D,j]=l.useState(""),[S,A]=l.useState([]),[E,P]=l.useState([]),[C,N]=l.useState(!1),[T,M]=l.useState(!1),[R,O]=l.useState(""),[z,B]=l.useState(""),[$,_]=l.useState(!1),[Q,W]=l.useState(""),[ne,re]=l.useState(""),[ue,Y]=l.useState(null),[le,J]=l.useState(!1),[L,V]=l.useState(""),[K,X]=l.useState(null),[U,ae]=l.useState(!1),ve=u?b.trim()!==""||y.trim()!==""||D.trim()!==""||E.length>0:y!==R||D!==z,ie=ue?ne!==L:Q.trim()!=="",fe=l.useCallback(je=>{switch(je){case"project-opencode":return t("settings.skills.location.option.projectOpencode.label");case"user-claude":return t("settings.skills.location.option.userClaude.label");case"project-claude":return t("settings.skills.location.option.projectClaude.label");case"user-agents":return t("settings.skills.location.option.userAgents.label");case"project-agents":return t("settings.skills.location.option.projectAgents.label");default:return t("settings.skills.location.option.userOpencode.label")}},[t]),H=l.useCallback(je=>{switch(je){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-claude":return t("settings.skills.location.option.userClaude.description");case"project-claude":return t("settings.skills.location.option.projectClaude.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);l.useEffect(()=>{(async()=>{if(u&&c)h(c.name||""),x(c.scope||"user"),w(c.source==="agents"?"agents":"opencode"),k(c.description||""),j(c.instructions||""),O(""),B(""),A([]),P(c.pendingFiles||[]);else if(e&&m){M(!0);try{const Se=await r(e);if(Se){const De=Se.sources.md;k(De.description||""),j(De.instructions||""),O(De.description||""),B(De.instructions||""),A(De.supportingFiles||[])}}catch(Se){console.error("Failed to load skill details:",Se)}finally{M(!1)}}})()},[m,u,e,o,c,r]);const ce=async()=>{const je=u?b.trim().replace(/\s+/g,"-").toLowerCase():e?.trim();if(!je){G.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(je)||je.length>64){G.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!y.trim()){G.error(t("settings.skills.page.toast.descriptionRequired"));return}if(u&&o.some(Se=>Se.name===je)){G.error(t("settings.skills.page.toast.skillExists"));return}N(!0);try{const Se={name:je,description:y.trim(),instructions:D.trim()||void 0,scope:u?v:void 0,source:u?g:void 0,targetPath:u?void 0:m?.path,supportingFiles:u&&E.length>0?E:void 0};let De;u?(De=await a(Se),De&&(d(null),P([]),p(je))):(De=await i(je,Se),De&&(O(y.trim()),B(D.trim()))),De?G.success(t(u?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated")):G.error(t(u?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(Se){console.error("Error saving skill:",Se),G.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{N(!1)}},se=()=>{Y(null),W(""),re(""),V(""),_(!0)},oe=async je=>{if(Y(je),W(je),u){const De=E.find(ye=>ye.path===je)?.content||"";re(De),V(De),_(!0);return}if(e){J(!0),_(!0);try{const{readSupportingFile:Se}=na.getState(),De=await Se(e,je);re(De||""),V(De||"")}catch{G.error(t("settings.skills.page.toast.loadFileContentFailed")),re(""),V("")}finally{J(!1)}}},te=async()=>{if(!Q.trim()){G.error(t("settings.skills.page.toast.fileNameRequired"));return}const je=Q.trim(),Se=ue!==null;if(u){if(Se)P(ge=>ge.map(Me=>Me.path===ue?{path:je,content:ne}:Me)),G.success(t("settings.skills.page.toast.fileUpdated",{path:je}));else{if(E.some(ge=>ge.path===je)){G.error(t("settings.skills.page.toast.fileExists"));return}P(ge=>[...ge,{path:je,content:ne}]),G.success(t("settings.skills.page.toast.fileAdded",{path:je}))}_(!1),Y(null);return}if(!e){G.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:De}=na.getState();if(await De(e,je,ne)){G.success(Se?t("settings.skills.page.toast.fileUpdated",{path:je}):t("settings.skills.page.toast.fileCreated",{path:je})),_(!1),Y(null);const ge=await r(e);ge&&A(ge.sources.md.supportingFiles||[])}else G.error(t(Se?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},ke=je=>{if(u){P(Se=>Se.filter(De=>De.path!==je)),G.success(t("settings.skills.page.toast.fileRemoved",{path:je}));return}e&&X(je)},Ne=async()=>{if(!K||!e)return;ae(!0);const{deleteSupportingFile:je}=na.getState();if(await je(e,K)){G.success(t("settings.skills.page.toast.fileDeleted",{path:K}));const De=await r(e);De&&A(De.sources.md.supportingFiles||[]),X(null)}else G.error(t("settings.skills.page.toast.deleteFileFailed"));ae(!1)};return!e&&!c||f?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(I,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):T?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.skills.page.loading.details")})})}):s.jsxs(Es,{outerClassName:"h-full",className:"w-full",children:[s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate flex items-center gap-2",children:u?t("settings.skills.page.title.newSkill"):e}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:m?t("settings.skills.page.subtitle.skillLocation",{location:fe(Ki(m.scope,m.source))}):t("settings.skills.page.subtitle.newSkill")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.basicInformation")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[u&&s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.skills.page.field.skillNameLocation")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:t("settings.skills.page.field.skillNameHint")}),s.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[s.jsx(Wt,{value:b,onChange:je=>h(je.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(ds,{value:Ki(v,g),onValueChange:je=>{const Se=hg(je);x(Se.scope),w(Se.source==="agents"?"agents":"opencode")},children:[s.jsxs(us,{className:"w-fit gap-1.5",children:[v==="user"?s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),g==="agents"?s.jsx(I,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:fe(Ki(v,g))})]}),s.jsx(ms,{align:"start",children:su.map(je=>s.jsx(Lt,{value:je.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[je.scope==="user"?s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),je.source==="agents"?s.jsx(I,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:fe(je.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:H(je.value)})]})},je.value))})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsxs("span",{className:"typography-ui-label text-foreground",children:[t("settings.common.field.description")," ",s.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:t("settings.skills.page.field.descriptionHint")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(bn,{value:y,onChange:je=>k(je.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent"})})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.instructions")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(bn,{value:D,onChange:je=>j(je.target.value),placeholder:t("settings.skills.page.field.instructionsPlaceholder"),className:"min-h-[220px] max-h-[60vh] font-mono typography-meta"})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.supportingFiles")}),s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:se,children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:(()=>{const je=u?E:S;return je.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-1.5",children:t("settings.skills.page.supportingFiles.empty")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:je.map(Se=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>oe(Se.path),children:[s.jsx(I,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Se.path}),u&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:t("settings.skills.page.badge.pending")}),s.jsx(be,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:De=>{De.stopPropagation(),ke(Se.path)},children:s.jsx(I,{name:"delete-bin",className:"h-3 w-3"})})]},Se.path))})})()})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(be,{onClick:ce,disabled:C||!ve,size:"xs",className:"!font-normal",children:t(C?"settings.common.actions.saving":u?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(vs,{open:K!==null,onOpenChange:je=>{!je&&!U&&X(null)},children:s.jsxs(ys,{className:"max-w-md",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Fs,{children:t("settings.skills.page.deleteFileDialog.description",{path:K??""})})]}),s.jsxs(Hs,{children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>X(null),disabled:U,children:t("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",variant:"destructive",onClick:Ne,disabled:U,children:t("settings.common.actions.delete")})]})]})}),s.jsx(vs,{open:$,onOpenChange:je=>{_(je),je||Y(null)},children:s.jsxs(ys,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(As,{className:"flex-shrink-0",children:[s.jsx(Ss,{children:t(ue?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Fs,{children:t(ue?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),le?s.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.skills.page.loading.fileContent")})}):s.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[s.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:t("settings.skills.page.fileDialog.field.filePath")}),s.jsx(Wt,{value:Q,onChange:je=>W(je.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:ue!==null}),!ue&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground flex-shrink-0",children:t("settings.skills.page.fileDialog.field.content")}),s.jsx(bn,{value:ne,onChange:je=>re(je.target.value),placeholder:t("settings.skills.page.fileDialog.field.contentPlaceholder"),outerClassName:"h-[45vh] min-h-[250px] max-h-[55vh]",className:"h-full min-h-0 font-mono typography-meta"})]})]}),s.jsxs(Hs,{className:"mt-4",children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>{_(!1),Y(null)},children:t("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",onClick:te,disabled:le||!ie,children:t(ue?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},gp=t=>{const e=at.c(2),{view:n}=t,r=n===void 0?"installed":n;let a;return e[0]!==r?(a=r==="catalog"?s.jsx(c3,{}):s.jsx(d3,{}),e[0]=r,e[1]=a):a=e[1],a};function u3(){}const gg=t=>{const e=at.c(26),{header:n,footer:r,children:a,className:i,variant:o}=t,c=o===void 0?"sidebar":o,d=un(),p=l.useRef(null),[m,u]=l.useState(!1),[f,b]=l.useState(!1),h=c==="background"||d?"bg-background":"bg-sidebar",v=h==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const N=p.current;if(!N){u(!1),b(!1);return}if(!(N.scrollHeight>N.clientHeight+1)){u(!1),b(!1);return}u(N.scrollTop>1),b(N.scrollTop+N.clientHeight<N.scrollHeight-1)},e[0]=x):x=e[0];const g=x;let w;e[1]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{g()},e[1]=w):w=e[1];let y;e[2]!==a?(y=[a,g],e[2]=a,e[3]=y):y=e[3],l.useEffect(w,y);let k,D;e[4]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{const N=p.current;if(!N)return;const T=()=>g();return N.addEventListener("scroll",T,{passive:!0}),()=>N.removeEventListener("scroll",T)},D=[g],e[4]=k,e[5]=D):(k=e[4],D=e[5]),l.useEffect(k,D);let j;e[6]!==h||e[7]!==i?(j=me("flex h-full flex-col",h,i),e[6]=h,e[7]=i,e[8]=j):j=e[8];let S;e[9]!==a?(S=s.jsx(Es,{ref:p,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:a}),e[9]=a,e[10]=S):S=e[10];let A;e[11]!==v||e[12]!==m?(A=m&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${v} 0%, transparent 100%)`}}),e[11]=v,e[12]=m,e[13]=A):A=e[13];let E;e[14]!==v||e[15]!==f?(E=f&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${v} 0%, transparent 100%)`}}),e[14]=v,e[15]=f,e[16]=E):E=e[16];let P;e[17]!==E||e[18]!==S||e[19]!==A?(P=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[S,A,E]}),e[17]=E,e[18]=S,e[19]=A,e[20]=P):P=e[20];let C;return e[21]!==r||e[22]!==n||e[23]!==P||e[24]!==j?(C=s.jsxs("div",{className:j,children:[n,P,r]}),e[21]=r,e[22]=n,e[23]=P,e[24]=j,e[25]=C):C=e[25],C},xg=t=>{const e=at.c(23),{title:n,metadata:r,selected:a,onSelect:i,icon:o,actions:c,className:d}=t,p=a===void 0?!1:a,m=c&&c.length>0,u=p?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[0]!==d||e[1]!==u?(f=me("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",u,d),e[0]=d,e[1]=u,e[2]=f):f=e[2];let b;e[3]!==n?(b=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n}),e[3]=n,e[4]=b):b=e[4];let h;e[5]!==o||e[6]!==b?(h=s.jsxs("div",{className:"flex items-center gap-1.5",children:[o,b]}),e[5]=o,e[6]=b,e[7]=h):h=e[7];let v;e[8]!==r?(v=r&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:r}),e[8]=r,e[9]=v):v=e[9];let x;e[10]!==i||e[11]!==h||e[12]!==v?(x=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[h,v]}),e[10]=i,e[11]=h,e[12]=v,e[13]=x):x=e[13];let g;e[14]!==c||e[15]!==m?(g=m&&s.jsxs(_s,{children:[s.jsx(Bs,{asChild:!0,children:s.jsx(be,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(zs,{align:"end",className:"w-fit min-w-20",children:c.map(m3)})]}),e[14]=c,e[15]=m,e[16]=g):g=e[16];let w;e[17]!==x||e[18]!==g?(w=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,g]}),e[17]=x,e[18]=g,e[19]=w):w=e[19];let y;return e[20]!==f||e[21]!==w?(y=s.jsx("div",{className:f,children:w}),e[20]=f,e[21]=w,e[22]=y):y=e[22],y};function m3(t){const e=t.icon;return s.jsxs(Vt,{onClick:n=>{n.stopPropagation(),t.onClick()},className:me(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(I,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const p3=t=>{const e=at.c(41),{onItemSelect:n}=t,{t:r}=mt(),a=Ls(f3),i=Te(h3),o=Te(g3),{currentTheme:c}=Cr();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[0]=d):d=e[0];const[p,m]=l.useState(d);let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=un(),e[1]=u):u=e[1];const f=u,b=x3;let h,v;e[2]!==a||e[3]!==i||e[4]!==o?(h=()=>{if(a.length===0){i!==null&&o(null);return}i&&a.some(P=>P.id===i)||o(a[0].id)},v=[a,i,o],e[2]=a,e[3]=i,e[4]=o,e[5]=h,e[6]=v):(h=e[5],v=e[6]),l.useEffect(h,v);let x;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=me("border-b px-3","pt-4 pb-3"),e[7]=x):x=e[7];let g;e[8]!==r?(g=r("settings.page.projects.title"),e[8]=r,e[9]=g):g=e[9];let w;e[10]!==g?(w=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:g}),e[10]=g,e[11]=w):w=e[11];let y;e[12]!==a.length||e[13]!==r?(y=r("settings.projects.sidebar.total",{count:a.length}),e[12]=a.length,e[13]=r,e[14]=y):y=e[14];let k;e[15]!==y?(k=s.jsx("span",{className:"typography-meta text-muted-foreground",children:y}),e[15]=y,e[16]=k):k=e[16];let D;e[17]!==r?(D=!f&&s.jsx(be,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:b,"aria-label":r("settings.projects.sidebar.actions.addProject"),children:s.jsx(I,{name:"add",className:"size-4"})}),e[17]=r,e[18]=D):D=e[18];let j;e[19]!==D||e[20]!==k?(j=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[k,D]}),e[19]=D,e[20]=k,e[21]=j):j=e[21];let S;e[22]!==j||e[23]!==w?(S=s.jsxs("div",{className:x,children:[w,j]}),e[22]=j,e[23]=w,e[24]=S):S=e[24];let A;if(e[25]!==p||e[26]!==c||e[27]!==n||e[28]!==a||e[29]!==i||e[30]!==o){let P;e[32]!==p||e[33]!==c||e[34]!==n||e[35]!==i||e[36]!==o?(P=C=>{const N=C.id===i,T=C.icon?Rl[C.icon]:null,M=`${C.id}:${C.iconImage?.updatedAt??0}`,R=p.has(M)?null:lo(C,{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),O=C.color?co[C.color]??null:null,z=R?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:C.iconBackground?{backgroundColor:C.iconBackground}:void 0,children:s.jsx("img",{src:R,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>{m(B=>{if(B.has(M))return B;const $=new Set(B);return $.add(M),$})}})}):T?s.jsx(I,{name:T,className:me("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:O?{color:O}:void 0}):s.jsx(I,{name:"folder",className:me("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:O?{color:O}:void 0});return s.jsx(xg,{title:C.label||C.path,icon:z,selected:N,onSelect:()=>{o(C.id),n?.()}},C.id)},e[32]=p,e[33]=c,e[34]=n,e[35]=i,e[36]=o,e[37]=P):P=e[37],A=a.map(P),e[25]=p,e[26]=c,e[27]=n,e[28]=a,e[29]=i,e[30]=o,e[31]=A}else A=e[31];let E;return e[38]!==S||e[39]!==A?(E=s.jsx(gg,{variant:"background",header:S,children:A}),e[38]=S,e[39]=A,e[40]=E):E=e[40],E};function f3(t){return t.projects}function h3(t){return t.settingsProjectsSelectedId}function g3(t){return t.setSettingsProjectsSelectedId}function x3(){Nr.requestDirectoryDialog()}const b3=({projectRef:t=null})=>{const{t:e}=mt(),{isMobile:n,isTablet:r}=an(),a=n||r,i=Ls(T=>T.getActiveProject()),o=t?.path??i?.path??null,c=_t(T=>T.getWorktreeMetadata),d=El(),p=Ws(T=>T.homeDirectory),[m,u]=l.useState([]),[f,b]=l.useState(!1),[h,v]=l.useState(null),[x,g]=l.useState([]),[w,y]=l.useState(!1),k=l.useMemo(()=>t?.id&&t?.path?{id:t.id,path:t.path}:!i?.id||!o?null:{id:i.id,path:o},[i?.id,o,t?.id,t?.path]),D=l.useCallback(async()=>{if(!(!k||h===!1))try{const T=await Jc(k);g(T)}catch{}},[k,h]);l.useEffect(()=>{if(!o)return;let T=!1;return v(null),(async()=>{try{const M=await rh(o);if(T)return;v(M)}catch{}})(),()=>{T=!0}},[o]),l.useEffect(()=>{if(!k){g([]),y(!1);return}if(h===!1){g([]),y(!1);return}let T=!1;return y(!0),g([]),(async()=>{try{const M=await Jc(k);if(T)return;g(M)}catch{}finally{T||y(!1)}})(),()=>{T=!0}},[k,h]),l.useEffect(()=>{if(!k)return;let T=!1;return b(!0),(async()=>{try{const M=await Vd(k);T||u(M.length>0?M:[""])}catch{T||u([""])}finally{T||b(!1)}})(),()=>{T=!0}},[k]);const j=l.useCallback((T,M)=>{u(R=>{const O=[...R];return O[T]=M,O})},[]),S=l.useCallback(()=>{u(T=>[...T,""])},[]),A=l.useCallback(async T=>{if(!k)return;const M=T.filter(R=>R.trim().length>0);await ah(k,M)},[k]),E=l.useCallback(T=>{u(M=>{const R=M.filter((O,z)=>z!==T);return A(R),R.length>0?R:[""]})},[A]),P=l.useCallback(()=>{A(m)},[A,m]),C=l.useCallback(T=>{const M=W=>W.replace(/\\/g,"/").replace(/\/+$/,""),R=M(T.path),O=d.filter(W=>{const ne=c(W.id);if(ne?.path&&M(ne.path)===R)return!0;const re=W.directory;return!!(re&&M(re)===R)}),z=new Set(O.map(W=>W.id)),B=W=>{const ne=d.filter(ue=>{const Y=ue.parentID;return Y&&W.has(Y)});if(ne.length===0)return[];const re=new Set(ne.map(ue=>ue.id));return[...ne,...B(re)]},$=B(z),_=new Set,Q=[...O,...$].filter(W=>_.has(W.id)?!1:(_.add(W.id),!0));Nr.requestDelete({sessions:Q,mode:"worktree",worktree:T})},[d,c]),N=l.useMemo(()=>d.map(T=>T.id).join(","),[d]);return l.useEffect(()=>{h&&o&&D()},[N,h,o,D]),o?h===!1?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.gitOnly")}):s.jsxs("div",{className:"max-w-[44rem] space-y-5",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.openchamber.worktrees.setup.title")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(At,{sideOffset:8,className:"max-w-xs",children:[e("settings.openchamber.worktrees.setup.tooltipPrefix")," ",s.jsx("code",{className:"font-mono text-xs bg-sidebar-accent/50 px-1 rounded",children:"$ROOT_PROJECT_PATH"})," ",e("settings.openchamber.worktrees.setup.tooltipSuffix")]})]})]})}),f?s.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.setup.loading")}):s.jsxs("div",{className:"space-y-2 px-1",children:[m.map((T,M)=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Wt,{value:T,onChange:R=>j(M,R.target.value),onBlur:P,placeholder:e("settings.openchamber.worktrees.setup.commandPlaceholder"),className:"h-7 w-[30rem] max-w-full font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{E(M)},className:"flex-shrink-0 flex h-7 w-7 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":e("settings.openchamber.worktrees.setup.removeCommandAria"),children:s.jsx(I,{name:"close",className:"h-4 w-4"})})]},M)),s.jsxs(be,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:S,children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),e("settings.openchamber.worktrees.setup.addCommand")]})]})]}),s.jsxs("div",{className:"space-y-2 border-t border-border/40 pt-4",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.openchamber.worktrees.list.title")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:e("settings.openchamber.worktrees.list.tooltip")})]})]})}),w?s.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.list.loading")}):x.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-1",children:e("settings.openchamber.worktrees.list.empty")}):s.jsx("div",{className:"space-y-1 px-1 max-w-[32.5rem]",children:x.map(T=>s.jsxs("div",{className:"group flex w-full items-center gap-2 py-1.5",children:[s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("p",{className:"typography-meta text-foreground truncate min-w-0",children:T.label||T.branch||e("settings.openchamber.worktrees.list.detachedHead")}),s.jsx("span",{className:"typography-micro text-muted-foreground/60 px-1.5 py-[1px] rounded bg-sidebar-accent/40 flex-shrink-0 self-center leading-none",children:"OpenCode"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground/60 truncate",children:Qi(T.path,p)})]}),s.jsx("button",{type:"button",onClick:()=>C(T),className:me("flex-shrink-0 flex h-7 w-7 items-center justify-center rounded text-muted-foreground/50 hover:text-destructive hover:bg-destructive/10 transition-opacity focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",a?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":e("settings.openchamber.worktrees.list.deleteWorktreeAria",{name:T.branch||T.label||T.path}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})]},T.path))})]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.selectProject")})},y3=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,v3=()=>({id:y3(),name:"",command:"",icon:"play"}),w3=({projectRef:t})=>{const{t:e}=mt(),n=l.useMemo(()=>yn(),[]),r=Qs(S=>S.instances),a=Qs(S=>S.load),[i,o]=l.useState([]),[c,d]=l.useState(!1),[p,m]=l.useState(!1),[u,f]=l.useState(null),[b,h]=l.useState({});l.useEffect(()=>{n&&a().catch(()=>{})},[n,a]),l.useEffect(()=>{let S=!1;return d(!0),(async()=>{try{const A=await Yc(t);if(S)return;o(A.actions),f(JSON.stringify({actions:A.actions}))}catch{if(S)return;o([]),f(JSON.stringify({actions:[]}))}finally{S||d(!1)}})(),()=>{S=!0}},[t]);const v=l.useMemo(()=>n?Dh(r):[],[r,n]),x=l.useMemo(()=>i.some(A=>A.name.trim().length===0||A.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[i,e]),g=l.useMemo(()=>u===null?!1:u!==JSON.stringify({actions:i}),[i,u]),w=l.useCallback(()=>{const S=v3();o(A=>[...A,S]),h(A=>({...A,[S.id]:!0}))},[]),y=l.useCallback(S=>{o(A=>A.filter(E=>E.id!==S)),h(A=>{const E={...A};return delete E[S],E})},[]),k=l.useCallback((S,A)=>{o(E=>E.map(P=>P.id===S?A(P):P))},[]),D=l.useCallback(async()=>{if(x){G.error(x);return}m(!0);try{if(!await Fb(t,{actions:i,primaryActionId:null})){G.error(e("settings.projects.actions.toast.saveFailed"));return}f(JSON.stringify({actions:i})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(nd,{detail:{projectId:t.id}})),G.success(e("settings.projects.actions.toast.saved"))}catch{G.error(e("settings.projects.actions.toast.saveFailed"))}finally{m(!1)}},[i,t,e,x]),j=!p&&!c&&g&&!x;return s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 flex items-start justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e("settings.projects.actions.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.description")})]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:w,children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),e("settings.projects.actions.actions.add")]})]}),s.jsxs("section",{className:"pb-2 pt-0 space-y-2",children:[c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.loading")}):i.length===0?s.jsx("div",{className:"py-2",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.empty")})}):s.jsx("div",{className:"space-y-0 max-w-[30rem]",children:i.map(S=>{const A=S.icon||"play",E=Ho[A]||"play",P=b[S.id]??!1,C=S.name.trim()||e("settings.projects.actions.state.untitled");return s.jsxs(gr,{open:P,onOpenChange:N=>{h(T=>({...T,[S.id]:N}))},className:me("py-1.5"),children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs(kr,{className:"group flex-1 justify-start gap-2 rounded-md px-0 pr-1 py-1 hover:bg-[var(--interactive-hover)] focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",children:[P?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx(I,{name:E,className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:C})})})]}),s.jsx(be,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>y(S.id),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(xr,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-2 pb-6 pl-3 pr-3",children:[s.jsxs("div",{className:"flex items-center gap-2 py-1",children:[s.jsxs(_s,{children:[s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-[var(--interactive-border)] text-foreground hover:bg-[var(--interactive-hover)]","aria-label":e("settings.projects.actions.field.selectIconAria"),children:s.jsx(I,{name:E,className:"h-4 w-4"})})}),s.jsx(zs,{align:"start",className:"w-56 p-2",children:s.jsx("div",{className:"grid grid-cols-6 gap-1",children:Ph.map(N=>{const T=N.Icon,M=(S.icon||"play")===N.key;return s.jsx("button",{type:"button",onClick:()=>k(S.id,R=>({...R,icon:N.key})),className:me("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",M&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:N.label}),children:s.jsx(I,{name:T,className:"h-4 w-4"})},N.key)})})})]}),s.jsx(Wt,{value:S.name,onChange:N=>k(S.id,T=>({...T,name:N.target.value})),placeholder:e("settings.projects.actions.field.actionNamePlaceholder"),className:"h-7 max-w-[14rem]"})]}),s.jsxs("div",{className:"py-1",children:[s.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.command")}),s.jsx(bn,{value:S.command,onChange:N=>k(S.id,T=>({...T,command:N.target.value})),placeholder:e("settings.projects.actions.field.commandPlaceholder"),className:"min-h-[88px] max-w-[30rem] font-mono text-xs"})]}),s.jsxs("div",{className:"py-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.projects.actions.field.autoOpenUrl")}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2",role:"button",tabIndex:0,"aria-pressed":S.autoOpenUrl===!0,onClick:()=>k(S.id,N=>({...N,...N.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),k(S.id,T=>({...T,...T.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[s.jsx(fs,{checked:S.autoOpenUrl===!0,onChange:N=>k(S.id,T=>({...T,...N?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:C})}),s.jsx("span",{className:"typography-ui-label font-normal text-foreground/80",children:e("settings.projects.actions.field.autoOpenUrlDescription")})]})]}),S.autoOpenUrl===!0?s.jsxs("div",{className:"mt-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Wt,{value:S.openUrl||"",onChange:N=>k(S.id,T=>({...T,openUrl:N.target.value})),placeholder:e("settings.projects.actions.field.overrideUrlPlaceholder"),className:"h-7 w-full max-w-[24rem]"}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:e("settings.projects.actions.field.overrideUrlTooltip")})]})]}),n?s.jsxs("div",{className:"mt-2",children:[s.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.desktopSshForward")}),v.length>0?s.jsxs(ds,{value:S.desktopOpenSshForward&&v.some(N=>N.id===S.desktopOpenSshForward)?S.desktopOpenSshForward:"__none__",onValueChange:N=>{k(S.id,T=>({...T,...N==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:N}}))},children:[s.jsx(us,{className:"h-7 w-full max-w-[30rem]",children:s.jsx(bs,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),v.map(N=>s.jsx(Lt,{value:N.id,children:N.label},N.id))]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.noDesktopSshForwards")})]}):null]}):null]})]})})]},S.id)})}),s.jsxs("div",{className:"pt-3",children:[x?s.jsx("p",{className:"typography-meta mb-2 text-[var(--status-warning)]",children:x}):null,s.jsx(be,{type:"button",size:"xs",className:"!font-normal",onClick:D,disabled:!j,children:e(p?"settings.common.actions.saving":"settings.projects.actions.actions.save")})]})]})]})},j3=()=>{const t=at.c(201),{t:e}=mt(),n=Ls(N3),r=Ls(S3),a=Ls(k3),i=Ls(C3),o=Ls(I3),c=Te(P3),d=Te(A3),{currentTheme:p}=Cr();let m;e:{if(!c){m=null;break e}let Nt;t[0]!==n||t[1]!==c?(Nt=n.find(Kt=>Kt.id===c)??null,t[0]=n,t[1]=c,t[2]=Nt):Nt=t[2],m=Nt}const u=m;let f,b;t[3]!==n||t[4]!==c||t[5]!==d?(f=()=>{if(n.length===0){d(null);return}c&&n.some(Nt=>Nt.id===c)||d(n[0].id)},b=[n,c,d],t[3]=n,t[4]=c,t[5]=d,t[6]=f,t[7]=b):(f=t[6],b=t[7]),l.useEffect(f,b);const[h,v]=l.useState(""),[x,g]=l.useState(null),[w,y]=l.useState(null),[k,D]=l.useState(null),[j,S]=l.useState(!1),[A,E]=l.useState(!1),[P,C]=l.useState(!1),[N,T]=l.useState(!1),[M,R]=l.useState(null),[O,z]=l.useState(null),[B,$]=l.useState(!1),_=l.useRef(null);let Q;t[8]===Symbol.for("react.memo_cache_sentinel")?(Q=()=>{R(null),z(D3)},t[8]=Q):Q=t[8];const W=Q;let ne;e:{if(!u){ne=null;break e}let Nt;t[9]!==u.id||t[10]!==u.path?(Nt={id:u.id,path:u.path},t[9]=u.id,t[10]=u.path,t[11]=Nt):Nt=t[11],ne=Nt}const re=ne;let ue,Y;t[12]!==u?(ue=()=>{if(!u){v(""),g(null),y(null),D(null);return}v(u.label??""),g(u.icon??null),y(u.color??null),D(u.iconBackground??null),T(!1),W(),$(!1)},Y=[u,W],t[12]=u,t[13]=ue,t[14]=Y):(ue=t[13],Y=t[14]),l.useEffect(ue,Y);let le,J;t[15]===Symbol.for("react.memo_cache_sentinel")?(le=()=>()=>{W()},J=[W],t[15]=le,t[16]=J):(le=t[15],J=t[16]),l.useEffect(le,J);let L;t[17]!==w||t[18]!==x||t[19]!==k||t[20]!==h||t[21]!==N||t[22]!==M||t[23]!==u?(L=!!u&&(h.trim()!==(u?.label??"").trim()||x!==(u?.icon??null)||w!==(u?.color??null)||k!==(u?.iconBackground??null)||N||!!M),t[17]=w,t[18]=x,t[19]=k,t[20]=h,t[21]=N,t[22]=M,t[23]=u,t[24]=L):L=t[24];const V=L;let K;t[25]!==w||t[26]!==x||t[27]!==k||t[28]!==h||t[29]!==N||t[30]!==M||t[31]!==i||t[32]!==u||t[33]!==e||t[34]!==r||t[35]!==a?(K=async()=>{if(!u)return;if(M){S(!0);const Kt=await a(u.id,M);if(S(!1),!Kt.ok){G.error(Kt.error||e("settings.projects.page.toast.uploadIconFailed"));return}G.success(e("settings.projects.page.toast.iconUpdated")),W(),T(!1)}const Nt=N&&!!u.iconImage;if(Nt){E(!0);const Kt=await i(u.id);if(E(!1),!Kt.ok){G.error(Kt.error||e("settings.projects.page.toast.removeIconFailed"));return}G.success(e("settings.projects.page.toast.iconRemoved")),T(!1),D(null)}r(u.id,{label:h.trim(),icon:x,color:w,iconBackground:Nt?null:k})},t[25]=w,t[26]=x,t[27]=k,t[28]=h,t[29]=N,t[30]=M,t[31]=i,t[32]=u,t[33]=e,t[34]=r,t[35]=a,t[36]=K):K=t[36];const X=K,U=w?co[w]??null:null,ae=!!u?.iconImage,ve=!!(M&&O),ie=u?.iconImage?.source==="custom",fe=ae&&!N||ve,H=fe;let ce;t[37]!==p||t[38]!==ve||t[39]!==ae||t[40]!==N||t[41]!==O||t[42]!==B||t[43]!==u?(ce=B?null:ve?O:u&&ae&&!N?lo(u,{themeVariant:p.metadata.variant,iconColor:p.colors.surface.foreground}):null,t[37]=p,t[38]=ve,t[39]=ae,t[40]=N,t[41]=O,t[42]=B,t[43]=u,t[44]=ce):ce=t[44];const se=ce;let oe;t[45]!==j||t[46]!==u?(oe=Nt=>{!u||!Nt||j||(T(!1),$(!1),R(Nt),z(Kt=>(Kt&&URL.revokeObjectURL(Kt),URL.createObjectURL(Nt))))},t[45]=j,t[46]=u,t[47]=oe):oe=t[47];const te=oe;let ke;t[48]!==ve||t[49]!==H||t[50]!==ae||t[51]!==A||t[52]!==u?(ke=()=>{!u||!H||A||(ve&&W(),T(!!ae),$(!1))},t[48]=ve,t[49]=H,t[50]=ae,t[51]=A,t[52]=u,t[53]=ke):ke=t[53];const Ne=ke;let je;t[54]!==o||t[55]!==P||t[56]!==u||t[57]!==e?(je=async()=>{!u||P||(W(),T(!1),$(!1),C(!0),o(u.id).then(Nt=>{if(!Nt.ok){G.error(Nt.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(Nt.skipped){G.success(e("settings.projects.page.toast.customIconAlreadySet"));return}G.success(e("settings.projects.page.toast.iconDiscovered"))}).finally(()=>{C(!1)}))},t[54]=o,t[55]=P,t[56]=u,t[57]=e,t[58]=je):je=t[58];const Se=je;if(!u){let Nt;t[59]!==e?(Nt=e("settings.projects.page.empty.noProjects"),t[59]=e,t[60]=Nt):Nt=t[60];let Kt;return t[61]!==Nt?(Kt=s.jsx(Es,{outerClassName:"h-full",className:"w-full",children:s.jsx("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:Nt})})}),t[61]=Nt,t[62]=Kt):Kt=t[62],Kt}let De;t[63]!==u.label||t[64]!==e?(De=u.label??e("settings.projects.page.title.default"),t[63]=u.label,t[64]=e,t[65]=De):De=t[65];let ye;t[66]!==De?(ye=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:De}),t[66]=De,t[67]=ye):ye=t[67];let ge;t[68]!==u.path?(ge=s.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:u.path,children:u.path}),t[68]=u.path,t[69]=ge):ge=t[69];let Me;t[70]!==ye||t[71]!==ge?(Me=s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[ye,ge]})}),t[70]=ye,t[71]=ge,t[72]=Me):Me=t[72];let Ue;t[73]!==e?(Ue=e("settings.projects.page.field.projectName"),t[73]=e,t[74]=Ue):Ue=t[74];let q;t[75]!==Ue?(q=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:Ue})}),t[75]=Ue,t[76]=q):q=t[76];let Ie;t[77]===Symbol.for("react.memo_cache_sentinel")?(Ie=Nt=>v(Nt.target.value),t[77]=Ie):Ie=t[77];let Le;t[78]!==e?(Le=e("settings.projects.page.field.projectNamePlaceholder"),t[78]=e,t[79]=Le):Le=t[79];let Pe;t[80]!==h||t[81]!==Le?(Pe=s.jsx("div",{className:"mt-1.5 flex min-w-0 items-center gap-2",children:s.jsx(Wt,{value:h,onChange:Ie,placeholder:Le,className:"h-7 min-w-0 w-full sm:max-w-[19rem]"})}),t[80]=h,t[81]=Le,t[82]=Pe):Pe=t[82];let he;t[83]!==q||t[84]!==Pe?(he=s.jsxs("div",{className:"py-1.5",children:[q,Pe]}),t[83]=q,t[84]=Pe,t[85]=he):he=t[85];let F;t[86]!==e?(F=e("settings.projects.page.field.accentColor"),t[86]=e,t[87]=F):F=t[87];let ee;t[88]!==F?(ee=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:F})}),t[88]=F,t[89]=ee):ee=t[89];let Ce;t[90]===Symbol.for("react.memo_cache_sentinel")?(Ce=()=>y(null),t[90]=Ce):Ce=t[90];const Fe=w===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let we;t[91]!==Fe?(we=me("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Fe),t[91]=Fe,t[92]=we):we=t[92];let Qe;t[93]!==e?(Qe=e("settings.projects.page.field.none"),t[93]=e,t[94]=Qe):Qe=t[94];let pe;t[95]===Symbol.for("react.memo_cache_sentinel")?(pe=s.jsx(I,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[95]=pe):pe=t[95];let Oe;t[96]!==we||t[97]!==Qe?(Oe=s.jsx("button",{type:"button",onClick:Ce,className:we,title:Qe,children:pe}),t[96]=we,t[97]=Qe,t[98]=Oe):Oe=t[98];let nt;t[99]!==w?(nt=Lb.map(Nt=>s.jsx("button",{type:"button",onClick:()=>y(Nt.key),className:me("h-7 w-7 rounded-md border transition-colors",w===Nt.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:Nt.cssVar},title:Nt.label},Nt.key)),t[99]=w,t[100]=nt):nt=t[100];let Re;t[101]!==Oe||t[102]!==nt?(Re=s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[Oe,nt]}),t[101]=Oe,t[102]=nt,t[103]=Re):Re=t[103];let de;t[104]!==ee||t[105]!==Re?(de=s.jsxs("div",{className:"py-1.5",children:[ee,Re]}),t[104]=ee,t[105]=Re,t[106]=de):de=t[106];let He;t[107]!==e?(He=e("settings.projects.page.field.projectIcon"),t[107]=e,t[108]=He):He=t[108];let st;t[109]!==He?(st=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:He})}),t[109]=He,t[110]=st):st=t[110];let qe;t[111]!==te?(qe=s.jsx("input",{ref:_,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:Nt=>{const Kt=Nt.target.files?.[0]??null;te(Kt),Nt.currentTarget.value=""}}),t[111]=te,t[112]=qe):qe=t[112];let et;t[113]===Symbol.for("react.memo_cache_sentinel")?(et=()=>g(null),t[113]=et):et=t[113];const rt=x===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let xe;t[114]!==rt?(xe=me("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",rt),t[114]=rt,t[115]=xe):xe=t[115];let Ye;t[116]!==e?(Ye=e("settings.projects.page.field.none"),t[116]=e,t[117]=Ye):Ye=t[117];let _e;t[118]===Symbol.for("react.memo_cache_sentinel")?(_e=s.jsx(I,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[118]=_e):_e=t[118];let We;t[119]!==xe||t[120]!==Ye?(We=s.jsx("button",{type:"button",onClick:et,className:xe,title:Ye,children:_e}),t[119]=xe,t[120]=Ye,t[121]=We):We=t[121];let lt;t[122]!==U||t[123]!==x?(lt=Ob.map(Nt=>{const Kt=Nt.Icon;return s.jsx("button",{type:"button",onClick:()=>g(Nt.key),className:me("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",x===Nt.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:Nt.label,children:s.jsx(I,{name:Kt,className:"w-4 h-4",style:U&&x===Nt.key?{color:U}:void 0})},Nt.key)}),t[122]=U,t[123]=x,t[124]=lt):lt=t[124];let Je;t[125]!==We||t[126]!==lt?(Je=s.jsxs("div",{className:"mt-1.5 flex max-w-[22rem] flex-wrap items-center gap-2",children:[We,lt]}),t[125]=We,t[126]=lt,t[127]=Je):Je=t[127];let Ve;t[128]!==fe||t[129]!==k||t[130]!==se||t[131]!==e?(Ve=fe&&se&&s.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.projects.page.field.preview")}),s.jsx("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-md 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:k?{backgroundColor:k}:void 0,children:s.jsx("img",{src:se,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>$(!0)})})})]}),t[128]=fe,t[129]=k,t[130]=se,t[131]=e,t[132]=Ve):Ve=t[132];let yt;t[133]!==fe||t[134]!==k||t[135]!==e?(yt=fe&&s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[s.jsx("input",{type:"color",value:k??"#000000",onChange:Nt=>D(Nt.target.value),className:"h-7 w-9 cursor-pointer rounded border border-border bg-transparent p-1","aria-label":e("settings.projects.page.field.projectIconBackgroundAria")}),s.jsx(Wt,{value:k??"",onChange:Nt=>D(Nt.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),s.jsx(be,{type:"button",size:"xs",variant:"outline",onClick:()=>D(null),className:"h-7 w-7 p-0","aria-label":e("settings.projects.page.field.clearIconBackgroundAria"),title:e("settings.projects.page.field.clearBackground"),disabled:!k,children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]}),t[133]=fe,t[134]=k,t[135]=e,t[136]=yt):yt=t[136];let $t;t[137]!==Se||t[138]!==ie||t[139]!==P||t[140]!==j||t[141]!==e?($t=!ie&&s.jsxs(s.Fragment,{children:[s.jsx(be,{size:"xs",className:"h-6 !font-normal",onClick:()=>_.current?.click(),disabled:j,children:e(j?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),s.jsx(be,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{Se()},disabled:P,children:e(P?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),t[137]=Se,t[138]=ie,t[139]=P,t[140]=j,t[141]=e,t[142]=$t):$t=t[142];let Gt;t[143]!==Ne||t[144]!==H||t[145]!==A||t[146]!==e?(Gt=H&&s.jsx(be,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{Ne()},disabled:A,children:e(A?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),t[143]=Ne,t[144]=H,t[145]=A,t[146]=e,t[147]=Gt):Gt=t[147];let ss;t[148]!==A||t[149]!==N||t[150]!==e?(ss=N&&s.jsx(be,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>T(!1),disabled:A,children:e("settings.projects.page.actions.undoRemove")}),t[148]=A,t[149]=N,t[150]=e,t[151]=ss):ss=t[151];let wt;t[152]!==$t||t[153]!==Gt||t[154]!==ss?(wt=s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[$t,Gt,ss]}),t[152]=$t,t[153]=Gt,t[154]=ss,t[155]=wt):wt=t[155];let Dt;t[156]!==st||t[157]!==qe||t[158]!==Je||t[159]!==Ve||t[160]!==yt||t[161]!==wt?(Dt=s.jsxs("div",{className:"py-1.5",children:[st,qe,Je,Ve,yt,wt]}),t[156]=st,t[157]=qe,t[158]=Je,t[159]=Ve,t[160]=yt,t[161]=wt,t[162]=Dt):Dt=t[162];let Xt;t[163]!==he||t[164]!==de||t[165]!==Dt?(Xt=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[he,de,Dt]}),t[163]=he,t[164]=de,t[165]=Dt,t[166]=Xt):Xt=t[166];let Yt;t[167]!==V||t[168]!==A||t[169]!==j||t[170]!==h?(Yt=!V||h.trim().length===0||j||A,t[167]=V,t[168]=A,t[169]=j,t[170]=h,t[171]=Yt):Yt=t[171];let ts;t[172]!==e?(ts=e("settings.common.actions.saveChanges"),t[172]=e,t[173]=ts):ts=t[173];let dt;t[174]!==X||t[175]!==Yt||t[176]!==ts?(dt=s.jsx("div",{className:"mt-0.5 px-2 py-1",children:s.jsx(be,{onClick:X,disabled:Yt,size:"xs",className:"!font-normal",children:ts})}),t[174]=X,t[175]=Yt,t[176]=ts,t[177]=dt):dt=t[177];let Rt;t[178]!==Xt||t[179]!==dt?(Rt=s.jsxs("div",{className:"mb-8",children:[Xt,dt]}),t[178]=Xt,t[179]=dt,t[180]=Rt):Rt=t[180];let is;t[181]!==re?(is=re&&s.jsx(w3,{projectRef:re}),t[181]=re,t[182]=is):is=t[182];let xs;t[183]!==is?(xs=s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:is})}),t[183]=is,t[184]=xs):xs=t[184];let ps;t[185]!==e?(ps=e("settings.projects.page.section.worktree"),t[185]=e,t[186]=ps):ps=t[186];let ws;t[187]!==ps?(ws=s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:ps})}),t[187]=ps,t[188]=ws):ws=t[188];let qt;t[189]!==re?(qt=re&&s.jsx(b3,{projectRef:re}),t[189]=re,t[190]=qt):qt=t[190];let Ge;t[191]!==qt?(Ge=s.jsx("section",{className:"px-2 pb-2 pt-0",children:qt}),t[191]=qt,t[192]=Ge):Ge=t[192];let St;t[193]!==ws||t[194]!==Ge?(St=s.jsxs("div",{className:"mb-8",children:[ws,Ge]}),t[193]=ws,t[194]=Ge,t[195]=St):St=t[195];let Mt;return t[196]!==Me||t[197]!==Rt||t[198]!==xs||t[199]!==St?(Mt=s.jsx(Es,{outerClassName:"h-full",className:"w-full bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:[Me,Rt,xs,St]})}),t[196]=Me,t[197]=Rt,t[198]=xs,t[199]=St,t[200]=Mt):Mt=t[200],Mt};function N3(t){return t.projects}function S3(t){return t.updateProjectMeta}function k3(t){return t.uploadProjectIcon}function C3(t){return t.removeProjectIcon}function I3(t){return t.discoverProjectIcon}function P3(t){return t.settingsProjectsSelectedId}function A3(t){return t.setSettingsProjectsSelectedId}function D3(t){return t&&URL.revokeObjectURL(t),null}const T3=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`,M3=()=>Math.floor(2e4+Math.random()*3e4),E3=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},R3=t=>{switch(t){case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"error":return"settings.remoteInstances.sidebar.phase.error";case"degraded":return"settings.remoteInstances.sidebar.phase.reconnect";case"installing":return"settings.remoteInstances.sidebar.phase.installing";case"updating":return"settings.remoteInstances.sidebar.phase.updating";case"forwarding":return"settings.remoteInstances.sidebar.phase.forwarding";case"server_starting":return"settings.remoteInstances.sidebar.phase.starting";case"master_connecting":return"settings.remoteInstances.sidebar.phase.connecting";default:return"settings.remoteInstances.sidebar.phase.idle"}},F3=({onItemSelect:t})=>{const{t:e}=mt(),n=Qs(g=>g.instances),r=Qs(g=>g.statusesById),a=Qs(g=>g.isLoading),i=Qs(g=>g.load),o=Qs(g=>g.loadImports),c=Qs(g=>g.createFromCommand),d=Qs(g=>g.connect),p=Qs(g=>g.disconnect),m=Qs(g=>g.retry),u=Qs(g=>g.removeInstance),f=Qs(g=>g.upsertInstance),b=Te(g=>g.settingsRemoteInstancesSelectedId),h=Te(g=>g.setSettingsRemoteInstancesSelectedId);l.useEffect(()=>{i(),o()},[i,o]),l.useEffect(()=>{if(!a){if(n.length===0){b!==null&&h(null);return}b&&n.some(g=>g.id===b)||h(n[0].id)}},[n,a,b,h]);const v=l.useCallback(async()=>{const g=T3();try{await c(g,"ssh user@example.com",e("settings.remoteInstances.sidebar.newSshInstanceName")),h(g),t?.()}catch(w){G.error(e("settings.remoteInstances.sidebar.toast.createFailed"),{description:w instanceof Error?w.message:String(w)})}},[c,t,h,e]),x=l.useCallback(async g=>{try{await d(g.id);return}catch(w){if(!E3(w)||!window.confirm(e("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw w;const k={...g,localForward:{...g.localForward,preferredLocalPort:M3()}};await f(k),await d(k.id),G.success(e("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[d,e,f]);return s.jsx(gg,{variant:"background",header:s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.remoteInstances.sidebar.title")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.remoteInstances.sidebar.total",{count:n.length})}),s.jsx(be,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:()=>{v()},"aria-label":e("settings.remoteInstances.sidebar.actions.addSshInstance"),children:s.jsx(I,{name:"add",className:"size-4"})})]})]}),children:n.map(g=>{const w=r[g.id],y=g.id===b,k=g.nickname?.trim()||g.sshParsed?.destination||g.id,D=`${e(R3(w?.phase))}${w?.localUrl?` · ${w.localUrl}`:""}`,j=w?.phase==="ready",S=w?.phase==="error"||w?.phase==="degraded";return s.jsx(xg,{title:k,metadata:D,selected:y,onSelect:()=>{h(g.id),t?.()},actions:[{label:e(j?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect"),icon:j?"stop":"plug-2",onClick:()=>{(j?p(g.id):x(g)).catch(E=>{G.error(e(j?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:E instanceof Error?E.message:String(E)})})}},{label:e("settings.remoteInstances.sidebar.actions.retry"),icon:"refresh",onClick:()=>{S&&m(g.id).catch(A=>{G.error(e("settings.remoteInstances.sidebar.toast.retryFailed"),{description:A instanceof Error?A.message:String(A)})})}},{label:e("settings.remoteInstances.sidebar.actions.remove"),icon:"delete-bin",destructive:!0,onClick:()=>{u(g.id).then(()=>{if(b===g.id){const A=n.find(E=>E.id!==g.id);h(A?.id||null)}}).catch(A=>{G.error(e("settings.remoteInstances.sidebar.toast.removeFailed"),{description:A instanceof Error?A.message:String(A)})})}}]},g.id)})})},xp=t=>{const e=at.c(10),{children:n,className:r,outerClassName:a}=t;let i;e[0]!==a?(i=me("h-full",a),e[0]=a,e[1]=i):i=e[1];let o;e[2]!==r?(o=me("mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",r),e[2]=r,e[3]=o):o=e[3];let c;e[4]!==n||e[5]!==o?(c=s.jsx("div",{className:o,children:n}),e[4]=n,e[5]=o,e[6]=c):c=e[6];let d;return e[7]!==i||e[8]!==c?(d=s.jsx(Es,{outerClassName:i,className:"w-full",children:c}),e[7]=i,e[8]=c,e[9]=d):d=e[9],d},yd=()=>Math.floor(2e4+Math.random()*3e4),L3=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},O3=t=>{switch(t){case"config_resolved":return"settings.remoteInstances.page.phase.resolvingConfiguration";case"auth_check":return"settings.remoteInstances.page.phase.checkingAuth";case"master_connecting":return"settings.remoteInstances.page.phase.establishingSsh";case"remote_probe":return"settings.remoteInstances.page.phase.probingRemote";case"installing":return"settings.remoteInstances.page.phase.installingOpenChamber";case"updating":return"settings.remoteInstances.page.phase.updatingOpenChamber";case"server_detecting":return"settings.remoteInstances.page.phase.detectingServer";case"server_starting":return"settings.remoteInstances.page.phase.startingServer";case"forwarding":return"settings.remoteInstances.page.phase.forwardingPorts";case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"degraded":return"settings.remoteInstances.page.phase.reconnecting";case"error":return"settings.remoteInstances.sidebar.phase.error";default:return"settings.remoteInstances.sidebar.phase.idle"}},$3=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),bg=t=>!!(t&&$3.has(t)),B3=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||bg(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",z3=t=>t.type==="dynamic"?`${t.localHost||"127.0.0.1"}:${t.localPort||0}`:t.type==="remote"?`${t.remoteHost||"127.0.0.1"}:${t.remotePort||0} -> ${t.localHost||"127.0.0.1"}:${t.localPort||0}`:`${t.localHost||"127.0.0.1"}:${t.localPort||0} -> ${t.remoteHost||"127.0.0.1"}:${t.remotePort||0}`,_3=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:yd(),remoteHost:"127.0.0.1",remotePort:80}),V3=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",_r=t=>{const e=at.c(8),{label:n,hint:r}=t;let a;e[0]!==n?(a=s.jsx("span",{children:n}),e[0]=n,e[1]=a):a=e[1];let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),e[2]=i):i=e[2];let o;e[3]!==r?(o=s.jsxs(It,{children:[i,s.jsx(At,{sideOffset:8,className:"max-w-xs",children:s.jsx("div",{className:"typography-meta text-foreground",children:r})})]}),e[3]=r,e[4]=o):o=e[4];let c;return e[5]!==a||e[6]!==o?(c=s.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[a,o]}),e[5]=a,e[6]=o,e[7]=c):c=e[7],c},U3=t=>{switch(t){case"remote":return"settings.remoteInstances.page.forwardTypeDescription.remote";case"dynamic":return"settings.remoteInstances.page.forwardTypeDescription.dynamic";default:return"settings.remoteInstances.page.forwardTypeDescription.local"}},bp=(t,e)=>{const n=(t||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},W3=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},K3=t=>{const e=t.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return t;const n=Number(e[1]),r=Number.isFinite(n)?new Date(n).toISOString():e[1],a=(e[2]||"INFO").toUpperCase(),i=e[3]||"";return`[${r}] [${a}] ${i}`},H3=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},G3=t=>{const e=t.sshCommand.trim(),n=t.nickname?.trim(),r=t.portForwards.map(a=>({...a,localHost:a.localHost?.trim()||"127.0.0.1",localPort:typeof a.localPort=="number"?Math.max(1,Math.min(65535,Math.round(a.localPort))):void 0,remoteHost:a.remoteHost?.trim(),remotePort:typeof a.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(a.remotePort))):void 0}));return{...t,sshCommand:e,...n?{nickname:n}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(t.connectionTimeoutSec||60))),localForward:{...t.localForward,bindHost:t.localForward.bindHost==="localhost"||t.localForward.bindHost==="0.0.0.0"?t.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof t.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(t.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...t.remoteOpenchamber,preferredPort:typeof t.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(t.remoteOpenchamber.preferredPort))):void 0},portForwards:r}},q3=()=>{const{t}=mt(),e=Qs(F=>F.instances),n=Qs(F=>F.statusesById),r=Qs(F=>F.importCandidates),a=Qs(F=>F.isImportsLoading),i=Qs(F=>F.isSaving),o=Qs(F=>F.error),c=Qs(F=>F.load),d=Qs(F=>F.loadImports),p=Qs(F=>F.refreshStatuses),m=Qs(F=>F.upsertInstance),u=Qs(F=>F.createFromCommand),f=Qs(F=>F.removeInstance),b=Qs(F=>F.connect),h=Qs(F=>F.disconnect),v=Qs(F=>F.retry),x=Te(F=>F.settingsRemoteInstancesSelectedId),g=Te(F=>F.setSettingsRemoteInstancesSelectedId),w=l.useMemo(()=>x&&e.find(F=>F.id===x)||null,[e,x]),[y,k]=l.useState(null),[D,j]=l.useState(!1),[S,A]=l.useState(!1),[E,P]=l.useState(null),[C,N]=l.useState([]),[T,M]=l.useState(null),[R,O]=l.useState(""),[z,B]=l.useState(!1),[$,_]=l.useState({}),[Q,W]=l.useState(!1),[ne,re]=l.useState(!1),[ue,Y]=l.useState(()=>Date.now());l.useEffect(()=>{c(),d()},[c,d]),l.useEffect(()=>{k(w)},[w]),l.useEffect(()=>{if(!x)return;const F=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||p()},2e3);return()=>{window.clearInterval(F)}},[p,x]),l.useEffect(()=>{let F=null,ee=Date.now();const Ce=()=>{const we=Date.now();we-ee>=1e3&&(Y(we),ee=we),F=requestAnimationFrame(Ce)};(typeof document>"u"||document.visibilityState==="visible")&&(F=requestAnimationFrame(Ce));const Fe=()=>{document.visibilityState==="visible"&&F===null?F=requestAnimationFrame(Ce):document.visibilityState!=="visible"&&F!==null&&(cancelAnimationFrame(F),F=null)};return document.addEventListener("visibilitychange",Fe),()=>{document.removeEventListener("visibilitychange",Fe),F!==null&&cancelAnimationFrame(F)}},[]);const le=x?n[x]:null,J=le?.phase,L=J==="ready",V=J==="degraded",K=bg(J),U=L||(K||V),ae=le?Math.max(0,ue-le.updatedAtMs):0,ve=V&&ae>12e3,ie=l.useMemo(()=>!y||!w?!1:JSON.stringify(y)!==JSON.stringify(w),[y,w]),fe=l.useCallback(F=>{k(ee=>ee&&F(ee))},[]),H=l.useCallback(async()=>{if(!y)return;const F=G3(y);if(!F.sshCommand.trim()){G.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(F.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(F.auth.sshPassword?.enabled&&F.auth.sshPassword.value?.trim()&&F.auth.sshPassword.store!=="settings"){const ee=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));F.auth.sshPassword.store=ee?"settings":"never",ee||(F.auth.sshPassword.value=void 0)}if(F.auth.openchamberPassword?.enabled&&F.auth.openchamberPassword.value?.trim()&&F.auth.openchamberPassword.store!=="settings"){const ee=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));F.auth.openchamberPassword.store=ee?"settings":"never",ee||(F.auth.openchamberPassword.value=void 0)}try{await m(F),G.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(ee){G.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:ee instanceof Error?ee.message:String(ee)})}}},[y,t,m]),ce=l.useCallback(async(F,ee)=>{const Ce=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await u(Ce,`ssh ${ee}`,F),g(Ce),G.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Fe){return G.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Fe instanceof Error?Fe.message:String(Fe)}),!1}},[u,g,t]),se=l.useCallback(()=>{z||(M(null),O(""))},[z]),oe=l.useCallback((F,ee)=>{if(ee){M(F),O(V3(F));return}ce(F,F)},[ce]),te=l.useCallback(async()=>{const F=T,ee=R.trim();if(F){if(!ee){G.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}B(!0);try{await ce(F,ee)&&(M(null),O(""))}finally{B(!1)}}},[ce,R,T,t]),ke=l.useCallback(async()=>{if(w)try{await b(w.id);return}catch(F){if(!L3(F)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw F;const Ce={...w,localForward:{...w.localForward,preferredLocalPort:yd()}};await m(Ce),await b(Ce.id),G.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[b,w,t,m]),Ne=l.useCallback(async F=>(await $b(F,600)).map(Ce=>K3(Ce)),[]),je=l.useCallback(async()=>{if(y){j(!0),A(!0),P(null);try{const F=await Ne(y.id);N(F)}catch(F){N([]),P(F instanceof Error?F.message:String(F))}finally{A(!1)}}},[y,Ne]);l.useEffect(()=>{if(!D||!y)return;let F=!1;const ee=async()=>{try{const Fe=await Ne(y.id);F||(N(Fe),P(null))}catch(Fe){F||P(Fe instanceof Error?Fe.message:String(Fe))}};ee();const Ce=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ee()},1e3);return()=>{F=!0,window.clearInterval(Ce)}},[y,D,Ne]);const Se=l.useMemo(()=>C.join(`
|
|
176
|
+
`),[C]),De=l.useCallback(()=>{if(!Se.trim()){G.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Rn(Se).then(F=>{F.ok&&G.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[Se,t]),ye=l.useCallback(async()=>{if(y)try{await Bb(y.id),N([]),G.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(F){G.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:F instanceof Error?F.message:String(F)})}},[y,t]),ge=l.useCallback(async()=>{if(!le?.localUrl){G.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const F=le.localUrl.trim();if(!F){G.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}H3(F)},[le?.localUrl,t]),Me=l.useCallback(()=>{if(!y)return;W(!0),(U?h(y.id):ke()).catch(ee=>{const Ce=U?L?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";G.error(t(Ce),{description:ee instanceof Error?ee.message:String(ee)})}).finally(()=>{W(!1)})},[U,ke,h,y,L,t]),Ue=l.useCallback(()=>{if(!y||K)return;re(!0),(V?h(y.id).then(()=>ke()):v(y.id)).catch(ee=>{G.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:ee instanceof Error?ee.message:String(ee)})}).finally(()=>{re(!1)})},[ke,h,y,K,V,v,t]),q=t(K?"settings.remoteInstances.page.actions.connecting":V?ve?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Ie=!Q&&!ne&&(J==="error"||J==="idle"||!J||V&&ve)&&!K,Le=t(L?"settings.remoteInstances.sidebar.actions.disconnect":U?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!y)return s.jsxs(xp,{children:[s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.description")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.empty.selectInstance")})})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsx("div",{className:"mb-1 px-1 space-y-0.5",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.import.sectionTitle")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:a?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):r.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.noneFound")}):s.jsx("div",{className:"space-y-2",children:r.map(F=>s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--interactive-border)] px-3 py-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"typography-ui-label text-foreground truncate",children:[F.host,F.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[F.source," config"]})]}),s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{oe(F.host,F.pattern)},children:t("settings.remoteInstances.page.actions.create")})]},`${F.source}:${F.host}`))})})]}),s.jsx(vs,{open:!!T,onOpenChange:F=>{F||se()},children:s.jsxs(ys,{className:"sm:max-w-md",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Fs,{children:T?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:T}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:F=>{F.preventDefault(),te()},children:[s.jsx(Wt,{value:R,onChange:F=>O(F.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:se,disabled:z,children:t("settings.common.actions.cancel")}),s.jsx(be,{type:"submit",size:"xs",className:"!font-normal",disabled:z,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const Pe=y.remoteOpenchamber.mode==="managed",he=y.nickname?.trim()||y.sshParsed?.destination||y.id;return s.jsxs(xp,{children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:he}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${B3(J)}`}),s.jsx("span",{children:t(O3(J))}),le?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:le.localUrl}):null,ve?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.actions")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.actionsDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(be,{type:"button",variant:U?"outline":"default",size:"xs",className:"!font-normal",onClick:Me,disabled:Q||ne,children:[U?s.jsx(I,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"plug-2",className:"h-3.5 w-3.5"}),Le]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ue,disabled:!Ie,children:[s.jsx(I,{name:"refresh",className:`h-3.5 w-3.5 ${K||V&&!ve?"animate-spin":""}`}),q]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{je()},children:[s.jsx(I,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&f(y.id).then(()=>{g(null),G.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(ee=>{G.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:ee instanceof Error?ee.message:String(ee)})})},children:[s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),le?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:le.localUrl})]}):null]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.instance")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.instanceDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshCommand")}),s.jsx(Wt,{className:"h-7 md:max-w-xl",value:y.sshCommand,onChange:F=>fe(ee=>({...ee,sshCommand:F.target.value})),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.nickname")}),s.jsx(Wt,{className:"h-7 md:max-w-sm",value:y.nickname||"",onChange:F=>fe(ee=>({...ee,nickname:F.target.value})),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.connectionTimeoutSeconds")}),s.jsx(xn,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:y.connectionTimeoutSec,onValueChange:F=>{fe(ee=>({...ee,connectionTimeoutSec:Number.isFinite(F)?F:ee.connectionTimeoutSec}))}})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.remoteServer")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.remoteServerDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(_r,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(ds,{value:y.remoteOpenchamber.mode,onValueChange:F=>fe(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,mode:F==="external"?"external":"managed"}})),children:[s.jsx(us,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(bs,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(Lt,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(_r,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(xn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:y.remoteOpenchamber.preferredPort,onValueChange:F=>{fe(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,preferredPort:Number.isFinite(F)&&F>0?F:void 0}}))},onClear:()=>{fe(F=>({...F,remoteOpenchamber:{...F.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),Pe?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(_r,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(ds,{value:y.remoteOpenchamber.installMethod,onValueChange:F=>fe(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,installMethod:F==="npm"||F==="download_release"||F==="upload_bundle"?F:"bun"}})),children:[s.jsx(us,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(bs,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"bun",children:"bun"}),s.jsx(Lt,{value:"npm",children:"npm"}),s.jsx(Lt,{value:"download_release",children:t("settings.remoteInstances.page.field.installMethodDownloadRelease")}),s.jsx(Lt,{value:"upload_bundle",children:t("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,Pe?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(_r,{label:t("settings.remoteInstances.page.field.keepServerRunning"),hint:t("settings.remoteInstances.page.field.keepServerRunningHint")})}),s.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:s.jsx(dl,{checked:y.remoteOpenchamber.keepRunning,onCheckedChange:F=>fe(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,keepRunning:F}}))})})]}):null]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.mainTunnel")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.mainTunnelDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(_r,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(ds,{value:y.localForward.bindHost,onValueChange:F=>{F==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||fe(ee=>({...ee,localForward:{...ee.localForward,bindHost:F==="localhost"||F==="0.0.0.0"?F:"127.0.0.1"}}))},children:[s.jsx(us,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(bs,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"127.0.0.1",children:"127.0.0.1"}),s.jsx(Lt,{value:"localhost",children:"localhost"}),s.jsx(Lt,{value:"0.0.0.0",children:"0.0.0.0"})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(_r,{label:t("settings.remoteInstances.page.field.preferredLocalPort"),hint:t("settings.remoteInstances.page.field.preferredLocalPortHint")})}),s.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[s.jsx(xn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:y.localForward.preferredLocalPort,onValueChange:F=>{fe(ee=>({...ee,localForward:{...ee.localForward,preferredLocalPort:Number.isFinite(F)&&F>0?F:void 0}}))},onClear:()=>{fe(F=>({...F,localForward:{...F.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>fe(F=>({...F,localForward:{...F.localForward,preferredLocalPort:yd()}})),children:s.jsx(I,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.authentication")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.authenticationDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshPasswordOptional")}),s.jsx(Wt,{className:"h-7 md:max-w-sm",type:"password",value:y.auth.sshPassword?.value||"",onChange:F=>fe(ee=>({...ee,auth:{...ee.auth,sshPassword:{enabled:F.target.value.trim().length>0,value:F.target.value,store:ee.auth.sshPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.uiPasswordOptional")}),s.jsx(Wt,{className:"h-7 md:max-w-sm",type:"password",value:y.auth.openchamberPassword?.value||"",onChange:F=>fe(ee=>({...ee,auth:{...ee.auth,openchamberPassword:{enabled:F.target.value.trim().length>0,value:F.target.value,store:ee.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.portForwards")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.portForwardsDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[y.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,y.portForwards.map((F,ee)=>{const Ce=qe=>{fe(et=>({...et,portForwards:et.portForwards.map((rt,xe)=>xe===ee?qe(rt):rt)}))},Fe=F.type==="remote"?"Local target":"Local listen",we=F.type==="remote"?"Local host and port on your machine that receives traffic from remote -R listener.":"Local host and port where this forward listens on your machine.",Qe=F.type==="remote"?"Remote listen":"Remote target",pe=F.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",Oe=bp(F.localHost||"localhost",F.localPort),nt=bp(F.remoteHost||"localhost",F.remotePort),Re=F.type==="local"&&typeof F.localPort=="number"&&F.localPort>0,de=Re?`http://${W3(F.localHost)}:${F.localPort}`:"",He=!!$[F.id],st=F.type==="local"?t("settings.remoteInstances.page.forwardType.local"):F.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(gr,{open:He,onOpenChange:qe=>{_(et=>({...et,[F.id]:qe}))},className:`${ee>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex items-center gap-2",children:s.jsxs(kr,{className:"flex items-center gap-2 group",children:[s.jsx(I,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${He?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:z3(F)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:st})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(dl,{checked:F.enabled,onCheckedChange:qe=>Ce(et=>({...et,enabled:qe})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(be,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>fe(qe=>({...qe,portForwards:qe.portForwards.filter(et=>et.id!==F.id)})),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(xr,{className:"pt-2",children:s.jsxs("div",{className:"space-y-0 pb-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:t(U3(F.type))}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(_r,{label:t("settings.remoteInstances.page.field.forwardType"),hint:t("settings.remoteInstances.page.field.forwardTypeHint")})}),s.jsxs(ds,{value:F.type,onValueChange:qe=>Ce(et=>({...et,type:qe==="dynamic"||qe==="remote"?qe:"local"})),children:[s.jsx(us,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(bs,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(Lt,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(Lt,{value:"dynamic",children:t("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(_r,{label:Fe,hint:we})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Wt,{className:"h-7 w-32",value:F.localHost||"127.0.0.1",onChange:qe=>Ce(et=>({...et,localHost:qe.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(xn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:F.localPort,onValueChange:qe=>{Ce(et=>({...et,localPort:Number.isFinite(qe)&&qe>0?qe:void 0}))},onClear:()=>{Ce(qe=>({...qe,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),F.type!=="dynamic"?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(_r,{label:Qe,hint:pe})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Wt,{className:"h-7 w-32",value:F.remoteHost||"",onChange:qe=>Ce(et=>({...et,remoteHost:qe.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(xn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:F.remotePort,onValueChange:qe=>{Ce(et=>({...et,remotePort:Number.isFinite(qe)&&qe>0?qe:void 0}))},onClear:()=>{Ce(qe=>({...qe,remotePort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}):null,s.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:F.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Oe}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):F.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:nt}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(I,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Oe}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Oe}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(I,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:nt}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),Re?s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{sr(de).then(qe=>{qe||G.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},F.id)}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const F=_3();fe(ee=>({...ee,portForwards:[...ee.portForwards,F]})),_(ee=>({...ee,[F.id]:!0}))},children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.addForward")]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsx("div",{className:"mb-1 px-1 space-y-0.5",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.import.sectionTitle")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:a?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):r.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.noneAvailable")}):s.jsx("div",{children:r.slice(0,8).map((F,ee)=>s.jsxs("div",{className:`flex items-center justify-between gap-2 px-1 py-2 ${ee>0?"border-t border-[var(--surface-subtle)]":""}`,children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"typography-ui-label text-foreground truncate",children:[F.host,F.pattern?" (pattern)":""]}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:F.sshCommand})]}),s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{oe(F.host,F.pattern)},children:t("settings.common.actions.import")})]},`${F.source}:${F.host}`))})})]}),s.jsx("div",{className:"sticky bottom-0 z-10 -mx-3 sm:-mx-6 bg-[var(--surface-background)] border-t border-[var(--interactive-border)] px-3 sm:px-6 py-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{H()},disabled:!ie||i,children:t("settings.common.actions.saveChanges")}),le?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Rn(le.localUrl||"").then(F=>{F.ok&&G.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(I,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ge()},children:[s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,o?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:o}):null]})}),s.jsx(vs,{open:D,onOpenChange:j,children:s.jsxs(ys,{className:"sm:max-w-2xl",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Fs,{children:y?.nickname?.trim()||y?.sshParsed?.destination||y?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:De,disabled:S||!Se.trim(),children:[s.jsx(I,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ye()},disabled:S,children:[s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),S?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):E?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:E}):s.jsx("pre",{className:"max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words",children:C.length>0?C.join(`
|
|
177
|
+
`):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(vs,{open:!!T,onOpenChange:F=>{F||se()},children:s.jsxs(ys,{className:"sm:max-w-md",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Fs,{children:T?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:T}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:F=>{F.preventDefault(),te()},children:[s.jsx(Wt,{value:R,onChange:F=>O(F.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:se,disabled:z,children:t("settings.common.actions.cancel")}),s.jsx(be,{type:"submit",size:"xs",className:"!font-normal",disabled:z,children:t("settings.common.actions.create")})]})]})]})})]})},Y3="__add_provider__",J3=()=>{const t=rn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},Q3=({onItemSelect:t})=>{const{t:e}=mt(),n=gt(f=>f.providers),r=gt(f=>f.selectedProviderId),a=gt(f=>f.setSelectedProvider),i=Ls(f=>f.activeProjectId),[o,c]=l.useState({}),d=l.useMemo(()=>J3(),[i]);l.useEffect(()=>{if(n.length===0){c({});return}let f=!1;return(async()=>{const h=n.map(async v=>{try{const x=d?`?directory=${encodeURIComponent(d)}`:"",g=await fetch(`/api/provider/${encodeURIComponent(v.id)}/source${x}`,{method:"GET",headers:{Accept:"application/json"}});if(!g.ok)return;const w=await g.json().catch(()=>null),y=w?.sources??w?.data?.sources;if(!y||f)return;c(k=>({...k,[v.id]:y}))}catch{}});await Promise.all(h)})(),()=>{f=!0}},[d,n]);const p="bg-background",m=l.useMemo(()=>n.filter(f=>!!o[f.id]?.project?.exists),[n,o]),u=l.useMemo(()=>n.filter(f=>!o[f.id]?.project?.exists),[n,o]);return s.jsxs("div",{className:me("flex h-full flex-col",p),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.providers.sidebar.title")}),s.jsx(mo,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{a(Y3),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Es,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:n.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(I,{name:"stack",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.providers.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.providers.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[u.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.providers.sidebar.section.userProviders")}),u.map(f=>s.jsx(yp,{provider:f,selectedProviderId:r,onSelect:()=>{a(f.id),t?.()}},f.id))]}),m.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:me("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",u.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),m.map(f=>s.jsx(yp,{provider:f,selectedProviderId:r,onSelect:()=>{a(f.id),t?.()}},f.id))]})]})})]})},yp=t=>{const e=at.c(17),{provider:n,selectedProviderId:r,onSelect:a}=t,i=Array.isArray(n.models)?n.models.length:0,o=n.id===r,c=n.id,d=o?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==d?(p=me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",d),e[0]=d,e[1]=p):p=e[1];let m;e[2]!==n.id?(m=s.jsx(jn,{providerId:n.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=n.id,e[3]=m):m=e[3];const u=n.name||n.id;let f;e[4]!==u?(f=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:u}),e[4]=u,e[5]=f):f=e[5];let b;e[6]!==i?(b=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=b):b=e[7];let h;e[8]!==a||e[9]!==m||e[10]!==f||e[11]!==b?(h=s.jsxs("button",{type:"button",onClick:a,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[m,f,b]}),e[8]=a,e[9]=m,e[10]=f,e[11]=b,e[12]=h):h=e[12];let v;return e[13]!==n.id||e[14]!==p||e[15]!==h?(v=s.jsx("div",{className:p,children:h},c),e[13]=n.id,e[14]=p,e[15]=h,e[16]=v):v=e[16],v},X3=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),vp=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=X3.format(t);return e.endsWith(".0")?e.slice(0,-2):e},Eo="__add_provider__",bi=t=>typeof t=="object"&&t!==null,wp=t=>{const e=typeof t.type=="string"?t.type:"",n=`${t.name??""} ${t.label??""}`.toLowerCase(),r=`${e} ${n}`.toLowerCase();return r.includes("oauth")?"oauth":r.includes("api")?"api":e.toLowerCase()},Z3=t=>{if(!bi(t))return{};const e={};for(const[n,r]of Object.entries(t))Array.isArray(r)&&(e[n]=r.filter(a=>bi(a)));return e},e5=t=>{if(typeof t=="string")return{id:t};if(!bi(t))return null;const e=typeof t.id=="string"&&t.id||typeof t.providerID=="string"&&t.providerID||typeof t.slug=="string"&&t.slug||typeof t.name=="string"&&t.name;if(!e)return null;const n=typeof t.name=="string"?t.name:void 0;return{id:e,name:n}},t5=t=>{let e=[];Array.isArray(t)?e=t:bi(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const n=e.map(a=>e5(a)).filter(a=>!!a),r=new Set;return n.filter(a=>r.has(a.id)?!1:(r.add(a.id),!0))},s5=()=>{const{t}=mt(),e=gt(se=>se.providers),n=gt(se=>se.selectedProviderId),r=gt(se=>se.setSelectedProvider),a=gt(se=>se.getModelMetadata),i=Te(se=>se.hiddenModels),o=Te(se=>se.toggleHiddenModel),c=Te(se=>se.hideAllModels),d=Te(se=>se.showAllModels),[p,m]=l.useState({}),[u,f]=l.useState(!1),[b,h]=l.useState({}),[v,x]=l.useState(null),[g,w]=l.useState(""),[y,k]=l.useState(null),[D,j]=l.useState({}),[S,A]=l.useState({}),[E,P]=l.useState([]),[C,N]=l.useState(!1),[T,M]=l.useState(null),[R,O]=l.useState(""),[z,B]=l.useState(""),[$,_]=l.useState(!1),[Q,W]=l.useState({}),[ne,re]=l.useState(!1);l.useEffect(()=>{!n&&e.length>0&&r(e[0].id)},[e,n,r]),l.useEffect(()=>{let se=!0;return(async()=>{f(!0);try{const te=await fetch("/api/provider/auth",{method:"GET",headers:{Accept:"application/json"}});if(!te.ok)throw new Error(`Auth methods request failed (${te.status})`);const ke=await te.json().catch(()=>({}));if(!se)return;m(Z3(ke))}catch(te){if(!se)return;console.error("Failed to load provider auth methods:",te),G.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{se&&f(!1)}})(),()=>{se=!1}},[t]),l.useEffect(()=>{let se=!0;return(async()=>{N(!0),M(null);try{const te=await fetch("/api/provider",{method:"GET",headers:{Accept:"application/json"}});if(!te.ok)throw new Error(`Provider list request failed (${te.status})`);const ke=await te.json().catch(()=>({}));if(!se)return;P(t5(ke))}catch(te){if(!se)return;console.error("Failed to load available providers:",te),M(t("settings.providers.page.state.unableToLoadProviderList"))}finally{se&&N(!1)}})(),()=>{se=!1}},[t]);const ue=l.useMemo(()=>new Set(e.map(se=>se.id)),[e]),Y=l.useMemo(()=>E.filter(se=>!ue.has(se.id)).sort((se,oe)=>{const te=(se.name||se.id).toLowerCase(),ke=(oe.name||oe.id).toLowerCase();return te.localeCompare(ke)}),[E,ue]);l.useEffect(()=>{n===Eo&&R&&!Y.some(se=>se.id===R)&&O("")},[n,R,Y]),l.useEffect(()=>{if(n===Eo){re(!0);return}re(!1)},[n,t]),l.useEffect(()=>{if(!n||n===Eo)return;let se=!1;return(async()=>{try{const te=await fetch(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),ke=await te.json().catch(()=>null);if(!te.ok)throw new Error(ke?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const Ne=ke?.sources??ke?.data?.sources;!se&&Ne&&W(je=>({...je,[n]:Ne}))}catch(te){se||console.error("Failed to load provider sources:",te)}})(),()=>{se=!0}},[n,t]);const le=e.find(se=>se.id===n),J=n?Q[n]:void 0,L=async se=>{const oe=b[se]?.trim()??"";if(!oe){G.error(t("settings.providers.page.toast.apiKeyRequired"));return}const te=`api:${se}`;x(te);try{const ke=await fetch(`/api/auth/${encodeURIComponent(se)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"api",key:oe})}),Ne=await ke.json().catch(()=>null);if(!ke.ok){const je=Ne?.error||t("settings.providers.page.toast.apiKeySaveFailed");throw new Error(je)}G.success(t("settings.providers.page.toast.apiKeySaved")),h(je=>({...je,[se]:""})),await ai({scopes:["providers"],mode:"active"}),r(se)}catch(ke){console.error("Failed to save API key:",ke),G.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{x(null)}},V=async(se,oe)=>{const te=`oauth:${se}:${oe}`;x(te);try{const ke=await fetch(`/api/provider/${encodeURIComponent(se)}/oauth/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:oe})}),Ne=await ke.json().catch(()=>null);if(!ke.ok){const Ue=Ne?.error||t("settings.providers.page.toast.oauthStartFailed");throw new Error(Ue)}const je=bi(Ne)?Ne:{},Se=bi(je.data)?je.data:je,De=typeof Se.url=="string"&&Se.url||typeof Se.verification_uri_complete=="string"&&Se.verification_uri_complete||typeof Se.verification_uri=="string"&&Se.verification_uri||void 0,ye=typeof Se.instructions=="string"&&Se.instructions||typeof Se.message=="string"&&Se.message||void 0,ge=typeof Se.user_code=="string"&&Se.user_code||typeof Se.code=="string"&&Se.code||typeof Se.userCode=="string"&&Se.userCode||void 0;if(!De&&!ye&&!ge)throw new Error(t("settings.providers.page.toast.oauthDetailsMissing"));const Me=`${se}:${oe}`;A(Ue=>({...Ue,[Me]:{url:De,instructions:ye,userCode:ge}})),De&&sr(De),k({providerId:se,methodIndex:oe}),G.message(t("settings.providers.page.toast.completeOAuthInBrowser"))}catch(ke){console.error("Failed to start OAuth flow:",ke),G.error(t("settings.providers.page.toast.oauthStartFailed"))}finally{x(null)}},K=async(se,oe)=>{const te=`${se}:${oe}`,ke=D[te]?.trim(),Ne=`oauth-complete:${se}:${oe}`;x(Ne);try{const je={method:oe};ke&&(je.code=ke);const Se=await fetch(`/api/provider/${encodeURIComponent(se)}/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(je)}),De=await Se.json().catch(()=>null);if(!Se.ok){const ye=De?.error||t("settings.providers.page.toast.oauthCompleteFailed");throw new Error(ye)}G.success(t("settings.providers.page.toast.oauthCompleted")),j(ye=>({...ye,[te]:""})),k(null),await ai({scopes:["providers"],mode:"active"}),r(se)}catch(je){console.error("Failed to complete OAuth flow:",je),G.error(t("settings.providers.page.toast.oauthCompleteFailed"))}finally{x(null)}},X=async se=>{const oe=await Rn(se);if(oe.ok){G.success(t("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",oe.error),G.error(t("settings.providers.page.toast.oauthLinkCopyFailed"))},U=async se=>{const oe=await Rn(se);if(oe.ok){G.success(t("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",oe.error),G.error(t("settings.providers.page.toast.deviceCodeCopyFailed"))},ae=async se=>{const oe=`disconnect:${se}`;x(oe);try{const te=await fetch(`/api/provider/${encodeURIComponent(se)}/auth?scope=all`,{method:"DELETE",headers:{"Content-Type":"application/json"}}),ke=await te.json().catch(()=>null);if(!te.ok){const Ne=ke?.error||t("settings.providers.page.toast.providerDisconnectFailed");throw new Error(Ne)}G.success(t("settings.providers.page.toast.providerDisconnected")),await ai({scopes:["providers"],mode:"active"})}catch(te){console.error("Failed to disconnect provider:",te),G.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{x(null)}},ve=n===Eo;if(!ve&&e.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(I,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.noProvidersDetected")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(ve)return s.jsx(Es,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:t("settings.providers.page.connect.title")})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.connect.selectProviderTitle")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.connect.providerField")}),C?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):T?s.jsx("p",{className:"typography-meta text-muted-foreground",children:T}):Y.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connect.allProvidersConnected")}):s.jsxs(_s,{open:$,onOpenChange:se=>{_(se),se||B("")},children:[s.jsx(Bs,{asChild:!0,children:s.jsxs("button",{type:"button",className:me("flex items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover h-6 w-fit"),children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[R?s.jsx(jn,{providerId:R,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:me("truncate typography-ui-label font-normal",R?"text-foreground":"text-muted-foreground"),children:R?Y.find(se=>se.id===R)?.name||R:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(zs,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:se=>se.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:se=>se.stopPropagation(),children:[s.jsx(I,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:z,onChange:se=>B(se.target.value),onKeyDown:se=>se.stopPropagation(),placeholder:t("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),s.jsx(Es,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const se=Y.filter(oe=>{const te=z.toLowerCase();return(oe.name||oe.id).toLowerCase().includes(te)||oe.id.toLowerCase().includes(te)});return se.length===0?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):se.map(oe=>s.jsxs(Vt,{onSelect:()=>{O(oe.id),_(!1),B("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(jn,{providerId:oe.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:oe.name||oe.id})]}),R===oe.id&&s.jsx(I,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},oe.id))})()})]})]})]})})]}),R&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")})}),u?s.jsx("p",{className:"typography-meta text-muted-foreground px-2",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.providers.page.auth.apiKeyTooltip")})]})]}),s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 mt-1.5",children:[s.jsx(Wt,{type:"password",value:b[R]??"",onChange:se=>h(oe=>({...oe,[R]:se.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(be,{size:"xs",className:"!font-normal shrink-0",onClick:()=>L(R),disabled:v===`api:${R}`,children:v===`api:${R}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),(()=>{const oe=(p[R]??[]).filter(te=>wp(te)==="oauth");return oe.length===0?null:s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:oe.map((te,ke)=>{const Ne=te.label||te.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(ke+1)}),je=`${R}:${ke}`,Se=y?.providerId===R&&y?.methodIndex===ke;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:Ne}),(te.description||te.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(te.description||te.help)})]}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>V(R,ke),disabled:v===`oauth:${R}:${ke}`,children:t("settings.providers.page.actions.connect")})]}),S[je]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:S[je]?.instructions}),S[je]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Wt,{value:S[je]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>U(S[je]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),S[je]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Wt,{value:S[je]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>sr(S[je]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>X(S[je]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),Se&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Wt,{value:D[je]??"",onChange:De=>j(ye=>({...ye,[je]:De.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(be,{size:"xs",className:"!font-normal",onClick:()=>K(R,ke),disabled:v===`oauth-complete:${R}:${ke}`,children:v===`oauth-complete:${R}:${ke}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${R}-${Ne}`)})})})()]})]})]})});if(!le)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(I,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.selectProviderFromSidebar")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const ie=Array.isArray(le.models)?le.models:[],H=(p[le.id]??[]).filter(se=>wp(se)==="oauth"),ce=ie.filter(se=>{const oe=typeof se?.name=="string"?se.name:"",te=typeof se?.id=="string"?se.id:"",ke=g.trim().toLowerCase();return ke?oe.toLowerCase().includes(ke)||te.toLowerCase().includes(ke):!0});return s.jsx(Es,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[s.jsx(jn,{providerId:le.id,className:"h-5 w-5 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:le.name||le.id}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s.jsx("span",{className:"font-mono",children:le.id})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>re(se=>!se),children:t(ne?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:ne?u?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.providers.page.auth.apiKeyTooltip")})]})]}),s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 mt-1.5",children:[s.jsx(Wt,{type:"password",value:b[le.id]??"",onChange:se=>h(oe=>({...oe,[le.id]:se.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(be,{size:"xs",className:"!font-normal shrink-0",onClick:()=>L(le.id),disabled:v===`api:${le.id}`,children:v===`api:${le.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),H.length>0&&s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:H.map((se,oe)=>{const te=se.label||se.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(oe+1)}),ke=`${le.id}:${oe}`,Ne=y?.providerId===le.id&&y?.methodIndex===oe;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:te}),(se.description||se.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(se.description||se.help)})]}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>V(le.id,oe),disabled:v===`oauth:${le.id}:${oe}`,children:t("settings.providers.page.actions.connect")})]}),S[ke]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:S[ke]?.instructions}),S[ke]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Wt,{value:S[ke]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>U(S[ke]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),S[ke]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Wt,{value:S[ke]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>sr(S[ke]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>X(S[ke]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),Ne&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Wt,{value:D[ke]??"",onChange:je=>j(Se=>({...Se,[ke]:je.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(be,{size:"xs",className:"!font-normal",onClick:()=>K(le.id,oe),disabled:v===`oauth-complete:${le.id}:${oe}`,children:v===`oauth-complete:${le.id}:${oe}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${le.id}-${te}`)})})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(I,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.connected")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-1",children:t("settings.providers.page.auth.useReconnectHint")})]})})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.connectionDetails.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:J&&(J.auth.exists||J.user.exists||J.project.exists||J.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[J.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,J.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,J.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,J.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connectionDetails.noActiveSource")})}),s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ae(le.id),disabled:v===`disconnect:${le.id}`,children:v===`disconnect:${le.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[t("settings.providers.page.models.title"),ie.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",ie.length,")"]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const se=ie.map(oe=>typeof oe?.id=="string"?oe.id:"").filter(oe=>oe.length>0);c(le.id,se)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>d(le.id),children:t("settings.providers.page.actions.showAll")})]})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(I,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Wt,{value:g,onChange:se=>w(se.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),ce.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:ce.map(se=>{const oe=typeof se?.id=="string"?se.id:"",te=typeof se?.name=="string"?se.name:oe,ke=oe?a(le.id,oe):void 0,Ne=i.some(ye=>ye.providerID===le.id&&ye.modelID===oe),je=vp(ke?.limit?.context),Se=vp(ke?.limit?.output),De=[];return ke?.tool_call&&De.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),ke?.reasoning&&De.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),ke?.attachment&&De.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:me("flex items-center gap-3",Ne&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:te}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(je||Se)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[je?`${je} ${t("settings.providers.page.models.tokenBadge.context")}`:"",je&&Se?" · ":"",Se?`${Se} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),De.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:De.map(({key:ye,icon:ge,label:Me})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Me,"aria-label":Me,children:s.jsx(I,{name:ge,className:"h-3 w-3"})},ye))}),s.jsx("button",{type:"button",onClick:()=>o(le.id,oe),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:t(Ne?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(Ne?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:Ne?s.jsx(I,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},oe)})})]})]})]})})},n5=t=>{const e=t?.windows??{},n=Object.values(e).map(r=>r.usedPercent).filter(r=>typeof r=="number");return n.length===0?null:Math.max(...n)},r5=t=>{const e=at.c(106),{onItemSelect:n}=t,{t:r}=mt(),a=$s(a5),i=$s(i5),o=$s(o5),c=$s(l5),d=$s(c5),p=$s(d5),m=$s(u5),u=$s(m5),f=$s(p5),b=$s(f5),h=$s(h5),v=$s(g5);let x,g;e[0]!==v?(x=()=>{v()},g=[v],e[0]=v,e[1]=x,e[2]=g):(x=e[1],g=e[2]),l.useEffect(x,g);const w=x5;let y;e[3]!==f?(y=ge=>{f(ge),w({usageAutoRefresh:ge})},e[3]=f,e[4]=y):y=e[4];const k=y;let D;e[5]!==b?(D=ge=>{const Me=Number(ge);Number.isFinite(Me)&&(b(Me),w({usageRefreshIntervalMs:Me}))},e[5]=b,e[6]=D):D=e[6];const j=D;let S;e[7]!==h?(S=ge=>{ge!=="usage"&&ge!=="remaining"||(h(ge),w({usageDisplayMode:ge}))},e[7]=h,e[8]=S):S=e[8];const A=S;let E;e[9]===Symbol.for("react.memo_cache_sentinel")?(E=me("flex h-full flex-col","bg-background"),e[9]=E):E=e[9];let P;e[10]!==r?(P=r("settings.usage.sidebar.title"),e[10]=r,e[11]=P):P=e[11];let C;e[12]!==P?(C=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:P}),e[12]=P,e[13]=C):C=e[13];let N;e[14]!==r?(N=r("settings.usage.sidebar.total",{count:Fr.length}),e[14]=r,e[15]=N):N=e[15];let T;e[16]!==N?(T=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[16]=N,e[17]=T):T=e[17];let M;e[18]!==r?(M=r("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[18]=r,e[19]=M):M=e[19];let R;e[20]!==k||e[21]!==M||e[22]!==p?(R=s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(fs,{checked:p,onChange:k,ariaLabel:M})})}),e[20]=k,e[21]=M,e[22]=p,e[23]=R):R=e[23];let O;e[24]!==r?(O=r("settings.usage.sidebar.tooltip.autoRefresh"),e[24]=r,e[25]=O):O=e[25];let z;e[26]!==O?(z=s.jsx(At,{side:"bottom",children:O}),e[26]=O,e[27]=z):z=e[27];let B;e[28]!==R||e[29]!==z?(B=s.jsxs(It,{children:[R,z]}),e[28]=R,e[29]=z,e[30]=B):B=e[30];const $=String(m),_=!p;let Q;e[31]!==r?(Q=r("settings.usage.sidebar.field.intervalPlaceholder"),e[31]=r,e[32]=Q):Q=e[32];let W;e[33]!==Q?(W=s.jsx(us,{className:"w-fit",children:s.jsx(bs,{placeholder:Q})}),e[33]=Q,e[34]=W):W=e[34];let ne;e[35]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsxs(ms,{children:[s.jsx(Lt,{value:"30000",children:"30s"}),s.jsx(Lt,{value:"60000",children:"1m"}),s.jsx(Lt,{value:"300000",children:"5m"})]}),e[35]=ne):ne=e[35];let re;e[36]!==j||e[37]!==$||e[38]!==_||e[39]!==W?(re=s.jsxs(ds,{value:$,onValueChange:j,disabled:_,children:[W,ne]}),e[36]=j,e[37]=$,e[38]=_,e[39]=W,e[40]=re):re=e[40];let ue;e[41]!==c?(ue=()=>c(),e[41]=c,e[42]=ue):ue=e[42];let Y;e[43]!==r?(Y=r("settings.usage.sidebar.actions.refreshAria"),e[43]=r,e[44]=Y):Y=e[44];let le;e[45]!==r?(le=r("settings.usage.sidebar.actions.refreshTitle"),e[45]=r,e[46]=le):le=e[46];const J=d&&"animate-spin";let L;e[47]!==J?(L=me("h-3.5 w-3.5",J),e[47]=J,e[48]=L):L=e[48];let V;e[49]!==L?(V=s.jsx(I,{name:"refresh",className:L}),e[49]=L,e[50]=V):V=e[50];let K;e[51]!==d||e[52]!==ue||e[53]!==Y||e[54]!==le||e[55]!==V?(K=s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:ue,"aria-label":Y,title:le,disabled:d,children:V}),e[51]=d,e[52]=ue,e[53]=Y,e[54]=le,e[55]=V,e[56]=K):K=e[56];let X;e[57]!==B||e[58]!==re||e[59]!==K?(X=s.jsxs("div",{className:"flex items-center gap-2",children:[B,re,K]}),e[57]=B,e[58]=re,e[59]=K,e[60]=X):X=e[60];let U;e[61]!==T||e[62]!==X?(U=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[T,X]}),e[61]=T,e[62]=X,e[63]=U):U=e[63];let ae;e[64]!==r?(ae=r("settings.usage.sidebar.field.display"),e[64]=r,e[65]=ae):ae=e[65];let ve;e[66]!==ae?(ve=s.jsx("span",{className:"typography-micro text-muted-foreground",children:ae}),e[66]=ae,e[67]=ve):ve=e[67];let ie;e[68]!==r?(ie=r("settings.usage.sidebar.field.displayModePlaceholder"),e[68]=r,e[69]=ie):ie=e[69];let fe;e[70]!==ie?(fe=s.jsx(us,{className:"w-fit",children:s.jsx(bs,{placeholder:ie})}),e[70]=ie,e[71]=fe):fe=e[71];let H;e[72]!==r?(H=r("settings.usage.sidebar.field.displayModeUsage"),e[72]=r,e[73]=H):H=e[73];let ce;e[74]!==H?(ce=s.jsx(Lt,{value:"usage",children:H}),e[74]=H,e[75]=ce):ce=e[75];let se;e[76]!==r?(se=r("settings.usage.sidebar.field.displayModeRemaining"),e[76]=r,e[77]=se):se=e[77];let oe;e[78]!==se?(oe=s.jsx(Lt,{value:"remaining",children:se}),e[78]=se,e[79]=oe):oe=e[79];let te;e[80]!==ce||e[81]!==oe?(te=s.jsxs(ms,{children:[ce,oe]}),e[80]=ce,e[81]=oe,e[82]=te):te=e[82];let ke;e[83]!==A||e[84]!==fe||e[85]!==te||e[86]!==u?(ke=s.jsxs(ds,{value:u,onValueChange:A,children:[fe,te]}),e[83]=A,e[84]=fe,e[85]=te,e[86]=u,e[87]=ke):ke=e[87];let Ne;e[88]!==ve||e[89]!==ke?(Ne=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[ve,ke]}),e[88]=ve,e[89]=ke,e[90]=Ne):Ne=e[90];let je;e[91]!==U||e[92]!==Ne||e[93]!==C?(je=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[C,U,Ne]}),e[91]=U,e[92]=Ne,e[93]=C,e[94]=je):je=e[94];let Se;e[95]!==n||e[96]!==a||e[97]!==i||e[98]!==o||e[99]!==r?(Se=Fr.map(ge=>{const Me=a.find(he=>he.providerId===ge.id),Ue=n5(Me?.usage),q=yh(Ue),Ie=ge.id===i,Le=Me?.configured??!1,Pe=Le?q==="critical"?{backgroundColor:"var(--status-error)"}:q==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",Ie?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{o(ge.id),n?.()},className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:Pe}),s.jsx(jn,{providerId:ge.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:ge.name}),!Le&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r("settings.usage.sidebar.status.notSet")})]})},ge.id)}),e[95]=n,e[96]=a,e[97]=i,e[98]=o,e[99]=r,e[100]=Se):Se=e[100];let De;e[101]!==Se?(De=s.jsx(Es,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:Se}),e[101]=Se,e[102]=De):De=e[102];let ye;return e[103]!==je||e[104]!==De?(ye=s.jsxs("div",{className:E,children:[je,De]}),e[103]=je,e[104]=De,e[105]=ye):ye=e[105],ye};function a5(t){return t.results}function i5(t){return t.selectedProviderId}function o5(t){return t.setSelectedProvider}function l5(t){return t.fetchAllQuotas}function c5(t){return t.isLoading}function d5(t){return t.autoRefresh}function u5(t){return t.refreshIntervalMs}function m5(t){return t.displayMode}function p5(t){return t.setAutoRefresh}function f5(t){return t.setRefreshInterval}function h5(t){return t.setDisplayMode}function g5(t){return t.loadSettings}async function x5(t){try{await Ms(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Ac=t=>{const e=at.c(52),{title:n,window:r,subtitle:a,showToggle:i,toggleEnabled:o,onToggle:c}=t,d=i===void 0?!1:i,p=o===void 0?!1:o,m=$s(b5),u=m==="remaining"?r.remainingPercent:r.usedPercent,f=m==="remaining"?"remaining":"used";let b;e[0]!==u||e[1]!==r.valueLabel?(b=Zi(r.valueLabel,u),e[0]=u,e[1]=r.valueLabel,e[2]=b):b=e[2];const h=b,v=r.resetAfterFormatted??r.resetAtFormatted;let x;e[3]!==v||e[4]!==r.resetAt?(x=Kd(r.resetAt,v),e[3]=v,e[4]=r.resetAt,e[5]=x):x=e[5];const g=x;let w;e[6]!==n?(w=Hd(n),e[6]=n,e[7]=w):w=e[7];const y=w;let k;e[8]!==n||e[9]!==r.resetAt||e[10]!==r.usedPercent||e[11]!==r.windowSeconds?(k=eo(r.usedPercent,r.resetAt,r.windowSeconds,n),e[8]=n,e[9]=r.resetAt,e[10]=r.usedPercent,e[11]=r.windowSeconds,e[12]=k):k=e[12];const D=k;let j;e:{if(!D||D.dailyAllocationPercent===null){j=null;break e}const re=Wr(D.elapsedRatio);j=m==="remaining"?100-re:re}const S=j;let A;e[13]!==c||e[14]!==d||e[15]!==p?(A=d&&s.jsx(fs,{checked:p,onChange:re=>c?.(re),ariaLabel:"Show in dropdown"}),e[13]=c,e[14]=d,e[15]=p,e[16]=A):A=e[16];let E;e[17]!==y?(E=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:y}),e[17]=y,e[18]=E):E=e[18];let P;e[19]!==a?(P=a&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:a}),e[19]=a,e[20]=P):P=e[20];let C;e[21]!==E||e[22]!==P?(C=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[E,P]}),e[21]=E,e[22]=P,e[23]=C):C=e[23];let N;e[24]!==C||e[25]!==A?(N=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[A,C]}),e[24]=C,e[25]=A,e[26]=N):N=e[26];const T=h==="-"?"":h;let M;e[27]!==T?(M=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:T}),e[27]=T,e[28]=M):M=e[28];let R;e[29]!==N||e[30]!==M?(R=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[N,M]}),e[29]=N,e[30]=M,e[31]=R):R=e[31];let O;e[32]!==u||e[33]!==S||e[34]!==r.usedPercent?(O=s.jsx(so,{percent:u,tonePercent:r.usedPercent,expectedMarkerPercent:S,className:"h-1.5"}),e[32]=u,e[33]=S,e[34]=r.usedPercent,e[35]=O):O=e[35];const z=g?`Resets ${g}`:"";let B;e[36]!==z?(B=s.jsx("span",{className:"typography-micro text-muted-foreground",children:z}),e[36]=z,e[37]=B):B=e[37];let $;e[38]!==f?($=s.jsx("span",{className:"typography-micro text-muted-foreground",children:f}),e[38]=f,e[39]=$):$=e[39];let _;e[40]!==B||e[41]!==$?(_=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[B,$]}),e[40]=B,e[41]=$,e[42]=_):_=e[42];let Q;e[43]!==O||e[44]!==_?(Q=s.jsxs("div",{className:"mt-2.5",children:[O,_]}),e[43]=O,e[44]=_,e[45]=Q):Q=e[45];let W;e[46]!==D?(W=D&&s.jsx("div",{className:"mt-1.5",children:s.jsx(no,{paceInfo:D})}),e[46]=D,e[47]=W):W=e[47];let ne;return e[48]!==R||e[49]!==Q||e[50]!==W?(ne=s.jsxs("div",{className:"py-3",children:[R,Q,W]}),e[48]=R,e[49]=Q,e[50]=W,e[51]=ne):ne=e[51],ne};function b5(t){return t.displayMode}const y5=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},v5=()=>{const{t}=mt(),e=$s(N=>N.results),n=$s(N=>N.selectedProviderId),r=$s(N=>N.setSelectedProvider),a=$s(N=>N.loadSettings),i=$s(N=>N.fetchAllQuotas),o=$s(N=>N.isLoading),c=$s(N=>N.lastUpdated),d=$s(N=>N.error),p=$s(N=>N.dropdownProviderIds),m=$s(N=>N.setDropdownProviderIds),u=$s(N=>N.selectedModels),f=$s(N=>N.toggleModelSelected),b=$s(N=>N.applyDefaultSelections);Sh(),l.useEffect(()=>{a(),i()},[a,i]),l.useEffect(()=>{if(n||e.length===0)return;const N=e.find(T=>T.configured)?.providerId;r(N??Fr[0]?.id??null)},[e,n,r]);const h=e.find(N=>N.providerId===n)??null,x=Fr.find(N=>N.id===n)?.name??n??t("settings.usage.sidebar.title"),g=h?.usage,w=n?p.includes(n):!1,y=l.useCallback(N=>{if(!n)return;const T=N?Array.from(new Set([...p,n])):p.filter(M=>M!==n);m(T),Ms({usageDropdownProviders:T})},[p,n,m]),k=l.useMemo(()=>g?.models?Object.entries(g.models).map(([N,T])=>({name:N,windows:T})).filter(N=>Object.keys(N.windows.windows).length>0):[],[g?.models]);l.useEffect(()=>{n&&k.length>0&&b(n,k.map(N=>N.name))},[n,k,b]);const D=l.useMemo(()=>!n||k.length===0?new Map:zv(k,N=>N.name,n),[k,n]),j=l.useMemo(()=>{if(!n)return[];const N=jh(n);return Nh(N)},[n]),[S,A]=l.useState(()=>({})),E=l.useCallback(N=>{A(T=>({...T,[N]:!T[N]}))},[]),P=l.useCallback(N=>{if(!n)return;f(n,N);const T=u[n]??[],R=T.includes(N)?T.filter(z=>z!==N):[...T,N],O={...u,[n]:R};Ms({usageSelectedModels:O})},[n,u,f]),C=n?u[n]??[]:[];return n?s.jsx(Es,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[s.jsx(jn,{providerId:n,className:"h-5 w-5 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.usage.page.header.providerUsage",{provider:x})}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:o?s.jsx("span",{className:"animate-pulse",children:t("settings.usage.page.header.refreshing")}):t("settings.usage.page.header.lastUpdated",{time:y5(c)})})]})]}),s.jsx("div",{className:"mb-8 px-2",children:s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>y(!w),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),y(!w))},children:[s.jsx(fs,{checked:w,onChange:y,ariaLabel:t("settings.usage.page.options.showInHeaderAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.options.showInHeader")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.usage.page.options.showInHeaderTooltip")})]})]})]})}),!h&&s.jsx("div",{className:"mb-8 px-2",children:s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noData")})}),d&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:t("settings.usage.page.state.refreshFailedTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:d})]}),h&&!h.configured&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),g?.windows&&Object.keys(g.windows).length>0&&s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(g.windows).map(([N,T])=>s.jsx(Ac,{title:N,window:T},N))})})}),k.length>0&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.usage.page.section.modelQuotas")})}),s.jsxs("div",{className:"space-y-3",children:[j.map(N=>{const T=D.get(N.id)??[];if(T.length===0)return null;const M=S[N.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(gr,{open:!M,onOpenChange:()=>E(N.id),children:[s.jsxs(kr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:N.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",T.length,")"]})]}),M?s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(xr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:T.map(R=>{const O=Object.entries(R.windows.windows);if(O.length===0)return null;const[z,B]=O[0],$=C.includes(R.name);return s.jsx(Ac,{title:z,subtitle:cl(R.name),window:B,showToggle:!0,toggleEnabled:$,onToggle:()=>P(R.name)},R.name)})})})]})},N.id)}),(()=>{const N=D.get(null)??[];if(N.length===0)return null;const T=S.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(gr,{open:!T,onOpenChange:()=>E("other"),children:[s.jsxs(kr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",N.length,")"]})]}),T?s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(xr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:N.map(M=>{const R=Object.entries(M.windows.windows);if(R.length===0)return null;const[O,z]=R[0],B=C.includes(M.name);return s.jsx(Ac,{title:O,subtitle:cl(M.name),window:z,showToggle:!0,toggleEnabled:B,onToggle:()=>P(M.name)},M.name)})})})]})})})()]})]}),h?.configured&&g&&Object.keys(g.windows??{}).length===0&&k.length===0&&s.jsxs("div",{className:"mb-8 px-2",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noQuotaWindowsTitle")}),s.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:t("settings.usage.page.state.noQuotaWindowsDescription")})]})]})}):s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.usage.page.empty.selectProvider")})})},w5="git.commit.generate",vd=ar(t=>({selectedPromptId:w5,setSelectedPromptId:e=>{t(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),j5=t=>{const e=at.c(23),{onItemSelect:n}=t,{t:r}=mt(),a=vd(N5),i=vd(S5);let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=o):o=e[0];let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=c):c=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=d):d=e[2];let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=[o,c,d,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[3]=p):p=e[3];const m=p;let u;e[4]!==r?(u=r("settings.magicPrompts.sidebar.title"),e[4]=r,e[5]=u):u=e[5];let f;e[6]!==u?(f=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:u}),e[6]=u,e[7]=f):f=e[7];let b;e[8]!==r?(b=r("settings.magicPrompts.sidebar.description"),e[8]=r,e[9]=b):b=e[9];let h;e[10]!==b?(h=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:b}),e[10]=b,e[11]=h):h=e[11];let v;e[12]!==f||e[13]!==h?(v=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[f,h]}),e[12]=f,e[13]=h,e[14]=v):v=e[14];let x;e[15]!==n||e[16]!==a||e[17]!==i||e[18]!==r?(x=s.jsx(Es,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(w=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:r(w.groupKey)}),w.items.map(y=>{const k=a===y.id;return s.jsx("button",{type:"button",onClick:()=>{i(y.id),n?.()},className:me("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",k?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:r(y.titleKey)})},y.id)})]},w.groupKey))}),e[15]=n,e[16]=a,e[17]=i,e[18]=r,e[19]=x):x=e[19];let g;return e[20]!==x||e[21]!==v?(g=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[v,x]}),e[20]=x,e[21]=v,e[22]=g):g=e[22],g};function N5(t){return t.selectedPromptId}function S5(t){return t.setSelectedPromptId}const jp={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},Np=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Sp=t=>t.endsWith(".visible"),k5=()=>{const{t}=mt(),e=l.useCallback(j=>t(j),[t]),n=vd(j=>j.selectedPromptId),[r,a]=l.useState(!0),[i,o]=l.useState({}),[c,d]=l.useState({}),[p,m]=l.useState({}),[u,f]=l.useState({}),[b,h]=l.useState(!1);l.useEffect(()=>{let j=!0;return(async()=>{a(!0);try{const A=await Ub();if(!j)return;o(A)}catch(A){console.warn("Failed to load magic prompts:",A),G.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{j&&a(!1)}})(),()=>{j=!1}},[t]);const v=jp[n]??jp["git.commit.generate"],x=l.useCallback(j=>Np(i,j)?i[j]:Xl(j),[i]),g=l.useCallback(j=>c[j]??x(j),[c,x]),w=l.useCallback((j,S)=>{d(A=>A[j]===S?A:{...A,[j]:S})},[]),y=l.useCallback(async j=>{const S=g(j);if(Sp(j)&&S.trim().length===0){G.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(A=>({...A,[j]:!0}));try{const A=S===Xl(j)?await Su(j):await zb(j,S);o(A.overrides),G.success(t("settings.magicPrompts.page.toast.saved"))}catch(A){const E=A instanceof Error?A.message:String(A);G.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:E})}finally{m(A=>({...A,[j]:!1}))}},[g,t]),k=l.useCallback(async j=>{f(S=>({...S,[j]:!0}));try{const S=await Su(j);o(S.overrides),d(A=>({...A,[j]:Xl(j)})),G.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(S){const A=S instanceof Error?S.message:String(S);G.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:A})}finally{f(S=>({...S,[j]:!1}))}},[t]),D=l.useCallback(async()=>{h(!0);try{const j=await _b();o(j.overrides),d({}),G.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(j){const S=j instanceof Error?j.message:String(j);G.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:S})}finally{h(!1)}},[t]);return r?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl px-6 py-6 space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[s.jsx("div",{className:"space-y-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:e(v.titleKey)}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:e(v.descriptionKey)})]})]})}),s.jsx(be,{variant:"outline",size:"sm",onClick:()=>{D()},disabled:b||Object.keys(i).length===0,children:t(b?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")})]}),v.blocks.map((j,S)=>{const A=Vb(j.id),E=x(j.id),P=g(j.id),C=Np(i,j.id),N=P!==E,T=Sp(j.id)&&P.trim().length===0,M=p[j.id]===!0,R=u[j.id]===!0;return s.jsxs("section",{className:S>0?"space-y-3 pt-5 border-t border-border":"space-y-3",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label text-foreground",children:e(j.titleKey)}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:A.description})]})]}),A.placeholders&&A.placeholders.length>0&&s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[t("settings.magicPrompts.page.placeholdersLabel")," ",A.placeholders.map(O=>`{{${O.key}}}`).join(", ")]})]}),s.jsx(bn,{value:P,onChange:O=>w(j.id,O.target.value),className:"min-h-[220px] font-mono text-sm"}),T&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(N?"settings.magicPrompts.page.status.unsavedChanges":C?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{variant:"outline",size:"sm",onClick:()=>{k(j.id)},disabled:!C||M||R,children:t(R?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(be,{size:"sm",onClick:()=>{y(j.id)},disabled:!N||M||R||T,children:t(M?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},j.id)})]})})},yg=()=>{const{t}=mt(),e=gt(u=>u.settingsGitmojiEnabled),n=gt(u=>u.setSettingsGitmojiEnabled),r=Od(),a=Te(u=>u.gitChangesViewMode),i=Te(u=>u.setGitChangesViewMode),[o,c]=l.useState(!0),d=l.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);l.useEffect(()=>{(async()=>{try{let f=null;if(!f){const b=hr()?.settings;if(b)try{const v=(await b.load())?.settings;v&&(f={gitmojiEnabled:typeof v.gitmojiEnabled=="boolean"?v.gitmojiEnabled:void 0,gitChangesViewMode:v.gitChangesViewMode==="flat"||v.gitChangesViewMode==="tree"?v.gitChangesViewMode:void 0})}catch{}}if(!f){const b=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});b.ok&&(f=await b.json())}f&&(typeof f.gitmojiEnabled=="boolean"&&n(f.gitmojiEnabled),(f.gitChangesViewMode==="flat"||f.gitChangesViewMode==="tree")&&i(f.gitChangesViewMode))}catch(f){console.warn("Failed to load git settings:",f)}finally{c(!1)}})()},[i,n]);const p=l.useCallback(async u=>{n(u);try{await Ms({gitmojiEnabled:u})}catch(f){console.warn("Failed to save gitmoji setting:",f)}},[n]),m=l.useCallback(u=>{u!==a&&(i(u),Ms({gitChangesViewMode:u}))},[a,i]);return o?null:s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.git.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"pt-1 pb-1",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.git.changesViewTitle")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.openchamber.git.changesViewAria"),className:"mt-0.5 space-y-0",children:d.map(u=>{const f=a===u.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>{m(u.id)},onKeyDown:b=>{(b.key===" "||b.key==="Enter")&&(b.preventDefault(),m(u.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:f,onChange:()=>{m(u.id)},ariaLabel:t("settings.openchamber.git.optionAria",{option:u.label})}),s.jsx("span",{className:f?"typography-ui-label font-normal text-foreground":"typography-ui-label font-normal text-foreground/50",children:u.label})]},u.id)})})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":e,onClick:()=>{p(!e)},onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),p(!e))},children:[s.jsx(fs,{checked:e,onChange:u=>{p(u)},ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.enableGitmoji")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":r,onClick:()=>Zl(!r),onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),Zl(!r))},children:[s.jsx(fs,{checked:r,onChange:Zl,ariaLabel:t("settings.openchamber.git.showGitignoredAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.showGitignored")})]})]})]})},vg=()=>{const{t}=mt(),{isMobile:e}=an(),n=hr()?.github,r=Hn(A=>A.status),a=Hn(A=>A.isLoading),i=Hn(A=>A.hasChecked),o=Hn(A=>A.refreshStatus),c=Hn(A=>A.setStatus),d=l.useCallback(async A=>{await sr(A)},[]),[p,m]=l.useState(!1),[u,f]=l.useState(null),[b,h]=l.useState(null),v=l.useRef(null),x=l.useCallback(()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null),h(null)},[]);l.useEffect(()=>((async()=>{try{i||await o(n)}catch(A){console.warn("Failed to load GitHub auth status:",A)}})(),()=>{x()}),[i,o,n,x]);const g=l.useCallback(async()=>{m(!0);try{const A=n?await n.authStart():await(async()=>{const P=await fetch("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),C=await P.json().catch(()=>null);if(!P.ok||!C||!("deviceCode"in C))throw new Error(C?.error||P.statusText);return C})();f(A),h(Math.max(1,A.interval)*1e3);const E=A.verificationUriComplete||A.verificationUri;d(E)}catch(A){console.error("Failed to start GitHub connect:",A),G.error(t("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[d,n,t]),w=l.useCallback(async A=>{if(n)return n.authComplete(A);const E=await fetch("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:A})}),P=await E.json().catch(()=>null);if(!E.ok||!P)throw new Error(P?.error||E.statusText);return P},[n]);l.useEffect(()=>{if(!(!u?.deviceCode||!b)&&v.current==null)return v.current=window.setInterval(()=>{(async()=>{try{const A=await w(u.deviceCode);if(A.connected){G.success(t("settings.github.page.toast.connected")),f(null),x(),await o(n,{force:!0});return}A.status==="slow_down"&&h(E=>E?E+5e3:5e3),(A.status==="expired_token"||A.status==="access_denied")&&(G.error(A.error||t("settings.github.page.toast.authorizationFailed")),f(null),x())}catch(A){console.warn("GitHub polling failed:",A)}})()},b),()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null)}},[u,b,w,o,n,x,t]);const y=l.useCallback(async()=>{m(!0);try{if(x(),f(null),n)await n.authDisconnect();else{const A=await fetch("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!A.ok)throw new Error(A.statusText)}G.success(t("settings.github.page.toast.disconnected")),await o(n,{force:!0})}catch(A){console.error("Failed to disconnect GitHub:",A),G.error(t("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[o,n,x,t]),k=l.useCallback(async A=>{if(A){m(!0);try{const E=n?await n.authActivate(A):await(async()=>{const P=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:A})}),C=await P.json().catch(()=>null);if(!P.ok||!C)throw new Error(C?.error||P.statusText);return C})();c(E),G.success(t("settings.github.page.toast.accountSwitched"))}catch(E){console.error("Failed to switch GitHub account:",E),G.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,c,t]);if(a)return null;const D=!!r?.connected,j=r?.user,S=r?.accounts??[];return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:"GitHub"}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.github.page.tooltip.connectAccount")})]})]})}),s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[D?s.jsxs("div",{className:me("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:me("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[j?.avatarUrl?s.jsx("img",{src:j.avatarUrl,alt:j.login?t("settings.github.page.avatarAlt.withLogin",{login:j.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:j?.name?.trim()||j?.login||"GitHub"}),s.jsxs("div",{className:me("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(I,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:j?.login||t("settings.github.page.label.unknownUser")}),j?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),j?.email&&s.jsx("span",{children:j.email})]}),r?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.label.scopes",{value:r.scope})})]})]}),s.jsx(be,{size:"sm",variant:"outline",onClick:y,disabled:p,className:me("text-[var(--status-error)] hover:text-[var(--status-error)]",e?"w-full":void 0),children:t("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.github.page.status.notConnected")})}),s.jsx(be,{size:"sm",variant:"default",onClick:g,disabled:p,children:t("settings.github.page.actions.connect")})]}),S.length>1&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:t("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:S.map(A=>{const E=A.user,P=!!A.current;return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[E?.avatarUrl?s.jsx("img",{src:E.avatarUrl,alt:E.login?t("settings.github.page.avatarAlt.withLogin",{login:E.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(I,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:E?.name?.trim()||E?.login||"GitHub"}),E?.login&&s.jsx("span",{className:"typography-micro text-muted-foreground truncate font-mono",children:E.login})]})]}),P?s.jsx("span",{className:"typography-micro text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:t("settings.github.page.status.active")}):s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>k(A.id),disabled:p,children:t("settings.github.page.actions.switchTo")})]},A.id)})})]})]}),D&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(be,{size:"sm",variant:"outline",onClick:g,disabled:p,className:me(e?"w-full":void 0),children:t("settings.github.page.actions.addAccount")})}),u&&s.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h4",{className:"typography-ui-label text-foreground",children:t("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:u.userCode}),s.jsx(be,{size:"sm",asChild:!0,children:s.jsx("a",{href:u.verificationUriComplete||u.verificationUri,target:"_blank",rel:"noopener noreferrer",children:t("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.github.page.flow.waiting")}),s.jsx(be,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{x(),f(null)},children:t("settings.common.actions.cancel")})]})]})]})},kp=[{key:"keyword",label:"Green",cssVar:"var(--syntax-keyword)"},{key:"error",label:"Red",cssVar:"var(--status-error)"},{key:"string",label:"Cyan",cssVar:"var(--syntax-string)"},{key:"function",label:"Orange",cssVar:"var(--syntax-function)"},{key:"type",label:"Yellow",cssVar:"var(--syntax-type)"}],C5=[{key:"branch",Icon:"git-branch",label:"Branch"},{key:"briefcase",Icon:"briefcase",label:"Work"},{key:"house",Icon:"home",label:"Personal"},{key:"graduation",Icon:"graduation-cap",label:"School"},{key:"code",Icon:"code",label:"Code"}],I5=({open:t,onOpenChange:e,profileId:n,importData:r})=>{const{t:a}=mt(),i=Zn(W=>W.getProfileById),o=Zn(W=>W.createProfile),c=Zn(W=>W.updateProfile),d=Zn(W=>W.deleteProfile),p=l.useMemo(()=>n&&n!=="new"&&!r?i(n):null,[n,i,r]),m=n==="new"||r!=null,u=n==="global",[f,b]=l.useState(""),[h,v]=l.useState(""),[x,g]=l.useState(""),[w,y]=l.useState("ssh"),[k,D]=l.useState(""),[j,S]=l.useState(""),[A,E]=l.useState("keyword"),[P,C]=l.useState("branch"),[N,T]=l.useState(!1),[M,R]=l.useState(!1),[O,z]=l.useState(!1);l.useEffect(()=>{if(t){if(r){const W=r.host.split("/"),ne=W.length>=3?W[W.length-1]:r.host;b(ne),v(r.username),g(""),y("token"),D(""),S(r.host),E("string"),C("code")}else if(m)b(""),v(""),g(""),y("ssh"),D(""),S(""),E("keyword"),C("branch");else if(p)b(p.name),v(p.userName),g(p.userEmail),y(p.authType||"ssh"),D(p.sshKey||""),S(p.host||""),E(p.color||"keyword"),C(p.icon||"branch");else if(u){const W=i("global");W&&(b(W.name),v(W.userName),g(W.userEmail),y(W.authType||"ssh"),D(W.sshKey||""),S(W.host||""),E(W.color||"keyword"),C(W.icon||"branch"))}}},[t,n,p,m,r,u,i]);const B=async()=>{if(!h.trim()||!x.trim()){G.error(a("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(w==="token"&&!j.trim()){G.error(a("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}T(!0);try{const W={name:f.trim()||h.trim(),userName:h.trim(),userEmail:x.trim(),authType:w,sshKey:w==="ssh"&&k.trim()||null,host:w==="token"&&j.trim()||null,color:A,icon:P};let ne;if(m)ne=await o(W);else if(n)ne=await c(n,W);else return;ne?(G.success(a(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):G.error(a(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(W){console.error("Error saving profile:",W),G.error(a("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{T(!1)}},$=async()=>{if(!(!n||m)){z(!0);try{await d(n)?(G.success(a("settings.gitIdentities.editor.toast.profileDeleted")),R(!1),e(!1)):G.error(a("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(W){console.error("Error deleting profile:",W),G.error(a("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{z(!1)}}},_=l.useMemo(()=>kp.find(ne=>ne.key===A)?.cssVar||"var(--syntax-keyword)",[A]),Q=r?a("settings.gitIdentities.editor.title.importCredential"):m?a("settings.gitIdentities.editor.title.newIdentity"):u?a("settings.gitIdentities.editor.title.globalIdentity"):p?.name||a("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(vs,{open:t,onOpenChange:e,children:s.jsxs(ys,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:Q}),s.jsx(Fs,{children:a(u?"settings.gitIdentities.editor.description.globalReadOnly":m?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!u&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-ui-label text-foreground block mb-1.5",children:a("settings.gitIdentities.editor.field.profileName")}),s.jsx(Wt,{value:f,onChange:W=>b(W.target.value),placeholder:a("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:kp.map(W=>s.jsx("button",{type:"button",onClick:()=>E(W.key),className:me("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",A===W.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:W.cssVar},title:W.label},W.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:C5.map(W=>{const ne=W.Icon;return s.jsx("button",{type:"button",onClick:()=>C(W.key),className:me("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",P===W.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:W.label,children:s.jsx(I,{name:ne,className:"w-3.5 h-3.5",style:{color:P===W.key?_:"var(--surface-muted-foreground)"}})},W.key)})})]})]}),!u&&s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.userName")}),!u&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.userNameTooltip")})]})]}),s.jsx(Wt,{value:h,onChange:W=>v(W.target.value),placeholder:a("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!u,readOnly:u,disabled:u,className:"h-8"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.emailAddress")}),!u&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.emailAddressTooltip")})]})]}),s.jsx(Wt,{type:"email",value:x,onChange:W=>g(W.target.value),placeholder:a("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!u,readOnly:u,disabled:u,className:"h-8"})]})]}),!u&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(be,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="ssh",onClick:()=>y("ssh"),children:[s.jsx(I,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(be,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="token",onClick:()=>y("token"),children:[s.jsx(I,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",a("settings.gitIdentities.editor.field.authToken")]})]})]}),w==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]})]}),s.jsx(Wt,{value:k,onChange:W=>D(W.target.value),placeholder:a("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),w==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.hostTooltip")})]})]}),s.jsx(Wt,{value:j,onChange:W=>S(W.target.value),placeholder:a("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(Hs,{className:"gap-2",children:[!u&&!m&&s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>R(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(I,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",a("settings.common.actions.delete")]}),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:a(u?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!u&&s.jsx(be,{size:"sm",onClick:B,disabled:N,children:a(N?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(vs,{open:M,onOpenChange:W=>{O||R(W)},children:s.jsxs(ys,{className:"max-w-md",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:a("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Fs,{children:a("settings.gitIdentities.page.deleteDialog.description",{name:p?.name||f})})]}),s.jsxs(Hs,{children:[s.jsx(be,{variant:"ghost",onClick:()=>R(!1),disabled:O,children:a("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",variant:"destructive",onClick:()=>{$()},disabled:O,children:a("settings.common.actions.delete")})]})]})})]})},P5={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},A5={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},D5=()=>{const t=at.c(116),{t:e}=mt(),{profiles:n,globalIdentity:r,defaultGitIdentityId:a,deleteProfile:i,loadProfiles:o,loadGlobalIdentity:c,loadDiscoveredCredentials:d,loadDefaultGitIdentityId:p,setDefaultGitIdentityId:m,getUnimportedCredentials:u}=Zn(br(M5)),[f,b]=l.useState(!1),[h,v]=l.useState(null),[x,g]=l.useState(null),[w,y]=l.useState(null),[k,D]=l.useState(!1);let j,S;t[0]!==p||t[1]!==d||t[2]!==c||t[3]!==o?(j=()=>{o(),c(),d(),p()},S=[o,c,d,p],t[0]=p,t[1]=d,t[2]=c,t[3]=o,t[4]=j,t[5]=S):(j=t[4],S=t[5]),l.useEffect(j,S);let A,E,P,C,N,T,M,R,O,z,B,$,_;if(t[6]!==a||t[7]!==w||t[8]!==i||t[9]!==u||t[10]!==r||t[11]!==n||t[12]!==m||t[13]!==e){const je=u();let Se;t[27]===Symbol.for("react.memo_cache_sentinel")?(Se=(F,ee)=>{v(F),g(ee??null),b(!0)},t[27]=Se):Se=t[27];const De=Se;let ye;t[28]!==a||t[29]!==m||t[30]!==e?(ye=async F=>{const ee=a===F?null:F;if(!await m(ee)){G.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}G.success(e(ee?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[28]=a,t[29]=m,t[30]=e,t[31]=ye):ye=t[31];const ge=ye;let Me;t[32]!==w||t[33]!==i||t[34]!==e?(Me=async()=>{if(!w)return;D(!0),await i(w.id)?(G.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:w.name})),y(null)):G.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),D(!1)},t[32]=w,t[33]=i,t[34]=e,t[35]=Me):Me=t[35],E=Me,A=Es,C="h-full",N="w-full bg-background",_="mx-auto w-full max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",t[36]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(vg,{}),t[36]=P):P=t[36],B="border-t border-border/40 pt-6";let Ue;t[37]!==e?(Ue=e("settings.gitIdentities.page.section.title"),t[37]=e,t[38]=Ue):Ue=t[38];let q;t[39]!==Ue?(q=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:Ue})}),t[39]=Ue,t[40]=q):q=t[40];let Ie,Le;t[41]===Symbol.for("react.memo_cache_sentinel")?(Ie=()=>De("new"),Le=s.jsx(I,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=Ie,t[42]=Le):(Ie=t[41],Le=t[42]);let Pe;t[43]!==e?(Pe=e("settings.common.badge.new"),t[43]=e,t[44]=Pe):Pe=t[44];let he;t[45]!==Pe?(he=s.jsxs(be,{size:"sm",variant:"outline",onClick:Ie,children:[Le," ",Pe]}),t[45]=Pe,t[46]=he):he=t[46],t[47]!==q||t[48]!==he?($=s.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[q,he]}),t[47]=q,t[48]=he,t[49]=$):$=t[49],T="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",M=r&&s.jsx(Cp,{profile:r,isDefault:a==="global",onEdit:()=>De("global"),onToggleDefault:()=>ge("global"),isReadOnly:!0,hasBorder:n.length>0||je.length>0}),R=n.map((F,ee)=>s.jsx(Cp,{profile:F,isDefault:a===F.id,onEdit:()=>De(F.id),onToggleDefault:()=>ge(F.id),onDelete:()=>y(F),hasBorder:ee<n.length-1||je.length>0},F.id)),O=!r&&n.length===0&&je.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(I,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),z=je.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-4 py-2 border-t border-[var(--surface-subtle)]",children:s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.gitIdentities.page.discoveredCredentials.title")})}),je.map((F,ee)=>s.jsx(T5,{credential:F,onImport:()=>De("new",{host:F.host,username:F.username}),hasBorder:ee<je.length-1},`${F.host}-${F.username}`))]}),t[6]=a,t[7]=w,t[8]=i,t[9]=u,t[10]=r,t[11]=n,t[12]=m,t[13]=e,t[14]=A,t[15]=E,t[16]=P,t[17]=C,t[18]=N,t[19]=T,t[20]=M,t[21]=R,t[22]=O,t[23]=z,t[24]=B,t[25]=$,t[26]=_}else A=t[14],E=t[15],P=t[16],C=t[17],N=t[18],T=t[19],M=t[20],R=t[21],O=t[22],z=t[23],B=t[24],$=t[25],_=t[26];let Q;t[50]!==T||t[51]!==M||t[52]!==R||t[53]!==O||t[54]!==z?(Q=s.jsxs("div",{className:T,children:[M,R,O,z]}),t[50]=T,t[51]=M,t[52]=R,t[53]=O,t[54]=z,t[55]=Q):Q=t[55];let W;t[56]!==Q||t[57]!==B||t[58]!==$?(W=s.jsxs("div",{className:B,children:[$,Q]}),t[56]=Q,t[57]=B,t[58]=$,t[59]=W):W=t[59];let ne;t[60]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsx(yg,{}),t[60]=ne):ne=t[60];let re;t[61]!==P||t[62]!==W||t[63]!==_?(re=s.jsxs("div",{className:_,children:[P,W,ne]}),t[61]=P,t[62]=W,t[63]=_,t[64]=re):re=t[64];let ue;t[65]!==A||t[66]!==C||t[67]!==N||t[68]!==re?(ue=s.jsx(A,{outerClassName:C,className:N,children:re}),t[65]=A,t[66]=C,t[67]=N,t[68]=re,t[69]=ue):ue=t[69];let Y;t[70]!==x||t[71]!==f||t[72]!==h?(Y=s.jsx(I5,{open:f,onOpenChange:b,profileId:h,importData:x}),t[70]=x,t[71]=f,t[72]=h,t[73]=Y):Y=t[73];const le=w!==null;let J;t[74]!==k?(J=je=>{k||je||y(null)},t[74]=k,t[75]=J):J=t[75];let L;t[76]!==e?(L=e("settings.gitIdentities.page.deleteDialog.title"),t[76]=e,t[77]=L):L=t[77];let V;t[78]!==L?(V=s.jsx(Ss,{children:L}),t[78]=L,t[79]=V):V=t[79];const K=w?.name??"";let X;t[80]!==e||t[81]!==K?(X=e("settings.gitIdentities.page.deleteDialog.description",{name:K}),t[80]=e,t[81]=K,t[82]=X):X=t[82];let U;t[83]!==X?(U=s.jsx(Fs,{children:X}),t[83]=X,t[84]=U):U=t[84];let ae;t[85]!==V||t[86]!==U?(ae=s.jsxs(As,{children:[V,U]}),t[85]=V,t[86]=U,t[87]=ae):ae=t[87];let ve;t[88]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>y(null),t[88]=ve):ve=t[88];let ie;t[89]!==e?(ie=e("settings.common.actions.cancel"),t[89]=e,t[90]=ie):ie=t[90];let fe;t[91]!==k||t[92]!==ie?(fe=s.jsx(be,{variant:"ghost",onClick:ve,disabled:k,children:ie}),t[91]=k,t[92]=ie,t[93]=fe):fe=t[93];let H;t[94]!==E?(H=()=>{E()},t[94]=E,t[95]=H):H=t[95];let ce;t[96]!==e?(ce=e("settings.common.actions.delete"),t[96]=e,t[97]=ce):ce=t[97];let se;t[98]!==k||t[99]!==H||t[100]!==ce?(se=s.jsx(be,{size:"sm",variant:"destructive",onClick:H,disabled:k,children:ce}),t[98]=k,t[99]=H,t[100]=ce,t[101]=se):se=t[101];let oe;t[102]!==fe||t[103]!==se?(oe=s.jsxs(Hs,{children:[fe,se]}),t[102]=fe,t[103]=se,t[104]=oe):oe=t[104];let te;t[105]!==ae||t[106]!==oe?(te=s.jsxs(ys,{className:"max-w-md",children:[ae,oe]}),t[105]=ae,t[106]=oe,t[107]=te):te=t[107];let ke;t[108]!==le||t[109]!==J||t[110]!==te?(ke=s.jsx(vs,{open:le,onOpenChange:J,children:te}),t[108]=le,t[109]=J,t[110]=te,t[111]=ke):ke=t[111];let Ne;return t[112]!==ue||t[113]!==Y||t[114]!==ke?(Ne=s.jsxs(s.Fragment,{children:[ue,Y,ke]}),t[112]=ue,t[113]=Y,t[114]=ke,t[115]=Ne):Ne=t[115],Ne},Cp=t=>{const e=at.c(54),{profile:n,isDefault:r,onEdit:a,onToggleDefault:i,onDelete:o,isReadOnly:c,hasBorder:d}=t,{t:p}=mt(),m=P5[n.icon||"branch"]||"git-branch",u=A5[n.color||""],f=n.authType||"ssh",b=d&&"border-b border-[var(--surface-subtle)]";let h;e[0]!==b?(h=me("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",b),e[0]=b,e[1]=h):h=e[1];let v;e[2]!==a?(v=B=>{(B.key==="Enter"||B.key===" ")&&a()},e[2]=a,e[3]=v):v=e[3];let x;e[4]!==u?(x={color:u},e[4]=u,e[5]=x):x=e[5];let g;e[6]!==m||e[7]!==x?(g=s.jsx(I,{name:m,className:"w-4 h-4 shrink-0",style:x}),e[6]=m,e[7]=x,e[8]=g):g=e[8];let w;e[9]!==n.name?(w=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:n.name}),e[9]=n.name,e[10]=w):w=e[10];let y;e[11]!==f?(y=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:f}),e[11]=f,e[12]=y):y=e[12];let k;e[13]!==r||e[14]!==p?(k=r&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:p("settings.gitIdentities.page.badge.default")}),e[13]=r,e[14]=p,e[15]=k):k=e[15];let D;e[16]!==c||e[17]!==p?(D=c&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:p("settings.agents.sidebar.badge.system")}),e[16]=c,e[17]=p,e[18]=D):D=e[18];let j;e[19]!==w||e[20]!==y||e[21]!==k||e[22]!==D?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,y,k,D]}),e[19]=w,e[20]=y,e[21]=k,e[22]=D,e[23]=j):j=e[23];const S=f==="token"&&n.host?n.host:n.userEmail;let A;e[24]!==S?(A=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:S}),e[24]=S,e[25]=A):A=e[25];let E;e[26]!==j||e[27]!==A?(E=s.jsxs("div",{className:"min-w-0",children:[j,A]}),e[26]=j,e[27]=A,e[28]=E):E=e[28];let P;e[29]!==E||e[30]!==g?(P=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[g,E]}),e[29]=E,e[30]=g,e[31]=P):P=e[31];let C;e[32]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(Bs,{asChild:!0,children:s.jsx(be,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:E5,children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[32]=C):C=e[32];let N;e[33]!==i?(N=B=>{B.stopPropagation(),i()},e[33]=i,e[34]=N):N=e[34];let T;e[35]!==r||e[36]!==p?(T=p(r?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault"),e[35]=r,e[36]=p,e[37]=T):T=e[37];let M;e[38]!==N||e[39]!==T?(M=s.jsx(Vt,{onClick:N,children:T}),e[38]=N,e[39]=T,e[40]=M):M=e[40];let R;e[41]!==c||e[42]!==o||e[43]!==p?(R=!c&&o&&s.jsxs(Vt,{onClick:B=>{B.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]}),e[41]=c,e[42]=o,e[43]=p,e[44]=R):R=e[44];let O;e[45]!==M||e[46]!==R?(O=s.jsxs(_s,{children:[C,s.jsxs(zs,{align:"end",className:"w-fit min-w-28",children:[M,R]})]}),e[45]=M,e[46]=R,e[47]=O):O=e[47];let z;return e[48]!==a||e[49]!==P||e[50]!==h||e[51]!==O||e[52]!==v?(z=s.jsxs("div",{className:h,onClick:a,role:"button",tabIndex:0,onKeyDown:v,children:[P,O]}),e[48]=a,e[49]=P,e[50]=h,e[51]=O,e[52]=v,e[53]=z):z=e[53],z},T5=t=>{const e=at.c(21),{credential:n,onImport:r,hasBorder:a}=t,{t:i}=mt();let o;e[0]!==n.host?(o=n.host.split("/"),e[0]=n.host,e[1]=o):o=e[1];const c=o,d=c.length>=3?c[c.length-1]:n.host,p=n.host.includes("/"),m=a&&"border-b border-[var(--surface-subtle)]";let u;e[2]!==m?(u=me("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",m),e[2]=m,e[3]=u):u=e[3];let f;e[4]!==d?(f=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:d}),e[4]=d,e[5]=f):f=e[5];const b=p?n.host:n.username;let h;e[6]!==b?(h=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:b}),e[6]=b,e[7]=h):h=e[7];let v;e[8]!==f||e[9]!==h?(v=s.jsxs("div",{className:"min-w-0",children:[f,h]}),e[8]=f,e[9]=h,e[10]=v):v=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(I,{name:"download",className:"h-3 w-3"}),e[11]=x):x=e[11];let g;e[12]!==i?(g=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=g):g=e[13];let w;e[14]!==r||e[15]!==g?(w=s.jsxs(be,{size:"sm",variant:"ghost",onClick:r,className:"gap-1 shrink-0",children:[x,g]}),e[14]=r,e[15]=g,e[16]=w):w=e[16];let y;return e[17]!==w||e[18]!==u||e[19]!==v?(y=s.jsxs("div",{className:u,children:[v,w]}),e[17]=w,e[18]=u,e[19]=v,e[20]=y):y=e[20],y};function M5(t){return{profiles:t.profiles,globalIdentity:t.globalIdentity,defaultGitIdentityId:t.defaultGitIdentityId,deleteProfile:t.deleteProfile,loadProfiles:t.loadProfiles,loadGlobalIdentity:t.loadGlobalIdentity,loadDiscoveredCredentials:t.loadDiscoveredCredentials,loadDefaultGitIdentityId:t.loadDefaultGitIdentityId,setDefaultGitIdentityId:t.setDefaultGitIdentityId,getUnimportedCredentials:t.getUnimportedCredentials}}function E5(t){return t.stopPropagation()}const wg=()=>{const t=Wb();return{displayMode:t,installed:t!=="browser",browserTab:t==="browser"}},jg=()=>{const t=at.c(2),[e,n]=l.useState(R5);let r,a;return t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const i=[window.matchMedia("(display-mode: standalone)"),window.matchMedia("(display-mode: minimal-ui)"),window.matchMedia("(display-mode: fullscreen)"),window.matchMedia("(display-mode: window-controls-overlay)")],o=()=>{n(wg())};o();for(const c of i)typeof c.addEventListener=="function"?c.addEventListener("change",o):typeof c.addListener=="function"&&c.addListener(o);return window.addEventListener("appinstalled",o),window.addEventListener("focus",o),()=>{for(const c of i)typeof c.removeEventListener=="function"?c.removeEventListener("change",o):typeof c.removeListener=="function"&&c.removeListener(o);window.removeEventListener("appinstalled",o),window.removeEventListener("focus",o)}},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),l.useEffect(r,a),e};function R5(){return wg()}const F5=[{value:"system",labelKey:"settings.openchamber.visual.option.themeMode.system"},{value:"light",labelKey:"settings.openchamber.visual.option.themeMode.light"},{value:"dark",labelKey:"settings.openchamber.visual.option.themeMode.dark"}],L5=[{id:"dynamic",labelKey:"settings.openchamber.visual.option.diffLayout.dynamic.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.dynamic.description"},{id:"inline",labelKey:"settings.openchamber.visual.option.diffLayout.inline.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.inline.description"},{id:"side-by-side",labelKey:"settings.openchamber.visual.option.diffLayout.sideBySide.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.sideBySide.description"}],O5=[{id:"single",labelKey:"settings.openchamber.visual.option.diffViewMode.single.label",descriptionKey:"settings.openchamber.visual.option.diffViewMode.single.description"},{id:"stacked",labelKey:"settings.openchamber.visual.option.diffViewMode.stacked.label",descriptionKey:"settings.openchamber.visual.option.diffViewMode.stacked.description"}],$5=[{id:"svg",labelKey:"settings.openchamber.visual.option.mermaidRendering.svg.label",descriptionKey:"settings.openchamber.visual.option.mermaidRendering.svg.description"},{id:"ascii",labelKey:"settings.openchamber.visual.option.mermaidRendering.ascii.label",descriptionKey:"settings.openchamber.visual.option.mermaidRendering.ascii.description"}],Mi="OpenChamber - AI Coding Assistant",Ip=[{id:"system",labelKey:"settings.openchamber.visual.option.pwaOrientation.system.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.system.description"},{id:"portrait",labelKey:"settings.openchamber.visual.option.pwaOrientation.portrait.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.portrait.description"},{id:"landscape",labelKey:"settings.openchamber.visual.option.pwaOrientation.landscape.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.landscape.description"}],Pp=[{id:"native",labelKey:"settings.openchamber.visual.option.mobileKeyboardMode.native.label",descriptionKey:"settings.openchamber.visual.option.mobileKeyboardMode.native.description"},{id:"resize-content",labelKey:"settings.openchamber.visual.option.mobileKeyboardMode.resizeContent.label",descriptionKey:"settings.openchamber.visual.option.mobileKeyboardMode.resizeContent.description"}],Dc=t=>t==="portrait"||t==="landscape"?t:"system",B5=[{id:"markdown",labelKey:"settings.openchamber.visual.option.userMessageRendering.markdown.label",descriptionKey:"settings.openchamber.visual.option.userMessageRendering.markdown.description"},{id:"plain",labelKey:"settings.openchamber.visual.option.userMessageRendering.plain.label",descriptionKey:"settings.openchamber.visual.option.userMessageRendering.plain.description"}],z5=[{id:"sorted",labelKey:"settings.openchamber.visual.option.chatRenderMode.sorted.label",descriptionKey:"settings.openchamber.visual.option.chatRenderMode.sorted.description"},{id:"live",labelKey:"settings.openchamber.visual.option.chatRenderMode.live.label",descriptionKey:"settings.openchamber.visual.option.chatRenderMode.live.description"}],Ap=[{id:"auto",labelKey:"settings.openchamber.visual.option.messageTransport.auto.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.auto.description"},{id:"ws",labelKey:"settings.openchamber.visual.option.messageTransport.ws.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.ws.description"},{id:"sse",labelKey:"settings.openchamber.visual.option.messageTransport.sse.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.sse.description"}],_5=[{id:"collapsed",labelKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.description"},{id:"summary",labelKey:"settings.openchamber.visual.option.activityRenderMode.summary.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.summary.description"}],Dp=[{id:"auto",labelKey:"settings.openchamber.visual.option.timeFormat.auto.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.auto.description"},{id:"24h",labelKey:"settings.openchamber.visual.option.timeFormat.24h.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.24h.description"},{id:"12h",labelKey:"settings.openchamber.visual.option.timeFormat.12h.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.12h.description"}],Tp=[{id:"auto",labelKey:"settings.openchamber.visual.option.weekStart.auto.label",descriptionKey:"settings.openchamber.visual.option.weekStart.auto.description"},{id:"monday",labelKey:"settings.openchamber.visual.option.weekStart.monday.label"},{id:"sunday",labelKey:"settings.openchamber.visual.option.weekStart.sunday.label"}],V5=t=>t==="markdown"?"markdown":"plain",nu=({visibleSettings:t})=>{const{locale:e,locales:n,setLocale:r,label:a,t:i}=mt(),o=l.useCallback(Z=>i(Z),[i]),{isMobile:c}=an(),{browserTab:d}=jg(),p=Tl(),m=Te(Z=>Z.showReasoningTraces),u=Te(Z=>Z.setShowReasoningTraces),f=Te(Z=>Z.collapsibleThinkingBlocks),b=Te(Z=>Z.setCollapsibleThinkingBlocks),h=Te(Z=>Z.mermaidRenderingMode),v=Te(Z=>Z.setMermaidRenderingMode),x=Te(Z=>Z.userMessageRenderingMode),g=Te(Z=>Z.setUserMessageRenderingMode),w=Te(Z=>Z.stickyUserHeader),y=Te(Z=>Z.setStickyUserHeader),k=Te(Z=>Z.wideChatLayoutEnabled),D=Te(Z=>Z.setWideChatLayoutEnabled),j=Te(Z=>Z.chatRenderMode),S=Te(Z=>Z.setChatRenderMode),A=Te(Z=>Z.activityRenderMode),E=Te(Z=>Z.setActivityRenderMode),P=Te(Z=>Z.fontSize),C=Te(Z=>Z.setFontSize),N=Te(Z=>Z.terminalFontSize),T=Te(Z=>Z.setTerminalFontSize),M=Te(Z=>Z.uiFont),R=Te(Z=>Z.setUiFont),O=Te(Z=>Z.monoFont),z=Te(Z=>Z.setMonoFont),B=Te(Z=>Z.padding),$=Te(Z=>Z.setPadding),_=Te(Z=>Z.inputBarOffset),Q=Te(Z=>Z.setInputBarOffset),W=Te(Z=>Z.mobileKeyboardMode),ne=Te(Z=>Z.setMobileKeyboardMode),re=Te(Z=>Z.diffLayoutPreference),ue=Te(Z=>Z.setDiffLayoutPreference),Y=Te(Z=>Z.diffViewMode),le=Te(Z=>Z.setDiffViewMode),J=Te(Z=>Z.showTerminalQuickKeysOnDesktop),L=Te(Z=>Z.setShowTerminalQuickKeysOnDesktop),V=ku(Z=>Z.queueModeEnabled),K=ku(Z=>Z.setQueueMode),X=Te(Z=>Z.persistChatDraft),U=Te(Z=>Z.setPersistChatDraft),ae=Te(Z=>Z.inputSpellcheckEnabled),ve=Te(Z=>Z.setInputSpellcheckEnabled),ie=Te(Z=>Z.showToolFileIcons),fe=Te(Z=>Z.setShowToolFileIcons),H=Te(Z=>Z.showExpandedBashTools),ce=Te(Z=>Z.setShowExpandedBashTools),se=Te(Z=>Z.showExpandedEditTools),oe=Te(Z=>Z.setShowExpandedEditTools),te=Te(Z=>Z.timeFormatPreference),ke=Te(Z=>Z.setTimeFormatPreference),Ne=Te(Z=>Z.weekStartPreference),je=Te(Z=>Z.setWeekStartPreference),Se=Te(Z=>Z.showSplitAssistantMessageActions),De=Te(Z=>Z.setShowSplitAssistantMessageActions),ye=Te(Z=>Z.showMobileSessionStatusBar),ge=Te(Z=>Z.setShowMobileSessionStatusBar),Me=gt(Z=>Z.settingsMessageStreamTransport),Ue=gt(Z=>Z.setSettingsMessageStreamTransport),q=Te(Z=>Z.isSettingsDialogOpen),{themeMode:Ie,setThemeMode:Le,availableThemes:Pe,customThemesLoading:he,reloadCustomThemes:F,lightThemeId:ee,darkThemeId:Ce,setLightThemePreference:Fe,setDarkThemePreference:we}=Cr(),[Qe,pe]=l.useState(!1),[Oe,nt]=l.useState(0),Re=Te(Z=>Z.reportUsage),de=Te(Z=>Z.setReportUsage),He=l.useCallback(Z=>{de(Z),Ms({reportUsage:Z})},[de]),st=q&&(t?t.includes("chatRenderMode"):!0);l.useEffect(()=>{if(!st)return;let Z=null,ft=Date.now();const kt=()=>{const Ns=Date.now();Ns-ft>=420&&(nt(Cs=>(Cs+1)%24),ft=Ns),Z=requestAnimationFrame(kt)};(typeof document>"u"||document.visibilityState==="visible")&&(Z=requestAnimationFrame(kt));const Ht=()=>{document.visibilityState==="visible"&&Z===null?Z=requestAnimationFrame(kt):document.visibilityState!=="visible"&&Z!==null&&(cancelAnimationFrame(Z),Z=null)};return document.addEventListener("visibilitychange",Ht),()=>{document.removeEventListener("visibilitychange",Ht),Z!==null&&cancelAnimationFrame(Z)}},[st]);const qe=l.useCallback(Z=>{g(Z),Ms({userMessageRenderingMode:Z})},[g]),et=l.useCallback(Z=>{y(Z),Ms({stickyUserHeader:Z})},[y]),rt=l.useCallback(Z=>{D(Z),Ms({wideChatLayoutEnabled:Z})},[D]),xe=l.useCallback(Z=>{De(Z),Ms({showSplitAssistantMessageActions:Z})},[De]),Ye=l.useCallback(Z=>{ve(Z),Ms({inputSpellcheckEnabled:Z})},[ve]),_e=l.useCallback(Z=>{S(Z),Ms({chatRenderMode:Z})},[S]),We=l.useCallback(Z=>{Ue(Z),Ms({messageStreamTransport:Z})},[Ue]),lt=l.useCallback(Z=>{E(Z),Ms({activityRenderMode:Z})},[E]),Je=l.useCallback(Z=>{v(Z),Ms({mermaidRenderingMode:Z})},[v]),Ve=l.useCallback(Z=>{fe(Z),Ms({showToolFileIcons:Z})},[fe]),yt=l.useCallback(Z=>{ce(Z),Ms({showExpandedBashTools:Z})},[ce]),$t=l.useCallback(Z=>{oe(Z),Ms({showExpandedEditTools:Z})},[oe]),Gt=l.useCallback(Z=>{ke(Z),Ms({timeFormatPreference:Z})},[ke]),ss=l.useCallback(Z=>{je(Z),Ms({weekStartPreference:Z})},[je]),wt=l.useMemo(()=>Pe.filter(Z=>Z.metadata.variant==="light").sort((Z,ft)=>Z.metadata.name.localeCompare(ft.metadata.name)),[Pe]),Dt=l.useMemo(()=>Pe.filter(Z=>Z.metadata.variant==="dark").sort((Z,ft)=>Z.metadata.name.localeCompare(ft.metadata.name)),[Pe]),Xt=l.useMemo(()=>wt.find(Z=>Z.metadata.id===ee)??wt[0],[wt,ee]),Yt=l.useMemo(()=>Dt.find(Z=>Z.metadata.id===Ce)??Dt[0],[Dt,Ce]),ts=l.useCallback((Z,ft)=>{const kt=ft==="dark"?" Dark":" Light";return Z.endsWith(kt)?Z.slice(0,-kt.length):Z},[]),dt=Z=>t?t.includes(Z):!0,Rt=un(),is=dt("theme")&&!Rt,xs=dt("theme")||dt("timeFormat")||dt("weekStart"),ps=Rt?xs:dt("theme")||dt("pwaInstallName")||dt("pwaOrientation")||dt("timeFormat")||dt("weekStart"),ws=dt("fontSize")||dt("terminalFontSize")||dt("spacing")||dt("inputBarOffset"),qt=dt("terminalQuickKeys")&&!c,Ge=dt("mermaidRendering")||dt("userMessageRendering")||dt("chatRenderMode")||dt("messageTransport")||dt("activityRenderMode")&&j==="sorted"||dt("stickyUserHeader")||dt("wideChatLayout")||dt("splitAssistantMessageActions")||dt("diffLayout")||dt("mobileStatusBar")&&c||dt("dotfiles")||dt("reasoning")||dt("queueMode")||dt("persistDraft")||dt("showToolFileIcons")||dt("expandedTools")||!c&&dt("inputSpellcheck"),St=dt("pwaInstallName")&&aa()&&d&&!yn()&&!Rt,Mt=dt("pwaOrientation")&&aa()&&!yn()&&!Rt,Nt=dt("mobileKeyboardMode")&&aa()&&!yn()&&!Rt&&Kb(),[Kt,ns]=l.useState(""),[js,ls]=l.useState("system"),ks=l.useMemo(()=>{const Z=Dp.find(ft=>ft.id===te);return o(Z?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[te,o]),Os=l.useMemo(()=>{const Z=Tp.find(ft=>ft.id===Ne);return o(Z?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[Ne,o]),xt=l.useMemo(()=>{const Z=Ip.find(ft=>ft.id===js);return Z?o(Z.labelKey):void 0},[js,o]),cs=l.useMemo(()=>{const Z=Pp.find(ft=>ft.id===W);return Z?o(Z.labelKey):void 0},[W,o]),jt=l.useCallback(async Z=>{if(typeof window>"u")return;const ft=window,Ht=Z.trim().replace(/\s+/g," ").slice(0,64);if(await Ms({pwaAppName:Ht}),typeof ft.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const Ns=ft.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Ht);ns(Ns);return}ns(Ht||Mi),ft.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Tt=l.useCallback(async Z=>{if(typeof window>"u")return;const ft=window,kt=Dc(Z);if(await Ms({pwaOrientation:kt}),typeof ft.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Ht=ft.__OPENCHAMBER_SET_PWA_ORIENTATION__(kt);ls(Ht);return}ls(kt),ft.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return l.useEffect(()=>{if(typeof window>"u"||!St&&!Mt&&!Nt)return;let Z=!1;return(async()=>{try{const kt=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!kt.ok){Z||ns(Mi);return}const Ht=await kt.json().catch(()=>({})),Cs=(typeof Ht?.pwaAppName=="string"?Ht.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Ke=Dc(Ht?.pwaOrientation),bt=Du(Ht?.mobileKeyboardMode);Z||(St&&ns(Cs||Mi),Mt&&ls(Ke),Nt&&ne(bt))}catch{Z||(St&&ns(Mi),Mt&&ls("system"),Nt&&ne("native"))}})(),()=>{Z=!0}},[ne,Nt,St,Mt]),s.jsxs("div",{className:"space-y-8",children:[ps&&s.jsxs("div",{className:"mb-8 space-y-6",children:[is&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.colorMode")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:F5.map(Z=>s.jsx(be,{variant:"chip",size:"xs","aria-pressed":Ie===Z.value,className:"!font-normal",onClick:()=>Le(Z.value),children:o(Z.labelKey)},Z.value))})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.lightTheme")}),s.jsxs(ds,{value:Xt?.metadata.id??"",onValueChange:Fe,children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:s.jsx(bs,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:Xt?ts(Xt.metadata.name,"light"):void 0})}),s.jsx(ms,{children:wt.map(Z=>s.jsx(Lt,{value:Z.metadata.id,children:ts(Z.metadata.name,"light")},Z.metadata.id))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.darkTheme")}),s.jsxs(ds,{value:Yt?.metadata.id??"",onValueChange:we,children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:s.jsx(bs,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:Yt?ts(Yt.metadata.name,"dark"):void 0})}),s.jsx(ms,{children:Dt.map(Z=>s.jsx(Lt,{value:Z.metadata.id,children:ts(Z.metadata.name,"dark")},Z.metadata.id))})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("button",{type:"button",disabled:he||Qe,onClick:()=>{const Z=Date.now();pe(!0),F().finally(()=>{const ft=Date.now()-Z;if(ft<500){window.setTimeout(()=>{pe(!1)},500-ft);return}pe(!1)})},className:"inline-flex items-center typography-ui-label font-normal text-foreground underline decoration-[1px] underline-offset-2 hover:text-foreground/80 disabled:cursor-not-allowed disabled:text-muted-foreground/60",children:i(Qe?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",className:"flex items-center justify-center rounded-md p-1 text-muted-foreground/70 hover:text-foreground","aria-label":i("settings.openchamber.visual.field.themeImportInfoAria"),children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(At,{sideOffset:8,children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),xs&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.localization")}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.appearance.language.label")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.appearance.language.description")})]}),s.jsxs(ds,{value:e,onValueChange:Z=>r(Z),children:[s.jsx(us,{"aria-label":i("settings.appearance.language.select"),className:"w-fit",children:s.jsx(bs,{children:a(e)})}),s.jsx(ms,{children:n.map(Z=>s.jsx(Lt,{value:Z,children:a(Z)},Z))})]})]}),!Rt&&(dt("timeFormat")||dt("weekStart"))&&s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[dt("timeFormat")&&s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.timeFormat")}),s.jsxs(ds,{value:te,onValueChange:Z=>Gt(Z),children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:s.jsx(bs,{children:ks})}),s.jsx(ms,{children:Dp.map(Z=>s.jsx(Lt,{value:Z.id,children:o(Z.labelKey)},Z.id))})]})]}),dt("weekStart")&&s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.weekStartsOn")}),s.jsxs(ds,{value:Ne,onValueChange:Z=>ss(Z),children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:s.jsx(bs,{children:Os})}),s.jsx(ms,{children:Tp.map(Z=>s.jsx(Lt,{value:Z.id,children:o(Z.labelKey)},Z.id))})]})]})]})]}),(St||Mt||Nt)&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[St&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.installAppName")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.installAppNameHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[28rem] items-center gap-2",children:[s.jsx(Wt,{value:Kt,onChange:Z=>{ns(Z.target.value)},onBlur:()=>{jt(Kt)},onKeyDown:Z=>{Z.key==="Enter"&&(Z.preventDefault(),jt(Kt))},className:"h-7",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ns(Mi),jt("")},className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Mt&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.installOrientation")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.installOrientationHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[s.jsxs(ds,{value:js,onValueChange:Z=>{const ft=Dc(Z);ls(ft),Tt(ft)},children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),className:"w-full",children:s.jsx(bs,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:xt})}),s.jsx(ms,{children:Ip.map(Z=>s.jsx(Lt,{value:Z.id,children:o(Z.labelKey)},Z.id))})]}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ls("system"),Tt("system")},disabled:js==="system",className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Nt&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.mobileKeyboardMode")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.mobileKeyboardModeHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[s.jsxs(ds,{value:W,onValueChange:Z=>{const ft=Du(Z);ne(ft),Ms({mobileKeyboardMode:ft})},children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),className:"w-full",children:s.jsx(bs,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:cs})}),s.jsx(ms,{children:Pp.map(Z=>s.jsx(Lt,{value:Z.id,children:o(Z.labelKey)},Z.id))})]}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ne("native"),Ms({mobileKeyboardMode:"native"})},disabled:W==="native",className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]}),ws&&s.jsx("div",{className:"mb-8 space-y-3",children:s.jsxs("section",{className:"p-2 space-y-0.5",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.spacingAndLayout")}),s.jsxs("div",{className:"pl-2",children:[dt("fontSize")&&!c&&s.jsxs("div",{className:"flex items-center gap-8 py-1",children:[s.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.interfaceFont")})}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsxs(ds,{value:M,onValueChange:Z=>R(Z),children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:s.jsx(bs,{children:Cu.find(Z=>Z.id===M)?.label})}),s.jsx(ms,{children:Cu.map(Z=>s.jsx(Lt,{value:Z.id,children:s.jsx("span",{style:{fontFamily:Z.stack},children:Z.label})},Z.id))})]}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>R(Iu),disabled:M===Iu,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),dt("terminalFontSize")&&s.jsxs("div",{className:me("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:me("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.codeFont")})}),s.jsxs("div",{className:me("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsxs(ds,{value:O,onValueChange:Z=>z(Z),children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:s.jsx(bs,{children:Pu.find(Z=>Z.id===O)?.label})}),s.jsx(ms,{children:Pu.map(Z=>s.jsx(Lt,{value:Z.id,children:s.jsx("span",{style:{fontFamily:Z.stack},children:Z.label})},Z.id))})]}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>z(Au),disabled:O===Au,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetCodeFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),dt("fontSize")&&!c&&s.jsxs("div",{className:"flex items-center gap-8 py-1",children:[s.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.interfaceFontSize")})}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsx(xn,{value:P,onValueChange:C,min:50,max:200,step:5,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria"),className:"w-16"}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>C(100),disabled:P===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),dt("terminalFontSize")&&s.jsxs("div",{className:me("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:me("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.terminalFontSize")})}),s.jsxs("div",{className:me("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(xn,{value:N,onValueChange:T,min:9,max:52,step:1,className:"w-16"}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>T(13),disabled:N===13,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),dt("spacing")&&s.jsxs("div",{className:me("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:me("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.spacingDensity")})}),s.jsxs("div",{className:me("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(xn,{value:B,onValueChange:$,min:50,max:200,step:5,className:"w-16"}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>$(100),disabled:B===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetSpacingAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),dt("inputBarOffset")&&s.jsxs("div",{className:me("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:me("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.inputBarOffset")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.inputBarOffsetTooltip")})]})]})}),s.jsxs("div",{className:me("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(xn,{value:_,onValueChange:Q,min:0,max:100,step:5,className:"w-16"}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>Q(0),disabled:_===0,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]})}),qt&&s.jsx("div",{className:"space-y-3",children:s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.navigation")}),dt("terminalQuickKeys")&&!c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":J,onClick:()=>L(!J),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),L(!J))},children:[s.jsx(fs,{checked:J,onChange:L,ariaLabel:i("settings.openchamber.visual.field.terminalQuickKeysAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.terminalQuickKeys")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.terminalQuickKeysTooltip")})]})]})]})]})}),Ge&&s.jsxs("div",{className:"space-y-3",children:[(dt("userMessageRendering")||dt("mermaidRendering")||dt("chatRenderMode")||dt("messageTransport")||dt("activityRenderMode")&&j==="sorted"||dt("diffLayout")&&!Rt)&&s.jsxs("div",{className:"grid grid-cols-1 gap-y-2 md:grid-cols-[minmax(0,16rem)_minmax(0,16rem)] md:justify-start md:gap-x-2",children:[dt("chatRenderMode")&&s.jsxs("section",{className:"p-2 md:col-span-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.chatRenderMode")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.chatRenderModeAria"),className:"mt-1 grid w-full max-w-[26rem] grid-cols-1 gap-3 sm:grid-cols-2",children:z5.map(Z=>{const ft=j===Z.id,kt=Oe%12;return s.jsxs("button",{type:"button",onClick:()=>_e(Z.id),"aria-pressed":ft,className:me("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",ft?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:me("typography-ui-label",ft?"text-foreground":"text-muted-foreground"),children:o(Z.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:Z.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Ht=>{const Ns=Ht*3+1,Cs=kt-Ns+1,Ke=Cs<=0?0:Cs===1?42:Cs===2?68:92,bt=Ke>0;return s.jsxs("div",{className:me("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",bt?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30 transition-all duration-300 motion-reduce:transition-none",style:{width:`${Ke}%`}})]},Ht)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Ht=>{const Ns=kt>=(Ht+1)*3;return s.jsxs("div",{className:me("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Ns?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},Ht)})})})]},Z.id)})})]}),dt("messageTransport")&&s.jsxs("section",{className:"p-2 md:col-span-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.messageStreamTransport")}),s.jsxs("div",{className:"mt-1 flex max-w-[24rem] flex-col gap-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Ap.map(Z=>s.jsx(be,{variant:"chip",size:"xs","aria-pressed":Me===Z.id,className:"!font-normal",onClick:()=>We(Z.id),children:o(Z.labelKey)},Z.id))}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const Z=Ap.find(ft=>ft.id===Me);return Z?.descriptionKey?o(Z.descriptionKey):""})()})]})]}),dt("activityRenderMode")&&j==="sorted"&&s.jsxs("section",{className:"p-2 md:col-span-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.activityDefault")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.activityDefaultAria"),className:"mt-0.5 space-y-0",children:_5.map(Z=>{const ft=A===Z.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ft,onClick:()=>lt(Z.id),onKeyDown:kt=>{(kt.key===" "||kt.key==="Enter")&&(kt.preventDefault(),lt(Z.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:ft,onChange:()=>lt(Z.id),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:o(Z.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ft?"text-foreground":"text-foreground/50"),children:o(Z.labelKey)})]},Z.id)})})]}),dt("expandedTools")&&s.jsxs("section",{className:"p-2 md:col-span-2 space-y-0.5",children:[s.jsx("div",{className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.showToolsOpenedByDefault")}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":H,onClick:()=>yt(!H),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),yt(!H))},children:[s.jsx(fs,{checked:H,onChange:yt,ariaLabel:i("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.bash")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":se,onClick:()=>$t(!se),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),$t(!se))},children:[s.jsx(fs,{checked:se,onChange:$t,ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editTools")})]})]}),dt("userMessageRendering")&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.userMessageRendering")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.userMessageRenderingAria"),className:"mt-0.5 space-y-0",children:B5.map(Z=>{const ft=V5(x)===Z.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ft,onClick:()=>qe(Z.id),onKeyDown:kt=>{(kt.key===" "||kt.key==="Enter")&&(kt.preventDefault(),qe(Z.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:ft,onChange:()=>qe(Z.id),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:o(Z.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ft?"text-foreground":"text-foreground/50"),children:o(Z.labelKey)})]},Z.id)})})]}),dt("mermaidRendering")&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.mermaidRendering")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.mermaidRenderingAria"),className:"mt-0.5 space-y-0",children:$5.map(Z=>{const ft=h===Z.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ft,onClick:()=>Je(Z.id),onKeyDown:kt=>{(kt.key===" "||kt.key==="Enter")&&(kt.preventDefault(),Je(Z.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:ft,onChange:()=>Je(Z.id),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:o(Z.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ft?"text-foreground":"text-foreground/50"),children:o(Z.labelKey)})]},Z.id)})})]}),dt("diffLayout")&&!Rt&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.diffLayout")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.diffLayoutAria"),className:"mt-0.5 space-y-0",children:L5.map(Z=>{const ft=re===Z.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ft,onClick:()=>ue(Z.id),onKeyDown:kt=>{(kt.key===" "||kt.key==="Enter")&&(kt.preventDefault(),ue(Z.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:ft,onChange:()=>ue(Z.id),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:o(Z.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ft?"text-foreground":"text-foreground/50"),children:o(Z.labelKey)})]},Z.id)})})]}),dt("diffLayout")&&!Rt&&s.jsxs("section",{className:"p-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.diffViewMode")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.diffViewModeAria"),className:"mt-0.5 space-y-0",children:O5.map(Z=>{const ft=Y===Z.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ft,onClick:()=>le(Z.id),onKeyDown:kt=>{(kt.key===" "||kt.key==="Enter")&&(kt.preventDefault(),le(Z.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Qa,{checked:ft,onChange:()=>le(Z.id),ariaLabel:i("settings.openchamber.visual.field.diffViewModeAria",{option:o(Z.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ft?"text-foreground":"text-foreground/50"),children:o(Z.labelKey)})]},Z.id)})})]})]}),(dt("stickyUserHeader")||dt("wideChatLayout")||dt("splitAssistantMessageActions")||dt("mobileStatusBar")&&c||dt("dotfiles")||dt("queueMode")||dt("persistDraft")||dt("showToolFileIcons")||!c&&dt("inputSpellcheck")||dt("reasoning"))&&s.jsxs("section",{className:"p-2 space-y-0.5",children:[dt("reasoning")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),u(!m))},children:[s.jsx(fs,{checked:m,onChange:u,ariaLabel:i("settings.openchamber.visual.field.showReasoningTracesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showReasoningTraces")})]}),dt("reasoning")&&m&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>b(!f),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),b(!f))},children:[s.jsx(fs,{checked:f,onChange:b,ariaLabel:i("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.collapsibleThinkingBlocks")})]}),dt("stickyUserHeader")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>et(!w),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),et(!w))},children:[s.jsx(fs,{checked:w,onChange:et,ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.stickyUserHeader")})]}),dt("wideChatLayout")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":k,onClick:()=>rt(!k),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),rt(!k))},children:[s.jsx(fs,{checked:k,onChange:rt,ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.wideChatLayout")})]}),dt("splitAssistantMessageActions")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Se,onClick:()=>xe(!Se),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),xe(!Se))},children:[s.jsx(fs,{checked:Se,onChange:xe,ariaLabel:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActions")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")})]})]})]}),dt("showToolFileIcons")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ie,onClick:()=>Ve(!ie),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),Ve(!ie))},children:[s.jsx(fs,{checked:ie,onChange:Ve,ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showToolFileIcons")})]}),dt("mobileStatusBar")&&c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ye,onClick:()=>ge(!ye),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),ge(!ye))},children:[s.jsx(fs,{checked:ye,onChange:ge,ariaLabel:i("settings.openchamber.visual.field.showMobileStatusBarAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showMobileStatusBar")})]}),dt("dotfiles")&&!un()&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>Uo(!p),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),Uo(!p))},children:[s.jsx(fs,{checked:p,onChange:Uo,ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showDotfiles")})]}),dt("queueMode")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":V,onClick:()=>K(!V),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),K(!V))},children:[s.jsx(fs,{checked:V,onChange:K,ariaLabel:i("settings.openchamber.visual.field.queueMessagesByDefaultAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.queueMessagesByDefault")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.queueMessagesByDefaultTooltip",{modifier:ll()})})]})]})]}),dt("persistDraft")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":X,onClick:()=>U(!X),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),U(!X))},children:[s.jsx(fs,{checked:X,onChange:U,ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.persistDraftMessages")})]}),!c&&dt("inputSpellcheck")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ae,onClick:()=>Ye(!ae),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),Ye(!ae))},children:[s.jsx(fs,{checked:ae,onChange:Ye,ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs")})]})]})]}),dt("reportUsage")&&s.jsx("div",{className:"space-y-3",children:s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground mb-2",children:i("settings.openchamber.visual.section.privacy")}),s.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[s.jsx(fs,{checked:Re,onChange:He,ariaLabel:i("settings.openchamber.visual.field.sendAnonymousUsageReportsAria")}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[s.jsx("div",{className:"group flex cursor-pointer",role:"button",tabIndex:0,"aria-pressed":Re,onClick:()=>He(!Re),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),He(!Re))},children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.sendAnonymousUsageReports")})}),s.jsx("span",{className:"typography-meta text-muted-foreground pointer-events-none",children:i("settings.openchamber.visual.field.sendAnonymousUsageReportsHint")})]})]})]})})]})};function U5(){if(typeof window>"u")return"unknown";try{const{deviceType:t}=Yb();return t}catch{return"unknown"}}function W5(){const t=typeof window<"u"?window.__VSCODE_CONFIG__?.arch?.toLowerCase?.():void 0;if(t==="arm64"||t==="aarch64")return"arm64";if(t==="x64"||t==="amd64"||t==="x86_64")return"x64";const n=(typeof navigator<"u"?navigator.userAgentData:void 0)?.architecture?.toLowerCase?.();if(n==="arm"||n==="arm64"||n==="aarch64")return"arm64";if(n==="x86"||n==="x64"||n==="amd64")return"x64";const r=typeof navigator<"u"?navigator.userAgent.toLowerCase():"";return r.includes("aarch64")||r.includes("arm64")||r.includes("armv")?"arm64":r.includes("x86_64")||r.includes("x64")||r.includes("amd64")||r.includes("win64")?"x64":"unknown"}function K5(){if(typeof navigator>"u")return"web";const t=(navigator.platform||"").toLowerCase();return t.includes("mac")?"macos":t.includes("win")?"windows":t.includes("linux")?"linux":"web"}function H5(t){const e=Te.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",U5()),n.set("arch",W5()),n.set("platform",K5()),t==="desktop"?(n.set("appType",qb()?"desktop-electron":"desktop-tauri"),n.set("instanceMode",Kr()?"local":"remote"),n):t==="vscode"?(n.set("appType","vscode"),n.set("instanceMode","local"),n):(n.set("appType","web"),n.set("instanceMode","unknown"),n)}async function Tc(t,e){try{const n=H5(t),r=typeof window<"u"?window.__VSCODE_CONFIG__?.extensionVersion:void 0;e?n.set("currentVersion",e):t==="vscode"&&r&&n.set("currentVersion",r);const a=await fetch(`/api/openchamber/update-check?${n.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!a.ok)throw new Error(`Server responded with ${a.status}`);const i=await a.json();return{available:i.available??!1,version:i.version,currentVersion:i.currentVersion??"unknown",body:i.body,nextSuggestedCheckInSec:typeof i.nextSuggestedCheckInSec=="number"&&Number.isFinite(i.nextSuggestedCheckInSec)?i.nextSuggestedCheckInSec:void 0,packageManager:i.packageManager,updateCommand:i.updateCommand}}catch(n){return console.warn("Failed to check for updates:",n),null}}function G5(){return Ma()?Kr()?"desktop":"web":un()?"vscode":aa()?"web":null}const Mp={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},Da=ar()((t,e)=>({...Mp,checkForUpdates:async()=>{const n=G5();if(!n)return null;t({checking:!0,error:null,runtimeType:n});try{let r=null,a=null;if(n==="desktop"){let i=await ec();t({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null});const o=await Tc("desktop",i?.currentVersion);if(a=o?.nextSuggestedCheckInSec??null,o?.available&&!i?.available){const c=await ec();c&&(i=c)}if(o){const c={...i??{available:!1,currentVersion:o.currentVersion??"unknown"},...o,currentVersion:i?.currentVersion??o.currentVersion??"unknown",available:o.available};t({available:c.available,info:c,nextCheckInSec:a})}else t({nextCheckInSec:a});return a}else n==="web"?(r=await Tc("web"),a=r?.nextSuggestedCheckInSec??null):n==="vscode"&&(a=(await Tc("vscode"))?.nextSuggestedCheckInSec??null);return t({checking:!1,available:n==="vscode"?!1:r?.available??!1,info:n==="vscode"?null:r,lastChecked:Date.now(),nextCheckInSec:a}),a}catch(r){return t({checking:!1,error:r instanceof Error?r.message:"Failed to check for updates"}),null}},downloadUpdate:async()=>{const{available:n,runtimeType:r}=e();if(!(r!=="desktop"||!n)){t({downloading:!0,error:null,progress:null});try{const a=await ec();if(!a?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(t(o=>({info:o.info?{...o.info,...a,body:o.info.body||a.body,available:o.info.available}:a})),!await Gb(o=>{t({progress:o})}))throw new Error("Desktop update only works on Local instance");t({downloading:!1,downloaded:!0})}catch(a){t({downloading:!1,error:a instanceof Error?a.message:"Failed to download update"})}}},restartToUpdate:async()=>{const{downloaded:n,runtimeType:r}=e();if(!(r!=="desktop"||!n))try{if(!await Hb())throw new Error("Desktop restart only works on Local instance")}catch(a){t({error:a instanceof Error?a.message:"Failed to restart"})}},dismiss:()=>{t({available:!1,downloaded:!1,info:null})},reset:()=>{t(Mp)}})),Ep="https://github.com/btriapitsyn/openchamber/releases";function q5(t){const e=new Date(`${t}T00:00:00`);return Number.isNaN(e.getTime())?t:new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric"}).format(e)}function Y5(t){return t.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Rp(t){return t.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function J5(t,e){const n=t.split(".").map(a=>Number.parseInt(a,10)),r=e.split(".").map(a=>Number.parseInt(a,10));for(let a=0;a<3;a+=1){const i=Number.isFinite(n[a])?n[a]:0,o=Number.isFinite(r[a])?r[a]:0;if(i!==o)return o-i}return 0}function Q5(t){const e=/^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2})\s*$/gm,n=[];let r;for(;(r=e.exec(t))!==null;)n.push({version:r[1]??"",date:r[2]??"",start:r.index});return n.length===0?[]:n.map((a,i)=>{const o=n[i+1]?.start??t.length,c=t.slice(a.start,o).trim();return{version:a.version,date:a.date,start:a.start,end:o,raw:c}})}const Fp=2e3,X5=600*1e3;async function Z5(){try{const t=await fetch("/api/openchamber/update-install",{method:"POST",headers:{"Content-Type":"application/json"}});return t.ok?{success:!0,autoRestart:(await t.json().catch(()=>({}))).autoRestart!==!1}:{success:!1,error:(await t.json().catch(()=>({}))).error||`Server error: ${t.status}`}}catch(t){return{success:!1,error:t instanceof Error?t.message:void 0}}}async function eC(){try{return(await fetch("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function tC(t,e=Math.ceil(X5/Fp),n=Fp){for(let r=0;r<e;r++){try{const a=await fetch("/api/openchamber/update-check",{method:"GET",headers:{Accept:"application/json"}});if(a.ok){const i=await a.json().catch(()=>null);if(i&&i.available===!1||i&&typeof i.currentVersion=="string"&&typeof t=="string"&&i.currentVersion!==t)return!0}else if((a.status===401||a.status===403)&&await eC())return!0}catch{}await new Promise(a=>setTimeout(a,n))}return!1}const wd=({open:t,onOpenChange:e,info:n,downloading:r,downloaded:a,progress:i,error:o,onDownload:c,onRestart:d,runtimeType:p="desktop"})=>{const{t:m}=mt(),[u,f]=ze.useState(!1),[b,h]=ze.useState("idle"),[v,x]=ze.useState(null),g=n?.version?`${Ep}/tag/v${n.version}`:Ep,w=i?.total?Math.round(i.downloaded/i.total*100):0,y=p==="web",k=n?.updateCommand||"openchamber update";ze.useEffect(()=>{t||(h("idle"),x(null))},[t]);const D=async()=>{(await Rn(k)).ok&&(f(!0),setTimeout(()=>f(!1),2e3))},j=ze.useCallback(async P=>{await sr(P)},[]),S=ze.useCallback(async()=>{h("updating"),x(null);const P=await Z5();if(!P.success){h("error"),x(P.error||m("updateDialog.error.updateFailed"));return}P.autoRestart&&(h("restarting"),await new Promise(N=>setTimeout(N,2e3))),h("reconnecting"),await tC(n?.currentVersion)?window.location.reload():(h("error"),x(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),A=b!=="idle"&&b!=="error",E=ze.useMemo(()=>{if(!n?.body)return null;const P=n.body.trim();if(!P)return null;const C=Q5(P);if(C.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:Rp(P)};const N=[...C].sort((T,M)=>J5(T.version,M.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:N.map(T=>({version:T.version,dateLabel:q5(T.date),content:Rp(Y5(T.raw)||P)}))}},[n?.body,m]);return s.jsx(vs,{open:t,onOpenChange:A?void 0:e,children:s.jsxs(ys,{className:"max-w-4xl p-5 bg-background border-[var(--interactive-border)]",showCloseButton:!0,children:[s.jsxs("div",{className:"flex items-center mb-1",children:[s.jsxs(Ss,{className:"flex items-center gap-2.5",children:[s.jsx(I,{name:"download-cloud",className:"h-5 w-5 text-[var(--primary-base)]"}),s.jsx("span",{className:"text-lg font-semibold text-foreground",children:m(b==="restarting"||b==="reconnecting"?"updateDialog.header.updating":"updateDialog.header.updateAvailable")})]}),(n?.currentVersion||n?.version)&&s.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm ml-3",children:[n?.currentVersion&&s.jsx("span",{className:"text-muted-foreground",children:n.currentVersion}),n?.currentVersion&&n?.version&&s.jsx("span",{className:"text-muted-foreground/50",children:"→"}),n?.version&&s.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:n.version})]})]}),s.jsxs("div",{className:"space-y-2",children:[y&&A&&s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/30 p-5 border border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(I,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),s.jsxs("div",{className:"typography-ui-label text-foreground",children:[b==="updating"&&m("updateDialog.status.installingUpdate"),b==="restarting"&&m("updateDialog.status.serverRestarting"),b==="reconnecting"&&m("updateDialog.status.waitingForServer")]})]}),s.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:m("updateDialog.status.autoReloadHint")})]}),E&&!A&&s.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:s.jsx(Es,{className:"max-h-[400px] p-0",fillContainer:!1,children:E.kind==="raw"?s.jsx("div",{className:"p-4 typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline hover:[&_a]:!underline",onClickCapture:P=>{const N=P.target.closest("a");N&&N.href&&(P.preventDefault(),P.stopPropagation(),j(N.href))},children:s.jsx(Ra,{content:E.content,disableLinkSafety:!0})}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:E.sections.map(P=>s.jsxs("div",{className:"p-4 hover:bg-background/40 transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[s.jsxs("span",{className:"typography-ui-label font-mono text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:["v",P.version]}),s.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:P.dateLabel})]}),s.jsx("div",{className:"typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline hover:[&_a]:!underline",onClickCapture:C=>{const T=C.target.closest("a");T&&T.href&&(C.preventDefault(),C.stopPropagation(),j(T.href))},children:s.jsx(Ra,{content:P.content,disableLinkSafety:!0})})]},P.version))})})}),y&&b==="error"&&s.jsxs("div",{className:"space-y-2 mt-4",children:[s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"terminal",className:"h-4 w-4"}),s.jsx("span",{children:m("updateDialog.fallback.updateViaTerminal")})]}),s.jsxs("div",{className:"flex items-center gap-2 p-1 pl-3 bg-[var(--surface-elevated)]/50 rounded-md border border-[var(--surface-subtle)]",children:[s.jsx("code",{className:"flex-1 font-mono text-sm text-foreground overflow-x-auto whitespace-nowrap",children:k}),s.jsx("button",{onClick:D,className:me("flex items-center justify-center p-2 rounded","text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]","transition-colors",u&&"text-[var(--status-success)]"),title:m(u?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:u?s.jsx(I,{name:"check",className:"h-4 w-4"}):s.jsx(I,{name:"clipboard",className:"h-4 w-4"})})]})]}),!y&&r&&s.jsxs("div",{className:"space-y-2 mt-4",children:[s.jsxs("div",{className:"flex items-center justify-between text-sm",children:[s.jsx("span",{className:"text-muted-foreground",children:m("updateDialog.status.downloadingPayload")}),s.jsxs("span",{className:"font-mono text-foreground",children:[w,"%"]})]}),s.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${w}%`}})})]}),(o||v)&&s.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:s.jsx("p",{className:"text-sm text-[var(--status-error)]",children:o||v})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[s.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0",children:[s.jsx(I,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),s.jsxs("div",{className:"flex-1 flex justify-end",children:[!y&&!a&&!r&&s.jsxs("button",{onClick:c,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[s.jsx(I,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!y&&r&&s.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[s.jsx(I,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.downloading")]}),!y&&a&&s.jsxs("button",{onClick:d,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--status-success)] text-white hover:opacity-90 transition-opacity",children:[s.jsx(I,{name:"restart",className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),y&&!A&&s.jsxs("button",{onClick:S,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[s.jsx(I,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),y&&A&&s.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[s.jsx(I,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},Lp="https://github.com/btriapitsyn/openchamber",sC=800,nC=()=>{const t=at.c(103),{t:e}=mt(),[n,r]=l.useState(!1),[a,i]=l.useState(!1),o=Da(br(rC)),{isMobile:c}=an(),d=o.info?.currentVersion||"unknown",p=l.useRef(!1);let m,u;t[0]!==a||t[1]!==e||t[2]!==o.available||t[3]!==o.checking||t[4]!==o.error?(m=()=>{if(o.checking)i(!0),p.current=!0;else if(a){const B=setTimeout(()=>{i(!1),p.current&&!o.available&&!o.error&&(G.success(e("settings.openchamber.about.toast.latestVersion")),p.current=!1)},sC);return()=>clearTimeout(B)}},u=[e,o.checking,a,o.available,o.error],t[0]=a,t[1]=e,t[2]=o.available,t[3]=o.checking,t[4]=o.error,t[5]=m,t[6]=u):(m=t[5],u=t[6]),l.useEffect(m,u);const f=o.checking||a;if(c){let B;t[7]!==d?(B=s.jsxs("span",{className:"typography-meta text-muted-foreground",children:["v",d]}),t[7]=d,t[8]=B):B=t[8];let $;t[9]!==f||t[10]!==e||t[11]!==o?($=!o.available&&!o.error&&s.jsx("button",{onClick:()=>o.checkForUpdates(),disabled:f,className:me("typography-meta text-muted-foreground/60 hover:text-muted-foreground disabled:cursor-default",f&&"animate-pulse [animation-duration:1s]"),children:e("settings.openchamber.about.actions.checkUpdates")}),t[9]=f,t[10]=e,t[11]=o,t[12]=$):$=t[12];let _;t[13]!==f||t[14]!==e||t[15]!==o.available?(_=!f&&o.available&&s.jsxs("button",{onClick:()=>r(!0),className:"flex items-center gap-1 typography-meta text-[var(--primary-base)] hover:underline",children:[s.jsx(I,{name:"download",className:"h-3.5 w-3.5"}),e("settings.openchamber.about.actions.update")]}),t[13]=f,t[14]=e,t[15]=o.available,t[16]=_):_=t[16];let Q;t[17]!==B||t[18]!==$||t[19]!==_?(Q=s.jsxs("div",{className:"flex items-center justify-between",children:[B,$,_]}),t[17]=B,t[18]=$,t[19]=_,t[20]=Q):Q=t[20];let W;t[21]!==o.error?(W=o.error&&s.jsx("p",{className:"typography-micro text-[var(--status-error)] truncate",children:o.error}),t[21]=o.error,t[22]=W):W=t[22];let ne;t[23]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsxs("a",{href:Lp,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"github-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"GitHub"})]}),t[23]=ne):ne=t[23];let re;t[24]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"discord-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"Discord"})]}),t[24]=re):re=t[24];let ue;t[25]===Symbol.for("react.memo_cache_sentinel")?(ue=s.jsxs("div",{className:"flex items-center gap-3",children:[ne,re,s.jsxs("a",{href:"https://x.com/btriapitsyn",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"twitter-xfill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[25]=ue):ue=t[25];let Y;t[26]!==n||t[27]!==o.downloadUpdate||t[28]!==o.downloaded||t[29]!==o.downloading||t[30]!==o.error||t[31]!==o.info||t[32]!==o.progress||t[33]!==o.restartToUpdate||t[34]!==o.runtimeType?(Y=s.jsx(wd,{open:n,onOpenChange:r,info:o.info,downloading:o.downloading,downloaded:o.downloaded,progress:o.progress,error:o.error,onDownload:o.downloadUpdate,onRestart:o.restartToUpdate,runtimeType:o.runtimeType}),t[26]=n,t[27]=o.downloadUpdate,t[28]=o.downloaded,t[29]=o.downloading,t[30]=o.error,t[31]=o.info,t[32]=o.progress,t[33]=o.restartToUpdate,t[34]=o.runtimeType,t[35]=Y):Y=t[35];let le;return t[36]!==Y||t[37]!==Q||t[38]!==W?(le=s.jsxs("div",{className:"w-full space-y-2",children:[Q,W,ue,Y]}),t[36]=Y,t[37]=Q,t[38]=W,t[39]=le):le=t[39],le}let b;t[40]!==e?(b=e("settings.openchamber.about.title"),t[40]=e,t[41]=b):b=t[41];let h;t[42]!==b?(h=s.jsx("div",{className:"mb-3 px-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:b})}),t[42]=b,t[43]=h):h=t[43];let v;t[44]!==e?(v=e("settings.openchamber.about.field.version"),t[44]=e,t[45]=v):v=t[45];let x;t[46]!==v?(x=s.jsx("span",{className:"typography-ui-label text-foreground",children:v}),t[46]=v,t[47]=x):x=t[47];let g;t[48]!==d?(g=s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:d}),t[48]=d,t[49]=g):g=t[49];let w;t[50]!==x||t[51]!==g?(w=s.jsxs("div",{className:"flex min-w-0 flex-col",children:[x,g]}),t[50]=x,t[51]=g,t[52]=w):w=t[52];let y;t[53]!==e||t[54]!==o.checking?(y=o.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(I,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),t[53]=e,t[54]=o.checking,t[55]=y):y=t[55];let k;t[56]!==e||t[57]!==o.available||t[58]!==o.checking||t[59]!==o.info?.version?(k=!o.checking&&o.available&&s.jsxs(be,{size:"sm",variant:"default",onClick:()=>r(!0),children:[s.jsx(I,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:o.info?.version||""})]}),t[56]=e,t[57]=o.available,t[58]=o.checking,t[59]=o.info?.version,t[60]=k):k=t[60];let D;t[61]!==e||t[62]!==o.available||t[63]!==o.checking||t[64]!==o.error?(D=!o.checking&&!o.available&&!o.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),t[61]=e,t[62]=o.available,t[63]=o.checking,t[64]=o.error,t[65]=D):D=t[65];let j;t[66]!==o?(j=()=>o.checkForUpdates(),t[66]=o,t[67]=j):j=t[67];const S=o.checking;let A;t[68]!==e?(A=e("settings.openchamber.about.actions.checkForUpdates"),t[68]=e,t[69]=A):A=t[69];let E;t[70]!==j||t[71]!==A||t[72]!==o.checking?(E=s.jsx(be,{size:"sm",variant:"outline",onClick:j,disabled:S,children:A}),t[70]=j,t[71]=A,t[72]=o.checking,t[73]=E):E=t[73];let P;t[74]!==D||t[75]!==E||t[76]!==y||t[77]!==k?(P=s.jsxs("div",{className:"flex items-center gap-3",children:[y,k,D,E]}),t[74]=D,t[75]=E,t[76]=y,t[77]=k,t[78]=P):P=t[78];let C;t[79]!==P||t[80]!==w?(C=s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-4 py-3 border-b border-[var(--surface-subtle)]",children:[w,P]}),t[79]=P,t[80]=w,t[81]=C):C=t[81];let N;t[82]!==o.error?(N=o.error&&s.jsx("div",{className:"px-3 py-2 border-b border-[var(--surface-subtle)]",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:o.error})}),t[82]=o.error,t[83]=N):N=t[83];let T;t[84]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsxs("a",{href:Lp,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(I,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),t[84]=T):T=t[84];let M;t[85]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[T,s.jsxs("a",{href:"https://x.com/btriapitsyn",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(I,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[85]=M):M=t[85];let R;t[86]!==C||t[87]!==N?(R=s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[C,N,M]}),t[86]=C,t[87]=N,t[88]=R):R=t[88];let O;t[89]!==n||t[90]!==o.downloadUpdate||t[91]!==o.downloaded||t[92]!==o.downloading||t[93]!==o.error||t[94]!==o.info||t[95]!==o.progress||t[96]!==o.restartToUpdate||t[97]!==o.runtimeType?(O=s.jsx(wd,{open:n,onOpenChange:r,info:o.info,downloading:o.downloading,downloaded:o.downloaded,progress:o.progress,error:o.error,onDownload:o.downloadUpdate,onRestart:o.restartToUpdate,runtimeType:o.runtimeType}),t[89]=n,t[90]=o.downloadUpdate,t[91]=o.downloaded,t[92]=o.downloading,t[93]=o.error,t[94]=o.info,t[95]=o.progress,t[96]=o.restartToUpdate,t[97]=o.runtimeType,t[98]=O):O=t[98];let z;return t[99]!==R||t[100]!==O||t[101]!==h?(z=s.jsxs("div",{className:"mb-8",children:[h,R,O]}),t[99]=R,t[100]=O,t[101]=h,t[102]=z):z=t[102],z};function rC(t){return{info:t.info,checking:t.checking,available:t.available,error:t.error,downloading:t.downloading,downloaded:t.downloaded,progress:t.progress,runtimeType:t.runtimeType,checkForUpdates:t.checkForUpdates,downloadUpdate:t.downloadUpdate,restartToUpdate:t.restartToUpdate}}const aC=1,iC=365,Op=30,oC=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Ng=()=>{const t=at.c(113),{t:e}=mt(),n=Te(lC),r=Te(cC),a=Te(dC),i=Te(uC),o=Te(mC),c=Te(pC);let d;t[0]===Symbol.for("react.memo_cache_sentinel")?(d={autoRun:!1},t[0]=d):d=t[0];const{candidates:p,isRunning:m,runCleanup:u,action:f}=Jb(d),b=p.length;let h;t[1]!==u||t[2]!==e?(h=async()=>{const te=await u({force:!0});if(te.completedIds.length===0&&te.failedIds.length===0){G.message(te.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}te.completedIds.length>0&&G.success(te.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:te.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:te.completedIds.length})),te.failedIds.length>0&&G.error(te.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:te.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:te.failedIds.length}))},t[1]=u,t[2]=e,t[3]=h):h=t[3];const v=h;let x;t[4]!==e?(x=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=x):x=t[5];let g;t[6]!==x?(g=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:x}),t[6]=x,t[7]=g):g=t[7];let w;t[8]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[8]=w):w=t[8];let y;t[9]!==e?(y=e("settings.openchamber.sessionRetention.tooltip"),t[9]=e,t[10]=y):y=t[10];let k;t[11]!==y?(k=s.jsxs(It,{children:[w,s.jsx(At,{sideOffset:8,className:"max-w-xs",children:y})]}),t[11]=y,t[12]=k):k=t[12];let D;t[13]!==g||t[14]!==k?(D=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[g,k]})}),t[13]=g,t[14]=k,t[15]=D):D=t[15];let j,S;t[16]!==n||t[17]!==i?(j=()=>i(!n),S=te=>{(te.key===" "||te.key==="Enter")&&(te.preventDefault(),i(!n))},t[16]=n,t[17]=i,t[18]=j,t[19]=S):(j=t[18],S=t[19]);let A;t[20]!==e?(A=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[20]=e,t[21]=A):A=t[21];let E;t[22]!==n||t[23]!==i||t[24]!==A?(E=s.jsx(fs,{checked:n,onChange:i,ariaLabel:A}),t[22]=n,t[23]=i,t[24]=A,t[25]=E):E=t[25];let P;t[26]!==e?(P=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[26]=e,t[27]=P):P=t[27];let C;t[28]!==P?(C=s.jsx("span",{className:"typography-ui-label text-foreground",children:P}),t[28]=P,t[29]=C):C=t[29];let N;t[30]!==n||t[31]!==E||t[32]!==C||t[33]!==j||t[34]!==S?(N=s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":n,onClick:j,onKeyDown:S,children:[E,C]}),t[30]=n,t[31]=E,t[32]=C,t[33]=j,t[34]=S,t[35]=N):N=t[35];let T;t[36]!==e?(T=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[36]=e,t[37]=T):T=t[37];let M;t[38]!==T?(M=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:T})}),t[38]=T,t[39]=M):M=t[39];let R;t[40]!==e?(R=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[40]=e,t[41]=R):R=t[41];let O;t[42]!==r||t[43]!==o||t[44]!==R?(O=s.jsx(xn,{value:r,onValueChange:o,min:aC,max:iC,step:1,"aria-label":R,className:"w-20 tabular-nums"}),t[42]=r,t[43]=o,t[44]=R,t[45]=O):O=t[45];let z;t[46]!==e?(z=e("settings.openchamber.sessionRetention.field.days"),t[46]=e,t[47]=z):z=t[47];let B;t[48]!==z?(B=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:z}),t[48]=z,t[49]=B):B=t[49];let $;t[50]!==o?($=()=>o(Op),t[50]=o,t[51]=$):$=t[51];const _=r===Op;let Q;t[52]!==e?(Q=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[52]=e,t[53]=Q):Q=t[53];let W;t[54]!==e?(W=e("settings.common.actions.reset"),t[54]=e,t[55]=W):W=t[55];let ne;t[56]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"}),t[56]=ne):ne=t[56];let re;t[57]!==$||t[58]!==_||t[59]!==Q||t[60]!==W?(re=s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:$,disabled:_,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":Q,title:W,children:ne}),t[57]=$,t[58]=_,t[59]=Q,t[60]=W,t[61]=re):re=t[61];let ue;t[62]!==O||t[63]!==B||t[64]!==re?(ue=s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[O,B,re]}),t[62]=O,t[63]=B,t[64]=re,t[65]=ue):ue=t[65];let Y;t[66]!==M||t[67]!==ue?(Y=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[M,ue]}),t[66]=M,t[67]=ue,t[68]=Y):Y=t[68];let le;t[69]!==e?(le=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[69]=e,t[70]=le):le=t[70];let J;t[71]!==le?(J=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:le})}),t[71]=le,t[72]=J):J=t[72];let L;t[73]!==a||t[74]!==c||t[75]!==e?(L=oC.map(te=>s.jsx(be,{type:"button",variant:"chip",size:"xs","aria-pressed":a===te.value,className:"!font-normal",onClick:()=>c(te.value),children:e(te.labelKey)},te.value)),t[73]=a,t[74]=c,t[75]=e,t[76]=L):L=t[76];let V;t[77]!==L?(V=s.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:L}),t[77]=L,t[78]=V):V=t[78];let K;t[79]!==J||t[80]!==V?(K=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[J,V]}),t[79]=J,t[80]=V,t[81]=K):K=t[81];let X;t[82]!==N||t[83]!==Y||t[84]!==K?(X=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[N,Y,K]}),t[82]=N,t[83]=Y,t[84]=K,t[85]=X):X=t[85];let U;t[86]!==e?(U=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[86]=e,t[87]=U):U=t[87];let ae;t[88]!==U?(ae=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("p",{className:"typography-meta text-foreground font-medium",children:U})}),t[88]=U,t[89]=ae):ae=t[89];let ve;t[90]!==m||t[91]!==e?(ve=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[90]=m,t[91]=e,t[92]=ve):ve=t[92];let ie;t[93]!==v||t[94]!==m||t[95]!==ve?(ie=s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsx(be,{type:"button",variant:"outline",size:"xs",onClick:v,disabled:m,className:"!font-normal",children:ve})}),t[93]=v,t[94]=m,t[95]=ve,t[96]=ie):ie=t[96];let fe;t[97]!==ae||t[98]!==ie?(fe=s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[ae,ie]}),t[97]=ae,t[98]=ie,t[99]=fe):fe=t[99];let H;t[100]!==f||t[101]!==b||t[102]!==e?(H=f==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:b}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:b}),t[100]=f,t[101]=b,t[102]=e,t[103]=H):H=t[103];let ce;t[104]!==H?(ce=s.jsx("p",{className:"typography-meta text-muted-foreground",children:H}),t[104]=H,t[105]=ce):ce=t[105];let se;t[106]!==fe||t[107]!==ce?(se=s.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[fe,ce]}),t[106]=fe,t[107]=ce,t[108]=se):se=t[108];let oe;return t[109]!==X||t[110]!==se||t[111]!==D?(oe=s.jsxs("div",{className:"mb-8",children:[D,X,se]}),t[109]=X,t[110]=se,t[111]=D,t[112]=oe):oe=t[112],oe};function lC(t){return t.autoDeleteEnabled}function cC(t){return t.autoDeleteAfterDays}function dC(t){return t.sessionRetentionAction}function uC(t){return t.setAutoDeleteEnabled}function mC(t){return t.setAutoDeleteAfterDays}function pC(t){return t.setSessionRetentionAction}const $p=(t,e)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(t),Sg=()=>{const{t}=mt(),[e,n]=l.useState(!1),[r,a]=l.useState(!0),[i,o]=l.useState(!1),[c,d]=l.useState(null),[p,m]=l.useState(!1),[u,f]=l.useState([]),[b,h]=l.useState(Qb),[v,x]=l.useState(""),g=l.useMemo(()=>Xb(),[]),w=l.useCallback(async()=>{a(!0),x("");try{const j=await Zb();f(j)}catch(j){const S=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.loadFailed");x(S)}finally{a(!1)}},[t]);l.useEffect(()=>{let j=!1;return(async()=>{try{if(!g.supported){j||(n(!1),a(!1));return}j||n(!0)}catch{j||n(!1)}if(!j){const S=await tc();if(h(S),!S.enabled){f([]),a(!1);return}await w()}})(),()=>{j=!0,Tu()}},[w,g.supported]);const y=l.useCallback(async()=>{if(!b.enabled){const j=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");x(j),G.message(j);return}if(!e){x(g.reason),G.message(g.reason);return}if(i){Tu(),o(!1);return}x(""),o(!0);try{await ey(),h(await tc()),await w(),G.success(t("settings.openchamber.passkeys.toast.added"))}catch(j){if(ty(j)){G.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const S=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.addFailed");x(S),G.error(S)}finally{o(!1)}},[i,w,b.enabled,g.reason,e,t]),k=l.useCallback(async j=>{d(j),x("");try{await sy(j),h(await tc()),await w(),G.success(t("settings.openchamber.passkeys.toast.removed"))}catch(S){const A=S instanceof Error?S.message:t("settings.openchamber.passkeys.toast.removeFailed");x(A),G.error(A)}finally{d(null)}},[w,t]),D=l.useCallback(async()=>{m(!0),x("");try{await ny(),window.location.reload()}catch(j){const S=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");x(S),G.error(S),m(!1)}},[t]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.passkeys.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.passkeys.field.currentDevice")})}),s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[s.jsx(be,{type:"button",variant:i?"secondary":"outline",size:"xs",onClick:()=>{y()},disabled:r||p,className:"!font-normal",children:t(i?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(be,{type:"button",variant:"ghost",size:"xs",onClick:()=>{D()},disabled:r||i||p,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(p?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]})]}),!b.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),b.enabled&&!e&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:g.reason}),r?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):u.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:u.map(j=>s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:j.label})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:j.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:$p(j.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"))}):t("settings.openchamber.passkeys.item.added",{time:$p(j.createdAt,t("settings.openchamber.passkeys.time.neverUsed"))})}),s.jsx(be,{type:"button",variant:"ghost",size:"xs",onClick:()=>{k(j.id)},disabled:c===j.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===j.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]})]},j.id))})]}),v&&s.jsx("div",{className:"mt-1 px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:v})})]})},fC=t=>{const e=hi(t);return e||{providerId:"",modelId:""}},kg=()=>{const{t}=mt(),e=gt(M=>M.setProvider),n=gt(M=>M.setModel),r=gt(M=>M.setAgent),a=gt(M=>M.setCurrentVariant),i=gt(M=>M.setSettingsDefaultModel),o=gt(M=>M.setSettingsDefaultVariant),c=gt(M=>M.setSettingsDefaultAgent),d=gt(M=>M.setSettingsDefaultFileViewerPreview),p=gt(M=>M.settingsDefaultFileViewerPreview),m=Te(M=>M.showDeletionDialog),u=Te(M=>M.setShowDeletionDialog),f=gt(M=>M.providers),[b,h]=l.useState(),[v,x]=l.useState(),[g,w]=l.useState(),[y,k]=l.useState(!0),D=l.useMemo(()=>fC(b),[b]);l.useEffect(()=>{(async()=>{try{let R=null;if(!R){const O=hr()?.settings;if(O)try{const B=(await O.load())?.settings;B&&(R={defaultModel:typeof B.defaultModel=="string"?B.defaultModel:void 0,defaultVariant:typeof B.defaultVariant=="string"?B.defaultVariant:void 0,defaultAgent:typeof B.defaultAgent=="string"?B.defaultAgent:void 0})}catch{}}if(!R){const O=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});O.ok&&(R=await O.json())}if(R){const O=typeof R.defaultModel=="string"&&R.defaultModel.trim().length>0?R.defaultModel.trim():void 0,z=typeof R.defaultVariant=="string"&&R.defaultVariant.trim().length>0?R.defaultVariant.trim():void 0,B=typeof R.defaultAgent=="string"&&R.defaultAgent.trim().length>0?R.defaultAgent.trim():void 0;O!==void 0&&h(O),z!==void 0&&x(z),B!==void 0&&w(B)}}catch(R){console.warn("Failed to load defaults settings:",R)}finally{k(!1)}})()},[]);const j=l.useCallback(async(M,R)=>{const O=M&&R?`${M}/${R}`:void 0;h(O),x(void 0),o(void 0),a(void 0),i(O),M&&R&&f.find(B=>B.id===M)&&(e(M),n(R));try{await Ms({defaultModel:O??"",defaultVariant:""});const z=await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:O})});z.ok||console.warn("Failed to save default model to server:",z.status,z.statusText)}catch(z){console.warn("Failed to save default model:",z)}},[f,a,n,e,i,o]),S="__default__",A=l.useCallback(M=>M===S?t("settings.openchamber.defaults.option.default"):M.charAt(0).toUpperCase()+M.slice(1),[t]),E=l.useCallback(async M=>{const R=M===S?void 0:M||void 0;x(R),o(R),a(R);try{await Ms({defaultVariant:R??""})}catch(O){console.warn("Failed to save default variant:",O)}},[a,o]),P=l.useCallback(async M=>{const R=M||void 0;w(R),c(R),M&&r(M);try{await Ms({defaultAgent:R??""})}catch(O){console.warn("Failed to save default agent:",O)}},[r,c]),C=l.useCallback(()=>{const M=!p;d(M),Ms({defaultFileViewerPreview:M}).catch(console.warn)},[p,d]),N=l.useMemo(()=>{if(!D.providerId||!D.modelId)return[];const O=f.find(z=>z.id===D.providerId)?.models.find(z=>z.id===D.modelId)?.variants;return O?Object.keys(O):[]},[D.modelId,D.providerId,f]),T=N.length>0;return l.useEffect(()=>{!T&&v&&(x(void 0),o(void 0),a(void 0),Ms({defaultVariant:""}).catch(()=>{}))},[v,a,o,T]),y?null:s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-0.5 px-1",children:s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.defaults.title")})})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",D.providerId?s.jsxs("span",{className:"text-foreground",children:[D.providerId,"/",D.modelId,T?` (${v??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),g&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:g})]})]}),s.jsxs("div",{className:me("flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(uo,{providerId:D.providerId,modelId:D.modelId,onChange:j})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultThinking")})}),s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsxs(ds,{value:v??S,onValueChange:E,disabled:!T,children:[s.jsx(us,{className:"w-fit min-w-[120px]",children:s.jsx(bs,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:A(v??S)})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:S,children:t("settings.openchamber.defaults.option.default")}),N.map(M=>s.jsx(Lt,{value:M,children:A(M)},M))]})]})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultAgent")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(Ll,{agentName:g||"",onChange:P})})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:M=>{(M.key===" "||M.key==="Enter")&&(M.preventDefault(),u(!m))},children:[s.jsx(fs,{checked:m,onChange:u,ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.showDeletionDialog")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":p,onClick:C,onKeyDown:M=>{(M.key===" "||M.key==="Enter")&&(M.preventDefault(),C())},children:[s.jsx(fs,{checked:p,onChange:d,ariaLabel:t("settings.openchamber.defaults.field.openFilesPreviewAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.openFilesPreview")})]})]})]})},Bp={completion:{titleKey:"settings.notifications.page.template.defaults.completion.title",messageKey:"settings.notifications.page.template.defaults.completion.message"},error:{titleKey:"settings.notifications.page.template.defaults.error.title",messageKey:"settings.notifications.page.template.defaults.error.message"},question:{titleKey:"settings.notifications.page.template.defaults.question.title",messageKey:"settings.notifications.page.template.defaults.question.message"},subtask:{titleKey:"settings.notifications.page.template.defaults.subtask.title",messageKey:"settings.notifications.page.template.defaults.subtask.message"}},hC={completion:"settings.notifications.page.template.event.completion",subtask:"settings.notifications.page.template.event.subtask",error:"settings.notifications.page.template.event.error",question:"settings.notifications.page.template.event.question"},zp="big-pickle",Mc="__not_selected__",_p=200,Vp=100,Up=250,gC=()=>{const{t}=mt(),{isMobile:e}=an(),n=l.useMemo(()=>yn(),[]),r=l.useMemo(()=>un(),[]),a=!n&&!r,i=Te(H=>H.nativeNotificationsEnabled),o=Te(H=>H.setNativeNotificationsEnabled),c=Te(H=>H.notificationMode),d=Te(H=>H.setNotificationMode),p=Te(H=>H.notifyOnSubtasks),m=Te(H=>H.setNotifyOnSubtasks),u=Te(H=>H.notifyOnCompletion),f=Te(H=>H.setNotifyOnCompletion),b=Te(H=>H.notifyOnError),h=Te(H=>H.setNotifyOnError),v=Te(H=>H.notifyOnQuestion),x=Te(H=>H.setNotifyOnQuestion),g=Te(H=>H.notificationTemplates),w=Te(H=>H.setNotificationTemplates),y=Te(H=>H.summarizeLastMessage),k=Te(H=>H.setSummarizeLastMessage),D=Te(H=>H.summaryThreshold),j=Te(H=>H.setSummaryThreshold),S=Te(H=>H.summaryLength),A=Te(H=>H.setSummaryLength),E=Te(H=>H.maxLastMessageLength),P=Te(H=>H.setMaxLastMessageLength),C=gt(H=>H.settingsZenModel),N=gt(H=>H.setSettingsZenModel),[T,M]=l.useState("default"),[R,O]=l.useState(!1),[z,B]=l.useState(!1),[$,_]=l.useState(!1),[Q,W]=l.useState([]);l.useEffect(()=>{const H=new AbortController;return fetch("/api/zen/models",{method:"GET",headers:{Accept:"application/json"},signal:H.signal}).then(async ce=>{if(!ce.ok)return[];const se=await ce.json().catch(()=>({}));return(Array.isArray(se?.models)?se.models:[]).map(te=>{const ke=typeof te?.id=="string"?te.id.trim():"";return ke?{id:ke,name:ke}:null}).filter(te=>te!==null)}).then(ce=>{W(ce)}).catch(ce=>{ce?.name!=="AbortError"&&console.warn("Failed to load zen utility models:",ce)}),()=>{H.abort()}},[]);const ne=l.useMemo(()=>Q,[Q]),re=l.useMemo(()=>C&&ne.some(H=>H.id===C)?C:ne.some(H=>H.id===zp)?zp:ne[0]?.id??"",[C,ne]),ue=l.useCallback(async H=>{const ce=H===Mc?void 0:H;N(ce);try{await Ms({zenModel:ce??"",gitProviderId:"",gitModelId:""})}catch(se){console.warn("Failed to save utility model setting:",se)}},[N]);l.useEffect(()=>{if(!a){O(!1),B(!1);return}typeof Notification<"u"&&M(Notification.permission);const H=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;O(H),(async()=>{if(!H){B(!1);return}try{const se=await navigator.serviceWorker.getRegistration();if(!se){B(!1);return}const oe=await se.pushManager.getSubscription();B(!!oe)}catch{B(!1)}})()},[a]);const Y=async H=>{if(n){o(H);return}if(!a){o(H);return}if(H&&typeof Notification<"u"&&Notification.permission==="default")try{const ce=await Notification.requestPermission();M(ce),ce==="granted"?o(!0):G.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(ce){console.error("Failed to request notification permission:",ce),G.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else o(!!(H&&T==="granted"))},le=n||r||a&&typeof Notification<"u"&&Notification.permission==="granted",J=(H,ce,se)=>{w({...g,[H]:{...g[H],[ce]:se}})},L=H=>{const ce="=".repeat((4-H.length%4)%4),se=(H+ce).replace(/-/g,"+").replace(/_/g,"/"),oe=atob(se),te=new Uint8Array(oe.length);for(let ke=0;ke<oe.length;ke+=1)te[ke]=oe.charCodeAt(ke);return te},V=async(H,ce,se)=>{let oe=null;const te=new Promise((ke,Ne)=>{oe=setTimeout(()=>{Ne(new Error(se))},ce)});try{return await Promise.race([H,te])}finally{oe&&clearTimeout(oe)}},K=async H=>{if(H.active)return;const ce=H.installing||H.waiting;ce&&ce.state!=="activated"&&await V(new Promise(se=>{const oe=()=>{ce.state==="activated"&&(ce.removeEventListener("statechange",oe),se())};ce.addEventListener("statechange",oe),oe()}),15e3,"Service worker activation timed out")},X=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const H=[{label:"no-options",opts:null},{label:"scope-root",opts:{scope:"/"}},{label:"type-classic",opts:{type:"classic"}},{label:"type-classic-scope",opts:{type:"classic",scope:"/"}},{label:"updateViaCache-none",opts:{type:"classic",updateViaCache:"none",scope:"/"}}];let ce=null;for(const se of H)try{const oe=se.opts?navigator.serviceWorker.register("/sw.js",se.opts):navigator.serviceWorker.register("/sw.js");return await V(oe,1e4,`Service worker registration timed out (${se.label})`)}catch(oe){ce=oe}throw ce instanceof Error?ce:new Error("Service worker registration failed")},U=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const H=await navigator.serviceWorker.getRegistration();if(H)return H;const ce=await X();try{await ce.update()}catch{}return await K(ce),ce},ae=H=>{const ce=H,se=[`type=${typeof H}`,`toString=${String(H)}`,`name=${String(ce?.name??"")}`,`message=${String(ce?.message??"")}`];let oe="";try{oe=JSON.stringify(H)}catch{}return{summary:se.filter(Boolean).join(" | "),json:oe,stack:typeof ce?.stack=="string"?ce.stack:""}},ve=async()=>{const H=hr();if(!H?.notifications){G.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await H.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?G.success(t("settings.notifications.page.toast.testNotificationSent")):G.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(ce){console.error("Test notification failed:",ce),G.error(t("settings.notifications.page.toast.testNotificationFailed"))}},ie=async()=>{if(!R){G.error(t("settings.notifications.page.toast.pushUnsupported"));return}const H=hr();if(!H?.push){G.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}_(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const Se=await Notification.requestPermission();if(M(Se),Se!=="granted"){G.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){G.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const ce=await H.push.getVapidPublicKey();if(!ce?.publicKey){G.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const se=await U();await K(se);const oe=await se.pushManager.getSubscription();if(!("pushManager"in se)||!se.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const ke=(oe??await V(se.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:L(ce.publicKey)}),15e3,"Push subscription timed out")).toJSON(),Ne=ke.keys;if(!ke.endpoint||!Ne?.p256dh||!Ne.auth)throw new Error("Push subscription missing keys");if(!(await V(H.push.subscribe({endpoint:ke.endpoint,keys:{p256dh:Ne.p256dh,auth:Ne.auth},origin:typeof window<"u"?window.location.origin:void 0}),15e3,"Push subscribe request timed out"))?.ok){G.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}B(!0),G.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(ce){console.error("[Push] Enable failed:",ce);const se=ae(ce);G.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:se.summary})}finally{_(!1)}},fe=async()=>{if(!R){B(!1);return}const H=hr();if(!H?.push){G.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}_(!0);try{const se=await(await U()).pushManager.getSubscription();if(!se){B(!1);return}const oe=se.endpoint;await se.unsubscribe(),await H.push.unsubscribe({endpoint:oe}),B(!1),G.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{_(!1)}};return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.delivery.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":i&&le,onClick:()=>{Y(!(i&&le))},onKeyDown:H=>{(H.key===" "||H.key==="Enter")&&(H.preventDefault(),Y(!(i&&le)))},children:[s.jsx(fs,{checked:i&&le,onChange:H=>{Y(H)},ariaLabel:t("settings.notifications.page.delivery.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.enableLabel")})]}),i&&le&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":c==="always",onClick:()=>d(c==="always"?"hidden-only":"always"),onKeyDown:H=>{(H.key===" "||H.key==="Enter")&&(H.preventDefault(),d(c==="always"?"hidden-only":"always"))},children:[s.jsx(fs,{checked:c==="always",onChange:H=>d(H?"always":"hidden-only"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.focusedLabel")})]}),s.jsx("div",{className:"py-2",children:s.jsx(be,{type:"button",variant:"outline",size:"sm",onClick:()=>{ve()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),a&&s.jsxs("div",{className:"mt-1 px-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.browserPermissionHint")}),T==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),T==="granted"&&!i&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]}),r&&s.jsx("div",{className:"mt-1 px-2",children:s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.vscodeHint")})})]}),i&&le&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.events.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":u,onClick:()=>f(!u),onKeyDown:H=>{(H.key===" "||H.key==="Enter")&&(H.preventDefault(),f(!u))},children:[s.jsx(fs,{checked:u,onChange:f,ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.completionLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>m(!p),onKeyDown:H=>{(H.key===" "||H.key==="Enter")&&(H.preventDefault(),m(!p))},children:[s.jsx(fs,{checked:p,onChange:m,ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.subtaskLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":b,onClick:()=>h(!b),onKeyDown:H=>{(H.key===" "||H.key==="Enter")&&(H.preventDefault(),h(!b))},children:[s.jsx(fs,{checked:b,onChange:h,ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.errorLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":v,onClick:()=>x(!v),onKeyDown:H=>{(H.key===" "||H.key==="Enter")&&(H.preventDefault(),x(!v))},children:[s.jsx(fs,{checked:v,onChange:x,ariaLabel:t("settings.notifications.page.events.questionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.questionLabel")})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.template.title")}),s.jsxs("p",{className:"typography-meta text-muted-foreground mt-0.5",children:[t("settings.notifications.page.template.variablesLabel")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]})]}),s.jsx("div",{className:"grid grid-cols-1 gap-2 md:grid-cols-2 md:gap-3",children:["completion","subtask","error","question"].map(H=>s.jsxs("section",{className:"p-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground font-normal capitalize block",children:t(hC[H])}),s.jsxs("div",{className:"mt-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.title")}),s.jsx(Wt,{value:g[H].title,onChange:ce=>J(H,"title",ce.target.value),className:"h-7",placeholder:t(Bp[H].titleKey)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.message")}),s.jsx(Wt,{value:g[H].message,onChange:ce=>J(H,"message",ce.target.value),className:"h-7",placeholder:t(Bp[H].messageKey)})]})]})]},H))})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.summary.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":y,onClick:()=>k(!y),onKeyDown:H=>{(H.key===" "||H.key==="Enter")&&(H.preventDefault(),k(!y))},children:[s.jsx(fs,{checked:y,onChange:k,ariaLabel:t("settings.notifications.page.summary.toggleAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.toggleLabel")})]}),s.jsx("div",{className:"pl-6 pb-1",children:s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.notifications.page.summary.requiresTemplateVariable")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"}),"."]})}),s.jsxs("div",{className:me("flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.modelLabel")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.notifications.page.summary.modelTooltip")})]})]})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsxs(ds,{value:re||Mc,onValueChange:ue,children:[s.jsx(us,{className:"w-fit min-w-[220px]",children:s.jsx(bs,{placeholder:t("settings.notifications.page.summary.notSelected")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:Mc,children:t("settings.notifications.page.summary.notSelected")}),ne.map(H=>s.jsx(Lt,{value:H.id,children:H.name},H.id))]})]})})]}),y?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-8 py-1.5 mt-1 border-t border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.thresholdLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.notifications.page.summary.thresholdHint")})]}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsx(xn,{value:D,onValueChange:j,min:50,max:2e3,step:50,className:"w-20 tabular-nums"}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(_p),disabled:D===_p,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.notifications.page.summary.resetThresholdAria"),title:t("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.lengthLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.notifications.page.summary.lengthHint")})]}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsx(xn,{value:S,onValueChange:A,min:20,max:500,step:10,className:"w-20 tabular-nums"}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>A(Vp),disabled:S===Vp,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.notifications.page.summary.resetLengthAria"),title:t("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}):s.jsxs("div",{className:me("py-1.5 mt-1 border-t border-[var(--surface-subtle)]",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:me("flex min-w-0 flex-col",e?"w-full":"w-56 shrink-0"),children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.maxLengthLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.notifications.page.summary.maxLengthHint")})]}),s.jsxs("div",{className:me("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(xn,{value:E,onValueChange:P,min:50,max:1e3,step:10,className:"w-20 tabular-nums"}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>P(Up),disabled:E===Up,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.notifications.page.summary.resetMaxLengthAria"),title:t("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]})]}),a&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.push.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[s.jsx(fs,{checked:R?z:!1,disabled:!R||$,onChange:H=>{H?ie():fe()},ariaLabel:t("settings.notifications.page.push.enableAria")}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:me("typography-ui-label",R?"text-foreground":"text-muted-foreground"),children:t("settings.notifications.page.push.enableLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t(R?"settings.notifications.page.push.supportedHint":"settings.notifications.page.push.unsupportedHint")})]}),$&&s.jsx("div",{className:"pt-0.5 text-muted-foreground",children:s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")})})]})})]})]})},xC=[{value:"en-US",label:"English"},{value:"es-ES",label:"Español"},{value:"fr-FR",label:"Français"},{value:"de-DE",label:"Deutsch"},{value:"ja-JP",label:"日本語"},{value:"zh-CN",label:"中文"},{value:"pt-BR",label:"Português"},{value:"it-IT",label:"Italiano"},{value:"ko-KR",label:"한국어"},{value:"uk-UA",label:"Українська"}],bC=t=>{const e=at.c(45),{modelId:n}=t,{t:r}=mt();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=Fi.getModelStatus(),e[0]=a):a=e[0];const[i,o]=ze.useState(a),[c,d]=ze.useState(!1);let p,m;e[1]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{const j=S=>o(S);return Fi.onModelStatusChange=j,wC},m=[],e[1]=p,e[2]=m):(p=e[1],m=e[2]),ze.useEffect(p,m);const u=Fi.getCurrentModelId(),f=i.state==="downloading"||i.state==="loading";let b,h;e[3]!==i.state?(b=()=>{i.state!=="downloading"&&i.state!=="loading"&&d(!1)},h=[i.state],e[3]=i.state,e[4]=b,e[5]=h):(b=e[4],h=e[5]),ze.useEffect(b,h);let v;e[6]!==n?(v=async()=>{d(!0);try{await Fi.loadModel(n)}catch{}},e[6]=n,e[7]=v):v=e[7];const x=v;if(i.state==="ready"&&u===n){let j;e[8]!==r?(j=r("settings.voice.page.stt.wasmLoaded"),e[8]=r,e[9]=j):j=e[9];let S;return e[10]!==j?(S=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"typography-ui-compact text-green-600 dark:text-green-400",children:j})}),e[10]=j,e[11]=S):S=e[11],S}if(f){let j;e[12]!==i.progress||e[13]!==i.state?(j=i.state==="downloading"?Math.round(i.progress):void 0,e[12]=i.progress,e[13]=i.state,e[14]=j):j=e[14];const S=j;let A;e[15]!==i.state||e[16]!==r?(A=i.state==="downloading"?r("settings.voice.page.stt.wasmDownloading"):r("settings.voice.page.stt.wasmLoading"),e[15]=i.state,e[16]=r,e[17]=A):A=e[17];const E=S!==void 0?` (${S}%)`:"";let P;return e[18]!==A||e[19]!==E?(P=s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[A,E]})}),e[18]=A,e[19]=E,e[20]=P):P=e[20],P}if(i.state==="error"){let j;e[21]!==i.error?(j=s.jsx("span",{className:"typography-ui-compact text-destructive",children:i.error}),e[21]=i.error,e[22]=j):j=e[22];let S;e[23]!==r?(S=r("settings.voice.page.stt.wasmRetry"),e[23]=r,e[24]=S):S=e[24];let A;e[25]!==x||e[26]!==c||e[27]!==S?(A=s.jsx(be,{variant:"chip",size:"xs",disabled:c,onClick:x,children:S}),e[25]=x,e[26]=c,e[27]=S,e[28]=A):A=e[28];let E;return e[29]!==j||e[30]!==A?(E=s.jsxs("div",{className:"flex items-center gap-2",children:[j,A]}),e[29]=j,e[30]=A,e[31]=E):E=e[31],E}let g;e[32]!==r?(g=r("settings.voice.page.stt.wasmNotLoaded"),e[32]=r,e[33]=g):g=e[33];let w;e[34]!==g?(w=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:g}),e[34]=g,e[35]=w):w=e[35];let y;e[36]!==r?(y=r("settings.voice.page.stt.wasmDownload"),e[36]=r,e[37]=y):y=e[37];let k;e[38]!==x||e[39]!==c||e[40]!==y?(k=s.jsx(be,{variant:"chip",size:"xs",disabled:c,onClick:x,children:y}),e[38]=x,e[39]=c,e[40]=y,e[41]=k):k=e[41];let D;return e[42]!==k||e[43]!==w?(D=s.jsxs("div",{className:"flex items-center gap-2",children:[w,k]}),e[42]=k,e[43]=w,e[44]=D):D=e[44],D},yC=[{value:"alloy",label:"Alloy"},{value:"ash",label:"Ash"},{value:"ballad",label:"Ballad"},{value:"coral",label:"Coral"},{value:"echo",label:"Echo"},{value:"fable",label:"Fable"},{value:"nova",label:"Nova"},{value:"onyx",label:"Onyx"},{value:"sage",label:"Sage"},{value:"shimmer",label:"Shimmer"},{value:"verse",label:"Verse"},{value:"marin",label:"Marin"},{value:"cedar",label:"Cedar"}],vC=()=>{const{t}=mt(),{isMobile:e}=an(),{isSupported:n,language:r,setLanguage:a}=ry(),i=gt(de=>de.voiceProvider),o=gt(de=>de.setVoiceProvider),c=gt(de=>de.speechRate),d=gt(de=>de.setSpeechRate),p=gt(de=>de.speechPitch),m=gt(de=>de.setSpeechPitch),u=gt(de=>de.speechVolume),f=gt(de=>de.setSpeechVolume),b=gt(de=>de.sayVoice),h=gt(de=>de.setSayVoice),v=gt(de=>de.browserVoice),x=gt(de=>de.setBrowserVoice),g=gt(de=>de.openaiVoice),w=gt(de=>de.setOpenaiVoice),y=gt(de=>de.openaiApiKey),k=gt(de=>de.setOpenaiApiKey),D=gt(de=>de.openaiCompatibleUrl),j=gt(de=>de.setOpenaiCompatibleUrl),S=gt(de=>de.openaiCompatibleVoice),A=gt(de=>de.setOpenaiCompatibleVoice),E=gt(de=>de.openaiCompatibleTtsModel),P=gt(de=>de.setOpenaiCompatibleTtsModel),C=gt(de=>de.showMessageTTSButtons),N=gt(de=>de.sttProvider),T=gt(de=>de.setSttProvider),M=gt(de=>de.sttServerUrl),R=gt(de=>de.setSttServerUrl),O=gt(de=>de.sttModel),z=gt(de=>de.setSttModel),B=gt(de=>de.wasmSttModel),$=gt(de=>de.setWasmSttModel),_=gt(de=>de.sttLanguage),Q=gt(de=>de.setSttLanguage),W=gt(de=>de.sttSilenceThresholdDb),ne=gt(de=>de.setSttSilenceThresholdDb),re=gt(de=>de.sttSilenceHoldMs),ue=gt(de=>de.setSttSilenceHoldMs),Y=gt(de=>de.sttTranscribeOnStop),le=gt(de=>de.setSttTranscribeOnStop),J=gt(de=>de.setShowMessageTTSButtons),L=gt(de=>de.voiceModeEnabled),V=gt(de=>de.setVoiceModeEnabled),K=gt(de=>de.summarizeMessageTTS),X=gt(de=>de.setSummarizeMessageTTS),U=gt(de=>de.summarizeVoiceConversation),ae=gt(de=>de.setSummarizeVoiceConversation),ve=gt(de=>de.summarizeCharacterThreshold),ie=gt(de=>de.setSummarizeCharacterThreshold),fe=gt(de=>de.summarizeMaxLength),H=gt(de=>de.setSummarizeMaxLength),[ce,se]=ze.useState(!1),[oe,te]=ze.useState([]),[ke,Ne]=ze.useState(!1),[je,Se]=ze.useState(null),[De,ye]=ze.useState(!1),[ge,Me]=ze.useState(!1),[Ue,q]=ze.useState(null),[Ie,Le]=ze.useState(!1),[Pe,he]=ze.useState(null),[F,ee]=ze.useState([]),[Ce,Fe]=ze.useState(!1);ze.useEffect(()=>((async()=>{const He=await sc.waitForVoices();ee(He)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{ee(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const we=ze.useMemo(()=>F.filter(de=>de.lang).sort((de,He)=>{const st=de.lang.startsWith("en"),qe=He.lang.startsWith("en");if(st&&!qe)return-1;if(!st&&qe)return 1;const et=de.lang.localeCompare(He.lang);return et!==0?et:de.name.localeCompare(He.name)}),[F]),Qe=ze.useCallback(()=>{if(Ce){sc.cancelSpeech(),Fe(!1);return}const de=F.find(et=>et.name===v),He=de?.name??t("settings.voice.page.preview.browserVoiceFallback"),st=t("settings.voice.page.preview.voiceLine",{voiceName:He});Fe(!0);const qe=new SpeechSynthesisUtterance(st);qe.rate=c,qe.pitch=p,qe.volume=u,de&&(qe.voice=de,qe.lang=de.lang),qe.onend=()=>Fe(!1),qe.onerror=()=>Fe(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(qe)},[v,F,c,p,u,Ce,t]);ze.useEffect(()=>()=>{Ce&&sc.cancelSpeech()},[Ce]),ze.useEffect(()=>{if(!L||i!=="openai"&&i!=="openai-compatible"){ye(y.trim().length>0);return}(async()=>{try{const qe=(await(await fetch("/api/tts/status")).json()).available,et=y.trim().length>0;ye(qe||et)}catch{ye(y.trim().length>0)}})()},[y,L,i]),ze.useEffect(()=>{if(!L){se(!1),te([]);return}fetch("/api/tts/say/status").then(de=>de.json()).then(de=>{if(se(de.available),de.voices){const He=de.voices.filter((st,qe,et)=>et.findIndex(rt=>rt.name===st.name)===qe).sort((st,qe)=>st.name.localeCompare(qe.name));te(He)}}).catch(()=>{se(!1)})},[L]);const pe=ze.useCallback(async()=>{if(je){je.pause(),je.currentTime=0,Se(null),Ne(!1);return}Ne(!0);try{const de=await fetch("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:b}),voice:b,rate:Math.round(100+(c-.5)*200)})});if(!de.ok)throw new Error("Preview failed");const He=await de.blob(),st=URL.createObjectURL(He),qe=new Audio(st);qe.onended=()=>{URL.revokeObjectURL(st),Se(null),Ne(!1)},qe.onerror=()=>{URL.revokeObjectURL(st),Se(null),Ne(!1)},Se(qe),await qe.play()}catch{Ne(!1)}},[b,c,je,t]);ze.useEffect(()=>()=>{je&&je.pause()},[je]);const Oe=ze.useCallback(async()=>{if(Ue){Ue.pause(),Ue.currentTime=0,q(null),Me(!1);return}Me(!0);try{const de=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:g}),voice:g,speed:c,apiKey:y||void 0})});if(!de.ok){const et=await de.json().catch(()=>({error:"Unknown error"}));throw new Error(et.error||`HTTP ${de.status}`)}const He=await de.blob(),st=URL.createObjectURL(He),qe=new Audio(st);qe.onended=()=>{URL.revokeObjectURL(st),q(null),Me(!1)},qe.onerror=()=>{URL.revokeObjectURL(st),q(null),Me(!1)},q(qe),await qe.play()}catch{Me(!1)}},[g,c,Ue,y,t]);ze.useEffect(()=>()=>{Ue&&Ue.pause()},[Ue]);const nt=ze.useCallback(async()=>{if(Pe){Pe.pause(),Pe.currentTime=0,he(null),Le(!1);return}if(D.trim()){Le(!0);try{const de=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:S,model:E||void 0,speed:c,baseURL:D})});if(!de.ok){const et=await de.json().catch(()=>({error:"Unknown error"}));throw new Error(et.error||`HTTP ${de.status}`)}const He=await de.blob(),st=URL.createObjectURL(He),qe=new Audio(st);qe.onended=()=>{URL.revokeObjectURL(st),he(null),Le(!1)},qe.onerror=()=>{URL.revokeObjectURL(st),he(null),Le(!1)},he(qe),await qe.play()}catch{Le(!1)}}},[D,S,E,c,Pe,t]);ze.useEffect(()=>()=>{Pe&&Pe.pause()},[Pe]);const Re="flex-1 min-w-0 h-1.5 bg-[var(--interactive-border)] rounded-full appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:border-0 disabled:opacity-50";return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.voiceSetup")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":L,onClick:()=>V(!L),onKeyDown:de=>{(de.key===" "||de.key==="Enter")&&(de.preventDefault(),V(!L))},children:[s.jsx(fs,{checked:L,onChange:V,ariaLabel:t("settings.voice.page.field.enableVoiceModeAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.enableVoiceMode")})]}),L&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.provider")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.browser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:"OpenAI:"})," ",t("settings.voice.page.tooltip.openai")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.custom")})," ",t("settings.voice.page.tooltip.custom")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.say")})," ",t("settings.voice.page.tooltip.say")]})]})})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(be,{variant:"chip",size:"xs","aria-pressed":i==="browser",onClick:()=>o("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":i==="openai",onClick:()=>o("openai"),className:"!font-normal",children:"OpenAI"}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":i==="openai-compatible",onClick:()=>o("openai-compatible"),className:"!font-normal",children:t("settings.voice.page.provider.custom")}),ce&&s.jsxs(be,{variant:"chip",size:"xs","aria-pressed":i==="say",onClick:()=>o("say"),className:"!font-normal",children:[s.jsx(I,{name:"apple",className:"w-3.5 h-3.5 mr-0.5"}),t("settings.voice.page.provider.say")]})]})]})}),i==="openai"&&s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:me("typography-ui-label text-foreground",!De&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:me("typography-meta ml-2",De?"text-muted-foreground":"text-[var(--status-error)]/80"),children:t(De&&!y?"settings.voice.page.field.apiKeyHintUsingConfig":De?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"password",value:y,onChange:de=>k(de.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),y&&s.jsx("button",{type:"button",onClick:()=>k(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"w-3.5 h-3.5"})})]})]}),i==="openai-compatible"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:me("typography-ui-label text-foreground",!D.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.serverUrlHint")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"text",value:D,onChange:de=>j(de.target.value),placeholder:"http://localhost:8880/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),D&&s.jsx("button",{type:"button",onClick:()=>j(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.model")}),s.jsx("div",{className:"relative mt-1.5 max-w-xs",children:s.jsx("input",{type:"text",value:E,onChange:de=>P(de.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.voice")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.voiceIdentifierHint")}),s.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[s.jsx("div",{className:"relative max-w-xs flex-1",children:s.jsx("input",{type:"text",value:S,onChange:de=>A(de.target.value),placeholder:"af_sky",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})}),s.jsx(be,{size:"xs",variant:"ghost",onClick:nt,title:t("settings.voice.page.actions.preview"),disabled:!D.trim(),children:Ie?s.jsx(I,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(I,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.voice")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[i==="openai"&&De&&s.jsxs(s.Fragment,{children:[s.jsxs(ds,{value:g,onValueChange:w,children:[s.jsx(us,{className:"w-fit",children:s.jsx(bs,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(ms,{children:yC.map(de=>s.jsx(Lt,{value:de.value,children:de.label},de.value))})]}),s.jsx(be,{size:"xs",variant:"ghost",onClick:Oe,title:t("settings.voice.page.actions.preview"),children:ge?s.jsx(I,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(I,{name:"play",className:"w-3.5 h-3.5"})})]}),i==="openai-compatible"&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.voice.page.field.configuredAbove")}),i==="say"&&ce&&oe.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(ds,{value:b,onValueChange:h,children:[s.jsx(us,{className:"w-fit",children:s.jsx(bs,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(ms,{children:oe.map(de=>s.jsx(Lt,{value:de.name,children:de.name},de.name))})]}),s.jsx(be,{size:"xs",variant:"ghost",onClick:pe,title:t("settings.voice.page.actions.preview"),children:ke?s.jsx(I,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(I,{name:"play",className:"w-3.5 h-3.5"})})]}),i==="browser"&&we.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(ds,{value:v||"$auto",onValueChange:de=>x(de==="$auto"?"":de),children:[s.jsx(us,{className:"w-fit max-w-[200px]",children:s.jsx(bs,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"$auto",children:t("settings.voice.page.field.auto")}),we.map(de=>s.jsxs(Lt,{value:de.name,children:[de.name," (",de.lang,")"]},de.name))]})]}),s.jsx(be,{size:"xs",variant:"ghost",onClick:Qe,title:t("settings.voice.page.actions.preview"),children:Ce?s.jsx(I,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(I,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.speechRate")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:c,onChange:de=>d(Number(de.target.value)),disabled:!n,className:Re}),s.jsx(xn,{value:c,onValueChange:d,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.speechPitch")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:p,onChange:de=>m(Number(de.target.value)),disabled:!n,className:Re}),s.jsx(xn,{value:p,onValueChange:m,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.speechVolume")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:u,onChange:de=>f(Number(de.target.value)),disabled:!n,className:Re}),e?s.jsx(xn,{value:Math.round(u*100),onValueChange:de=>f(de/100),min:0,max:100,step:10,className:"w-16 tabular-nums"}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(u*100),"%"]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.language")}),s.jsx("div",{className:"flex items-center gap-2 w-fit",children:s.jsxs(ds,{value:r,onValueChange:a,disabled:!n,children:[s.jsx(us,{className:"w-fit",children:s.jsx(bs,{placeholder:t("settings.voice.page.field.selectLanguagePlaceholder")})}),s.jsx(ms,{children:xC.map(de=>s.jsx(Lt,{value:de.value,children:de.label},de.value))})]})})]})]})]})]}),L&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.speechRecognition")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.provider")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.sttBrowser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.server")})," ",t("settings.voice.page.tooltip.sttServer")]})]})})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(be,{variant:"chip",size:"xs","aria-pressed":N==="browser",onClick:()=>T("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":N==="server",onClick:()=>T("server"),className:"!font-normal",children:t("settings.voice.page.provider.server")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":N==="wasm",onClick:()=>T("wasm"),className:"!font-normal",children:t("settings.voice.page.provider.wasm")})]})]})}),N==="server"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":Y,onClick:()=>le(!Y),onKeyDown:de=>{(de.key===" "||de.key==="Enter")&&(de.preventDefault(),le(!Y))},children:[s.jsx(fs,{checked:Y,onChange:le,ariaLabel:t("settings.voice.page.field.transcribeOnStopAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.transcribeOnStop")})]}),!ay.isSupported()&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:t("settings.voice.page.field.sttBrowserSupportError")}),s.jsxs("div",{children:[s.jsx("span",{className:me("typography-ui-label text-foreground",!M.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.sttServerUrlHint")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"text",value:M,onChange:de=>R(de.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),M&&s.jsx("button",{type:"button",onClick:()=>R(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.model")}),s.jsx("div",{className:"relative mt-1.5 max-w-xs",children:s.jsx("input",{type:"text",value:O,onChange:de=>z(de.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.language")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.sttLanguageHint")}),s.jsx("div",{className:"relative mt-1.5 max-w-[8rem]",children:s.jsx("input",{type:"text",value:_,onChange:de=>Q(de.target.value),placeholder:"auto",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"flex items-center gap-8 py-0.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.silenceThreshold")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:-60,max:-20,step:1,value:W,onChange:de=>ne(Number(de.target.value)),className:Re}),s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3.5rem] text-right",children:[W," dB"]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-0.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.silenceHold")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:500,max:3e3,step:100,value:re,onChange:de=>ue(Number(de.target.value)),className:Re}),s.jsx(xn,{value:re,onValueChange:ue,min:500,max:3e3,step:100,className:"w-20 tabular-nums"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.voice.page.field.millisecondsUnit")})]})]})]}),N==="wasm"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:t("settings.voice.page.stt.wasmModel")}),s.jsxs(ds,{value:B,onValueChange:$,children:[s.jsx(us,{className:"mt-0.5",children:s.jsx(bs,{placeholder:t("settings.voice.page.stt.wasmModel")})}),s.jsx(ms,{children:Mu.map(de=>s.jsx(Lt,{value:de.id,children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{children:de.name}),s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[de.size," · ",de.languages]})]})},de.id))})]}),s.jsx("p",{className:"typography-ui-compact text-muted-foreground mt-0.5",children:Mu.find(de=>de.id===B)?.description})]}),s.jsx(bC,{modelId:B})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.playbackAndSummary")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":C,onClick:()=>J(!C),onKeyDown:de=>{(de.key===" "||de.key==="Enter")&&(de.preventDefault(),J(!C))},children:[s.jsx(fs,{checked:C,onChange:J,ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.messageReadAloudButton")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":K,onClick:()=>X(!K),onKeyDown:de=>{(de.key===" "||de.key==="Enter")&&(de.preventDefault(),X(!K))},children:[s.jsx(fs,{checked:K,onChange:X,ariaLabel:t("settings.voice.page.field.summarizeBeforePlaybackAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.summarizeBeforePlayback")})]}),L&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":U,onClick:()=>ae(!U),onKeyDown:de=>{(de.key===" "||de.key==="Enter")&&(de.preventDefault(),ae(!U))},children:[s.jsx(fs,{checked:U,onChange:ae,ariaLabel:t("settings.voice.page.field.summarizeVoiceModeResponsesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.summarizeVoiceModeResponses")})]}),(K||U)&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.summarizationThreshold")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:50,max:2e3,step:50,value:ve,onChange:de=>ie(Number(de.target.value)),className:Re}),s.jsx(xn,{value:ve,onValueChange:ie,min:50,max:2e3,step:50,className:"w-16 tabular-nums"})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.summaryMaxLength")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:50,max:2e3,step:50,value:fe,onChange:de=>H(Number(de.target.value)),className:Re}),s.jsx(xn,{value:fe,onValueChange:H,min:50,max:2e3,step:50,className:"w-16 tabular-nums"})]})]})]})]}),L&&n&&s.jsx("div",{className:"mt-2 px-2",children:s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[t("settings.voice.page.hint.shiftClickPrefix")," ",s.jsx("kbd",{className:"px-1 py-0.5 mx-0.5 rounded border border-[var(--interactive-border)] bg-background typography-mono text-[10px]",children:"Shift"})," + ",s.jsx("kbd",{className:"px-1 py-0.5 mx-0.5 rounded border border-[var(--interactive-border)] bg-background typography-mono text-[10px]",children:"Click"})," ",t("settings.voice.page.hint.shiftClickSuffix")]})})]})]})};function wC(){Fi.onModelStatusChange=null}const Ec=[{value:"1800000",label:"30m",ms:1800*1e3},{value:"180000",label:"3m",ms:180*1e3},{value:"7200000",label:"2h",ms:7200*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3}],Rc=[{value:"3600000",label:"1h",ms:3600*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"43200000",label:"12h",ms:720*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3},{value:"604800000",label:"1w",ms:10080*60*1e3},{value:"2592000000",label:"30d",ms:720*60*60*1e3}],jC="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",NC="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Wp=[{value:"quick",labelKey:"settings.openchamber.tunnel.option.mode.quick.label",tooltipKey:"settings.openchamber.tunnel.option.mode.quick.tooltip"},{value:"managed-remote",labelKey:"settings.openchamber.tunnel.option.mode.managedRemote.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedRemote.tooltip"},{value:"managed-local",labelKey:"settings.openchamber.tunnel.option.mode.managedLocal.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedLocal.tooltip"}],SC=[".yml",".yaml",".json"],kC="settings.openchamber.tunnel.error.invalidConfigExtension",Ei=t=>{const e=t.trim().toLowerCase();return SC.some(n=>e.endsWith(n))},Cg=t=>t==="cloudflare"?"Cloudflare":t,Kp=t=>{const e=at.c(11),{provider:n}=t;let r;e[0]!==n?(r=Cg(n),e[0]=n,e[1]=r):r=e[1];const a=r,o=n==="cloudflare"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==o?(c=me("size-4 shrink-0",o),e[2]=o,e[3]=c):c=e[3];let d;e[4]!==c?(d=s.jsx(I,{name:"cloud",className:c}),e[4]=c,e[5]=d):d=e[5];let p;e[6]!==a?(p=s.jsx("span",{children:a}),e[6]=a,e[7]=p):p=e[7];let m;return e[8]!==d||e[9]!==p?(m=s.jsxs("span",{className:"flex items-center gap-2",children:[d,p]}),e[8]=d,e[9]=p,e[10]=m):m=e[10],m},ba=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",Hp=(t,e,n)=>t.find(a=>a.ms===e)?.value||n,Gp=t=>{const e=Math.max(0,t),n=Math.floor(e/1e3),r=Math.floor(n/3600),a=Math.floor(n%3600/60),i=n%60;return r>0?`${r}h ${a}m`:a>0?`${a}m ${i}s`:`${i}s`},CC=t=>new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),Xo=t=>{const e=t.trim();if(!e)return"";try{return(e.includes("://")?new URL(e):new URL(`https://${e}`)).hostname.trim().toLowerCase()}catch{return e.toLowerCase()}},IC=t=>{if(!Array.isArray(t))return[];const e=new Set,n=new Set,r=[];for(const a of t){if(!a||typeof a!="object")continue;const i=a,o=typeof i.id=="string"?i.id.trim():"",c=typeof i.name=="string"?i.name.trim():"",d=Xo(typeof i.hostname=="string"?i.hostname:"");!o||!c||!d||e.has(o)||n.has(d)||(e.add(o),n.add(d),r.push({id:o,name:c,hostname:d}))}return r},PC=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,AC=()=>{const{t}=mt(),e=l.useCallback(xe=>t(xe),[t]),[n,r]=l.useState("checking"),[a,i]=l.useState(null),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(null),[f,b]=l.useState(null),[h,v]=l.useState(!1),[x,g]=l.useState(!1),[w,y]=l.useState(!1),[k,D]=l.useState("cloudflare"),[j,S]=l.useState([]),[A,E]=l.useState("quick"),[P,C]=l.useState(null),[N,T]=l.useState([]),[M,R]=l.useState({}),[O,z]=l.useState(""),[B,$]=l.useState({}),[_,Q]=l.useState(new Set),[W,ne]=l.useState(!1),[re,ue]=l.useState(""),[Y,le]=l.useState(""),[J,L]=l.useState(""),[V,K]=l.useState(1800*1e3),[X,U]=l.useState(480*60*1e3),[ae,ve]=l.useState(""),[ie,fe]=l.useState([]),[H,ce]=l.useState(()=>Date.now()),[se,oe]=l.useState(null),te=t(kC),ke=l.useRef(null),Ne=l.useMemo(()=>P?!Ei(P):!1,[P]),je=l.useMemo(()=>N.find(xe=>xe.id===O)||N[0]||null,[N,O]),Se=l.useMemo(()=>ie.map(xe=>{const Ye=xe.expiresAt<=H,_e=xe.status==="active"&&!Ye,We=_e?Gp(xe.expiresAt-H):xe.inactiveReason==="expired"||Ye?"expired":"inactive",lt=We==="expired"?t("settings.openchamber.tunnel.state.expired"):xe.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),Je=ba(xe.mode);return{...xe,isActive:_e,mode:Je,remainingTextForSession:We,inactiveLabel:lt}}),[H,ie,t]),De=l.useMemo(()=>a?.connectUrl?a.bootstrapExpiresAt===null?!0:a.bootstrapExpiresAt>H:!1,[H,a?.bootstrapExpiresAt,a?.connectUrl]),ye=l.useMemo(()=>!a||n!=="active"&&n!=="stopping"?!1:o===A,[o,n,a,A]),ge=l.useMemo(()=>!a||n!=="active"||!o?!1:o!==A,[o,n,a,A]),Me=l.useMemo(()=>{if(typeof se=="number"&&Number.isFinite(se)&&se>0)return se;if(typeof window>"u")return null;const xe=Number(window.location.port);return Number.isFinite(xe)&&xe>0?xe:null},[se]),Ue=l.useCallback(async xe=>{await sr(xe)},[]),q=l.useCallback(async xe=>{try{const[Ye,_e,We,lt]=await Promise.all([fetch("/api/openchamber/tunnel/check",{signal:xe}),fetch("/api/openchamber/tunnel/status",{signal:xe}),fetch("/api/config/settings",{signal:xe,headers:{Accept:"application/json"}}),fetch("/api/openchamber/tunnel/providers",{signal:xe})]),Je=await Ye.json(),Ve=await _e.json(),yt=We.ok?await We.json():{},$t=lt.ok?await lt.json():{},Gt=Ve.ttlConfig?.bootstrapTtlMs??(yt?.tunnelBootstrapTtlMs===null?null:typeof yt?.tunnelBootstrapTtlMs=="number"?yt.tunnelBootstrapTtlMs:1800*1e3),ss=typeof Ve.ttlConfig?.sessionTtlMs=="number"?Ve.ttlConfig.sessionTtlMs:typeof yt?.tunnelSessionTtlMs=="number"?yt.tunnelSessionTtlMs:480*60*1e3,wt=ba(Ve.mode??yt?.tunnelMode),Dt=typeof yt?.tunnelProvider=="string"&&yt.tunnelProvider.trim().length>0?yt.tunnelProvider.trim().toLowerCase():"cloudflare",Xt=typeof yt?.managedLocalTunnelConfigPath=="string"&&yt.managedLocalTunnelConfigPath.trim()||null,Yt=IC(Ve?.managedRemoteTunnelPresets),ts=typeof Ve.managedRemoteTunnelHostname=="string"?Ve.managedRemoteTunnelHostname:"",dt=Yt.length>0?Yt:ts?[{id:`legacy-${Xo(ts)}`,name:ts,hostname:Xo(ts)}]:[],Rt=dt[0]?.id||"";if(K(Gt),U(ss),D(Dt),S(Array.isArray($t?.providers)?$t.providers:[]),E(wt),C(Xt),T(dt),z(Rt),fe(Array.isArray(Ve.activeSessions)?Ve.activeSessions:[]),c(Ve.activeTunnelMode?ba(Ve.activeTunnelMode):Ve.active&&Ve.mode?ba(Ve.mode):null),Q(new Set(Array.isArray(Ve.managedRemoteTunnelTokenPresetIds)?Ve.managedRemoteTunnelTokenPresetIds:[])),oe(typeof Ve.localPort=="number"?Ve.localPort:null),Ve.active&&Ve.url){i({url:Ve.url,connectUrl:null,bootstrapExpiresAt:typeof Ve.bootstrapExpiresAt=="number"?Ve.bootstrapExpiresAt:null}),r("active");return}r(Je.available?"idle":"not-available")}catch{xe.aborted||(r("error"),u(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[t]);l.useEffect(()=>{const xe=new AbortController;return q(xe.signal),()=>xe.abort()},[q]),l.useEffect(()=>{if(!a?.connectUrl){p(null);return}let xe=!1;return Ax.toDataURL(a.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(Ye=>{xe||p(Ye)}).catch(()=>{xe||p(null)}),()=>{xe=!0}},[a?.connectUrl]),l.useEffect(()=>{if(!a?.bootstrapExpiresAt){ve(t("settings.openchamber.tunnel.state.noExpiry"));return}let xe=null,Ye=Date.now();const _e=()=>{const Je=a.bootstrapExpiresAt?a.bootstrapExpiresAt-Date.now():0;Je<=0?ve(t("settings.openchamber.tunnel.state.expired")):ve(Gp(Je))},We=()=>{const Je=Date.now();Je-Ye>=1e3&&(_e(),Ye=Je),xe=requestAnimationFrame(We)};_e(),(typeof document>"u"||document.visibilityState==="visible")&&(xe=requestAnimationFrame(We));const lt=()=>{document.visibilityState==="visible"&&xe===null?xe=requestAnimationFrame(We):document.visibilityState!=="visible"&&xe!==null&&(cancelAnimationFrame(xe),xe=null)};return document.addEventListener("visibilitychange",lt),()=>{document.removeEventListener("visibilitychange",lt),xe!==null&&cancelAnimationFrame(xe)}},[t,a?.bootstrapExpiresAt]),l.useEffect(()=>{let xe=null,Ye=Date.now();const _e=()=>{const lt=Date.now();lt-Ye>=1e3&&(ce(lt),Ye=lt),xe=requestAnimationFrame(_e)};(typeof document>"u"||document.visibilityState==="visible")&&(xe=requestAnimationFrame(_e));const We=()=>{document.visibilityState==="visible"&&xe===null?xe=requestAnimationFrame(_e):document.visibilityState!=="visible"&&xe!==null&&(cancelAnimationFrame(xe),xe=null)};return document.addEventListener("visibilitychange",We),()=>{document.removeEventListener("visibilitychange",We),xe!==null&&cancelAnimationFrame(xe)}},[]),l.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let xe=!1;const Ye=async()=>{try{const We=await fetch("/api/openchamber/tunnel/status");if(!We.ok||xe)return;const lt=await We.json();if(xe)return;fe(Array.isArray(lt.activeSessions)?lt.activeSessions:[]),Q(new Set(Array.isArray(lt.managedRemoteTunnelTokenPresetIds)?lt.managedRemoteTunnelTokenPresetIds:[])),oe(typeof lt.localPort=="number"?lt.localPort:null)}catch{}},_e=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Ye()},5e3);return()=>{xe=!0,window.clearInterval(_e)}},[n]);const Ie=l.useCallback(async xe=>{y(!0);try{await Ms(xe),Object.prototype.hasOwnProperty.call(xe,"tunnelMode")&&xe.tunnelMode&&E(xe.tunnelMode),Object.prototype.hasOwnProperty.call(xe,"tunnelProvider")&&typeof xe.tunnelProvider=="string"&&D(xe.tunnelProvider),Object.prototype.hasOwnProperty.call(xe,"managedLocalTunnelConfigPath")&&C(xe.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(xe,"managedRemoteTunnelPresets")&&xe.managedRemoteTunnelPresets&&T(xe.managedRemoteTunnelPresets)}catch{G.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{y(!1)}},[t]),Le=l.useCallback(async(xe,Ye)=>{g(!0);try{await Ms({tunnelBootstrapTtlMs:xe,tunnelSessionTtlMs:Ye})}catch{G.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{g(!1)}},[t]),Pe=l.useCallback(async xe=>{const Ye=xe.token.trim();if(Ye)try{const _e={...B,[xe.presetId]:Ye};await Ms({managedRemoteTunnelPresetTokens:_e}),Q(We=>{const lt=new Set(We);return lt.add(xe.presetId),lt})}catch{G.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[B,t]),he=l.useCallback(async xe=>{b(null),u(null),await Ie({tunnelProvider:xe})},[Ie]),F=l.useCallback(async()=>{const xe=await Zf({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(xe.success&&typeof xe.path=="string"&&xe.path.trim().length>0){const Ye=xe.path.trim();if(!Ei(Ye)){G.error(te);return}C(Ye),await Ie({managedLocalTunnelConfigPath:Ye});return}ke.current?.click()},[te,Ie]),ee=l.useCallback(xe=>{const Ye=xe.trim();C(Ye.length>0?Ye:null)},[]),Ce=l.useCallback(async()=>{if(P&&!Ei(P)){G.error(te);return}await Ie({managedLocalTunnelConfigPath:P})},[te,P,Ie]),Fe=l.useCallback(async()=>{C(null),await Ie({managedLocalTunnelConfigPath:null})},[Ie]),we=l.useCallback(async xe=>{const Ye=xe.target.files?.[0];if(!Ye)return;const _e=Ye.name.trim();if(_e.length!==0){if(!Ei(_e)){G.error(te);return}C(_e),await Ie({managedLocalTunnelConfigPath:_e}),xe.target.value=""}},[te,Ie]),Qe=l.useCallback(async()=>{if(u(null),b(null),A==="managed-local"&&P&&!Ei(P)){u(te),G.error(te);return}r("starting");try{let xe="",Ye="";if(A==="managed-remote"){if(!je){r("idle"),b(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),G.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}xe=je.hostname,Ye=(B[je.id]||"").trim(),await Ie({tunnelMode:"managed-remote",managedRemoteTunnelPresets:N})}const _e=await fetch("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:k,mode:A,...A==="managed-remote"&&je?{managedRemoteTunnelPresetId:je.id,managedRemoteTunnelPresetName:je.name}:{},...A==="managed-remote"&&xe?{managedRemoteTunnelHostname:xe}:{},...A==="managed-remote"&&Ye?{managedRemoteTunnelToken:Ye}:{},...A==="managed-local"&&P?{configPath:P}:{}})}),We=await _e.json();if(!_e.ok||!We.ok){if(A==="managed-remote"&&typeof We.error=="string"&&We.error.includes("Managed remote tunnel token is required")){r("idle"),b(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),G.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),u(We.error||t("settings.openchamber.tunnel.toast.startFailed")),G.error(We.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const lt=typeof We.url=="string"?We.url:"";if(!lt){r("error"),u(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),G.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(i({url:lt,connectUrl:typeof We.connectUrl=="string"?We.connectUrl:null,bootstrapExpiresAt:typeof We.bootstrapExpiresAt=="number"?We.bootstrapExpiresAt:null}),c(We.activeTunnelMode?ba(We.activeTunnelMode):We.mode?ba(We.mode):A),fe(Array.isArray(We.activeSessions)?We.activeSessions:[]),Array.isArray(We.managedRemoteTunnelTokenPresetIds)&&Q(new Set(We.managedRemoteTunnelTokenPresetIds)),typeof We.localPort=="number"&&oe(We.localPort),typeof We.mode=="string"&&E(ba(We.mode)),r("active"),We.replacedTunnel){const Je=typeof We.revokedBootstrapCount=="number"?We.revokedBootstrapCount:0,Ve=typeof We.invalidatedSessionCount=="number"?We.invalidatedSessionCount:0;Je===1&&Ve===1?G.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):Je===1?G.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:Ve})):Ve===1?G.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:Je})):G.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:Je,invalidatedSessionCount:Ve}))}else G.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.startFailed")),G.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[te,N,Ie,je,B,t,k,A,P]),pe=l.useCallback(async()=>{r("stopping");try{await fetch("/api/openchamber/tunnel/stop",{method:"POST"});const xe=await fetch("/api/openchamber/tunnel/status");if(xe.ok){const Ye=await xe.json();fe(Array.isArray(Ye.activeSessions)?Ye.activeSessions:[]),Q(new Set(Array.isArray(Ye.managedRemoteTunnelTokenPresetIds)?Ye.managedRemoteTunnelTokenPresetIds:[])),oe(typeof Ye.localPort=="number"?Ye.localPort:null)}i(null),c(null),p(null),r("idle"),G.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.stopFailed")),G.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),Oe=l.useCallback(async()=>{if(a?.connectUrl)try{await navigator.clipboard.writeText(a.connectUrl),v(!0),G.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>v(!1),2e3)}catch{G.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,a?.connectUrl]),nt=l.useCallback(async xe=>{const Ye=Ec.find(_e=>_e.value===xe);Ye&&(K(Ye.ms),await Le(Ye.ms,X))},[Le,X]),Re=l.useCallback(async xe=>{const Ye=Rc.find(_e=>_e.value===xe);!Ye||Ye.ms===null||(U(Ye.ms),await Le(V,Ye.ms))},[V,Le]),de=l.useCallback(async xe=>{b(null),u(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await Ie({tunnelMode:xe,managedRemoteTunnelPresets:N})},[N,Ie,n]),He=l.useCallback(async(xe,Ye)=>{try{await Ms({managedRemoteTunnelPresets:Ye})}catch{G.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),st=l.useCallback(xe=>{const Ye=N.find(_e=>_e.id===xe);Ye&&(z(Ye.id),b(null),He(Ye,N))},[N,He]),qe=l.useCallback(async()=>{const xe=re.trim(),Ye=Xo(Y),_e=J.trim();if(!xe){G.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!Ye){G.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!_e){G.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(N.some(Je=>Je.hostname===Ye)){G.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const We={id:PC(),name:xe,hostname:Ye},lt=[...N,We];T(lt),z(We.id),R(Je=>({...Je,[We.id]:!0})),$(Je=>({...Je,[We.id]:_e})),b(null),ne(!1),ue(""),le(""),L(""),await Ie({tunnelMode:"managed-remote",managedRemoteTunnelPresets:lt,managedRemoteTunnelPresetTokens:{...B,[We.id]:_e}}),await Pe({presetId:We.id,presetName:We.name,hostname:We.hostname,token:_e}),G.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[N,Y,re,J,Pe,Ie,B,t]),et=l.useCallback(async xe=>{const Ye=N.find(Ve=>Ve.id===xe);if(!Ye)return;const _e=N.filter(Ve=>Ve.id!==Ye.id),We=_e[0]?.id||"",lt=O===Ye.id?We:O,Je=Object.fromEntries(Object.entries(B).filter(([Ve,yt])=>Ve!==Ye.id&&yt.trim().length>0));T(_e),z(lt),R(Ve=>{const yt={...Ve};return delete yt[Ye.id],yt}),$(Ve=>{const yt={...Ve};return delete yt[Ye.id],yt}),Q(Ve=>{const yt=new Set(Ve);return yt.delete(Ye.id),yt}),b(null),await Ie({managedRemoteTunnelPresets:_e,managedRemoteTunnelPresetTokens:Je}),G.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[N,Ie,O,B,t]),rt="gap-2 border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)]";return n==="checking"?s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.openchamber.tunnel.state.loading")})}):s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:t("settings.openchamber.tunnel.title")}),s.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/70",children:t("settings.openchamber.tunnel.description")}),s.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/60",children:t("settings.openchamber.tunnel.note.serverSideEnforced")}),s.jsx("p",{className:"typography-meta mt-0 text-muted-foreground/60",children:t("settings.openchamber.tunnel.note.connectLinksOneTime")})]}),Se.length>0&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(I,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:Se.map(xe=>{const Ye=xe.mode==="quick",_e=xe.mode==="managed-remote",We=Ye?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":_e?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",lt=xe.isActive?Ye?"text-[var(--status-warning)]":_e?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",Je=t(Ye?"settings.openchamber.tunnel.badge.quick":_e?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(I,{name:"checkbox-blank-circle-fill",className:me("size-2.5 shrink-0",lt)}),s.jsx("span",{className:me("typography-micro rounded border px-1.5 py-0.5 uppercase",We),children:Je}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:CC(xe.createdAt)})}),s.jsx("span",{className:"typography-meta text-foreground",children:xe.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:xe.remainingTextForSession}):xe.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:xe.inactiveLabel})})]},xe.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(I,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.notAvailable.cloudflaredNotFound")}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:"brew install cloudflared"})]})]})}),n!=="not-available"&&s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(ds,{value:k,onValueChange:xe=>{he(xe)},disabled:w||n==="starting"||n==="stopping",children:[s.jsx(us,{className:"max-w-[16rem]",children:s.jsx(bs,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:Cg(k)})}),s.jsxs(ms,{children:[j.length>0?j.map(xe=>s.jsx(Lt,{value:xe.provider,children:s.jsx(Kp,{provider:xe.provider})},xe.provider)):s.jsx(Lt,{value:"cloudflare",children:s.jsx(Kp,{provider:"cloudflare"})}),s.jsx(Lt,{value:"__more-soon",disabled:!0,children:t("settings.openchamber.tunnel.option.moreProvidersSoon")})]})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Wp.map(xe=>s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(be,{variant:"chip",size:"xs","aria-pressed":A===xe.value,className:"!font-normal",onClick:()=>{de(xe.value)},disabled:w||n==="starting"||n==="stopping",children:e(xe.labelKey)})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:e(xe.tooltipKey)})]},xe.value))})]})]}),s.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(ds,{value:Hp(Ec,V,"1800000"),onValueChange:xe=>{nt(xe)},disabled:x||w||n==="starting"||n==="stopping",children:[s.jsx(us,{className:"max-w-[11rem] min-w-0",children:s.jsx(bs,{className:"truncate"})}),s.jsx(ms,{children:Ec.map(xe=>s.jsx(Lt,{value:xe.value,children:xe.label},xe.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(ds,{value:Hp(Rc,X,"28800000"),onValueChange:xe=>{Re(xe)},disabled:x||w||n==="starting"||n==="stopping",children:[s.jsx(us,{className:"max-w-[11rem] min-w-0",children:s.jsx(bs,{className:"truncate"})}),s.jsx(ms,{children:Rc.map(xe=>s.jsx(Lt,{value:xe.value,children:xe.label},xe.value))})]})]})]}),A==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(I,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.option.mode.quick.tooltip")}),s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),A==="managed-remote"&&s.jsxs("div",{className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Me=="number"&&s.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:s.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTarget")," ",s.jsxs("code",{children:["http://localhost:",Me]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(be,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ne(xe=>!xe),disabled:n==="starting"||n==="stopping"||w,children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),N.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:N.map((xe,Ye)=>{const _e=B[xe.id]||"",We=_.has(xe.id),lt=M[xe.id]??!1;return s.jsx("div",{className:me(Ye<N.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(gr,{open:lt,onOpenChange:Je=>{R(Ve=>({...Ve,[xe.id]:Je})),Je&&st(xe.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(kr,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||w,children:[lt?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("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:xe.name})]}),s.jsx(be,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.openchamber.tunnel.actions.removePresetAria",{name:xe.name}),onClick:()=>{et(xe.id)},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(xr,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-1 px-3 pb-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:xe.hostname})]}),s.jsx(Wt,{type:"password",value:_e,onChange:Je=>{const Ve=Je.target.value;b(null),$(yt=>({...yt,[xe.id]:Ve}))},onBlur:Je=>{const Ve=Je.currentTarget.value.trim();Ve&&Pe({presetId:xe.id,presetName:xe.name,hostname:xe.hostname,token:Ve})},placeholder:t(We?"settings.openchamber.tunnel.field.savedTokenAvailablePlaceholder":"settings.openchamber.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||_e.trim().length===0,onClick:()=>{Pe({presetId:xe.id,presetName:xe.name,hostname:xe.hostname,token:_e})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},xe.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),W&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Wt,{value:re,onChange:xe=>ue(xe.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Wt,{value:Y,onChange:xe=>le(xe.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Wt,{type:"password",value:J,onChange:xe=>L(xe.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),typeof Me=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Me]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{qe()},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ne(!1),ue(""),le(""),L("")},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground/70 hover:text-foreground","aria-label":t("settings.openchamber.tunnel.field.managedRemoteTokenInfoAria"),children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]})]}),!je&&f&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:f})]}),A==="managed-local"&&s.jsx("div",{className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:ke,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:xe=>{we(xe)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Wt,{value:P||"",onChange:xe=>{ee(xe.target.value)},onBlur:()=>{Ce()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||w}),s.jsx(be,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{F()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(I,{name:"folder",className:"size-3.5"})}),P&&s.jsx(be,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{Fe()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(I,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(P?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),Ne&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:te})]})}),!ye&&s.jsxs("div",{className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(I,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[A==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Ue(jC)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(I,{name:"external-link",className:"size-3.5"})]})]}),A==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Ue(NC)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(I,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.startModeAndGenerateLink",{mode:e(Wp.find(xe=>xe.value===A)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),A==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(ds,{value:O||(N[0]?.id??""),onValueChange:xe=>{st(xe)},disabled:w||n==="starting"||n==="stopping"||N.length<=1,children:[s.jsx(us,{children:s.jsx(bs,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:je?.name})}),s.jsx(ms,{fitContent:!0,children:N.map(xe=>s.jsx(Lt,{value:xe.id,children:xe.name},xe.id))})]})]}),ge&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(I,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(be,{size:"sm",variant:"outline",onClick:Qe,disabled:n==="starting"||w||A==="managed-remote"&&!je||A==="managed-local"&&Ne,className:me(rt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),ye&&a&&s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:a.url})]}),De&&a.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:a.connectUrl}),s.jsxs(be,{size:"sm",variant:"ghost",onClick:Oe,className:"shrink-0 gap-1.5",children:[h?s.jsx(I,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(I,{name:"file-copy",className:"size-3.5"}),t(h?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.expires"),": ",a.bootstrapExpiresAt?ae:t("settings.openchamber.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[d?s.jsx("img",{src:d,alt:t("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(be,{size:"sm",variant:"outline",onClick:Qe,disabled:n==="stopping"||w||A==="managed-local"&&Ne,className:rt,children:[s.jsx(I,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(be,{size:"sm",variant:"ghost",onClick:pe,disabled:n==="stopping"||w,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&m&&s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m}),s.jsx(be,{size:"sm",variant:"ghost",onClick:Qe,children:t("settings.openchamber.tunnel.actions.retry")})]})]})},Ig=()=>{const{t}=mt(),[e,n]=ze.useState(""),[r,a]=ze.useState(!0),[i,o]=ze.useState(!1),c=Te(u=>u.showOpenCodeUpdateNotifications),d=Te(u=>u.setShowOpenCodeUpdateNotifications);ze.useEffect(()=>{let u=!1;return(async()=>{try{const f=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!f.ok)return;const b=await f.json().catch(()=>null);if(u||!b)return;const h=typeof b.opencodeBinary=="string"?b.opencodeBinary.trim():"";n(h)}catch{}finally{u||a(!1)}})(),()=>{u=!0}},[]);const p=ze.useCallback(async()=>{if(typeof window>"u"||!yn()||!Ma())return;const u=window.__TAURI__;if(u?.dialog?.open)try{const f=await u.dialog.open({title:t("settings.openchamber.opencodeCli.dialog.selectBinaryTitle"),multiple:!1,directory:!1});typeof f=="string"&&f.trim().length>0&&n(f.trim())}catch{}},[t]),m=ze.useCallback(async()=>{o(!0);try{await Ms({opencodeBinary:e.trim()}),await ai({message:t("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}finally{o(!1)}},[t,e]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.opencodeCli.title")}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(At,{sideOffset:8,className:"max-w-xs",children:[t("settings.openchamber.opencodeCli.tooltipPrefix")," ",s.jsx("code",{className:"font-mono text-xs",children:"opencode"}),t("settings.openchamber.opencodeCli.tooltipSuffix")]})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-3",children:[s.jsx("div",{className:"flex min-w-0 flex-col shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.opencodeCli.field.binaryPath")})}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2 sm:w-[20rem]",children:[s.jsx(Wt,{value:e,onChange:u=>n(u.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:r||i,className:"h-7 min-w-0 flex-1 font-mono text-xs"}),s.jsx(be,{type:"button",variant:"outline",size:"xs",onClick:p,disabled:r||i||!yn()||!Ma(),className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(I,{name:"folder",className:"h-4 w-4"})})]})]}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"typography-micro text-muted-foreground/70",children:[t("settings.openchamber.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.openchamber.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]})}),s.jsxs("label",{className:"flex cursor-pointer items-center gap-2 py-1.5",children:[s.jsx(fs,{checked:c,onChange:d,ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.opencodeCli.field.showUpdateNotifications")})]}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(be,{type:"button",size:"xs",onClick:m,disabled:r||i,className:"shrink-0 !font-normal",children:t(i?"settings.common.actions.saving":"settings.openchamber.opencodeCli.actions.saveAndReload")})})]})]})},Pg=()=>{const{t}=mt(),e=yn()&&Kr(),[n,r]=ze.useState(!1),[a,i]=ze.useState(!1),[o,c]=ze.useState(!0),[d,p]=ze.useState(!1),[m,u]=ze.useState(null),[f,b]=ze.useState(null);ze.useEffect(()=>{if(!e){c(!1);return}let y=!1;return(async()=>{try{const k=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!k.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const D=await k.json().catch(()=>null);if(y)return;const j=D?.desktopLanAccessEnabled===!0;r(j),i(j),u(null)}catch(k){y||u(k instanceof Error?k.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{y||c(!1)}})(),()=>{y=!0}},[e,t]),ze.useEffect(()=>{if(!e||!a){b(null);return}let y=!1;return(async()=>{const k=await iy();y||b(k)})(),()=>{y=!0}},[a,e]);const h=a!==n,v=ze.useMemo(()=>{if(typeof window>"u")return null;const y=Number(window.location.port);return Number.isFinite(y)&&y>0?y:null},[]),x=a&&f&&v?`http://${f}:${v}`:null,g=ze.useCallback(()=>{i(y=>!y)},[]),w=ze.useCallback(async()=>{if(h){p(!0),u(null);try{if(!(await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:a})})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(r(a),!await ih())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(y){u(y instanceof Error?y.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),p(!1)}}},[a,h,t]);return e?s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.desktopNetwork.title")})}),s.jsxs("section",{className:"space-y-2 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:g,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),g())},children:[s.jsx(fs,{checked:a,onChange:g,ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria"),disabled:o||d}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.desktopNetwork.field.allowLanAccess")}),s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription")}),s.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.warning")})]})]}),m?s.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:m}):null,x?s.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[t(h&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:x})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(be,{type:"button",size:"xs",onClick:w,disabled:o||d||!h,className:"shrink-0 !font-normal",children:t(d?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})]}):null},DC=new Set(["shift","control","alt","meta"]),TC=t=>{if(DC.has(t.key.toLowerCase()))return null;const e=[];(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt");const n=ly(t.key);return n?(e.push(n),Xa(e.join("+"))):null},MC=()=>{const t=at.c(58),{t:e}=mt();let n;t[0]!==e?(n=J=>e(J),t[0]=e,t[1]=n):n=t[1];const r=n,a=Te(EC),i=Te(RC),o=Te(FC),c=Te(LC);let d;t[2]===Symbol.for("react.memo_cache_sentinel")?(d=oy(),t[2]=d):d=t[2];const p=d;let m;t[3]!==r?(m=(J,L)=>{const V=`settings.openchamber.keyboardShortcuts.action.${J}.label`,K=r(V);return K===V?L:K},t[3]=r,t[4]=m):m=t[4];const u=m,[f,b]=l.useState(null);let h;t[5]===Symbol.for("react.memo_cache_sentinel")?(h={},t[5]=h):h=t[5];const[v,x]=l.useState(h),[g,w]=l.useState(""),[y,k]=l.useState(""),[D,j]=l.useState(null);let S;t[6]!==a?(S=(J,L)=>{const V=Xa(L);for(const K of p){if(K.id===J)continue;const X=Ur(K.id,a);if(Xa(X)===V)return K.id}return null},t[6]=a,t[7]=S):S=t[7];const A=S;let E;t[8]!==A||t[9]!==i||t[10]!==e?(E=(J,L)=>{const V=Xa(L),K=A(J,V);if(K){j({actionId:J,combo:V,conflictActionId:K}),w("");return}i(J,V),j(null),w(""),k(Eu(V)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(X=>{const U={...X};return delete U[J],U})},t[8]=A,t[9]=i,t[10]=e,t[11]=E):E=t[11];const P=E;let C;t[12]!==D||t[13]!==i||t[14]!==e?(C=()=>{D&&(i(D.conflictActionId,cy),i(D.actionId,D.combo),j(null),w(""),k(Eu(D.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(J=>{const L={...J};return delete L[D.actionId],L}))},t[12]=D,t[13]=i,t[14]=e,t[15]=C):C=t[15];const N=C;let T;t[16]!==o?(T=J=>{o(J),x(L=>{const V={...L};return delete V[J],V}),j(null),w(""),k("")},t[16]=o,t[17]=T):T=t[17];const M=T;let R;t[18]!==e?(R=e("settings.openchamber.keyboardShortcuts.title"),t[18]=e,t[19]=R):R=t[19];let O;t[20]!==R?(O=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:R}),t[20]=R,t[21]=O):O=t[21];let z;t[22]!==c?(z=()=>{c(),x({}),j(null),w(""),k("")},t[22]=c,t[23]=z):z=t[23];let B;t[24]!==e?(B=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),t[24]=e,t[25]=B):B=t[25];let $;t[26]!==z||t[27]!==B?($=s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:z,children:B}),t[26]=z,t[27]=B,t[28]=$):$=t[28];let _;t[29]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(Pt,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[29]=_):_=t[29];let Q;t[30]!==e?(Q=e("settings.openchamber.keyboardShortcuts.tooltip"),t[30]=e,t[31]=Q):Q=t[31];let W;t[32]!==Q?(W=s.jsxs(It,{children:[_,s.jsx(At,{sideOffset:8,className:"max-w-xs",children:Q})]}),t[32]=Q,t[33]=W):W=t[33];let ne;t[34]!==$||t[35]!==W||t[36]!==O?(ne=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[O,$,W]})}),t[34]=$,t[35]=W,t[36]=O,t[37]=ne):ne=t[37];let re;t[38]!==N||t[39]!==g||t[40]!==D||t[41]!==e||t[42]!==y?(re=(g||y||D)&&s.jsxs("div",{className:"mb-2 space-y-2 px-1",children:[D&&s.jsxs("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[s.jsx("span",{className:"typography-meta text-foreground",children:e("settings.openchamber.keyboardShortcuts.overwritePrompt")}),s.jsxs("div",{className:"flex gap-2 shrink-0",children:[s.jsx(be,{type:"button",size:"xs",className:"!font-normal",onClick:N,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),s.jsx(be,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>j(null),children:e("settings.common.actions.cancel")})]})]}),g&&s.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:g}),y&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:y})]}),t[38]=N,t[39]=g,t[40]=D,t[41]=e,t[42]=y,t[43]=re):re=t[43];let ue;t[44]!==u||t[45]!==f||t[46]!==v||t[47]!==M||t[48]!==P||t[49]!==a||t[50]!==e?(ue=p.map((J,L)=>{const V=Ur(J.id,a),K=v[J.id],X=K??V,U=typeof K=="string"&&Xa(K)!==Xa(V);return s.jsxs("div",{className:me("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",L>0&&"border-t border-[var(--surface-subtle)]"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:u(J.id,J.label)})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx(Wt,{readOnly:!0,value:f===J.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):Il(X),onFocus:()=>{b(J.id),w("")},onBlur:()=>{f===J.id&&b(null)},onKeyDown:ae=>{if(ae.preventDefault(),ae.stopPropagation(),ae.key==="Escape"){b(null);return}const ve=TC(ae);ve&&(x(ie=>({...ie,[J.id]:ve})),b(null),j(null),w(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),s.jsx(be,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const ae=v[J.id];if(!ae){w(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}P(J.id,ae)},disabled:!U,children:e("settings.common.actions.saveChanges")}),s.jsx(be,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>M(J.id),children:e("settings.common.actions.reset")})]})]},J.id)}),t[44]=u,t[45]=f,t[46]=v,t[47]=M,t[48]=P,t[49]=a,t[50]=e,t[51]=ue):ue=t[51];let Y;t[52]!==ue?(Y=s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:ue}),t[52]=ue,t[53]=Y):Y=t[53];let le;return t[54]!==ne||t[55]!==re||t[56]!==Y?(le=s.jsxs("div",{className:"mb-8",children:[ne,re,Y]}),t[54]=ne,t[55]=re,t[56]=Y,t[57]=le):le=t[57],le};function EC(t){return t.shortcutOverrides}function RC(t){return t.setShortcutOverride}function FC(t){return t.clearShortcutOverride}function LC(t){return t.resetAllShortcutOverrides}const OC=t=>{const e=at.c(20),{section:n}=t,{isMobile:r}=an();let a;e[0]!==r?(a=r&&aa(),e[0]=r,e[1]=a):a=e[1];const i=a;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=un(),e[2]=o):o=e[2];const c=o;let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=yn()&&Kr(),e[3]=d):d=e[3];const p=d;if(!n){let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(nu,{}),e[4]=h):h=e[4];let v,x,g;e[5]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(kg,{})}),x=!c&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ig,{})}),g=p&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Pg,{})}),e[5]=v,e[6]=x,e[7]=g):(v=e[5],x=e[6],g=e[7]);let w;e[8]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ng,{})}),e[8]=w):w=e[8];let y;e[9]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Sg,{})}),e[9]=y):y=e[9];let k;e[10]!==i?(k=i&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(nC,{})}),e[10]=i,e[11]=k):k=e[11];let D;return e[12]!==k?(D=s.jsx(Es,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-3 p-3 sm:space-y-6 sm:p-6 sm:pt-8",children:[h,v,x,g,w,y,k]})}),e[12]=k,e[13]=D):D=e[13],D}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return s.jsx(BC,{});case"chat":return s.jsx(zC,{});case"sessions":return s.jsx(_C,{});case"shortcuts":return s.jsx($C,{});case"git":return s.jsx(VC,{});case"github":return s.jsx(UC,{});case"notifications":return s.jsx(WC,{});case"voice":return s.jsx(KC,{});case"tunnel":return s.jsx(HC,{});default:return null}},e[14]=n,e[15]=m):m=e[15];const u=m;let f;e[16]!==u?(f=u(),e[16]=u,e[17]=f):f=e[17];let b;return e[18]!==f?(b=s.jsx(Es,{outerClassName:"h-full",className:"w-full",children:s.jsx("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",children:f})}),e[18]=f,e[19]=b):b=e[19],b},$C=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(MC,{}),t[0]=e):e=t[0],e},BC=()=>{const t=at.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=un(),t[0]=e):e=t[0];const n=e;let r;return t[1]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(nu,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat","weekStart","fontSize","terminalFontSize","spacing","inputBarOffset",...n?[]:["terminalQuickKeys"],"reportUsage"]}),t[1]=r):r=t[1],r},zC=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(nu,{visibleSettings:["chatRenderMode","messageTransport","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","expandedTools","stickyUserHeader","wideChatLayout","splitAssistantMessageActions","diffLayout","mobileStatusBar","dotfiles","queueMode","persistDraft","inputSpellcheck"]}),t[0]=e):e=t[0],e},_C=()=>{const t=at.c(7);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=un(),t[0]=e):e=t[0];const n=e;let r;t[1]===Symbol.for("react.memo_cache_sentinel")?(r=yn()&&Kr(),t[1]=r):r=t[1];const a=r;let i,o,c;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(kg,{}),o=!n&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ig,{})}),c=a&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Pg,{})}),t[2]=i,t[3]=o,t[4]=c):(i=t[2],o=t[3],c=t[4]);let d;t[5]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ng,{})}),t[5]=d):d=t[5];let p;return t[6]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsxs("div",{className:"space-y-6",children:[i,o,c,d,s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Sg,{})})]}),t[6]=p):p=t[6],p},VC=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"space-y-6",children:s.jsx(yg,{})}),t[0]=e):e=t[0],e},UC=()=>{const t=at.c(1);if(un())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(vg,{}),t[0]=e):e=t[0],e},WC=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(gC,{}),t[0]=e):e=t[0],e},KC=()=>{const t=at.c(1);if(un())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(vC,{}),t[0]=e):e=t[0],e},HC=()=>{const t=at.c(1);if(un())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(AC,{}),t[0]=e):e=t[0],e},jd=176,Nd=280,qp=8;function Fc(t){return Math.min(Nd,Math.max(jd,t))}const GC=["appearance","chat","notifications","sessions","shortcuts","git","magic-prompts","projects","remote-instances","agents","behavior","commands","mcp","providers","usage","skills.installed","skills.catalog","voice","tunnel"];function qC(t){const e=un(),n=!t&&aa();return{isVSCode:e,isWeb:n,isDesktop:t}}function Yp(t,e){return t.isAvailable?t.isAvailable(e):!0}function ru(t){switch(t){case"projects":return"folders";case"remote-instances":return"server";case"appearance":return"palette";case"chat":return"chat-ai-3";case"magic-prompts":return"ai-generate-2";case"notifications":return"notification-3";case"shortcuts":return"command";case"sessions":return"chat-history";case"providers":return"cloud";case"agents":return"ai-agent";case"behavior":return"brain";case"commands":return"slash-commands-2";case"mcp":return"plug-2";case"skills.installed":return"book-open";case"skills.catalog":return"book";case"git":return"git-branch";case"usage":return"bar-chart-2";case"voice":return"mic";case"tunnel":return"global";case"home":return null;default:return"robot-2"}}const Lc=t=>{const e=at.c(95),{onOpen:n}=t,{t:r}=mt();let a;e[0]!==r?(a=r("settings.view.home.title"),e[0]=r,e[1]=a):a=e[1];let i;e[2]!==a?(i=s.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:a}),e[2]=a,e[3]=i):i=e[3];let o;e[4]!==r?(o=r("settings.view.home.description"),e[4]=r,e[5]=o):o=e[5];let c;e[6]!==o?(c=s.jsx("p",{className:"typography-ui text-muted-foreground",children:o}),e[6]=o,e[7]=c):c=e[7];let d;e[8]!==i||e[9]!==c?(d=s.jsxs("div",{className:"space-y-1",children:[i,c]}),e[8]=i,e[9]=c,e[10]=d):d=e[10];let p;e[11]!==n?(p=()=>n("providers"),e[11]=n,e[12]=p):p=e[12];let m;e[13]===Symbol.for("react.memo_cache_sentinel")?(m=me("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[13]=m):m=e[13];let u;e[14]!==r?(u=r("settings.view.home.cards.providers.title"),e[14]=r,e[15]=u):u=e[15];let f;e[16]!==u?(f=s.jsx("div",{className:"typography-ui-label text-foreground",children:u}),e[16]=u,e[17]=f):f=e[17];let b;e[18]!==r?(b=r("settings.view.home.cards.providers.description"),e[18]=r,e[19]=b):b=e[19];let h;e[20]!==b?(h=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:b}),e[20]=b,e[21]=h):h=e[21];let v;e[22]!==h||e[23]!==p||e[24]!==f?(v=s.jsxs("button",{type:"button",onClick:p,className:m,children:[f,h]}),e[22]=h,e[23]=p,e[24]=f,e[25]=v):v=e[25];let x;e[26]!==n?(x=()=>n("agents"),e[26]=n,e[27]=x):x=e[27];let g;e[28]===Symbol.for("react.memo_cache_sentinel")?(g=me("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[28]=g):g=e[28];let w;e[29]!==r?(w=r("settings.view.home.cards.agents.title"),e[29]=r,e[30]=w):w=e[30];let y;e[31]!==w?(y=s.jsx("div",{className:"typography-ui-label text-foreground",children:w}),e[31]=w,e[32]=y):y=e[32];let k;e[33]!==r?(k=r("settings.view.home.cards.agents.description"),e[33]=r,e[34]=k):k=e[34];let D;e[35]!==k?(D=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:k}),e[35]=k,e[36]=D):D=e[36];let j;e[37]!==x||e[38]!==y||e[39]!==D?(j=s.jsxs("button",{type:"button",onClick:x,className:g,children:[y,D]}),e[37]=x,e[38]=y,e[39]=D,e[40]=j):j=e[40];let S;e[41]!==n?(S=()=>n("skills.catalog"),e[41]=n,e[42]=S):S=e[42];let A;e[43]===Symbol.for("react.memo_cache_sentinel")?(A=me("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[43]=A):A=e[43];let E;e[44]!==r?(E=r("settings.view.home.cards.skillsCatalog.title"),e[44]=r,e[45]=E):E=e[45];let P;e[46]!==E?(P=s.jsx("div",{className:"typography-ui-label text-foreground",children:E}),e[46]=E,e[47]=P):P=e[47];let C;e[48]!==r?(C=r("settings.view.home.cards.skillsCatalog.description"),e[48]=r,e[49]=C):C=e[49];let N;e[50]!==C?(N=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:C}),e[50]=C,e[51]=N):N=e[51];let T;e[52]!==S||e[53]!==P||e[54]!==N?(T=s.jsxs("button",{type:"button",onClick:S,className:A,children:[P,N]}),e[52]=S,e[53]=P,e[54]=N,e[55]=T):T=e[55];let M;e[56]!==n?(M=()=>n("mcp"),e[56]=n,e[57]=M):M=e[57];let R;e[58]===Symbol.for("react.memo_cache_sentinel")?(R=me("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[58]=R):R=e[58];let O;e[59]!==r?(O=r("settings.view.home.cards.mcp.title"),e[59]=r,e[60]=O):O=e[60];let z;e[61]!==O?(z=s.jsx("div",{className:"typography-ui-label text-foreground",children:O}),e[61]=O,e[62]=z):z=e[62];let B;e[63]!==r?(B=r("settings.view.home.cards.mcp.description"),e[63]=r,e[64]=B):B=e[64];let $;e[65]!==B?($=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:B}),e[65]=B,e[66]=$):$=e[66];let _;e[67]!==M||e[68]!==z||e[69]!==$?(_=s.jsxs("button",{type:"button",onClick:M,className:R,children:[z,$]}),e[67]=M,e[68]=z,e[69]=$,e[70]=_):_=e[70];let Q;e[71]!==n?(Q=()=>n("usage"),e[71]=n,e[72]=Q):Q=e[72];let W;e[73]===Symbol.for("react.memo_cache_sentinel")?(W=me("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[73]=W):W=e[73];let ne;e[74]!==r?(ne=r("settings.view.home.cards.usage.title"),e[74]=r,e[75]=ne):ne=e[75];let re;e[76]!==ne?(re=s.jsx("div",{className:"typography-ui-label text-foreground",children:ne}),e[76]=ne,e[77]=re):re=e[77];let ue;e[78]!==r?(ue=r("settings.view.home.cards.usage.description"),e[78]=r,e[79]=ue):ue=e[79];let Y;e[80]!==ue?(Y=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:ue}),e[80]=ue,e[81]=Y):Y=e[81];let le;e[82]!==Q||e[83]!==re||e[84]!==Y?(le=s.jsxs("button",{type:"button",onClick:Q,className:W,children:[re,Y]}),e[82]=Q,e[83]=re,e[84]=Y,e[85]=le):le=e[85];let J;e[86]!==v||e[87]!==j||e[88]!==T||e[89]!==_||e[90]!==le?(J=s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[v,j,T,_,le]}),e[86]=v,e[87]=j,e[88]=T,e[89]=_,e[90]=le,e[91]=J):J=e[91];let L;return e[92]!==J||e[93]!==d?(L=s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl px-6 py-6 space-y-6",children:[d,J]})}),e[92]=J,e[93]=d,e[94]=L):L=e[94],L},YC=t=>{const e=at.c(104),{onClose:n,forceMobile:r,isWindowed:a}=t,{t:i}=mt(),o=an(),c=r??o.isMobile,d=Te(JC),p=Te(QC),m=Te(XC);let u;e[0]!==d?(u=cg(d),e[0]=d,e[1]=u):u=e[1];const f=u,[b,h]=l.useState("nav"),v=l.useRef(null),[x,g]=l.useState(216),[w,y]=l.useState(!1),[k,D]=l.useState(!1),j=l.useRef(0),S=l.useRef(x),A=l.useRef(null);let E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=yn(),e[2]=E):E=e[2];const P=E;let C;e[3]===Symbol.for("react.memo_cache_sentinel")?(C=qC(P),e[3]=C):C=e[3];const N=C;let T;if(e[4]!==c){let Pe;e[6]===Symbol.for("react.memo_cache_sentinel")?(Pe=F=>Yp(F,N),e[6]=Pe):Pe=e[6];let he;e[7]===Symbol.for("react.memo_cache_sentinel")?(he=F=>!(N.isVSCode&&F.slug==="projects"),e[7]=he):he=e[7],T=eu.filter(ZC).filter(Pe).filter(he).filter(F=>!(c&&F.slug==="shortcuts")),e[4]=c,e[5]=T}else T=e[5];const M=T;let R;e[8]===Symbol.for("react.memo_cache_sentinel")?(R=new Map(GC.map(e4)),e[8]=R):R=e[8];const O=R;let z;if(e[9]!==M){let Pe;e[11]===Symbol.for("react.memo_cache_sentinel")?(Pe=(he,F)=>(O.get(he.slug)??999)-(O.get(F.slug)??999),e[11]=Pe):Pe=e[11],z=M.slice().sort(Pe),e[9]=M,e[10]=z}else z=e[10];const B=z,$=Ls(t4);let _,Q;e[12]!==w?(_=()=>{if(typeof window>"u")return;const Pe=()=>{if(!w){const he=Fc(Math.floor(window.innerWidth*.12));g(he)}};return window.addEventListener("resize",Pe),()=>window.removeEventListener("resize",Pe)},Q=[w],e[12]=w,e[13]=_,e[14]=Q):(_=e[13],Q=e[14]),l.useEffect(_,Q);let W,ne;e[15]!==k?(ne=()=>{if(!k)return;const Pe=F=>{const ee=F.clientX-j.current,Ce=Fc(S.current+ee);g(Ce),y(!0)},he=()=>D(!1);return window.addEventListener("pointermove",Pe),window.addEventListener("pointerup",he,{once:!0}),()=>{window.removeEventListener("pointermove",Pe),window.removeEventListener("pointerup",he)}},W=[k],e[15]=k,e[16]=W,e[17]=ne):(W=e[16],ne=e[17]),l.useEffect(ne,W);let re;e[18]!==x?(re=Pe=>{D(!0),j.current=Pe.clientX,S.current=x,Pe.preventDefault()},e[18]=x,e[19]=re):re=e[19];const ue=re;let Y;e[20]!==x?(Y=Pe=>{const he=Pe.shiftKey?qp*4:qp;let F;e:switch(Pe.key){case"ArrowLeft":{F=x-he;break e}case"ArrowRight":{F=x+he;break e}case"Home":{F=jd;break e}case"End":{F=Nd;break e}default:return}Pe.preventDefault(),g(Fc(F)),y(!0)},e[20]=x,e[21]=Y):Y=e[21];const le=Y;let J;e[22]!==p||e[23]!==a||e[24]!==f?(J=()=>{if(!(!p&&!N.isVSCode&&!a)){if(f==="agents"){di.getState().loadAgents();return}if(f==="commands"){_d.getState().loadCommands();return}if(f==="mcp"){to.getState().loadMcpConfigs();return}(f==="skills.installed"||f==="skills.catalog")&&(na.getState().loadSkills(),Pa.getState().loadCatalog())}},e[22]=p,e[23]=a,e[24]=f,e[25]=J):J=e[25];let L;e[26]!==$||e[27]!==p||e[28]!==a||e[29]!==f?(L=[$,p,a,N.isVSCode,f],e[26]=$,e[27]=p,e[28]=a,e[29]=f,e[30]=L):L=e[30],l.useEffect(J,L);let V;e[31]!==c||e[32]!==m?(V=Pe=>{if(m(Pe),v.current=Pe,!c)return;const he=Oi(Pe);if(!he||he.slug==="home"){h("nav");return}h(he.kind==="split"?"page-sidebar":"page-content")},e[31]=c,e[32]=m,e[33]=V):V=e[33];const K=V;let X;e[34]!==f?(X=Oi(f),e[34]=f,e[35]=X):X=e[35];const U=X;let ae;e[36]===Symbol.for("react.memo_cache_sentinel")?(ae={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[36]=ae):ae=e[36];const ve=ae;let ie;e[37]!==i?(ie=Pe=>{switch(Pe){case"projects":return i("settings.page.projects.title");case"remote-instances":return i("settings.page.remoteInstances.title");case"providers":return i("settings.page.providers.title");case"usage":return i("settings.page.usage.title");case"agents":return i("settings.page.agents.title");case"behavior":return i("settings.page.behavior.title");case"commands":return i("settings.page.commands.title");case"mcp":return i("settings.page.mcp.title");case"skills.installed":return i("settings.page.skills.title");case"skills.catalog":return i("settings.page.skillsCatalog.title");case"git":return i("settings.page.git.title");case"appearance":return i("settings.page.appearance.title");case"chat":return i("settings.page.chat.title");case"shortcuts":return i("settings.page.shortcuts.title");case"sessions":return i("settings.page.sessions.title");case"magic-prompts":return i("settings.page.magicPrompts.title");case"notifications":return i("settings.page.notifications.title");case"voice":return i("settings.page.voice.title");case"tunnel":return i("settings.page.tunnel.title");default:return i("settings.view.home.title")}},e[37]=i,e[38]=ie):ie=e[38];const fe=ie;let H;e[39]!==i?(H=()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:i("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:i("settings.view.unavailable.description")})]})}),e[39]=i,e[40]=H):H=e[40];const ce=H,se=s4;let oe;e[41]!==K||e[42]!==ce?(oe=Pe=>{const he=Oi(Pe);if(he&&!Yp(he,N))return ce();switch(Pe){case"home":return s.jsx(Lc,{onOpen:K});case"projects":return s.jsx(j3,{});case"remote-instances":return s.jsx(q3,{});case"agents":return s.jsx(qS,{});case"behavior":return s.jsx(ZS,{});case"commands":return s.jsx(lk,{});case"mcp":return s.jsx(Lk,{});case"skills.installed":return s.jsx(gp,{view:"installed"});case"skills.catalog":return s.jsx(gp,{view:"catalog"});case"providers":return s.jsx(s5,{});case"usage":return s.jsx(v5,{});case"magic-prompts":return s.jsx(k5,{});case"git":return s.jsx(D5,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const F=ve[Pe]??"visual";return s.jsx(OC,{section:F})}default:return s.jsx(Lc,{onOpen:K})}},e[41]=K,e[42]=ce,e[43]=oe):oe=e[43];const te=oe;let ke,Ne;e[44]!==c||e[45]!==b||e[46]!==f?(ke=()=>{if(!c||b!=="nav"||f==="home"||v.current===f)return;const Pe=Oi(f);!Pe||Pe.slug==="home"||(v.current=f,h(Pe.kind==="split"?"page-sidebar":"page-content"))},Ne=[c,b,f],e[44]=c,e[45]=b,e[46]=f,e[47]=ke,e[48]=Ne):(ke=e[47],Ne=e[48]),l.useEffect(ke,Ne);const je=c&&b!=="nav";let Se,De,ye,ge,Me,Ue,q;if(e[49]!==U||e[50]!==fe||e[51]!==c||e[52]!==a||e[53]!==b||e[54]!==n||e[55]!==K||e[56]!==te||e[57]!==f||e[58]!==je||e[59]!==B||e[60]!==i){const Pe=ll();let he;e[68]===Symbol.for("react.memo_cache_sentinel")?(he=()=>{h("nav")},e[68]=he):he=e[68];const F=he;let ee;e[69]===Symbol.for("react.memo_cache_sentinel")?(ee=()=>{h("page-sidebar")},e[69]=ee):ee=e[69];const Ce=ee;let Fe;e[70]!==fe||e[71]!==K||e[72]!==f||e[73]!==B||e[74]!==i?(Fe=()=>s.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden",children:s.jsx("div",{className:"flex flex-col gap-0.5 pt-4 pb-2 px-2",children:B.map(pe=>{const Oe=f===pe.slug,nt=ru(pe.slug);return nt?s.jsx(It,{children:s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>K(pe.slug),"aria-current":Oe?"page":void 0,className:me("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",Oe?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[s.jsx(I,{name:nt,className:"h-4 w-4 shrink-0"}),s.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[s.jsx("span",{className:"typography-ui-label font-normal truncate",children:fe(pe.slug)}),(pe.slug==="voice"||pe.slug==="tunnel")&&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:i("settings.view.badge.beta")})]})]})})},pe.slug):null})})}),s.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:s.jsx("div",{className:"border-t border-border bg-sidebar px-2 py-1 space-y-0.5",children:!N.isVSCode&&s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",className:me("flex h-7 w-full items-center gap-2 rounded-md px-2 overflow-hidden whitespace-nowrap","text-sm font-semibold text-sidebar-foreground/90","hover:text-sidebar-foreground hover:bg-interactive-hover"),onClick:n4,children:[s.jsx(I,{name:"restart",className:"h-4 w-4 shrink-0"}),s.jsx("span",{children:i("settings.view.actions.reloadOpenCode")})]})}),s.jsx(At,{children:i("settings.view.actions.reloadOpenCodeTooltip")})]})})})]}),e[70]=fe,e[71]=K,e[72]=f,e[73]=B,e[74]=i,e[75]=Fe):Fe=e[75],ye=Fe;let we;e[76]!==U||e[77]!==b||e[78]!==te||e[79]!==ye||e[80]!==f?(we=()=>{if(b==="nav")return s.jsx("div",{className:me("flex-1 min-h-0 overflow-hidden",N.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(Xs,{children:ye()})})});if(!U)return s.jsx("div",{className:"flex-1 bg-background"});if(b==="page-sidebar"){if(U.kind!=="split"){const Oe=te(f);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Xs,{children:Oe})})}return s.jsx("div",{className:me("flex-1 min-h-0 overflow-hidden",N.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx(Xs,{children:se(f,{onItemSelect:()=>h("page-content")})})})}const pe=te(f);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Xs,{children:pe})})},e[76]=U,e[77]=b,e[78]=te,e[79]=ye,e[80]=f,e[81]=we):we=e[81],De=we;let Qe;e[82]!==U||e[83]!==K||e[84]!==te||e[85]!==f?(Qe=()=>!U||f==="home"?s.jsx(Lc,{onOpen:K}):U.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:me("w-[264px] min-w-[264px] border-r",N.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:s.jsx(Xs,{children:se(f,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Xs,{children:te(f)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:s.jsx(Xs,{children:te(f)})}),e[82]=U,e[83]=K,e[84]=te,e[85]=f,e[86]=Qe):Qe=e[86],Se=Qe,ge=A,Me="true",e[87]===Symbol.for("react.memo_cache_sentinel")?(Ue=me("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[87]=Ue):Ue=e[87],q=c?s.jsxs("div",{className:me("flex items-center gap-2 px-3 py-2 border-b","bg-background"),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("button",{type:"button",onClick:je?F:n,"aria-label":i(je?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"arrow-left-s",className:"h-5 w-5"})}),s.jsx("div",{className:"min-w-0 flex-1 typography-ui-label font-medium text-foreground truncate",children:b==="nav"?i("settings.view.home.title"):U?fe(U.slug):i("settings.view.home.title")}),b==="page-content"&&U?.kind==="split"&&s.jsx("button",{type:"button",onClick:Ce,"aria-label":i("settings.view.actions.openSectionList"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"list-unordered",className:"h-5 w-5"})}),n&&s.jsx("button",{type:"button",onClick:n,"aria-label":i("settings.view.actions.closeSettings"),title:i("settings.view.actions.closeSettingsWithShortcut",{shortcut:Pe}),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[je&&s.jsx("div",{className:me("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:F,"aria-label":i("settings.view.actions.back"),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"arrow-left-s",className:"h-5 w-5"})})}),n&&s.jsx("div",{className:me("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:n,"aria-label":i("settings.view.actions.closeSettings"),title:i("settings.view.actions.closeSettingsWithShortcut",{shortcut:Pe}),className:"inline-flex h-7 w-7 items-center justify-center rounded-md p-0.5 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"close",className:"h-5 w-5"})})})]}),e[49]=U,e[50]=fe,e[51]=c,e[52]=a,e[53]=b,e[54]=n,e[55]=K,e[56]=te,e[57]=f,e[58]=je,e[59]=B,e[60]=i,e[61]=Se,e[62]=De,e[63]=ye,e[64]=ge,e[65]=Me,e[66]=Ue,e[67]=q}else Se=e[61],De=e[62],ye=e[63],ge=e[64],Me=e[65],Ue=e[66],q=e[67];let Ie;e[88]!==ue||e[89]!==le||e[90]!==c||e[91]!==k||e[92]!==x||e[93]!==Se||e[94]!==De||e[95]!==ye||e[96]!==i?(Ie=s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?De():s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:me("relative flex h-full min-h-0 flex-col overflow-hidden border-r",P?"bg-sidebar":N.isVSCode?"bg-background":"bg-sidebar",k?"":"transition-[width,min-width] duration-200 ease-[cubic-bezier(0.25,0.1,0.25,1)]"),style:{width:`${x}px`,minWidth:`${x}px`,borderColor:"var(--interactive-border)"},children:[s.jsx("div",{className:me("absolute right-0 top-0 z-20 h-full w-[6px] -mr-[3px] cursor-col-resize","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",k?"bg-primary/30":"bg-transparent hover:bg-primary/20"),tabIndex:0,onPointerDown:ue,onKeyDown:le,role:"separator","aria-orientation":"vertical","aria-valuemin":jd,"aria-valuemax":Nd,"aria-valuenow":x,"aria-label":i("settings.view.actions.resizeNavigation")}),s.jsx(Xs,{children:ye()})]}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:Se()})]})}),e[88]=ue,e[89]=le,e[90]=c,e[91]=k,e[92]=x,e[93]=Se,e[94]=De,e[95]=ye,e[96]=i,e[97]=Ie):Ie=e[97];let Le;return e[98]!==ge||e[99]!==Me||e[100]!==Ue||e[101]!==q||e[102]!==Ie?(Le=s.jsxs("div",{ref:ge,"data-settings-view":Me,className:Ue,children:[q,Ie]}),e[98]=ge,e[99]=Me,e[100]=Ue,e[101]=q,e[102]=Ie,e[103]=Le):Le=e[103],Le};function JC(t){return t.settingsPage}function QC(t){return t.isSettingsDialogOpen}function XC(t){return t.setSettingsPage}function ZC(t){return t.slug!=="home"}function e4(t,e){return[t,e]}function t4(t){return t.activeProjectId}function s4(t,e){switch(t){case"projects":return s.jsx(p3,{onItemSelect:e.onItemSelect});case"remote-instances":return s.jsx(F3,{onItemSelect:e.onItemSelect});case"agents":return s.jsx(_S,{onItemSelect:e.onItemSelect});case"commands":return s.jsx(ek,{onItemSelect:e.onItemSelect});case"mcp":return s.jsx(ck,{onItemSelect:e.onItemSelect});case"skills.installed":return s.jsx(Ok,{onItemSelect:e.onItemSelect});case"providers":return s.jsx(Q3,{onItemSelect:e.onItemSelect});case"usage":return s.jsx(r5,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(j5,{onItemSelect:e.onItemSelect});default:return null}}function n4(){ai({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]})}const r4=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:YC,getSettingsNavIcon:ru},Symbol.toStringTag,{value:"Module"})),Sd=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const a=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!a&&!i&&(r=r.replace(/\/+$/,"")),r},a4=()=>{const t=at.c(162),{t:e}=mt(),n=Te(i4),r=Te(o4),a=Te(l4),i=Te(c4),o=Te(d4),c=Te(u4),d=Te(m4),p=Te(p4),m=Te(f4),u=Te(h4),f=Te(g4),b=Te(x4),h=_t(b4),v=_t(y4),x=Ia(v4),g=Ws(w4),w=Ls(j4),y=Lr(),k=$d(N4),{files:D,git:j}=_n(),S=nn(S4),{isMobile:A}=an();let E;t[0]!==y?(E=y?Sd(y):null,t[0]=y,t[1]=E):E=t[1];const P=E,[C,N]=l.useState(""),T=Ml(C,200);let M;t[2]!==T?(M=T.trim(),t[2]=T,t[3]=M):M=t[3];const R=M;let O;t[4]!==C?(O=C.trim(),t[4]=C,t[5]=O):O=t[5];const z=O;let B,$;t[6]!==n?(B=()=>{n&&N("")},$=[n],t[6]=n,t[7]=B,t[8]=$):(B=t[7],$=t[8]),l.useEffect(B,$);let _,Q;t[9]!==x||t[10]!==S||t[11]!==j||t[12]!==n?(_=()=>{if(!n||!j)return;const Je=setTimeout(()=>{const Ve=new Set;for(const yt of x){const $t=_i(yt);!$t||Ve.has($t)||(Ve.add($t),S($t,j))}},0);return()=>clearTimeout(Je)},Q=[n,x,j,S],t[9]=x,t[10]=S,t[11]=j,t[12]=n,t[13]=_,t[14]=Q):(_=t[13],Q=t[14]),l.useEffect(_,Q);let W;t[15]!==r?(W=()=>r(!1),t[15]=r,t[16]=W):W=t[16];const ne=W;let re;t[17]!==ne?(re=Je=>()=>{ne(),Je()},t[17]=ne,t[18]=re):re=t[18];const ue=re;let Y;t[19]!==w?.id||t[20]!==w?.path||t[21]!==g||t[22]!==A||t[23]!==u||t[24]!==h||t[25]!==ue||t[26]!==a||t[27]!==c||t[28]!==i||t[29]!==e||t[30]!==m||t[31]!==p||t[32]!==d?(Y=()=>{const Je=[{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:ue(()=>{a("chat"),c(!1),h()})},{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:ue(k4)},{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:ue(C4)},{id:"toggle-sidebar",title:e(A?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(I,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(A?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:ue(()=>{if(A){const{isSessionSwitcherOpen:Ve}=Te.getState();c(!Ve)}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:ue(()=>p())},{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:ue(()=>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:ue(()=>{g&&u(g)})},{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:ue(()=>i(!0))}];return Td()&&Je.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:ue(()=>{al("desktop_open_draft_mini_chat_window",{directory:Sd(g||w?.path||""),projectId:w?.id??null}).catch(I4)})}),Je},t[19]=w?.id,t[20]=w?.path,t[21]=g,t[22]=A,t[23]=u,t[24]=h,t[25]=ue,t[26]=a,t[27]=c,t[28]=i,t[29]=e,t[30]=m,t[31]=p,t[32]=d,t[33]=Y):Y=t[33],w?.id,w?.path;let le;t[34]!==Y?(le=Y(),t[34]=Y,t[35]=le):le=t[35];const J=le;let L;t[36]===Symbol.for("react.memo_cache_sentinel")?(L=yn(),t[36]=L):L=t[36];const V=L;let K;t[37]===Symbol.for("react.memo_cache_sentinel")?(K={isVSCode:un(),isWeb:!V&&aa(),isDesktop:V},t[37]=K):K=t[37];const X=K;let U;if(t[38]!==ue||t[39]!==i||t[40]!==o){let Je;t[42]===Symbol.for("react.memo_cache_sentinel")?(Je=Ve=>Ve.isAvailable?Ve.isAvailable(X):!0,t[42]=Je):Je=t[42],U=eu.filter(P4).filter(Je).map(Ve=>{const yt=ru(Ve.slug)??"settings-3",$t=(Ve.keywords??[]).join(" ");return{id:`settings:${Ve.slug}`,title:Ve.title,icon:s.jsx(I,{name:yt,className:"mr-2 h-4 w-4"}),searchText:`${Ve.title} ${Ve.group} ${$t}`,onSelect:ue(()=>{o(Ve.slug),i(!0)})}}),t[38]=ue,t[39]=i,t[40]=o,t[41]=U}else U=t[41];const ae=U,ve=A4;let ie;if(t[43]!==x){let Je;t[45]===Symbol.for("react.memo_cache_sentinel")?(Je=(Ve,yt)=>ve(yt)-ve(Ve),t[45]=Je):Je=t[45],ie=[...x].sort(Je),t[43]=x,t[44]=ie}else ie=t[44];const fe=ie,H=oh(),ce=_t(D4);let se;t[46]!==H||t[47]!==ce?(se=(Je,Ve)=>{const yt=ce.get(Je);return yt?.branch?yt.branch.trim()||null:Ve&&H.get(Ve)?.trim()||null},t[46]=H,t[47]=ce,t[48]=se):se=t[48];const oe=se;let te;t[49]===Symbol.for("react.memo_cache_sentinel")?(te=[],t[49]=te):te=t[49];const[ke,Ne]=l.useState(te),[je,Se]=l.useState(!1);let De,ye;t[50]!==P||t[51]!==n||t[52]!==k||t[53]!==R?(De=()=>{if(!n){Ne([]),Se(!1);return}if(!P||R.length===0){Ne([]),Se(!1);return}let Je=!1;return Se(!0),k(P,R,10,{type:"file"}).then(Ve=>{Je||Ne(Ve.map(T4))}).catch(()=>{Je||Ne([])}).finally(()=>{Je||Se(!1)}),()=>{Je=!0}},ye=[n,P,R,k],t[50]=P,t[51]=n,t[52]=k,t[53]=R,t[54]=De,t[55]=ye):(De=t[54],ye=t[55]),l.useEffect(De,ye);const ge=z.length>0;let Me;e:{if(!ge){let Ve;t[56]!==J?(Ve=J.map(M4),t[56]=J,t[57]=Ve):Ve=t[57],Me=Ve;break e}let Je;t[58]!==J||t[59]!==z?(Je=vo(J,z,E4,{limit:7,noFuzzy:!0}),t[58]=J,t[59]=z,t[60]=Je):Je=t[60],Me=Je}const Ue=Me;let q;e:{if(!ge){let Ve;t[61]===Symbol.for("react.memo_cache_sentinel")?(Ve=[],t[61]=Ve):Ve=t[61],q=Ve;break e}let Je;t[62]!==z||t[63]!==ae?(Je=vo(ae,z,R4,{limit:7,noFuzzy:!0}),t[62]=z,t[63]=ae,t[64]=Je):Je=t[64],q=Je}const Ie=q;let Le;e:{if(!ge){let Ve;t[65]!==fe?(Ve=fe.slice(0,5).map(F4),t[65]=fe,t[66]=Ve):Ve=t[66],Le=Ve;break e}let Je;t[67]!==z||t[68]!==fe?(Je=vo(fe,z,L4,{limit:7,threshold:.2}),t[67]=z,t[68]=fe,t[69]=Je):Je=t[69],Le=Je}const Pe=Le;let he;e:{if(!ge||ke.length===0){let Ve;t[70]===Symbol.for("react.memo_cache_sentinel")?(Ve=[],t[70]=Ve):Ve=t[70],he=Ve;break e}let Je;t[71]!==ke||t[72]!==z?(Je=vo(ke,z,O4,{limit:10,threshold:.4}),t[71]=ke,t[72]=z,t[73]=Je):Je=t[73],he=Je}const F=he;let ee,Ce,Fe,we,Qe,pe,Oe,nt,Re,de,He,st,qe,et,rt;if(t[74]!==oe||t[75]!==ne||t[76]!==P||t[77]!==D||t[78]!==ge||t[79]!==n||t[80]!==f||t[81]!==C||t[82]!==Ue||t[83]!==F||t[84]!==Pe||t[85]!==Ie||t[86]!==r||t[87]!==v||t[88]!==b||t[89]!==e){const Je=Ue.map($4),Ve=Ie.map(B4),yt=Pe.map(z4);rt=ge?F.map(_4):[];let $t;e:{if(!ge){$t=["commands","sessions"];break e}const qt=V4,Ge=[{key:"commands",score:qt(Ue)},{key:"settings",score:qt(Ie)},{key:"sessions",score:qt(Pe)},{key:"files",score:qt(F)}];Ge.sort(U4),$t=Ge.map(W4)}const Gt=$t;let ss;t[105]!==ne||t[106]!==v?(ss=qt=>{ne(),v(qt.id,_i(qt))},t[105]=ne,t[106]=v,t[107]=ss):ss=t[107];const wt=ss;let Dt;t[108]!==ne||t[109]!==P||t[110]!==D||t[111]!==f?(Dt=async qt=>{if(!P)return;const Ge=await Xd(D,qt);if(!Ge.ok){G.error(Zd(Ge.reason));return}f(P,qt),ne()},t[108]=ne,t[109]=P,t[110]=D,t[111]=f,t[112]=Dt):Dt=t[112];const Xt=Dt;let Yt;t[113]!==b?(Yt=qt=>Il(Ur(qt,b)),t[113]=b,t[114]=Yt):Yt=t[114];const ts=Yt;we=vs,st=n,qe=r;let dt;t[115]!==e?(dt=e("commandPalette.title"),t[115]=e,t[116]=dt):dt=t[116];let Rt;t[117]!==dt?(Rt=s.jsx(Ss,{children:dt}),t[117]=dt,t[118]=Rt):Rt=t[118];let is;t[119]!==e?(is=e("commandPalette.description"),t[119]=e,t[120]=is):is=t[120];let xs;t[121]!==is?(xs=s.jsx(Fs,{children:is}),t[121]=is,t[122]=xs):xs=t[122],t[123]!==Rt||t[124]!==xs?(et=s.jsxs(As,{className:"sr-only",children:[Rt,xs]}),t[123]=Rt,t[124]=xs,t[125]=et):et=t[125],Fe=ys,de="overflow-hidden p-0",He=!0,Ce=La,Oe=!1,nt="[&_[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 ps;t[126]!==e?(ps=e("commandPalette.input.placeholder"),t[126]=e,t[127]=ps):ps=t[127],t[128]!==C||t[129]!==ps?(Re=s.jsx(oa,{value:C,onValueChange:N,placeholder:ps}),t[128]=C,t[129]=ps,t[130]=Re):Re=t[130],ee=Oa;let ws;t[131]!==e?(ws=e("commandPalette.empty.noResults"),t[131]=e,t[132]=ws):ws=t[132],t[133]!==ws?(Qe=s.jsx($a,{children:ws}),t[133]=ws,t[134]=Qe):Qe=t[134],pe=Gt.map(qt=>qt==="commands"&&Je.length>0?s.jsx(zn,{children:Je.map(Ge=>s.jsxs(Dn,{value:Ge.id,onSelect:Ge.onSelect,children:[Ge.icon,s.jsx("span",{children:Ge.title}),Ge.shortcutId?s.jsx(Mw,{children:ts(Ge.shortcutId)}):null]},Ge.id))},"commands"):qt==="settings"&&Ve.length>0?s.jsx(zn,{children:Ve.map(K4)},"settings"):qt==="sessions"&&yt.length>0?s.jsx(zn,{children:yt.map(Ge=>{const St=Ge.title||e("commandPalette.session.untitled"),Mt=_i(Ge),Nt=oe(Ge.id,Mt);return s.jsxs(Dn,{value:`session:${Ge.id}`,onSelect:()=>wt(Ge),children:[s.jsx(I,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:St}),Nt?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:Nt})]}):null]},Ge.id)})},"sessions"):qt==="files"&&rt.length>0?s.jsx(zn,{children:rt.map(Ge=>{const St=dy(Ge.relativePath||Ge.name,{maxLength:80});return s.jsxs(Dn,{value:`file:${Ge.path}`,onSelect:()=>{Xt(Ge.path)},children:[s.jsx(jr,{filePath:Ge.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":Ge.relativePath,children:St})]},`file:${Ge.path}`)})},"files"):null),t[74]=oe,t[75]=ne,t[76]=P,t[77]=D,t[78]=ge,t[79]=n,t[80]=f,t[81]=C,t[82]=Ue,t[83]=F,t[84]=Pe,t[85]=Ie,t[86]=r,t[87]=v,t[88]=b,t[89]=e,t[90]=ee,t[91]=Ce,t[92]=Fe,t[93]=we,t[94]=Qe,t[95]=pe,t[96]=Oe,t[97]=nt,t[98]=Re,t[99]=de,t[100]=He,t[101]=st,t[102]=qe,t[103]=et,t[104]=rt}else ee=t[90],Ce=t[91],Fe=t[92],we=t[93],Qe=t[94],pe=t[95],Oe=t[96],nt=t[97],Re=t[98],de=t[99],He=t[100],st=t[101],qe=t[102],et=t[103],rt=t[104];let xe;t[135]!==ge||t[136]!==je||t[137]!==e||t[138]!==rt?(xe=ge&&je&&rt.length===0?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[135]=ge,t[136]=je,t[137]=e,t[138]=rt,t[139]=xe):xe=t[139];let Ye;t[140]!==ee||t[141]!==Qe||t[142]!==pe||t[143]!==xe?(Ye=s.jsxs(ee,{children:[Qe,pe,xe]}),t[140]=ee,t[141]=Qe,t[142]=pe,t[143]=xe,t[144]=Ye):Ye=t[144];let _e;t[145]!==Ce||t[146]!==Oe||t[147]!==nt||t[148]!==Re||t[149]!==Ye?(_e=s.jsxs(Ce,{shouldFilter:Oe,className:nt,children:[Re,Ye]}),t[145]=Ce,t[146]=Oe,t[147]=nt,t[148]=Re,t[149]=Ye,t[150]=_e):_e=t[150];let We;t[151]!==Fe||t[152]!==de||t[153]!==He||t[154]!==_e?(We=s.jsx(Fe,{className:de,showCloseButton:He,children:_e}),t[151]=Fe,t[152]=de,t[153]=He,t[154]=_e,t[155]=We):We=t[155];let lt;return t[156]!==we||t[157]!==st||t[158]!==qe||t[159]!==et||t[160]!==We?(lt=s.jsxs(we,{open:st,onOpenChange:qe,children:[et,We]}),t[156]=we,t[157]=st,t[158]=qe,t[159]=et,t[160]=We,t[161]=lt):lt=t[161],lt};function i4(t){return t.isCommandPaletteOpen}function o4(t){return t.setCommandPaletteOpen}function l4(t){return t.setActiveMainTab}function c4(t){return t.setSettingsDialogOpen}function d4(t){return t.setSettingsPage}function u4(t){return t.setSessionSwitcherOpen}function m4(t){return t.toggleSidebar}function p4(t){return t.toggleRightSidebar}function f4(t){return t.toggleBottomTerminal}function h4(t){return t.openContextOverview}function g4(t){return t.openContextFile}function x4(t){return t.shortcutOverrides}function b4(t){return t.openNewSessionDraft}function y4(t){return t.setCurrentSession}function v4(t){return t.activeSessions}function w4(t){return t.currentDirectory}function j4(t){return t.getActiveProject()}function N4(t){return t.searchFiles}function S4(t){return t.ensureStatus}function k4(){lh()}function C4(){Nr.requestDirectoryDialog()}function I4(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function P4(t){return t.slug!=="home"}function A4(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function D4(t){return t.worktreeMetadata}function T4(t){return{path:Sd(t.path),name:t.name,relativePath:t.relativePath}}function M4(t){return{item:t,score:0}}function E4(t){return t.searchText}function R4(t){return t.searchText}function F4(t){return{item:t,score:0}}function L4(t){return t.title||""}function O4(t){return t.name}function $4(t){return t.item}function B4(t){return t.item}function z4(t){return t.item}function _4(t){return t.item}function V4(t){return t.length?t[0].score:1/0}function U4(t,e){return t.score-e.score}function W4(t){return t.key}function K4(t){return s.jsxs(Dn,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const Jp=(t,e,n)=>my(t)?Il(Ur(t,n)):e,H4=()=>{const t=at.c(68),{t:e}=mt(),n=Te(G4),r=Te(q4),a=Te(Y4);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=uy(),t[0]=i):i=t[0];const o=i;let c,d,p,m,u,f,b,h,v;if(t[1]!==n||t[2]!==r||t[3]!==a||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 + ${o} + 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:[`${o} + 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=vs,h=n,v=r,c=ys,f="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let O;t[14]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(I,{name:"settings-3",className:"h-5 w-5"}),t[14]=O):O=t[14];let z;t[15]!==e?(z=e("helpDialog.title"),t[15]=e,t[16]=z):z=t[16];let B;t[17]!==z?(B=s.jsxs(Ss,{className:"flex items-center gap-2",children:[O,z]}),t[17]=z,t[18]=B):B=t[18];let $;t[19]!==e?($=e("helpDialog.description"),t[19]=e,t[20]=$):$=t[20];let _;t[21]!==$?(_=s.jsx(Fs,{children:$}),t[21]=$,t[22]=_):_=t[22],t[23]!==B||t[24]!==_?(b=s.jsxs(As,{children:[B,_]}),t[23]=B,t[24]=_,t[25]=b):b=t[25],u="flex-1 overflow-y-auto mt-3 pr-1",p="space-y-4",m=R.map(Q=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(Q.categoryKey)}),s.jsx("div",{className:"space-y-1",children:Q.items.map(W=>{const ne=W.id?Jp(W.id,Array.isArray(W.keys)?W.keys[0]:W.keys,a):Array.isArray(W.keys)?W.keys:W.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:[W.icon&&s.jsx(I,{name:W.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(W.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(ne)?ne:[ne]).map((re,ue)=>s.jsxs(l.Fragment,{children:[ue>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:re})]},`${re}-${ue}`))})]},W.id||W.descriptionKey)})})]},Q.categoryKey)),t[1]=n,t[2]=r,t[3]=a,t[4]=e,t[5]=c,t[6]=d,t[7]=p,t[8]=m,t[9]=u,t[10]=f,t[11]=b,t[12]=h,t[13]=v}else c=t[5],d=t[6],p=t[7],m=t[8],u=t[9],f=t[10],b=t[11],h=t[12],v=t[13];let x;t[26]!==p||t[27]!==m?(x=s.jsx("div",{className:p,children:m}),t[26]=p,t[27]=m,t[28]=x):x=t[28];let g;t[29]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(I,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[29]=g):g=t[29];let w;t[30]!==e?(w=e("helpDialog.proTips.title"),t[30]=e,t[31]=w):w=t[31];let y;t[32]!==w?(y=s.jsx("p",{className:"font-medium mb-1",children:w}),t[32]=w,t[33]=y):y=t[33];let k;t[34]!==a||t[35]!==e?(k=e("helpDialog.proTips.commandPalette",{shortcut:Jp("open_command_palette",`${o} P`,a)}),t[34]=a,t[35]=e,t[36]=k):k=t[36];let D;t[37]!==k?(D=s.jsxs("li",{children:["• ",k]}),t[37]=k,t[38]=D):D=t[38];let j;t[39]!==e?(j=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=j):j=t[40];let S;t[41]!==j?(S=s.jsxs("li",{children:["• ",j]}),t[41]=j,t[42]=S):S=t[42];let A;t[43]!==e?(A=e("helpDialog.proTips.themeCycling"),t[43]=e,t[44]=A):A=t[44];let E;t[45]!==A?(E=s.jsxs("li",{children:["• ",A]}),t[45]=A,t[46]=E):E=t[46];let P;t[47]!==D||t[48]!==S||t[49]!==E?(P=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[D,S,E]}),t[47]=D,t[48]=S,t[49]=E,t[50]=P):P=t[50];let C;t[51]!==y||t[52]!==P?(C=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[g,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[y,P]})]})}),t[51]=y,t[52]=P,t[53]=C):C=t[53];let N;t[54]!==C||t[55]!==u||t[56]!==x?(N=s.jsxs("div",{className:u,children:[x,C]}),t[54]=C,t[55]=u,t[56]=x,t[57]=N):N=t[57];let T;t[58]!==c||t[59]!==N||t[60]!==f||t[61]!==b?(T=s.jsxs(c,{className:f,children:[b,N]}),t[58]=c,t[59]=N,t[60]=f,t[61]=b,t[62]=T):T=t[62];let M;return t[63]!==d||t[64]!==T||t[65]!==h||t[66]!==v?(M=s.jsx(d,{open:h,onOpenChange:v,children:T}),t[63]=d,t[64]=T,t[65]=h,t[66]=v,t[67]=M):M=t[67],M};function G4(t){return t.isHelpDialogOpen}function q4(t){return t.setHelpDialogOpen}function Y4(t){return t.shortcutOverrides}const J4=()=>{const t=at.c(32),{t:e}=mt(),n=Te(Q4),r=Te(X4),a=Te(Z4);let i;t[0]!==a||t[1]!==e?(i=async()=>{if(!a)return;if((await Rn(a)).ok){G.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}G.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=a,t[1]=e,t[2]=i):i=t[2];const o=i;let c;t[3]!==e?(c=e("openCodeStatusDialog.title"),t[3]=e,t[4]=c):c=t[4];let d;t[5]!==c?(d=s.jsx(Ss,{children:c}),t[5]=c,t[6]=d):d=t[6];let p;t[7]!==e?(p=e("openCodeStatusDialog.description"),t[7]=e,t[8]=p):p=t[8];let m;t[9]!==p?(m=s.jsx(Fs,{children:p}),t[9]=p,t[10]=m):m=t[10];let u;t[11]!==d||t[12]!==m?(u=s.jsxs(As,{children:[d,m]}),t[11]=d,t[12]=m,t[13]=u):u=t[13];let f;t[14]!==e?(f=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=f):f=t[15];let b;t[16]!==o||t[17]!==f?(b=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:o,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:f})}),t[16]=o,t[17]=f,t[18]=b):b=t[18];let h;t[19]!==a||t[20]!==e?(h=a||e("openCodeStatusDialog.empty.noData"),t[19]=a,t[20]=e,t[21]=h):h=t[21];let v;t[22]!==h?(v=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:h}),t[22]=h,t[23]=v):v=t[23];let x;t[24]!==u||t[25]!==b||t[26]!==v?(x=s.jsxs(ys,{className:"max-w-2xl",children:[u,b,v]}),t[24]=u,t[25]=b,t[26]=v,t[27]=x):x=t[27];let g;return t[28]!==n||t[29]!==r||t[30]!==x?(g=s.jsx(vs,{open:n,onOpenChange:r,children:x}),t[28]=n,t[29]=r,t[30]=x,t[31]=g):g=t[31],g};function Q4(t){return t.isOpenCodeStatusDialogOpen}function X4(t){return t.setOpenCodeStatusDialogOpen}function Z4(t){return t.openCodeStatusText}const eI=180,Qp=600,tI=1,sI=6,nI=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],ensureSessionRenderable:r})=>{const a=l.useRef(new Map),i=l.useRef([]),o=l.useRef(new Set),c=l.useCallback(()=>{if(!(typeof window>"u"))for(;o.current.size<tI&&i.current.length>0;){const p=i.current.shift();if(!p)break;_t.getState().currentSessionId!==p&&(Ru(p).renderable||(o.current.add(p),r(p).catch(()=>{}).finally(()=>{o.current.delete(p),c()})))}},[r]),d=l.useCallback(p=>{if(!p||p===t||typeof window>"u"||Ru(p).renderable||o.current.has(p)||i.current.includes(p))return;i.current.length>=sI&&i.current.shift();const m=a.current.get(p);m!==void 0&&window.clearTimeout(m);const u=window.setTimeout(()=>{a.current.delete(p),i.current.push(p),c()},eI);a.current.set(p,u)},[t,c]);l.useEffect(()=>{if(!t||e.length===0)return;const p=window.setTimeout(()=>{const m=e.findIndex(u=>u.id===t);m<0||(d(e[m-1]?.id),d(e[m+1]?.id))},Qp);return()=>window.clearTimeout(p)},[t,d,e]),l.useEffect(()=>{if(!t||n.length===0)return;const p=window.setTimeout(()=>{const m=n.indexOf(t);m<0||(d(n[m-1]),d(n[m+1]))},Qp);return()=>window.clearTimeout(p)},[t,n,d]),l.useEffect(()=>{const p=a.current;return()=>{p.forEach(m=>{clearTimeout(m)}),p.clear(),i.current=[]}},[])};function Xp(t){const{localBranches:e,remoteBranches:n,query:r}=t,a=r.trim();if(!a)return{matching:[],otherLocal:e,otherRemote:n};const i=Fu(e,a,m=>m),o=Fu(n,a,m=>m),c=[],d=i.other,p=o.other;for(const m of i.matching)c.push({label:m,value:m,source:"local"});for(const m of o.matching)c.push({label:m,value:`remotes/${m}`,source:"remote"});return c.sort((m,u)=>{const f=m.label.localeCompare(u.label,void 0,{sensitivity:"accent"});return f!==0?f:m.source!==u.source?m.source.localeCompare(u.source):m.value.localeCompare(u.value)}),{matching:c,otherLocal:d,otherRemote:p}}function rI({open:t,onOpenChange:e,onSelect:n}){const{t:r}=mt(),a=Te(H=>H.isMobile),{github:i}=_n(),o=Hn(H=>H.status),c=Hn(H=>H.hasChecked),d=Te(H=>H.setSettingsDialogOpen),p=Te(H=>H.setSettingsPage),m=Ls(H=>H.getActiveProject()),u=m?.path??null,f=ze.useMemo(()=>u&&m?{id:m.id,path:u}:null,[m,u]),[b,h]=ze.useState("issues"),[v,x]=ze.useState(""),[g,w]=ze.useState([]),[y,k]=ze.useState([]),[D,j]=ze.useState(!1),[S,A]=ze.useState(!1),[E,P]=ze.useState(null),[C,N]=ze.useState(null),[T,M]=ze.useState(null),[R,O]=ze.useState(!1),[z,B]=ze.useState(new Map),[$,_]=ze.useState(1),[Q,W]=ze.useState(!1),ne=ze.useCallback(async()=>{if(!(!u||!i)&&!(c&&o?.connected===!1)){j(!0),P(null),_(1),W(!1);try{if(b==="issues"&&i.issuesList){const H=await i.issuesList(u,{page:1});H.connected===!1?(P(r("session.githubIntegration.error.notConnected")),w([])):(w(H.issues??[]),_(H.page??1),W(!!H.hasMore))}else if(b==="prs"&&i.prsList){const H=await i.prsList(u,{page:1});H.connected===!1?(P(r("session.githubIntegration.error.notConnected")),k([])):(k(H.prs??[]),_(H.page??1),W(!!H.hasMore))}}catch(H){P(H instanceof Error?H.message:r("session.githubIntegration.error.loadDataFailed"))}finally{j(!1)}}},[u,i,c,o,b,r]),re=ze.useCallback(async()=>{if(!(!u||!i)&&!(D||S)&&Q){A(!0);try{const H=$+1;if(b==="issues"&&i.issuesList){const ce=await i.issuesList(u,{page:H});ce.connected!==!1&&(w(se=>[...se,...ce.issues??[]]),_(ce.page??H),W(!!ce.hasMore))}else if(b==="prs"&&i.prsList){const ce=await i.prsList(u,{page:H});ce.connected!==!1&&(k(se=>[...se,...ce.prs??[]]),_(ce.page??H),W(!!ce.hasMore))}}catch{}finally{A(!1)}}},[u,i,b,$,Q,D,S]);ze.useEffect(()=>{if(!t){h("issues"),x(""),w([]),k([]),N(null),M(null),O(!1),P(null),B(new Map),_(1),W(!1);return}ne()},[t,ne]);const ue=ze.useCallback(async H=>{if(!(!f||!H)&&!z.has(H))try{const se=(await ch(f,{mode:"new",branchName:H,worktreeName:H})).errors.find(oe=>oe.code==="branch_in_use");B(oe=>new Map(oe).set(H,{isValid:!se,error:se?r(se.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{B(ce=>new Map(ce).set(H,{isValid:!1,error:r("session.githubIntegration.validation.failed")}))}},[f,z,r]);ze.useEffect(()=>{!t||b!=="prs"||y.forEach(H=>{H.head&&ue(H.head)})},[t,b,y,ue]);const Y=ze.useMemo(()=>{const H=v.trim().toLowerCase();return H?g.filter(ce=>String(ce.number)===H.replace(/^#/,"")?!0:ce.title.toLowerCase().includes(H)):g},[g,v]),le=ze.useMemo(()=>{const H=v.trim().toLowerCase();return H?y.filter(ce=>String(ce.number)===H.replace(/^#/,"")?!0:ce.title.toLowerCase().includes(H)):y},[y,v]),J=c&&o?.connected===!0,L=()=>{p("github"),d(!0)},V=H=>{N(H),M(null)},K=H=>{M(H),N(null)},X=()=>{C?n({type:"issue",item:C}):T&&n({type:"pr",item:T,includeDiff:R}),e(!1)},U=()=>{N(null),M(null),O(!1)},ae=C||T&&z.get(T.head??"")?.isValid!==!1,ve=H=>H.head?z.get(H.head)?.isValid===!1:!0,ie=s.jsx(s.Fragment,{children:J?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"relative mt-2",children:[s.jsx(I,{name:"search",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),s.jsx(Wt,{value:v,onChange:H=>x(H.target.value),placeholder:r(b==="issues"?"session.githubIntegration.search.issuesPlaceholder":"session.githubIntegration.search.prsPlaceholder"),className:"h-8 pl-9"})]}),s.jsx("div",{className:"mt-2 h-[300px] overflow-hidden",children:s.jsxs("div",{className:"h-full overflow-y-auto",children:[D&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx(I,{name:"loader-4",className:"h-5 w-5 animate-spin text-muted-foreground"})}),E&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive",children:[s.jsx(I,{name:"error-warning",className:"h-4 w-4"}),s.jsx("span",{className:"typography-small",children:E})]})}),!D&&!E&&b==="issues"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[Y.length>0?Y.map(H=>s.jsx("button",{onClick:()=>V(H),className:me("w-full text-left px-2 py-1.5 rounded transition-colors",C?.number===H.number?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("span",{className:"text-muted-foreground shrink-0 typography-micro",children:["#",H.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-2",children:H.title}),H.sourceRepo?.source==="upstream"?s.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block",children:[H.sourceRepo.owner,"/",H.sourceRepo.repo]}):null]})]})},`${H.sourceRepo?.owner??""}-${H.sourceRepo?.repo??""}-${H.number}`)):s.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:r("session.githubIntegration.empty.noIssuesFound")}),Q&&!S&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{re()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),S&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),!D&&!E&&b==="prs"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[le.length>0?le.map(H=>{const ce=ve(H),se=H.head?z.get(H.head):void 0;return s.jsx("button",{onClick:()=>!ce&&K(H),disabled:ce,className:me("w-full text-left px-2 py-1.5 rounded transition-colors",T?.number===H.number?"bg-interactive-selection text-interactive-selection-foreground":ce?"opacity-50 cursor-not-allowed":"hover:bg-interactive-hover"),children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("span",{className:"text-muted-foreground shrink-0 typography-micro",children:["#",H.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-1",children:H.title}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[H.head," → ",H.base]}),H.sourceRepo?.source==="upstream"?s.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[H.sourceRepo.owner,"/",H.sourceRepo.repo]}):null,ce&&se?.error&&s.jsx("span",{className:"typography-micro text-destructive",children:se.error})]})]})]})},`${H.sourceRepo?.owner??""}-${H.sourceRepo?.repo??""}-${H.number}`)}):s.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:r("session.githubIntegration.empty.noPullRequestsFound")}),Q&&!S&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{re()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),S&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]})]})})]}):s.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 gap-4",children:[s.jsx(I,{name:"github",className:"h-12 w-12 text-muted-foreground"}),s.jsxs("div",{className:"text-center",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:r("session.githubIntegration.connect.title")}),s.jsx("p",{className:"typography-small text-muted-foreground mt-1",children:r("session.githubIntegration.connect.description")})]}),s.jsx(be,{onClick:L,size:"sm",children:r("session.githubIntegration.connect.action")})]})}),fe=s.jsxs("div",{className:me("w-full",a?"flex flex-col gap-2":"flex flex-row items-center"),children:[s.jsxs("div",{className:me("flex items-center gap-4",a?"w-full justify-center order-1":"flex-1"),children:[!a&&(C||T)&&s.jsxs("div",{className:"flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate max-w-[150px]",children:C?r("session.githubIntegration.selected.issueNumber",{number:C.number}):r("session.githubIntegration.selected.prNumber",{number:T?.number??""})}),s.jsx("button",{onClick:U,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]}),b==="prs"&&T&&s.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[s.jsx(fs,{checked:R,onChange:H=>O(H),ariaLabel:r("session.githubIntegration.includeDiffAria")}),s.jsx("span",{className:"typography-small text-foreground",children:r("session.githubIntegration.includeDiff")})]})]}),s.jsxs("div",{className:me("flex gap-2",a?"w-full order-2":"justify-end"),children:[s.jsx(be,{variant:"outline",size:"sm",onClick:()=>e(!1),className:me(a&&"flex-1"),children:r("session.githubIntegration.actions.cancel")}),s.jsx(be,{size:"sm",onClick:X,disabled:!ae,className:me(a&&"flex-1"),children:r("session.githubIntegration.actions.select")})]})]});return s.jsx(s.Fragment,{children:a?s.jsx(Mr,{open:t,title:r("session.githubIntegration.title"),onClose:()=>e(!1),footer:J?fe:void 0,renderHeader:H=>s.jsxs("div",{className:"flex flex-col gap-2 px-3 py-2 border-b border-border/40",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:r("session.githubIntegration.title")}),H]}),s.jsx("div",{className:"w-full",children:s.jsx(Er,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(I,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:ce=>{h(ce),x("")},variant:"active-pill",layoutMode:"fit"})}),(C||T)&&s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate flex-1",children:C?r("session.githubIntegration.selected.issueNumber",{number:C.number}):r("session.githubIntegration.selected.prNumber",{number:T?.number??""})}),s.jsx("button",{onClick:U,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]})]}),children:ie}):s.jsx(vs,{open:t,onOpenChange:e,children:s.jsxs(ys,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsx(As,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(Ss,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(I,{name:"github",className:"h-5 w-5"}),r("session.githubIntegration.title")]}),s.jsx("div",{className:"w-[220px]",children:s.jsx(Er,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(I,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:H=>{h(H),x("")},variant:"active-pill",layoutMode:"fit"})})]})}),ie,s.jsx(Hs,{className:"mt-1",children:fe})]})})})}const $i=t=>t.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),$n=t=>t.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,"").split("/").join("-").replace(/[^A-Za-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"").slice(0,80),Zp="oc:lastWorktreeSourceBranch",aI=t=>String(t).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",ef=(t,e,n)=>{const r=$i(t.head||"");if(!r)throw new Error("PR head branch is missing");if(e.includes(r))return{existingBranch:r,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:r};const a=n.find(p=>{const m=p.indexOf("/");return m<=0||m>=p.length-1?!1:p.slice(m+1)===r});if(a){const p=a.indexOf("/"),m=a.slice(0,p);return{existingBranch:`remotes/${a}`,setUpstream:!0,upstreamRemote:m,upstreamBranch:r,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${m}/${r}`}}const i=String(t.headLabel||"").split(":")[0]?.trim(),o=t.headRepo?.owner||i||"pr-head",c=`pr-${aI(o)}`,d=t.headRepo?.sshUrl||t.headRepo?.cloneUrl||"";if(!d)throw new Error("PR head repository URL is unavailable");return{existingBranch:`remotes/${c}/${r}`,setUpstream:!0,upstreamRemote:c,upstreamBranch:r,ensureRemoteName:c,ensureRemoteUrl:d,sourceLabel:`${c}/${r}`}},iI=t=>{const e={repo:t.repo??null,issue:t.issue,comments:t.comments};return`GitHub issue context (JSON)
|
|
178
|
+
${JSON.stringify(e,null,2)}`},oI=t=>`GitHub pull request context (JSON)
|
|
179
|
+
${JSON.stringify(t,null,2)}`;function lI({open:t,onOpenChange:e,onWorktreeCreated:n}){const{t:r}=mt(),{github:a,git:i}=_n(),o=Te(pe=>pe.isMobile),c=Hn(pe=>pe.status),d=Hn(pe=>pe.hasChecked),p=Ls(pe=>pe.getActiveProject()),m=p?.path??null,u=ze.useMemo(()=>m&&p?{id:p.id,path:m}:null,[p,m]),[f,b]=ze.useState("new-branch"),[h,v]=ze.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[x,g]=ze.useState({selectedBranch:"",worktreeName:""}),w=Fd(m),y=dh(m),k=nn(pe=>pe.fetchBranches),D=ze.useMemo(()=>w?.all?w.all.filter(pe=>!pe.startsWith("remotes/")).sort():[],[w]),j=ze.useMemo(()=>w?.all?w.all.filter(pe=>pe.startsWith("remotes/")).map(pe=>pe.replace(/^remotes\//,"")).sort():[],[w]),S=_t(pe=>pe.availableWorktreesByProject),A=ze.useMemo(()=>{if(!m)return new Set;const pe=S.get(m)??[];return new Set(pe.map(Oe=>Oe.name))},[S,m]),E=ze.useCallback((pe=10)=>{for(let Oe=0;Oe<pe;Oe++){const nt=nc();if(!A.has(nt))return nt}return`${nc()}-${Date.now().toString(36).slice(-4)}`},[A]),[P,C]=ze.useState(!1),[N,T]=ze.useState(!1),[M,R]=ze.useState(!1),[O,z]=ze.useState(!1),[B,$]=ze.useState(!1),[_,Q]=ze.useState(""),[W,ne]=ze.useState(""),re=ze.useRef(null),ue=ze.useRef(null),Y=ze.useRef(null),le=ze.useRef(null),J=ze.useCallback(pe=>{pe.stopPropagation()},[]),L=ze.useCallback(pe=>{let Oe=pe;for(;Oe&&Oe!==document.body;){const{overflowY:nt}=window.getComputedStyle(Oe);if((nt==="auto"||nt==="scroll")&&Oe.scrollHeight>Oe.clientHeight)return Oe;Oe=Oe.parentElement}return null},[]),V=ze.useCallback(pe=>{pe&&(pe.scrollTop=0)},[]),K=ze.useCallback(pe=>{const Oe=pe.current?.querySelector('[data-slot="command-list"]')??null;V(Oe)},[V]),X=ze.useCallback(pe=>{const Oe=L(pe.current);V(Oe)},[L,V]),U=ze.useMemo(()=>Xp({localBranches:D,remoteBranches:j,query:_}),[D,j,_]),ae=ze.useMemo(()=>Xp({localBranches:D,remoteBranches:j,query:W}),[D,j,W]),ve=_.trim().length>0,ie=W.trim().length>0,fe=U.matching.length>0,H=ae.matching.length>0,ce=!!(m&&i),se=ze.useCallback(()=>{!m||!i||k(m,i)},[m,i,k]);ze.useEffect(()=>{!N&&!O&&Q("")},[N,O]),ze.useEffect(()=>{!M&&!B&&ne("")},[M,B]),ze.useEffect(()=>{N&&K(re),O&&X(Y)},[N,O,_,K,X]),ze.useEffect(()=>{M&&K(ue),B&&X(le)},[M,B,W,K,X]);const[oe,te]=ze.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[ke,Ne]=ze.useState(!1),[je,Se]=ze.useState(null),De=ze.useCallback(()=>{const pe=gt.getState(),Oe=pe.getVisibleAgents();if(pe.settingsDefaultAgent){const nt=Oe.find(Re=>Re.name===pe.settingsDefaultAgent);if(nt)return nt.name}return Oe.find(nt=>nt.name==="build")?.name||Oe[0]?.name},[]),ye=ze.useCallback(()=>{const pe=gt.getState(),Oe=pe.settingsDefaultModel;if(!Oe)return null;const nt=hi(Oe);if(!nt)return null;const{providerId:Re,modelId:de}=nt;return pe.getModelMetadata(Re,de)?{providerID:Re,modelID:de}:null},[]),ge=ze.useCallback((pe,Oe)=>{const nt=gt.getState(),Re=nt.settingsDefaultVariant;if(!Re)return;const st=nt.providers.find(qe=>qe.id===pe)?.models.find(qe=>qe.id===Oe)?.variants;if(st&&Object.prototype.hasOwnProperty.call(st,Re))return Re},[]),Me=ze.useCallback(pe=>{const Oe=gt.getState();try{wo.getState().saveSessionModelSelection(pe.sessionId,pe.providerID,pe.modelID)}catch{}if(pe.agentName){try{Oe.setAgent(pe.agentName)}catch{}try{wo.getState().saveSessionAgentSelection(pe.sessionId,pe.agentName)}catch{}try{wo.getState().saveAgentModelForSession(pe.sessionId,pe.agentName,pe.providerID,pe.modelID)}catch{}if(pe.variant!==void 0){try{Oe.setCurrentVariant(pe.variant)}catch{}try{wo.getState().saveAgentModelVariantForSession(pe.sessionId,pe.agentName,pe.providerID,pe.modelID,pe.variant)}catch{}}}},[]),Ue=ze.useCallback(async pe=>{if(!m||!a)return;const Oe=gt.getState(),nt=Pl.getState().lastUsedProvider,Re=ye(),de=Re?.providerID||Oe.currentProviderId||nt?.providerID,He=Re?.modelID||Oe.currentModelId||nt?.modelID,st=De()||Oe.currentAgentName||void 0;if(!de||!He){G.error(r("session.newWorktree.error.noModelSelected"));return}const qe=ge(de,He);if(Me({sessionId:pe.sessionId,providerID:de,modelID:He,agentName:st,variant:qe}),pe.issue){if(!a.issueGet||!a.issueComments)return;const et=await a.issueGet(m,pe.issue.number);if(et.connected===!1||!et.repo||!et.issue)throw new Error("Failed to load issue context");const rt=await a.issueComments(m,pe.issue.number);if(rt.connected===!1)throw new Error("Failed to load issue comments");const xe=await Nn("github.issue.review.visible",{issue_number:String(pe.issue.number)}),Ye=await Nn("github.issue.review.instructions"),_e=iI({repo:et.repo,issue:et.issue,comments:rt.comments??[]});await rn.sendMessage({id:pe.sessionId,providerID:de,modelID:He,agent:st,variant:qe,text:xe,additionalParts:[{text:Ye,synthetic:!0},{text:_e,synthetic:!0}]}),G.success(r("session.newWorktree.toast.sessionFromIssue"));return}if(pe.pr){if(!a.prContext)return;const et=await a.prContext(m,pe.pr.number,{includeDiff:pe.includeDiff,includeCheckDetails:!1});if(et.connected===!1||!et.repo||!et.pr)throw new Error("Failed to load PR context");const rt=await Nn("github.pr.review.visible",{pr_number:String(pe.pr.number)}),xe=await Nn("github.pr.review.instructions"),Ye=oI(et);await rn.sendMessage({id:pe.sessionId,providerID:de,modelID:He,agent:st,variant:qe,text:rt,additionalParts:[{text:xe,synthetic:!0},{text:Ye,synthetic:!0}]}),G.success(r("session.newWorktree.toast.sessionFromPr"))}},[Me,a,m,De,ye,ge,r]),q=f==="new-branch"?h:x;ze.useEffect(()=>{if(!w?.all||!m||h.sourceBranch)return;(async()=>{try{const Oe=await io(m).catch(()=>null),nt=localStorage.getItem(Zp),Re=nt&&w.all?.includes(nt)?nt:Oe&&w.all?.includes(Oe)?Oe:w.all?.includes("main")?"main":w.all?.includes("master")?"master":w.all?.[0]||"";Re&&v(de=>({...de,sourceBranch:Re}))}catch{}})()},[w,m,h.sourceBranch]),ze.useEffect(()=>{if(!t)return;b("new-branch"),g({selectedBranch:"",worktreeName:""}),T(!1),R(!1),z(!1),$(!1),Q(""),ne(""),te({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const pe=E();v({branchName:pe,worktreeName:pe,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[t,E]),ze.useEffect(()=>{if(f!=="new-branch"||!h.isSyncingWorktreeName)return;const pe=$i(h.branchName),Oe=$n(pe);v(nt=>({...nt,worktreeName:Oe}))},[f,h.branchName,h.isSyncingWorktreeName]);const Ie=ze.useCallback(async()=>{if(!u||!oe.touched||ke)return;je&&je.abort();const pe=new AbortController;Se(pe),te(Oe=>({...Oe,isValidating:!0}));try{const Oe=f==="new-branch"?h.branchName:x.selectedBranch,nt=q.worktreeName,Re=$i(Oe),de=$n(nt);let He=null,st=null;if(Re||(He=r("session.newWorktree.error.branchNameRequired")),de||(st=r("session.newWorktree.error.worktreeDirectoryRequired")),Re&&de){const qe=f==="new-branch"?h.linkedPr:null,et=qe?ef(qe,D,j):null,rt=await ch(u,{mode:f==="existing-branch"||et?"existing":"new",branchName:Re,worktreeName:de,existingBranch:et?.existingBranch??(f==="existing-branch"?Re:void 0),...et?.ensureRemoteName?{ensureRemoteName:et.ensureRemoteName}:{},...et?.ensureRemoteUrl?{ensureRemoteUrl:et.ensureRemoteUrl}:{}});if(pe.signal.aborted)return;rt.ok||rt.errors.forEach(xe=>{if(xe.code==="worktree_exists"){st=st??xe.message;return}xe.code.startsWith("branch_")&&(He=He??xe.message)})}pe.signal.aborted||te(qe=>({...qe,isValidating:!1,branchError:He,worktreeError:st}))}catch{pe.signal.aborted||te(Oe=>({...Oe,isValidating:!1}))}},[u,f,h.branchName,h.linkedPr,x.selectedBranch,q.worktreeName,D,j,oe.touched,je,ke,r]),Le=f==="new-branch"?h.branchName:x.selectedBranch;ze.useEffect(()=>{if(!t||!u||!oe.touched||ke)return;const pe=setTimeout(()=>{Ie()},300);return()=>clearTimeout(pe)},[q.worktreeName,Le,t,u,Ie,oe.touched,ke]);const Pe=async()=>{if(!u||!m){G.error(r("session.newWorktree.error.noActiveProject"));return}te(de=>({...de,touched:!0}));const pe=f==="new-branch"?h.branchName:x.selectedBranch,Oe=q.worktreeName,nt=$i(pe),Re=$n(Oe);if(!nt){G.error(r("session.newWorktree.error.branchNameRequired"));return}if(!Re){G.error(r("session.newWorktree.error.worktreeDirectoryRequired"));return}je&&(je.abort(),Se(null)),te(de=>({...de,isValidating:!1,branchError:null,worktreeError:null})),Ne(!0);try{const de=await Vd(u),He=f==="new-branch"?h.linkedPr:null,st=h.sourceBranch;let qe="";const et=(()=>{if(He){const Je=ef(He,D,j);return qe=Je.sourceLabel,{preferredName:nt||Re,mode:"existing",branchName:nt,worktreeName:Re,existingBranch:Je.existingBranch,setupCommands:de,setUpstream:Je.setUpstream,upstreamRemote:Je.upstreamRemote,upstreamBranch:Je.upstreamBranch,...Je.ensureRemoteName?{ensureRemoteName:Je.ensureRemoteName}:{},...Je.ensureRemoteUrl?{ensureRemoteUrl:Je.ensureRemoteUrl}:{}}}return qe=f==="new-branch"?st:"",{preferredName:nt||Re,mode:f==="existing-branch"?"existing":"new",branchName:f==="existing-branch"?void 0:nt,worktreeName:Re,existingBranch:f==="existing-branch"?nt:void 0,setupCommands:de,...st&&f==="new-branch"?{startRef:st}:{}}})(),rt=await py(m,et),xe=await fy(u,rt),Ye=f==="new-branch"?h.linkedIssue:null,_e=f==="new-branch"?h.linkedPr:null,We=f==="new-branch"?h.includePrDiff:!1;let lt=null;if(Ye||_e){const Je=Ye?`#${Ye.number} ${Ye.title}`.trim():_e?`#${_e.number} ${_e.title}`.trim():r("session.newWorktree.newSessionTitle"),Ve=await hy(Je,xe.path,null);if(!Ve?.id)throw new Error("Failed to create session");lt=Ve.id,gy(Ve.id,Je).catch(()=>{});try{_t.getState().initializeNewOpenChamberSession(Ve.id,gt.getState().agents)}catch{}}h.sourceBranch&&f==="new-branch"&&!h.linkedPr&&localStorage.setItem(Zp,h.sourceBranch),G.success(r("session.newWorktree.toast.worktreeCreated"),{description:r("session.newWorktree.toast.worktreeCreatedDescription",{target:`${xe.branch||xe.name}${qe?` ${r("session.newWorktree.fromSource",{source:qe})}`:""}`})}),e(!1),lt?(n?.(xe.path,{sessionId:lt}),Ue({sessionId:lt,issue:Ye,pr:_e,includeDiff:We}).catch(Je=>{const Ve=Je instanceof Error?Je.message:r("session.newWorktree.error.sendGitHubContextFailed");G.error(r("session.newWorktree.error.sendGitHubContextFailed"),{description:Ve})})):n?.(xe.path)}catch(de){const He=de instanceof Error?de.message:r("session.newWorktree.error.createWorktreeFailed");G.error(r("session.newWorktree.error.createWorktreeFailed"),{description:He})}finally{Ne(!1)}},he=pe=>{b(pe),te(Oe=>({...Oe,touched:!1,branchError:null,worktreeError:null}))},F=pe=>{if(!pe){v(Oe=>({...Oe,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(pe.type==="issue"){const Oe=pe.item,nt=`issue-${Oe.number}-${nc()}`;v(Re=>({...Re,linkedIssue:Oe,linkedPr:null,includePrDiff:!1,branchName:nt,worktreeName:$n(nt),isSyncingWorktreeName:!0}))}else if(pe.type==="pr"){const Oe=pe.item;v(nt=>({...nt,linkedPr:Oe,linkedIssue:null,includePrDiff:pe.includeDiff??!1,branchName:Oe.head,worktreeName:$n(Oe.head),isSyncingWorktreeName:!0}))}},ee=d&&c?.connected===!0,Fe=(f==="existing-branch"?!!x.selectedBranch&&!!x.worktreeName&&!oe.branchError&&!oe.worktreeError:!!$i(h.branchName)&&!!h.worktreeName&&!oe.branchError&&!oe.worktreeError)&&!ke,we=()=>{v(pe=>({...pe,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},Qe=s.jsxs("div",{className:me("flex gap-2",o?"flex-col w-full":"flex-row items-center"),children:[s.jsx("div",{className:me("flex items-center gap-1.5 text-destructive",o?"w-full justify-center order-first":"mr-auto"),children:oe.touched&&(oe.branchError||oe.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:oe.branchError||oe.worktreeError})]})}),s.jsxs("div",{className:me("flex gap-2",o&&"w-full"),children:[s.jsx(be,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:ke,className:me(o&&"flex-1"),children:r("session.newWorktree.actions.cancel")}),s.jsxs(be,{size:"sm",onClick:Pe,disabled:!Fe||ke,className:me("gap-1.5",o&&"flex-1"),children:[ke&&s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(ke?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return s.jsxs(s.Fragment,{children:[o?s.jsxs(Mr,{open:t,title:r("session.newWorktree.title"),onClose:()=>e(!1),footer:Qe,children:[s.jsx("div",{className:"w-full mb-4",children:s.jsx(Er,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(I,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:f,onSelect:pe=>he(pe),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),s.jsxs("div",{className:"space-y-6",children:[f==="existing-branch"?s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.selectBranch")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>z(!0),className:"flex-1 justify-between h-9",children:[s.jsx("span",{className:x.selectedBranch?"text-foreground":"text-muted-foreground",children:x.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(I,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(be,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:se,disabled:!ce||y,title:r("session.newWorktree.fetchBranches"),children:y?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"refresh",className:"size-4"})})]}),s.jsx(Mr,{open:O,title:r("session.newWorktree.selectBranch"),onClose:()=>z(!1),children:s.jsxs("div",{className:"space-y-4",ref:Y,children:[s.jsx(Wt,{value:_,onChange:pe=>Q(pe.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),y?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):D.length===0&&j.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[ve&&fe&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r("session.newWorktree.matchingBranches")}),s.jsx("div",{className:"space-y-1",children:U.matching.map(pe=>s.jsx("button",{onClick:()=>{g(Oe=>({...Oe,selectedBranch:pe.value,worktreeName:$n(pe.label)})),te(Oe=>({...Oe,touched:!0})),z(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===pe.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:pe.label})},`${pe.source}-${pe.value}`))})]}),ve&&!fe&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),U.otherLocal.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(ve?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:U.otherLocal.map(pe=>s.jsx("button",{onClick:()=>{g(Oe=>({...Oe,selectedBranch:pe,worktreeName:$n(pe)})),te(Oe=>({...Oe,touched:!0})),z(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===pe?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:pe})},pe))})]}),U.otherRemote.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(ve?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:U.otherRemote.map(pe=>s.jsx("button",{onClick:()=>{g(Oe=>({...Oe,selectedBranch:`remotes/${pe}`,worktreeName:$n(pe)})),te(Oe=>({...Oe,touched:!0})),z(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===`remotes/${pe}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:pe})},`remotes/${pe}`))})]})]})]})})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),f==="new-branch"&&ee&&s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>C(!0),className:"gap-1.5 h-7",children:[s.jsx(I,{name:"github",className:"size-4 text-status-success"}),h.linkedIssue||h.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Wt,{value:h.branchName,onChange:pe=>{v(Oe=>({...Oe,branchName:pe.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>te(pe=>({...pe,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!h.linkedPr,className:me("h-8",oe.touched&&oe.branchError&&"border-destructive",h.linkedPr&&"bg-muted text-muted-foreground")}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:h.linkedPr.head})})]}),h.linkedIssue&&!h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:h.linkedIssue.number,title:h.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),f!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const pe=$n(f==="new-branch"?h.branchName:"");v(Oe=>({...Oe,worktreeName:pe,isSyncingWorktreeName:!0}))},disabled:!h.branchName||h.worktreeName===$n(h.branchName),className:me("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",h.worktreeName===$n(h.branchName)||!h.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(I,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Wt,{value:q.worktreeName,onChange:pe=>{f==="new-branch"?v(Oe=>({...Oe,worktreeName:pe.target.value,isSyncingWorktreeName:!1})):g(Oe=>({...Oe,worktreeName:pe.target.value}))},onBlur:()=>te(pe=>({...pe,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:me("h-8",oe.touched&&oe.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!h.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>$(!0),className:"w-full justify-between h-9",children:[s.jsx("span",{className:h.sourceBranch?"text-foreground":"text-muted-foreground",children:h.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(I,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),h.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:h.sourceBranch})}),s.jsx(Mr,{open:B,title:r("session.newWorktree.selectSourceBranch"),onClose:()=>$(!1),children:s.jsxs("div",{className:"space-y-4",ref:le,children:[s.jsx(Wt,{value:W,onChange:pe=>ne(pe.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),y?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):D.length===0&&j.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[ie&&H&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r("session.newWorktree.matchingBranches")}),s.jsx("div",{className:"space-y-1",children:ae.matching.map(pe=>s.jsx("button",{onClick:()=>{v(Oe=>({...Oe,sourceBranch:pe.value})),$(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===pe.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:pe.label})},`${pe.source}-${pe.value}`))})]}),ie&&!H&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),ae.otherLocal.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(ie?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:ae.otherLocal.map(pe=>s.jsx("button",{onClick:()=>{v(Oe=>({...Oe,sourceBranch:pe})),$(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===pe?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:pe})},pe))})]}),ae.otherRemote.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(ie?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:ae.otherRemote.map(pe=>s.jsx("button",{onClick:()=>{v(Oe=>({...Oe,sourceBranch:`remotes/${pe}`})),$(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===`remotes/${pe}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:pe})},`remotes/${pe}`))})]})]})]})})]}),(h.linkedIssue||h.linkedPr)&&f==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),h.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:h.linkedIssue.number})}),h.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:h.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:h.linkedIssue?.title||h.linkedPr?.title}),s.jsx("a",{href:h.linkedIssue?.url||h.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:pe=>pe.stopPropagation(),children:s.jsx(I,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:we,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[h.linkedPr.head," → ",h.linkedPr.base]}),h.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]})]}):s.jsx(vs,{open:t,onOpenChange:e,children:s.jsxs(ys,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[s.jsx(As,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(Ss,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(I,{name:"git-branch",className:"h-5 w-5"}),r("session.newWorktree.title")]}),s.jsx("div",{className:"w-[280px] shrink-0",children:s.jsx(Er,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(I,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:f,onSelect:pe=>he(pe),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),s.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[f==="existing-branch"?s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.selectBranch")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(_s,{open:N,onOpenChange:T,children:[s.jsx(Bs,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:me("truncate",x.selectedBranch?"text-foreground":"text-muted-foreground"),children:x.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(zs,{align:"start",sideOffset:6,portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:re,children:s.jsxs(La,{shouldFilter:!1,children:[s.jsx(oa,{placeholder:r("session.newWorktree.searchBranches"),value:_,onValueChange:Q,onKeyDown:J}),s.jsx(Oa,{disableHorizontal:!0,children:y?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):D.length===0&&j.length===0?s.jsx($a,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[ve&&fe&&s.jsx(zn,{heading:r("session.newWorktree.matchingBranches"),children:U.matching.map(pe=>s.jsx(Dn,{value:pe.value,onSelect:()=>{g(Oe=>({...Oe,selectedBranch:pe.value,worktreeName:$n(pe.label)})),te(Oe=>({...Oe,touched:!0})),T(!1)},children:s.jsx("span",{className:"typography-small break-all",children:pe.label})},`${pe.source}-${pe.value}`))}),ve&&!fe&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),U.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[ve&&s.jsx(ka,{}),s.jsx(zn,{heading:r(ve?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:U.otherLocal.map(pe=>s.jsx(Dn,{value:pe,onSelect:()=>{g(Oe=>({...Oe,selectedBranch:pe,worktreeName:$n(pe)})),te(Oe=>({...Oe,touched:!0})),T(!1)},children:s.jsx("span",{className:"typography-small break-all",children:pe})},`local-${pe}`))})]}),U.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(U.otherLocal.length>0||ve)&&s.jsx(ka,{}),s.jsx(zn,{heading:r(ve?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:U.otherRemote.map(pe=>s.jsx(Dn,{value:`remotes/${pe}`,onSelect:()=>{g(Oe=>({...Oe,selectedBranch:`remotes/${pe}`,worktreeName:$n(pe)})),te(Oe=>({...Oe,touched:!0})),T(!1)},children:s.jsx("span",{className:"typography-small break-all",children:pe})},`remote-${pe}`))})]})]})})]})})]}),s.jsx(be,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:se,disabled:!ce||y,title:r("session.newWorktree.fetchBranches"),children:y?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"refresh",className:"size-4"})})]})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),f==="new-branch"&&ee&&s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>C(!0),className:"gap-1.5 h-7",children:[s.jsx(I,{name:"github",className:"size-4 text-status-success"}),h.linkedIssue||h.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Wt,{value:h.branchName,onChange:pe=>{v(Oe=>({...Oe,branchName:pe.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>te(pe=>({...pe,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!h.linkedPr,className:me("h-8",oe.touched&&oe.branchError&&"border-destructive",h.linkedPr&&"bg-muted text-muted-foreground")}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:h.linkedPr.head})})]}),h.linkedIssue&&!h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:h.linkedIssue.number,title:h.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),f!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const pe=$n(f==="new-branch"?h.branchName:"");v(Oe=>({...Oe,worktreeName:pe,isSyncingWorktreeName:!0}))},disabled:!h.branchName||h.worktreeName===$n(h.branchName),className:me("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",h.worktreeName===$n(h.branchName)||!h.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(I,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Wt,{value:q.worktreeName,onChange:pe=>{f==="new-branch"?v(Oe=>({...Oe,worktreeName:pe.target.value,isSyncingWorktreeName:!1})):g(Oe=>({...Oe,worktreeName:pe.target.value}))},onBlur:()=>te(pe=>({...pe,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:me("h-8",oe.touched&&oe.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!h.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(_s,{open:M,onOpenChange:R,children:[s.jsx(Bs,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:me("truncate",h.sourceBranch?"text-foreground":"text-muted-foreground"),children:h.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(zs,{align:"start",portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:ue,children:s.jsxs(La,{shouldFilter:!1,children:[s.jsx(oa,{placeholder:r("session.newWorktree.searchBranches"),value:W,onValueChange:ne,onKeyDown:J}),s.jsx(Oa,{disableHorizontal:!0,children:y?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):D.length===0&&j.length===0?s.jsx($a,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[ie&&H&&s.jsx(zn,{heading:r("session.newWorktree.matchingBranches"),children:ae.matching.map(pe=>s.jsx(Dn,{value:pe.value,onSelect:()=>{v(Oe=>({...Oe,sourceBranch:pe.value})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:pe.label})},`${pe.source}-${pe.value}`))}),ie&&!H&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),ae.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[ie&&s.jsx(ka,{}),s.jsx(zn,{heading:r(ie?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:ae.otherLocal.map(pe=>s.jsx(Dn,{value:pe,onSelect:()=>{v(Oe=>({...Oe,sourceBranch:pe})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:pe})},`local-${pe}`))})]}),ae.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(ae.otherLocal.length>0||ie)&&s.jsx(ka,{}),s.jsx(zn,{heading:r(ie?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:ae.otherRemote.map(pe=>s.jsx(Dn,{value:`remotes/${pe}`,onSelect:()=>{v(Oe=>({...Oe,sourceBranch:`remotes/${pe}`})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:pe})},`remote-${pe}`))})]})]})})]})})]}),h.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:h.sourceBranch})})]}),(h.linkedIssue||h.linkedPr)&&f==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),h.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:h.linkedIssue.number})}),h.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:h.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:h.linkedIssue?.title||h.linkedPr?.title}),s.jsx("a",{href:h.linkedIssue?.url||h.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:pe=>pe.stopPropagation(),children:s.jsx(I,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:we,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[h.linkedPr.head," → ",h.linkedPr.base]}),h.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]}),s.jsxs(Hs,{className:"mt-1 flex items-center justify-between",children:[s.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:oe.touched&&(oe.branchError||oe.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:oe.branchError||oe.worktreeError})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:ke,children:r("session.newWorktree.actions.cancel")}),s.jsxs(be,{size:"sm",onClick:Pe,disabled:!Fe||ke,className:"gap-1.5",children:[ke&&s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(ke?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),s.jsx(rI,{open:P,onOpenChange:C,onSelect:F})]})}let oi=null,li=null,Zo=null,yl=0;const Ta=new Set,cI=3e4,dI=45e3,Ag=()=>{Zo&&(clearTimeout(Zo),Zo=null)},Dg=()=>{if(li||Ta.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(yl,5)),cI);li=setTimeout(()=>{li=null,yl+=1,Tg()},t)},vl=()=>{Ag(),oi&&oi.close(),oi=null},tf=()=>{Ag(),Ta.size!==0&&(Zo=setTimeout(()=>{vl(),Dg()},dI))},uI=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}},mI=t=>{if(t.type==="openchamber:event-stream-ready"){yl=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:"",a=typeof e?.ranAt=="number"?e.ranAt:Date.now(),i=e?.status,o=i==="running"||i==="error"?i:"success";if(!n||!r)return;const c={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:a,status:o,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of Ta)d(c)},Tg=()=>{if(typeof window>"u"||Ta.size===0||typeof EventSource!="function"||oi&&oi.readyState!==EventSource.CLOSED)return;vl();const t=new EventSource("/api/openchamber/events");t.onopen=()=>{tf()},t.onmessage=e=>{tf();const n=uI(e.data);n&&mI(n)},t.onerror=()=>{vl(),Dg()},oi=t},Mg=t=>(Ta.add(t),Tg(),()=>{Ta.delete(t),Ta.size===0&&(li&&(clearTimeout(li),li=null),yl=0,vl())}),$l=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},yi=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},pI=async t=>{const e=yi(t),n=await fetch(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await $l(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},sf=async(t,e)=>{const n=yi(t),r=await fetch(`/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 $l(r,"Failed to save scheduled task"));const a=await r.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},fI=async(t,e)=>{const n=yi(t),r=yi(e),a=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}`,{method:"DELETE",headers:{accept:"application/json"}});if(!a.ok)throw new Error(await $l(a,"Failed to delete scheduled task"));const i=await a.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},hI=async(t,e)=>{const n=yi(t),r=yi(e),a=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}/run`,{method:"POST",headers:{accept:"application/json"}});if(!a.ok)throw new Error(await $l(a,"Failed to run scheduled task"));const i=await a.json().catch(()=>null);return{sessionId:typeof i?.sessionId=="string"&&i.sessionId.length>0?i.sessionId:void 0}},Eg=[0,1,2,3,4,5,6],nf=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"],rf=()=>{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}`},el=t=>{const e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),a=Number(e[3]),i=new Date(n,r-1,a);return Number.isNaN(i.getTime())||i.getFullYear()!==n||i.getMonth()!==r-1||i.getDate()!==a?null:i},af=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},gI=(t,e,n)=>{const r=el(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},of=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),xI=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),o=(new Date(n,r,1).getDay()-e+7)%7,c=new Date(n,r+1,0).getDate(),d=new Date(n,r,0).getDate(),p=[];for(let m=0;m<42;m+=1){const u=m-o+1;if(u<=0){const f=d+u;p.push({date:new Date(n,r-1,f),inCurrentMonth:!1});continue}if(u>c){p.push({date:new Date(n,r+1,u-c),inCurrentMonth:!1});continue}p.push({date:new Date(n,r,u),inCurrentMonth:!0})}return p},bI=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],a=n>=12?"PM":"AM",i=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(i).padStart(2,"0"),minute:r,meridiem:a}},ya=(t,e,n)=>{const r=Number(t),a=Number(e),i=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,o=Number.isFinite(a)?Math.min(59,Math.max(0,a)):0;let c=i%12;return n==="PM"&&(c+=12),`${String(c).padStart(2,"0")}:${String(o).padStart(2,"0")}`},ji=(t,e)=>{const{max:n,min:r=0,loop:a=!1}=e;let i=Number.parseInt(t,10);return Number.isFinite(i)?(a?(i>n&&(i=r),i<r&&(i=n)):(i>n&&(i=n),i<r&&(i=r)),String(i).padStart(2,"0")):"00"},lf=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:ji(t,{min:1,max:12}),Ro=t=>/^[0-5][0-9]$/.test(t)?t:ji(t,{max:59}),yI=(t,e)=>ji(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),cf=(t,e)=>ji(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),vI=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}},wI=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}},jI=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Eg.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},NI=(t,e)=>[...t.slice(e),...t.slice(0,e)],vr=t=>{const e=at.c(6),{htmlFor:n,required:r,children:a}=t;let i;e[0]!==r?(i=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=i):i=e[1];let o;return e[2]!==a||e[3]!==n||e[4]!==i?(o=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,i]})}),e[2]=a,e[3]=n,e[4]=i,e[5]=o):o=e[5],o},df=t=>{const e=at.c(84),{value:n,onChange:r,use24Hour:a,hourAriaLabel:i,minuteAriaLabel:o,periodAriaLabel:c,amLabel:d,pmLabel:p}=t;let m;e[0]!==n?(m=bI(n),e[0]=n,e[1]=m):m=e[1];const u=m,f=ze.useRef(null),b=ze.useRef(null),[h,v]=ze.useState(null),[x,g]=ze.useState(null),w=ze.useRef(null),y=ze.useRef(null);let k;e[2]===Symbol.for("react.memo_cache_sentinel")?(k=te=>{w.current=te,v(te)},e[2]=k):k=e[2];const D=k;let j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=te=>{y.current=te,g(te)},e[3]=j):j=e[3];const S=j,A=AI,E=DI,P=TI;let C;e[4]!==r||e[5]!==u.meridiem||e[6]!==u.minute||e[7]!==a?(C=te=>{const ke=te.replace(/\D/g,"").slice(0,2);D(ke),ke.length===2&&(r(a?P(A(ke),u.minute):ya(lf(ke),u.minute,u.meridiem)),D(null),b.current?.focus())},e[4]=r,e[5]=u.meridiem,e[6]=u.minute,e[7]=a,e[8]=C):C=e[8];const N=C;let T;e[9]!==r||e[10]!==u.meridiem||e[11]!==u.minute||e[12]!==a?(T=()=>{const te=w.current;if(te!==null&&(D(null),te.length!==0)){if(a){r(P(A(te.padStart(2,"0")),u.minute));return}r(ya(lf(te.padStart(2,"0")),u.minute,u.meridiem))}},e[9]=r,e[10]=u.meridiem,e[11]=u.minute,e[12]=a,e[13]=T):T=e[13];const M=T;let R;e[14]!==r||e[15]!==u.hour12||e[16]!==u.hour24||e[17]!==u.meridiem||e[18]!==a?(R=te=>{const ke=te.replace(/\D/g,"").slice(0,2);S(ke),ke.length===2&&(r(a?P(u.hour24,Ro(ke)):ya(u.hour12,Ro(ke),u.meridiem)),S(null))},e[14]=r,e[15]=u.hour12,e[16]=u.hour24,e[17]=u.meridiem,e[18]=a,e[19]=R):R=e[19];const O=R;let z;e[20]!==r||e[21]!==u.hour12||e[22]!==u.hour24||e[23]!==u.meridiem||e[24]!==a?(z=()=>{const te=y.current;te!==null&&(S(null),te.length!==0&&r(a?P(u.hour24,Ro(te.padStart(2,"0"))):ya(u.hour12,Ro(te.padStart(2,"0")),u.meridiem)))},e[20]=r,e[21]=u.hour12,e[22]=u.hour24,e[23]=u.meridiem,e[24]=a,e[25]=z):z=e[25];const B=z;let $;e[26]!==r||e[27]!==u.hour12||e[28]!==u.hour24||e[29]!==u.meridiem||e[30]!==u.minute||e[31]!==a?($=te=>r(a?P(E(u.hour24,te),u.minute):ya(yI(u.hour12,te),u.minute,u.meridiem)),e[26]=r,e[27]=u.hour12,e[28]=u.hour24,e[29]=u.meridiem,e[30]=u.minute,e[31]=a,e[32]=$):$=e[32];const _=$;let Q;e[33]!==r||e[34]!==u.hour12||e[35]!==u.hour24||e[36]!==u.meridiem||e[37]!==u.minute||e[38]!==a?(Q=te=>r(a?P(u.hour24,cf(u.minute,te)):ya(u.hour12,cf(u.minute,te),u.meridiem)),e[33]=r,e[34]=u.hour12,e[35]=u.hour24,e[36]=u.meridiem,e[37]=u.minute,e[38]=a,e[39]=Q):Q=e[39];const W=Q;let ne;e[40]!==r||e[41]!==u.hour12||e[42]!==u.meridiem||e[43]!==u.minute?(ne=te=>{te!==u.meridiem&&r(ya(u.hour12,u.minute,te))},e[40]=r,e[41]=u.hour12,e[42]=u.meridiem,e[43]=u.minute,e[44]=ne):ne=e[44];const re=ne;let ue;e[45]!==M||e[46]!==_?(ue=te=>{if(te.key==="ArrowRight"){te.preventDefault(),M(),b.current?.focus();return}(te.key==="ArrowUp"||te.key==="ArrowDown")&&(te.preventDefault(),D(null),_(te.key==="ArrowUp"?1:-1))},e[45]=M,e[46]=_,e[47]=ue):ue=e[47];const Y=ue;let le;e[48]!==B||e[49]!==W?(le=te=>{if(te.key==="ArrowLeft"&&(te.currentTarget.selectionStart??0)===0){te.preventDefault(),B(),f.current?.focus();return}(te.key==="ArrowUp"||te.key==="ArrowDown")&&(te.preventDefault(),S(null),W(te.key==="ArrowUp"?1:-1))},e[48]=B,e[49]=W,e[50]=le):le=e[50];const J=le,L=a?"px-2":"pl-2 pr-1";let V;e[51]!==L?(V=me("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",L),e[51]=L,e[52]=V):V=e[52];const K=h??(a?u.hour24:u.hour12);let X;e[53]!==N?(X=te=>N(te.target.value),e[53]=N,e[54]=X):X=e[54];let U;e[55]===Symbol.for("react.memo_cache_sentinel")?(U=()=>D(""),e[55]=U):U=e[55];let ae;e[56]!==M||e[57]!==i||e[58]!==Y||e[59]!==K||e[60]!==X?(ae=s.jsx("input",{ref:f,inputMode:"numeric",value:K,onChange:X,onKeyDown:Y,onFocus:U,onBlur:M,maxLength:2,"aria-label":i,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=M,e[57]=i,e[58]=Y,e[59]=K,e[60]=X,e[61]=ae):ae=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 ie=x??u.minute;let fe;e[63]!==O?(fe=te=>O(te.target.value),e[63]=O,e[64]=fe):fe=e[64];let H;e[65]===Symbol.for("react.memo_cache_sentinel")?(H=()=>S(""),e[65]=H):H=e[65];let ce;e[66]!==B||e[67]!==o||e[68]!==J||e[69]!==ie||e[70]!==fe?(ce=s.jsx("input",{ref:b,inputMode:"numeric",value:ie,onChange:fe,onKeyDown:J,onFocus:H,onBlur:B,maxLength:2,"aria-label":o,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]=B,e[67]=o,e[68]=J,e[69]=ie,e[70]=fe,e[71]=ce):ce=e[71];let se;e[72]!==d||e[73]!==u.meridiem||e[74]!==c||e[75]!==p||e[76]!==re||e[77]!==a?(se=a?null:s.jsxs(ds,{value:u.meridiem,onValueChange:te=>re(te),children:[s.jsx(us,{"aria-label":c,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(bs,{})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"AM",children:d}),s.jsx(Lt,{value:"PM",children:p})]})]}),e[72]=d,e[73]=u.meridiem,e[74]=c,e[75]=p,e[76]=re,e[77]=a,e[78]=se):se=e[78];let oe;return e[79]!==V||e[80]!==ae||e[81]!==ce||e[82]!==se?(oe=s.jsxs("div",{className:V,children:[ae,ve,ce,se]}),e[79]=V,e[80]=ae,e[81]=ce,e[82]=se,e[83]=oe):oe=e[83],oe},uf=t=>new Date(t.getFullYear(),t.getMonth(),1),SI=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},mf=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),kI=t=>{if(!t)return["09:00"];const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(a=>typeof a=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(a)).map(a=>a.trim()),r=Array.from(new Set(n)).sort((a,i)=>a.localeCompare(i));return r.length>0?r:["09:00"]},pf=(t,e)=>{const n=Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC";return t?{id:t.id,name:t.name,enabled:t.enabled,schedule:{kind:t.schedule.kind==="once"?"once":t.schedule.kind==="weekly"?"weekly":"daily",times:kI(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:rf(),onceTime:typeof t.schedule.time=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.time)?t.schedule.time:"09:00",weekdays:Array.isArray(t.schedule.weekdays)?t.schedule.weekdays:[1],timezone:t.schedule.timezone||n},execution:{prompt:t.execution.prompt,providerID:t.execution.providerID,modelID:t.execution.modelID,variant:t.execution.variant||"",agent:t.execution.agent||""},state:t.state}:{name:"",enabled:!0,schedule:{kind:"daily",times:["09:00"],onceDate:rf(),onceTime:"09:00",weekdays:[1],timezone:n},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent}}},CI=(t,e)=>{if(!t.name.trim())return e("sessions.scheduledTasks.editor.validation.taskNameRequired");if(!t.execution.prompt.trim())return e("sessions.scheduledTasks.editor.validation.promptRequired");if(!t.execution.providerID.trim()||!t.execution.modelID.trim())return e("sessions.scheduledTasks.editor.validation.modelRequired");if(t.schedule.kind==="once"){if(!/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.onceDate))return e("sessions.scheduledTasks.editor.validation.dateFormat");if(!/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.onceTime))return e("sessions.scheduledTasks.editor.validation.timeFormat")}else if(t.schedule.times.filter(r=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(r)).length===0)return e("sessions.scheduledTasks.editor.validation.atLeastOneTime");return t.schedule.kind==="weekly"&&t.schedule.weekdays.length===0?e("sessions.scheduledTasks.editor.validation.atLeastOneWeekday"):t.schedule.timezone.trim()?null:e("sessions.scheduledTasks.editor.validation.timezoneRequired")},II=t=>{const e=t.filter(n=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(n));return Array.from(new Set(e)).sort((n,r)=>n.localeCompare(r))};function PI(t){const{open:e,task:n,onOpenChange:r,onSave:a}=t,{t:i,locale:o}=mt(),c=gt(q=>q.loadProviders),d=gt(q=>q.loadAgents),p=gt(q=>q.providers),m=gt(q=>q.currentProviderId),u=gt(q=>q.currentModelId),f=gt(q=>q.currentVariant||""),b=gt(q=>q.currentAgentName||""),h=Te(q=>q.timeFormatPreference),v=Te(q=>q.weekStartPreference),x=Te(q=>q.isMobile),[g,w]=ze.useState(()=>pf(n,{providerID:m,modelID:u,variant:f,agent:b})),[y,k]=ze.useState(!1),[D,j]=ze.useState(!1),[S,A]=ze.useState(!1),[E,P]=ze.useState(""),[C,N]=ze.useState(!1),[T,M]=ze.useState(""),[R,O]=ze.useState(()=>{const q=el(n?.schedule?.date||"")||new Date;return new Date(q.getFullYear(),q.getMonth(),1)}),z=ze.useRef(null),B=ze.useRef(null),$=ze.useRef(null),_=ze.useRef(null),Q=ze.useMemo(()=>wI(o),[o]),W=ze.useMemo(()=>vI(o),[o]),ne=ze.useMemo(()=>h==="24h"?!0:h==="12h"?!1:Q,[h,Q]),re=ze.useMemo(()=>v==="sunday"?0:v==="monday"?1:W,[v,W]),ue=ze.useMemo(()=>{const q=jI(o);return NI(Eg.map(Ie=>({value:Ie,label:q[Ie]||""})),re)},[o,re]);ze.useEffect(()=>{e&&(c(),d())},[e,c,d]),ze.useEffect(()=>{if(!e)return;w(pf(n,{providerID:m,modelID:u,variant:f,agent:b}));const q=el(n?.schedule?.date||"")||new Date;O(new Date(q.getFullYear(),q.getMonth(),1)),j(!1),N(!1),A(!1),M(""),P("")},[e,n,m,u,f,b]),ze.useEffect(()=>{if(!D)return;const q=Ie=>{z.current&&!z.current.contains(Ie.target)&&j(!1)};return document.addEventListener("mousedown",q),()=>{document.removeEventListener("mousedown",q)}},[D]);const Y=ze.useMemo(()=>{const Ie=p.find(Le=>Le.id===g.execution.providerID)?.models?.find(Le=>Le.id===g.execution.modelID);return Ie?.variants?Object.keys(Ie.variants):[]},[p,g.execution.providerID,g.execution.modelID]),le=Y.length>0,J=ze.useMemo(()=>!le||!g.execution.variant?"__default":Y.includes(g.execution.variant)?g.execution.variant:"__default",[g.execution.variant,le,Y]);ze.useEffect(()=>{le||!g.execution.variant||w(q=>({...q,execution:{...q.execution,variant:""}}))},[le,g.execution.variant]);const L=ze.useCallback((q,Ie)=>{w(Le=>{const Pe=new Set(Le.schedule.weekdays);return Ie?Pe.add(q):Pe.delete(q),{...Le,schedule:{...Le.schedule,weekdays:Array.from(Pe).sort((he,F)=>he-F)}}})},[]),V=ze.useCallback((q,Ie)=>{w(Le=>{const Pe=Le.schedule.times.slice();return Pe[q]=Ie,{...Le,schedule:{...Le.schedule,times:Pe}}})},[]),K=ze.useCallback(q=>{w(Ie=>{const Le=Ie.schedule.times.filter((Pe,he)=>he!==q);return{...Ie,schedule:{...Ie.schedule,times:Le.length>0?Le:["09:00"]}}})},[]),X=ze.useCallback(()=>{w(q=>({...q,schedule:{...q.schedule,times:[...q.schedule.times,"12:00"]}}))},[]),U=ze.useMemo(()=>SI(),[]),ae=ze.useMemo(()=>uf(U),[U]),ve=ze.useMemo(()=>{const q=el(g.schedule.onceDate);return q?mf(q,U)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(o,{weekday:"short"}).format(q):null},[g.schedule.onceDate,o,i,U]),ie=ze.useMemo(()=>uf(R).getTime()<=ae.getTime(),[R,ae]),fe=ze.useMemo(()=>ue.map(q=>q.label),[ue]),H=ze.useCallback(q=>{w(Ie=>({...Ie,schedule:{...Ie.schedule,onceDate:q}}))},[]),ce=ze.useCallback((q,Ie)=>{if(q.startsWith("/")){const he=q.indexOf(" "),F=q.indexOf(`
|
|
180
|
+
`),ee=Math.min(he===-1?q.length:he,F===-1?q.length:F);if(Ie<=ee&&he===-1){M(q.substring(1,ee)),N(!0),A(!1);return}}N(!1);const Le=q.substring(0,Ie),Pe=Le.lastIndexOf("@");if(Pe!==-1){const he=Pe>0?Le[Pe-1]:null,F=Le.substring(Pe+1);(!he||/\s/.test(he))&&!F.includes(" ")&&!F.includes(`
|
|
181
|
+
`)?(P(F),A(!0)):A(!1);return}A(!1)},[]),se=ze.useCallback(q=>{w(Ie=>({...Ie,execution:{...Ie.execution,prompt:q}}))},[]),oe=ze.useCallback(q=>{const Ie=g.execution.prompt,Pe=B.current?.selectionStart??Ie.length,F=Ie.substring(0,Pe).lastIndexOf("@"),ee=q.relativePath&&q.relativePath.trim().length>0?q.relativePath.trim():q.path||q.name,Ce=F!==-1?F:Pe,Fe=`${Ie.substring(0,Ce)}@${ee} ${Ie.substring(Pe)}`,we=Ce+ee.length+2;se(Fe),A(!1),P(""),requestAnimationFrame(()=>{const Qe=B.current;Qe&&(Qe.selectionStart=we,Qe.selectionEnd=we,Qe.focus()),ce(Fe,we)})},[g.execution.prompt,se,ce]),te=ze.useCallback(q=>{const Ie=g.execution.prompt,Pe=B.current?.selectionStart??Ie.length,F=Ie.substring(0,Pe).lastIndexOf("@"),ee=F!==-1?F:Pe,Ce=`${Ie.substring(0,ee)}@${q} ${Ie.substring(Pe)}`,Fe=ee+q.length+2;se(Ce),A(!1),P(""),requestAnimationFrame(()=>{const we=B.current;we&&(we.selectionStart=Fe,we.selectionEnd=Fe,we.focus()),ce(Ce,Fe)})},[g.execution.prompt,se,ce]),ke=ze.useCallback(q=>{const Ie=`/${q.name} `;se(Ie),N(!1),M(""),requestAnimationFrame(()=>{const Le=B.current;Le&&(Le.focus(),Le.selectionStart=Le.value.length,Le.selectionEnd=Le.value.length),ce(Ie,Ie.length)})},[se,ce]),Ne=ze.useCallback(q=>{if(C&&_.current&&(q.key==="Enter"||q.key==="ArrowUp"||q.key==="ArrowDown"||q.key==="Escape"||q.key==="Tab")){q.preventDefault(),_.current.handleKeyDown(q.key);return}S&&$.current&&(q.key==="Enter"||q.key==="ArrowUp"||q.key==="ArrowDown"||q.key==="Escape"||q.key==="Tab")&&(q.preventDefault(),$.current.handleKeyDown(q.key))},[C,S]),je=ze.useCallback(async()=>{const q=CI(g,i);if(q){G.error(q);return}const Ie=II(g.schedule.times),Le={...g.id?{id:g.id}:{},name:g.name.trim(),enabled:g.enabled,schedule:{kind:g.schedule.kind,timezone:g.schedule.timezone.trim(),...g.schedule.kind==="once"?{date:g.schedule.onceDate,time:g.schedule.onceTime}:{times:Ie,...g.schedule.kind==="weekly"?{weekdays:g.schedule.weekdays}:{}}},execution:{prompt:g.execution.prompt,providerID:g.execution.providerID,modelID:g.execution.modelID,...g.execution.variant.trim()?{variant:g.execution.variant.trim()}:{},...g.execution.agent.trim()?{agent:g.execution.agent.trim()}:{}},...g.state?{state:g.state}:{}};k(!0);try{await a(Le),r(!1)}catch(Pe){G.error(Pe instanceof Error?Pe.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{k(!1)}},[g,r,a,i]),Se=ze.useId(),De=ze.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),ye=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),ge=i("sessions.scheduledTasks.editor.description"),Me=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(vr,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(Wt,{id:"sched-name",value:g.name,onChange:q=>w(Ie=>({...Ie,name:q.target.value})),placeholder:i("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(vr,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(ds,{value:g.schedule.kind,onValueChange:q=>{w(Ie=>({...Ie,schedule:{...Ie.schedule,kind:q}}))},children:[s.jsx(us,{className:"w-fit max-w-full",children:s.jsx(bs,{children:q=>i(q==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":q==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(Lt,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(Lt,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")})]})]})]})]}),g.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:z,children:[s.jsx(vr,{children:i("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:"inline-flex h-9 w-fit max-w-full items-center justify-between gap-2 rounded-md border border-border bg-background px-3 text-left hover:bg-interactive-hover",onClick:()=>j(q=>!q),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:gI(g.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),o)})]}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),D?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:()=>O(q=>of(q,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:ie,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(o,{month:"long",year:"numeric"}).format(R)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>O(q=>of(q,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:fe.map((q,Ie)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:q},`${q}-${Ie}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:xI(R,re).map(({date:q,inCurrentMonth:Ie})=>{const Le=af(q),Pe=Le===g.schedule.onceDate,he=mf(q,U),F=q.getTime()<U.getTime(),ee=Pe?"bg-interactive-selection text-interactive-selection-foreground":F?"text-muted-foreground/40":Ie?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{F||(H(Le),j(!1))},disabled:F,className:["h-8 rounded-md typography-ui-label",ee,he&&!Pe?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",F?"cursor-not-allowed opacity-45":""].join(" "),children:q.getDate()},Le)})}),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:ve||""}),s.jsx(be,{type:"button",size:"xs",variant:"ghost",onClick:()=>{H(af(U)),O(new Date(U.getFullYear(),U.getMonth(),1))},children:i("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(vr,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(df,{value:g.schedule.onceTime,use24Hour:ne,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:q=>w(Ie=>({...Ie,schedule:{...Ie.schedule,onceTime:q}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(vr,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(ds,{value:g.schedule.timezone,onValueChange:q=>{w(Ie=>({...Ie,schedule:{...Ie.schedule,timezone:q}}))},children:[s.jsx(us,{className:"w-fit max-w-full",children:s.jsx(bs,{})}),s.jsx(ms,{children:nf.map(q=>s.jsx(Lt,{value:q,children:q},q))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[g.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(vr,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:ue.map(q=>{const Ie=g.schedule.weekdays.includes(q.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",Ie?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(fs,{checked:Ie,onChange:Le=>L(q.value,Le),ariaLabel:q.label}),s.jsx("button",{type:"button",onClick:()=>L(q.value,!Ie),className:"group-hover:text-foreground",children:q.label})]},q.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(vr,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:g.schedule.times.map((q,Ie)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(df,{value:q,use24Hour:ne,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:Le=>V(Ie,Le)}),g.schedule.times.length>1?s.jsx(be,{type:"button",size:"icon",variant:"ghost",onClick:()=>K(Ie),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null]},Ie))}),s.jsx("div",{children:s.jsxs(be,{type:"button",size:"sm",variant:"outline",onClick:X,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",i("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(vr,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(ds,{value:g.schedule.timezone,onValueChange:q=>{w(Ie=>({...Ie,schedule:{...Ie.schedule,timezone:q}}))},children:[s.jsx(us,{className:"w-fit max-w-full",children:s.jsx(bs,{})}),s.jsx(ms,{children:nf.map(q=>s.jsx(Lt,{value:q,children:q},q))})]})]})]}),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(vr,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(uo,{providerId:g.execution.providerID,modelId:g.execution.modelID,onChange:(q,Ie)=>{w(Le=>({...Le,execution:{...Le.execution,providerID:q,modelID:Ie,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(vr,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(ds,{value:J,disabled:!le,onValueChange:q=>{w(Ie=>({...Ie,execution:{...Ie.execution,variant:q==="__default"?"":q}}))},children:[s.jsx(us,{className:"w-fit max-w-full",children:s.jsx(bs,{children:q=>q==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):q})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),Y.map(q=>s.jsx(Lt,{value:q,children:q},q))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(vr,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Ll,{agentName:g.execution.agent,filter:q=>Jf(q.mode),onChange:q=>w(Ie=>({...Ie,execution:{...Ie.execution,agent:q}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(vr,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(bn,{id:"sched-prompt",ref:B,value:g.execution.prompt,onChange:q=>{const Ie=q.target.value;se(Ie);const Le=q.target.selectionStart??Ie.length;ce(Ie,Le)},onKeyDown:Ne,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),C?s.jsx(uh,{ref:_,searchQuery:T,onCommandSelect:ke,onClose:()=>N(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,S?s.jsx(mh,{ref:$,searchQuery:E,onFileSelect:oe,onAgentSelect:te,onClose:()=>A(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),Ue=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(fs,{checked:g.enabled,onChange:q=>w(Ie=>({...Ie,enabled:q})),ariaLabel:i("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:y,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(be,{type:"button",size:"sm",onClick:je,disabled:y,children:i(y?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return x?s.jsx(Mr,{open:e,title:ye,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:q=>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:ye}),q]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:ge})]}),footer:Ue,children:Me}):s.jsx(vs,{open:e,onOpenChange:q=>{!q&&De()||r(q)},children:s.jsxs(ys,{"aria-describedby":Se,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Fs,{id:Se,className:"sr-only",children:ge}),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(Ss,{className:"typography-ui-label font-medium text-foreground",children:ye}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:ge})]})}),s.jsx(ao,{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:Me})}),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:Ue})})]})})}function AI(t){return ji(t,{min:0,max:23})}function DI(t,e){return ji(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function TI(t,e){const n=Number(t),r=Number(e),a=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,i=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(a).padStart(2,"0")}:${String(i).padStart(2,"0")}`}const MI=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,a)=>r.localeCompare(a))},EI=(t,e)=>{const n=MI(t).join(", ")||"--:--",r=a=>e(a===0?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sun":a===1?"sessions.scheduledTasks.dialog.schedule.weekdayShort.mon":a===2?"sessions.scheduledTasks.dialog.schedule.weekdayShort.tue":a===3?"sessions.scheduledTasks.dialog.schedule.weekdayShort.wed":a===4?"sessions.scheduledTasks.dialog.schedule.weekdayShort.thu":a===5?"sessions.scheduledTasks.dialog.schedule.weekdayShort.fri":a===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 a=Array.isArray(t.schedule.weekdays)?t.schedule.weekdays.map(i=>r(i)).join(", "):"";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.weeklyWithTimezone",{days:a,time:n,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.weekly",{days:a,time:n})}if(t.schedule.kind==="once"){const a=typeof t.schedule.date=="string"&&t.schedule.date.trim().length>0?t.schedule.date:e("sessions.scheduledTasks.dialog.schedule.unknownDate"),i=typeof t.schedule.time=="string"&&t.schedule.time.trim().length>0?t.schedule.time:"--:--";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.onceWithTimezone",{date:a,time:i,timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.once",{date:a,time:i})}return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.cronWithTimezone",{cron:t.schedule.cron||"",timezone:t.schedule.timezone}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},RI=t=>!t||!Number.isFinite(t)?"":new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),ff=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),a=6e4,i=60*a,o=24*i,c=n>=0;if(r<a)return e(c?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<i){const u=Math.round(r/a);return c?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:u}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:u})}if(r<o){const u=Math.floor(r/i),f=Math.round(r%i/a),b=f>0?`${u}h ${f}m`:`${u}h`;return c?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:b}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:b})}const d=Math.floor(r/o),p=Math.round(r%o/i),m=p>0?`${d}d ${p}h`:`${d}d`;return c?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:m}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:m})},FI={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"}},LI=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function OI(){const{t}=mt(),e=Te(M=>M.isScheduledTasksDialogOpen),n=Te(M=>M.setScheduledTasksDialogOpen),r=Te(M=>M.isMobile),a=Ls(M=>M.projects),i=Ls(M=>M.getActiveProject()),o=Ws(M=>M.homeDirectory),{currentTheme:c}=Cr(),[d,p]=ze.useState(""),[m,u]=ze.useState([]),[f,b]=ze.useState(!0),[h,v]=ze.useState(!1),[x,g]=ze.useState(null),[w,y]=ze.useState(null),k=ze.useMemo(()=>a.find(M=>M.id===d)||null,[a,d]),D=ze.useCallback(M=>{const R=M.label?.trim()||Fa(M.path,o||void 0),O=lo({id:M.id,iconImage:M.iconImage??null},{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),z=M.icon?Rl[M.icon]:null,B=M.color?co[M.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[O?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:M.iconBackground?{backgroundColor:M.iconBackground}:void 0,children:s.jsx("img",{src:O,alt:"",className:"h-full w-full object-contain",draggable:!1})}):z?s.jsx(I,{name:z,className:"h-3.5 w-3.5 shrink-0",style:B?{color:B}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:B?{color:B}:void 0}),s.jsx("span",{className:"truncate",children:R})]})},[o,c.metadata.variant,c.colors.surface.foreground]),j=ze.useCallback(async(M,R)=>{if(!M){u([]);return}R?.silent||b(!0);try{const O=await pI(M);O.sort((z,B)=>{if(z.enabled!==B.enabled)return z.enabled?-1:1;const $=z.name.localeCompare(B.name);return $!==0?$:(z.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(B.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),u(O)}catch(O){G.error(O instanceof Error?O.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),R?.silent||u([])}finally{R?.silent||b(!1)}},[t]);ze.useEffect(()=>{if(!e)return;const M=i?.id||a[0]?.id||"";p(M),M?j(M):(u([]),b(!1))},[e,i,a,j]),ze.useEffect(()=>{if(!e)return;let M=null;const R=Mg(O=>{O.type==="scheduled-task-ran"&&O.projectId===d&&(M&&clearTimeout(M),M=setTimeout(()=>{j(d,{silent:!0})},400))});return()=>{M&&clearTimeout(M),R()}},[e,d,j]);const S=ze.useCallback(async M=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await sf(d,M),await j(d),G.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,j,t]),A=ze.useCallback(async(M,R)=>{if(d){y(M.id),u(O=>O.map(z=>z.id===M.id?{...z,enabled:R}:z));try{await sf(d,{...M,enabled:R}),await j(d,{silent:!0})}catch(O){G.error(O instanceof Error?O.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await j(d,{silent:!0})}finally{y(null)}}},[d,j,t]),E=ze.useCallback(async M=>{if(!(!d||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:M.name})))){y(M.id);try{await fI(d,M.id),await j(d,{silent:!0}),G.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(O){G.error(O instanceof Error?O.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{y(null)}}},[d,j,t]),P=ze.useCallback(async M=>{if(d){y(M.id);try{await hI(d,M.id),await Promise.all([j(d,{silent:!0}),Qc()]),G.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(R){G.error(R instanceof Error?R.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{y(null)}}},[d,j,t]),C=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(ds,{value:d||"__none",onValueChange:M=>{const R=M==="__none"?"":M;p(R),R?j(R):u([])},children:[s.jsx(us,{className:r?"w-full":void 0,children:k?s.jsx(bs,{children:D(k)}):s.jsx(bs,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(ms,{children:[a.length===0?s.jsx(Lt,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,a.map(M=>s.jsx(Lt,{value:M.id,children:D(M)},M.id))]})]})]}),N=()=>{g(null),v(!0)},T=s.jsxs("div",{className:"space-y-4",children:[r?C:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[C,s.jsxs(be,{onClick:N,disabled:!d,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:f?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")]}):m.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(d?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:m.map(M=>{const R=w===M.id,O=M.state?.lastStatus||"idle",z=FI[O],B=t(O==="success"?"sessions.scheduledTasks.dialog.status.success":O==="error"?"sessions.scheduledTasks.dialog.status.error":O==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),$=M.state?.nextRunAt,_=M.state?.lastRunAt;return s.jsxs("div",{className:me("rounded-lg border border-border p-4 transition-opacity",!M.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:M.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:EI(M,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")}),$?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:ff($,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:RI($)})]}):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")}),O==="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")]}):_?s.jsxs(s.Fragment,{children:[z.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${z.tone})`},children:[s.jsx(I,{name:z.Icon,className:"h-3.5 w-3.5"}),B]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:ff(_,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),M.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:LI("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:M.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:me("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",M.enabled?"text-foreground":"text-muted-foreground",R&&"cursor-not-allowed opacity-50"),children:[s.jsx(fs,{checked:M.enabled,onChange:Q=>{A(M,Q)},ariaLabel:M.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:M.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:M.name}),disabled:R}),M.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(be,{variant:"outline",size:"sm",onClick:()=>{P(M)},disabled:R,children:[s.jsx(I,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>{g(M),v(!0)},disabled:R,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:M.name}),children:[s.jsx(I,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(be,{variant:"destructive",size:"sm",onClick:()=>{E(M)},disabled:R,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:M.name}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},M.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Mr,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:M=>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")}),M]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(be,{className:"w-full",onClick:N,disabled:!d,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:T}):s.jsx(vs,{open:e,onOpenChange:n,children:s.jsxs(ys,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(Fs,{children:t("sessions.scheduledTasks.dialog.description")})]}),T]})}),s.jsx(PI,{open:h,task:x,onOpenChange:v,onSave:S})]})}const $I=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(c=>Ps(c.path)??c.path).filter(c=>!!c)]),i=(c=>c.filter(d=>Xi(d,t.normalizedPath,r)))(e.archivedSessions),o=e.sessions.filter(c=>c.time?.archived||Ps(c.directory??null)?!1:Xi(c,t.normalizedPath,r));return gi([...i,...o])},BI=t=>{const e=at.c(12),{normalizedProjects:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:o,isSessionsLoading:c,foldersMap:d,createFolder:p,addSessionToFolder:m,cleanupSessions:u}=t;let f,b;e[0]!==m||e[1]!==a||e[2]!==i||e[3]!==u||e[4]!==p||e[5]!==d||e[6]!==c||e[7]!==o||e[8]!==n||e[9]!==r?(f=()=>{c||n.forEach(h=>{const v=Ud(h.normalizedPath),x=$I(h,{sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:o}),g=new Set(x.map(zI)),w=d[v]??[],y=new Map(w.map(_I));x.forEach(k=>{const D=xy(k,h.normalizedPath),j=D.toLowerCase();let S=y.get(j);S||(S=p(v,D),y.set(j,S)),S.sessionIds.includes(k.id)||m(v,S.id,k.id)}),u(v,g)})},b=[n,r,a,i,o,c,d,p,m,u],e[0]=m,e[1]=a,e[2]=i,e[3]=u,e[4]=p,e[5]=d,e[6]=c,e[7]=o,e[8]=n,e[9]=r,e[10]=f,e[11]=b):(f=e[10],b=e[11]),l.useEffect(f,b)};function zI(t){return t.id}function _I(t){return[t.name.toLowerCase(),t]}const VI=t=>{const e=at.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:a,availableWorktreesByProject:i,projectRepoStatus:o,projectRootBranches:c,lastRepoStatus:d,buildGroupedSessions:p,hasSessionSearchQuery:m,normalizedSessionSearchQuery:u,filterSessionNodesForSearch:f,buildGroupSearchText:b,foldersMap:h}=t;let v;if(e[0]!==i||e[1]!==p||e[2]!==a||e[3]!==r||e[4]!==d||e[5]!==n||e[6]!==o||e[7]!==c){let P;e[9]!==i||e[10]!==p||e[11]!==a||e[12]!==r||e[13]!==d||e[14]!==o||e[15]!==c?(P=C=>{const N=gi([...r(C),...a(C)]),T=i.get(C.normalizedPath)??[],M=o.has(C.id)?!!o.get(C.id):d,R=p(N,C.normalizedPath,T,c.get(C.id)??null,M);return{project:C,groups:R}},e[9]=i,e[10]=p,e[11]=a,e[12]=r,e[13]=d,e[14]=o,e[15]=c,e[16]=P):P=e[16],v=n.map(P),e[0]=i,e[1]=p,e[2]=a,e[3]=r,e[4]=d,e[5]=n,e[6]=o,e[7]=c,e[8]=v}else v=e[8];const x=v,g=x;let w;if(e[17]!==b||e[18]!==f||e[19]!==h||e[20]!==m||e[21]!==u||e[22]!==g){e:{const P=new WeakMap;if(!m){w=P;break e}const C=N=>N.reduce((T,M)=>T+1+C(M.children),0);g.forEach(N=>{N.groups.forEach(T=>{const M=f(T.sessions,u),R=C(M),O=b(T).includes(u),z=Ps(T.directory??null),$=(z?h[z]??[]:[]).filter(_=>_.name.toLowerCase().includes(u)).length;P.set(T,{filteredNodes:M,matchedSessionCount:R,folderNameMatchCount:$,groupMatches:O,hasMatch:O||R>0||$>0})})}),w=P}e[17]=b,e[18]=f,e[19]=h,e[20]=m,e[21]=u,e[22]=g,e[23]=w}else w=e[23];const y=w;let k;e:{if(!m){k=g;break e}let P;if(e[24]!==y||e[25]!==g){let C;e[27]!==y?(C=N=>({...N,groups:N.groups.filter(T=>y.get(T)?.hasMatch===!0)}),e[27]=y,e[28]=C):C=e[28],P=g.map(C).filter(UI),e[24]=y,e[25]=g,e[26]=P}else P=e[26];k=P}const D=k,j=m?D:g;let S;e:{if(!m){S=0;break e}let P;if(e[29]!==y||e[30]!==j){let C;e[32]!==y?(C=(N,T)=>N+T.groups.reduce((M,R)=>{const O=y.get(R);if(!O)return M;const z=O.folderNameMatchCount+(O.groupMatches?1:0);return M+O.matchedSessionCount+z},0),e[32]=y,e[33]=C):C=e[33],P=j.reduce(C,0),e[29]=y,e[30]=j,e[31]=P}else P=e[31];S=P}const A=S;let E;return e[34]!==y||e[35]!==x||e[36]!==A||e[37]!==D||e[38]!==j||e[39]!==g?(E={projectSections:x,visibleProjectSections:g,groupSearchDataByGroup:y,searchableProjectSections:D,sectionsForRender:j,searchMatchCount:A},e[34]=y,e[35]=x,e[36]=A,e[37]=D,e[38]=j,e[39]=g,e[40]=E):E=e[40],E};function UI(t){return t.groups.length>0}const WI=t=>{const e=at.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:a,setActiveSessionByProject:i,currentSessionId:o,handleSessionSelect:c,newSessionDraftOpen:d,mobileVariant:p,openNewSessionDraft:m,setActiveMainTab:u,setSessionSwitcherOpen:f,sessions:b,worktreeMetadata:h}=t;let v,x;if(e[0]!==n){x=new Map,v=new Map;const C=(N,T,M,R)=>{x.has(N)||x.set(N,new Map);const O=x.get(N);R.forEach(z=>{const B=Ps(z.worktree?.path??z.session.directory??M??T);O.set(z.session.id,{directory:B}),v.has(N)||v.set(N,{id:z.session.id,directory:B}),z.children.length>0&&C(N,T,B,z.children)})};n.forEach(N=>{N.groups.forEach(T=>{C(N.project.id,N.project.normalizedPath,T.directory,T.sessions)})}),e[0]=n,e[1]=v,e[2]=x}else v=e[1],x=e[2];let g;e[3]!==v||e[4]!==x?(g={metaByProject:x,firstSessionByProject:v},e[3]=v,e[4]=x,e[5]=g):g=e[5];const w=g,y=l.useRef(null);let k,D;e[6]!==r||e[7]!==a||e[8]!==o||e[9]!==c||e[10]!==p||e[11]!==d||e[12]!==m||e[13]!==n||e[14]!==w||e[15]!==u||e[16]!==i||e[17]!==f?(k=()=>{if(!r||d||y.current===r)return;const C=n.find(B=>B.project.id===r);if(!C)return;y.current=r;const N=w.metaByProject.get(r);if(o&&N&&N.has(o)){i(B=>{if(B.get(r)===o)return B;const $=new Map(B);return $.set(r,o),$});return}if(!N||N.size===0){u("chat"),p&&f(!1),m({directoryOverride:C.project.normalizedPath});return}const T=a.get(r),M=T&&N.has(T)?T:null,R=w.firstSessionByProject.get(r)?.id??null,O=M??R;if(!O||O===o)return;const z=N.get(O)?.directory??null;c(O,z,!1,r)},D=[r,a,o,c,d,p,m,n,w,u,f,i],e[6]=r,e[7]=a,e[8]=o,e[9]=c,e[10]=p,e[11]=d,e[12]=m,e[13]=n,e[14]=w,e[15]=u,e[16]=i,e[17]=f,e[18]=k,e[19]=D):(k=e[18],D=e[19]),l.useLayoutEffect(k,D);let j,S;e[20]!==r||e[21]!==o||e[22]!==w||e[23]!==i?(j=()=>{if(!r||!o)return;const C=w.metaByProject.get(r);!C||!C.has(o)||i(N=>{if(N.get(r)===o)return N;const T=new Map(N);return T.set(r,o),T})},S=[r,o,w,i],e[20]=r,e[21]=o,e[22]=w,e[23]=i,e[24]=j,e[25]=S):(j=e[24],S=e[25]),l.useEffect(j,S);let A;if(e[26]!==o||e[27]!==b||e[28]!==h){e:{if(!o){A=null;break e}const C=h.get(o)?.path;if(C){A=Ps(C)??C;break e}let N;e[30]!==o?(N=M=>M.id===o,e[30]=o,e[31]=N):N=e[31];const T=b.find(N);if(!T){A=null;break e}A=Ps(T.directory??null)}e[26]=o,e[27]=b,e[28]=h,e[29]=A}else A=e[29];const E=A;let P;return e[32]!==E?(P={currentSessionDirectory:E},e[32]=E,e[33]=P):P=e[33],P},KI=t=>{const e=at.c(4);let n;e[0]!==t?(n=(i,o)=>{const c=t.get(i);if(!c||c.length===0)return o;const d=new Map(o.map(HI)),p=[];return c.forEach(m=>{const u=d.get(m);u&&(p.push(u),d.delete(m))}),o.forEach(m=>{d.has(m.id)&&p.push(m)}),p},e[0]=t,e[1]=n):n=e[1];const r=n;let a;return e[2]!==r?(a={getOrderedGroups:r},e[2]=r,e[3]=a):a=e[3],a};function HI(t){return[t.id,t]}const Fo=t=>!!t.time?.archived,GI=t=>{const{t:e}=mt(),n=l.useCallback(o=>[o.label,o.branch??"",o.description??"",o.directory??""].join(" ").toLowerCase(),[]),r=l.useCallback(o=>{const c=Ps(o.directory??null)??"";return`${(o.title||e("sessions.sidebar.session.untitled")).trim()} ${c}`.toLowerCase()},[e]),a=l.useCallback((o,c)=>c?o.flatMap(d=>{if(r(d.session).includes(c))return[d];const m=a(d.children,c);return m.length===0?[]:[{...d,children:m}]}):o,[r]),i=l.useCallback((o,c,d,p,m)=>{const u=Ps(c??null),f=gi(o).sort((C,N)=>ii(C,N,t.pinnedSessionIds)),b=new Map(f.map(C=>[C.id,C])),h=new Map;f.forEach(C=>{const N=C.parentID;if(!N)return;const T=b.get(N);if(!T||Fo(T)!==Fo(C))return;const M=h.get(N)??[];M.push(C),h.set(N,M)}),h.forEach(C=>C.sort((N,T)=>ii(N,T,t.pinnedSessionIds)));const v=new Map;d.forEach(C=>{if(C.path){const N=Ps(C.path)??C.path;v.set(N,C)}});const x=C=>{const N=Ps(C.directory??null),T=t.worktreeMetadata.get(C.id)??null;if(T)return T;if(N){const M=v.get(N)??null;if(M&&N!==u)return M}return null},g=C=>{const N=h.get(C.id)??[];return{session:C,children:N.map(T=>g(T)),worktree:x(C)}},w=f.filter(C=>{const N=C.parentID;if(!N)return!0;const T=b.get(N);return T?Fo(T)!==Fo(C):!0}),y=new Map,k="__archived__",D=C=>{if(C.time?.archived)return k;const N=Ps(t.worktreeMetadata.get(C.id)?.path??null),T=Ps(C.directory??null);if(!N&&!T)return k;const M=Ps(C.project?.worktree??null),R=N??T??M;return R?R!==u&&v.has(R)?R:R===u?u??"__project_root__":k:k};w.forEach(C=>{const N=g(C),T=D(C);y.has(T)||y.set(T,[]),y.get(T)?.push(N)});const j=u??"__project_root__",S=[{id:"root",label:m&&p&&p!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:p}):e("sessions.sidebar.grouping.projectRoot"),branch:p??null,description:u?Qi(u,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:u,folderScopeKey:u,sessions:y.get(j)??[]}],A=new Map;d.forEach(C=>{const N=Ps(C.path)??C.path,T=y.get(N)??[],M=T.length>0,R=T.reduce((O,z)=>{const B=Number(z.session.time?.updated??z.session.time?.created??0);return Number.isFinite(B)?Math.max(O,B):O},0);A.set(N,{hasActiveSession:M,lastUpdatedAt:R})}),[...d].sort((C,N)=>{const T=Ps(C.path)??C.path,M=Ps(N.path)??N.path,R=A.get(T)??{hasActiveSession:!1,lastUpdatedAt:0},O=A.get(M)??{hasActiveSession:!1,lastUpdatedAt:0};if(R.hasActiveSession!==O.hasActiveSession)return R.hasActiveSession?-1:1;if(R.hasActiveSession&&O.hasActiveSession)return O.lastUpdatedAt-R.lastUpdatedAt;const z=(C.label||C.branch||C.name||C.path||"").toLowerCase(),B=(N.label||N.branch||N.name||N.path||"").toLowerCase();return z.localeCompare(B)}).forEach(C=>{const N=Ps(C.path)??C.path,T=t.gitBranches.get(N)?.trim()||null,M=C.branch?.trim()||null,O=!!(T&&M&&C.label&&Lu(C.label)===Lu(M))?T:C.label||C.name||Fa(N,t.homeDirectory)||N;S.push({id:`worktree:${N}`,label:O,branch:T||M,description:Qi(N,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:C,directory:N,folderScopeKey:N,sessions:y.get(N)??[]})});const P=y.get(k)??[];return P.length>0&&S.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&&u?Ud(u):null,sessions:P}),S},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:a,buildGroupedSessions:i}},qI=t=>{const e=at.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:a,sessionSearchContainerRef:i}=t;let o,c;e[0]!==n||e[1]!==a?(o=()=>{if(!n||typeof window>"u")return;const m=window.requestAnimationFrame(()=>{a.current?.focus(),a.current?.select()});return()=>window.cancelAnimationFrame(m)},c=[n,a],e[0]=n,e[1]=a,e[2]=o,e[3]=c):(o=e[2],c=e[3]),l.useEffect(o,c);let d,p;e[4]!==n||e[5]!==i||e[6]!==r?(d=()=>{if(!n||typeof document>"u")return;const m=u=>{i.current&&(i.current.contains(u.target)||r(!1))};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},p=[n,r,i],e[4]=n,e[5]=i,e[6]=r,e[7]=d,e[8]=p):(d=e[7],p=e[8]),l.useEffect(d,p)},YI=t=>{const e=at.c(42),{t:n}=mt(),[r,a]=l.useState(null),i=l.useRef(null);let o,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>()=>{i.current&&clearTimeout(i.current)},c=[],e[0]=o,e[1]=c):(o=e[0],c=e[1]),l.useEffect(o,c);let d;e[2]!==t?(d=(R,O,z,B)=>{if(z)return;const $=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(B&&B!==t.activeProjectId&&t.setActiveProjectIdOnly(B),O&&O!==t.currentDirectory&&t.setDirectory(O,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),R===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(R),$();return}t.setCurrentSession(R,O??null),t.onSessionSelected?.(R),$()},e[2]=t,e[3]=d):d=e[3];const p=d;let m;e[4]!==t?(m=()=>{t.setActiveMainTab("chat")},e[4]=t,e[5]=m):m=e[5];const u=m;let f;e[6]!==t?(f=async()=>{t.editingId&&t.editTitle.trim()&&(await t.updateSessionTitle(t.editingId,t.editTitle.trim()),t.setEditingId(null),t.setEditTitle(""))},e[6]=t,e[7]=f):f=e[7];const b=f;let h;e[8]!==t?(h=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=h):h=e[9];const v=h;let x;e[10]!==t||e[11]!==n?(x=async R=>{const O=await t.shareSession(R.id);O&&O.share?.url?G.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):G.error(n("sessions.sidebar.session.share.error"))},e[10]=t,e[11]=n,e[12]=x):x=e[12];const g=x;let w;e[13]!==n?(w=(R,O)=>{Rn(R).then(z=>{if(!z.ok){G.error(n("sessions.sidebar.session.share.copyUrlError"));return}a(O),i.current&&clearTimeout(i.current),i.current=window.setTimeout(()=>{a(null),i.current=null},2e3)}).catch(()=>{G.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=w):w=e[14];const y=w;let k;e[15]!==t||e[16]!==n?(k=async R=>{await t.unshareSession(R)?G.success(n("sessions.sidebar.session.unshare.success")):G.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=k):k=e[17];const D=k;let j;e[18]!==t.childrenMap?(j=R=>{const O=[],z=B=>{(t.childrenMap.get(B)??[]).forEach(_=>{O.push(_),z(_.id)})};return z(R),O},e[18]=t.childrenMap,e[19]=j):j=e[19];const S=j;let A;e[20]!==t||e[21]!==S||e[22]!==n?(A=async(R,O)=>{const z=S(R.id),B=O?.archivedBucket===!0;if(z.length===0){(B?await t.deleteSession(R.id):await t.archiveSession(R.id))?G.success(n(B?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):G.error(n(B?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const $=[R.id,...z.map(JI)];if(B){const{deletedIds:W,failedIds:ne}=await t.deleteSessions($);W.length>0&&G.success(W.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:W.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:W.length})),ne.length>0&&G.error(ne.length===1?n("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ne.length}):n("sessions.sidebar.bulkActions.failedDeletePlural",{count:ne.length}));return}const{archivedIds:_,failedIds:Q}=await t.archiveSessions($);_.length>0&&G.success(_.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:_.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:_.length})),Q.length>0&&G.error(Q.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Q.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:Q.length}))},e[20]=t,e[21]=S,e[22]=n,e[23]=A):A=e[23];const E=A;let P;e[24]!==t||e[25]!==S||e[26]!==E?(P=(R,O)=>{const z=S(R.id);if(!t.showDeletionDialog){E(R,O);return}t.setDeleteSessionConfirm({session:R,descendantCount:z.length,archivedBucket:O?.archivedBucket===!0})},e[24]=t,e[25]=S,e[26]=E,e[27]=P):P=e[27];const C=P;let N;e[28]!==t||e[29]!==E?(N=async()=>{if(!t.deleteSessionConfirm)return;const{session:R,archivedBucket:O}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await E(R,{archivedBucket:O})},e[28]=t,e[29]=E,e[30]=N):N=e[30];const T=N;let M;return e[31]!==T||e[32]!==r||e[33]!==v||e[34]!==y||e[35]!==C||e[36]!==b||e[37]!==u||e[38]!==p||e[39]!==g||e[40]!==D?(M={copiedSessionId:r,handleSessionSelect:p,handleSessionDoubleClick:u,handleSaveEdit:b,handleCancelEdit:v,handleShareSession:g,handleCopyShareUrl:y,handleUnshareSession:D,handleDeleteSession:C,confirmDeleteSession:T},e[31]=T,e[32]=r,e[33]=v,e[34]=y,e[35]=C,e[36]=b,e[37]=u,e[38]=p,e[39]=g,e[40]=D,e[41]=M):M=e[41],M};function JI(t){return t.id}const QI=t=>{const e=at.c(36),{isVSCode:n,hasLoadedGlobalSessions:r,safeStorage:a,keys:i,sessions:o,setPinnedSessionIds:c,groupOrderByProject:d,activeSessionByProject:p,collapsedGroups:m,setExpandedParents:u,setCollapsedProjects:f}=t,b=l.useRef(null),h=l.useRef(null);let v;e[0]!==n?(v=()=>{if(n)return;const O=h.current;if(h.current=null,b.current=null,!O)return;const{projects:z}=Ls.getState(),B=z.map($=>({...$,sidebarCollapsed:O.has($.id)}));Ms({projects:B}).catch(XI)},e[0]=n,e[1]=v):v=e[1];const x=v;let g;e[2]!==x||e[3]!==n?(g=O=>{typeof window>"u"||n||(h.current=O,b.current!==null&&window.clearTimeout(b.current),b.current=window.setTimeout(()=>{x()},700))},e[2]=x,e[3]=n,e[4]=g):g=e[4];const w=g;let y,k;e[5]===Symbol.for("react.memo_cache_sentinel")?(y=()=>()=>{typeof window<"u"&&b.current!==null&&window.clearTimeout(b.current),b.current=null,h.current=null},k=[],e[5]=y,e[6]=k):(y=e[5],k=e[6]),l.useEffect(y,k);let D,j;e[7]!==i.projectCollapse||e[8]!==i.sessionExpanded||e[9]!==a||e[10]!==f||e[11]!==u?(D=()=>{try{const O=a.getItem(i.sessionExpanded);if(O){const B=JSON.parse(O);Array.isArray(B)&&u(new Set(B.filter(ZI)))}const z=a.getItem(i.projectCollapse);if(z){const B=JSON.parse(z);Array.isArray(B)&&f(new Set(B.filter(eP)))}}catch{}},j=[i.projectCollapse,i.sessionExpanded,a,f,u],e[7]=i.projectCollapse,e[8]=i.sessionExpanded,e[9]=a,e[10]=f,e[11]=u,e[12]=D,e[13]=j):(D=e[12],j=e[13]),l.useEffect(D,j);let S,A;e[14]!==r||e[15]!==o||e[16]!==c?(S=()=>{if(!r)return;const O=new Set(o.map(tP));c(z=>{let B=!1;const $=new Set;return z.forEach(_=>{O.has(_)?$.add(_):B=!0}),B?$:z})},A=[r,o,c],e[14]=r,e[15]=o,e[16]=c,e[17]=S,e[18]=A):(S=e[17],A=e[18]),l.useEffect(S,A);let E,P;e[19]!==d||e[20]!==i.groupOrder||e[21]!==a?(E=()=>{try{const O=Object.fromEntries(d.entries());a.setItem(i.groupOrder,JSON.stringify(O))}catch{}},P=[d,i.groupOrder,a],e[19]=d,e[20]=i.groupOrder,e[21]=a,e[22]=E,e[23]=P):(E=e[22],P=e[23]),l.useEffect(E,P);let C,N;e[24]!==p||e[25]!==i.projectActiveSession||e[26]!==a?(C=()=>{try{const O=Object.fromEntries(p.entries());a.setItem(i.projectActiveSession,JSON.stringify(O))}catch{}},N=[p,i.projectActiveSession,a],e[24]=p,e[25]=i.projectActiveSession,e[26]=a,e[27]=C,e[28]=N):(C=e[27],N=e[28]),l.useEffect(C,N);let T,M;e[29]!==m||e[30]!==i.groupCollapse||e[31]!==a?(T=()=>{try{a.setItem(i.groupCollapse,JSON.stringify(Array.from(m)))}catch{}},M=[m,i.groupCollapse,a],e[29]=m,e[30]=i.groupCollapse,e[31]=a,e[32]=T,e[33]=M):(T=e[32],M=e[33]),l.useEffect(T,M);let R;return e[34]!==w?(R={scheduleCollapsedProjectsPersist:w},e[34]=w,e[35]=R):R=e[35],R};function XI(){}function ZI(t){return typeof t=="string"}function eP(t){return typeof t=="string"}function tP(t){return t.id}const sP=async(t,e,n)=>{if(t.length===0)return[];const r=Math.max(1,Math.min(e,t.length)),a=new Array(t.length);let i=0;const o=async()=>{for(;;){const c=i;if(i+=1,c>=t.length)return;a[c]=await n(t[c])}};return await Promise.all(Array.from({length:r},()=>o())),a},nP=t=>{const e=at.c(23),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:a,setProjectRootBranches:i}=t,{git:o}=_n(),c=nn(rP);let d,p;e[0]!==c||e[1]!==o||e[2]!==n||e[3]!==a?(d=()=>{if(!o||n.length===0){a(new Map);return}n.forEach(x=>{c(x.normalizedPath,o)})},p=[n,o,c,a],e[0]=c,e[1]=o,e[2]=n,e[3]=a,e[4]=d,e[5]=p):(d=e[4],p=e[5]),l.useEffect(d,p);let m,u;e[6]!==r||e[7]!==n||e[8]!==a?(m=()=>{const x=new Map;n.forEach(g=>{x.set(g.id,r.get(g.normalizedPath)?.isGitRepo??null)}),a(x)},u=[n,r,a],e[6]=r,e[7]=n,e[8]=a,e[9]=m,e[10]=u):(m=e[9],u=e[10]),l.useEffect(m,u);let f;if(e[11]!==r||e[12]!==n){let x;e[14]!==r?(x=g=>{const w=r.get(g.normalizedPath)?.branch??"";return`${g.id}:${w}`},e[14]=r,e[15]=x):x=e[15],f=n.map(x).join("|"),e[11]=r,e[12]=n,e[13]=f}else f=e[13];const b=f;let h;e[16]!==n||e[17]!==i?(h=()=>{let x=!1;return(async()=>{const w=await sP(n,2,iP);x||i(y=>{const k=new Map(y);return w.forEach(D=>{const{id:j,branch:S}=D;S&&k.set(j,S)}),k})})(),()=>{x=!0}},e[16]=n,e[17]=i,e[18]=h):h=e[18];let v;e[19]!==n||e[20]!==b||e[21]!==i?(v=[n,b,i],e[19]=n,e[20]=b,e[21]=i,e[22]=v):v=e[22],l.useEffect(h,v)};function rP(t){return t.ensureStatus}function aP(){return null}async function iP(t){const e=await io(t.normalizedPath).catch(aP);return{id:t.id,branch:e}}const oP=t=>{const e=at.c(14),{isVSCode:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i}=t;let o;e[0]!==r?(o=new Map,r.forEach(b=>{const h=Ps(b.directory??null)??Ps(b.project?.worktree??null);if(!h)return;const v=o.get(h)??[];v.push(b),o.set(h,v)}),e[0]=r,e[1]=o):o=e[1];const c=o;let d;e[2]!==i||e[3]!==n||e[4]!==c?(d=b=>{const h=n?[]:i.get(b.normalizedPath)??[],v=[b.normalizedPath,...h.map(lP).filter(cP)],x=new Set,g=[];return v.forEach(w=>{(c.get(w)??[]).forEach(k=>{x.has(k.id)||(x.add(k.id),g.push(k))})}),g},e[2]=i,e[3]=n,e[4]=c,e[5]=d):d=e[5];const p=d;let m;e[6]!==a||e[7]!==i||e[8]!==n||e[9]!==r?(m=b=>{if(n){const y=a.filter(D=>{const j=Ps(D.directory??null),S=Ps(D.project?.worktree??null);return j?j===b.normalizedPath:S===b.normalizedPath}),k=r.filter(D=>D.time?.archived||Ps(D.directory??null)?!1:Ps(D.project?.worktree??null)===b.normalizedPath);return gi([...y,...k])}const h=n?[]:i.get(b.normalizedPath)??[],v=new Set([b.normalizedPath,...h.map(dP).filter(uP)]),g=(y=>y.filter(k=>Xi(k,b.normalizedPath,v)))(a),w=r.filter(y=>{if(y.time?.archived||Ps(y.directory??null))return!1;const D=Ps(y.project?.worktree??null);return D?D===b.normalizedPath||D.startsWith(`${b.normalizedPath}/`):!1});return gi([...g,...w])},e[6]=a,e[7]=i,e[8]=n,e[9]=r,e[10]=m):m=e[10];const u=m;let f;return e[11]!==u||e[12]!==p?(f={getSessionsForProject:p,getArchivedSessionsForProject:u},e[11]=u,e[12]=p,e[13]=f):f=e[13],f};function lP(t){return Ps(t.path)??t.path}function cP(t){return!!t}function dP(t){return Ps(t.path)??t.path}function uP(t){return!!t}const mP=t=>{const e=at.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:a,normalizedProjects:i,isVSCode:o,availableWorktreesByProject:c,cleanupSessions:d}=t;let p,m;e[0]!==a||e[1]!==c||e[2]!==d||e[3]!==n||e[4]!==o||e[5]!==i||e[6]!==r?(p=()=>{if(n)return;const u=new Map;r.forEach(h=>{const v=Ps(h.directory??null);if(!v)return;const x=u.get(v);if(x){x.add(h.id);return}u.set(v,new Set([h.id]))}),i.forEach(h=>{const v=Ud(h.normalizedPath),x=o?[]:c.get(h.normalizedPath)??[],g=new Set([h.normalizedPath,...x.map(pP).filter(fP)]),w=gi([...a,...r.filter(y=>y.time?.archived||Ps(y.directory??null)?!1:Xi(y,h.normalizedPath,g))]).filter(y=>Xi(y,h.normalizedPath,g));u.set(v,new Set(w.map(hP)))});const f=Xn.getState().foldersMap;new Set([...Object.keys(f),...u.keys()]).forEach(h=>{d(h,u.get(h)??new Set)})},m=[a,c,d,n,o,i,r],e[0]=a,e[1]=c,e[2]=d,e[3]=n,e[4]=o,e[5]=i,e[6]=r,e[7]=p,e[8]=m):(p=e[7],m=e[8]),l.useEffect(p,m)};function pP(t){return Ps(t.path)??t.path}function fP(t){return!!t}function hP(t){return t.id}const gP=t=>{const e=at.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:a}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[o,c]=l.useState(i);let d;e[1]!==n||e[2]!==a?(d=()=>{if(!n)return;const m=new IntersectionObserver(u=>{u.forEach(f=>{const b=f.target.dataset.projectId;b&&c(h=>{const v=new Set(h);return f.isIntersecting?v.delete(b):v.add(b),v})})},{threshold:0});return a.current.forEach(u=>{u&&m.observe(u)}),()=>m.disconnect()},e[1]=n,e[2]=a,e[3]=d):d=e[3];let p;return e[4]!==n||e[5]!==a||e[6]!==r?(p=[n,a,r],e[4]=n,e[5]=a,e[6]=r,e[7]=p):p=e[7],l.useEffect(d,p),o},xP=t=>{const e=at.c(85),{folder:n,sessions:r,subFolderItems:a,isCollapsed:i,onToggle:o,onRename:c,onDelete:d,renderSessionNode:p,groupDirectory:m,projectId:u,mobileVariant:f,alwaysShowActions:b,isRenaming:h,renameDraft:v,onRenameDraftChange:x,onRenameSave:g,onRenameCancel:w,droppableRef:y,isDropTarget:k,onNewSession:D,onNewSubFolder:j,depth:S,hideActions:A,archivedBucket:E}=t,C=b===void 0?f===void 0?!1:f:b,N=h===void 0?!1:h,T=v===void 0?"":v,M=k===void 0?!1:k,R=S===void 0?0:S,O=A===void 0?!1:A,z=E===void 0?!1:E,{t:B}=mt(),[$,_]=l.useState(!1),[Q,W]=l.useState(""),ne=l.useRef(null),re=N||$,ue=N?T:Q;let Y;e[0]!==n.name?(Y=()=>{W(n.name),_(!0)},e[0]=n.name,e[1]=Y):Y=e[1];const le=Y;let J;e[2]!==ue||e[3]!==n.name||e[4]!==N||e[5]!==c||e[6]!==g?(J=()=>{const ee=ue.trim();ee&&ee!==n.name&&c(ee),N&&g&&g(),_(!1),W("")},e[2]=ue,e[3]=n.name,e[4]=N,e[5]=c,e[6]=g,e[7]=J):J=e[7];const L=J;let V;e[8]!==N||e[9]!==w?(V=()=>{N&&w&&w(),_(!1),W("")},e[8]=N,e[9]=w,e[10]=V):V=e[10];const K=V;let X;e[11]!==N||e[12]!==x?(X=ee=>{N&&x?x(ee):W(ee)},e[11]=N,e[12]=x,e[13]=X):X=e[13];const U=X;let ae,ve;e[14]!==N?(ae=()=>{if(!N)return;const ee=()=>{const we=ne.current;we&&(we.focus(),we.select())},Ce=requestAnimationFrame(ee),Fe=window.setTimeout(ee,0);return()=>{cancelAnimationFrame(Ce),window.clearTimeout(Fe)}},ve=[N],e[14]=N,e[15]=ae,e[16]=ve):(ae=e[15],ve=e[16]),l.useEffect(ae,ve);const ie=i?"folder":"folder-open",H=R>0&&"ml-3";let ce;e[17]!==H?(ce=me("oc-folder",H),e[17]=H,e[18]=ce):ce=e[18];const se=M&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let oe;e[19]!==se?(oe=me("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",se),e[19]=se,e[20]=oe):oe=e[20];const te=re?void 0:o,ke=re?void 0:"button",Ne=re?void 0:0;let je;e[21]!==o||e[22]!==re?(je=re?void 0:ee=>{(ee.key==="Enter"||ee.key===" ")&&(ee.preventDefault(),o())},e[21]=o,e[22]=re,e[23]=je):je=e[23];let Se;e[24]!==n.name||e[25]!==i||e[26]!==B?(Se=i?B("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):B("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[24]=n.name,e[25]=i,e[26]=B,e[27]=Se):Se=e[27];const De=z?C?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let ye;e[28]!==De?(ye=me("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",De),e[28]=De,e[29]=ye):ye=e[29];const ge=M?"text-primary":"text-muted-foreground";let Me;e[30]!==ge?(Me=me("h-3.5 w-3.5 flex-shrink-0",ge),e[30]=ge,e[31]=Me):Me=e[31];let Ue;e[32]!==ie||e[33]!==Me?(Ue=s.jsx(I,{name:ie,className:Me}),e[32]=ie,e[33]=Me,e[34]=Ue):Ue=e[34];let q;e[35]!==ue||e[36]!==n.name||e[37]!==K||e[38]!==U||e[39]!==L||e[40]!==i||e[41]!==M||e[42]!==re||e[43]!==r||e[44]!==B?(q=re?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:yP,onMouseDown:vP,onSubmit:ee=>{ee.preventDefault(),L()},children:[s.jsx("input",{ref:ne,value:ue,onChange:ee=>U(ee.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:B("sessions.sidebar.folderItem.namePlaceholder"),onClick:wP,onPointerDown:jP,onMouseDown:NP,onKeyDown:ee=>{if(ee.key==="Escape"){ee.stopPropagation(),K();return}(ee.key===" "||ee.key==="Enter")&&ee.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:SP,onPointerDown:kP,onMouseDown:CP,children:s.jsx(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:ee=>{ee.stopPropagation(),K()},onPointerDown:IP,onMouseDown:PP,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:me("typography-ui-label font-semibold truncate",M?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),i?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=ue,e[36]=n.name,e[37]=K,e[38]=U,e[39]=L,e[40]=i,e[41]=M,e[42]=re,e[43]=r,e[44]=B,e[45]=q):q=e[45];let Ie;e[46]!==ye||e[47]!==Ue||e[48]!==q?(Ie=s.jsxs("div",{className:ye,children:[Ue,q]}),e[46]=ye,e[47]=Ue,e[48]=q,e[49]=Ie):Ie=e[49];let Le;e[50]!==C||e[51]!==z||e[52]!==R||e[53]!==n.name||e[54]!==le||e[55]!==O||e[56]!==d||e[57]!==D||e[58]!==j||e[59]!==re||e[60]!==B?(Le=!re&&(!O||z)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:me("flex items-center gap-0.5 transition-opacity",C?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",z&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!z&&D?s.jsx("button",{type:"button",onClick:ee=>{ee.stopPropagation(),D()},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":B("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:B("sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})}):null,!z&&j&&R===0?s.jsx("button",{type:"button",onClick:ee=>{ee.stopPropagation(),j()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":B("sessions.sidebar.folderItem.newSubfolderAria",{folderName:n.name}),title:B("sessions.sidebar.folderItem.newSubfolder"),children:s.jsx(I,{name:"folder-add",className:"h-3.5 w-3.5"})}):null,z?null:s.jsx("button",{type:"button",onClick:ee=>{ee.stopPropagation(),le()},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":B("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:ee=>{ee.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":z?B("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):B("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[50]=C,e[51]=z,e[52]=R,e[53]=n.name,e[54]=le,e[55]=O,e[56]=d,e[57]=D,e[58]=j,e[59]=re,e[60]=B,e[61]=Le):Le=e[61];let Pe;e[62]!==y||e[63]!==oe||e[64]!==te||e[65]!==ke||e[66]!==Ne||e[67]!==je||e[68]!==Se||e[69]!==Ie||e[70]!==Le?(Pe=s.jsxs("div",{ref:y,className:oe,onClick:te,role:ke,tabIndex:Ne,onKeyDown:je,"aria-label":Se,children:[Ie,Le]}),e[62]=y,e[63]=oe,e[64]=te,e[65]=ke,e[66]=Ne,e[67]=je,e[68]=Se,e[69]=Ie,e[70]=Le,e[71]=Pe):Pe=e[71];let he;e[72]!==z||e[73]!==m||e[74]!==i||e[75]!==u||e[76]!==p||e[77]!==r||e[78]!==a||e[79]!==B?(he=i?null:s.jsxs("div",{className:"pb-1 pl-2",children:[a,r.length>0?r.map(ee=>p(ee,0,m??null,u??null,z)):a?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:B("sessions.sidebar.folderItem.emptyFolder")})]}),e[72]=z,e[73]=m,e[74]=i,e[75]=u,e[76]=p,e[77]=r,e[78]=a,e[79]=B,e[80]=he):he=e[80];let F;return e[81]!==ce||e[82]!==Pe||e[83]!==he?(F=s.jsxs("div",{className:ce,children:[Pe,he]}),e[81]=ce,e[82]=Pe,e[83]=he,e[84]=F):F=e[84],F},bP=l.memo(xP);function yP(t){return t.stopPropagation()}function vP(t){return t.stopPropagation()}function wP(t){return t.stopPropagation()}function jP(t){return t.stopPropagation()}function NP(t){return t.stopPropagation()}function SP(t){return t.stopPropagation()}function kP(t){return t.stopPropagation()}function CP(t){return t.stopPropagation()}function IP(t){return t.stopPropagation()}function PP(t){return t.stopPropagation()}const AP=t=>{const e=at.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:a,children:i}=t,o=`session-drag:${n}`;let c;e[0]!==r||e[1]!==n||e[2]!==a?(c={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:a},e[0]=r,e[1]=n,e[2]=a,e[3]=c):c=e[3];let d;e[4]!==o||e[5]!==c?(d={id:o,data:c},e[4]=o,e[5]=c,e[6]=d):d=e[6];const{attributes:p,listeners:m,setNodeRef:u,isDragging:f}=Dx(d);let b;e[7]!==m?(b=g=>{g.stopPropagation(),m?.onPointerDown&&m.onPointerDown(g)},e[7]=m,e[8]=b):b=e[8];const h=b,v=f?"opacity-30":void 0;let x;return e[9]!==p||e[10]!==i||e[11]!==h||e[12]!==u||e[13]!==v?(x=s.jsx("div",{ref:u,...p,onPointerDown:h,className:v,children:i}),e[9]=p,e[10]=i,e[11]=h,e[12]=u,e[13]=v,e[14]=x):x=e[14],x},DP=t=>{const e=at.c(11),{folderId:n,children:r}=t,a=`folder-drop:${n}`;let i;e[0]!==n?(i={type:"folder",folderId:n},e[0]=n,e[1]=i):i=e[1];let o;e[2]!==a||e[3]!==i?(o={id:a,data:i},e[2]=a,e[3]=i,e[4]=o):o=e[4];const{setNodeRef:c,isOver:d}=Tx(o);let p;e[5]!==r||e[6]!==d||e[7]!==c?(p=r(c,d),e[5]=r,e[6]=d,e[7]=c,e[8]=p):p=e[8];let m;return e[9]!==p?(m=s.jsx(s.Fragment,{children:p}),e[9]=p,e[10]=m):m=e[10],m},TP=t=>{const e=at.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:a,children:i}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={activationConstraint:{distance:8}},e[0]=o):o=e[0];const c=Hi(ni(Gi,o)),[d,p]=l.useState(null),[m,u]=l.useState("Session"),[f,b]=l.useState(null),[h,v]=l.useState(null);if(!n){let S;return e[1]!==i?(S=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=S):S=e[2],S}let x;e[3]!==a?(x=S=>{p(null),b(null),v(null);const{active:A,over:E}=S;if(!E)return;const P=A.data.current,C=E.data.current;P?.type==="session"&&P.sessionId&&C?.type==="folder"&&C.folderId&&a(P.sessionId,C.folderId)},e[3]=a,e[4]=x):x=e[4];const g=x;let w,y;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=S=>{const A=S.active.data.current;if(A?.type==="session"&&A.sessionId){p(A.sessionId),u(A.sessionTitle??"Session");const E=S.active.rect.current.initial?.width,P=S.active.rect.current.initial?.height;b(typeof E=="number"?E:null),v(typeof P=="number"?P:null)}},y=()=>{p(null),b(null),v(null)},e[5]=w,e[6]=y):(w=e[5],y=e[6]);let k;e[7]!==h||e[8]!==d||e[9]!==m||e[10]!==f||e[11]!==r?(k=d&&r?s.jsxs("div",{style:{width:f?`${f}px`:"auto",height:h?`${h}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]=h,e[8]=d,e[9]=m,e[10]=f,e[11]=r,e[12]=k):k=e[12];let D;e[13]!==k?(D=s.jsx(nl,{children:k}),e[13]=k,e[14]=D):D=e[14];let j;return e[15]!==i||e[16]!==g||e[17]!==c||e[18]!==D?(j=s.jsxs(qi,{sensors:c,collisionDetection:Yi,onDragStart:w,onDragCancel:y,onDragEnd:g,children:[i,D]}),e[15]=i,e[16]=g,e[17]=c,e[18]=D,e[19]=j):j=e[19],j},Ca=ar()(ro(t=>({displayMode:"default",showRecentSection:!0,setDisplayMode:e=>t({displayMode:e}),setShowRecentSection:e=>t({showRecentSection:e}),toggleRecentSection:()=>t(e=>({showRecentSection:!e.showRecentSection}))}),{name:"session-display-mode"}));function MP(t){const e=at.c(289),{t:n}=mt(),{group:r,groupKey:a,projectId:i,hideGroupLabel:o,hasSessionSearchQuery:c,normalizedSessionSearchQuery:d,groupSearchDataByGroup:p,expandedSessionGroups:m,collapsedGroups:u,hideDirectoryControls:f,collapsedFolderIds:b,toggleFolderCollapse:h,renameFolder:v,deleteFolder:x,showDeletionDialog:g,setDeleteFolderConfirm:w,renderSessionNode:y,projectRepoStatus:k,lastRepoStatus:D,toggleGroupSessionLimit:j,mobileVariant:S,alwaysShowActions:A,activeProjectId:E,setActiveProjectIdOnly:P,setActiveMainTab:C,setSessionSwitcherOpen:N,openNewSessionDraft:T,addSessionToFolder:M,createFolderAndStartRename:R,renamingFolderId:O,renameFolderDraft:z,setRenameFolderDraft:B,setRenamingFolderId:$,pinnedSessionIds:_,sessionOrderIndex:Q,prVisualStateByDirectoryBranch:W,onToggleCollapsedGroup:ne,dragHandleProps:re,compactBodyPadding:ue}=t,Y=ue===void 0?!1:ue;let le;e[0]!==_||e[1]!==Q?(le=(it,zt)=>{const hs=Q.get(it.session.id),Jt=Q.get(zt.session.id);if(hs!==void 0||Jt!==void 0){if(hs===void 0)return 1;if(Jt===void 0)return-1;if(hs!==Jt)return hs-Jt}return ii(it.session,zt.session,_)},e[0]=_,e[1]=Q,e[2]=le):le=e[2];const J=le;let L;e[3]!==r||e[4]!==p||e[5]!==c?(L=c?p.get(r):null,e[3]=r,e[4]=p,e[5]=c,e[6]=L):L=e[6];const V=L,K=Ca(_P),X=Xn(zP),U=K==="minimal";let ae;e[7]!==m||e[8]!==a?(ae=m.has(a),e[7]=m,e[8]=a,e[9]=ae):ae=e[9];const ve=ae;let ie;e[10]!==u||e[11]!==a||e[12]!==c?(ie=c?!1:u.has(a),e[10]=u,e[11]=a,e[12]=c,e[13]=ie):ie=e[13];const fe=ie,H=f?10:5,ce=c?V?.groupMatches===!0:!1,se=c;V?.filteredNodes;let oe;e[14]!==J||e[15]!==r.sessions||e[16]!==V?.filteredNodes||e[17]!==se?(oe=[...se?V?.filteredNodes??[]:r.sessions].sort(J),e[14]=J,e[15]=r.sessions,e[16]=V?.filteredNodes,e[17]=se,e[18]=oe):oe=e[18];const te=oe;let ke;e[19]!==r.directory||e[20]!==r.folderScopeKey?(ke=r.folderScopeKey??Ps(r.directory??null),e[19]=r.directory,e[20]=r.folderScopeKey,e[21]=ke):ke=e[21];const Ne=ke;let je;e[22]!==Ne||e[23]!==X?(je=Ne?X[Ne]??[]:[],e[22]=Ne,e[23]=X,e[24]=je):je=e[24];const Se=je;let De;if(e[25]!==te){De=new Map;const it=zt=>{zt.forEach(hs=>{De.set(hs.session.id,hs),hs.children.length>0&&it(hs.children)})};it(te),e[25]=te,e[26]=De}else De=e[26];const ye=De;let ge;if(e[27]!==J||e[28]!==ye||e[29]!==Se){let it;e[31]!==J||e[32]!==ye?(it=zt=>{const hs=zt.sessionIds.map(Jt=>ye.get(Jt)).filter(BP).sort(J);return{folder:zt,nodes:hs}},e[31]=J,e[32]=ye,e[33]=it):it=e[33],ge=Se.map(it),e[27]=J,e[28]=ye,e[29]=Se,e[30]=ge}else ge=e[30];const Me=ge;let Ue;if(e[34]!==Me||e[35]!==r.isArchivedBucket||e[36]!==c||e[37]!==d){const it=new Map(Me.map($P)),zt=new Map;for(const{folder:Ut}of Me){if(!Ut.parentId)continue;const os=zt.get(Ut.parentId);os?os.push(Ut.id):zt.set(Ut.parentId,[Ut.id])}const hs=new Map,Jt=Ut=>{const os=hs.get(Ut);if(os!==void 0)return os;const tn=it.get(Ut);if(!tn)return hs.set(Ut,!1),!1;const Zs=zt.get(Ut)??[];if(r.isArchivedBucket&&tn.nodes.length===0){const Ds=Zs.some(on=>Jt(on));return hs.set(Ut,Ds),Ds}if(!c||tn.folder.name.toLowerCase().includes(d)||tn.nodes.length>0)return hs.set(Ut,!0),!0;const Vn=Zs.some(Ds=>Jt(Ds));return hs.set(Ut,Vn),Vn};Ue=Me.filter(Ut=>{const{folder:os}=Ut;return Jt(os.id)}),e[34]=Me,e[35]=r.isArchivedBucket,e[36]=c,e[37]=d,e[38]=Ue}else Ue=e[38];const q=Ue;let Ie;e[39]!==q?(Ie=new Set(q.flatMap(OP)),e[39]=q,e[40]=Ie):Ie=e[40];const Le=Ie;let Pe;if(e[41]!==Le||e[42]!==te){let it;e[44]!==Le?(it=zt=>!Le.has(zt.session.id),e[44]=Le,e[45]=it):it=e[45],Pe=te.filter(it),e[41]=Le,e[42]=te,e[43]=Pe}else Pe=e[43];const he=Pe;let F;e[46]!==q?(F=q.filter(LP),e[46]=q,e[47]=F):F=e[47];const ee=F;if(c&&!ce&&ee.length===0&&he.length===0)return null;const Ce=he.length;let Fe;e[48]!==r.isArchivedBucket||e[49]!==c||e[50]!==ve||e[51]!==H||e[52]!==he?(Fe=r.isArchivedBucket||c||ve?he:he.slice(0,H),e[48]=r.isArchivedBucket,e[49]=c,e[50]=ve,e[51]=H,e[52]=he,e[53]=Fe):Fe=e[53];const we=Fe,Qe=Ce-we.length,pe=FP;let Oe;e[54]!==te?(Oe=pe(te),e[54]=te,e[55]=Oe):Oe=e[55];const nt=Oe;let Re;e[56]!==D||e[57]!==i||e[58]!==k?(Re=i&&k.has(i)?!!k.get(i):D,e[56]=D,e[57]=i,e[58]=k,e[59]=Re):Re=e[59];const de=Re,He=r.directory??null;let st;e[60]!==He?(st=Ps(He),e[60]=He,e[61]=st):st=e[61];const qe=st;let et;e[62]!==r.branch?(et=r.branch?.trim()??null,e[62]=r.branch,e[63]=et):et=e[63];const rt=et;let xe,Ye,_e,We,lt,Je,Ve,yt;e[64]!==r.branch||e[65]!==r.isMain||e[66]!==rt||e[67]!==qe||e[68]!==W||e[69]!==n?(We=qe&&rt?W.get(`${qe}::${rt}`)??null:null,Ve=!!(We&&r.branch),Je=!We&&!r.isMain&&!!r.branch,lt=We?.visualState??null,xe=We&&We.state==="open"&&We.checks?n("sessions.sidebar.group.pr.checksPassed",{success:We.checks.success,total:We.checks.total}):null,Ye=We&&We.state==="open"&&We.checks?[We.checks.failure>0?n("sessions.sidebar.group.pr.failingCount",{count:We.checks.failure}):null,We.checks.pending>0?n("sessions.sidebar.group.pr.pendingCount",{count:We.checks.pending}):null].filter(RP).join(", "):null,_e=We&&We.state==="open"?We.mergeableState==="blocked"||We.mergeableState==="dirty"?n("sessions.sidebar.group.pr.conflictsOrBlocked"):We.mergeableState==="clean"||We.canMerge===!0?n("sessions.sidebar.group.pr.mergeable"):null:null,yt=We&&We.state==="open"&&We.mergeableState?n("sessions.sidebar.group.pr.mergeState",{state:We.mergeableState}):null,e[64]=r.branch,e[65]=r.isMain,e[66]=rt,e[67]=qe,e[68]=W,e[69]=n,e[70]=xe,e[71]=Ye,e[72]=_e,e[73]=We,e[74]=lt,e[75]=Je,e[76]=Ve,e[77]=yt):(xe=e[70],Ye=e[71],_e=e[72],We=e[73],lt=e[74],Je=e[75],Ve=e[76],yt=e[77]);const $t=yt,Gt=We?.base??null,ss=We?.head??null;let wt;e:{if(!We){let it;e[78]!==r.branch||e[79]!==r.label?(it=r.branch&&by(r.branch,r.label)?{label:r.branch,color:null}:null,e[78]=r.branch,e[79]=r.label,e[80]=it):it=e[80],wt=it;break e}switch(We.visualState){case"merged":{let it;e[81]!==n?(it=n("sessions.sidebar.group.pr.status.merged"),e[81]=n,e[82]=it):it=e[82];let zt;e[83]!==it?(zt={label:it,color:"var(--pr-merged)"},e[83]=it,e[84]=zt):zt=e[84],wt=zt;break e}case"open":{let it;e[85]!==We.canMerge||e[86]!==We.checks?.state||e[87]!==We.mergeableState||e[88]!==n?(it=We.canMerge===!0||We.mergeableState==="clean"||We.checks?.state==="success"?{label:n("sessions.sidebar.group.pr.status.readyToMerge"),color:"var(--pr-open)"}:{label:n("sessions.sidebar.group.pr.status.open"),color:"var(--pr-open)"},e[85]=We.canMerge,e[86]=We.checks?.state,e[87]=We.mergeableState,e[88]=n,e[89]=it):it=e[89],wt=it;break e}case"blocked":{let it;e[90]!==We.mergeableState||e[91]!==n?(it=We.mergeableState==="dirty"?n("sessions.sidebar.group.pr.status.mergeConflicts"):n("sessions.sidebar.group.pr.status.mergeBlocked"),e[90]=We.mergeableState,e[91]=n,e[92]=it):it=e[92];let zt;e[93]!==it?(zt={label:it,color:"var(--pr-blocked)"},e[93]=it,e[94]=zt):zt=e[94],wt=zt;break e}case"draft":{let it;e[95]!==n?(it=n("sessions.sidebar.group.pr.status.draft"),e[95]=n,e[96]=it):it=e[96];let zt;e[97]!==it?(zt={label:it,color:"var(--pr-draft)"},e[97]=it,e[98]=zt):zt=e[98],wt=zt;break e}case"closed":{let it;e[99]!==n?(it=n("sessions.sidebar.group.pr.status.closed"),e[99]=n,e[100]=it):it=e[100];let zt;e[101]!==it?(zt={label:it,color:"var(--pr-closed)"},e[101]=it,e[102]=zt):zt=e[102],wt=zt;break e}default:wt=null}}const Dt=wt,Xt=Dt?.color??(lt?`var(--pr-${lt})`:void 0);let Yt;e[103]!==We?.url?(Yt=it=>{it.preventDefault(),it.stopPropagation();const zt=We?.url;zt&&sr(zt)},e[103]=We?.url,e[104]=Yt):Yt=e[104];const ts=Yt;let dt,Rt,is,xs,ps,ws;if(e[105]!==E||e[106]!==M||e[107]!==q||e[108]!==A||e[109]!==b||e[110]!==R||e[111]!==x||e[112]!==Ne||e[113]!==r.directory||e[114]!==r.isArchivedBucket||e[115]!==r.isMain||e[116]!==r.worktree||e[117]!==c||e[118]!==U||e[119]!==S||e[120]!==T||e[121]!==i||e[122]!==v||e[123]!==z||e[124]!==O||e[125]!==y||e[126]!==ee||e[127]!==C||e[128]!==P||e[129]!==w||e[130]!==B||e[131]!==$||e[132]!==N||e[133]!==g||e[134]!==h){const it=(Jt,Ut,os)=>{const tn=q.filter(Ds=>{const{folder:on}=Ds;return on.parentId===Jt.id}),Zs=tn.length>0?s.jsx(s.Fragment,{children:tn.map(Ds=>{const{folder:on,nodes:en}=Ds;return it(on,en,os+1)})}):void 0,nr=Ds=>{const on=q.find(mn=>{const{folder:Sn}=mn;return Sn.id===Ds})?.nodes??[],en=q.filter(mn=>{const{folder:Sn}=mn;return Sn.parentId===Ds});return[...pe(on),...en.flatMap(mn=>{const{folder:Sn}=mn;return nr(Sn.id)})]},Vn=r.isArchivedBucket?nr(Jt.id):[];return s.jsx(DP,{folderId:Jt.id,children:(Ds,on)=>s.jsx(bP,{folder:Jt,sessions:Ut,subFolderItems:Zs,isCollapsed:c?!1:b.has(Jt.id),onToggle:()=>h(Jt.id),onRename:en=>{Ne&&v(Ne,Jt.id,en)},onDelete:()=>{if(r.isArchivedBucket){Nr.requestDelete({sessions:Vn,mode:"session"});return}if(!Ne)return;if(!g){x(Ne,Jt.id);return}const en=q.filter(Sn=>{const{folder:Fn}=Sn;return Fn.parentId===Jt.id}).length,mn=Ut.length;w({scopeKey:Ne,folderId:Jt.id,folderName:Jt.name,subFolderCount:en,sessionCount:mn})},renderSessionNode:y,groupDirectory:r.directory,projectId:i,mobileVariant:S,alwaysShowActions:A,isRenaming:O===Jt.id,renameDraft:O===Jt.id?z:void 0,onRenameDraftChange:en=>B(en),onRenameSave:()=>{const en=z.trim();en&&Ne&&v(Ne,Jt.id,en),$(null),B("")},onRenameCancel:()=>{$(null),B("")},droppableRef:Ds,isDropTarget:on,depth:os,onNewSession:()=>{i&&i!==E&&P(i),C("chat"),S&&N(!1),T({directoryOverride:r.directory,targetFolderId:Jt.id})},onNewSubFolder:os===0?()=>{Ne&&R(Ne,Jt.id)}:void 0,hideActions:!1,archivedBucket:r.isArchivedBucket===!0})},Jt.id)},zt=()=>ee.map(Jt=>{const{folder:Ut,nodes:os}=Jt;return it(Ut,os,0)}),hs=!!(!r.isMain&&r.worktree);Rt=A?hs?"pr-14":"pr-7":U?hs?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":hs?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",dt=TP,is=Ne,xs=q.length>0,e[141]!==M||e[142]!==Ne?(ps=(Jt,Ut)=>{Ne&&M(Ne,Ut,Jt)},e[141]=M,e[142]=Ne,e[143]=ps):ps=e[143],ws=zt(),e[105]=E,e[106]=M,e[107]=q,e[108]=A,e[109]=b,e[110]=R,e[111]=x,e[112]=Ne,e[113]=r.directory,e[114]=r.isArchivedBucket,e[115]=r.isMain,e[116]=r.worktree,e[117]=c,e[118]=U,e[119]=S,e[120]=T,e[121]=i,e[122]=v,e[123]=z,e[124]=O,e[125]=y,e[126]=ee,e[127]=C,e[128]=P,e[129]=w,e[130]=B,e[131]=$,e[132]=N,e[133]=g,e[134]=h,e[135]=dt,e[136]=Rt,e[137]=is,e[138]=xs,e[139]=ps,e[140]=ws}else dt=e[135],Rt=e[136],is=e[137],xs=e[138],ps=e[139],ws=e[140];let qt;if(e[144]!==r.directory||e[145]!==r.isArchivedBucket||e[146]!==i||e[147]!==y||e[148]!==we){let it;e[150]!==r.directory||e[151]!==r.isArchivedBucket||e[152]!==i||e[153]!==y?(it=zt=>y(zt,0,r.directory,i,r.isArchivedBucket===!0),e[150]=r.directory,e[151]=r.isArchivedBucket,e[152]=i,e[153]=y,e[154]=it):it=e[154],qt=we.map(it),e[144]=r.directory,e[145]=r.isArchivedBucket,e[146]=i,e[147]=y,e[148]=we,e[149]=qt}else qt=e[149];let Ge;e[155]!==q.length||e[156]!==r.isArchivedBucket||e[157]!==n||e[158]!==Ce?(Ge=Ce===0&&q.length===0?s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:r.isArchivedBucket?n("sessions.sidebar.group.empty.noArchivedSessions"):n("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,e[155]=q.length,e[156]=r.isArchivedBucket,e[157]=n,e[158]=Ce,e[159]=Ge):Ge=e[159];let St;e[160]!==a||e[161]!==ve||e[162]!==Qe||e[163]!==n||e[164]!==j?(St=Qe>0&&!ve?s.jsx("button",{type:"button",onClick:()=>j(a),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:Qe===1?n("sessions.sidebar.group.showMoreSingle",{count:Qe}):n("sessions.sidebar.group.showMorePlural",{count:Qe})}):null,e[160]=a,e[161]=ve,e[162]=Qe,e[163]=n,e[164]=j,e[165]=St):St=e[165];let Mt;e[166]!==a||e[167]!==ve||e[168]!==H||e[169]!==n||e[170]!==j||e[171]!==Ce?(Mt=ve&&Ce>H?s.jsx("button",{type:"button",onClick:()=>j(a),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:n("sessions.sidebar.group.showFewer")}):null,e[166]=a,e[167]=ve,e[168]=H,e[169]=n,e[170]=j,e[171]=Ce,e[172]=Mt):Mt=e[172];let Nt;e[173]!==dt||e[174]!==is||e[175]!==xs||e[176]!==ps||e[177]!==ws||e[178]!==qt||e[179]!==Ge||e[180]!==St||e[181]!==Mt?(Nt=s.jsxs(dt,{scopeKey:is,hasFolders:xs,onSessionDroppedOnFolder:ps,children:[ws,qt,Ge,St,Mt]}),e[173]=dt,e[174]=is,e[175]=xs,e[176]=ps,e[177]=ws,e[178]=qt,e[179]=Ge,e[180]=St,e[181]=Mt,e[182]=Nt):Nt=e[182];const Kt=Nt,ns=Y?"pb-2 pl-1":"pb-3 pl-4";if(o){let it;e[183]!==ns?(it=me("oc-group-body",ns),e[183]=ns,e[184]=it):it=e[184];let zt;return e[185]!==Kt||e[186]!==it?(zt=s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:it,children:Kt})}),e[185]=Kt,e[186]=it,e[187]=zt):zt=e[187],zt}let js;e[188]===Symbol.for("react.memo_cache_sentinel")?(js=me("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),e[188]=js):js=e[188];let ls;e[189]!==a||e[190]!==ne?(ls=()=>ne(a),e[189]=a,e[190]=ne,e[191]=ls):ls=e[191];let ks;e[192]!==a||e[193]!==ne?(ks=it=>{(it.key==="Enter"||it.key===" ")&&(it.preventDefault(),ne(a))},e[192]=a,e[193]=ne,e[194]=ks):ks=e[194];let Os;e[195]!==r.label||e[196]!==fe||e[197]!==n?(Os=fe?n("sessions.sidebar.group.expandAria",{label:r.label}):n("sessions.sidebar.group.collapseAria",{label:r.label}),e[195]=r.label,e[196]=fe,e[197]=n,e[198]=Os):Os=e[198];const xt=!fe,cs=re?.setActivatorNodeRef;let jt;e[199]!==Rt?(jt=me("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",Rt),e[199]=Rt,e[200]=jt):jt=e[200];let Tt;e[201]!==re?.listeners?(Tt=re?.listeners??{},e[201]=re?.listeners,e[202]=Tt):Tt=e[202];let Z;e[203]!==A||e[204]!==Gt||e[205]!==Xt||e[206]!==xe||e[207]!==Ye||e[208]!==r.branch||e[209]!==r.isArchivedBucket||e[210]!==r.isMain||e[211]!==r.label||e[212]!==r.worktree||e[213]!==ts||e[214]!==ss||e[215]!==fe||e[216]!==$t||e[217]!==_e||e[218]!==d||e[219]!==We||e[220]!==Ve?(Z=Ve&&We?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(It,{children:[s.jsx(Pt,{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:me("h-3.5 w-3.5 shrink-0",A?"hidden":"group-hover/gh:hidden"),style:Xt?{color:Xt}:void 0}),s.jsx("span",{className:me("text-muted-foreground h-3.5 w-3.5 items-center justify-center",A?"inline-flex":"hidden group-hover/gh:inline-flex"),children:fe?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"})})]}),We.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:EP,onClick:ts,children:["#",We.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",We.number]})]})}),s.jsx(At,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Gt||ss?s.jsx("div",{className:"text-muted-foreground truncate",children:Gt&&ss?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Gt}),s.jsx(I,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:ss})]}):s.jsx("span",{children:Gt??ss??""})}):null,$t?s.jsx("div",{className:"text-muted-foreground truncate",children:$t}):null,_e||xe?s.jsxs("div",{className:"text-muted-foreground truncate",children:[_e??"",_e&&xe?" • ":"",xe??"",Ye?` (${Ye})`:""]}):null]})})]}),s.jsx("span",{className:"ml-1 min-w-0 flex-1 truncate leading-none align-middle",children:r.branch})]}):r.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:me("h-3.5 w-3.5 shrink-0 text-muted-foreground",A?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:me("text-muted-foreground h-3.5 w-3.5 items-center justify-center",A?"inline-flex":"hidden group-hover/gh:inline-flex"),children:fe?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:Vi(r.label,d)})]}):!r.isMain||r.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:me("h-3.5 w-3.5 shrink-0 text-muted-foreground",A?"hidden":"group-hover/gh:hidden"),style:Xt?{color:Xt}:void 0}),s.jsx("span",{className:me("text-muted-foreground h-3.5 w-3.5 items-center justify-center",A?"inline-flex":"hidden group-hover/gh:inline-flex"),children:fe?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:Vi(r.label,d)})]}):Vi(r.label,d),e[203]=A,e[204]=Gt,e[205]=Xt,e[206]=xe,e[207]=Ye,e[208]=r.branch,e[209]=r.isArchivedBucket,e[210]=r.isMain,e[211]=r.label,e[212]=r.worktree,e[213]=ts,e[214]=ss,e[215]=fe,e[216]=$t,e[217]=_e,e[218]=d,e[219]=We,e[220]=Ve,e[221]=Z):Z=e[221];let ft;e[222]!==Z?(ft=s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:Z}),e[222]=Z,e[223]=ft):ft=e[223];let kt;e[224]!==Gt||e[225]!==Xt||e[226]!==xe||e[227]!==Ye||e[228]!==r.isArchivedBucket||e[229]!==r.isMain||e[230]!==ss||e[231]!==de||e[232]!==$t||e[233]!==_e||e[234]!==We||e[235]!==Je||e[236]!==Ve||e[237]!==Dt?(kt=Je&&Dt?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[r.isArchivedBucket?s.jsx(I,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!r.isMain||de?Ve&&We?s.jsxs(It,{children:[s.jsx(Pt,{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:Xt?{color:Xt}:void 0})})}),s.jsx(At,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Gt||ss?s.jsx("div",{className:"text-muted-foreground truncate",children:Gt&&ss?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Gt}),s.jsx(I,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:ss})]}):s.jsx("span",{children:Gt??ss??""})}):null,$t?s.jsx("div",{className:"text-muted-foreground truncate",children:$t}):null,_e||xe?s.jsxs("div",{className:"text-muted-foreground truncate",children:[_e??"",_e&&xe?" • ":"",xe??"",Ye?` (${Ye})`:""]}):null]})})]}):s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:Xt?{color:Xt}:void 0}):null,s.jsx("span",{className:me("min-w-0 truncate text-[11px] font-medium",!Dt.color&&"text-muted-foreground/80"),style:Dt.color?{color:Dt.color}:void 0,children:Dt.label})]}):null,e[224]=Gt,e[225]=Xt,e[226]=xe,e[227]=Ye,e[228]=r.isArchivedBucket,e[229]=r.isMain,e[230]=ss,e[231]=de,e[232]=$t,e[233]=_e,e[234]=We,e[235]=Je,e[236]=Ve,e[237]=Dt,e[238]=kt):kt=e[238];let Ht;e[239]!==ft||e[240]!==kt?(Ht=s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[ft,kt]}),e[239]=ft,e[240]=kt,e[241]=Ht):Ht=e[241];let Ns;e[242]!==cs||e[243]!==jt||e[244]!==Tt||e[245]!==Ht?(Ns=s.jsx("div",{ref:cs,className:jt,...Tt,children:Ht}),e[242]=cs,e[243]=jt,e[244]=Tt,e[245]=Ht,e[246]=Ns):Ns=e[246];let Cs;e[247]!==nt||e[248]!==A||e[249]!==r.isArchivedBucket||e[250]!==r.label||e[251]!==n?(Cs=r.isArchivedBucket&&nt.length>0?s.jsx("div",{className:me("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:it=>{it.stopPropagation(),Nr.requestDelete({sessions:nt,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":n("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:r.label}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,e[247]=nt,e[248]=A,e[249]=r.isArchivedBucket,e[250]=r.label,e[251]=n,e[252]=Cs):Cs=e[252];let Ke;e[253]!==nt||e[254]!==A||e[255]!==r.directory||e[256]!==r.isMain||e[257]!==r.label||e[258]!==r.worktree||e[259]!==n?(Ke=r.directory&&!r.isMain&&r.worktree?s.jsx("div",{className:me("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:it=>{it.stopPropagation(),Nr.requestDelete({sessions:nt,mode:"worktree",worktree:r.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":n("sessions.sidebar.group.actions.deleteGroupAria",{label:r.label}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,e[253]=nt,e[254]=A,e[255]=r.directory,e[256]=r.isMain,e[257]=r.label,e[258]=r.worktree,e[259]=n,e[260]=Ke):Ke=e[260];let bt;e[261]!==E||e[262]!==A||e[263]!==r.directory||e[264]!==r.label||e[265]!==S||e[266]!==T||e[267]!==i||e[268]!==C||e[269]!==P||e[270]!==N||e[271]!==n?(bt=r.directory?s.jsx("div",{className:me("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:it=>{it.stopPropagation(),i&&i!==E&&P(i),C("chat"),S&&N(!1),T({directoryOverride:r.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":n("sessions.sidebar.group.actions.newDraftInGroupAria",{label:r.label}),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.project.actions.newDraftSession")})})]})}):null,e[261]=E,e[262]=A,e[263]=r.directory,e[264]=r.label,e[265]=S,e[266]=T,e[267]=i,e[268]=C,e[269]=P,e[270]=N,e[271]=n,e[272]=bt):bt=e[272];let Ct;e[273]!==ls||e[274]!==ks||e[275]!==Os||e[276]!==xt||e[277]!==Ns||e[278]!==Cs||e[279]!==Ke||e[280]!==bt?(Ct=s.jsxs("div",{className:js,onClick:ls,role:"button",tabIndex:0,onKeyDown:ks,"aria-label":Os,"aria-expanded":xt,children:[Ns,Cs,Ke,bt]}),e[273]=ls,e[274]=ks,e[275]=Os,e[276]=xt,e[277]=Ns,e[278]=Cs,e[279]=Ke,e[280]=bt,e[281]=Ct):Ct=e[281];let Ft;e[282]!==Kt||e[283]!==ns||e[284]!==fe?(Ft=fe?null:s.jsx("div",{className:me("oc-group-body",ns),children:Kt}),e[282]=Kt,e[283]=ns,e[284]=fe,e[285]=Ft):Ft=e[285];let Zt;return e[286]!==Ct||e[287]!==Ft?(Zt=s.jsxs("div",{className:"oc-group",children:[Ct,Ft]}),e[286]=Ct,e[287]=Ft,e[288]=Zt):Zt=e[288],Zt}function EP(t){return t.stopPropagation()}function RP(t){return!!t}function FP(t){const e=[],n=r=>{r.forEach(a=>{e.push(a.session),a.children.length>0&&n(a.children)})};return n(t),e}function LP(t){const{folder:e}=t;return!e.parentId}function OP(t){return t.folder.sessionIds}function $P(t){return[t.folder.id,t]}function BP(t){return!!t}function zP(t){return t.foldersMap}function _P(t){return t.displayMode}function VP(t){const e=at.c(37),{t:n}=mt(),{hideDirectoryControls:r,handleOpenDirectoryDialog:a,handleNewSession:i,canOpenMultiRun:o,openMultiRunLauncher:c,headerActionIconClass:d,reserveHeaderActionsSpace:p,headerActionButtonClass:m,isSessionSearchOpen:u,setIsSessionSearchOpen:f,sessionSearchInputRef:b,sessionSearchQuery:h,setSessionSearchQuery:v,hasSessionSearchQuery:x,searchMatchCount:g,collapseAllProjects:w,expandAllProjects:y,openScheduledTasksDialog:k,selectionModeEnabled:D,onToggleSelectionMode:j,showSidebarToggle:S,onToggleSidebar:A,avoidWindowControlsOverlay:E}=t,P=S===void 0?!1:S,C=E===void 0?!1:E,N=Ca(GP),T=Ca(HP),M=Ca(KP),R=Ca(WP);if(r)return null;const O=P?C?"pl-[5.5rem] pr-3":"pl-3 pr-3":"px-2.5 py-1";let z;e[0]!==O?(z=me("select-none flex-shrink-0",O),e[0]=O,e[1]=z):z=e[1];let B;e[2]!==C||e[3]!==P?(B=P&&C?{paddingTop:"var(--oc-safe-area-top, 0px)"}:void 0,e[2]=C,e[3]=P,e[4]=B):B=e[4];let $;e[5]!==C||e[6]!==o||e[7]!==w||e[8]!==N||e[9]!==y||e[10]!==i||e[11]!==a||e[12]!==x||e[13]!==m||e[14]!==d||e[15]!==u||e[16]!==j||e[17]!==A||e[18]!==c||e[19]!==k||e[20]!==p||e[21]!==g||e[22]!==D||e[23]!==b||e[24]!==h||e[25]!==M||e[26]!==f||e[27]!==v||e[28]!==T||e[29]!==P||e[30]!==n||e[31]!==R?($=p?s.jsxs("div",{className:me("flex h-auto flex-col gap-1",P?C?"min-h-[calc(var(--oc-header-height,56px)-var(--oc-safe-area-top,0px))] justify-center":"min-h-[var(--oc-header-height,56px)] justify-center":"min-h-8"),children:[s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[P&&A?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:A,className:"inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50","aria-label":n("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(I,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.closeSessions")})})]}):null,s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:m,"aria-label":n("sessions.sidebar.header.actions.addProject"),children:s.jsx(I,{name:"folder-add",className:d})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.addProject")})})]}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:m,"aria-label":n("sessions.sidebar.header.actions.newSession"),children:s.jsx(I,{name:"chat-new",className:d})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newSession")})})]}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:m,"aria-label":n("sessions.sidebar.header.actions.newMultiRun"),disabled:!o,children:s.jsx(yy,{className:d})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newMultiRun")})})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:k,className:m,"aria-label":n("sessions.sidebar.header.actions.scheduledTasks"),children:s.jsx(I,{name:"calendar-schedule",className:d})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.scheduledTasks")})})]}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>f(UP),className:m,"aria-label":n("sessions.sidebar.header.actions.searchSessions"),"aria-expanded":u,children:s.jsx(I,{name:"search",className:d})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.searchSessions")})})]}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,className:me(m,D&&"bg-interactive-hover text-primary"),"aria-label":n(D?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),"aria-pressed":D,children:s.jsx(I,{name:"checkbox-multiple",className:d})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n(D?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions")})})]}),s.jsxs(_s,{children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:m,"aria-label":n("sessions.sidebar.header.actions.sessionDisplayMode"),children:s.jsx(I,{name:"equalizer-2",className:d})})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.displayMode.label")})})]}),s.jsxs(zs,{align:"end",className:"min-w-[160px]",children:[s.jsxs(Vt,{onClick:()=>M("default"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.default")}),N==="default"?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsxs(Vt,{onClick:()=>M("minimal"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.minimal")}),N==="minimal"?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsx(Tn,{}),s.jsxs(Vt,{onClick:R,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),T?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsx(Tn,{}),s.jsxs(Vt,{onClick:w,className:"flex items-center gap-2",children:[s.jsx(I,{name:"contract-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.collapseAll")})]}),s.jsxs(Vt,{onClick:y,className:"flex items-center gap-2",children:[s.jsx(I,{name:"expand-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.expandAll")})]})]})]})]})]}),u?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:[x?s.jsx("span",{children:g===1?n("sessions.sidebar.header.search.matchCountSingle",{count:g}):n("sessions.sidebar.header.search.matchCountPlural",{count:g})}):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:b,value:h,onChange:Q=>v(Q.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:Q=>{Q.key==="Escape"&&(Q.stopPropagation(),x?v(""):f(!1))}}),h.length>0?s.jsx("button",{type:"button",onClick:()=>v(""),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]}):null,e[5]=C,e[6]=o,e[7]=w,e[8]=N,e[9]=y,e[10]=i,e[11]=a,e[12]=x,e[13]=m,e[14]=d,e[15]=u,e[16]=j,e[17]=A,e[18]=c,e[19]=k,e[20]=p,e[21]=g,e[22]=D,e[23]=b,e[24]=h,e[25]=M,e[26]=f,e[27]=v,e[28]=T,e[29]=P,e[30]=n,e[31]=R,e[32]=$):$=e[32];let _;return e[33]!==z||e[34]!==B||e[35]!==$?(_=s.jsx("div",{className:z,style:B,children:$}),e[33]=z,e[34]=B,e[35]=$,e[36]=_):_=e[36],_}function UP(t){return!t}function WP(t){return t.toggleRecentSection}function KP(t){return t.setDisplayMode}function HP(t){return t.showRecentSection}function GP(t){return t.displayMode}const hf=7;function qP(t){const e=at.c(20),{sections:n,renderSessionNode:r}=t,{t:a}=mt();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[o,c]=l.useState(i);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[1]=d):d=e[1];const[p,m]=l.useState(d);let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=y=>{c(k=>{const D=new Set(k);return D.has(y)?D.delete(y):D.add(y),D})},e[2]=u):u=e[2];const f=u;let b;e[3]===Symbol.for("react.memo_cache_sentinel")?(b=y=>{m(k=>{const D=new Set(k);return D.has(y)?D.delete(y):D.add(y),D})},e[3]=b):b=e[3];const h=b;let v,x,g;if(e[4]!==o||e[5]!==p||e[6]!==r||e[7]!==n||e[8]!==a){g=Symbol.for("react.early_return_sentinel");e:{const y=n.filter(YP);if(y.length===0){g=null;break e}v="space-y-2 pb-2 pt-1";let k;e[12]!==o||e[13]!==p||e[14]!==r||e[15]!==a?(k=D=>{const j=o.has(D.key),S=p.has(D.key),A=S?D.items:D.items.slice(0,hf),E=D.items.length-A.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>f(D.key),className:"group flex w-full items-center gap-1 rounded-md px-0.5 py-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!j,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:j?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:D.title})]}),j?null:s.jsxs("div",{className:me("space-y-0.5 pl-7"),children:[A.map(P=>r(P.node,0,P.groupDirectory,P.projectId,!1,P.secondaryMeta,"recent")),E>0&&!S?s.jsx("button",{type:"button",onClick:()=>h(D.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:E===1?a("sessions.sidebar.group.showMoreSingle",{count:E}):a("sessions.sidebar.group.showMorePlural",{count:E})}):null,S&&D.items.length>hf?s.jsx("button",{type:"button",onClick:()=>h(D.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:a("sessions.sidebar.group.showFewer")}):null]})]},D.key)},e[12]=o,e[13]=p,e[14]=r,e[15]=a,e[16]=k):k=e[16],x=y.map(k)}e[4]=o,e[5]=p,e[6]=r,e[7]=n,e[8]=a,e[9]=v,e[10]=x,e[11]=g}else v=e[9],x=e[10],g=e[11];if(g!==Symbol.for("react.early_return_sentinel"))return g;let w;return e[17]!==v||e[18]!==x?(w=s.jsx("div",{className:v,children:x}),e[17]=v,e[18]=x,e[19]=w):w=e[19],w}function YP(t){return t.items.length>0}const Oc="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 JP(t){const e=at.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:a,onOpenUpdate:i,showRuntimeButtons:o,showUpdateButton:c}=t,d=o===void 0?!0:o,p=c===void 0?!0:c,{t:m}=mt();let u;e[0]!==a||e[1]!==n||e[2]!==r||e[3]!==d||e[4]!==m?(u=d?s.jsxs(s.Fragment,{children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:Oc,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(I,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:Oc,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(I,{name:"question",className:"h-4.5 w-4.5"})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:Oc,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(I,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=a,e[1]=n,e[2]=r,e[3]=d,e[4]=m,e[5]=u):u=e[5];let f;e[6]!==i||e[7]!==p||e[8]!==m?(f=p?s.jsx(be,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:i,children:m("sessions.sidebar.footer.actions.update")}):null,e[6]=i,e[7]=p,e[8]=m,e[9]=f):f=e[9];let b;return e[10]!==u||e[11]!==f?(b=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[u,f]}),e[10]=u,e[11]=f,e[12]=b):b=e[12],b}const QP=t=>{const e=at.c(58),{id:n,projectLabel:r,projectDescription:a,projectIcon:i,projectColor:o,projectIconImage:c,projectIconBackground:d,isCollapsed:p,isActiveProject:m,isRepo:u,isDesktopShell:f,isStuck:b,hideDirectoryControls:h,alwaysShowActions:v,onToggle:x,onNewSession:g,onNewWorktreeSession:w,onRenameStart:y,onClose:k,sentinelRef:D,children:j,showCreateButtons:S,hideHeader:A,openSidebarMenuKey:E,setOpenSidebarMenuKey:P}=t,C=S===void 0?!0:S,N=A===void 0?!1:A,{t:T}=mt(),{currentTheme:M}=Cr();let R;e[0]!==n?(R={id:n},e[0]=n,e[1]=R):R=e[1];const{attributes:O,listeners:z,setNodeRef:B,transform:$,transition:_,isDragging:Q}=Nl(R),[W,ne]=l.useState(!1),re=l.useRef(!1),ue=`project:${n}`,Y=E===ue;let le;e[2]===Symbol.for("react.memo_cache_sentinel")?(le=()=>{ne(!1)},e[2]=le):le=e[2];const J=c?.updatedAt;let L;e[3]!==n||e[4]!==J?(L=[n,J],e[3]=n,e[4]=J,e[5]=L):L=e[5],l.useEffect(le,L);const V=i?Rl[i]:null,K=o?co[o]??null:null;let X;e[6]!==M||e[7]!==n||e[8]!==W||e[9]!==c?(X=W?null:lo({id:n,iconImage:c},{themeVariant:M.metadata.variant,iconColor:M.colors.surface.foreground}),e[6]=M,e[7]=n,e[8]=W,e[9]=c,e[10]=X):X=e[10];const U=X;let ae;e[11]!==ue||e[12]!==P?(ae=ge=>{P(ge?ue:null)},e[11]=ue,e[12]=P,e[13]=ae):ae=e[13];const ve=ae,ie=e6,fe=t6,H=s6;let ce;e[14]===Symbol.for("react.memo_cache_sentinel")?(ce=ge=>{(ge.button===2||ge.button===0&&ge.ctrlKey)&&(re.current=!0)},e[14]=ce):ce=e[14];const se=ce;let oe;e[15]!==x?(oe=()=>{if(re.current){re.current=!1;return}x()},e[15]=x,e[16]=oe):oe=e[16];const te=oe;let ke;e[17]!==$?(ke=Sl.Transform.toString($),e[17]=$,e[18]=ke):ke=e[18];let Ne;e[19]!==ke||e[20]!==_?(Ne={transform:ke,transition:_},e[19]=ke,e[20]=_,e[21]=Ne):Ne=e[21];const je=Q&&"opacity-30";let Se;e[22]!==je?(Se=me("relative",je),e[22]=je,e[23]=Se):Se=e[23];let De;e[24]!==v||e[25]!==O||e[26]!==ve||e[27]!==te||e[28]!==h||e[29]!==N||e[30]!==K||e[31]!==n||e[32]!==U||e[33]!==m||e[34]!==p||e[35]!==f||e[36]!==Y||e[37]!==u||e[38]!==b||e[39]!==z||e[40]!==k||e[41]!==g||e[42]!==w||e[43]!==y||e[44]!==a||e[45]!==d||e[46]!==V||e[47]!==r||e[48]!==D||e[49]!==C||e[50]!==T?(De=N?null:s.jsxs(s.Fragment,{children:[f&&s.jsx("div",{ref:D,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:me("w-full text-left group/project select-none"),style:{backgroundColor:f&&b?"transparent":void 0},children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",...O,children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:se,onClick:te,...z,className:me("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]",u&&!h?v?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":v?"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:me("h-3.5 w-3.5 items-center justify-center text-muted-foreground",v?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:p?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"})}),U?s.jsx("span",{className:me("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",v?"hidden":"inline-flex group-hover/project:hidden group-focus-within/project:hidden"),style:d?{backgroundColor:d}:void 0,children:s.jsx("img",{src:U,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>ne(!0)})}):V?s.jsx(I,{name:V,className:me("h-3.5 w-3.5",v?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:K?{color:K}:void 0}):s.jsx(I,{name:"folder",className:me("h-3.5 w-3.5 text-muted-foreground/80",v?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:K?{color:K}:void 0})]}),s.jsx("span",{className:me("text-[14px] font-normal truncate lowercase",m?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(At,{side:"right",sideOffset:8,children:a})]}),s.jsxs("div",{className:me("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",C?"right-7":"right-0.5"),children:[C&&u&&!h&&w?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ge=>{ge.stopPropagation(),w()},className:me("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",v?"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":T("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(I,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:T("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(_s,{open:Y,onOpenChange:ve,children:[s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:me("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",Y?"opacity-100 pointer-events-auto":v?"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":T("sessions.sidebar.project.actions.projectMenu"),onPointerDown:fe,onMouseDown:H,onClick:ie,children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs(zs,{align:"end",className:"min-w-[180px]",children:[C&&!u&&!h&&g&&s.jsxs(Vt,{onClick:g,children:[s.jsx(I,{name:"add",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.project.actions.newSession")]}),s.jsxs(Vt,{onClick:y,children:[s.jsx(I,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.session.menu.rename")]}),s.jsxs(Vt,{onClick:k,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.project.actions.closeProject")]})]})]})]}),C&&g?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ge=>{ge.stopPropagation(),g()},className:me("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",v?"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":T(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:T(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})})]}),e[24]=v,e[25]=O,e[26]=ve,e[27]=te,e[28]=h,e[29]=N,e[30]=K,e[31]=n,e[32]=U,e[33]=m,e[34]=p,e[35]=f,e[36]=Y,e[37]=u,e[38]=b,e[39]=z,e[40]=k,e[41]=g,e[42]=w,e[43]=y,e[44]=a,e[45]=d,e[46]=V,e[47]=r,e[48]=D,e[49]=C,e[50]=T,e[51]=De):De=e[51];let ye;return e[52]!==j||e[53]!==B||e[54]!==Ne||e[55]!==Se||e[56]!==De?(ye=s.jsxs("div",{ref:B,style:Ne,className:Se,children:[De,j]}),e[52]=j,e[53]=B,e[54]=Ne,e[55]=Se,e[56]=De,e[57]=ye):ye=e[57],ye},XP=t=>{const e=at.c(21),{id:n,disabled:r,children:a}=t,i=r===void 0?!1:r;let o;e[0]!==i||e[1]!==n?(o={id:n,disabled:i},e[0]=i,e[1]=n,e[2]=o):o=e[2];const{listeners:c,setNodeRef:d,setActivatorNodeRef:p,transform:m,transition:u,isDragging:f}=Nl(o);let b;e[3]!==c||e[4]!==p?(b={listeners:c,setActivatorNodeRef:p},e[3]=c,e[4]=p,e[5]=b):b=e[5];const h=b;let v;e[6]!==m?(v=Sl.Transform.toString(m),e[6]=m,e[7]=v):v=e[7];let x;e[8]!==v||e[9]!==u?(x={transform:v,transition:u},e[8]=v,e[9]=u,e[10]=x):x=e[10];const g=f&&"opacity-50";let w;e[11]!==g?(w=me("space-y-0.5 rounded-md",g),e[11]=g,e[12]=w):w=e[12];let y;e[13]!==a||e[14]!==h?(y=typeof a=="function"?a(h):a,e[13]=a,e[14]=h,e[15]=y):y=e[15];let k;return e[16]!==d||e[17]!==x||e[18]!==w||e[19]!==y?(k=s.jsx("div",{ref:d,style:x,className:w,children:y}),e[16]=d,e[17]=x,e[18]=w,e[19]=y,e[20]=k):k=e[20],k},ZP=l.memo(XP);function e6(t){t.stopPropagation()}function t6(t){t.stopPropagation()}function s6(t){t.stopPropagation()}function n6(t){const e=at.c(25),{t:n}=mt();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={activationConstraint:{distance:8}},e[0]=r):r=e[0];let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a={coordinateGetter:Ex},e[1]=a):a=e[1];const i=Hi(ni(Gi,r),ni(Mx,a));let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o={activationConstraint:{distance:8}},e[2]=o):o=e[2];const c=Hi(ni(Gi,o));if(t.projectSections.length===0){const f=(t.mobileVariant,"");let b;e[3]!==f?(b=me("space-y-1 pb-1 pl-2.5 pr-2",f),e[3]=f,e[4]=b):b=e[4];let h;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==b?(h=s.jsxs(Es,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:b,children:[t.topContent,t.emptyState]}),e[5]=t.emptyState,e[6]=t.topContent,e[7]=b,e[8]=h):h=e[8],h}if(t.sectionsForRender.length===0){const f=(t.mobileVariant,"");let b;e[9]!==f?(b=me("space-y-1 pb-1 pl-2.5 pr-2",f),e[9]=f,e[10]=b):b=e[10];let h;return e[11]!==t.searchEmptyState||e[12]!==b?(h=s.jsx(Es,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:b,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=b,e[13]=h):h=e[13],h}const d=(t.mobileVariant,"");let p;e[14]!==d?(p=me("space-y-1 pb-1 pl-2.5 pr-2",d),e[14]=d,e[15]=p):p=e[15];let m;e[16]!==c||e[17]!==i||e[18]!==t||e[19]!==n?(m=t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const f=t.sectionsForRender.find(x=>x.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!f)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const b=f.groups.find(u6)??f.groups.find(d6)??f.groups.find(c6)??f.groups[0];if(!b)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")});const h=f.groups.find(l6);return[b,...h&&h.id!==b.id?[h]:[]].map(x=>{const g=`${f.project.id}:${x.id}`,w=x.id===b.id;return s.jsx(l.Fragment,{children:t.renderGroupSessions(x,g,f.project.id,w,null,!0)},g)})})()}):s.jsx(s.Fragment,{children:s.jsxs(qi,{sensors:i,collisionDetection:Yi,onDragEnd:f=>{if(t.isInlineEditing)return;const{active:b,over:h}=f;if(!h||b.id===h.id)return;const v=t.sectionsForRender.findIndex(g=>g.project.id===b.id),x=t.sectionsForRender.findIndex(g=>g.project.id===h.id);v===-1||x===-1||v===x||t.reorderProjects(v,x)},children:[s.jsx(sl,{items:t.sectionsForRender.map(o6),strategy:Hc,children:t.sectionsForRender.map(f=>{const b=f.project,h=b.id,v=ph(b.label?.trim()||Fa(b.normalizedPath,t.homeDirectory)||b.normalizedPath),x=Qi(b.normalizedPath,t.homeDirectory),g=t.collapsedProjects.has(h),w=h===t.activeProjectId,y=t.projectRepoStatus.get(h),k=t.getOrderedGroups(h,f.groups),D=k.find(i6)??null,j=D?k.filter(S=>S.id!==D.id):k;return s.jsx(QP,{id:h,projectLabel:v,projectDescription:x,projectIcon:b.icon,projectColor:b.color,projectIconImage:b.iconImage,projectIconBackground:b.iconBackground,isCollapsed:g,isActiveProject:w,isRepo:!!y,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(h),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onToggle:()=>t.toggleProject(h),onNewSession:()=>{h!==t.activeProjectId&&t.setActiveProjectIdOnly(h),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:b.normalizedPath})},onNewWorktreeSession:()=>{h!==t.activeProjectId&&t.setActiveProjectIdOnly(h),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(h),onClose:()=>t.removeProject(h),sentinelRef:S=>{t.projectHeaderSentinelRefs.current.set(h,S)},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:f.groups.length>0?s.jsxs(qi,{sensors:c,collisionDetection:Yi,onDragEnd:S=>{if(t.isInlineEditing)return;const{active:A,over:E}=S;if(!E||A.id===E.id)return;const P=j.findIndex(M=>M.id===A.id),C=j.findIndex(M=>M.id===E.id);if(P===-1||C===-1||P===C)return;const N=Ff(j,P,C).map(a6),T=D?[D.id,...N]:N;t.setGroupOrderByProject(M=>{const R=new Map(M);return R.set(h,T),R})},children:[D?t.renderGroupSessions(D,`${h}:${D.id}`,h,!0):null,s.jsx(sl,{items:j.map(r6),strategy:Hc,children:j.map(S=>{const A=`${h}:${S.id}`;return s.jsx(ZP,{id:S.id,disabled:t.isInlineEditing,children:E=>t.renderGroupSessions(S,A,h,!1,E)},S.id)})}),s.jsx(nl,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})},h)})}),s.jsx(nl,{dropAnimation:null})]})}),e[16]=c,e[17]=i,e[18]=t,e[19]=n,e[20]=m):m=e[20];let u;return e[21]!==t.topContent||e[22]!==p||e[23]!==m?(u=s.jsxs(Es,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:p,children:[t.topContent,m]}),e[21]=t.topContent,e[22]=p,e[23]=m,e[24]=u):u=e[24],u}function r6(t){return t.id}function a6(t){return t.id}function i6(t){return t.isMain}function o6(t){return t.project.id}function l6(t){return t.isArchivedBucket}function c6(t){return t.isMain}function d6(t){return t.sessions.length>0}function u6(t){return t.isMain&&t.sessions.length>0}function m6(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(void 0,{month:"short"}),r=e.getDate(),a=e.getFullYear(),i=String(e.getHours()).padStart(2,"0"),o=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${a}, ${i}:${o}`}function p6(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 f6(t){const e=t.info.role==="user"?"User":"Assistant",n=m6(t.info.time?.created),r=p6(t),a=n&&r?`${n} (${r})`:n||r;return a?`**${e}**
|
|
182
|
+
|
|
183
|
+
*${a}*`:`**${e}**`}function h6(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function Rg(t){const e=f6(t),n=h6(t.parts).trim();return n?`${e}
|
|
184
|
+
|
|
185
|
+
${n}`:""}function Fg(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",a=`${n} Sub-agent: ${t.title}${r}
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
`,i=t.records.map(Rg).filter(Boolean).join(`
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
`),o=[a+i];for(const c of t.children)o.push(Fg(c,e+1));return o.join(`
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
`)}function g6(t,e,n){const r=e?.trim()||"Session",a=new Date().toISOString().split("T")[0],i=`# ${r}
|
|
198
|
+
|
|
199
|
+
*Exported on ${a}*
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
`,o=t.map(Rg).filter(Boolean).join(`
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
`);let c=i+o;if(n&&n.length>0){const d=n.map(p=>Fg(p,1)).join(`
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
`);c+=`
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
`+d}return c}function x6(t,e){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),a=document.createElement("a");a.href=r,a.download=e,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(r)}async function b6(t,e){const n=await vy(e,t);if(n)return n;if(!un())return null;try{const r=await fetch("/api/vscode/save-markdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fileName:e,content:t})});if(!r.ok)return null;const a=await r.json();if(a.saved!==!0)return null;const i=typeof a.path=="string"?a.path.trim():"";return i.length>0?i:null}catch{return null}}async function y6(t){const e=hr()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await wy(t)?!0:rl(t)}function v6(){return Bd()}function w6(t){const r=(t?.trim()||"session").normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").slice(0,60)||"session",a=new Date().toISOString().split("T")[0];return`${r}-${a}.md`}const j6=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const a of t){r.has(a)||(r.add(a),n.push(a));const i=e.get(a);if(i)for(const o of i)r.has(o)||(r.add(o),n.push(o))}return n},pr=ar()((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,a)=>{const i=e(),o=new Set(i.selectedIds);let c=i.scopeKey,d=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(o.clear(),c=r,d=null):c===null&&r!==null&&(c=r);const m=a&&a.length>0?[n,...a]:[n];if(o.has(n)){for(const f of m)o.delete(f);d===n&&(d=null)}else{for(const f of m)o.add(f);d=n}o.size===0?t({selectedIds:o,scopeKey:null,anchorId:null}):t({selectedIds:o,scopeKey:c,anchorId:d})},setRange:(n,r,a,i,o)=>{const c=e();if(a.length===0)return;const d=n&&a.includes(n)?n:a[0],p=a.indexOf(d),m=a.indexOf(r);if(p<0||m<0)return;const[u,f]=p<=m?[p,m]:[m,p],b=a.slice(u,f+1),h=j6(b,o),x=i!==null&&c.scopeKey!==null&&i!==c.scopeKey?new Set:new Set(c.selectedIds);for(const g of h)x.add(g);t({selectedIds:x,scopeKey:i??c.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 a=new Set(r.selectedIds);for(const i of n)a.delete(i);a.size!==r.selectedIds.size&&(a.size===0?t({selectedIds:a,scopeKey:null,anchorId:null}):t({selectedIds:a}))}})),N6=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,tl=t=>{if(!t)return null;const e=t.split("/");if(e.length!==3&&e.length!==4)return null;const[n,r,a,i]=e;if(!N6.test(n)||!r?.trim()||!a?.trim()||r!==r.trim()||a!==a.trim())return null;if(e.length===3)return{groupSlug:n,providerID:r,modelID:a,fusion:!1};if(i==="fusion")return{groupSlug:n,providerID:r,modelID:a,fusion:!0};if(!/^\d+$/.test(i))return null;const o=Number.parseInt(i,10);return!Number.isSafeInteger(o)||o<=0?null:{groupSlug:n,providerID:r,modelID:a,index:o,fusion:!1}},S6=(t,e,n)=>`${t}/${e}/${n}/fusion`,Lg=t=>{const e=at.c(35),{value:n,onChange:r,className:a,disabled:i,id:o,portalToBody:c}=t,{t:d}=mt(),p=gt(k6),m=gt(C6),u=gt(I6);let f;e[0]!==p?(f=p(),e[0]=p,e[1]=f):f=e[1];const b=f;let h;e[2]!==b?(h=b.filter(P6),e[2]=b,e[3]=h):h=e[3];const v=h;let x,g;e[4]!==m?(x=()=>{m()},g=[m],e[4]=m,e[5]=x,e[6]=g):(x=e[5],g=e[6]),l.useEffect(x,g);let w,y;e[7]!==u||e[8]!==i||e[9]!==r||e[10]!==v||e[11]!==n?(w=()=>{if(i)return;const N=n.trim();if(N.length>0&&v.some(R=>R.name===N))return;const T=typeof u=="string"&&u.trim().length>0?u.trim():null;if(T&&v.some(R=>R.name===T)){r(T);return}const M=v[0]?.name;M&&r(M)},y=[u,i,r,v,n],e[7]=u,e[8]=i,e[9]=r,e[10]=v,e[11]=n,e[12]=w,e[13]=y):(w=e[12],y=e[13]),l.useEffect(w,y);const k=n.trim().length>0?n:void 0;let D;e[14]!==a?(D=me("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",a),e[14]=a,e[15]=D):D=e[15];let j;e[16]!==d?(j=d("multirun.agentSelector.placeholder"),e[16]=d,e[17]=j):j=e[17];let S;e[18]!==j?(S=s.jsx(bs,{placeholder:j}),e[18]=j,e[19]=S):S=e[19];let A;e[20]!==o||e[21]!==D||e[22]!==S?(A=s.jsx(us,{id:o,size:"lg",className:D,children:S}),e[20]=o,e[21]=D,e[22]=S,e[23]=A):A=e[23];let E;e[24]!==v?(E=v.length>0&&s.jsx(Xc,{children:v.map(A6)}),e[24]=v,e[25]=E):E=e[25];let P;e[26]!==c||e[27]!==E?(P=s.jsx(ms,{fitContent:!0,portalToBody:c,children:E}),e[26]=c,e[27]=E,e[28]=P):P=e[28];let C;return e[29]!==i||e[30]!==r||e[31]!==k||e[32]!==A||e[33]!==P?(C=s.jsxs(ds,{value:k,onValueChange:r,disabled:i,children:[A,P]}),e[29]=i,e[30]=r,e[31]=k,e[32]=A,e[33]=P,e[34]=C):C=e[34],C};function k6(t){return t.getVisibleAgents}function C6(t){return t.loadAgents}function I6(t){return t.currentAgentName}function P6(t){return t.mode!=="subagent"}function A6(t){return s.jsx(Lt,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const Og="h-7",wl=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,D6=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),T6=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=D6.format(t);return e.endsWith(".0")?e.slice(0,-2):e},M6=t=>{const e=at.c(12),{model:n,instanceIndex:r,totalSameModel:a,onRemove:i}=t,o=n.displayName||`${n.providerID}/${n.modelID}`,c=a>1?`${o} (${r})`:o;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=me("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",Og),e[0]=d):d=e[0];let p;e[1]!==n.providerID?(p=s.jsx(jn,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=p):p=e[2];let m;e[3]!==c?(m=s.jsx("span",{className:"typography-meta font-medium truncate max-w-[140px]",children:c}),e[3]=c,e[4]=m):m=e[4];let u;e[5]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(I,{name:"close",className:"h-3.5 w-3.5"}),e[5]=u):u=e[5];let f;e[6]!==i?(f=s.jsx("button",{type:"button",onClick:i,className:"text-muted-foreground hover:text-foreground ml-0.5",children:u}),e[6]=i,e[7]=f):f=e[7];let b;return e[8]!==p||e[9]!==m||e[10]!==f?(b=s.jsxs("div",{className:d,children:[p,m,f]}),e[8]=p,e[9]=m,e[10]=f,e[11]=b):b=e[11],b},$g=({selectedModels:t,onAdd:e,onRemove:n,onUpdate:r,minModels:a,addButtonLabel:i,showChips:o=!0,maxModels:c,addButtonClassName:d,dropdownSide:p="top",dropdownClassName:m,containerClassName:u,triggerIcon:f})=>{const{t:b}=mt(),h=gt(Y=>Y.providers),v=gt(Y=>Y.modelsMetadata),{favoriteModelsList:x,recentModelsList:g}=Yf(),[w,y]=l.useState(!1),[k,D]=l.useState(""),[j,S]=l.useState(0),[A,E]=l.useState(null),P=l.useRef(null),C=l.useRef(null),N=l.useRef(null),T=l.useRef([]),M=c===1,R=c===void 0||t.length<c||M,O=l.useMemo(()=>{const Y=new Map;for(const le of t){const J=`${le.providerID}:${le.modelID}`;Y.set(J,(Y.get(J)||0)+1)}return Y},[t]),z=l.useCallback(Y=>t.filter(J=>J.providerID===Y.providerID&&J.modelID===Y.modelID).findIndex(J=>J.instanceId===Y.instanceId)+1,[t]),B=(Y,le)=>{const J=`${Y}/${le}`;return v.get(J)},$=Y=>{const le=Y?.name||Y?.id||"",J=String(le);return J.length>40?J.substring(0,37)+"...":J},_=l.useCallback((Y,le)=>{if(!k.trim())return!0;const J=k.toLowerCase();return Y.toLowerCase().includes(J)||le.toLowerCase().includes(J)},[k]),Q=l.useMemo(()=>x.filter(({model:Y,providerID:le})=>{const L=h.find(K=>K.id===le)?.name||le,V=$(Y);return _(V,L)}),[x,h,_]),W=l.useMemo(()=>g.filter(({model:Y,providerID:le})=>{const L=h.find(K=>K.id===le)?.name||le,V=$(Y);return _(V,L)}),[g,h,_]),ne=l.useMemo(()=>h.map(Y=>{const J=(Array.isArray(Y.models)?Y.models:[]).filter(L=>{const V=$(L);return _(V,Y.name||Y.id||"")});return{...Y,models:J}}).filter(Y=>Y.models.length>0),[h,_]),re=Q.length>0||W.length>0||ne.length>0;l.useEffect(()=>{if(!w||!N.current)return;const Y=N.current.getBoundingClientRect();if(p==="bottom"){const X=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-Y.bottom-16-112;E(Math.max(160,Math.min(320,X)));return}let le=N.current.parentElement;for(;le&&!(le.getAttribute("role")==="dialog"||le.hasAttribute("data-scroll-shadow"));){const V=getComputedStyle(le);if(V.overflow==="auto"||V.overflow==="hidden"||V.overflowY==="auto"||V.overflowY==="hidden")break;le=le.parentElement}const J=le?le.getBoundingClientRect().top:0,L=Y.top-J-16;E(Math.max(150,Math.min(300,L)))},[p,w]),l.useEffect(()=>{w&&P.current&&P.current.focus()},[w]),l.useEffect(()=>{!R&&w&&(y(!1),D(""),S(0))},[R,w]),l.useEffect(()=>{if(!w)return;const Y=le=>{C.current&&!C.current.contains(le.target)&&(y(!1),D(""),S(0))};return document.addEventListener("mousedown",Y),()=>document.removeEventListener("mousedown",Y)},[w]),l.useEffect(()=>{S(0)},[k]);const ue=(Y,le,J,L,V,K)=>{const X=`${le}:${J}`,U=O.get(X)||0,ae=B(le,J),ve=T6(ae?.limit?.context),ie=L==="fav"||L==="recent";return s.jsxs("button",{ref:fe=>{T.current[V]=fe},type:"button",disabled:!R,onClick:()=>{const fe={providerID:le,modelID:J,displayName:Y.name||J,instanceId:wl()};if(M&&t.length>0&&r){r(0,fe),y(!1),D(""),S(0);return}e({...fe}),M&&(y(!1),D(""),S(0))},onMouseEnter:()=>S(V),className:me("w-full text-left px-2 py-1.5 rounded-md typography-meta transition-colors flex items-center gap-2",R&&(K?"bg-interactive-selection":"hover:bg-interactive-hover/50"),!R&&"cursor-not-allowed opacity-60"),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[ie&&s.jsx(jn,{providerId:le,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(Y)}),ve&&s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:ve})]}),U>0&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:["×",U]})]},`${L}-${X}`)};return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[s.jsxs("div",{className:me("relative",u),ref:C,children:[s.jsxs(be,{ref:N,type:"button",variant:"outline",size:"sm",className:me(Og,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",d),disabled:!R,onClick:()=>{y(!w)},children:[f??s.jsx(I,{name:"add",className:"h-3.5 w-3.5 mr-1"}),i??b("multirun.modelMultiSelect.actions.addModel")]}),w&&(()=>{const Y=[];Q.forEach(({model:V,providerID:K,modelID:X})=>{Y.push({model:V,providerID:K,modelID:X,section:"fav"})}),W.forEach(({model:V,providerID:K,modelID:X})=>{Y.push({model:V,providerID:K,modelID:X,section:"recent"})}),ne.forEach(V=>{V.models.forEach(K=>{Y.push({model:K,providerID:V.id,modelID:K.id,section:"provider"})})});const le=Y.length,J=V=>{if(!jy(V))if(V.key==="ArrowDown"){V.preventDefault(),V.stopPropagation();const K=(j+1)%Math.max(1,le);S(K),setTimeout(()=>{T.current[K]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(V.key==="ArrowUp"){V.preventDefault(),V.stopPropagation();const K=(j-1+Math.max(1,le))%Math.max(1,le);S(K),setTimeout(()=>{T.current[K]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(V.key==="Enter"){V.preventDefault(),V.stopPropagation();const K=Y[j];if(K&&R){const X={providerID:K.providerID,modelID:K.modelID,displayName:K.model.name||K.modelID,instanceId:wl()};M&&t.length>0&&r?r(0,X):e(X),M&&(y(!1),D(""),S(0))}}else V.key==="Escape"&&(V.preventDefault(),V.stopPropagation(),y(!1),D(""),S(0))};let L=0;return s.jsxs("div",{className:me("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",p==="top"?"bottom-full mb-1":"top-full mt-1",m),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:[s.jsx("div",{className:"p-2 border-b border-border/40",children:s.jsxs("div",{className:"relative",children:[s.jsx(I,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Wt,{ref:P,type:"text",placeholder:b("multirun.modelMultiSelect.search.placeholder"),value:k,onChange:V=>D(V.target.value),onKeyDown:J,className:"h-8 pl-8 typography-meta"})]})}),s.jsx(Es,{outerClassName:"flex-1",style:{maxHeight:A?`${A}px`:"300px"},children:s.jsxs("div",{className:"p-1",children:[!re&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:b("multirun.modelMultiSelect.search.noResults")}),Q.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(I,{name:"star-fill",className:"h-4 w-4 text-primary"}),b("multirun.modelMultiSelect.sections.favorites")]}),Q.map(({model:V,providerID:K,modelID:X})=>{const U=L++;return ue(V,K,X,"fav",U,j===U)})]}),W.length>0&&s.jsxs(s.Fragment,{children:[Q.length>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(I,{name:"time",className:"h-4 w-4"}),b("multirun.modelMultiSelect.sections.recent")]}),W.map(({model:V,providerID:K,modelID:X})=>{const U=L++;return ue(V,K,X,"recent",U,j===U)})]}),(Q.length>0||W.length>0)&&ne.length>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),ne.map((V,K)=>s.jsxs(l.Fragment,{children:[K>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(jn,{providerId:V.id,className:"h-4 w-4 flex-shrink-0"}),V.name]}),V.models.map(X=>{const U=L++;return ue(X,V.id,X.id,"provider",U,j===U)})]},V.id))]})}),s.jsx("div",{className:"px-3 pt-1 pb-1.5 border-t border-border/40 typography-micro text-muted-foreground",children:b("multirun.modelMultiSelect.keyboard.hint")})]})})()]}),o&&t.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:t.map((Y,le)=>{const J=`${Y.providerID}:${Y.modelID}`,L=O.get(J)||1,V=z(Y),X=h.find(fe=>fe.id===Y.providerID)?.models.find(fe=>fe.id===Y.modelID),U=X?.variants?Object.keys(X.variants):[],ae=U.length>0,ve="__default__",ie=Y.variant??ve;return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(M6,{model:Y,instanceIndex:V,totalSameModel:L,onRemove:()=>n(le)}),ae&&s.jsxs(ds,{value:ie,onValueChange:fe=>{if(!r)return;r(le,{...Y,variant:fe===ve?void 0:fe})},children:[s.jsxs(us,{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:me("h-3.5 w-3.5 flex-shrink-0",ie===ve?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(bs,{placeholder:b("multirun.modelMultiSelect.variant.placeholder"),children:fe=>fe===ve?b("multirun.modelMultiSelect.variant.default"):fe})]}),s.jsxs(ms,{fitContent:!0,children:[s.jsx(Lt,{value:ve,className:"pr-2 [&>span:first-child]:hidden",children:b("multirun.modelMultiSelect.variant.default")}),U.map(fe=>s.jsx(Lt,{value:fe,className:"pr-2 [&>span:first-child]:hidden",children:fe},fe))]})]})]},Y.instanceId)})})]}),a!==void 0&&t.length<a&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:c!==void 0?b("multirun.modelMultiSelect.validation.minToMax",{min:a,max:c}):b("multirun.modelMultiSelect.validation.minOnly",{min:a})})]})},E6=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
|
|
216
|
+
|
|
217
|
+
--- RESULT ${n+1}: ${r} ---
|
|
218
|
+
${e.trim()}
|
|
219
|
+
--- END RESULT ${n+1} ---`},gf=(t,e)=>_t.getState().getWorktreeMetadata(t)?.projectDirectory??e,R6=async t=>{const e=t.directory??void 0,n=Ny(t.session.id,e);if(n.length===0&&t.directory){const a=(await rn.withDirectory(t.directory,()=>rn.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let i=a.length-1;i>=0;i-=1){const o=a[i];if(o.info?.role==="assistant")return Ou(o.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const a=n[r];if(a.role==="assistant")return Ou(Sy(a.id,e)).trim()}return""};function F6({session:t,open:e,onOpenChange:n}){const{t:r}=mt(),a=Dd(),i=Ia(B=>B.activeSessions),o=Ia(B=>B.archivedSessions),c=gt(B=>B.providers),d=gt(B=>B.currentProviderId),p=gt(B=>B.currentModelId),m=gt(B=>B.currentAgentName),[u,f]=l.useState(d??""),[b,h]=l.useState(p??""),[v,x]=l.useState(()=>d&&p?[{providerID:d,modelID:p,instanceId:wl()}]:[]),[g,w]=l.useState(""),[y,k]=l.useState(m??""),[D,j]=l.useState([]),[S,A]=l.useState(!1),E=l.useMemo(()=>tl(t.title),[t.title]),P=l.useMemo(()=>{const B=new Map;for(const $ of a)B.set($.id,$);for(const $ of i)B.set($.id,$);for(const $ of o)B.set($.id,$);return t.id&&B.set(t.id,t),Array.from(B.values())},[i,o,a,t]);l.useEffect(()=>{if(!e||!E)return;const B=_t.getState().getDirectoryForSession(t.id),$=gf(t.id,B),_=P.map(Q=>{const W=tl(Q.title);if(!W||W.groupSlug!==E.groupSlug||W.fusion)return null;const ne=_t.getState().getDirectoryForSession(Q.id)??_i(Q),re=gf(Q.id,ne);return $&&re&&$!==re?null:{session:Q,directory:ne,projectDirectory:re}}).filter(Q=>Q!==null).sort((Q,W)=>(Q.session.time?.created??0)-(W.session.time?.created??0));j(_)},[P,e,E,t.id]);const N=c.find(B=>B.id===u)?.models.find(B=>B.id===b),T=N?.variants?Object.keys(N.variants):[],M=!!(E&&u&&b&&D.length>0&&!S),R=l.useCallback(B=>{x([B]),f(B.providerID),h(B.modelID),w("")},[]),O=v[0]?.displayName||v[0]?.modelID||r("multirun.fusion.model.placeholder"),z=async()=>{if(!(!E||!u||!b)){A(!0);try{const B=await Promise.all(D.map(ue=>R6(ue))),$=D.map((ue,Y)=>({source:ue,text:B[Y]??""})).filter(ue=>ue.text.trim().length>0);if($.length===0){G.error(r("multirun.fusion.toast.noOutputs"));return}const _=D[0]?.projectDirectory??D[0]?.directory??null,Q=S6(E.groupSlug,u,b),[W,ne]=await Promise.all([Nn("session.fusion.visible"),Nn("session.fusion.instructions")]),re=await _t.getState().createSession(Q,_,null);if(!re)throw new Error("Failed to create fusion session");_t.getState().setCurrentSession(re.id,_),n(!1),await rn.withDirectory(_??rn.getDirectory(),()=>rn.sendMessage({id:re.id,providerID:u,modelID:b,variant:g||void 0,agent:y||void 0,text:W,additionalParts:[{text:ne,synthetic:!0},...$.map((ue,Y)=>({text:E6(ue.source,ue.text,Y),synthetic:!0})),{text:`
|
|
220
|
+
|
|
221
|
+
--- FUSION INPUTS END ---
|
|
222
|
+
Now write the final fused answer.`,synthetic:!0}]}))}catch(B){console.error("[MultiRunFusion] Failed to start fusion",B),G.error(r("multirun.fusion.toast.failed"))}finally{A(!1)}}};return s.jsx(vs,{open:e,onOpenChange:n,children:s.jsxs(ys,{className:"max-w-xl overflow-visible",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:r("multirun.fusion.title")}),s.jsx(Fs,{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($g,{selectedModels:v,onAdd:R,onUpdate:(B,$)=>R($),onRemove:()=>{x([]),f(""),h(""),w("")},maxModels:1,addButtonLabel:O,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:u?s.jsx(jn,{providerId:u,className:"h-3.5 w-3.5 mr-1"}):void 0})}),T.length>0?s.jsxs(ds,{value:g||"__default__",onValueChange:B=>w(B==="__default__"?"":B),children:[s.jsxs(us,{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(bs,{children:B=>B==="__default__"?r("multirun.modelMultiSelect.variant.default"):B})]}),s.jsxs(ms,{fitContent:!0,portalToBody:!0,children:[s.jsx(Lt,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),T.map(B=>s.jsx(Lt,{value:B,children:B},B))]})]}):null,s.jsx(Lg,{value:y,onChange:k,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:D.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:D.map(B=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(jn,{providerId:tl(B.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:B.session.title||B.session.id}),s.jsx("button",{type:"button",onClick:()=>j($=>$.filter(_=>_.session.id!==B.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"h-4 w-4"})})]},B.session.id))})]}),s.jsxs(Hs,{children:[s.jsx(be,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(be,{onClick:z,disabled:!M,children:r(S?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function L6(t){const e=at.c(7);let n,r,a,i,o;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"}),a=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),i=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),o=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=a,e[3]=i,e[4]=o):(n=e[0],r=e[1],a=e[2],i=e[3],o=e[4]);let c;return e[5]!==t?(c=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,a,i,o]}),e[5]=t,e[6]=c):c=e[6],c}const xf=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),ja=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(ja(n,e))return!0;return!1},kd=(t,e,n,r)=>{if(!e)return!1;if(`${n}:${r?"archived":"active"}:${t.session.id}`===e)return!0;for(const i of t.children)if(kd(i,e,n,r))return!0;return!1},O6=(t,e)=>{const n=t.node.session,r=e.node.session,a=n.id,i=r.id;if(a!==i||t.node.session!==e.node.session||xf(t.node)!==xf(e.node)||t.depth!==e.depth||t.groupDirectory!==e.groupDirectory||t.projectId!==e.projectId||t.archivedBucket!==e.archivedBucket)return!1;if(t.currentSessionId!==e.currentSessionId){const m=ja(t.node,t.currentSessionId),u=ja(e.node,e.currentSessionId);if(m||u)return!1}if(t.pinnedSessionIds.has(a)!==e.pinnedSessionIds.has(i)||t.expandedParents.has(a)!==e.expandedParents.has(i)||t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const m=ja(t.node,t.editingId),u=ja(e.node,e.editingId);if(m||u)return!1}if(t.editTitle!==e.editTitle){const m=ja(t.node,t.editingId),u=ja(e.node,e.editingId);if(m||u)return!1}if(t.copiedSessionId===a!=(e.copiedSessionId===i))return!1;const o=kd(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),c=kd(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(o!==c)return!1;const d=Ps(n.directory??null)??Ps(t.groupDirectory??null),p=Ps(r.directory??null)??Ps(e.groupDirectory??null);return!(d!==p||(d?t.directoryStatus.get(d):null)!==(p?e.directoryStatus.get(p):null)||(t.secondaryMeta?.projectLabel??null)!==(e.secondaryMeta?.projectLabel??null)||(t.secondaryMeta?.branchLabel??null)!==(e.secondaryMeta?.branchLabel??null)||t.mobileVariant!==e.mobileVariant||t.alwaysShowActions!==e.alwaysShowActions||(t.renderContext??"project")!==(e.renderContext??"project")||t.renamingFolderId!==e.renamingFolderId)};function $6(t){const{t:e}=mt(),{node:n,depth:r=0,groupDirectory:a,projectId:i,archivedBucket:o=!1,directoryStatus:c,currentSessionId:d,pinnedSessionIds:p,expandedParents:m,hasSessionSearchQuery:u,normalizedSessionSearchQuery:f,notifyOnSubtasks:b,editingId:h,setEditingId:v,editTitle:x,setEditTitle:g,handleSaveEdit:w,handleCancelEdit:y,toggleParent:k,handleSessionSelect:D,handleSessionDoubleClick:j,togglePinnedSession:S,handleShareSession:A,copiedSessionId:E,handleCopyShareUrl:P,handleUnshareSession:C,openSidebarMenuKey:N,setOpenSidebarMenuKey:T,renamingFolderId:M,getFoldersForScope:R,getSessionFolderId:O,removeSessionFromFolder:z,addSessionToFolder:B,createFolderAndStartRename:$,openContextPanelTab:_,handleDeleteSession:Q,mobileVariant:W,alwaysShowActions:ne,renderSessionNode:re,secondaryMeta:ue,renderContext:Y="project"}=t,le=!!ue?.projectLabel,J=!!ue?.branchLabel,V=Ca(xt=>xt.displayMode)==="minimal",K=l.useMemo(()=>un(),[]),X=l.useMemo(()=>Td(),[]),U=K?"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",ae=K?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",ve=!o&&!W,ie=V?K?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":K?ve?"group-hover:pr-12":"group-hover:pr-5":ve?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",fe=ve?"pr-13":"pr-7",H=l.useRef(!1),[ce,se]=l.useState(!1),oe=n.session,ke=Wf(oe.id)??oe,Ne=Ps(oe.directory??null)??Ps(a??null),je=ky(Ne??void 0),Se=Wd(),De=pr(xt=>xt.enabled),ye=pr(l.useCallback(xt=>xt.selectedIds.has(oe.id),[oe.id])),ge=pr(xt=>xt.toggleSelected),Me=pr(xt=>xt.setRange),Ue=l.useCallback(xt=>{const cs=[],jt=Tt=>{Tt.children.forEach(Z=>{cs.push(Z.session.id),jt(Z)})};return jt(xt),cs},[]),[q,Ie]=l.useState(!1),[Le,Pe]=l.useState(!0),he=`${Y}:${o?"archived":"active"}:${oe.id}`,F=fh(l.useCallback(xt=>!!xt.sessionMemoryState.get(oe.id)?.isZombie,[oe.id])),ee=Cy(oe.id),Ce=Iy(oe.id,Ne??void 0),we=(Ne?c.get(Ne):null)==="missing",Qe=d===oe.id,pe=ke.title||e("sessions.sidebar.session.untitled"),Oe=n.children.length>0,nt=p.has(oe.id),Re=u?!0:m.has(oe.id),de=!!ke.parentID,st=Py(oe.id)>0&&(!de||b),qe=ke.summary,et=Hf(qe),rt=ke.time?.updated||ke.time?.created||Date.now(),xe=Ay(rt),Ye=Ey(rt),_e=N===he,We=l.useMemo(()=>tl(ke.title)!==null,[ke.title]),[lt,Je]=l.useState(!1),Ve=l.useMemo(()=>Ue(n).length,[Ue,n]),yt=l.useCallback(async xt=>{const cs=[];let jt=0;for(const Tt of xt)try{await Se.ensureSessionRenderable(Tt.session.id);const Z=$u(je.getState(),Tt.session.id).list,ft=Tt.session.title||e("sessions.sidebar.session.export.untitledSubagent"),kt=Tt.session.agent,Ht=await yt(Tt.children);jt+=Ht.skipped,cs.push({title:ft,agent:kt,records:Z,children:Ht.children})}catch{jt+=Ue(Tt).length+1}return{children:cs,skipped:jt}},[Ue,je,Se,e]),$t=l.useCallback(xt=>{xt<=0||G.warning(xt===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:xt}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:xt}))},[e]),Gt=l.useCallback(async xt=>{if(!Ne){G.error(e("sessions.sidebar.session.export.nothingToExport"));return}await Se.ensureSessionRenderable(oe.id);const cs=$u(je.getState(),oe.id).list;if(cs.length===0){G.error(e("sessions.sidebar.session.export.nothingToExport"));return}let jt,Tt=0;if(xt&&n.children.length>0){const Ht=await yt(n.children);jt=Ht.children,Tt=Ht.skipped}const Z=g6(cs,ke.title??null,jt),ft=w6(ke.title??null),kt=await b6(Z,ft);if(kt){G.success(e("sessions.sidebar.session.export.success"),{action:{label:e(v6()),onClick:()=>{y6(kt).then(Ht=>{Ht||G.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),$t(Tt);return}x6(Z,ft),G.success(e("sessions.sidebar.session.export.success")),$t(Tt)},[yt,je,n.children,ke.title,oe.id,Ne,$t,Se,e]),ss=l.useCallback(async()=>{if(n.children.length>0){Pe(!0),Ie(!0);return}await Gt(!1)},[Gt,n.children.length]),wt=l.useCallback(()=>{Ne&&al("desktop_open_session_mini_chat_window",{sessionId:oe.id,directory:Ne}).catch(xt=>{console.warn("[session-sidebar] failed to open mini chat window",xt)})},[oe.id,Ne]);if(h===oe.id)return s.jsx("div",{className:me("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",{className:"flex w-full items-center gap-2",onSubmit:xt=>{xt.preventDefault(),w()},children:[s.jsx("input",{value:x,onChange:xt=>g(xt.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:xt=>{if(xt.key==="Escape"){xt.stopPropagation(),y();return}(xt.key===" "||xt.key==="Enter")&&xt.stopPropagation()}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:y,"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"})})]}),V?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:[Oe?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:Re?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:xe}),et?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",et.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",et.deletions]})]}):null,le?s.jsx("span",{className:"truncate",children:ue?.projectLabel}):null,J?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:ue?.branchLabel})]}):null]})})]})},oe.id);const Dt=ee?.type??"idle",Xt=Dt==="busy"||Dt==="retry",Yt=Ce.length,dt=Xt||!Xt&&st&&!Qe,Rt=Xt?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")}),is=dt||nt?s.jsxs("span",{className:me("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",V?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",dt&&nt?"left-[-18px] w-6":"left-[-10px] w-3.5",Oe&&!ne?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[dt?Rt:null,nt?s.jsx(I,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,xs=Oe?s.jsx("span",{role:"button",tabIndex:0,onClick:xt=>{xt.stopPropagation(),k(oe.id)},onKeyDown:xt=>{(xt.key==="Enter"||xt.key===" ")&&(xt.preventDefault(),xt.stopPropagation(),k(oe.id))},className:me("absolute left-[-10px] inline-flex h-3.5 w-3.5 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",V?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",V&&dt&&!ne?"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(Re?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Re?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,ps=F?s.jsx(I,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,ws=xt=>{T(xt?he:null)},qt=xt=>{xt.preventDefault(),xt.stopPropagation(),T(_e?null:he)},Ge=xt=>{xt.preventDefault(),xt.stopPropagation()},St=xt=>{xt.preventDefault(),xt.stopPropagation()},Mt=xt=>{xt.preventDefault(),xt.stopPropagation()},Nt=xt=>{xt.preventDefault(),xt.stopPropagation()},Kt=xt=>{xt.preventDefault(),xt.stopPropagation(),T(null),Q(oe,{archivedBucket:o})},ns=xt=>{if(H.current){H.current=!1;return}if(De){if(xt?.preventDefault(),xt?.stopPropagation(),xt?.shiftKey){const jt=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(ft=>ft.getAttribute("data-session-row")).filter(ft=>typeof ft=="string"&&ft.length>0),Tt=pr.getState().anchorId,Z=new Map;Z.set(oe.id,Ue(n)),Me(Tt,oe.id,jt,Ne??null,Z);return}ge(oe.id,Ne??null,Ue(n));return}D(oe.id,Ne,we,i)},js=xt=>{(xt.button===2||xt.button===0&&xt.ctrlKey&&!De)&&(H.current=!0)},ls=xt=>{W&&xt.pointerType==="touch"&&se(!0)},ks=xt=>{W&&xt.pointerType==="touch"&&se(!1)},Os=s.jsxs(zs,{align:"end",className:"min-w-[180px]",onCloseAutoFocus:xt=>{M&&xt.preventDefault()},children:[s.jsxs(Vt,{onClick:()=>{v(oe.id),g(pe)},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(Vt,{onClick:()=>S(oe.id),className:"[&>svg]:mr-1",children:[nt?s.jsx(I,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(I,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(nt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),ke.share?s.jsxs(s.Fragment,{children:[s.jsx(Vt,{onClick:()=>{ke.share?.url&&P(ke.share.url,oe.id)},className:"[&>svg]:mr-1",children:E===oe.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(Vt,{onClick:()=>C(oe.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(Vt,{onClick:()=>A(ke),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(Vt,{onClick:()=>{ss()},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),We?s.jsxs(Vt,{onClick:()=>Je(!0),className:"[&>svg]:mr-1",children:[s.jsx(L6,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Ne&&!o?(()=>{const xt=R(Ne),cs=O(Ne,oe.id);return s.jsxs(s.Fragment,{children:[s.jsx(Tn,{}),s.jsxs(Dy,{children:[s.jsxs(Ty,{className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(My,{className:"min-w-[180px]",children:[xt.length===0?s.jsx(Vt,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):xt.map(jt=>s.jsxs(Vt,{onClick:()=>{cs===jt.id?z(Ne,oe.id):B(Ne,jt.id,oe.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:jt.name}),cs===jt.id?s.jsx(I,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},jt.id)),s.jsx(Tn,{}),s.jsxs(Vt,{onClick:()=>{const jt=$(Ne);jt&&B(Ne,jt.id,oe.id)},children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),cs?s.jsxs(Vt,{onClick:()=>{z(Ne,oe.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,K?null:s.jsxs(Vt,{disabled:!Ne,onClick:()=>{Ne&&_(Ne,{mode:"chat",dedupeKey:`session:${oe.id}`,label:pe})},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")})]}),X?s.jsxs(Vt,{disabled:!Ne,onClick:wt,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(Tn,{}),s.jsxs(Vt,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>Q(oe,{archivedBucket:o}),children:[s.jsx(I,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e(o?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(l.Fragment,{children:[s.jsx(AP,{sessionId:oe.id,sessionDirectory:Ne??null,sessionTitle:pe,children:s.jsxs("div",{"data-session-row":oe.id,"data-session-scope":Ne??"","data-session-archived":o?"1":"0",className:me("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",we?"opacity-75":"",r>0&&"pl-[20px]",ye&&"bg-primary/15"),children:[is,xs,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:V?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",disabled:we,onPointerDown:ls,onPointerUp:ks,onPointerCancel:ks,onMouseDown:js,onClick:xt=>ns(xt),onDoubleClick:xt=>{xt.stopPropagation(),j()},className:me("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ce&&"bg-interactive-hover/70",ne?K?ie:fe:ie),children:s.jsxs("div",{className:me("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:me("block min-w-0 flex-1 truncate typography-ui-label font-normal",Qe?"text-primary":"text-foreground"),children:Vi(pe,f)}),ne?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Ye}):null,ne?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:me("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",_e?"opacity-0":ae),children:Ye})}),Yt>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:Yt})]}):null]})})}),s.jsx(At,{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:me("flex items-center gap-3 text-left text-muted-foreground",ue?.projectLabel?"justify-between":"justify-start"),children:[ue?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:ue.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:xe})]}),ue?.branchLabel||et?s.jsxs("div",{className:me("flex items-center gap-3 text-left text-muted-foreground",ue?.branchLabel?"justify-between":"justify-start"),children:[ue?.branchLabel?s.jsx("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ue.branchLabel})]})}):null,et?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",et.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",et.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:we,onPointerDown:ls,onPointerUp:ks,onPointerCancel:ks,onMouseDown:js,onClick:xt=>ns(xt),onDoubleClick:xt=>{xt.stopPropagation(),j()},className:me("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ce&&"bg-interactive-hover/70",ne?K?ie:fe:ie),children:[s.jsxs("div",{className:me("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:me("block min-w-0 flex-1 truncate typography-ui-label font-normal",Qe?"text-primary":"text-foreground"),children:Vi(pe,f)}),Yt>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:Yt})]}):null]}),V?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[s.jsx("span",{className:"flex-shrink-0",children:xe}),et?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",et.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",et.deletions]})]}):null,le?s.jsx("span",{className:"truncate",children:ue?.projectLabel}):null,J?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:ue?.branchLabel})]}):null]})})]})}),ps&&!W?s.jsx("div",{className:me("absolute top-1/2 -translate-y-1/2 z-10",V?"right-0":"right-[30px]"),children:ps}):null,s.jsxs("div",{className:me("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",_e||ne&&!K?"opacity-100":me("opacity-0",U)),children:[ve?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",className:me("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",V&&!ne?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:Mt,onMouseDown:Nt,onClick:Kt,onKeyDown:xt=>xt.stopPropagation(),children:s.jsx(I,{name:"archive",className:me(V&&!ne?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(At,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,s.jsxs(_s,{open:_e,onOpenChange:ws,children:[s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:me("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",V&&!ne?_e?"h-4 w-4 opacity-100":me("h-4 w-4 opacity-0",U):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:Ge,onMouseDown:St,onClick:qt,onKeyDown:xt=>xt.stopPropagation(),children:s.jsx(I,{name:"more-2",className:me(V&&!ne?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),Os]})]})]})}),Oe&&Re?n.children.map(xt=>re(xt,r+1,Ne??a,i,o,void 0,Y)):null,s.jsx(vs,{open:q,onOpenChange:Ie,children:s.jsxs(ys,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(As,{children:[s.jsx(Ss,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Fs,{children:Ve===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Ve}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Ve})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:Le,onChange:xt=>Pe(xt.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(Hs,{children:[s.jsx(be,{type:"button",onClick:()=>Ie(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(be,{type:"button",onClick:()=>{Ie(!1),Gt(Le)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),We?s.jsx(F6,{session:ke,open:lt,onOpenChange:Je}):null]},oe.id)}const B6=l.memo($6,O6);function z6(t){const e=at.c(71),{t:n}=mt(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:o,onConfirm:c}=t;let d,p,m,u,f,b,h,v,x,g;if(e[0]!==a||e[1]!==n||e[2]!==r){const $=n("sessions.sidebar.session.untitled");u=vs,x=!!r,e[13]!==a?(g=Q=>{Q||a(null)},e[13]=a,e[14]=g):g=e[14],m=ys,h=!1,v="max-w-sm gap-5",p=As;let _;e[15]!==n||e[16]!==r?.archivedBucket?(_=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=_):_=e[17],e[18]!==_?(b=s.jsx(Ss,{children:_}),e[18]=_,e[19]=b):b=e[19],d=Fs,f=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||$,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||$,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||$,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||$,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||$}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||$}),e[0]=a,e[1]=n,e[2]=r,e[3]=d,e[4]=p,e[5]=m,e[6]=u,e[7]=f,e[8]=b,e[9]=h,e[10]=v,e[11]=x,e[12]=g}else d=e[3],p=e[4],m=e[5],u=e[6],f=e[7],b=e[8],h=e[9],v=e[10],x=e[11],g=e[12];let w;e[20]!==d||e[21]!==f?(w=s.jsx(d,{children:f}),e[20]=d,e[21]=f,e[22]=w):w=e[22];let y;e[23]!==p||e[24]!==b||e[25]!==w?(y=s.jsxs(p,{children:[b,w]}),e[23]=p,e[24]=b,e[25]=w,e[26]=y):y=e[26];let k;e[27]!==o||e[28]!==i?(k=()=>o(!i),e[27]=o,e[28]=i,e[29]=k):k=e[29];const D=!i;let j;e[30]!==i?(j=i?s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(I,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=i,e[31]=j):j=e[31];let S;e[32]!==n?(S=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=S):S=e[33];let A;e[34]!==j||e[35]!==S||e[36]!==k||e[37]!==D?(A=s.jsxs("button",{type:"button",onClick:k,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":D,children:[j,S]}),e[34]=j,e[35]=S,e[36]=k,e[37]=D,e[38]=A):A=e[38];let E;e[39]!==a?(E=()=>a(null),e[39]=a,e[40]=E):E=e[40];let P;e[41]!==n?(P=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=P):P=e[42];let C;e[43]!==E||e[44]!==P?(C=s.jsx("button",{type:"button",onClick:E,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[43]=E,e[44]=P,e[45]=C):C=e[45];let N;e[46]!==c?(N=()=>{c()},e[46]=c,e[47]=N):N=e[47];let T;e[48]!==n||e[49]!==r?.archivedBucket?(T=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=T):T=e[50];let M;e[51]!==N||e[52]!==T?(M=s.jsx("button",{type:"button",onClick:N,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[51]=N,e[52]=T,e[53]=M):M=e[53];let R;e[54]!==C||e[55]!==M?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[C,M]}),e[54]=C,e[55]=M,e[56]=R):R=e[56];let O;e[57]!==A||e[58]!==R?(O=s.jsxs(Hs,{className:"w-full sm:items-center sm:justify-between",children:[A,R]}),e[57]=A,e[58]=R,e[59]=O):O=e[59];let z;e[60]!==m||e[61]!==h||e[62]!==O||e[63]!==v||e[64]!==y?(z=s.jsxs(m,{showCloseButton:h,className:v,children:[y,O]}),e[60]=m,e[61]=h,e[62]=O,e[63]=v,e[64]=y,e[65]=z):z=e[65];let B;return e[66]!==u||e[67]!==z||e[68]!==x||e[69]!==g?(B=s.jsx(u,{open:x,onOpenChange:g,children:z}),e[66]=u,e[67]=z,e[68]=x,e[69]=g,e[70]=B):B=e[70],B}function _6(t){const e=at.c(57),{t:n}=mt(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:o,onConfirm:c}=t,d=r?.archivedBucket===!0,p=r?.sessionCount??0;let m;e[0]!==d||e[1]!==p||e[2]!==n?(m=n(d?p===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":p===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=p,e[2]=n,e[3]=m):m=e[3];const u=m;let f;e[4]!==d||e[5]!==p||e[6]!==n?(f=d?p===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:p}):p===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:p}),e[4]=d,e[5]=p,e[6]=n,e[7]=f):f=e[7];const b=f,h=!!r;let v;e[8]!==a?(v=B=>{B||a(null)},e[8]=a,e[9]=v):v=e[9];let x;e[10]!==u?(x=s.jsx(Ss,{children:u}),e[10]=u,e[11]=x):x=e[11];let g;e[12]!==b?(g=s.jsx(Fs,{children:b}),e[12]=b,e[13]=g):g=e[13];let w;e[14]!==x||e[15]!==g?(w=s.jsxs(As,{children:[x,g]}),e[14]=x,e[15]=g,e[16]=w):w=e[16];let y;e[17]!==o||e[18]!==i?(y=()=>o(!i),e[17]=o,e[18]=i,e[19]=y):y=e[19];const k=!i;let D;e[20]!==i?(D=i?s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(I,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=i,e[21]=D):D=e[21];let j;e[22]!==n?(j=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=j):j=e[23];let S;e[24]!==j||e[25]!==y||e[26]!==k||e[27]!==D?(S=s.jsxs("button",{type:"button",onClick:y,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":k,children:[D,j]}),e[24]=j,e[25]=y,e[26]=k,e[27]=D,e[28]=S):S=e[28];let A;e[29]!==a?(A=()=>a(null),e[29]=a,e[30]=A):A=e[30];let E;e[31]!==n?(E=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=E):E=e[32];let P;e[33]!==A||e[34]!==E?(P=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:E}),e[33]=A,e[34]=E,e[35]=P):P=e[35];let C;e[36]!==c?(C=()=>{c()},e[36]=c,e[37]=C):C=e[37];let N;e[38]!==d||e[39]!==n?(N=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=N):N=e[40];let T;e[41]!==C||e[42]!==N?(T=s.jsx("button",{type:"button",onClick:C,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:N}),e[41]=C,e[42]=N,e[43]=T):T=e[43];let M;e[44]!==P||e[45]!==T?(M=s.jsxs("div",{className:"flex items-center gap-2",children:[P,T]}),e[44]=P,e[45]=T,e[46]=M):M=e[46];let R;e[47]!==S||e[48]!==M?(R=s.jsxs(Hs,{className:"w-full sm:items-center sm:justify-between",children:[S,M]}),e[47]=S,e[48]=M,e[49]=R):R=e[49];let O;e[50]!==R||e[51]!==w?(O=s.jsxs(ys,{showCloseButton:!1,className:"max-w-sm gap-5",children:[w,R]}),e[50]=R,e[51]=w,e[52]=O):O=e[52];let z;return e[53]!==h||e[54]!==O||e[55]!==v?(z=s.jsx(vs,{open:h,onOpenChange:v,children:O}),e[53]=h,e[54]=O,e[55]=v,e[56]=z):z=e[56],z}function V6(t){const e=at.c(36),{t:n}=mt(),{value:r,setValue:a,onConfirm:i}=t,o=!!r;let c;e[0]!==a?(c=D=>{D||a(null)},e[0]=a,e[1]=c):c=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let p;e[4]!==d?(p=s.jsx(Ss,{children:d}),e[4]=d,e[5]=p):p=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 u;e[9]!==m?(u=s.jsx(Fs,{children:m}),e[9]=m,e[10]=u):u=e[10];let f;e[11]!==p||e[12]!==u?(f=s.jsxs(As,{children:[p,u]}),e[11]=p,e[12]=u,e[13]=f):f=e[13];let b;e[14]!==a?(b=()=>a(null),e[14]=a,e[15]=b):b=e[15];let h;e[16]!==n?(h=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=h):h=e[17];let v;e[18]!==b||e[19]!==h?(v=s.jsx("button",{type:"button",onClick:b,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:h}),e[18]=b,e[19]=h,e[20]=v):v=e[20];let x;e[21]!==n?(x=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=x):x=e[22];let g;e[23]!==i||e[24]!==x?(g=s.jsx("button",{type:"button",onClick:i,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:x}),e[23]=i,e[24]=x,e[25]=g):g=e[25];let w;e[26]!==g||e[27]!==v?(w=s.jsxs(Hs,{children:[v,g]}),e[26]=g,e[27]=v,e[28]=w):w=e[28];let y;e[29]!==w||e[30]!==f?(y=s.jsxs(ys,{showCloseButton:!1,className:"max-w-sm gap-5",children:[f,w]}),e[29]=w,e[30]=f,e[31]=y):y=e[31];let k;return e[32]!==o||e[33]!==c||e[34]!==y?(k=s.jsx(vs,{open:o,onOpenChange:c,children:y}),e[32]=o,e[33]=c,e[34]=y,e[35]=k):k=e[35],k}const U6=t=>{const e=at.c(46),{selectedCount:n,scopeKey:r,scopeFolders:a,archivedBucket:i,onMoveToFolder:o,onCreateFolderAndMove:c,onRemoveFromFolder:d,canRemoveFromFolder:p,onDelete:m,onDone:u}=t,{t:f}=mt(),b=!!r&&!i;let h;e[0]!==i||e[1]!==f?(h=f(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=f,e[2]=h):h=e[2];const v=h;let x;e[3]!==n||e[4]!==f?(x=f("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=f,e[5]=x):x=e[5];let g;e[6]!==x?(g=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:x}),e[6]=x,e[7]=g):g=e[7];let w;e[8]!==b||e[9]!==p||e[10]!==c||e[11]!==o||e[12]!==d||e[13]!==a||e[14]!==f?(w=b?s.jsxs(_s,{children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(Bs,{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":f("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(I,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:f("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(zs,{align:"end",className:"min-w-[180px]",children:[a.length===0?s.jsx(Vt,{disabled:!0,className:"text-muted-foreground",children:f("sessions.sidebar.folders.none")}):a.map(O=>s.jsx(Vt,{onClick:()=>o(O.id),children:s.jsx("span",{className:"flex-1 truncate",children:O.name})},O.id)),s.jsx(Tn,{}),s.jsxs(Vt,{onClick:c,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),f("sessions.sidebar.folders.newFolderEllipsis")]}),p?s.jsxs(Vt,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1 h-4 w-4"}),f("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=b,e[9]=p,e[10]=c,e[11]=o,e[12]=d,e[13]=a,e[14]=f,e[15]=w):w=e[15];let y;e[16]===Symbol.for("react.memo_cache_sentinel")?(y=me("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]=y):y=e[16];let k;e[17]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(I,{name:"delete-bin",className:"h-4 w-4"}),e[17]=k):k=e[17];let D;e[18]!==v||e[19]!==m?(D=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:y,"aria-label":v,children:k})}),e[18]=v,e[19]=m,e[20]=D):D=e[20];let j;e[21]!==v?(j=s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:v})}),e[21]=v,e[22]=j):j=e[22];let S;e[23]!==D||e[24]!==j?(S=s.jsxs(It,{children:[D,j]}),e[23]=D,e[24]=j,e[25]=S):S=e[25];let A;e[26]!==f?(A=f("sessions.sidebar.header.actions.exitSelection"),e[26]=f,e[27]=A):A=e[27];let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(I,{name:"close",className:"h-4 w-4"}),e[28]=E):E=e[28];let P;e[29]!==u||e[30]!==A?(P=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":A,children:E})}),e[29]=u,e[30]=A,e[31]=P):P=e[31];let C;e[32]!==f?(C=f("sessions.sidebar.header.actions.exitSelection"),e[32]=f,e[33]=C):C=e[33];let N;e[34]!==C?(N=s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:C})}),e[34]=C,e[35]=N):N=e[35];let T;e[36]!==P||e[37]!==N?(T=s.jsxs(It,{children:[P,N]}),e[36]=P,e[37]=N,e[38]=T):T=e[38];let M;e[39]!==T||e[40]!==w||e[41]!==S?(M=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[w,S,T]}),e[39]=T,e[40]=w,e[41]=S,e[42]=M):M=e[42];let R;return e[43]!==M||e[44]!==g?(R=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[g,M]}),e[43]=M,e[44]=g,e[45]=R):R=e[45],R},Bg="oc.sessions.activeNow",W6=2160*60*1e3,zg=t=>!!t.parentID,au=t=>!!t.time?.archived,Cd=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},K6=t=>{try{const e=t.getItem(Bg);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,a=[];return n.forEach(i=>{const o=typeof i=="string"?i:i&&typeof i=="object"&&"sessionId"in i&&typeof i.sessionId=="string"?i.sessionId:null;!o||r.has(o)||(r.add(o),a.push({sessionId:o}))}),a}catch{return[]}},$c=(t,e)=>{try{t.setItem(Bg,JSON.stringify(e))}catch{}},H6=(t,e,n=Date.now())=>{const r=n-W6;return t.filter(a=>{const i=e.get(a.sessionId);return i?au(i)?!1:Cd(i)>=r:!0})},G6=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],_g=t=>[...t].sort((e,n)=>Cd(n)-Cd(e)),q6=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!au(r)).filter(r=>!zg(r));return _g(n)},Y6=(t,e)=>{const n=t.filter(r=>{if(au(r)||zg(r))return!1;const a=e[r.id];return a?.type==="busy"||a?.type==="retry"});return _g(n)},Lo=sa(),Bc=ar((t,e)=>({entries:K6(Lo),setEntries:n=>{n!==e().entries&&(t({entries:n}),$c(Lo,n))},addSession:n=>{const r=G6(e().entries,n);r!==e().entries&&(t({entries:r}),$c(Lo,r))},prune:n=>{const r=e().entries,a=H6(r,n);a.length===r.length&&a.every((i,o)=>i.sessionId===r[o]?.sessionId)||(t({entries:a}),$c(Lo,a))}})),Oo="oc.sessions.projectCollapse",bf="oc.sessions.groupOrder",yf="oc.sessions.groupCollapse",vf="oc.sessions.activeSessionByProject",zc="oc.sessions.expandedParents",J6="oc.sessions.pinned",Q6=(t,e)=>{const n=new Set;for(const r of t){const a=Ps(r.path)?.toLowerCase();a&&n.add(a)}for(const r of e.values())for(const a of r){const i=Ps(a.path)?.toLowerCase();i&&n.add(i)}return n},X6=(t,e)=>{if(t.time?.archived)return!0;const n=Ps(_i(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},Z6=5*6e4,wf=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:a=!1})=>{const{t:i}=mt(),[o,c]=l.useState(!1),[d,p]=l.useState(""),m=l.useRef(null),u=l.useRef(null),f=l.useRef(new Set),[b,h]=l.useState(null),[v,x]=l.useState(""),[g,w]=l.useState(null),[y,k]=l.useState(new Set),[D]=l.useState(()=>new Map),j=l.useMemo(()=>sa(),[]),S=Bc(Ee=>Ee.entries),A=Bc(Ee=>Ee.addSession),E=Bc(Ee=>Ee.prune),[P,C]=l.useState(new Set),[N,T]=l.useState(new Map),[M,R]=l.useState(new Set),[O,z]=l.useState(!1),[B,$]=l.useState(!1),[_,Q]=l.useState(null),[W,ne]=l.useState(null),[re,ue]=l.useState(""),[Y,le]=l.useState(null),[J,L]=l.useState(null),[V,K]=l.useState(null),X=rc(Ee=>Ee.ids),U=rc(Ee=>Ee.setIds),ae=rc(Ee=>Ee.toggle),[ve,ie]=l.useState(()=>{try{const Ee=sa().getItem(yf);if(!Ee)return new Set;const vt=JSON.parse(Ee);return new Set(Array.isArray(vt)?vt.filter(pt=>typeof pt=="string"):[])}catch{return new Set}}),[fe,H]=l.useState(()=>{try{const Ee=sa().getItem(bf);if(!Ee)return new Map;const vt=JSON.parse(Ee),pt=new Map;return Object.entries(vt).forEach(([Qt,Ts])=>{Array.isArray(Ts)&&pt.set(Qt,Ts.filter(hn=>typeof hn=="string"))}),pt}catch{return new Map}}),[ce,se]=l.useState(()=>{try{const Ee=sa().getItem(vf);if(!Ee)return new Map;const vt=JSON.parse(Ee),pt=new Map;return Object.entries(vt).forEach(([Qt,Ts])=>{typeof Ts=="string"&&Ts.length>0&&pt.set(Qt,Ts)}),pt}catch{return new Map}}),[oe,te]=l.useState(new Map),ke=l.useRef(new Map),Ne=l.useRef(0),je=Ws(Ee=>Ee.homeDirectory),Se=Ws(Ee=>Ee.currentDirectory),De=Ws(Ee=>Ee.setDirectory),ye=Ls(Ee=>Ee.projects),ge=Ls(Ee=>Ee.activeProjectId),Me=Ls(Ee=>Ee.removeProject),Ue=Ls(Ee=>Ee.setActiveProjectIdOnly),q=Ls(Ee=>Ee.updateProjectMeta),Ie=Ls(Ee=>Ee.reorderProjects),Le=Te(Ee=>Ee.setActiveMainTab),Pe=Te(Ee=>Ee.openContextPanelTab),he=Te(Ee=>Ee.setSettingsDialogOpen),F=Te(Ee=>Ee.toggleHelpDialog),ee=Te(Ee=>Ee.setAboutDialogOpen),Ce=Te(Ee=>Ee.setSessionSwitcherOpen),Fe=Te(Ee=>Ee.setScheduledTasksDialogOpen),we=Te(Ee=>Ee.toggleSidebar),Qe=Te(Ee=>Ee.openMultiRunLauncher),pe=Te(Ee=>Ee.notifyOnSubtasks),Oe=Te(Ee=>Ee.showDeletionDialog),nt=Te(Ee=>Ee.setShowDeletionDialog),Re=Ml(d,120),de=l.useMemo(()=>Re.trim().toLowerCase(),[Re]),He=de.length>0,st=Xn(Ee=>Ee.collapsedFolderIds),qe=Xn(Ee=>Ee.foldersMap),et=Xn(Ee=>Ee.getFoldersForScope),rt=Xn(Ee=>Ee.createFolder),xe=Xn(Ee=>Ee.renameFolder),Ye=Xn(Ee=>Ee.deleteFolder),_e=Xn(Ee=>Ee.addSessionToFolder),We=Xn(Ee=>Ee.addSessionsToFolder),lt=Xn(Ee=>Ee.removeSessionFromFolder),Je=Xn(Ee=>Ee.removeSessionsFromFolders),Ve=Xn(Ee=>Ee.toggleFolderCollapse),yt=Xn(Ee=>Ee.cleanupSessions),$t=Xn(Ee=>Ee.getSessionFolderId);qI({isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchContainerRef:m});const Gt=oh(),ss=Wd(),wt=Dd(),Dt=Ry(),Xt=Ia(Ee=>Ee.hasLoaded),Yt=Ia(Ee=>Ee.activeSessions),ts=Ia(Ee=>Ee.archivedSessions),dt=_t(Ee=>Ee.currentSessionId),Rt=_t(Ee=>!!Ee.newSessionDraft?.open),is=_t(Ee=>Ee.setCurrentSession),xs=_t(Ee=>Ee.updateSessionTitle),ps=_t(Ee=>Ee.shareSession),ws=_t(Ee=>Ee.unshareSession),qt=_t(Ee=>Ee.worktreeMetadata),Ge=_t(Ee=>Ee.availableWorktreesByProject),St=_t(Ee=>Ee.openNewSessionDraft),Mt=Da(br(Ee=>({checkForUpdates:Ee.checkForUpdates,available:Ee.available,runtimeType:Ee.runtimeType,info:Ee.info,downloading:Ee.downloading,downloaded:Ee.downloaded,progress:Ee.progress,error:Ee.error,downloadUpdate:Ee.downloadUpdate,restartToUpdate:Ee.restartToUpdate}))),Nt=l.useMemo(()=>Q6(ye,Ge),[Ge,ye]),Kt=l.useMemo(()=>{const Ee=new Map(wt.map(Qt=>[Qt.id,Qt])),vt=Yt.map(Qt=>Ee.get(Qt.id)??Qt),pt=new Set(vt.map(Qt=>Qt.id));return wt.forEach(Qt=>{pt.has(Qt.id)||vt.push(Qt)}),vt.filter(Qt=>X6(Qt,Nt))},[Yt,Nt,wt]),ns=l.useMemo(()=>wt.map(Ee=>{const vt=Ps(Ee.directory??null)??"";return`${Ee.id}:${Ee.title??""}:${Ee.time?.archived?1:0}:${vt}`}).join("|"),[wt]),js=l.useRef(wt);l.useEffect(()=>{js.current=wt},[ns,wt]),l.useEffect(()=>{let Ee=!1;const vt=async()=>{const pt=Ls.getState().projects;if(pt.length===0)return;const Qt=new Map,Ts=[];await Promise.all(pt.map(async hn=>{const Ae=Ps(hn.path);if(Ae)try{if(!(nn.getState().directories.get(Ae)?.isGitRepo??await Sr(()=>import("./modelPrefsAutoSave-2uwW8uD9.js").then(Ot=>Ot.f0),__vite__mapDeps([2,0,1,3,4])).then(Ot=>Ot.checkIsGitRepository(Ae))))return;const ht=await Jc({id:hn.id,path:Ae});if(Ee||ht.length===0)return;Qt.set(Ae,ht),Ts.push(...ht)}catch{}})),!Ee&&_t.setState({availableWorktrees:Ts,availableWorktreesByProject:Qt})};return Qc(js.current),vt(),()=>{Ee=!0}},[Se,ns,ye]),l.useEffect(()=>{let Ee=null;const vt=Mg(pt=>{pt.type==="scheduled-task-ran"&&(Ee&&clearTimeout(Ee),Ee=setTimeout(()=>{Qc(js.current)},500))});return()=>{Ee&&clearTimeout(Ee),vt()}},[]);const ls=l.useMemo(()=>yn(),[]),ks=Cl(),[Os,xt]=l.useState(!1),cs=l.useMemo(()=>un(),[]),{isTablet:jt}=an(),Tt=t||jt,Z=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),ft=!t&&!cs&&!ls,kt=!t&&!cs&&!ft,Ht=ls&&Z&&!Os||ks?"pl-[5.5rem]":"pl-3",Ns="app-region-no-drag inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50";l.useEffect(()=>{if(!ls||!Z){xt(!1);return}let Ee=!1,vt=null;const pt=async()=>{try{const Ts=await Oy();Ee||xt(Ts)}catch{Ee||xt(!1)}},Qt=async()=>{try{vt=$y(()=>{pt()})}catch{}};return pt(),Qt(),()=>{Ee=!0,vt&&vt()}},[ls,Z]);const Cs=l.useCallback(async Ee=>{const vt=Ee.target;vt.closest(".app-region-no-drag")||vt.closest("button, a, input, select, textarea")||Ee.button===0&&ls&&await hh()},[ls]),{buildGroupSearchText:Ke,filterSessionNodesForSearch:bt,buildGroupedSessions:Ct}=GI({homeDirectory:je,worktreeMetadata:qt,pinnedSessionIds:X,gitBranches:Gt,isVSCode:cs}),{scheduleCollapsedProjectsPersist:Ft}=QI({isVSCode:cs,hasLoadedGlobalSessions:Xt,safeStorage:j,keys:{sessionExpanded:zc,projectCollapse:Oo,sessionPinned:J6,groupOrder:bf,projectActiveSession:vf,groupCollapse:yf},sessions:Kt,setPinnedSessionIds:U,groupOrderByProject:fe,activeSessionByProject:ce,collapsedGroups:ve,setExpandedParents:k,setCollapsedProjects:C}),Zt=l.useMemo(()=>[...Kt].sort((Ee,vt)=>ii(Ee,vt,X)),[Kt,X]),it=l.useMemo(()=>new Map(Zt.map((Ee,vt)=>[Ee.id,vt])),[Zt]),zt=l.useMemo(()=>{const Ee=new Map;return Zt.forEach(vt=>{const pt=vt.parentID;if(!pt)return;const Qt=Ee.get(pt)??[];Qt.push(vt),Ee.set(pt,Qt)}),Ee.forEach(vt=>vt.sort((pt,Qt)=>ii(pt,Qt,X))),Ee},[Zt,X]),hs=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:i("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:i("sessions.sidebar.empty.noSessions.description")})]}),Jt=l.useMemo(()=>ye.find(Ee=>Ee.id===g)??null,[ye,g]),Ut=l.useCallback(Ee=>{g&&(q(g,Ee),w(null))},[g,q]),os=l.useCallback(()=>{z(!0)},[]),tn=l.useCallback(()=>{const Ee=Da.getState();if(Ee.available&&Ee.info){$(!0);return}Mt.checkForUpdates().then(()=>{const{available:vt,error:pt}=Da.getState();if(pt){G.error(i("sessions.sidebar.updateCheck.errorTitle"),{description:pt});return}if(!vt){G.success(i("sessions.sidebar.updateCheck.latestVersion"));return}$(!0)})},[i,Mt]),Zs=l.useCallback(()=>{t&&Ce(!1),he(!0)},[t,Ce,he]),nr=Mt.available&&(Mt.runtimeType==="desktop"||Mt.runtimeType==="web"),Vn=_t(Ee=>Ee.deleteSession),Ds=_t(Ee=>Ee.deleteSessions),on=_t(Ee=>Ee.archiveSession),en=_t(Ee=>Ee.archiveSessions),{copiedSessionId:mn,handleSessionSelect:Sn,handleSessionDoubleClick:Fn,handleSaveEdit:Mn,handleCancelEdit:cn,handleShareSession:kn,handleCopyShareUrl:Cn,handleUnshareSession:Be,handleDeleteSession:Et,confirmDeleteSession:rs}=YI({activeProjectId:ge,currentDirectory:Se,currentSessionId:dt,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:o,sessionSearchQuery:d,setSessionSearchQuery:p,setIsSessionSearchOpen:c,setActiveProjectIdOnly:Ue,setDirectory:De,setActiveMainTab:Le,setSessionSwitcherOpen:Ce,setCurrentSession:is,updateSessionTitle:xs,shareSession:ps,unshareSession:ws,deleteSession:Vn,deleteSessions:Ds,archiveSession:on,archiveSessions:en,childrenMap:zt,showDeletionDialog:Oe,setDeleteSessionConfirm:le,deleteSessionConfirm:Y,setEditingId:h,setEditTitle:x,editingId:b,editTitle:v}),gs=l.useCallback(()=>{if(!J)return;const{scopeKey:Ee,folderId:vt}=J;L(null),Ye(Ee,vt)},[J,Ye]),Ys=l.useCallback(()=>{Nr.requestDirectoryDialog()},[]);l.useEffect(()=>{if(!dt)return;const vt=Kt.find(pt=>pt.id===dt)?.parentID;vt&&k(pt=>{if(pt.has(vt))return pt;const Qt=new Set(pt);Qt.add(vt);try{j.setItem(zc,JSON.stringify(Array.from(Qt)))}catch{}return Qt})},[dt,Kt,j]);const Gs=l.useCallback(Ee=>{k(vt=>{const pt=new Set(vt);pt.has(Ee)?pt.delete(Ee):pt.add(Ee);try{j.setItem(zc,JSON.stringify(Array.from(pt)))}catch{}return pt})},[j]),Is=l.useCallback((Ee,vt)=>{if(!Ee)return null;vt&&st.has(vt)&&Ve(vt);const pt=rt(Ee,i("sessions.sidebar.folder.newFolderName"),vt);return ne(pt.id),ue(pt.name),pt},[st,Ve,rt,i]),qs=l.useCallback(Ee=>{R(vt=>{const pt=new Set(vt);return pt.has(Ee)?pt.delete(Ee):pt.add(Ee),pt})},[]),dn=l.useCallback(()=>{Ne.current=Date.now()+150,C(()=>{const Ee=new Set(ye.map(vt=>vt.id));try{j.setItem(Oo,JSON.stringify(Array.from(Ee)))}catch{}return cs||Ft(Ee),Ee})},[ye,cs,j,Ft]),ir=l.useCallback(()=>{Ne.current=Date.now()+150,C(()=>{const Ee=new Set;try{j.setItem(Oo,JSON.stringify([]))}catch{}return cs||Ft(Ee),Ee})},[cs,j,Ft]),Ln=l.useCallback(Ee=>{Ne.current=Date.now()+150,C(vt=>{const pt=new Set(vt);pt.has(Ee)?pt.delete(Ee):pt.add(Ee);try{j.setItem(Oo,JSON.stringify(Array.from(pt)))}catch{}return cs||Ft(pt),pt})},[cs,j,Ft]),Gn=l.useMemo(()=>ye.map(Ee=>({...Ee,normalizedPath:Ps(Ee.path)})).filter(Ee=>!!Ee.normalizedPath),[ye]),Or=l.useMemo(()=>Gn.map(Ee=>Ee.normalizedPath),[Gn]),{github:Ir}=_n(),En=Hn(Ee=>Ee.status),qn=Hn(Ee=>Ee.hasChecked),pn=Fy(Or),Yn=fr(Ee=>Ee.ensureEntry),In=fr(Ee=>Ee.setParams),Rr=fr(Ee=>Ee.refreshTargets);nP({normalizedProjects:Gn,gitRepoStatus:pn,setProjectRepoStatus:T,setProjectRootBranches:te});const or=_t(Ee=>Ee.isLoading);mP({isSessionsLoading:or,sessions:Kt,archivedSessions:ts,normalizedProjects:Gn,isVSCode:cs,availableWorktreesByProject:Ge,cleanupSessions:yt});const{getSessionsForProject:yr,getArchivedSessionsForProject:Pn}=oP({isVSCode:cs,sessions:Kt,archivedSessions:ts,availableWorktreesByProject:Ge});BI({normalizedProjects:Gn,sessions:Kt,archivedSessions:ts,availableWorktreesByProject:Ge,isVSCode:cs,isSessionsLoading:or,foldersMap:qe,createFolder:rt,addSessionToFolder:_e,cleanupSessions:yt});const Jn=l.useRef(!1);ge&&N.has(ge)&&(Jn.current=!!N.get(ge));const{projectSections:rr,groupSearchDataByGroup:fn,sectionsForRender:lr,searchMatchCount:Ni}=VI({normalizedProjects:Gn,getSessionsForProject:yr,getArchivedSessionsForProject:Pn,availableWorktreesByProject:Ge,projectRepoStatus:N,projectRootBranches:oe,lastRepoStatus:Jn.current,buildGroupedSessions:Ct,hasSessionSearchQuery:He,normalizedSessionSearchQuery:de,filterSessionNodesForSearch:bt,buildGroupSearchText:Ke,foldersMap:qe}),_a=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:i("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:i("sessions.sidebar.empty.noMatches.description")})]}),qr=!0,{currentSessionDirectory:la}=WI({projectSections:rr,activeProjectId:ge,activeSessionByProject:ce,setActiveSessionByProject:se,currentSessionId:dt,handleSessionSelect:Sn,newSessionDraftOpen:Rt,mobileVariant:t,openNewSessionDraft:St,setActiveMainTab:Le,setSessionSwitcherOpen:Ce,sessions:Kt,worktreeMetadata:qt}),{getOrderedGroups:vn}=KI(fe),ca=l.useRef(!1);l.useEffect(()=>{if(ca.current||rr.length===0)return;const Ee=rr.flatMap(vt=>vt.groups.filter(pt=>pt.isArchivedBucket).map(pt=>`${vt.project.id}:${pt.id}`));Ee.length>0&&ie(vt=>new Set([...vt,...Ee])),ca.current=!0},[rr]);const Va=l.useMemo(()=>{const Ee=new Map,vt=new Map;return rr.forEach(pt=>{const Qt=ph(pt.project.label?.trim()||Fa(pt.project.normalizedPath,je)||pt.project.normalizedPath);pt.groups.forEach(Ts=>{const hn=Ts.branch&&Ts.branch!=="HEAD"&&Ts.branch!==Qt?Ts.branch:null,Ae={projectLabel:Qt,branchLabel:hn},Xe=ut=>{ut.forEach(ht=>{const Ot=pt.project.normalizedPath.length,es=vt.get(ht.session.id)??-1;Ot<es||(Ee.set(ht.session.id,{node:ht,projectId:pt.project.id,groupDirectory:Ts.directory,secondaryMeta:Ae}),vt.set(ht.session.id,Ot),ht.children.length>0&&Xe(ht.children))})};Xe(Ts.sessions)})}),Ee},[rr,je]),$e=Ca(Ee=>Ee.showRecentSection),Ze=l.useMemo(()=>$e?q6(S,new Map(Kt.map(Ee=>[Ee.id,Ee]))).sort((Ee,vt)=>ii(Ee,vt,X)):[],[S,X,Kt,$e]),tt=l.useMemo(()=>$e?Y6(Kt,Dt):[],[Dt,Kt,$e]);l.useEffect(()=>{!$e||tt.length===0||tt.forEach(Ee=>A(Ee.id))},[A,tt,$e]),l.useEffect(()=>{if(!$e)return;const Ee=new Map;[...Kt,...ts].forEach(vt=>{Ee.set(vt.id,vt)}),E(Ee)},[ts,E,Kt,$e]);const ct=l.useMemo(()=>{if(!$e)return[];const Ee=vt=>{const pt=Va.get(vt.id),Qt=Ps(vt.directory??null);return{node:pt?.node??{session:vt,children:[],worktree:null},projectId:pt?.projectId??null,groupDirectory:pt?.groupDirectory??Qt,secondaryMeta:pt?.secondaryMeta??null}};return[{key:"active-now",title:i("sessions.sidebar.activity.recentTitle"),items:Ze.map(Ee)}]},[Ze,Va,$e,i]),Bt=l.useMemo(()=>new Set(Ze.map(Ee=>Ee.id)),[Ze]),as=l.useMemo(()=>[...Bt],[Bt]);nI({currentSessionId:dt,sortedSessions:Zt,recentSessionIds:as,ensureSessionRenderable:ss.ensureSessionRenderable});const Vs=l.useMemo(()=>{if(!cs||He||Bt.size===0)return lr;const Ee=vt=>vt.reduce((pt,Qt)=>{if(Bt.has(Qt.session.id))return pt;const Ts=Ee(Qt.children);return Ts.length===Qt.children.length?(pt.push(Qt),pt):(pt.push({...Qt,children:Ts}),pt)},[]);return lr.map(vt=>({...vt,groups:vt.groups.map(pt=>({...pt,sessions:Ee(pt.sessions)}))}))},[cs,He,Bt,lr]),Us=l.useMemo(()=>{const Ee=new Set;return Vs.forEach(vt=>{vt.groups.forEach(pt=>{const Qt=Ps(pt.directory??null),Ts=pt.branch?.trim()||Gt.get(Qt||"")?.trim();!Qt||!Ts||Ee.add(Wi(Qt,Ts))})}),[...Ee]},[Gt,Vs]),Qn=y0(Us);l.useEffect(()=>{if(!qn||!En?.connected||!Ir)return;const Ee=[],vt=Date.now();if(Vs.forEach(Qt=>{P.has(Qt.project.id)||Qt.groups.forEach(Ts=>{const hn=Ps(Ts.directory??null),Ae=Ts.branch?.trim()||Gt.get(hn||"")?.trim();if(!hn||!Ae)return;const Xe=Wi(hn,Ae),ut=fr.getState().entries[Xe],ht=!!ut?.status?.pr,Ot=`${hn}::${Ae}`,es=Math.max(ut?.lastRefreshAt??0,ut?.lastDiscoveryPollAt??0),Rs=!!(ut?.isInitialStatusResolved&&!ht&&(!f.current.has(Ot)||vt-es>=Z6));(!ut||!ut.isInitialStatusResolved||Rs)&&(Rs&&f.current.add(Ot),Ee.push({directory:hn,branch:Ae}))})}),Ee.length===0)return;const pt=new Map;Ee.forEach(Qt=>{const Ts=Wi(Qt.directory,Qt.branch,Qt.remoteName??null);pt.has(Ts)||pt.set(Ts,Qt)}),pt.forEach((Qt,Ts)=>{Yn(Ts),In(Ts,{directory:Qt.directory,branch:Qt.branch,remoteName:Qt.remoteName??null,canShow:!0,github:Ir,githubAuthChecked:qn,githubConnected:En.connected})}),Rr([...pt.values()],{force:!0,silent:!0,markInitialResolved:!0})},[P,Yn,Ir,qn,En?.connected,Gt,Rr,Vs,In]);const $r=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",Bl="h-4.5 w-4.5",zl=gP({isDesktopShellRuntime:ls,projectSections:rr,projectHeaderSentinelRefs:ke}),On=l.useCallback((Ee,vt=0,pt,Qt,Ts=!1,hn,Ae="project")=>s.jsx(B6,{node:Ee,depth:vt,groupDirectory:pt,projectId:Qt,archivedBucket:Ts,directoryStatus:D,currentSessionId:dt,pinnedSessionIds:X,expandedParents:y,hasSessionSearchQuery:He,normalizedSessionSearchQuery:de,notifyOnSubtasks:pe,editingId:b,setEditingId:h,editTitle:v,setEditTitle:x,handleSaveEdit:Mn,handleCancelEdit:cn,toggleParent:Gs,handleSessionSelect:Sn,handleSessionDoubleClick:Fn,togglePinnedSession:ae,handleShareSession:kn,copiedSessionId:mn,handleCopyShareUrl:Cn,handleUnshareSession:Be,openSidebarMenuKey:_,setOpenSidebarMenuKey:Q,renamingFolderId:W,getFoldersForScope:et,getSessionFolderId:$t,removeSessionFromFolder:lt,addSessionToFolder:_e,createFolderAndStartRename:Is,openContextPanelTab:Pe,handleDeleteSession:Et,mobileVariant:t,alwaysShowActions:Tt,renderSessionNode:On,secondaryMeta:hn,renderContext:Ae}),[D,dt,X,y,He,de,pe,b,h,v,x,Mn,cn,Gs,Sn,Fn,ae,kn,mn,Cn,Be,_,Q,W,et,$t,lt,_e,Is,Pe,Et,t,Tt]),Jr=l.useCallback(Ee=>{ie(vt=>{const pt=new Set(vt);return pt.has(Ee)?pt.delete(Ee):pt.add(Ee),pt})},[]),Ua=l.useMemo(()=>{const Ee=new Map;for(const[vt,pt]of Qn)Ee.set(vt,{visualState:pt.visualState,number:pt.number,url:pt.url,state:pt.prState,draft:pt.draft,title:pt.title,base:pt.base,head:pt.head,checks:pt.checks,canMerge:pt.canMerge,mergeableState:pt.mergeableState,repo:pt.repo});return Ee},[Qn]),Si=l.useCallback((Ee,vt,pt,Qt,Ts,hn)=>s.jsx(MP,{group:Ee,groupKey:vt,projectId:pt,hideGroupLabel:Qt,compactBodyPadding:hn,hasSessionSearchQuery:He,normalizedSessionSearchQuery:de,groupSearchDataByGroup:fn,expandedSessionGroups:M,collapsedGroups:ve,hideDirectoryControls:r,collapsedFolderIds:st,toggleFolderCollapse:Ve,renameFolder:xe,deleteFolder:Ye,showDeletionDialog:Oe,setDeleteFolderConfirm:L,renderSessionNode:On,currentSessionDirectory:la,projectRepoStatus:N,lastRepoStatus:Jn.current,toggleGroupSessionLimit:qs,mobileVariant:t,alwaysShowActions:Tt,activeProjectId:ge,setActiveProjectIdOnly:Ue,setActiveMainTab:Le,setSessionSwitcherOpen:Ce,openNewSessionDraft:St,addSessionToFolder:_e,createFolderAndStartRename:Is,renamingFolderId:W,renameFolderDraft:re,setRenameFolderDraft:ue,setRenamingFolderId:ne,pinnedSessionIds:X,sessionOrderIndex:it,prVisualStateByDirectoryBranch:Ua,onToggleCollapsedGroup:Jr,dragHandleProps:Ts}),[He,de,fn,M,ve,r,st,Ve,xe,Ye,Oe,On,la,N,qs,t,Tt,ge,Ue,Le,Ce,St,_e,Is,W,re,X,it,Ua,Jr]),lu=$e&&!He?s.jsx(qP,{sections:ct,renderSessionNode:On}):null,da=!!(W||b||g),Br=pr(Ee=>Ee.enabled),sn=pr(Ee=>Ee.selectedIds),ua=pr(Ee=>Ee.scopeKey),Wa=pr,fo=l.useCallback(()=>{pr.getState().toggleMode()},[]),ho=l.useCallback(()=>{pr.getState().disable()},[]),ma=l.useMemo(()=>{if(sn.size===0||typeof document>"u")return!1;let Ee=!1,vt=!1;for(const pt of sn){const Qt=document.querySelectorAll(`[data-session-row="${CSS.escape(pt)}"]`);for(const Ts of Qt)Ts.getAttribute("data-session-archived")==="1"?vt=!0:Ee=!0}return vt&&!Ee},[sn]),An=l.useMemo(()=>{if(ua)return ua;if(sn.size===0||typeof document>"u")return null;for(const Ee of sn){const pt=document.querySelector(`[data-session-row="${CSS.escape(Ee)}"]`)?.getAttribute("data-session-scope");if(pt&&pt.length>0)return pt}return null},[sn,ua]),Ka=l.useMemo(()=>An?qe[An]??[]:[],[qe,An]),_l=l.useMemo(()=>{if(!An||sn.size===0)return!1;const Ee=qe[An]??[];for(const vt of Ee)for(const pt of vt.sessionIds)if(sn.has(pt))return!0;return!1},[qe,An,sn]),Vl=l.useCallback(Ee=>{!An||sn.size===0||We(An,Ee,Array.from(sn))},[We,sn,An]),go=l.useCallback(()=>{if(!An||sn.size===0)return;const Ee=Is(An);Ee&&We(An,Ee.id,Array.from(sn))},[We,Is,sn,An]),Qr=l.useCallback(()=>{!An||sn.size===0||Je(An,Array.from(sn))},[Je,sn,An]),pa=l.useCallback(async()=>{const Ee=Array.from(sn);if(Ee.length!==0){if(ma){const{deletedIds:vt,failedIds:pt}=await Ds(Ee);vt.length>0&&G.success(vt.length===1?i("sessions.sidebar.bulkActions.deletedSingle",{count:vt.length}):i("sessions.sidebar.bulkActions.deletedPlural",{count:vt.length})),pt.length>0&&G.error(pt.length===1?i("sessions.sidebar.bulkActions.failedDeleteSingle",{count:pt.length}):i("sessions.sidebar.bulkActions.failedDeletePlural",{count:pt.length}))}else{const{archivedIds:vt,failedIds:pt}=await en(Ee);vt.length>0&&G.success(vt.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:vt.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:vt.length})),pt.length>0&&G.error(pt.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:pt.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:pt.length}))}pr.getState().clear()}},[en,ma,Ds,sn,i]),Ha=l.useCallback(()=>{const Ee=sn.size;if(Ee!==0){if(!Oe){pa();return}K({sessionCount:Ee,archivedBucket:ma})}},[ma,pa,sn,Oe]),xo=l.useCallback(async()=>{K(null),await pa()},[pa]);l.useEffect(()=>{if(!Br)return;const Ee=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),vt=pt=>{if(da)return;const Qt=pt.target;if(Qt&&(Qt.tagName==="INPUT"||Qt.tagName==="TEXTAREA"||Qt.isContentEditable))return;const Ts=Ee?pt.metaKey:pt.ctrlKey;if(pt.key==="Escape"){pt.preventDefault(),pr.getState().disable();return}if(Ts&&pt.key==="Backspace"){pt.preventDefault(),Ha();return}if(Ts&&(pt.key==="a"||pt.key==="A")){const hn=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(hn.length===0)return;pt.preventDefault();const Xe=Wa.getState().scopeKey??hn[0]?.getAttribute("data-session-scope")??null,ut=Ot=>Xe?Ot.getAttribute("data-session-scope")===Xe:!0,ht=hn.filter(ut).map(Ot=>Ot.getAttribute("data-session-row")).filter(Ot=>typeof Ot=="string"&&Ot.length>0);if(ht.length===0)return;Wa.getState().replaceAll(ht,Xe||null)}};return window.addEventListener("keydown",vt),()=>window.removeEventListener("keydown",vt)},[Ha,da,Wa,Br]);const Ul=l.useCallback(()=>{Le("chat"),t&&Ce(!1),St()},[t,St,Le,Ce]),Wl=l.useCallback(()=>{Le("chat"),t&&Ce(!1),Qe()},[t,Qe,Le,Ce]);return s.jsxs("div",{ref:m,className:me("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[kt?s.jsx("div",{onMouseDown:Cs,className:me("app-region-drag flex h-[var(--oc-header-height,56px)] flex-shrink-0 items-center pr-3",Ht),children:s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:we,className:Ns,"aria-label":i("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(I,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(At,{children:s.jsx("p",{children:i("sessions.sidebar.header.actions.closeSessions")})})]})}):null,s.jsx(VP,{hideDirectoryControls:r,handleOpenDirectoryDialog:Ys,handleNewSession:Ul,canOpenMultiRun:ye.length>0,openMultiRunLauncher:Wl,headerActionIconClass:Bl,reserveHeaderActionsSpace:qr,headerActionButtonClass:$r,isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchQuery:d,setSessionSearchQuery:p,hasSessionSearchQuery:He,searchMatchCount:Ni,collapseAllProjects:dn,expandAllProjects:ir,openScheduledTasksDialog:()=>Fe(!0),selectionModeEnabled:Br,onToggleSelectionMode:fo,showSidebarToggle:ft,onToggleSidebar:we,avoidWindowControlsOverlay:ks}),s.jsx(n6,{topContent:lu,sectionsForRender:Vs,projectSections:rr,activeProjectId:ge,showOnlyMainWorkspace:a,hasSessionSearchQuery:He,emptyState:hs,searchEmptyState:_a,renderGroupSessions:Si,homeDirectory:je,collapsedProjects:P,hideDirectoryControls:r,projectRepoStatus:N,isDesktopShellRuntime:ls,stuckProjectHeaders:zl,mobileVariant:t,alwaysShowActions:Tt,toggleProject:Ln,setActiveProjectIdOnly:Ue,setActiveMainTab:Le,setSessionSwitcherOpen:Ce,openNewSessionDraft:St,openNewWorktreeDialog:os,openProjectEditDialog:w,removeProject:Me,projectHeaderSentinelRefs:ke,reorderProjects:Ie,getOrderedGroups:vn,setGroupOrderByProject:H,openSidebarMenuKey:_,setOpenSidebarMenuKey:Q,isInlineEditing:da}),Br&&sn.size>0?s.jsx(U6,{selectedCount:sn.size,scopeKey:An,scopeFolders:Ka,archivedBucket:ma,onMoveToFolder:Vl,onCreateFolderAndMove:go,onRemoveFromFolder:Qr,canRemoveFromFolder:_l,onDelete:Ha,onDone:ho}):null,s.jsx(JP,{onOpenSettings:Zs,onOpenShortcuts:F,onOpenAbout:()=>ee(!0),onOpenUpdate:tn,showRuntimeButtons:!cs,showUpdateButton:nr}),s.jsx(wd,{open:B,onOpenChange:$,info:Mt.info,downloading:Mt.downloading,downloaded:Mt.downloaded,progress:Mt.progress,error:Mt.error,onDownload:Mt.downloadUpdate,onRestart:Mt.restartToUpdate,runtimeType:Mt.runtimeType}),Jt?s.jsx(Ly,{open:!!Jt,onOpenChange:Ee=>{Ee||w(null)},projectId:Jt.id,projectName:Jt.label||Fa(Jt.path,je),projectPath:Jt.path,initialIcon:Jt.icon,initialColor:Jt.color,initialIconBackground:Jt.iconBackground,onSave:Ut}):null,s.jsx(lI,{open:O,onOpenChange:z,onWorktreeCreated:(Ee,vt)=>{if(Le("chat"),t&&Ce(!1),vt?.sessionId){is(vt.sessionId);return}St({directoryOverride:Ee})}}),s.jsx(OI,{}),s.jsx(z6,{value:Y,setValue:le,showDeletionDialog:Oe,setShowDeletionDialog:nt,onConfirm:rs}),s.jsx(V6,{value:J,setValue:L,onConfirm:gs}),s.jsx(_6,{value:V,setValue:K,showDeletionDialog:Oe,setShowDeletionDialog:nt,onConfirm:xo})]})},eA=()=>{const t=at.c(13),[e,n]=ze.useState(!1);let r,a;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(yn())},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),ze.useEffect(r,a);let i;t[2]!==e?(i=async f=>e?await By(f):{success:!0,path:f},t[2]=e,t[3]=i):i=t[3];const o=i;let c;t[4]!==e?(c=async f=>e?await zy():{success:!0},t[4]=e,t[5]=c):c=t[5];const d=c;let p;t[6]!==e?(p=async f=>e?await _y():{success:!0},t[6]=e,t[7]=p):p=t[7];const m=p;let u;return t[8]!==e||t[9]!==o||t[10]!==d||t[11]!==m?(u={isDesktop:e,requestAccess:o,startAccessing:d,stopAccessing:m},t[8]=e,t[9]=o,t[10]=d,t[11]=m,t[12]=u):u=t[12],u},tA=t=>t==="/",jl=t=>t.replace(/\\/g,"/"),iu=t=>{if(!t||tA(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},ci=t=>t.endsWith("/"),sA=t=>{const e=t.trim();return!e||ci(e)?e:`${e}/`},ou=t=>t.lastIndexOf("/"),Vg=t=>{if(ci(t))return t;const e=ou(t);return e<0?t:t.slice(0,e+1)},nA=t=>{const e=ou(t);return t.slice(e+1)},Ug=t=>{const e=iu(t.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=ou(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},rA=t=>ci(t)&&Ug(t)!==null,aA=(t,e)=>`${Vg(t)}${e}/`,Ya=t=>{if(!t)return null;const e=iu(jl(t.trim()));return e?e.toLowerCase():null},jf=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},iA=t=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?t.metaKey&&!t.ctrlKey:t.ctrlKey&&!t.metaKey,_c=t=>{if(!t)return;t.focus({preventScroll:!0});const e=t.value.length;t.setSelectionRange(e,e),t.scrollLeft=t.scrollWidth},oA=async()=>{try{const t=await fetch("/api/fs/home",{method:"GET",headers:{Accept:"application/json"}});if(t.ok){const e=await t.json();if(typeof e.home=="string"&&e.home.trim().length>0)return jl(e.home.trim())}}catch{}return rn.getFilesystemHome().catch(()=>null)},lA=({open:t,onOpenChange:e})=>{const{t:n}=mt(),r=Ws(we=>we.homeDirectory),a=Ls(we=>we.projects),i=Ls(we=>we.addProject),o=Zn(we=>we.profiles),c=Zn(we=>we.globalIdentity),d=Zn(we=>we.defaultGitIdentityId),p=Zn(we=>we.loadProfiles),m=Zn(we=>we.loadGlobalIdentity),u=Zn(we=>we.loadDefaultGitIdentityId),f=Tl(),{isDesktop:b,requestAccess:h,startAccessing:v}=eA(),{isMobile:x}=an(),g=l.useRef(null),w=l.useRef(null),y=l.useRef(new Map),[k,D]=l.useState(""),[j,S]=l.useState("~/"),[A,E]=l.useState([]),[P,C]=l.useState(!1),[N,T]=l.useState(!1),[M,R]=l.useState(0),[O,z]=l.useState(!1),[B,$]=l.useState(!1),[_,Q]=l.useState(0),[W,ne]=l.useState(!1),[re,ue]=l.useState(""),[Y,le]=l.useState(null),J=k||r,L=l.useMemo(()=>new Set(a.map(we=>Ya(we.path)).filter(we=>!!we)),[a]);l.useEffect(()=>{if(!t)return;S("~/"),E([]),R(0),z(!1),$(!1),ne(!1),ue(""),le(null),requestAnimationFrame(()=>_c(g.current));let we=!1;return(async()=>{const pe=await oA();we||(D(pe||r||""),requestAnimationFrame(()=>_c(g.current)))})(),()=>{we=!0}},[r,t]),l.useEffect(()=>{t&&(p(),m(),u())},[u,p,m,t]);const V=l.useMemo(()=>{const we=new Map;c&&we.set(c.id,c);for(const Qe of o)we.set(Qe.id,Qe);return Array.from(we.values())},[o,c]);l.useEffect(()=>{if(!t||!W||Y!==null)return;const we=typeof d=="string"?d.trim():"";if(we&&V.some(pe=>pe.id===we)){le(we);return}const Qe=V.find(pe=>pe.authType==="ssh"||pe.sshKey);Qe&&le(Qe.id)},[V,d,W,t,Y]);const K=l.useMemo(()=>V.find(we=>we.id===Y)??null,[V,Y]),X=l.useMemo(()=>Vg(j),[j]),U=l.useMemo(()=>ci(j)?"":nA(j),[j]),ae=l.useMemo(()=>J?jf(X,J):"",[X,J]);l.useEffect(()=>{if(!t||!ae){E([]);return}let we=!1;return C(!0),T(!1),rn.listLocalDirectory(ae).then(Qe=>{if(we)return;T(!1);const pe=Qe.filter(Oe=>Oe.isDirectory).map(Oe=>({name:Oe.name,path:jl(Oe.path)})).sort((Oe,nt)=>Oe.name.localeCompare(nt.name));E(pe)}).catch(()=>{we||(E([]),T(!0))}).finally(()=>{we||C(!1)}),()=>{we=!0}},[ae,t]);const ve=l.useMemo(()=>{const we=U.toLowerCase(),Qe=f||U.startsWith(".");return A.filter(pe=>pe.name.toLowerCase().startsWith(we)&&(Qe||!pe.name.startsWith(".")))},[U,A,f]),ie=l.useMemo(()=>{const we=[];rA(j)&&we.push({type:"up",value:"browse:up",name:"..",path:Ug(j)});for(const Qe of ve){const pe=Ya(Qe.path);we.push({type:"directory",value:`browse:${Qe.path}`,name:Qe.name,path:Qe.path,disabled:!!(pe&&L.has(pe))})}return we},[L,ve,j]);l.useEffect(()=>{R(0)},[j,ie.length]);const fe=l.useMemo(()=>J?iu(jf(j,J)):"",[J,j]),H=Ya(fe),ce=!!(H&&L.has(H)),se=l.useMemo(()=>U?ve.find(we=>we.name===U)??null:null,[U,ve]),oe=!!(fe&&!ce&&(ci(j)&&N||!ci(j)&&U.trim().length>0&&se===null)),te=!O&&!B&&!ce&&!!fe,ke=te&&re.trim().length>0,Ne=ie[M]??null,je=!!(Ne&&(Ne.type==="up"||Ne.type==="directory"&&!Ne.disabled)),Se=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",De=n(ce?"directoryExplorerDialog.actions.alreadyAdded":W?O?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":O?"directoryExplorerDialog.actions.adding":oe?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");l.useLayoutEffect(()=>{const we=w.current;if(!we)return;const Qe=()=>Q(Math.ceil(we.getBoundingClientRect().width));if(Qe(),typeof ResizeObserver>"u")return;const pe=new ResizeObserver(Qe);return pe.observe(we),()=>pe.disconnect()},[De]),l.useLayoutEffect(()=>{const we=g.current;we&&(we.scrollLeft=we.scrollWidth)},[_,j]),l.useLayoutEffect(()=>{t&&_c(g.current)},[t]),l.useLayoutEffect(()=>{const we=ie[M];we&&y.current.get(we.value)?.scrollIntoView({block:"nearest"})},[M,ie]);const ye=l.useCallback(()=>{e(!1)},[e]),ge=l.useCallback(async we=>{if(!we||O)return;const Qe=Ya(we);if(Qe&&L.has(Qe))return;let pe=we;z(!0);try{const Oe=!W&&oe&&Ya(we)===Ya(fe);if(W){const Re=re.trim();if(!Re){G.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}pe=(await rn.cloneRepository({remoteUrl:Re,destinationPath:we,gitIdentityId:K?.id??null})).path}else Oe&&await rn.createDirectory(we,{allowOutsideWorkspace:!0});if(!i(pe)){G.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}ye()}catch(Oe){G.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Oe instanceof Error?Oe.message:n("directoryExplorerDialog.toast.unknownError")})}finally{z(!1)}},[i,L,re,ye,W,O,K?.id,oe,fe,n]),Me=l.useCallback(we=>{S(sA(we))},[]),Ue=l.useCallback(we=>{S(aA(j,we.name))},[j]),q=l.useCallback(we=>{if(we){if(we.type==="up"){we.path&&Me(we.path);return}we.disabled||Ue(we)}},[Me,Ue]),Ie=l.useCallback(async()=>{if(!(!b||B)){$(!0);try{const we=await h(fe);if(!we.success||!we.path){we.error&&we.error!=="Directory selection cancelled"&&G.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:we.error});return}const Qe=await v(we.path);if(!Qe.success){G.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:Qe.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await ge(we.path)}catch(we){G.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:we instanceof Error?we.message:n("directoryExplorerDialog.toast.unknownError")})}finally{$(!1)}}},[ge,b,B,h,v,n,fe]),Le=l.useCallback(we=>{if(we.key==="ArrowDown"){we.preventDefault(),R(Qe=>Math.min(ie.length-1,Qe+1));return}if(we.key==="ArrowUp"){we.preventDefault(),R(Qe=>Math.max(0,Qe-1));return}if(we.key==="Enter"){if(we.preventDefault(),iA(we)){ge(fe);return}je&&q(Ne);return}we.key==="Backspace"&&j===""&&(we.preventDefault(),ye())},[q,ge,ye,je,Ne,j,ie.length,fe]),Pe=s.jsxs("button",{type:"button",onClick:()=>Uo(!f),className:"flex flex-shrink-0 items-center gap-2 rounded-lg px-2 py-1 typography-meta text-muted-foreground transition-colors hover:bg-interactive-hover/40",children:[f?s.jsx(I,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),he=s.jsxs("div",{className:"px-2.5 py-1.5",children:[W?s.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[s.jsx(Wt,{value:re,onChange:we=>ue(we.target.value),placeholder:n("directoryExplorerDialog.clone.remoteUrlPlaceholder"),className:"min-w-0 flex-1 border-border/60 bg-[var(--surface-elevated)] font-mono typography-ui-label shadow-none",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),s.jsx(Bh,{activeProfile:K,identities:V,onSelect:we=>le(we.id),isApplying:O,iconOnly:!0})]}):null,s.jsxs("div",{className:"relative",children:[s.jsx(I,{name:"folder-add",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),s.jsx(Wt,{ref:g,value:j,onChange:we=>S(jl(we.target.value)),onKeyDown:Le,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!x&&_>0?{paddingRight:`${_+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),x?null:s.jsx(be,{ref:w,variant:"outline",size:"xs",tabIndex:-1,className:"absolute right-1.5 top-1/2 h-7 -translate-y-1/2 gap-1 px-2 typography-meta",disabled:W?!ke:!te,onMouseDown:we=>we.preventDefault(),onClick:()=>{ge(fe)},title:De,children:De})]})]}),F=s.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:s.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[s.jsx("div",{className:"px-2 pb-1 pt-0.5 typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:n("directoryExplorerDialog.browse.directories")}),P?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):ie.length===0?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.empty")}):s.jsx("div",{className:"space-y-0.5",children:ie.map((we,Qe)=>{const pe=Qe===M;return s.jsxs("button",{ref:Oe=>{Oe?y.current.set(we.value,Oe):y.current.delete(we.value)},type:"button",disabled:we.type==="directory"&&we.disabled,onMouseEnter:()=>R(Qe),onMouseDown:Oe=>Oe.preventDefault(),onClick:()=>q(we),className:me("flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",pe&&"bg-interactive-selection text-interactive-selection-foreground",!pe&&"hover:bg-interactive-hover/50",we.type==="directory"&&we.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[we.type==="up"?s.jsx(I,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(I,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:we.name})}),we.type==="directory"&&we.disabled?s.jsx("span",{className:"rounded-full border border-border/60 px-2 py-0.5 typography-meta text-muted-foreground",children:n("directoryExplorerDialog.browse.addedBadge")}):null]},we.value)})})]})}),ee=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[he,F]}),Ce=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(I,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),s.jsx(I,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.navigate")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(I,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.select")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx("span",{children:Se}),s.jsx(I,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),Fe=()=>s.jsxs(s.Fragment,{children:[x?null:Ce,s.jsxs("div",{className:me("flex w-full flex-row justify-end gap-2 sm:w-auto",x&&"justify-stretch"),children:[b?s.jsx(be,{variant:"ghost",size:"xs",onClick:Ie,disabled:O||B||W,children:n(B?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(be,{variant:"ghost",size:"xs",onClick:()=>ne(we=>!we),disabled:O||B,className:me(x&&"flex-1"),children:n(W?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),x?s.jsx(be,{size:"xs",onClick:()=>{ge(fe)},disabled:W?!ke:!te,className:"flex-1",children:De}):null]})]});return x?s.jsx(Mr,{open:t,onClose:ye,title:n("directoryExplorerDialog.title"),className:"h-[88dvh] max-h-[720px] max-w-full",contentMaxHeightClassName:"flex-1",footer:s.jsx("div",{className:"flex flex-col gap-2",children:Fe()}),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[s.jsx("div",{className:"flex justify-end",children:Pe}),ee]})}):s.jsx(vs,{open:t,onOpenChange:e,children:s.jsxs(ys,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[s.jsx(As,{className:"px-5 pb-2 pt-5",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx(Ss,{children:n("directoryExplorerDialog.title")}),s.jsx(Fs,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),Pe]})}),s.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:ee}),s.jsx(Hs,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:Fe()})]})})},va=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,Ar=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},cA=()=>{const{t}=mt(),[e,n]=l.useState(!1),[r,a]=l.useState(!1),[i,o]=l.useState(null),[c,d]=l.useState([]),[p,m]=l.useState(!1),[u,f]=l.useState(!1),[b,h]=l.useState(!1),[v,x]=l.useState(!1),[g,w]=l.useState(new Set),y=_t(te=>te.getWorktreeMetadata),k=_t(te=>te.newSessionDraft),D=_t(te=>te.setNewSessionDraftTarget),j=_t(te=>te.setDraftBootstrapPendingDirectory),S=Vy,A=Ky,E=_t(te=>te.deleteSessions),P=_t(te=>te.archiveSessions),C=Te(te=>te.showDeletionDialog),N=Te(te=>te.setShowDeletionDialog),T=Ws(te=>te.currentDirectory),M=Ws(te=>te.homeDirectory),R=Ws(te=>te.isHomeReady),O=Ls(te=>te.projects),z=Ls(te=>te.activeProjectId),{isMobile:B,isTablet:$,hasTouchInput:_}=an(),Q=B||$||_,W=l.useMemo(()=>{const ke=(z?O.find(Ne=>Ne.id===z)??null:null)?.path??T;return Ar(ke)},[z,T,O]),ne=l.useCallback(te=>{const Ne=Ar(te.projectDirectory)||W;return{id:(O.find(Se=>Ar(Se.path)===Ne)??null)?.id??`path:${Ne}`,path:Ne}},[W,O]),re=v&&g.size>0,ue=l.useMemo(()=>{const te=i?.worktree;return te&&typeof te.branch=="string"&&te.branch.trim().length>0?!0:c.length>0&&c.every(({metadata:ke})=>typeof ke.branch=="string"&&ke.branch.trim().length>0)},[i?.worktree,c]),Y=i?.mode==="worktree",le=Y,J=b||!Y||!ue,L=b||!Y;l.useEffect(()=>{r||!R||O.length>0||(a(!0),n(!0))},[r,R,O.length]);const V=l.useCallback(te=>{o({sessions:te.sessions,dateLabel:te.dateLabel,mode:te.mode??"session",worktree:te.worktree??null})},[]),K=l.useCallback(()=>{o(null),d([]),m(!1),f(!1),h(!1),x(!1),w(new Set)},[]),X=l.useCallback(async te=>{if(te.sessions.length===0)return;if(te.sessions.length===1){const Se=te.sessions[0];await S(Se.id)?G.success(t("sessions.sidebar.session.delete.success")):G.error(t("sessions.sidebar.session.delete.error"));return}const ke=te.sessions.map(Se=>Se.id),{deletedIds:Ne,failedIds:je}=await E(ke);if(Ne.length>0){const Se=je.length>0?je.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:je.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:je.length}):te.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:te.dateLabel}):void 0;G.success(Ne.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Ne.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Ne.length}),{description:va(Se)})}je.length>0&&G.error(je.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:je.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:je.length}),{description:va(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[S,E,t]);l.useEffect(()=>Nr.onDeleteRequest(te=>{if(!C&&(te.mode??"session")==="session"){X(te);return}V(te)}),[V,C,X]),l.useEffect(()=>Nr.onDirectoryRequest(()=>{n(!0)}),[]),l.useEffect(()=>{if(!i){d([]),m(!1),f(!1),x(!1),w(new Set);return}const te=i.sessions.map(je=>{const Se=y(je.id);return Se?{session:je,metadata:Se}:null}).filter(je=>!!je);d(te),m(!1),x(!1),w(new Set);const ke=new Map;if(i.worktree?.path&&ke.set(Ar(i.worktree.path),i.worktree),te.forEach(({metadata:je})=>{je.path&&ke.set(Ar(je.path),je)}),ke.size===0){x(!0);return}let Ne=!1;return(async()=>{const je=new Map,Se=new Set;await Promise.all(Array.from(ke.entries()).map(async([De,ye])=>{try{const ge=await Uy(ye.path);je.set(De,ge),ge?.isDirty&&Se.add(De)}catch{ye.status&&(je.set(De,ye.status),ye.status.isDirty&&Se.add(De))}})).catch(De=>{console.warn("Failed to inspect worktree status before deletion:",De)}),!Ne&&(w(Se),x(!0),o(De=>{if(!De?.worktree?.path)return De;const ye=Ar(De.worktree.path),ge=je.get(ye);if(!ge)return De;const Me=De.worktree.status;return Me?.isDirty===ge.isDirty&&Me?.ahead===ge.ahead&&Me?.behind===ge.behind&&Me?.upstream===ge.upstream?De:{...De,worktree:{...De.worktree,status:ge}}}),d(De=>De.map(ye=>{const ge=Ar(ye.metadata.path),Me=je.get(ge);return Me?{session:ye.session,metadata:{...ye.metadata,status:Me}}:ye})))})(),()=>{Ne=!0}},[i,y]),l.useEffect(()=>{ue||m(!1)},[ue]);const U=l.useCallback(async(te,ke)=>{const Ne=p&&ue,je=ne(te),Se=Ar(te.path),De=Ar(je.path);try{await Wy(je,te,{deleteRemoteBranch:Ne,deleteLocalBranch:ke});const ye=Ar(k?.directoryOverride);return k?.open&&Se&&ye===Se&&De&&(j(null),D({projectId:je.id,directoryOverride:De},{force:!0})),Ar(T)===Se&&De&&Ws.getState().setDirectory(De,{showOverlay:!1}),!0}catch(ye){return G.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:va(ye instanceof Error?ye.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[ue,T,p,ne,k?.directoryOverride,k?.open,j,D,t]),ae=l.useCallback(async()=>{if(i){h(!0);try{const te=le,ke=te&&p,Ne=te&&u;if(i.sessions.length===0&&Y&&i.worktree){if(!await U(i.worktree,Ne)){K();return}const De=t(p&&ue?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");G.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:va(De)}),K();return}if(i.sessions.length===1){const je=i.sessions[0];if(!(Y?await A(je.id):await S(je.id,{archiveWorktree:!1,deleteRemoteBranch:ke,deleteLocalBranch:Ne}))){G.error(t(Y?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),h(!1);return}const De=!Y&&te?t(ke?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;G.success(t(Y?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:va(De),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const je=i.sessions.map(ye=>ye.id);let Se=[],De=[];if(Y){const ye=await P(je);Se=ye.archivedIds,De=ye.failedIds}else{const ye=await E(je);Se=ye.deletedIds,De=ye.failedIds}if(Y&&i.worktree&&De.length===0&&await U(i.worktree,Ne),Se.length>0){const ye=!Y&&te?t(ke?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Me=[De.length>0?Y?De.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:De.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:De.length}):De.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:De.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:De.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,ye].filter(Boolean).join(" ");G.success(Y?Se.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:Se.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:Se.length}):Se.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Se.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Se.length}),{description:va(Me||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(De.length>0&&(G.error(Y?De.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:De.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:De.length}):De.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:De.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:De.length}),{description:va(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),Se.length===0)){h(!1);return}}Y&&i.sessions.length===1&&i.worktree&&await U(i.worktree,Ne),K()}finally{h(!1)}}},[i,p,u,S,E,A,P,K,le,Y,ue,U,t]),ve=i?.worktree??c[0]?.metadata??null,ie=i?i.mode==="worktree"?i.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):i.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:i.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:i.sessions.length}):i.sessions.length===1?i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:i.sessions.length,dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:i.sessions.length}):"",fe=i?s.jsxs("div",{className:me(Y?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:me(Y?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[Y&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:i.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:i.sessions.length})]}),s.jsxs("ul",{className:me(Y?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(te=>s.jsxs("li",{className:me(Y?"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:me(!Y&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:te.title||t("sessions.sidebar.session.untitled")})]},te.id)),i.sessions.length>5&&s.jsx("li",{className:me(Y?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:i.sessions.length-5})})]})]}),Y?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")}),ve?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:ve.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:ve?Qi(ve.path,M):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),re&&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,H=Y?ue?s.jsxs("button",{type:"button",onClick:()=>{J||m(te=>!te)},disabled:J,className:me("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",J?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[p?s.jsx(I,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(I,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,ce=Y?s.jsxs("button",{type:"button",onClick:()=>{L||f(te=>!te)},disabled:L,className:me("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",L?"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.deleteLocalBranch")]}):null,se=Y?s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[ce,H]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{variant:"ghost",onClick:K,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(be,{variant:"destructive",onClick:ae,disabled:b,children:t(b?"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:()=>N(!C),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":!C,children:[C?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(be,{variant:"ghost",onClick:K,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(be,{variant:"destructive",onClick:ae,disabled:b,children:b?t("sessions.sidebar.sessionDialogs.actions.deleting"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),oe=Y?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[Q?s.jsx(Mr,{open:!!i,onClose:()=>{b||K()},title:oe,footer:s.jsx("div",{className:"flex justify-end gap-2",children:se}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[ie&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:ie}),fe]})}):s.jsx(vs,{open:!!i,onOpenChange:te=>{if(!te){if(b)return;K()}},children:s.jsxs(ys,{className:me(Y?"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(As,{children:[s.jsxs(Ss,{className:me(Y&&"flex items-center gap-2"),children:[Y&&s.jsx(I,{name:"delete-bin",className:"h-5 w-5"}),oe]}),ie&&s.jsx(Fs,{children:ie})]}),s.jsx("div",{className:me(Y&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:fe}),s.jsx(Hs,{className:"mt-2 gap-2 pt-1 pb-1",children:se})]})}),s.jsx(lA,{open:e,onOpenChange:n})]})},Id=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),dA=(t,e)=>{const n=Id(t),r=Id(e);return`${n}-${r}`.substring(0,60)},Nf=(t,e)=>`${t}/${e}`,uA=()=>{const t=Ls.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(a=>a.id===e);if(n?.path)return{id:n.id,path:n.path};const r=Ws.getState().currentDirectory??null;if(r&&r.trim().length>0){const a=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${a}`,path:a}}return null},Vc=ar()(vi(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),r=e.prompt.trim(),{models:a,agent:i,files:o,setupCommands:c}=e;if(!n)return t({error:"Group name is required"}),null;if(!r)return t({error:"Prompt is required"}),null;if(a.length<1)return t({error:"Select at least 1 model"}),null;if(a.length>5)return t({error:"Maximum 5 models allowed"}),null;t({isLoading:!0,error:null});try{const d=uA();if(!d)return t({error:"Select a project",isLoading:!1}),null;const p=d.path,u=await rh(p)&&e.isolateRuns!==!1,f=Id(n),b=u?await io(p):void 0,h=u?await Hy(p):null,v=[],x=c?.filter(S=>S.trim().length>0)??[],g=new Map;for(const S of a){const A=`${S.providerID}:${S.modelID}`;g.set(A,(g.get(A)||0)+1)}const w=new Map;for(const S of a){const A=`${S.providerID}:${S.modelID}`,E=g.get(A)||1,P=(w.get(A)||0)+1;w.set(A,P);const C=dA(S.providerID,S.modelID),N=E>1?Nf(f,`${C}/${P}`):Nf(f,C);try{const T=E>1?`${f}/${S.providerID}/${S.modelID}/${P}`:`${f}/${S.providerID}/${S.modelID}`;if(!u){const z=await rn.withDirectory(p,()=>rn.createSession({title:T}));v.push({sessionId:z.id,worktreePath:p,providerID:S.providerID,modelID:S.modelID,variant:S.variant});continue}const M=await Gy(d,{preferredName:N,mode:"new",branchName:N,worktreeName:N,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:x},{resolvedRootTrackingRemote:h}),R={...M,createdFromBranch:b,kind:"standard"},O=await rn.withDirectory(M.path,()=>rn.createSession({title:T}));_t.getState().setWorktreeMetadata(O.id,R),v.push({sessionId:O.id,worktreePath:M.path,providerID:S.providerID,modelID:S.modelID,variant:S.variant})}catch(T){console.warn("[MultiRun] Failed to create session:",T)}}const y=c?.filter(S=>S.trim().length>0)??[];y.length>0&&ah(d,y).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const k=v.map(S=>S.sessionId),D=v[0]?.sessionId??null;if(k.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const j=o?.map(S=>({type:"file",mime:S.mime,filename:S.filename,url:S.url}));return(async()=>{try{await Promise.allSettled(v.map(async S=>{try{await rn.withDirectory(S.worktreePath,()=>rn.sendMessage({id:S.sessionId,providerID:S.providerID,modelID:S.modelID,variant:S.variant,text:r,agent:i,files:j}))}catch(A){console.warn("[MultiRun] Failed to start run:",A)}}))}catch(S){console.warn("[MultiRun] Failed to start runs:",S)}})(),t({isLoading:!1}),{groupSlug:f,sessionIds:k,firstSessionId:D}}catch(d){return t({error:d instanceof Error?d.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"})),mA="oc:lastWorktreeSourceBranch";function Wg(t){const e=at.c(30),{git:n}=_n(),r=Fd(t),a=Rd(t),i=Ld(t),o=dh(t),c=nn(xA),d=nn(gA);let p,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==a||e[4]!==i?(p=()=>{!t||!n||a!==null||i||d(t,n,{silent:!0})},m=[t,n,d,a,i],e[0]=t,e[1]=d,e[2]=n,e[3]=a,e[4]=i,e[5]=p,e[6]=m):(p=e[5],m=e[6]),l.useEffect(p,m);let u;e[7]!==r?.all||e[8]!==t||e[9]!==c||e[10]!==n||e[11]!==a?(u=()=>{!t||!n||a===!0&&(r?.all||c(t,n))},e[7]=r?.all,e[8]=t,e[9]=c,e[10]=n,e[11]=a,e[12]=u):u=e[12];const f=r?.all;let b;e[13]!==t||e[14]!==c||e[15]!==n||e[16]!==a||e[17]!==f?(b=[t,n,a,f,c],e[13]=t,e[14]=c,e[15]=n,e[16]=a,e[17]=f,e[18]=b):b=e[18],l.useEffect(u,b);const h=i||a===!0&&o;let v;e:{if(!r?.all){let S;e[19]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[19]=S):S=e[19],v=S;break e}let j;e[20]!==r.all?(j=r.all.filter(hA).sort(),e[20]=r.all,e[21]=j):j=e[21],v=j}const x=v;let g;e:{if(!r?.all){let S;e[22]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[22]=S):S=e[22],g=S;break e}let j;e[23]!==r.all?(j=r.all.filter(fA).map(pA).sort(),e[23]=r.all,e[24]=j):j=e[24],g=j}const w=g;let y;e:{if(!t){y=null;break e}if(a!==null){y=a;break e}if(h){y=null;break e}y=r?.all?!0:null}const k=y;let D;return e[25]!==k||e[26]!==h||e[27]!==x||e[28]!==w?(D={localBranches:x,remoteBranches:w,isLoading:h,isGitRepository:k},e[25]=k,e[26]=h,e[27]=x,e[28]=w,e[29]=D):D=e[29],D}function pA(t){return t.replace(/^remotes\//,"")}function fA(t){return t.startsWith("remotes/")}function hA(t){return!t.startsWith("remotes/")}function gA(t){return t.fetchStatus}function xA(t){return t.fetchBranches}const bA=({directory:t,value:e,onChange:n,className:r,disabled:a,id:i})=>{const{t:o}=mt(),{localBranches:c,remoteBranches:d,isLoading:p,isGitRepository:m}=Wg(t),u=l.useMemo(()=>[...c,...d.map(b=>`remotes/${b}`)],[c,d]);l.useEffect(()=>{if(a||p||u.length===0||e&&u.includes(e))return;(async()=>{try{const h=t?await io(t).catch(()=>null):null,v=localStorage.getItem(mA);v&&u.includes(v)?n(v):h&&u.includes(h)?n(h):u.includes("main")?n("main"):u.includes("master")?n("master"):u[0]&&n(u[0])}catch{}})()},[u,t,a,p,n,e]);const f=a||!m||p;return s.jsxs("div",{children:[s.jsxs(ds,{value:e,onValueChange:n,disabled:f,children:[s.jsx(us,{id:i,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(bs,{placeholder:o(p?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(ms,{className:"max-h-[280px] max-w-[320px]",children:p?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:o("multiRun.branchSelector.status.loadingBranches")}):c.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:o("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[c.length>0&&s.jsxs(Xc,{children:[s.jsx(Bu,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.localBranches")}),c.map(b=>s.jsx(Lt,{value:b,className:"whitespace-normal break-all",children:b},b))]}),c.length>0&&d.length>0&&s.jsx(qy,{}),d.length>0&&s.jsxs(Xc,{children:[s.jsx(Bu,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.remoteBranches")}),d.map(b=>s.jsx(Lt,{value:`remotes/${b}`,className:"whitespace-normal break-all",children:b},`remotes/${b}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:o("multiRun.branchSelector.status.notInGitRepository")})]})},yA=10*1024*1024,Uc=5,$o=t=>{const e=at.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Pt,{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 a;return e[1]!==n?(a=s.jsxs(It,{children:[r,s.jsx(At,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=a):a=e[2],a},Ja=t=>{const e=at.c(9),{htmlFor:n,required:r,children:a,info:i}=t;let o;e[0]!==r?(o=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=o):o=e[1];let c;e[2]!==a||e[3]!==n||e[4]!==o?(c=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,o]}),e[2]=a,e[3]=n,e[4]=o,e[5]=c):c=e[5];const d=i&&i;let p;return e[6]!==c||e[7]!==d?(p=s.jsxs("div",{className:"flex items-center gap-1.5",children:[c,d]}),e[6]=c,e[7]=d,e[8]=p):p=e[8],p},vA=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:a}=mt(),[i,o]=l.useState(""),[c,d]=l.useState(()=>t??""),[p,m]=l.useState([]),[u,f]=l.useState(""),[b,h]=l.useState([]),[v,x]=l.useState(!1),[g,w]=l.useState([]),[y,k]=l.useState(!1),[D,j]=l.useState(!1),[S,A]=l.useState(!0),[E,P]=l.useState(!1),[C,N]=l.useState(""),[T,M]=l.useState(!1),[R,O]=l.useState(""),z=l.useRef(null),B=l.useRef(null),$=l.useRef(null),_=l.useRef(null),Q=Ws(Re=>Re.currentDirectory??null),W=Ws(Re=>Re.homeDirectory??null),ne=l.useMemo(()=>{if(typeof window>"u")return null;const Re=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof Re=="string"&&Re.trim().length>0?Re.trim():null},[]),re=Ls(Re=>Re.activeProjectId),ue=Ls(Re=>Re.setActiveProjectIdOnly),Y=Ls(Re=>Re.projects),[le,J]=l.useState(()=>re??null);l.useEffect(()=>{if(re){J(re);return}!le&&Y.length>0&&J(Y[0].id)},[re,Y,le]);const L=l.useMemo(()=>le?Y.find(Re=>Re.id===le)??null:null,[Y,le]),V=L?.path??Q,K=l.useCallback(Re=>{J(Re),Re!==re&&ue(Re)},[re,ue]),{currentTheme:X}=Cr(),U=l.useCallback(Re=>{const de=Re.label?.trim()||Fa(Re.path,W),He=lo({id:Re.id,iconImage:Re.iconImage??null},{themeVariant:X.metadata.variant,iconColor:X.colors.surface.foreground}),st=Re.icon?Rl[Re.icon]:null,qe=Re.color?co[Re.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[He?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:Re.iconBackground?{backgroundColor:Re.iconBackground}:void 0,children:s.jsx("img",{src:He,alt:"",className:"h-full w-full object-contain",draggable:!1})}):st?s.jsx(I,{name:st,className:"h-3.5 w-3.5 shrink-0",style:qe?{color:qe}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:qe?{color:qe}:void 0}),s.jsx("span",{className:"truncate",children:de})]})},[W,X.metadata.variant,X.colors.surface.foreground]),ae=l.useMemo(()=>{if(L?.path)return{id:L.id,path:L.path};const Re=Q??ne;return Re?{id:`path:${Re}`,path:Re}:null},[L,Q,ne]),[ve,ie]=l.useState(()=>typeof window>"u"?!1:yn()),fe=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),H=Cl();l.useEffect(()=>{typeof window>"u"||ie(yn())},[]);const ce=l.useMemo(()=>{if(typeof window>"u")return null;const Re=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Re=="number"&&Number.isFinite(Re)&&Re>0)return Re;if(typeof navigator>"u")return null;const de=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!de)return null;const He=Number.parseInt(de[1],10),st=Number.parseInt(de[2],10);return Number.isNaN(He)?null:He===10?st:He},[]),se=l.useMemo(()=>ve&&fe||H?"pl-[5.5rem]":"pl-3",[ve,fe,H]),oe=l.useMemo(()=>!ve||!fe||ce===null?"":ce>=26?"h-12":ce<=15?"h-14":"",[ve,fe,ce]),te=l.useCallback(async Re=>{Re.target.closest("button, a, input, select, textarea")||Re.button===0&&ve&&await hh()},[ve]);l.useEffect(()=>{if(!n)return;const Re=de=>{de.key==="Escape"&&(de.preventDefault(),de.stopPropagation(),n())};return window.addEventListener("keydown",Re,!0),()=>window.removeEventListener("keydown",Re,!0)},[n]);const[ke,Ne]=l.useState(""),{isLoading:je,isGitRepository:Se}=Wg(V),De=l.useRef(!1),ye=Se===!0,ge=ye&&S;l.useEffect(()=>{if(Se===!1){De.current=!0,A(!1);return}Se===!0&&De.current&&(De.current=!1,A(!0))},[Se]);const Me=Vc(Re=>Re.createMultiRun),Ue=Vc(Re=>Re.error),q=Vc(Re=>Re.clearError);l.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(Re=>Re.trim().length>0?Re:t)},[t]),l.useEffect(()=>{if(!ae)return;let Re=!1;return j(!0),(async()=>{try{const de=await Vd(ae);Re||w(de)}catch{}finally{Re||j(!1)}})(),()=>{Re=!0}},[ae]);const Ie=Re=>{p.length>=Uc||(m(de=>[...de,Re]),q())},Le=Re=>{m(de=>de.filter((He,st)=>st!==Re)),q()},Pe=l.useCallback((Re,de)=>{m(He=>He.map((st,qe)=>qe===Re?de:st))},[]),he=async Re=>{const de=Re.target.files;if(!de)return;let He=0;for(let st=0;st<de.length;st++){const qe=de[st];if(qe.size>yA){G.error(a("multirun.launcher.toast.fileTooLarge",{fileName:qe.name}));continue}try{const et=await new Promise((xe,Ye)=>{const _e=new FileReader;_e.onload=()=>xe(_e.result),_e.onerror=Ye,_e.readAsDataURL(qe)}),rt={id:wl(),filename:qe.name,mimeType:qe.type||"application/octet-stream",size:qe.size,dataUrl:et};h(xe=>[...xe,rt]),He++}catch(et){console.error("File attach failed",et),G.error(a("multirun.launcher.toast.attachFailed",{fileName:qe.name}))}}He>0&&G.success(He===1?a("multirun.launcher.toast.attachedSingle",{count:He}):a("multirun.launcher.toast.attachedPlural",{count:He})),z.current&&(z.current.value="")},F=Re=>{h(de=>de.filter(He=>He.id!==Re))},ee=l.useCallback((Re,de)=>{if(Re.startsWith("/")){const qe=Re.indexOf(" "),et=Re.indexOf(`
|
|
223
|
+
`),rt=Math.min(qe===-1?Re.length:qe,et===-1?Re.length:et);if(de<=rt&&qe===-1){O(Re.substring(1,rt)),M(!0),P(!1);return}}M(!1);const He=Re.substring(0,de),st=He.lastIndexOf("@");if(st!==-1){const qe=st>0?He[st-1]:null,et=He.substring(st+1);(!qe||/\s/.test(qe))&&!et.includes(" ")&&!et.includes(`
|
|
224
|
+
`)?(N(et),P(!0)):P(!1);return}P(!1)},[]),Ce=l.useCallback(Re=>{if(T&&_.current&&(Re.key==="Enter"||Re.key==="ArrowUp"||Re.key==="ArrowDown"||Re.key==="Escape"||Re.key==="Tab")){Re.preventDefault(),_.current.handleKeyDown(Re.key);return}E&&$.current&&(Re.key==="Enter"||Re.key==="ArrowUp"||Re.key==="ArrowDown"||Re.key==="Escape"||Re.key==="Tab")&&(Re.preventDefault(),$.current.handleKeyDown(Re.key))},[T,E]),Fe=l.useCallback(Re=>{const He=B.current?.selectionStart??c.length,qe=c.substring(0,He).lastIndexOf("@"),et=Re.relativePath&&Re.relativePath.trim().length>0?Re.relativePath.trim():Re.path||Re.name,rt=qe!==-1?qe:He,xe=`${c.substring(0,rt)}@${et} ${c.substring(He)}`,Ye=rt+et.length+2;d(xe),P(!1),N(""),requestAnimationFrame(()=>{const _e=B.current;_e&&(_e.selectionStart=Ye,_e.selectionEnd=Ye,_e.focus()),ee(xe,Ye)})},[c,ee]),we=l.useCallback(Re=>{const He=B.current?.selectionStart??c.length,qe=c.substring(0,He).lastIndexOf("@"),et=qe!==-1?qe:He,rt=`${c.substring(0,et)}@${Re} ${c.substring(He)}`,xe=et+Re.length+2;d(rt),P(!1),N(""),requestAnimationFrame(()=>{const Ye=B.current;Ye&&(Ye.selectionStart=xe,Ye.selectionEnd=xe,Ye.focus()),ee(rt,xe)})},[c,ee]),Qe=l.useCallback(Re=>{const de=`/${Re.name} `;d(de),M(!1),O(""),requestAnimationFrame(()=>{const He=B.current;He&&(He.focus(),He.selectionStart=He.value.length,He.selectionEnd=He.value.length),ee(de,de.length)})},[ee]),pe=async Re=>{if(Re.preventDefault(),!!c.trim()&&!(p.length<2)){x(!0),q();try{le&&le!==re&&ue(le);const de=p.map(({instanceId:rt,...xe})=>xe),He=b.map(rt=>({mime:rt.mimeType,filename:rt.filename,url:rt.dataUrl})),st=g.filter(rt=>rt.trim().length>0),qe={name:i.trim(),prompt:c.trim(),models:de,agent:u||void 0,worktreeBaseBranch:ge?ke:void 0,isolateRuns:ge,files:He.length>0?He:void 0,setupCommands:st.length>0?st:void 0},et=await Me(qe);et&&(et.firstSessionId&&_t.getState().setCurrentSession(et.firstSessionId),e?.())}finally{x(!1)}}},Oe=!!(i.trim()&&c.trim()&&p.length>=2&&V&&!je&&(Se===!1||!ge||ke)),nt=g.filter(Re=>Re.trim()).length;return s.jsxs("form",{onSubmit:pe,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:te,className:me("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",se,oe),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:a("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":a("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(At,{children:s.jsx("p",{children:a("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(ao,{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(Ja,{htmlFor:"multirun-project",required:!0,children:a("multirun.launcher.project.label")}),Y.length>0?s.jsxs(ds,{value:le??void 0,onValueChange:K,children:[s.jsx(us,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:L?s.jsx(bs,{children:U(L)}):s.jsx(bs,{placeholder:a("multirun.launcher.project.placeholder")})}),s.jsx(ms,{fitContent:!0,children:Y.map(Re=>s.jsx(Lt,{value:Re.id,className:"max-w-[24rem]",children:U(Re)},Re.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:a("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ja,{htmlFor:"group-name",required:!0,info:s.jsx($o,{children:a("multirun.launcher.groupName.info")}),children:a("multirun.launcher.groupName.label")}),s.jsx(Wt,{id:"group-name",value:i,onChange:Re=>o(Re.target.value),placeholder:a("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ja,{htmlFor:"multirun-worktree-base-branch",info:s.jsx($o,{children:a("multirun.launcher.baseBranch.info")}),children:a("multirun.launcher.baseBranch.label")}),s.jsx(bA,{directory:V,value:ke,onChange:Ne,disabled:!ge,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(fs,{checked:S,onChange:A,disabled:!ye,ariaLabel:a("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:a("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ja,{htmlFor:"multirun-agent",info:s.jsx($o,{children:a("multirun.launcher.agent.info")}),children:a("multirun.launcher.agent.label")}),s.jsx(Lg,{value:u,onChange:f,id:"multirun-agent"})]})]}),s.jsxs(gr,{open:y,onOpenChange:k,children:[s.jsxs(kr,{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:a("multirun.launcher.setupCommands.label")}),nt>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:nt}),s.jsx(I,{name:"arrow-down-s",className:me("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",y&&"rotate-180")})]}),s.jsx(xr,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:D?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:a("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[g.map((Re,de)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Wt,{value:Re,onChange:He=>{const st=[...g];st[de]=He.target.value,w(st)},placeholder:a("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{const He=g.filter((st,qe)=>qe!==de);w(He)},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":a("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]},`${Re}-${de}`)),s.jsxs("button",{type:"button",onClick:()=>w([...g,""]),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"}),a("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Ja,{htmlFor:"prompt",required:!0,children:a("multirun.launcher.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(bn,{id:"prompt",ref:B,value:c,onChange:Re=>{const de=Re.target.value;d(de);const He=Re.target.selectionStart??de.length;ee(de,He)},onKeyDown:Ce,placeholder:a("multirun.launcher.prompt.placeholder"),className:"typography-meta min-h-[100px] max-h-[300px] resize-none overflow-y-auto field-sizing-content",required:!0}),T?s.jsx(uh,{ref:_,searchQuery:R,onCommandSelect:Qe,onClose:()=>M(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,E?s.jsx(mh,{ref:$,searchQuery:C,onFileSelect:Fe,onAgentSelect:we,onClose:()=>P(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:z,type:"file",multiple:!0,className:"hidden",onChange:he,accept:"*/*"}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>z.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"}),a("multirun.launcher.attachments.attach")]})}),s.jsx(At,{children:a("multirun.launcher.attachments.tooltip")})]}),b.map(Re=>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:[Re.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:Re.filename,children:Re.filename}),s.jsx("button",{type:"button",onClick:()=>F(Re.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(I,{name:"close",className:"h-3 w-3"})})]},Re.id))]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Ja,{required:!0,info:s.jsx($o,{children:a("multirun.launcher.models.info",{max:Uc})}),children:a("multirun.launcher.models.label")}),s.jsx($g,{selectedModels:p,onAdd:Ie,onRemove:Le,onUpdate:Pe,minModels:2,maxModels:Uc})]}),Ue&&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:Ue})]})})}),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:[!ge&&Se!==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:a("multirun.launcher.project.gitRequired")})]}):null,s.jsx(be,{type:"button",variant:"ghost",size:"sm",onClick:n,children:a("multirun.launcher.actions.cancel")}),s.jsx(be,{type:"submit",size:"sm",disabled:!Oe||v,children:v?a("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:a("multirun.launcher.actions.startWithModelCount",{count:p.length})})})]})})]})};class wA extends l.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?s.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:s.jsxs(gh,{className:"w-full max-w-md",children:[s.jsx(Yy,{className:"text-center",children:s.jsxs(Jy,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(I,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(Qy,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&s.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&s.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[s.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),s.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(be,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(I,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),s.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function jA(t){const e=at.c(22),{t:n}=mt();let r;e[0]!==n?(r=n("chat.errorBoundary.title"),e[0]=n,e[1]=r):r=e[1];let a;e[2]!==n?(a=n("chat.errorBoundary.description"),e[2]=n,e[3]=a):a=e[3];let i;e[4]!==n?(i=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=i):i=e[5];let o;e[6]!==n?(o=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=o):o=e[7];let c;e[8]!==n?(c=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=c):c=e[9];let d;e[10]!==n?(d=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=d):d=e[11];let p;e[12]!==r||e[13]!==a||e[14]!==i||e[15]!==o||e[16]!==c||e[17]!==d?(p={title:r,description:a,sessionLabel:i,detailsSummary:o,resetAction:c,persistentHint:d},e[12]=r,e[13]=a,e[14]=i,e[15]=o,e[16]=c,e[17]=d,e[18]=p):p=e[18];let m;return e[19]!==t||e[20]!==p?(m=s.jsx(wA,{...t,texts:p}),e[19]=t,e[20]=p,e[21]=m):m=e[21],m}const Pd=t=>{const e=at.c(5),{readOnly:n}=t,r=n===void 0?!1:n,i=_t(NA)||void 0;let o;e[0]!==r?(o=s.jsx(Xy,{readOnly:r}),e[0]=r,e[1]=o):o=e[1];let c;return e[2]!==i||e[3]!==o?(c=s.jsx(jA,{sessionId:i,children:o}),e[2]=i,e[3]=o,e[4]=c):c=e[4],c};function NA(t){return t.currentSessionId}const SA=Gr(()=>Sr(()=>Promise.resolve().then(()=>W2),void 0).then(t=>({default:t.PlanView}))),Sf=Gr(()=>Sr(()=>Promise.resolve().then(()=>Z0),void 0).then(t=>({default:t.GitView}))),kA=Gr(()=>Sr(()=>Promise.resolve().then(()=>u2),void 0).then(t=>({default:t.DiffView}))),kf=Gr(()=>Sr(()=>import("./TerminalView-D11XIZuz.js"),__vite__mapDeps([5,0,1,2,3,4,6])).then(t=>({default:t.TerminalView}))),CA=Gr(()=>Sr(()=>Promise.resolve().then(()=>$2),void 0).then(t=>({default:t.FilesView}))),IA=Gr(()=>Sr(()=>Promise.resolve().then(()=>r4),void 0).then(t=>({default:t.SettingsView}))),PA=Gr(()=>Sr(()=>import("./SettingsWindow-BgyVY5gz.js"),__vite__mapDeps([7,0,1,2,3,4,6])).then(t=>({default:t.SettingsWindow}))),AA=Gr(()=>Sr(()=>import("./MultiRunWindow-wnUGv0Dl.js"),__vite__mapDeps([8,0,1,2,3,4,6])).then(t=>({default:t.MultiRunWindow}))),Bo=85,DA=250,TA=500,MA=400,EA=860,RA=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},FA=()=>{const{t}=mt(),e=1140,n=1220,r=640,a=700,i=Te(J=>J.isSidebarOpen),o=Te(J=>J.isRightSidebarOpen),c=Te(J=>J.isBottomTerminalOpen),d=Te(J=>J.setRightSidebarOpen),p=Te(J=>J.setBottomTerminalOpen),m=Te(J=>J.activeMainTab),u=Te(J=>J.setIsMobile),f=Te(J=>J.isSessionSwitcherOpen),b=Te(J=>J.isSettingsDialogOpen),h=Te(J=>J.setSettingsDialogOpen),v=Te(J=>J.isMultiRunLauncherOpen),x=Te(J=>J.setMultiRunLauncherOpen),g=Te(J=>J.multiRunLauncherPrefillPrompt),{isMobile:w,isTablet:y}=an(),k=l.useMemo(()=>yn(),[]),D=Te(J=>J.sidebarWidth),j=Te(J=>J.rightSidebarWidth),[S,A]=l.useState(null),E=Lr()??"",P=l.useMemo(()=>RA(E),[E]),C=Te(J=>{if(!P)return!1;const L=J.contextPanelByDirectory[P],V=L?.tabs??[],K=V.find(X=>X.id===L?.activeTabId)??V[V.length-1];return!!(L?.isOpen&&K)}),N=Te(J=>J.setSidebarOpen),T=l.useRef(!1),M=l.useRef(!1),R=l.useRef(!1),[O,z]=l.useState(!1),B=l.useRef(!1),$=fu(0),_=ze.useRef(0),Q=fu(0),W=ze.useRef(0);ze.useEffect(()=>{w&&(_.current=window.innerWidth*(Bo/100),W.current=window.innerWidth*(Bo/100))},[w]),ze.useEffect(()=>{if(!w)return;const J=O?0:-_.current;hu($,J,{type:"spring",stiffness:400,damping:35,mass:.8})},[O,w,$]),ze.useEffect(()=>{if(!w)return;B.current=o;const J=o?0:W.current;hu(Q,J,{type:"spring",stiffness:400,damping:35,mass:.8})},[w,o,Q]),ze.useEffect(()=>{w&&z(f)},[f,w]),ze.useEffect(()=>{!w||!b||(z(!1),f&&Te.getState().setSessionSwitcherOpen(!1),o&&d(!1))},[w,b,f,o,d]),ze.useEffect(()=>{w&&(B.current=o)},[o,w]);const ne=Da(J=>J.checkForUpdates);l.useEffect(()=>{let X=!1,U=null;const ae=ie=>{const fe=Math.round(ie*1e3);return Math.max(3e5,Math.min(864e5,fe))},ve=ie=>{X||(U=window.setTimeout(async()=>{const fe=await ne(),H=typeof fe=="number"&&Number.isFinite(fe)?ae(fe):36e5;ve(H)},ie))};return ve(3e3),()=>{X=!0,U!==null&&window.clearTimeout(U)}},[ne]),l.useEffect(()=>{Te.getState().isMobile!==w&&u(w)},[w,u]),l.useEffect(()=>{if(typeof window>"u")return;let J;const L=()=>{J!==void 0&&window.clearTimeout(J),J=window.setTimeout(()=>{Te.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",L),()=>{window.removeEventListener("resize",L),J!==void 0&&window.clearTimeout(J)}},[]),l.useEffect(()=>{if(C){Te.getState().isSidebarOpen&&(N(!1),R.current=!0);return}R.current&&(N(!0),R.current=!1)},[C,N]),l.useEffect(()=>{if(typeof window>"u")return;let J;const L=()=>{const K=Te.getState(),X=window.innerWidth,U=window.innerHeight;if(!w&&!y){const ae=X<e,ve=X>=n;ae?K.isRightSidebarOpen&&(d(!1),T.current=!0):ve&&T.current&&(d(!0),T.current=!1);const ie=U<r,fe=U>=a;ie?K.isBottomTerminalOpen&&(p(!1),M.current=!0):fe&&M.current&&(p(!0),M.current=!1)}},V=()=>{J!==void 0&&window.clearTimeout(J),J=window.setTimeout(()=>{L()},100)};return L(),window.addEventListener("resize",V),()=>{window.removeEventListener("resize",V),J!==void 0&&window.clearTimeout(J)}},[w,y,p,d]),l.useEffect(()=>{if(typeof window>"u")return;const J=Te.subscribe((L,V)=>{const K=window.innerWidth,X=window.innerHeight,U=K>=n,ae=X>=a;L.isRightSidebarOpen!==V.isRightSidebarOpen&&U&&(T.current=!1),L.isBottomTerminalOpen!==V.isBottomTerminalOpen&&ae&&(M.current=!1)});return()=>{J()}},[w,y,p,d]);const re=l.useMemo(()=>{switch(m){case"plan":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(SA,{})});case"git":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(Sf,{})});case"diff":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(kA,{})});case"terminal":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(kf,{})});case"files":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(CA,{})});default:return null}},[m]),ue=m==="chat",Y=l.useMemo(()=>Math.min(TA,Math.max(DA,D||rd)),[D]),le=l.useMemo(()=>Math.min(EA,Math.max(MA,j||Mh)),[j]);return s.jsx(Bj,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:me("main-content-safe-area h-[100dvh]",w?"flex flex-col":"flex","bg-background"),children:[s.jsx(a4,{}),s.jsx(H4,{}),s.jsx(J4,{}),s.jsx(cA,{}),w?s.jsxs(Zy,{value:{leftDrawerOpen:O,rightDrawerOpen:o,toggleLeftDrawer:()=>{o&&d(!1),z(!O)},toggleRightDrawer:()=>{O&&z(!1),d(!o)},leftDrawerX:$,rightDrawerX:Q,leftDrawerWidth:_,rightDrawerWidth:W,setMobileLeftDrawerOpen:z,setRightSidebarOpen:d},children:[!b&&s.jsx(am,{onToggleLeftDrawer:()=>{o&&d(!1),z(!O)},onToggleRightDrawer:()=>{O&&z(!1),d(!o)},leftDrawerOpen:O,rightDrawerOpen:o}),s.jsx(Gl.button,{type:"button",initial:!1,animate:{opacity:O||o?1:0,pointerEvents:O||o?"auto":"none"},className:"fixed left-0 right-0 bottom-0 top-[var(--oc-header-height,56px)] z-40 bg-black/50 cursor-default",onClick:()=>{z(!1),d(!1)},"aria-label":t("mainLayout.mobile.closeDrawerAria")}),s.jsx(Gl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:-(_.current||window.innerWidth*.85),right:0},style:{width:`${Bo}%`,x:$},onDragEnd:(J,L)=>{const V=_.current||window.innerWidth*.85,K=V*.3,X=500,U=$.get(),ae=L.offset.x<-K||L.velocity.x<-X,ve=L.offset.x>K||L.velocity.x>X;ae?($.set(-V),z(!1)):ve?($.set(0),z(!0)):U>-V/2?$.set(0):$.set(-V)},className:me("fixed left-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!O,children:s.jsx("div",{"data-page-scroll-lock":"true",className:"h-full overflow-hidden flex bg-[var(--surface-background)] shadow-none drawer-safe-area",style:{backgroundImage:"linear-gradient(var(--surface-muted), var(--surface-muted))"},children:s.jsx("div",{className:"flex-1 min-w-0 overflow-hidden flex flex-col","data-page-scroll-lock":"true",children:s.jsx(Xs,{children:s.jsx(wf,{mobileVariant:!0})})})})}),s.jsx(Gl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:0,right:W.current||window.innerWidth*.85},style:{width:`${Bo}%`,x:Q},onDragEnd:(J,L)=>{const V=W.current||window.innerWidth*.85,K=V*.3,X=500,U=Q.get(),ae=L.offset.x>K||L.velocity.x>X,ve=L.offset.x<-K||L.velocity.x<-X;ae?(Q.set(V),d(!1)):ve?(Q.set(0),d(!0)):U<V/2?Q.set(0):Q.set(V)},className:me("fixed right-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!o,children:s.jsx("div",{className:"h-full overflow-hidden flex flex-col bg-background shadow-none drawer-safe-area","data-page-scroll-lock":"true",children:s.jsx(Xs,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(Sf,{})})})})}),s.jsx("div",{"data-page-scroll-lock":"true",className:me("flex flex-1 overflow-hidden relative",b&&"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:me("absolute inset-0",!ue&&"invisible"),children:s.jsx(Xs,{children:s.jsx(Pd,{})})}),re&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Xs,{children:re})}),v&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Xs,{children:s.jsx(vA,{initialPrompt:g,onCreated:()=>x(!1),onCancel:()=>x(!1)})})})]})}),b&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(Xs,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(IA,{onClose:()=>h(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-1 overflow-hidden relative",children:s.jsxs("div",{className:me("absolute inset-0 flex overflow-hidden","bg-sidebar"),"data-page-scroll-lock":"true",children:[i?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:me("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{left:`${Y}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:me("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{left:`${Y}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)"}})]}):null,o?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:me("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{right:`${le}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:me("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{right:`${le}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)"}})]}):null,s.jsx(X1,{isOpen:i,isMobile:w,className:"border-0",children:s.jsx(wf,{})}),s.jsxs("div",{className:me("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-sidebar",i&&"border-l border-border/50 rounded-tl-[10px] rounded-bl-[10px]",o&&"border-r border-border/50 rounded-tr-[10px] rounded-br-[10px]"),"data-page-scroll-lock":"true",children:[s.jsx(am,{desktopRightSidebarActionsHost:S}),s.jsx("div",{className:me("flex flex-1 min-h-0 overflow-hidden",i||ue?"":"border-l border-border/50",o?"":"border-r border-border/50"),"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:me("absolute inset-0",!ue&&"invisible"),children:s.jsx(Xs,{children:s.jsx(Pd,{})})}),re&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Xs,{children:re})})]}),s.jsx(DS,{})]})}),s.jsx(G1,{isOpen:c,isMobile:w,children:c?s.jsx(Xs,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(kf,{})})}):null})]}),s.jsx(Z1,{isOpen:o,className:"border-0",onTopActionsHostChange:A,children:s.jsx(Xs,{children:s.jsx(EN,{})})})]})}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(PA,{open:b,onOpenChange:h})}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(AA,{open:v,onOpenChange:x,initialPrompt:g})})]})]})})},LA=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`},mr=t=>{const e=at.c(8),{label:n,value:r}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=a):a=e[0];let i;e[1]!==n?(i=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=i):i=e[2];let o;e[3]!==r?(o=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=o):o=e[4];let c;return e[5]!==i||e[6]!==o?(c=s.jsxs("div",{className:"rounded-md p-2",style:a,children:[i,o]}),e[5]=i,e[6]=o,e[7]=c):c=e[7],c},Cf=t=>{const e=at.c(43),{title:n,snapshot:r,emptyLabel:a}=t,{t:i}=mt();let o;if(e[0]!==a||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==i||e[6]!==n){const c=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(BA,0),e[8]=r.entries,e[9]=d):d=e[9];const p=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 u;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==i?(u=r.startedAt?LA(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=u):u=e[15];let f;e[16]!==u?(f=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:u}),e[16]=u,e[17]=f):f=e[17];let b;e[18]!==m||e[19]!==f?(b=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,f]}),e[18]=m,e[19]=f,e[20]=b):b=e[20];let h;e[21]!==i?(h=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=h):h=e[22];let v;e[23]!==r.entries.length||e[24]!==h?(v=s.jsx(mr,{label:h,value:r.entries.length}),e[23]=r.entries.length,e[24]=h,e[25]=v):v=e[25];let x;e[26]!==i?(x=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=x):x=e[27];let g;e[28]!==x||e[29]!==p?(g=s.jsx(mr,{label:x,value:p}),e[28]=x,e[29]=p,e[30]=g):g=e[30];let w;e[31]!==i?(w=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=w):w=e[32];let y;e[33]!==r.lastUpdatedAt||e[34]!==i?(y=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=y):y=e[35];let k;e[36]!==w||e[37]!==y?(k=s.jsx(mr,{label:w,value:y}),e[36]=w,e[37]=y,e[38]=k):k=e[38];let D;e[39]!==g||e[40]!==k||e[41]!==v?(D=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[v,g,k]}),e[39]=g,e[40]=k,e[41]=v,e[42]=D):D=e[42],o=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[b,D,c.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:a}):s.jsx(Es,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:c.map(j=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:j.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:i("memoryDebugPanel.metric.countValue",{value:j.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:j.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:j.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:j.total})})]})]},j.metric))})})]}),e[0]=a,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=i,e[6]=n,e[7]=o}else o=e[7];return o},OA=t=>{const e=at.c(101),{onClose:n}=t,{t:r}=mt(),[a,i]=l.useState("memory"),[o,c]=l.useState("idle"),d=_t(zA),p=fh(_A),m=El(),u=sh(VA),f=fr(UA),[b,h]=l.useState(WA),[v,x]=l.useState(KA);let g;e[0]!==b.entries?(g=new Map,b.entries.forEach(Ne=>{g.set(Ne.metric,Ne.count)}),e[0]=b.entries,e[1]=g):g=e[1];let w;e[2]!==g?(w=g.get("ui.message_list.render")??0,e[2]=g,e[3]=w):w=e[3];let y;e[4]!==g?(y=g.get("ui.message_list.render.streaming")??0,e[4]=g,e[5]=y):y=e[5];let k;e[6]!==g?(k=g.get("ui.chat_message.render")??0,e[6]=g,e[7]=k):k=e[7];let D;e[8]!==g?(D=g.get("ui.chat_message.render.streaming")??0,e[8]=g,e[9]=D):D=e[9];let j;e[10]!==g?(j=g.get("ui.chat_message.render.static_during_stream")??0,e[10]=g,e[11]=j):j=e[11];let S;e[12]!==g?(S=g.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=g,e[13]=S):S=e[13];let A;e[14]!==w||e[15]!==y||e[16]!==k||e[17]!==D||e[18]!==j||e[19]!==S?(A={messageListRender:w,messageListRenderStreaming:y,chatMessageRender:k,chatMessageRenderStreaming:D,chatMessageRenderStaticDuringStream:j,chatMessageRenderStaticOutsideActiveTurnDuringStream:S},e[14]=w,e[15]=y,e[16]=k,e[17]=D,e[18]=j,e[19]=S,e[20]=A):A=e[20];const E=A;let P,C;e[21]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{const Ne=()=>{h(Wo()),x(Ko())};Ne();const je=window.setInterval(Ne,500);return()=>window.clearInterval(je)},C=[],e[21]=P,e[22]=C):(P=e[21],C=e[22]),l.useEffect(P,C);let N,T;e[23]!==o?(N=()=>{if(o==="idle")return;const Ne=window.setTimeout(()=>{c("idle")},1500);return()=>window.clearTimeout(Ne)},T=[o],e[23]=o,e[24]=N,e[25]=T):(N=e[24],T=e[25]),l.useEffect(N,T);let M=0,R;if(e[26]!==u?(R=Object.keys(u),e[26]=u,e[27]=R):R=e[27],e[28]!==u||e[29]!==R||e[30]!==M){for(const Ne of R)M=M+(u[Ne]?.length??0);e[28]=u,e[29]=R,e[30]=M,e[31]=M}else M=e[31];const O=M;let z;if(e[32]!==d||e[33]!==u||e[34]!==p||e[35]!==m||e[36]!==r){let Ne;e[38]!==d||e[39]!==u||e[40]!==p||e[41]!==r?(Ne=je=>{const Se=u[je.id]?.length||0,De=p.get(je.id);return{id:je.id,title:je.title||r("memoryDebugPanel.common.untitled"),messageCount:Se,isStreaming:De?.isStreaming||!1,isZombie:De?.isZombie||!1,backgroundCount:De?.backgroundMessageCount||0,lastAccessed:De?.lastAccessedAt||0,isCurrent:je.id===d}},e[38]=d,e[39]=u,e[40]=p,e[41]=r,e[42]=Ne):Ne=e[42],z=m.map(Ne).sort(HA),e[32]=d,e[33]=u,e[34]=p,e[35]=m,e[36]=r,e[37]=z}else z=e[37];const B=z;let $;e[43]!==u?($=Object.keys(u),e[43]=u,e[44]=$):$=e[44];const _=$.length;let Q;e[45]===Symbol.for("react.memo_cache_sentinel")?(Q=async()=>{try{const Ne={generatedAt:new Date().toISOString(),ui:Wo(),vscode:Ko()};await navigator.clipboard.writeText(JSON.stringify(Ne,null,2)),c("copied")}catch{c("error")}},e[45]=Q):Q=e[45];const W=Q;let ne;e[46]===Symbol.for("react.memo_cache_sentinel")?(ne={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=ne):ne=e[46];let re;e[47]!==a?(re=a==="memory"?s.jsx(I,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(I,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=a,e[48]=re):re=e[48];let ue;e[49]!==r?(ue=r("memoryDebugPanel.title"),e[49]=r,e[50]=ue):ue=e[50];let Y;e[51]!==ue?(Y=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:ue}),e[51]=ue,e[52]=Y):Y=e[52];let le;e[53]!==re||e[54]!==Y?(le=s.jsxs("div",{className:"flex items-center gap-2",children:[re,Y]}),e[53]=re,e[54]=Y,e[55]=le):le=e[55];let J;e[56]!==a?(J=a==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(be,{size:"xs",variant:"ghost",onClick:W,children:s.jsx(I,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(be,{size:"xs",variant:"ghost",onClick:()=>{tv(),h(Wo()),x(Ko())},children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=a,e[57]=J):J=e[57];let L;e[58]!==n?(L=n?s.jsx(be,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null,e[58]=n,e[59]=L):L=e[59];let V;e[60]!==J||e[61]!==L?(V=s.jsxs("div",{className:"flex items-center gap-1",children:[J,L]}),e[60]=J,e[61]=L,e[62]=V):V=e[62];let K;e[63]!==le||e[64]!==V?(K=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[le,V]}),e[63]=le,e[64]=V,e[65]=K):K=e[65];let X;e[66]===Symbol.for("react.memo_cache_sentinel")?(X={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=X):X=e[66];const U=a==="memory"?"secondary":"ghost";let ae;e[67]===Symbol.for("react.memo_cache_sentinel")?(ae=()=>i("memory"),e[67]=ae):ae=e[67];let ve;e[68]!==r?(ve=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=ve):ve=e[69];let ie;e[70]!==U||e[71]!==ve?(ie=s.jsx(be,{size:"sm",variant:U,className:"flex-1",onClick:ae,children:ve}),e[70]=U,e[71]=ve,e[72]=ie):ie=e[72];const fe=a==="streaming"?"secondary":"ghost";let H;e[73]===Symbol.for("react.memo_cache_sentinel")?(H=()=>i("streaming"),e[73]=H):H=e[73];let ce;e[74]!==r?(ce=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=ce):ce=e[75];let se;e[76]!==fe||e[77]!==ce?(se=s.jsx(be,{size:"sm",variant:fe,className:"flex-1",onClick:H,children:ce}),e[76]=fe,e[77]=ce,e[78]=se):se=e[78];let oe;e[79]!==ie||e[80]!==se?(oe=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:X,children:[ie,se]}),e[79]=ie,e[80]=se,e[81]=oe):oe=e[81];let te;e[82]!==a||e[83]!==_||e[84]!==o||e[85]!==d||e[86]!==u||e[87]!==p||e[88]!==B||e[89]!==m||e[90]!==E||e[91]!==b||e[92]!==r||e[93]!==f||e[94]!==O||e[95]!==v?(te=a==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(mr,{label:r("memoryDebugPanel.metric.totalMessages"),value:O}),s.jsx(mr,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${_} / ${zu.MAX_SESSIONS}`})]}),s.jsxs("div",{className:"typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2",children:[s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.viewportWindow")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.messagesValue",{count:ev()})})]}),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:zu.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:f})]})]}),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(Es,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:B.map(Ne=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Ne.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:Ne.title}),Ne.isStreaming?s.jsx(I,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Ne.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:Ne.messageCount})}),Ne.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Ne.backgroundCount]}):null]})]},Ne.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(be,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(GA),currentSessionId:d,cachedSessions:Object.keys(u),memoryStates:Object.fromEntries(p)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(At,{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(o==="copied"?"memoryDebugPanel.streaming.copy.copied":o==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(be,{size:"xs",variant:"outline",onClick:W,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(mr,{label:r("memoryDebugPanel.metric.uiMetrics"),value:b.entries.length}),s.jsx(mr,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:v.entries.length}),s.jsx(mr,{label:r("memoryDebugPanel.metric.messageListRenders"),value:E.messageListRender}),s.jsx(mr,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:E.messageListRenderStreaming}),s.jsx(mr,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:E.chatMessageRender}),s.jsx(mr,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:E.chatMessageRenderStreaming}),s.jsx(mr,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:E.chatMessageRenderStaticDuringStream}),s.jsx(mr,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:E.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(Cf,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:b,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),v.entries.length>0?s.jsx(Cf,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:v,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=a,e[83]=_,e[84]=o,e[85]=d,e[86]=u,e[87]=p,e[88]=B,e[89]=m,e[90]=E,e[91]=b,e[92]=r,e[93]=f,e[94]=O,e[95]=v,e[96]=te):te=e[96];let ke;return e[97]!==K||e[98]!==oe||e[99]!==te?(ke=s.jsxs(gh,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:ne,children:[K,oe,te]}),e[97]=K,e[98]=oe,e[99]=te,e[100]=ke):ke=e[100],ke},$A=OA;function BA(t,e){return t+e.count}function zA(t){return t.currentSessionId}function _A(t){return t.sessionMemoryState}function VA(t){return t.message}function UA(t){return t.totalRequestCount}function WA(){return Wo()}function KA(){return Ko()}function HA(t,e){return e.lastAccessed-t.lastAccessed}function GA(t){return{id:t.id,title:t.title}}const qA=()=>{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()??"":""},YA=async()=>{const t=qA()||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")},If="openchamber:menu-action",Wc="openchamber:check-for-updates",JA=t=>{const e=_t(x=>x.openNewSessionDraft),n=Te(x=>x.toggleCommandPalette),r=Te(x=>x.setCommandPaletteOpen),a=Te(x=>x.toggleHelpDialog),i=Te(x=>x.toggleSidebar),o=Te(x=>x.setSessionSwitcherOpen),c=Te(x=>x.setActiveMainTab),d=Te(x=>x.setSettingsDialogOpen),p=Te(x=>x.setAboutDialogOpen),m=Da(x=>x.checkForUpdates),{setThemeMode:u}=Cr(),f=l.useRef(!1),b=l.useCallback(()=>{f.current||(f.current=!0,m().then(()=>{const{available:x,error:g}=Da.getState();if(g){G.error("Failed to check for updates",{description:g});return}x||G.success("You are on the latest version")}).finally(()=>{f.current=!1}))},[m]),h=l.useCallback(()=>{Nr.requestDirectoryDialog()},[]),v=l.useCallback(x=>{switch(x){case"about":p(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":c("chat"),o(!1),e();break;case"new-worktree-session":c("chat"),o(!1),lh();break;case"change-workspace":h();break;case"open-git-tab":{const{activeMainTab:g}=Te.getState();c(g==="git"?"chat":"git");break}case"open-diff-tab":{const{activeMainTab:g}=Te.getState();c(g==="diff"?"chat":"diff");break}case"open-files-tab":{const{activeMainTab:g}=Te.getState();c(g==="files"?"chat":"files");break}case"open-terminal-tab":{const{activeMainTab:g}=Te.getState();c(g==="terminal"?"chat":"terminal");break}case"copy":{const g=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(g)||YA();break}case"theme-light":u("light");break;case"theme-dark":u("dark");break;case"theme-system":u("system");break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"help-dialog":a();break;case"download-logs":{sv().catch(()=>{G.error("Failed to collect OpenCode status")});break}}},[h,t,e,p,c,o,r,d,u,n,a,i]);l.useEffect(()=>{const x=w=>{const y=w.detail;y&&v(y)},g=()=>{b()};return window.addEventListener(If,x),window.addEventListener(Wc,g),()=>{window.removeEventListener(If,x),window.removeEventListener(Wc,g)}},[v,b]),l.useEffect(()=>{if(typeof window>"u")return;const g=window.__TAURI__?.event?.listen;if(typeof g!="function")return;let w=null,y=null;return g("openchamber:menu-action",k=>{const D=k?.payload;typeof D=="string"&&v(D)}).then(k=>{w=k}).catch(()=>{}),g("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(Wc))}).then(k=>{y=k}).catch(()=>{}),()=>{(async()=>{try{const D=w?.();D instanceof Promise&&await D}catch{}try{const D=y?.();D instanceof Promise&&await D}catch{}})()}},[v])},QA=["chat","git","diff","terminal","files"],XA=["settings","agents","commands","skills","providers","usage","git-identities"],wr={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Pf(t){const e=ZA();return{sessionId:eD(e),tab:tD(e),settingsPath:sD(e),diffFile:nD(e)}}function ZA(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function eD(t){const e=t.get(wr.SESSION);return!e||e.trim().length===0?null:e.trim()}function tD(t){const e=t.get(wr.TAB);if(!e)return null;const n=e.toLowerCase().trim();return QA.includes(n)?n:null}function sD(t){const e=t.get(wr.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(XA.includes(n),n)}function nD(t){const e=t.get(wr.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function Af(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(wr.SESSION)||t.has(wr.TAB)||t.has(wr.SETTINGS)||t.has(wr.FILE)}catch{return!1}}const rD="chat";function Kg(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(wr.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(wr.SETTINGS,n),e}return t.tab!==rD&&e.set(wr.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(wr.FILE,t.diffFile),e}function aD(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function iD(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=Kg(t),r=[...e.entries()].sort((i,o)=>i[0].localeCompare(o[0])),a=[...n.entries()].sort((i,o)=>i[0].localeCompare(o[0]));if(r.length!==a.length)return!1;for(let i=0;i<r.length;i++)if(r[i][0]!==a[i][0]||r[i][1]!==a[i][1])return!1;return!0}catch{return!0}}function oD(t,e={}){if(!(typeof window>"u")&&!lD()&&!(!e.force&&iD(t)))try{const n=Kg(t),r=aD(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function lD(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function cD(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function dD(){const t=l.useMemo(()=>cD(),[]),e=l.useRef(!1),n=l.useRef(!1),r=_t(u=>u.setCurrentSession),a=Te(u=>u.setActiveMainTab),i=Te(u=>u.setSettingsDialogOpen),o=Te(u=>u.setSettingsPage),c=Te(u=>u.navigateToDiff),d=l.useCallback(async u=>{if(!n.current){n.current=!0;try{if(u.sessionId){const f=_t.getState().currentSessionId;u.sessionId!==f&&await r(u.sessionId)}if(u.settingsPath){o(cg(u.settingsPath)),i(!0);return}Te.getState().isSettingsDialogOpen&&i(!1),u.tab&&a(u.tab),u.diffFile&&(u.tab==="diff"||!u.tab)&&c(u.diffFile)}finally{n.current=!1}}},[r,a,i,o,c]),p=l.useCallback(()=>{const u=_t.getState(),f=Te.getState();return{sessionId:u.currentSessionId,tab:f.activeMainTab,isSettingsOpen:f.isSettingsDialogOpen,settingsPath:f.settingsPage,diffFile:f.pendingDiffFile}},[]),m=l.useCallback((u={})=>{if(t||n.current)return;const f=p();oD(f,u)},[t,p]);l.useEffect(()=>{if(e.current||(e.current=!0,!Af()))return;const u=Pf();(async()=>(await d(u),t||m({replace:!0})))()},[d,t,m]),l.useEffect(()=>{if(t)return;let u=_t.getState().currentSessionId;return _t.subscribe(b=>{const h=b.currentSessionId;h===u||n.current||(u=h,m())})},[t,m]),l.useEffect(()=>{if(t)return;let u=Te.getState().activeMainTab,f=Te.getState().isSettingsDialogOpen,b=Te.getState().settingsPage,h=Te.getState().pendingDiffFile;return Te.subscribe(x=>{if(n.current)return;const g=x.activeMainTab!==u,w=x.isSettingsDialogOpen!==f,y=x.settingsPage!==b,k=x.pendingDiffFile!==h&&x.activeMainTab==="diff";u=x.activeMainTab,f=x.isSettingsDialogOpen,b=x.settingsPage,h=x.pendingDiffFile,(g||w||y||k)&&m()})},[t,m]),l.useEffect(()=>{if(typeof window>"u"||t)return;const u=()=>{const f=Pf();if(Af())d(f);else{const b=Te.getState();b.isSettingsDialogOpen&&i(!1),b.activeMainTab!=="chat"&&a("chat")}};return window.addEventListener("popstate",u),()=>{window.removeEventListener("popstate",u)}},[d,t,a,i])}const Df="pwa-install-toast-shown",uD=()=>{const t=at.c(6),{browserTab:e}=jg(),{t:n}=mt(),r=l.useRef(n);let a,i;t[0]!==n?(a=()=>{r.current=n},i=[n],t[0]=n,t[1]=a,t[2]=i):(a=t[1],i=t[2]),l.useEffect(a,i);let o,c;t[3]!==e?(o=()=>{if(typeof window>"u"||!aa()||!e)return;let d=null,p=null;const m=()=>{p!==null&&(G.dismiss(p),p=null)},u=async()=>{if(!d)return;const h=d;d=null,m(),await h.prompt();const{outcome:v}=await h.userChoice;v==="accepted"&&G.success(r.current("pwa.installPrompt.started"))},f=h=>{const v=h;if(typeof v.prompt!="function")return;v.preventDefault(),d=v;const x=Uf();x.getItem(Df)!=="true"&&p===null&&(x.setItem(Df,"true"),p=G.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{u()}}}))},b=()=>{d=null,m(),G.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",f),window.addEventListener("appinstalled",b),()=>{m(),window.removeEventListener("beforeinstallprompt",f),window.removeEventListener("appinstalled",b)}},c=[e],t[3]=e,t[4]=o,t[5]=c):(o=t[4],c=t[5]),l.useEffect(o,c)},mD=["local","remote",null],pD=["ok","not-configured","unreachable","wrong-service","missing"];function Hg(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!mD.includes(n)))return{valid:!1};if(typeof r!="string"||!pD.includes(r))return{valid:!1};if(n==="remote"||n==="local"){if(r==="ok"&&n==="local")return{valid:!0,outcome:{target:"local",status:"ok"}};if(r==="ok"&&n==="remote")return typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"ok",hostId:e.hostId,url:e.url}};if(r==="unreachable")return n==="local"?{valid:!0,outcome:{target:"local",status:"unreachable"}}:typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"unreachable",hostId:e.hostId,url:e.url}};if(r==="wrong-service")return n!=="remote"?{valid:!1}:typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"wrong-service",hostId:e.hostId,url:e.url}};if(r==="missing")return n!=="remote"?{valid:!1}:typeof e.hostId!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"missing",hostId:e.hostId}}}if(n===null){if(r==="not-configured")return{valid:!0,outcome:{target:null,status:"not-configured"}};if(r==="missing")return{valid:!1}}return{valid:!1}}function Tf(t){if(!t.isDesktopShell)return null;const e=t.bootOutcome;if(!e)return null;if(e.status==="ok"){if(e.target==="local")return{screen:"main"};if(e.target==="remote")return{screen:"main",hostId:e.hostId,url:e.url}}if(e.target===null&&e.status==="not-configured")return{screen:"chooser"};if(e.target==="local"&&e.status==="unreachable")return{screen:"recovery",variant:"local-unavailable"};if(e.target==="remote"){if(e.status==="unreachable")return{screen:"recovery",variant:"remote-unreachable",hostId:e.hostId,url:e.url};if(e.status==="wrong-service")return{screen:"recovery",variant:"remote-wrong-service",hostId:e.hostId,url:e.url};if(e.status==="missing")return{screen:"recovery",variant:"remote-missing",hostId:e.hostId}}return null}function fD(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function hD(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function Mf(){if(Ad()!=="valid")return null;const e=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__,n=Hg(e);return n.valid?n.outcome:null}function Ad(){if(typeof window>"u")return"not-injected";const t=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":Hg(t).valid?"valid":"malformed"}const gD=()=>{const t=at.c(5),[e,n]=l.useState(xD),{isUpdating:r,message:a}=e;let i,o;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>rv(n),o=[],t[0]=i,t[1]=o):(i=t[0],o=t[1]),l.useEffect(i,o),!r)return null;let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(zd,{width:80,height:80}),t[2]=c):c=t[2];let d;return t[3]!==a?(d=s.jsxs("div",{className:"fixed inset-0 z-[9999] flex flex-col items-center justify-center gap-6 bg-background/90",children:[c,s.jsx("p",{className:"typography-body text-muted-foreground",children:a})]}),t[3]=a,t[4]=d):d=t[4],d};function xD(){return nv()}const bD=({open:t,onOpenChange:e})=>{const{t:n}=mt(),[r,a]=l.useState(null),[i,o]=l.useState(null),[c,d]=l.useState(!1),[p,m]=l.useState(!1),[u,f]=l.useState(null),[b,h]=l.useState(!1),v=l.useCallback(async()=>{if(!c){d(!0),m(!1);try{if(!u){G.error(n("aboutDialog.toast.copyFailed"),{description:n("aboutDialog.toast.diagnosticsNotReady")});return}const g=await _u.copyTextToClipboard(u);g.ok?(m(!0),G.success(n("aboutDialog.toast.diagnosticsCopied"))):G.error(n("aboutDialog.toast.copyFailed"),{description:g.error})}catch(g){G.error(n("aboutDialog.toast.copyFailed")),console.error("Failed to copy diagnostics:",g)}finally{d(!1)}}},[u,c,n]);l.useEffect(()=>{if(!t)return;(async()=>{try{const w=await fetch("/api/system/info");if(w.ok){const y=await w.json();if(typeof y.openchamberVersion=="string"&&y.openchamberVersion.trim()){a(y.openchamberVersion);return}}}catch{}a(await av())})()},[t]),l.useEffect(()=>{if(!t)return;let g=!1;return(async()=>{try{const y=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!y.ok)return;const k=await y.json().catch(()=>null),D=typeof k?.currentVersion=="string"?k.currentVersion.trim():"";!g&&D&&o(D)}catch{}})(),()=>{g=!0}},[t]),l.useEffect(()=>{if(!t){f(null),h(!1);return}let g=!1;return h(!0),_u.buildDiagnosticsReport().then(w=>{g||f(w)}).catch(w=>{g||(console.error("Failed to prepare diagnostics:",w),f(null))}).finally(()=>{g||h(!1)}),()=>{g=!0}},[t]);const x=r;return s.jsx(vs,{open:t,onOpenChange:e,children:s.jsx(ys,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(zd,{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:[x&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:x})}),i&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:i})})]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("button",{onClick:v,disabled:c||b||!u,className:me("typography-meta text-muted-foreground hover:text-foreground","underline-offset-2 hover:underline","disabled:opacity-50 disabled:cursor-not-allowed"),children:n(p?"aboutDialog.actions.diagnosticsCopied":b?"aboutDialog.actions.preparingDiagnostics":"aboutDialog.actions.copyDiagnostics")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:n("aboutDialog.diagnosticsDescription")})]}),s.jsxs("div",{className:"flex items-center gap-4 pt-2",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/btriapitsyn",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:"@btriapitsyn"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},Kc=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},yD=(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},vD=()=>{const t=wn(i=>i.completeAuth),[e,n]=l.useState("working"),[r,a]=l.useState("Completing MCP authorization...");return l.useEffect(()=>{if(typeof window>"u"){n("error"),a("Browser context unavailable.");return}const i=new URLSearchParams(window.location.search),o=Kc(i,"code"),c=fg(i),d=tu(i),p=Kc(i,"error"),m=Kc(i,"error_description");if(p){d&&fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(m??p);return}(async()=>{try{if(!o)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let u=c;if(!u&&d){const f=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(f.ok){const b=await f.json().catch(()=>null);b?.name?.trim()&&(u={name:b.name.trim(),directory:typeof b.directory=="string"&&b.directory.trim()?b.directory.trim():null})}}if(!u?.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(u.name,o,u.directory),d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),a("Authorization completed. You can close this tab and return to OpenChamber.")}catch(u){d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(yD(u,"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(be,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},zo="opencode-update-available",_o="opencode-upgrade-progress",wD=5e3,jD=[1e4,6e4],Gg=()=>{const{t}=mt(),e=Te(o=>o.showOpenCodeUpdateNotifications),n=ze.useRef(new Set),r=ze.useRef(!1);ze.useEffect(()=>{e||G.dismiss(zo)},[e]);const a=ze.useCallback(()=>{G.dismiss(_o),ai({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),i=ze.useCallback(async()=>{if(!r.current){r.current=!0,G.dismiss(zo),G.message(t("opencodeUpdate.toast.upgrading.title"),{id:_o,description:t("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:s.jsx(I,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const o=await fetch("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),c=await o.json().catch(()=>null);if(!o.ok||c?.success===!1)throw new Error(c?.error||o.statusText||t("opencodeUpdate.toast.failed.description"));G.success(t("opencodeUpdate.toast.updated.title"),{id:_o,description:c?.version?t("opencodeUpdate.toast.updated.descriptionWithVersion",{version:c.version}):t("opencodeUpdate.toast.updated.description"),duration:1/0,icon:s.jsx(I,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:t("opencodeUpdate.toast.actions.reload"),onClick:a}})}catch(o){G.error(t("opencodeUpdate.toast.failed.title"),{id:_o,description:o instanceof Error?o.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[a,t]);return ze.useEffect(()=>{const o=u=>{if(!Te.getState().showOpenCodeUpdateNotifications){G.dismiss(zo);return}u&&(n.current.has(u)||(n.current.add(u),G.info(t("opencodeUpdate.toast.available.title"),{id:zo,description:t("opencodeUpdate.toast.available.description",{version:u}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:i}})))},c=u=>{const f=typeof u.detail?.version=="string"?String(u.detail.version).trim():"";o(f)};let d=!1;const p=[],m=async u=>{try{const f=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!f.ok)throw new Error(f.statusText||"OpenCode upgrade status check failed");const b=await f.json().catch(()=>null),h=typeof b?.latestVersion=="string"?b.latestVersion.trim():"";!d&&b?.available===!0&&h&&o(h)}catch{const f=jD[u];!d&&f!==void 0&&p.push(setTimeout(()=>{m(u+1)},f))}};return e&&p.push(setTimeout(()=>{m(0)},wD)),window.addEventListener("openchamber:opencode-update-available",c),()=>{d=!0;for(const u of p)clearTimeout(u);window.removeEventListener("openchamber:opencode-update-available",c)}},[i,e,t]),null},Ef=Gr(()=>Sr(()=>import("./OnboardingScreen-17dAs0NH.js"),__vite__mapDeps([9,0,1,2,3,4])).then(t=>({default:t.OnboardingScreen}))),ND=()=>{const t=at.c(3),e=Te(AD),n=Te(DD);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(bD,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},SD=t=>{const e=at.c(21),{onRetry:n,isRetrying:r}=t,{t:a}=mt();let i;e[0]!==a?(i=a("startup.initRecovery.title"),e[0]=a,e[1]=i):i=e[1];let o;e[2]!==i?(o=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=o):o=e[3];let c;e[4]!==a?(c=a("startup.initRecovery.description"),e[4]=a,e[5]=c):c=e[5];let d;e[6]!==c?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:c}),e[6]=c,e[7]=d):d=e[7];let p;e[8]!==o||e[9]!==d?(p=s.jsxs("div",{className:"flex flex-col gap-2",children:[o,d]}),e[8]=o,e[9]=d,e[10]=p):p=e[10];let m;e[11]!==r||e[12]!==a?(m=a(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=a,e[13]=m):m=e[13];let u;e[14]!==r||e[15]!==n||e[16]!==m?(u=s.jsx(be,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=u):u=e[17];let f;return e[18]!==p||e[19]!==u?(f=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:[p,u]})}),e[18]=p,e[19]=u,e[20]=f):f=e[20],f},Rf=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",kD=()=>{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"),a=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:a,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true"}},CD=()=>typeof window>"u"?!1:window.location.pathname===pg,ID=t=>{const e=at.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:a}=t,i=Ws(TD),o=_t(MD),c=_t(ED),d=Wd(),p=l.useRef(null);let m;e[0]!==n.directory?(m=Rf(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const u=m;let f;e[2]!==i?(f=Rf(i),e[2]=i,e[3]=f):f=e[3];const b=f;let h,v;if(e[4]!==b||e[5]!==o||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==u||e[9]!==r||e[10]!==c||e[11]!==d?(h=()=>{if(r||u&&b!==u)return;const D=`${u}
|
|
225
|
+
${n.sessionId}`;p.current===D&&o===n.sessionId||(p.current=D,c(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},v=[b,o,n.directory,n.sessionId,u,r,c,d],e[4]=b,e[5]=o,e[6]=n.directory,e[7]=n.sessionId,e[8]=u,e[9]=r,e[10]=c,e[11]=d,e[12]=h,e[13]=v):(h=e[12],v=e[13]),l.useEffect(h,v),u&&b!==u)return null;let x;e[14]!==a?(x=s.jsx(xh,{embeddedBackgroundWorkEnabled:a}),e[14]=a,e[15]=x):x=e[15];let g;e[16]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(Gg,{}),e[16]=g):g=e[16];let w;e[17]!==n.readOnly?(w=s.jsx(Pd,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=w):w=e[18];let y;e[19]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(bh,{}),e[19]=y):y=e[19];let k;return e[20]!==x||e[21]!==w?(k=s.jsxs(s.Fragment,{children:[x,g,w,y]}),e[20]=x,e[21]=w,e[22]=k):k=e[22],k};function PD({apis:t}){const e=gt(L=>L.initializeApp),n=gt(L=>L.isInitialized),r=gt(L=>L.isConnected),a=gt(L=>L.providers.length),i=gt(L=>L.agents.length),o=gt(L=>L.loadProviders),c=gt(L=>L.loadAgents),d=_t(L=>L.error),p=_t(L=>L.clearError),m=Ws(L=>L.currentDirectory),u=Ws(L=>L.setDirectory),f=Ws(L=>L.isSwitchingDirectory),[b,h]=l.useState(!1),v=Hn(L=>L.refreshStatus),[x,g]=l.useState(()=>t.runtime.isVSCode),[w,y]=l.useState(!0),[k,D]=l.useState(!1),[j,S]=l.useState(0),[A,E]=l.useState(!1),P=Te(L=>L.wideChatLayoutEnabled),C=Te(L=>L.mobileKeyboardMode),N=l.useMemo(()=>yn(),[]),T=Md(L=>L.setPlanModeEnabled),[M,R]=l.useState(()=>Ad()),[O,z]=l.useState(()=>{const L=Mf();return L!==null?Tf({isDesktopShell:!0,bootOutcome:L}):null}),B=l.useRef(!1),$=l.useMemo(()=>kD(),[]),_=!$||w,Q=l.useMemo(()=>CD(),[]);l.useEffect(()=>(Vu(b),()=>{Vu(!1)}),[b]),l.useEffect(()=>{iv(C)},[C]),l.useEffect(()=>{g(t.runtime.isVSCode)},[t.runtime.isVSCode]),l.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",P),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[P]),l.useEffect(()=>(Uu(t),()=>Uu(null)),[t]),l.useEffect(()=>{$||v(t.github,{force:!0})},[t.github,$,v]),ov();const W=M==="valid",ne=O?.screen==="main";l.useEffect(()=>{if(!fD({isDesktopShell:N,isInitialized:n,bootOutcomeKnown:W,bootViewIsMain:ne}))return;const L=setTimeout(()=>{const V=document.getElementById("initial-loading");V&&(V.classList.add("fade-out"),setTimeout(()=>{V.remove()},300))},150);return()=>clearTimeout(L)},[N,n,W,ne]),l.useEffect(()=>{if(!N||M!=="malformed")return;const L=document.getElementById("initial-loading");L&&(L.textContent="Desktop startup failed — please restart the app.")},[N,M]),l.useEffect(()=>{if(N)return;const L=setTimeout(()=>{const V=document.getElementById("initial-loading");V&&!n&&(V.classList.add("fade-out"),setTimeout(()=>{V.remove()},300))},5e3);return()=>clearTimeout(L)},[N,n]),l.useEffect(()=>{let L=!1;return(async()=>{const K=await fetch("/health",{method:"GET"}).catch(()=>null);if(!K||!K.ok||L)return;const X=await K.json().catch(()=>null);if(!X||L)return;const U=X.planModeExperimentalEnabled;T(U===!0||U===1||U==="1"||U==="true")})(),()=>{L=!0}},[T]),l.useEffect(()=>{x||e()},[e,x]),l.useEffect(()=>{if(x||n)return;let L=!0,V,K=0;const X=10,U=1e3,ae=async()=>{if(!L)return;if(K>=X){D(!0);return}const ve=gt.getState();if(ve.isInitialized){D(!1);return}K+=1,await ve.initializeApp();const ie=gt.getState();if(!L)return;if(ie.isInitialized){D(!1);return}if(K>=X){D(!0);return}const fe=Math.min(U*Math.pow(2,K-1),16e3);V=setTimeout(ae,fe)};return V=setTimeout(ae,U),()=>{L=!1,V&&clearTimeout(V)}},[j,n,x]),l.useEffect(()=>{n&&D(!1)},[n]),l.useEffect(()=>{if(!k)return;const L=document.getElementById("initial-loading");L&&(L.classList.add("fade-out"),setTimeout(()=>{L.remove()},300))},[k]),l.useEffect(()=>{if(x||!r||a>0&&i>0)return;let L=!0,V=0;const K=15,X=async()=>{const ae=gt.getState();if(!(ae.providers.length>0&&ae.agents.length>0))try{ae.providers.length===0&&await o(),gt.getState().agents.length===0&&await c()}catch{}};X();const U=setInterval(()=>{if(L){if(++V>=K){clearInterval(U);return}X()}},2e3);return()=>{L=!1,clearInterval(U)}},[r,x,c,o,a,i]),l.useEffect(()=>{f||x||r&&rn.setDirectory(m)},[m,f,r,x]),l.useEffect(()=>{if(!$||typeof window>"u")return;const L=X=>{const U=X?.visible===!0;y(U)},V=X=>{if(X.origin!==window.location.origin)return;const U=X.data;U?.type==="openchamber:embedded-visibility"&&L(U.payload)},K=window;return K.__openchamberSetEmbeddedVisibility=L,window.addEventListener("message",V),()=>{window.removeEventListener("message",V),K.__openchamberSetEmbeddedVisibility===L&&delete K.__openchamberSetEmbeddedVisibility}},[$]),l.useEffect(()=>{!$?.directory||x||m!==$.directory&&u($.directory,{showOverlay:!1})},[m,$,x,u]),l.useEffect(()=>{if(!$||typeof window>"u")return;const L=V=>{V.storageArea===window.localStorage&&V.key==="ui-store"&&Te.persist.rehydrate()};return window.addEventListener("storage",L),()=>{window.removeEventListener("storage",L)}},[$]),l.useEffect(()=>{if(typeof window>"u")return;const L=V=>{const K=V.detail,X=typeof K?.sessionId=="string"?K.sessionId.trim():"";if(!X)return;const U=typeof K?.directory=="string"&&K.directory.trim().length>0?K.directory.trim():null;Te.getState().setActiveMainTab("chat"),_t.getState().setCurrentSession(X,U)};return window.addEventListener("openchamber:open-session",L),()=>window.removeEventListener("openchamber:open-session",L)},[]),l.useEffect(()=>{if(typeof window>"u")return;const L=V=>{const K=V.detail,X=typeof K?.directory=="string"&&K.directory.trim().length>0?K.directory.trim():null,U=typeof K?.projectId=="string"&&K.projectId.trim().length>0?K.projectId.trim():null;Te.getState().setActiveMainTab("chat"),Te.getState().setSessionSwitcherOpen(!1),_t.getState().openNewSessionDraft({selectedProjectId:U,directoryOverride:X,preserveDirectoryOverride:!!X})};return window.addEventListener("openchamber:open-draft-session",L),()=>window.removeEventListener("openchamber:open-draft-session",L)},[]),l.useEffect(()=>{if(typeof window>"u")return;const L=V=>{const K=V.detail,X=typeof K?.projectPath=="string"?K.projectPath.trim():"";if(!X)return;const U=Ls.getState(),ae=U.projects.find(ve=>ve.path===X);ae?U.setActiveProject(ae.id):U.addProject(X)};return window.addEventListener("openchamber:open-project",L),()=>window.removeEventListener("openchamber:open-project",L)},[]),l.useEffect(()=>{typeof window>"u"||!n||f||B.current||(B.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,f]),lv({enabled:_}),uD(),cv(),dD();const re=l.useCallback(()=>{h(L=>!L)},[]);JA(re),l.useEffect(()=>{if($)return;const L=V=>{Ed(V)&&V.shiftKey&&!V.altKey&&(V.code==="KeyD"||V.key.toLowerCase()==="d")&&(V.preventDefault(),h(X=>!X))};return window.addEventListener("keydown",L,!0),()=>window.removeEventListener("keydown",L,!0)},[$]),l.useEffect(()=>{$||d&&setTimeout(()=>p(),5e3)},[p,$,d]),l.useEffect(()=>{if(!N||M!=="not-injected")return;let L=!1,V=0;const K=200,X=2e3,U=50,ae=()=>{if(L)return;V++;const ve=Ad();if(ve!=="not-injected"){if(L=!0,R(ve),ve==="valid"){const fe=Mf();fe&&z(Tf({isDesktopShell:!0,bootOutcome:fe}))}return}const ie=Math.min(K*Math.pow(1.1,V),X);if(V>=U){const fe=document.getElementById("initial-loading");fe&&!fe.textContent?.includes("taking longer")&&(fe.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(ae,ie)};return window.setTimeout(ae,K),()=>{L=!0}},[N,M]);const ue=l.useCallback(async()=>{if(hD({isTauriShell:Ma(),isDesktopLocalOriginActive:Kr()})){await ih();return}window.location.reload()},[]),Y=l.useCallback(async()=>{if(!A){D(!1),E(!0);try{await gt.getState().initializeApp()}finally{E(!1)}gt.getState().isInitialized||S(L=>L+1)}},[A]),le=L=>{if(L.screen==="recovery")return L.variant};if(N&&O&&O.screen!=="main"){if(O.screen==="chooser")return s.jsx(Xs,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(l.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Ef,{mode:"first-launch",onCliAvailable:ue,onChooseRemote:()=>{}})})})});const L=le(O),V=O.screen==="recovery"&&"url"in O?O.url:void 0;return s.jsx(Xs,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(l.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Ef,{mode:"recovery",recoveryVariant:L,recoveryHostUrl:V,recoveryHostLabel:void 0,onCliAvailable:ue})})})})}if($)return s.jsx(Xs,{children:s.jsx(Wu,{sdk:rn.getSdkClient(),directory:m||"",children:s.jsx(Ku,{apis:t,children:s.jsx(Hu,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(ID,{embeddedSessionChat:$,isVSCodeRuntime:x,embeddedBackgroundWorkEnabled:_})})})})})});if(Q)return s.jsx(Xs,{children:s.jsx(vD,{})});if(k&&!n&&!x&&!$)return s.jsx(Xs,{children:s.jsx(SD,{onRetry:()=>{Y()},isRetrying:A})});const J=!n&&!N;return s.jsx(Xs,{children:s.jsx(Wu,{sdk:rn.getSdkClient(),directory:m||"",children:s.jsx(Ku,{apis:t,children:s.jsx(Dw,{children:s.jsx(dv,{children:s.jsx(Hu,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:N?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(xh,{embeddedBackgroundWorkEnabled:_}),s.jsx(Gg,{}),s.jsx(FA,{}),s.jsx(bh,{}),!J&&s.jsxs(s.Fragment,{children:[s.jsx(gD,{}),s.jsx(ND,{}),b&&s.jsx($A,{onClose:()=>h(!1)})]})]})})})})})})})}function AD(t){return t.isAboutDialogOpen}function DD(t){return t.setAboutDialogOpen}function TD(t){return t.currentDirectory}function MD(t){return t.currentSessionId}function ED(t){return t.setCurrentSession}const RD=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();uv();mv().then(()=>{Promise.all([pv(),fv()]).catch(t=>{console.error("[main] settings init failed:",t)}),hv(),gv(),xv()}).catch(t=>{console.error("[main] appearance init failed:",t)});const qg=document.getElementById("root");if(!qg)throw new Error("Root element not found");Rx.createRoot(qg).render(s.jsx(ze.StrictMode,{children:s.jsx(bv,{children:s.jsx(yv,{children:s.jsx(vv,{children:s.jsx(wv,{children:s.jsx(PD,{apis:RD})})})})})}));const UD=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{vA as M,Ho as P,Er as S,YC as a,UD as m,ln as u};
|