@openchamber/web 1.11.5 → 1.11.7
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/README.md +6 -0
- package/bin/cli.js +443 -2
- package/dist/assets/{MarkdownRendererImpl-C3-ZpwEx.js → MarkdownRendererImpl-DaF15QNC.js} +1 -1
- package/dist/assets/{MultiRunWindow-BDfPzMDy.js → MultiRunWindow-Cl7wS_CB.js} +1 -1
- package/dist/assets/{OnboardingScreen-DGgh4IXB.js → OnboardingScreen-DTv6YJI1.js} +2 -2
- package/dist/assets/{SettingsWindow-B8QKr5dB.js → SettingsWindow-_c3TTL2z.js} +1 -1
- package/dist/assets/{TerminalView-D7IIkSGJ.js → TerminalView-CuXkDROt.js} +4 -4
- package/dist/assets/es-CYoUf2D-.js +15 -0
- package/dist/assets/{index-DHluop4D.js → index-3WXrN3AX.js} +1 -1
- package/dist/assets/index-BREIbhcb.css +1 -0
- package/dist/assets/ko-2tM0fIna.js +15 -0
- package/dist/assets/main-BF3kWAJ9.js +239 -0
- package/dist/assets/{main-VVcyjpiF.js → main-o8ZERrmU.js} +2 -2
- package/dist/assets/miniChat-BZQjpK23.js +2 -0
- package/dist/assets/{modelPrefsAutoSave-Ctdc3cCY.js → modelPrefsAutoSave-wwnbqBk7.js} +109 -107
- package/dist/assets/pl-Dq8uAotM.js +15 -0
- package/dist/assets/pt-BR-nh9s9DFT.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-CsddCM3q.js → renderElectronMiniChatApp-C-Ezew9P.js} +2 -2
- package/dist/assets/uk-BZtz0wUV.js +15 -0
- package/dist/assets/{vendor-.bun-Bum-iBXX.js → vendor-.bun-CV3tusA8.js} +1 -1
- package/dist/assets/zh-CN-j_nYMchE.js +15 -0
- package/dist/assets/zh-TW-B11UpkDJ.js +15 -0
- package/dist/index.html +11 -28
- package/dist/mini-chat.html +4 -4
- package/package.json +1 -1
- package/server/index.js +2 -0
- package/server/lib/cloudflare-tunnel.js +3 -5
- package/server/lib/fs/routes.js +5 -0
- package/server/lib/fs/routes.test.js +61 -1
- package/server/lib/git/DOCUMENTATION.md +1 -0
- package/server/lib/git/routes.js +82 -1
- package/server/lib/git/service.js +338 -19
- package/server/lib/git/service.test.js +414 -8
- package/server/lib/ngrok-tunnel.js +209 -0
- package/server/lib/opencode/core-routes.js +1 -0
- package/server/lib/opencode/env-runtime.js +52 -4
- package/server/lib/opencode/env-runtime.test.js +82 -6
- package/server/lib/opencode/feature-routes-runtime.js +35 -0
- package/server/lib/opencode/index.js +19 -0
- package/server/lib/opencode/npm-registry.js +157 -0
- package/server/lib/opencode/npm-registry.test.js +179 -0
- package/server/lib/opencode/openchamber-routes.js +9 -7
- package/server/lib/opencode/plugin-routes.js +373 -0
- package/server/lib/opencode/plugin-routes.test.js +384 -0
- package/server/lib/opencode/plugin-spec.js +107 -0
- package/server/lib/opencode/plugin-spec.test.js +154 -0
- package/server/lib/opencode/plugins.js +393 -0
- package/server/lib/opencode/plugins.test.js +176 -0
- package/server/lib/opencode/settings-helpers.js +6 -0
- package/server/lib/opencode/settings-helpers.test.js +11 -0
- package/server/lib/opencode/settings-runtime.js +39 -1
- package/server/lib/opencode/settings-runtime.test.js +39 -0
- package/server/lib/skills-catalog/source.js +1 -1
- package/server/lib/tunnels/DOCUMENTATION.md +1 -0
- package/server/lib/tunnels/providers/ngrok.js +117 -0
- package/server/lib/tunnels/types.js +2 -0
- package/dist/assets/es-dIVpApmS.js +0 -15
- package/dist/assets/index-Bk9IWJe1.css +0 -1
- package/dist/assets/ko-Cqf3E9-d.js +0 -15
- package/dist/assets/main-D45l3Dxw.js +0 -232
- package/dist/assets/miniChat-a9w7WM0c.js +0 -2
- package/dist/assets/pl-C577DpsX.js +0 -15
- package/dist/assets/pt-BR-BeeF6VlK.js +0 -15
- package/dist/assets/uk-CZ7XVz_D.js +0 -15
- package/dist/assets/zh-CN-BMSSqdyO.js +0 -15
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-CV3tusA8.js","assets/vendor--V65Sl9C2.css","assets/modelPrefsAutoSave-wwnbqBk7.js","assets/index-3WXrN3AX.js","assets/index-BREIbhcb.css","assets/TerminalView-CuXkDROt.js","assets/SettingsWindow-_c3TTL2z.js","assets/MultiRunWindow-Cl7wS_CB.js","assets/OnboardingScreen-DTv6YJI1.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as ot,R as o,u as mo,a as bi,j as s,b as Xl,C as Zl,P as po,S as Al,d as Ix,D as Dl,e as fo,f as ho,g as ar,i as ei,r as Ve,k as Px,l as Ax,p as Fi,m as Co,n as Dx,o as Tx,q as Ex,_ as Rr,s as uh,v as fd,t as ti,w as mh,x as ol,W as Mx,y as Rx,V as Fx,F as Lx,z as Ox,A as Qn,E as $x,B as zn,G as _x,H as Li,I as Ru,J as Bx,K as Vx,L as hc,M as zx,N as Ux,O as Wx,Q as Fu,T as Tl,U as Lu,X as Kx,Y as ph,Z as fh,$ as Hx,a0 as Ou,a1 as Gx,a2 as qx,a3 as Jx,a4 as Yx,a5 as Qx,a6 as $u,a7 as xt,a8 as Lo,a9 as Xx,aa as Zx,ab as eb,ac as tb,ad as sb,ae as nb,af as rb,ag as ab,ah as ib,ai as ob,aj as lb,ak as cb,al as _u,am as Bu,an as Vu,ao as db}from"./vendor-.bun-CV3tusA8.js";import{a as ub,b as mb,f as pb}from"./index-3WXrN3AX.js";import{u as pt,a as _e,b as an,c as ge,I as A,d as Cs,i as un,g as dr,e as vr,s as ll,r as cl,f as dl,h as Ss,o as rn,j as Ms,T as It,k as Pt,l as At,m as Ga,n as ia,p as zu,D as Ot,q as fb,t as El,v as Ln,w as K,x as Is,y as nr,z as Ps,A as As,B as hh,C as Uu,E as hb,F as gb,G as Wu,H as xb,J as bb,K as yb,L as vb,M as Wn,N as In,O as rr,P as hd,Q as wr,R as ra,S as gh,U as wb,V as jt,W as Lt,X as jb,Y as xh,Z as wa,_ as Qd,$ as Yn,a0 as Xd,a1 as bh,a2 as Nb,a3 as Ku,a4 as Sb,a5 as kb,a6 as yh,a7 as Cb,a8 as Ib,a9 as vh,aa as Zd,ab as Pb,ac as ec,ad as sa,ae as eu,af as ul,ag as Ab,ah as Db,ai as Qs,aj as wh,ak as jh,al as Nh,am as Ur,an as ki,ao as Tb,ap as Sh,aq as ps,ar as ds,as as he,at as os,au as ls,av as qa,aw as Eb,ax as Mb,ay as Oo,az as Cn,aA as kh,aB as Ch,aC as tc,aD as Rb,aE as Ih,aF as Hu,aG as Gu,aH as ln,aI as $t,aJ as fs,aK as Fb,aL as Lb,aM as Ob,aN as $b,aO as _b,aP as Bb,aQ as Vb,aR as vs,aS as _s,aT as zb,aU as Ub,aV as ys,aW as Wb,aX as Kb,aY as Hb,aZ as Gb,a_ as Er,a$ as Io,b0 as qb,b1 as Rs,b2 as sc,b3 as gi,b4 as Ci,b5 as Ii,b6 as qu,b7 as Jb,b8 as Pi,b9 as Yb,ba as Qb,bb as Xb,bc as Zb,bd as ey,be as ty,bf as sy,bg as ns,bh as rs,bi as ms,bj as as,bk as Rt,bl as ny,bm as Na,bn as ry,bo as la,bp as tu,bq as nc,br as ay,bs as su,bt as iy,bu as oy,bv as nu,bw as ly,bx as qs,by as Po,bz as Mr,bA as cy,bB as dy,bC as gc,bD as rc,bE as ru,bF as au,bG as ac,bH as Bn,bI as iu,bJ as Ja,bK as Ml,bL as Rl,bM as Ai,bN as Ph,bO as uy,bP as Sr,bQ as my,bR as Fl,bS as py,bT as Ju,bU as fy,bV as ro,bW as ic,bX as Ah,bY as hy,bZ as gy,b_ as Ao,b$ as xy,c0 as ou,c1 as by,c2 as xi,c3 as go,c4 as Dh,c5 as Di,c6 as Th,c7 as yy,c8 as vy,c9 as lu,ca as ya,cb as yi,cc as Oa,cd as Ua,ce as oc,cf as Do,cg as To,ch as gd,ci as Eh,cj as cu,ck as Mh,cl as xo,cm as wy,cn as jy,co as Ny,cp as Sy,cq as ky,cr as vi,cs as xc,ct as Yu,cu as Cy,cv as Iy,cw as Py,cx as Ay,cy as lc,cz as bc,cA as Dy,cB as Qu,cC as aa,cD as Ty,cE as Xu,cF as Zu,cG as em,cH as tm,cI as ml,cJ as sm,cK as Ey,cL as yc,cM as My,cN as Ry,cO as Fy,cP as Ly,cQ as Oy,cR as $y,cS as _y,cT as vc,cU as nm,cV as By,cW as Vy,cX as zy,cY as Uy,cZ as Wy,c_ as wc,c$ as Ky,d0 as rm,d1 as eo,d2 as Hy,d3 as Gy,d4 as qy,d5 as Rh,d6 as Jy,d7 as pi,d8 as Yy,d9 as am,da as Qy,db as Fh,dc as $o,dd as ao,de as Xy,df as Lh,dg as Zy,dh as ev,di as im,dj as om,dk as Oh,dl as $h,dm as jc,dn as _o,dp as tv,dq as sv,dr as nv,ds as rv,dt as _h,du as Bh,dv as Vh,dw as xd,dx as du,dy as av,dz as xs,dA as bo,dB as Ti,dC as wi,dD as lm,dE as er,dF as iv,dG as io,dH as ov,dI as zh,dJ as lv,dK as cv,dL as bd,dM as dv,dN as cm,dO as uv,dP as mv,dQ as pv,dR as uu,dS as Uh,dT as fv,dU as hv,dV as gv,dW as xv,dX as dm,dY as bv,dZ as yv,d_ as vv,d$ as wv,e0 as Nc,e1 as jv,e2 as Nv,e3 as Sv,e4 as kv,e5 as Cv,e6 as Iv,e7 as Pv,e8 as Av,e9 as Dv,ea as Tv,eb as Ev,ec as Mv,ed as Rv,ee as Fv,ef as Lv,eg as um,eh as Ov,ei as $v,ej as Wh,ek as _v,el as Bv,em as Vv,en as zv,eo as ca,ep as Uv,eq as mm,er as Wv,es as pl,et as fl,eu as Kv,ev as Hv,ew as Gv,ex as qv,ey as Jv,ez as Yv,eA as pm,eB as Qv,eC as fm,eD as Xv,eE as Zv,eF as e1,eG as hm,eH as gm,eI as xm,eJ as t1,eK as Kh,eL as Hh,eM as s1,eN as n1,eO as r1,eP as a1,eQ as i1,eR as o1,eS as l1,eT as c1,eU as d1,eV as u1,eW as m1}from"./modelPrefsAutoSave-wwnbqBk7.js";const p1=({transform:t})=>({...t,y:0}),f1=t=>{const e=ot.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:l,listeners:c,setNodeRef:d,transform:f,transition:m,isDragging:u}=Xl(i);let p;e[2]!==f?(p=Zl.Transform.toString(f),e[2]=f,e[3]=p):p=e[3];let b;e[4]!==p||e[5]!==m?(b={transform:p,transition:m},e[4]=p,e[5]=m,e[6]=b):b=e[6];const g=u&&"opacity-50";let y;e[7]!==a||e[8]!==g?(y=ge("h-full rounded-md",a,g),e[7]=a,e[8]=g,e[9]=y):y=e[9];let x;return e[10]!==l||e[11]!==r||e[12]!==n||e[13]!==c||e[14]!==d||e[15]!==b||e[16]!==y?(x=s.jsx("div",{ref:d,"data-sortable-tab-id":n,style:b,className:y,...l,...c,children:r}),e[10]=l,e[11]=r,e[12]=n,e[13]=c,e[14]=d,e[15]=b,e[16]=y,e[17]=x):x=e[17],x},h1=t=>{const e=ot.c(6),{id:n,children:r,className:a}=t;let i;e[0]!==a?(i=ge("h-full",a),e[0]=a,e[1]=i):i=e[1];let l;return e[2]!==r||e[3]!==n||e[4]!==i?(l=s.jsx("div",{className:i,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=i,e[5]=l):l=e[5],l},Fr=t=>{const e=ot.c(121),{items:n,activeId:r,onSelect:a,onClose:i,onReorder:l,layoutMode:c,variant:d,activePillInsetClassName:f,activePillButtonClassName:m,inactiveTabsIconOnly:u,iconOnlyActiveTab:p,animateActivePill:b,activePillLowercase:g,className:y}=t,x=c===void 0?"scrollable":c,h=d===void 0?"default":d,j=u===void 0?!1:u,v=p===void 0?!1:p,C=g===void 0?!0:g,{t:k}=pt(),w=_e(g1),{isTablet:N}=an(),I=w||N,E=o.useRef(null);let P;e[0]===Symbol.for("react.memo_cache_sentinel")?(P={left:!1,right:!1},e[0]=P):P=e[0];const[T,S]=o.useState(P);let M;e[1]!==n?(M=n.map(x1),e[1]=n,e[2]=M):M=e[2];const D=M,F=x==="scrollable",_=h==="default",V=h==="active-pill",$=h==="animated",O=V||$,B=_,G=O||B,R=V&&F,H=O,J=b??$,ne=typeof l=="function",ue=ne?f1:h1;let de;e[3]===Symbol.for("react.memo_cache_sentinel")?(de=new Map,e[3]=de):de=e[3];const pe=o.useRef(de),[W,te]=o.useState(null);let X;e[4]===Symbol.for("react.memo_cache_sentinel")?(X={activationConstraint:{distance:8}},e[4]=X):X=e[4];const ee=mo(bi(po,X)),fe=b1;let be;e[5]===Symbol.for("react.memo_cache_sentinel")?(be=(Ze,ze)=>{if(ze){pe.current.set(Ze,ze);return}pe.current.delete(Ze)},e[5]=be):be=e[5];const Ne=be;let se;e[6]!==r||e[7]!==G?(se=()=>{if(!G||!r){te(y1);return}const Ze=E.current,ze=pe.current.get(r);if(!Ze||!ze){te(v1);return}let rt=0,Ge=0,ct=ze;for(;ct&&ct!==Ze;)rt=rt+ct.offsetLeft,Ge=Ge+ct.offsetTop,ct=ct.offsetParent;const Pe={left:rt,top:Ge,width:ze.offsetWidth,height:ze.offsetHeight};te(Me=>fe(Me,Pe)?Me:Pe)},e[6]=r,e[7]=G,e[8]=se):se=e[8];const ie=se;let ae;e[9]!==F?(ae=()=>{if(!F){S({left:!1,right:!1});return}const Ze=E.current;if(!Ze){S({left:!1,right:!1});return}S({left:Ze.scrollLeft>2,right:Ze.scrollLeft+Ze.clientWidth<Ze.scrollWidth-2})},e[9]=F,e[10]=ae):ae=e[10];const xe=ae;let Z;e[11]!==F||e[12]!==xe?(Z=()=>{if(!F){S({left:!1,right:!1});return}const Ze=E.current;if(!Ze)return;xe(),Ze.addEventListener("scroll",xe,{passive:!0});const ze=new ResizeObserver(xe);return ze.observe(Ze),()=>{Ze.removeEventListener("scroll",xe),ze.disconnect()}},e[11]=F,e[12]=xe,e[13]=Z):Z=e[13];let me;e[14]!==F||e[15]!==n.length||e[16]!==xe?(me=[F,n.length,xe],e[14]=F,e[15]=n.length,e[16]=xe,e[17]=me):me=e[17],o.useEffect(Z,me);let Y;e[18]!==r||e[19]!==ie||e[20]!==G?(Y=()=>{if(!G){te(null);return}ie();const Ze=E.current;if(!Ze)return;const ze=new ResizeObserver(ie);if(ze.observe(Ze),r){const rt=pe.current.get(r);rt&&ze.observe(rt)}return()=>{ze.disconnect()}},e[18]=r,e[19]=ie,e[20]=G,e[21]=Y):Y=e[21];let Se;e[22]!==r||e[23]!==n.length||e[24]!==ie||e[25]!==G?(Se=[r,n.length,ie,G],e[22]=r,e[23]=n.length,e[24]=ie,e[25]=G,e[26]=Se):Se=e[26],o.useEffect(Y,Se);let we;e[27]!==ie?(we=()=>{ie()},e[27]=ie,e[28]=we):we=e[28],o.useLayoutEffect(we);let ke;e[29]!==r||e[30]!==F||e[31]!==xe?(ke=()=>{if(!F||!r)return;const Ze=E.current;if(!Ze)return;const ze=window.requestAnimationFrame(()=>{const rt=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),Ge=Ze.querySelector(`[data-sortable-tab-id="${rt}"]`);Ge&&(Ge.scrollIntoView({block:"nearest",inline:"nearest"}),xe())});return()=>{window.cancelAnimationFrame(ze)}},e[29]=r,e[30]=F,e[31]=xe,e[32]=ke):ke=e[32];let Fe;e[33]!==r||e[34]!==F||e[35]!==n.length||e[36]!==xe?(Fe=[r,F,n.length,xe],e[33]=r,e[34]=F,e[35]=n.length,e[36]=xe,e[37]=Fe):Fe=e[37],o.useEffect(ke,Fe);let Ce;e[38]!==l?(Ce=Ze=>{if(!l)return;const{active:ze,over:rt}=Ze;!rt||ze.id===rt.id||l(String(ze.id),String(rt.id))},e[38]=l,e[39]=Ce):Ce=e[39];const Q=Ce;let ce;e[40]!==y?(ce=ge("relative flex h-full min-w-0 flex-1",y),e[40]=y,e[41]=ce):ce=e[41];let ve;e[42]!==F||e[43]!==T||e[44]!==O?(ve=F&&T.left?s.jsx("div",{className:ge("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",O?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=F,e[43]=T,e[44]=O,e[45]=ve):ve=e[45];let le;e[46]!==F||e[47]!==T||e[48]!==O?(le=F&&T.right?s.jsx("div",{className:ge("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",O?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=F,e[47]=T,e[48]=O,e[49]=le):le=e[49];const Ae=O?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Te=O&&"@container/pill-tabs",$e=O&&"pill-tabs__track",ye=O&&(f??"gap-0.5 py-0.5"),q=B&&"items-center overflow-y-hidden",L=H&&"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",U=F?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let oe;e[50]!==Ae||e[51]!==Te||e[52]!==$e||e[53]!==ye||e[54]!==q||e[55]!==L||e[56]!==U?(oe=ge("relative flex h-full min-w-0 flex-1",Ae,Te,$e,ye,q,L,U),e[50]=Ae,e[51]=Te,e[52]=$e,e[53]=ye,e[54]=q,e[55]=L,e[56]=U,e[57]=oe):oe=e[57];let Ee;e[58]!==F?(Ee=F?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=F,e[59]=Ee):Ee=e[59];let Oe;e[60]!==k?(Oe=k("sortableTabsStrip.aria.tabs"),e[60]=k,e[61]=Oe):Oe=e[61];let Ie;e[62]!==W||e[63]!==J||e[64]!==O?(Ie=O&&W?s.jsx("div",{className:ge("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(${W.left}px, ${W.top}px, 0)`,width:`${W.width}px`,height:`${W.height}px`,transition:J?"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]=W,e[63]=J,e[64]=O,e[65]=Ie):Ie=e[65];let z;e[66]!==W||e[67]!==B?(z=B&&W?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(${W.left}px, 0, 0)`,width:`${W.width}px`},"aria-hidden":!0}):null,e[66]=W,e[67]=B,e[68]=z):z=e[68];let De;if(e[69]!==ue||e[70]!==r||e[71]!==m||e[72]!==C||e[73]!==I||e[74]!==v||e[75]!==j||e[76]!==V||e[77]!==w||e[78]!==F||e[79]!==n||e[80]!==i||e[81]!==a||e[82]!==R||e[83]!==O){let Ze;e[85]!==ue||e[86]!==r||e[87]!==m||e[88]!==C||e[89]!==I||e[90]!==v||e[91]!==j||e[92]!==V||e[93]!==w||e[94]!==F||e[95]!==i||e[96]!==a||e[97]!==R||e[98]!==O?(Ze=ze=>{const rt=ze.id===r,Ge=j&&O&&!rt&&!!ze.icon,ct=!Ge,Pe=!!ze.icon&&(!v||rt),Me=j&&O&&rt&&!F&&!R,Ue=ze.closable!==!1&&!!i,He=Ue&&!!ze.icon,lt=F||R?void 0:O?Me?"flex-none basis-auto":w?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",vt=Ue?dt=>{dt.button===1&&(dt.preventDefault(),dt.stopPropagation(),i?.(ze.id))}:void 0,ft=Ue?w1:void 0;return s.jsx(ue,{id:ze.id,className:lt,children:s.jsxs("div",{ref:dt=>Ne(ze.id,dt),onAuxClick:vt,onMouseDown:ft,className:ge("group flex h-full min-w-0 flex-nowrap items-center",F||R?"shrink-0":O?"w-full":"w-full min-w-0",O?"relative z-10 bg-transparent":rt?"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":rt,"aria-label":Ge?ze.title??ze.label:void 0,onClick:()=>a(ze.id),className:ge(O?"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",O&&C?"lowercase":null,O&&(Ge?"gap-0":"gap-1.5"),O?R?"shrink-0 whitespace-nowrap px-3 text-center":F?"max-w-56 shrink-0 px-3 text-center":Ge?"px-2 !min-w-0 text-center":Me?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":F?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",O?m??(V?w?"h-[38px]":"h-[31px]":"h-7"):null,O?rt?"text-foreground":"text-muted-foreground hover:text-foreground":null,O?"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:ze.title??ze.label,children:O?s.jsxs(s.Fragment,{children:[Pe?s.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[s.jsx("span",{className:ge("flex items-center justify-center transition-opacity",He&&(I?"opacity-0":"group-hover:opacity-0")),children:ze.icon}),He?s.jsx("span",{role:"button",tabIndex:-1,className:ge("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",I?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:j1,onClick:dt=>{dt.stopPropagation(),i?.(ze.id)},"aria-label":ze.closeLabel??`Close ${ze.label} tab`,title:ze.closeLabel??`Close ${ze.label} tab`,children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,ct?s.jsx("span",{className:"animated-tabs__label truncate",children:ze.label}):null]}):s.jsxs("span",{className:ge("flex min-w-0 flex-nowrap items-center gap-1.5",!F&&"justify-center"),children:[Pe?s.jsxs("span",{className:ge("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",rt?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:ge("flex items-center justify-center transition-opacity",He&&(I?"opacity-0":"group-hover:opacity-0")),children:ze.icon}),He?s.jsx("span",{role:"button",tabIndex:-1,className:ge("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",I?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:N1,onClick:dt=>{dt.stopPropagation(),i?.(ze.id)},"aria-label":ze.closeLabel??`Close ${ze.label} tab`,title:ze.closeLabel??`Close ${ze.label} tab`,children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:ze.label})]})}),Ue&&!He?s.jsx("button",{type:"button",onPointerDown:S1,onClick:dt=>{dt.stopPropagation(),i?.(ze.id)},className:ge("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",O?"-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",O?rt?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":rt?"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":ze.closeLabel??`Close ${ze.label} tab`,title:ze.closeLabel??`Close ${ze.label} tab`,children:s.jsx(A,{name:"close",className:"h-3 w-3"})}):null]})},ze.id)},e[85]=ue,e[86]=r,e[87]=m,e[88]=C,e[89]=I,e[90]=v,e[91]=j,e[92]=V,e[93]=w,e[94]=F,e[95]=i,e[96]=a,e[97]=R,e[98]=O,e[99]=Ze):Ze=e[99],De=n.map(Ze),e[69]=ue,e[70]=r,e[71]=m,e[72]=C,e[73]=I,e[74]=v,e[75]=j,e[76]=V,e[77]=w,e[78]=F,e[79]=n,e[80]=i,e[81]=a,e[82]=R,e[83]=O,e[84]=De}else De=e[84];let Qe;e[100]!==oe||e[101]!==Ee||e[102]!==Oe||e[103]!==Ie||e[104]!==z||e[105]!==De?(Qe=s.jsxs("div",{ref:E,className:oe,style:Ee,role:"tablist","aria-label":Oe,children:[Ie,z,De]}),e[100]=oe,e[101]=Ee,e[102]=Oe,e[103]=Ie,e[104]=z,e[105]=De,e[106]=Qe):Qe=e[106];let tt;e[107]!==ce||e[108]!==ve||e[109]!==le||e[110]!==Qe?(tt=s.jsxs("div",{className:ce,children:[ve,le,Qe]}),e[107]=ce,e[108]=ve,e[109]=le,e[110]=Qe,e[111]=tt):tt=e[111];const et=tt;if(!ne)return et;let We;e[112]===Symbol.for("react.memo_cache_sentinel")?(We=[p1],e[112]=We):We=e[112];let at;e[113]!==D||e[114]!==et?(at=s.jsx(Al,{items:D,strategy:Ix,children:et}),e[113]=D,e[114]=et,e[115]=at):at=e[115];let qe;e[116]===Symbol.for("react.memo_cache_sentinel")?(qe=s.jsx(Dl,{dropAnimation:null}),e[116]=qe):qe=e[116];let nt;return e[117]!==Q||e[118]!==ee||e[119]!==at?(nt=s.jsxs(fo,{sensors:ee,collisionDetection:ho,onDragEnd:Q,modifiers:We,children:[at,qe]}),e[117]=Q,e[118]=ee,e[119]=at,e[120]=nt):nt=e[120],nt};function g1(t){return t.isMobile}function x1(t){return t.id}function b1(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 y1(t){return t===null?t:null}function v1(t){return t===null?t:null}function w1(t){t.button===1&&t.preventDefault()}function j1(t){t.stopPropagation()}function N1(t){t.stopPropagation()}function S1(t){t.stopPropagation()}function bm(t){const e=ot.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 l=typeof a=="number"?`${a}px`:a,c=typeof a=="number"?`${a}px`:a;let d;e[5]!==i||e[6]!==l||e[7]!==c?(d={width:l,height:c,...i},e[5]=i,e[6]=l,e[7]=c,e[8]=d):d=e[8];let f;e[9]===Symbol.for("react.memo_cache_sentinel")?(f=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]=f):f=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:f}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const Gr=[{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:"wafer",name:"Wafer.ai"}];Gr.reduce((t,e)=>(t[e.id]=e,t),{});const k1=t=>typeof t!="number"||!Number.isFinite(t)?null:Math.max(0,Math.min(100,Math.round(t))),C1=t=>typeof t!="number"||!Number.isFinite(t)?"-":`${Math.round(t)}%`,yo=(t,e)=>t??C1(e),mu=(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??""}},Gh=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",pu=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,I1=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},vo=(t,e,n,r)=>{let a=n;if(a===null&&r&&(a=I1(r)),t===null||e===null||a===null||a<=0)return null;const i=Date.now(),l=Math.max(0,(e-i)/1e3),c=Math.max(0,Math.min(a,a-l)),d=Math.max(0,Math.min(1,c/a)),f=t/100,m=t>=100&&l>0;let u;d>.01?u=Math.min(999,f/d*100):u=t;let p;m?p="exhausted":f<=d?p="on-track":u<=130?p="slightly-fast":p="too-fast";const b=a>=120*3600,g=b?86400:3600,y=b?"d":"h",x=a/g,h=Math.max(c/g,x*.01),j=t/h,v=Number.isFinite(j)?`${Math.min(999.9,Math.max(0,j)).toFixed(1)}%/${y}`:"-",C=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`;let k=null;const w=a/86400;return w>=7&&(k=100/w),{elapsedRatio:d,usageRatio:f,predictedFinalPercent:u,remainingSeconds:l,isExhausted:m,elapsedSeconds:c,totalSeconds:a,status:p,paceRateText:v,predictText:C,dailyAllocationPercent:k}},P1=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)"}},ym=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,l=n%60;return a>0?`${a}d ${i}h`:r>0?`${r}h`:n===0?"<1m":`${l}m`},na=t=>Math.min(100,Math.max(0,t*100));function Ll(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 A1=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],qh={google:A1};function Jh(t,e){const n=qh[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function Yh(t){return qh[t]??[]}function Qh(t){return[...t].sort((e,n)=>e.order-n.order)}function D1(t,e){const n=new Map;for(const r of Object.keys(t)){const i=Jh(r,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(r)}return n}function T1(t,e,n){const r=new Map;for(const a of t){const i=e(a),c=Jh(i,n)?.id??null;r.has(c)||r.set(c,[]),r.get(c).push(a)}return r}function E1(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 fu=6e4,vm=t=>{const e=Gr.map(p=>p.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))):fu,a=t?.usageDisplayMode==="remaining"?"remaining":"usage",i=typeof t?.usageShowPredValues=="boolean"?t.usageShowPredValues:!1,l=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,c=l?l.filter(p=>typeof p=="string"&&e.includes(p)):e,d={},f=t?.usageSelectedModels;if(f&&typeof f=="object")for(const[p,b]of Object.entries(f))Array.isArray(b)&&(d[p]=b.filter(g=>typeof g=="string"));const m={},u=t?.usageExpandedFamilies;if(u&&typeof u=="object")for(const[p,b]of Object.entries(u))Array.isArray(b)&&(m[p]=b.filter(g=>typeof g=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:a,showPredValues:i,dropdownProviderIds:c,selectedModels:d,expandedFamilies:m}},M1=async()=>{const t=dr()?.settings;if(t)try{const n=(await t.load())?.settings;return vm(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 vm(n)}}return{autoRefresh:!1,refreshIntervalMs:fu,displayMode:"usage",showPredValues:!1,dropdownProviderIds:Gr.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Ns=ar()(ei((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:fu,displayMode:"usage",showPredValues:!1,dropdownProviderIds:Gr.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await M1();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Gr.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(l=>{const c=l.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(l=>{const c=l.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}),setShowPredValues:n=>t({showPredValues: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}})),Cs({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}}}),Cs({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=E1(n,r);i.length!==0&&(t(l=>({selectedModels:{...l.selectedModels,[n]:i}})),Cs({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Xh=()=>{const t=ot.c(5),e=Ns(R1),n=Ns(F1),r=Ns(L1);let a,i;t[0]!==e||t[1]!==r||t[2]!==n?(a=()=>{if(!e)return;const l=window.setInterval(()=>{r()},n);return()=>window.clearInterval(l)},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]),o.useEffect(a,i)};function R1(t){return t.autoRefresh}function F1(t){return t.refreshIntervalMs}function L1(t){return t.fetchAllQuotas}const Ol=Ve.forwardRef((t,e)=>{const n=ot.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=ge("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 l;n[5]===Symbol.for("react.memo_cache_sentinel")?(l={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=l):l=n[5];let c;n[6]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Px,{className:ge("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(Ax,{className:i,style:l,...a,ref:e,children:c}),n[7]=a,n[8]=e,n[9]=i,n[10]=d):d=n[10],d});Ol.displayName="Switch";const Bo=()=>{try{const e=Ss.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},wm=t=>t?Object.entries(t).map(([e,n])=>({key:e,value:n})):[],jm=t=>{const e=t.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},Vo=t=>typeof t!="string"?void 0:t.trim()||void 0,Sc=800,O1=5e3,$1="__default__",yd=new Map,kc=new Map,Zh=t=>t?.trim()||$1,Cc=t=>{yd.delete(Zh(t))},wo=ar()(ei(Fi((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=Bo(),a=Zh(r),i=Date.now(),l=yd.get(a)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&i-l<O1)return!0;const d=kc.get(a);if(!n?.force&&d)return d;const f=(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 p=await u.json();return t({mcpServers:p,isLoading:!1}),yd.set(a,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();kc.set(a,f);try{return await f}finally{kc.delete(a)}},createMcp:async n=>{ll("Creating MCP server configuration…");let r=!1;try{const a=Nm(n),i=Bo(),l=i?`?directory=${encodeURIComponent(i)}`:"",c=await fetch(`/api/config/mcp/${encodeURIComponent(n.name)}${l}`,{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 Cc(i),d?.requiresReload?(r=!0,await cl({message:d.message,delayMs:d.reloadDelayMs??Sc,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||dl()}},updateMcp:async(n,r)=>{ll("Updating MCP server configuration…");let a=!1;try{const i=Nm(r),l=Bo(),c=l?`?directory=${encodeURIComponent(l)}`:"",d=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${c}`,{method:"PATCH",headers:{"Content-Type":"application/json",...l?{"x-opencode-directory":l}:{}},body:JSON.stringify(i)}),f=await d.json().catch(()=>null);if(!d.ok)throw new Error(f?.error||"Failed to update MCP server");return Cc(l),f?.requiresReload?(a=!0,await cl({message:f.message,delayMs:f.reloadDelayMs??Sc,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:f?.reloadFailed===!0,message:f?.message,warning:f?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:f?.reloadFailed===!0,message:f?.message,warning:f?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{a||dl()}},deleteMcp:async n=>{ll("Deleting MCP server configuration…");let r=!1;try{const a=Bo(),i=a?`?directory=${encodeURIComponent(a)}`:"",l=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:a?{"x-opencode-directory":a}:void 0}),c=await l.json().catch(()=>null);if(!l.ok)throw new Error(c?.error||"Failed to delete MCP server");return Cc(a),c?.requiresReload&&(r=!0,await cl({message:c.message,delayMs:c.reloadDelayMs??Sc,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||dl()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:Co(()=>vr()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function Nm(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=jm(t.environment)??{}),t.headers!==void 0&&(e.headers=jm(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:Vo(t.oauthClientId),clientSecret:Vo(t.oauthClientSecret),scope:Vo(t.oauthScope),redirectUri:Vo(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 _1={},B1={},ta=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},li=t=>ta(t)??"__global__",Da=t=>{const e=ta(t);return e?rn.getScopedApiClient(e):rn.getApiClient()},kn=ar()(ei((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=li(n??Ms.getState().currentDirectory);return e().byDirectory[r]??_1},getDiagnosticForDirectory:n=>{const r=li(n??Ms.getState().currentDirectory);return e().diagnosticsByDirectory[r]??B1},getErrorForDirectory:n=>{const r=li(n??Ms.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=ta(n?.directory??Ms.getState().currentDirectory),a=li(r);n?.silent||t(i=>({loadingKeys:{...i.loadingKeys,[a]:!0},lastErrorKeys:{...i.lastErrorKeys,[a]:null}}));try{const c=(await Da(r).mcp.status()).data??{};t(d=>({byDirectory:{...d.byDirectory,[a]:c},diagnosticsByDirectory:{...d.diagnosticsByDirectory,[a]:Object.fromEntries(Object.entries(d.diagnosticsByDirectory[a]??{}).filter(([f])=>!c[f]))},loadingKeys:{...d.loadingKeys,[a]:!1},lastErrorKeys:{...d.lastErrorKeys,[a]:null}}))}catch(i){const l=i instanceof Error?i.message:"Failed to load MCP status";t(c=>({loadingKeys:{...c.loadingKeys,[a]:!1},lastErrorKeys:{...c.lastErrorKeys,[a]:l}}))}},connect:async(n,r)=>{const a=ta(r??Ms.getState().currentDirectory),i=li(a),l=Da(a);try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(c){const d=c instanceof Error?c.message:"Connection failed";throw t(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[i]:{...f.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:d}}}})),c}await e().refresh({directory:a,silent:!0})},disconnect:async(n,r)=>{const a=ta(r??Ms.getState().currentDirectory);await Da(a).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},startAuth:async(n,r)=>{const a=ta(r??Ms.getState().currentDirectory),c=(await Da(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=ta(a??Ms.getState().currentDirectory);await Da(i).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,r)=>{const a=ta(r??Ms.getState().currentDirectory);await Da(a).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},testConnection:async(n,r)=>{const a=ta(r??Ms.getState().currentDirectory),i=li(a),l=Da(a),d=e().getStatusForDirectory(a)[n]?.status==="connected";let f,m;try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(b){f=b instanceof Error?b.message:"Connection failed",t(g=>({diagnosticsByDirectory:{...g.diagnosticsByDirectory,[i]:{...g.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:f??"Connection failed"}}}}))}await e().refresh({directory:a,silent:!0});const u=e().getStatusForDirectory(a)[n],p=u;if(!d&&u?.status==="connected"){try{await l.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:p??e().getStatusForDirectory(a)[n],error:f,warning:m}}}))),V1=(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}},z1=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},eg=({active:t,className:e})=>{const{t:n}=pt(),a=Ms(h=>h.currentDirectory)??null,i=kn(h=>h.getStatusForDirectory(a)),l=kn(h=>h.refresh),c=kn(h=>h.connect),d=kn(h=>h.disconnect),f=wo(h=>h.mcpServers),m=wo(h=>h.loadMcpConfigs),[u,p]=o.useState(!1),[b,g]=o.useState(null);o.useEffect(()=>{l({directory:a,silent:!0})},[l,a]),o.useEffect(()=>{m({force:!0})},[m]),o.useEffect(()=>{t&&Promise.all([l({directory:a,silent:!0}),m({force:!0})])},[t,l,a,m]);const y=o.useMemo(()=>{const h=new Set(Object.keys(i));for(const j of f)j?.name&&h.add(j.name);return Array.from(h).sort((j,v)=>j.localeCompare(v))},[f,i]),x=o.useCallback(h=>{if(h?.preventDefault(),u)return;p(!0);const j=new Promise(v=>setTimeout(v,500));Promise.all([l({directory:a}),j]).finally(()=>{p(!1)})},[u,l,a]);return s.jsxs("div",{className:ge("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(A,{name:"refresh",className:ge("h-4 w-4",u&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[y.map(h=>{const j=i[h],v=z1(j),C=j?.status==="connected",k=b===h,w=V1(j,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:ge("h-2 w-2 rounded-full flex-shrink-0",v==="success"&&"bg-status-success",v==="error"&&"bg-status-error",v==="warning"&&"bg-status-warning",v==="default"&&"bg-muted-foreground/40"),"aria-label":w})}),s.jsx(At,{side:"left",children:s.jsx("p",{children:w})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:h})]})}),s.jsx(Ol,{checked:C,disabled:k,className:"data-[checked]:bg-status-info",onCheckedChange:async N=>{g(h);try{N?await c(h,a):await d(h,a)}finally{g(null)}}})]},h)}),y.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},jo=t=>{const e=ot.c(20),{percent:n,tonePercent:r,className:a,expectedMarkerPercent:i}=t;let l;e[0]!==n?(l=k1(n)??0,e[0]=n,e[1]=l):l=e[1];const c=l,d=r??n;let f;e[2]!==d?(f=Gh(d),e[2]=d,e[3]=f):f=e[3];const m=f,u=i!=null?Math.max(0,Math.min(100,i)):null;let p;e[4]!==m?(p=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=p):p=e[5];const b=p;let g;e[6]!==a?(g=ge("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",a),e[6]=a,e[7]=g):g=e[7];const y=`${c}%`;let x;e[8]!==b||e[9]!==y?(x={...b,width:y},e[8]=b,e[9]=y,e[10]=x):x=e[10];let h;e[11]!==c||e[12]!==x?(h=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]=h):h=e[13];let j;e[14]!==u?(j=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]=j):j=e[15];let v;return e[16]!==g||e[17]!==h||e[18]!==j?(v=s.jsxs("div",{className:g,children:[h,j]}),e[16]=g,e[17]=h,e[18]=j,e[19]=v):v=e[19],v},No=t=>{const e=ot.c(67),{paceInfo:n,className:r,compact:a}=t,i=a===void 0?!1:a,{t:l}=pt();let c;e[0]!==n.status?(c=P1(n.status),e[0]=n.status,e[1]=c):c=e[1];const d=c;let f;e:{switch(n.status){case"on-track":{let N;e[2]!==l?(N=l("settings.usage.pace.status.onTrack"),e[2]=l,e[3]=N):N=e[3],f=N;break e}case"slightly-fast":{let N;e[4]!==l?(N=l("settings.usage.pace.status.slightlyFast"),e[4]=l,e[5]=N):N=e[5],f=N;break e}case"too-fast":{let N;e[6]!==l?(N=l("settings.usage.pace.status.tooFast"),e[6]=l,e[7]=N):N=e[7],f=N;break e}case"exhausted":{let N;e[8]!==l?(N=l("settings.usage.pace.status.usedUp"),e[8]=l,e[9]=N):N=e[9],f=N;break e}}f=void 0}const m=f;let u;e[10]!==n.predictText||e[11]!==l?(u=l("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=l,e[12]=u):u=e[12];const p=u;if(i){let N;e[13]!==r?(N=ge("flex items-center gap-1.5",r),e[13]=r,e[14]=N):N=e[14];let I;e[15]!==d?(I={backgroundColor:d},e[15]=d,e[16]=I):I=e[16];let E;e[17]!==m||e[18]!==I?(E=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:I,title:m}),e[17]=m,e[18]=I,e[19]=E):E=e[19];let P;e[20]!==d?(P={color:d},e[20]=d,e[21]=P):P=e[21];const T=n.isExhausted?void 0:p;let S;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==l?(S=n.isExhausted?s.jsx(s.Fragment,{children:l("settings.usage.pace.wait",{duration:ym(n.remainingSeconds)})}):s.jsx(s.Fragment,{children:l("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=l,e[26]=S):S=e[26];let M;e[27]!==S||e[28]!==P||e[29]!==T?(M=s.jsx("span",{className:"typography-micro tabular-nums",style:P,title:T,children:S}),e[27]=S,e[28]=P,e[29]=T,e[30]=M):M=e[30];let D;return e[31]!==M||e[32]!==N||e[33]!==E?(D=s.jsxs("div",{className:N,children:[E,M]}),e[31]=M,e[32]=N,e[33]=E,e[34]=D):D=e[34],D}let b;e[35]!==r?(b=ge("flex items-center justify-between gap-2",r),e[35]=r,e[36]=b):b=e[36];let g;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==l?(g=!n.isExhausted&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=l,e[40]=g):g=e[40];let y;e[41]!==g?(y=s.jsx("div",{className:"flex items-center gap-1.5",children:g}),e[41]=g,e[42]=y):y=e[42];let x;e[43]!==d?(x={color:d},e[43]=d,e[44]=x):x=e[44];let h;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==p||e[49]!==m||e[50]!==l?(h=n.isExhausted?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"font-medium",children:m}),s.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.waitSeparator")}),s.jsx("span",{className:"font-medium",children:ym(n.remainingSeconds)})]}):s.jsxs("span",{title:p,children:[s.jsx("span",{className:"text-muted-foreground",children:l("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]=p,e[49]=m,e[50]=l,e[51]=h):h=e[51];let j;e[52]!==x||e[53]!==h?(j=s.jsx("span",{className:"typography-micro tabular-nums",style:x,children:h}),e[52]=x,e[53]=h,e[54]=j):j=e[54];let v;e[55]!==d?(v={backgroundColor:d},e[55]=d,e[56]=v):v=e[56];let C;e[57]!==m||e[58]!==v?(C=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:v,title:m}),e[57]=m,e[58]=v,e[59]=C):C=e[59];let k;e[60]!==j||e[61]!==C?(k=s.jsxs("div",{className:"flex items-center gap-1.5",children:[j,C]}),e[60]=j,e[61]=C,e[62]=k):k=e[62];let w;return e[63]!==k||e[64]!==b||e[65]!==y?(w=s.jsxs("div",{className:b,children:[y,k]}),e[63]=k,e[64]=b,e[65]=y,e[66]=w):w=e[66],w},jr=Dx,Lr=t=>{const e=ot.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 l;e[5]!==n||e[6]!==r?(l=n&&Ve.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=l):l=e[7];const c=l;let d;e[8]!==a?(d=ge("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 f;return e[10]!==i||e[11]!==c||e[12]!==d?(f=s.jsx(Tx,{className:d,...i,...c}),e[10]=i,e[11]=c,e[12]=d,e[13]=f):f=e[13],f},Nr=t=>{const e=ot.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=ge("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},va=[{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"}],vd="finder",wd=new Set(["finder","terminal"]),hu=t=>typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32"&&t.id==="finder"?{...t,label:"Explorer",appName:"File Explorer"}:t,jd=t=>{if(!t)return null;const e=va.find(n=>n.id===t)??null;return e?hu(e):null},Ic=()=>va.filter(t=>wd.has(t.id)).map(t=>({...hu(t)})),U1=()=>{if(typeof window>"u")return vd;const t=window.localStorage.getItem("openInAppId");return t&&jd(t)?t:vd};let Pc=!1,ci=!1,ma=!1,pa=0,oo=null;const Sm=()=>{oo&&(clearTimeout(oo),oo=null)},Vr=ar()((t,e)=>({selectedAppId:U1(),availableApps:Ic(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(Pc||typeof window>"u")return;Pc=!0;const n=(d,f=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:Ic(),hasLoadedApps:f});return}const m=new Set(d.map(g=>g.name)),u=new Map(d.map(g=>[g.name,g.iconDataUrl??void 0])),b=va.filter(g=>m.has(g.appName)||wd.has(g.id)).map(g=>({...hu(g),iconDataUrl:u.get(g.appName)}));t({availableApps:b,hasLoadedApps:!0})},r=async d=>{if(!Ga()||!ia()||ci||e().hasLoadedApps&&!d)return;const m=va.map(u=>u.appName);Sm(),ci=!0,ma=!1,t({isScanning:!0});try{const{apps:u,success:p,hasCache:b,isCacheStale:g}=await zu(m,d),y=p&&!b&&u.length===0&&pa<3;if(t({isCacheStale:b?g:!1}),n(u,p?!y:!1),p){if(y){const h=[800,1600,3200][pa]??3200;pa+=1,ma=!0,oo=setTimeout(()=>{r()},h);return}pa=0,ma=!1;return}if(pa<3){const h=[1e3,3e3,7e3][pa]??7e3;pa+=1,ma=!0,oo=setTimeout(()=>{r()},h)}}finally{ci=!1,ma||t({isScanning:!1})}};r();const a=d=>{const f=d.detail,m=f&&typeof f.openInAppId=="string"&&f.openInAppId.length>0&&jd(f.openInAppId)?f.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},i=()=>{r()},l=d=>{const f=d.detail;Array.isArray(f)&&(pa=3,ma=!1,t({isScanning:!1,isCacheStale:!1}),n(f))};window.addEventListener("openchamber:settings-synced",a),window.addEventListener("openchamber:app-ready",i),window.addEventListener("openchamber:installed-apps-updated",l),window.__openchamberAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(Pc||e().initialize(),!Ga()||!ia()||ci||e().hasLoadedApps&&!n)return;const a=va.map(i=>i.appName);Sm(),n&&t({hasLoadedApps:!1}),ci=!0,ma=!1,t({isScanning:!0});try{const{apps:i,hasCache:l,isCacheStale:c}=await zu(a,n),d=new Set(i.map(p=>p.name)),f=new Map(i.map(p=>[p.name,p.iconDataUrl??void 0])),u=va.filter(p=>d.has(p.appName)||wd.has(p.id)).map(p=>({...p,iconDataUrl:f.get(p.appName)}));t({availableApps:u.length>0?u:Ic(),hasLoadedApps:u.length>0,isCacheStale:l?c:!1})}finally{ci=!1,ma||t({isScanning:!1})}},selectApp:async n=>{jd(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await Cs({openInAppId:n}))}})),W1="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",K1="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",Ac=t=>({...t,fallbackIconDataUrl:t.id==="finder"?W1:t.id==="terminal"?K1:void 0}),km=t=>{const e=ot.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:a}=t,[i,l]=o.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,f=r||a;if(f&&!i){let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=()=>l(!0),e[2]=p):p=e[2];let b;return e[3]!==f?(b=s.jsx("img",{src:f,alt:"",className:"h-4 w-4 rounded-sm",onError:p}),e[3]=f,e[4]=b):b=e[4],b}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=ge("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},H1=t=>{const e=ot.c(75),{directory:n,className:r}=t,{t:a}=pt(),i=Vr(G1),l=Vr(q1),c=Vr(J1),d=Vr(Y1),f=Vr(Q1),m=Vr(X1),u=Vr(Z1);let p,b;e[0]!==f?(p=()=>{f()},b=[f],e[0]=f,e[1]=p,e[2]=b):(p=e[1],b=e[2]),o.useEffect(p,b);const g=Ga()&&ia();let y;e:{let W;e[3]!==l||e[4]!==i?(W=l.find(ee=>ee.id===i)??l.find(ew)??l[0]??va[0],e[3]=l,e[4]=i,e[5]=W):W=e[5];const te=W;if(te){let ee;e[6]!==te?(ee=Ac(te),e[6]=te,e[7]=ee):ee=e[7],y=ee;break e}let X;e[8]===Symbol.for("react.memo_cache_sentinel")?(X=Ac(va[0]),e[8]=X):X=e[8],y=X}const x=y;if(!g||!n||l.length===0)return null;let h;e[9]!==n?(h=async W=>{await fb(n,W.id,W.appName)||await El(n,W.appName)},e[9]=n,e[10]=h):h=e[10];const j=h;let v;e[11]!==j||e[12]!==u?(v=async W=>{await u(W.id),await j(W)},e[11]=j,e[12]=u,e[13]=v):v=e[13];const C=v;let k;e[14]!==n||e[15]!==a?(k=async()=>{(await Ln(n)).ok&&K.success(a("openInApp.toast.pathCopied"))},e[14]=n,e[15]=a,e[16]=k):k=e[16];const w=k;let N;e[17]!==r?(N=ge("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]=N):N=e[18];let I;e[19]!==j||e[20]!==x?(I=()=>{j(x)},e[19]=j,e[20]=x,e[21]=I):I=e[21];const E=d&&"animate-pulse";let P;e[22]!==E?(P=ge("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",E),e[22]=E,e[23]=P):P=e[23];let T;e[24]!==x.label||e[25]!==a?(T=a("openInApp.actions.openInAria",{app:x.label}),e[24]=x.label,e[25]=a,e[26]=T):T=e[26];let S;e[27]!==x.fallbackIconDataUrl||e[28]!==x.iconDataUrl||e[29]!==x.label?(S=s.jsx(km,{label:x.label,iconDataUrl:x.iconDataUrl,fallbackIconDataUrl:x.fallbackIconDataUrl}),e[27]=x.fallbackIconDataUrl,e[28]=x.iconDataUrl,e[29]=x.label,e[30]=S):S=e[30];let M;e[31]!==P||e[32]!==T||e[33]!==S||e[34]!==I?(M=s.jsx("button",{type:"button",onClick:I,className:P,"aria-label":T,children:S}),e[31]=P,e[32]=T,e[33]=S,e[34]=I,e[35]=M):M=e[35];let D;e[36]===Symbol.for("react.memo_cache_sentinel")?(D=ge("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[36]=D):D=e[36];let F;e[37]!==a?(F=a("openInApp.actions.chooseAppAria"),e[37]=a,e[38]=F):F=e[38];let _;e[39]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=_):_=e[39];let V;e[40]!==F?(V=s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:D,"aria-label":F,children:_})}),e[40]=F,e[41]=V):V=e[41];let $;e[42]!==w?($=()=>{w()},e[42]=w,e[43]=$):$=e[43];let O;e[44]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(A,{name:"file-copy",className:"h-4 w-4"}),e[44]=O):O=e[44];let B;e[45]!==a?(B=a("openInApp.actions.copyPath"),e[45]=a,e[46]=B):B=e[46];let G;e[47]!==B?(G=s.jsx("span",{className:"typography-ui-label text-foreground",children:B}),e[47]=B,e[48]=G):G=e[48];let R;e[49]!==$||e[50]!==G?(R=s.jsxs(Ot,{className:"flex items-center gap-2",onClick:$,children:[O,G]}),e[49]=$,e[50]=G,e[51]=R):R=e[51];let H;e[52]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(nr,{}),e[52]=H):H=e[52];let J;if(e[53]!==l||e[54]!==C||e[55]!==x.id){let W;e[57]!==C||e[58]!==x.id?(W=te=>{const X=Ac(te);return s.jsxs(Ot,{className:"flex items-center gap-2",onClick:()=>{C(te)},children:[s.jsx(km,{label:te.label,iconDataUrl:te.iconDataUrl,fallbackIconDataUrl:X.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:te.label}),x.id===te.id?s.jsx(A,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},te.id)},e[57]=C,e[58]=x.id,e[59]=W):W=e[59],J=l.map(W),e[53]=l,e[54]=C,e[55]=x.id,e[56]=J}else J=e[56];let ne;e[60]!==c||e[61]!==m||e[62]!==a?(ne=c?s.jsxs(Ot,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(A,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("openInApp.actions.refreshApps")})]}):null,e[60]=c,e[61]=m,e[62]=a,e[63]=ne):ne=e[63];let ue;e[64]!==R||e[65]!==J||e[66]!==ne?(ue=s.jsxs(Ps,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[R,H,J,ne]}),e[64]=R,e[65]=J,e[66]=ne,e[67]=ue):ue=e[67];let de;e[68]!==V||e[69]!==ue?(de=s.jsxs(As,{children:[V,ue]}),e[68]=V,e[69]=ue,e[70]=de):de=e[70];let pe;return e[71]!==M||e[72]!==de||e[73]!==N?(pe=s.jsxs("div",{className:N,children:[M,de]}),e[71]=M,e[72]=de,e[73]=N,e[74]=pe):pe=e[74],pe};function G1(t){return t.selectedAppId}function q1(t){return t.availableApps}function J1(t){return t.isCacheStale}function Y1(t){return t.isScanning}function Q1(t){return t.initialize}function X1(t){return t.loadInstalledApps}function Z1(t){return t.selectApp}function ew(t){return t.id===vd}const tw=1e6,sw="terminal-store";let Cm=!1;const Dc=t=>typeof t=="object"&&t!==null,nw=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function qn(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const Tc=(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}),Ec=t=>({tabs:[t],activeTabId:t.id}),_r=(t,e)=>t.tabs.findIndex(n=>n.id===e),on=ar()(ei(Fi((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=qn(n);r&&t(a=>{if(a.sessions.has(r))return a;const i=new Map(a.sessions),l=`tab-${a.nextTabId}`,c=Tc(l,"Terminal");return i.set(r,Ec(c)),{sessions:i,nextTabId:a.nextTabId+1}})},getDirectoryState:n=>{const r=qn(n);return e().sessions.get(r)},getActiveTab:n=>{const r=qn(n),a=e().sessions.get(r);if(!a)return;const i=a.activeTabId;return i?a.tabs.find(l=>l.id===i)??a.tabs[0]:a.tabs[0]},createTab:n=>{const r=qn(n);if(!r)return"tab-invalid";const a=`tab-${e().nextTabId}`;return t(i=>{const l=new Map(i.sessions),c=l.get(r),d=i.nextTabId+1,m=`Terminal ${(c?.tabs.length??0)+1}`,u=Tc(a,m);return c?l.set(r,{...c,tabs:[...c.tabs,u]}):l.set(r,Ec(u)),{sessions:l,nextTabId:d}}),a},setActiveTab:(n,r)=>{const a=qn(n);t(i=>{const l=new Map(i.sessions),c=l.get(a);return!c||c.activeTabId===r||_r(c,r)<0?i:(l.set(a,{...c,activeTabId:r}),{sessions:l})})},setTabLabel:(n,r,a)=>{const i=qn(n),l=a.trim();l&&t(c=>{const d=new Map(c.sessions),f=d.get(i);if(!f)return c;const m=_r(f,r);if(m<0||f.tabs[m]?.label===l)return c;const u=[...f.tabs];return u[m]={...u[m],label:l},d.set(i,{...f,tabs:u}),{sessions:d}})},setTabIconKey:(n,r,a)=>{const i=qn(n);t(l=>{const c=new Map(l.sessions),d=c.get(i);if(!d)return l;const f=_r(d,r);if(f<0)return l;const m=a?.trim()||null;if(d.tabs[f]?.iconKey===m)return l;const u=[...d.tabs];return u[f]={...u[f],iconKey:m},c.set(i,{...d,tabs:u}),{sessions:c}})},closeTab:async(n,r)=>{const a=qn(n),c=e().sessions.get(a)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(c)try{await ub(c)}catch{}t(d=>{const f=new Map(d.sessions),m=f.get(a);if(!m)return d;const u=_r(m,r);if(u<0)return d;const p=m.tabs.filter(x=>x.id!==r),b=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,x])=>!(x.directory===a&&x.tabId===r))),g=Object.keys(b).length!==Object.keys(d.projectActionRuns).length;if(p.length===0){const x=`tab-${d.nextTabId}`,h=Tc(x,"Terminal");return f.set(a,Ec(h)),{sessions:f,nextTabId:d.nextTabId+1,...g?{projectActionRuns:b}:{}}}let y=m.activeTabId;return m.activeTabId===r&&(y=p[Math.min(u,p.length-1)]?.id??p[0]?.id??null),f.set(a,{...m,tabs:p,activeTabId:y}),{sessions:f,...g?{projectActionRuns:b}:{}}})},setTabSessionId:(n,r,a)=>{const i=qn(n);t(l=>{const c=new Map(l.sessions),d=c.get(i);if(!d)return l;const f=_r(d,r);if(f<0)return l;const m=d.tabs[f],u=a!==null&&m.terminalSessionId!==a,p=a?"running":m.terminalSessionId?"exited":m.lifecycle,b={...m,terminalSessionId:a,lifecycle:p,isConnecting:!1,...u?{bufferChunks:[],bufferLength:0}:{}},g=[...d.tabs];return g[f]=b,c.set(i,{...d,tabs:g}),{sessions:c}})},setTabLifecycle:(n,r,a)=>{const i=qn(n);t(l=>{const c=new Map(l.sessions),d=c.get(i);if(!d)return l;const f=_r(d,r);if(f<0)return l;const m=[...d.tabs];return m[f]={...m[f],lifecycle:a,isConnecting:!1},c.set(i,{...d,tabs:m}),{sessions:c}})},setConnecting:(n,r,a)=>{const i=qn(n);t(l=>{const c=new Map(l.sessions),d=c.get(i);if(!d)return l;const f=_r(d,r);if(f<0)return l;const m=[...d.tabs];return m[f]={...m[f],isConnecting:a},c.set(i,{...d,tabs:m}),{sessions:c}})},appendToBuffer:(n,r,a)=>{if(!a)return;const i=qn(n);t(l=>{const c=new Map(l.sessions),d=c.get(i);if(!d)return l;const f=_r(d,r);if(f<0)return l;const m=d.tabs[f],u=l.nextChunkId,p={id:u,data:a},b=[...m.bufferChunks,p];let g=m.bufferLength+a.length;for(;g>tw&&b.length>1;){const x=b.shift();if(!x)break;g-=x.data.length}const y=[...d.tabs];return y[f]={...m,bufferChunks:b,bufferLength:g},c.set(i,{...d,tabs:y}),{sessions:c,nextChunkId:u+1}})},setTabPreviewUrl:(n,r,a,i={})=>{const l=qn(n);t(c=>{const d=new Map(c.sessions),f=d.get(l);if(!f)return c;const m=_r(f,r);if(m<0)return c;const u=f.tabs[m],p=i.autoOpened??u.previewAutoOpened,b=i.locked??u.previewUrlLocked;if(u.previewUrl===a&&u.previewAutoOpened===p&&u.previewUrlLocked===b)return c;const g=[...f.tabs];return g[m]={...u,previewUrl:a,previewAutoOpened:p,previewUrlLocked:b},d.set(l,{...f,tabs:g}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const a=qn(n);t(i=>{const l=new Map(i.sessions),c=l.get(a);if(!c)return i;const d=_r(c,r);if(d<0)return i;const f=c.tabs[d];if(!f.previewUrl||f.previewAutoOpened)return i;const m=[...c.tabs];return m[d]={...f,previewAutoOpened:!0},l.set(a,{...c,tabs:m}),{sessions:l}})},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=qn(n);t(i=>{const l=new Map(i.sessions),c=l.get(a);if(!c)return i;const d=_r(c,r);if(d<0)return i;const f=[...c.tabs];return f[d]={...f[d],bufferChunks:[],bufferLength:0},l.set(a,{...c,tabs:f}),{sessions:l}})},removeDirectory:n=>{const r=qn(n);t(a=>{const i=new Map(a.sessions);i.delete(r);const l=Object.fromEntries(Object.entries(a.projectActionRuns).filter(([,c])=>c.directory!==r));return{sessions:i,projectActionRuns:l}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:sw,storage:Co(()=>hh()),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(!Dc(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,f]=c;if(typeof d!="string"||!Dc(f))continue;const m=Array.isArray(f.tabs)?f.tabs:[],u=[];for(const g of m){if(!Dc(g))continue;const y=typeof g.id=="string"?g.id:null;if(!y)continue;const x=nw(y);x!==null&&(a=Math.max(a,x));const h=typeof g.terminalSessionId=="string"||g.terminalSessionId===null?g.terminalSessionId:null,j=g.lifecycle,v=j==="idle"||j==="running"||j==="exited"?j:h?"running":"idle";u.push({id:y,label:typeof g.label=="string"?g.label:"Terminal",iconKey:typeof g.iconKey=="string"?g.iconKey:null,terminalSessionId:h,lifecycle:v,createdAt:typeof g.createdAt=="number"?g.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(u.length===0)continue;const p=typeof f.activeTabId=="string"?f.activeTabId:null,b=p?u.some(g=>g.id===p):!1;r.set(d,{tabs:u,activeTabId:b?p:u[0].id})}const i=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,l=Math.max(e.nextTabId,i,a+1);return{...e,sessions:r,nextChunkId:1,nextTabId:l,hasHydrated:!0}}})));if(typeof window<"u"&&!Cm){Cm=!0;const t=on.persist,e=()=>{on.getState().hasHydrated||on.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const Im=(t,e)=>e.updatedAtMs-t.updatedAtMs,Js=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([bb(),Wu()]),a={};for(const i of r.sort(Im))a[i.id]=i;e().listenerReady||await yb(i=>{t(l=>({statusesById:{...l.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 xb();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await Wu(),r={};for(const a of n.sort(Im))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 gb({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=vb(n,r);a&&a.trim()&&(i.nickname=a.trim()),await e().upsertInstance(i)},removeInstance:async n=>{await Uu(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 hb(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 Uu(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})})),tg=[{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"}],hl=Object.fromEntries(tg.map(t=>[t.key,t.Icon])),Nd="openchamber:project-actions-updated",sg=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},fa=(t,e)=>`${sg(t)}::${e}`,rw=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Pm=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},aw=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=Pm(e.localPort),r=Pm(e.remotePort);if(!n||!r)return null;const a=rw(e.localHost||t.localForward.bindHost||"127.0.0.1"),i=(e.remoteHost||"127.0.0.1").trim(),l=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${l} - ${a}:${n} -> ${i}:${r}`,url:`http://${a}:${n}`}},ng=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const a=aw(n,r);a&&e.push(a)}return e},iw=(t,e)=>{const n=(t||"").trim();return n&&ng(e).find(i=>i.id===n)?.url||null},ow=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],lw=["dev","start","preview","serve"];async function cw(t,e,n){if(!t)return null;const r=mw(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const a=pw(n);if(a){const i=await fw(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 dw(t)){const a=await uw(),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 dw(t){const e=`${t}/index.html`,n=await $l(e);return typeof n=="string"&&n.trim().length>0}async function uw(){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 mw(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(lw.some(a=>n.includes(a)))return e}return null}function pw(t){for(const{pattern:e}of ow)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function fw(t){const e=await $l(`${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 $l(`${t}/${r}`);if(typeof i=="string"&&i.trim().length>0)return a}return"npm"}async function $l(t){const e=dr()?.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 hw(t){try{const e=await $l(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const gw=t=>new Promise(e=>{window.setTimeout(e,t)}),xw="\x1B",bw=new RegExp(`${xw}\\[[0-9;?]*[ -/]*[@-~]`,"g"),yw=/https?:\/\/[^\s<>'"`]+/gi,hr="__openchamber_auto_discover_preview__",vw=15e3,ww=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},jw=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}},Nw=t=>{const n=t.replace(bw,"").match(yw);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 l=new URL(i);l.port&&l.port.length>0&&a.push({raw:i,parsed:l})}catch{}if(a.length>0){const i=l=>{const{parsed:c}=l,d=c.hostname.toLowerCase(),f=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=c.pathname||"/",u=m.split("/").filter(Boolean).length,p=m==="/"||m==="",b=!!(c.search||c.hash);let g=0;return f&&(g+=50),p&&(g+=30),g-=Math.min(u*5,20),b&&(g-=10),g};return a.sort((l,c)=>i(c)-i(l)),a[0]?.parsed.origin??a[0]?.raw??null}return r[0]??null},Am=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:a=!1})=>{const{t:i}=pt(),{terminal:l,runtime:c}=Wn(),{isMobile:d}=an(),f=o.useMemo(()=>In(),[]),m=Js(le=>le.instances),u=Js(le=>le.load),p=_e(le=>le.setBottomTerminalOpen),b=_e(le=>le.setActiveMainTab),g=_e(le=>le.setSettingsPage),y=_e(le=>le.setSettingsDialogOpen),x=_e(le=>le.setSettingsProjectsSelectedId),h=_e(le=>le.openContextPreview),j=on(le=>le.sessions),v=on(le=>le.ensureDirectory),C=on(le=>le.setTabLabel),k=on(le=>le.setTabIconKey),w=on(le=>le.setActiveTab),N=on(le=>le.setConnecting),I=on(le=>le.setTabSessionId),E=on(le=>le.setTabPreviewUrl),P=on(le=>le.projectActionRuns),T=on(le=>le.setProjectActionRun),S=on(le=>le.updateProjectActionRunStatus),M=on(le=>le.removeProjectActionRun),[D,F]=o.useState([]),[_,V]=o.useState(null),[$,O]=o.useState(!1),B=o.useRef({}),G=o.useRef({}),R=o.useRef({}),H=o.useRef({}),J=o.useRef(0),ne=t?.id??null,ue=t?.path??"",de=o.useMemo(()=>ne?{id:ne,path:ue}:null,[ne,ue]);o.useEffect(()=>{f&&u().catch(()=>{})},[f,u]);const pe=o.useCallback(async le=>{await rr(le)},[]),W=o.useCallback(async()=>{if(!de)return;const le=J.current+1;J.current=le,O(!0);try{const Ae=await hd(de);if(J.current!==le)return;const Te=Ae.actions;F(Te),V($e=>$e===hr||$e&&Te.some(ye=>ye.id===$e)?$e:null)}catch{if(J.current!==le)return}finally{J.current===le&&O(!1)}},[de]),te=o.useMemo(()=>sg(e||de?.path||""),[e,de?.path]),X=o.useMemo(()=>_?D.find(le=>le.id===_)??null:null,[D,_]),ee=o.useMemo(()=>({id:hr,name:i("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[i]),fe=!d,be=o.useMemo(()=>fe?[ee,...D]:D,[D,ee,fe]);o.useEffect(()=>{W()},[W]),o.useEffect(()=>{if(typeof window>"u")return;const le=Ae=>{const Te=Ae.detail;ne&&(Te?.projectId&&Te.projectId!==ne||W())};return window.addEventListener(Nd,le),()=>{window.removeEventListener(Nd,le)}},[W,ne]),o.useEffect(()=>{_&&(_===hr&&fe||D.some(le=>le.id===_)||V(null))},[D,fe,_]),o.useEffect(()=>{for(const[le,Ae]of Object.entries(P)){const $e=j.get(Ae.directory)?.tabs.find(ye=>ye.id===Ae.tabId);(!$e||$e.terminalSessionId!==Ae.sessionId)&&M(le)}},[P,M,j]),o.useEffect(()=>{for(const[le,Ae]of Object.entries(P)){const Te=G.current[le]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};G.current[le]=Te;const $e=be.find(Ie=>Ie.id===Ae.actionId);if(!$e)continue;const q=j.get(Ae.directory)?.tabs.find(Ie=>Ie.id===Ae.tabId);if(!q||!Array.isArray(q.bufferChunks)||q.bufferChunks.length===0)continue;const L=q.bufferChunks.filter(Ie=>Te.lastSeenChunkId===null?!0:Ie.id>Te.lastSeenChunkId);if(L.length===0)continue;const U=L.map(Ie=>Ie.data).join(""),oe=`${Te.tail}${U}`,Ee=!Te.openedUrl&&$e.autoOpenUrl===!0?Nw(oe):null,Oe=L[L.length-1]?.id??Te.lastSeenChunkId;if(Te.lastSeenChunkId=Oe,Te.tail=oe.slice(-512),Ee)if(Te.openedUrl=!0,Te.openInPreview){const Ie=P[le];Ie&&(E(Ie.directory,Ie.tabId,Ee,{locked:!1,autoOpened:!1}),Ie.status==="waiting-for-preview"&&S(le,"running"),window.clearTimeout(H.current[le]),delete H.current[le],h(Ie.directory,Ee))}else pe(Ee),K.success(i("projectActions.toast.openedUrlFromOutput"));G.current[le]=Te}for(const le of Object.keys(G.current))P[le]||(delete G.current[le],window.clearTimeout(H.current[le]),delete H.current[le])},[be,h,pe,P,E,i,j,S]);const Ne=o.useCallback(async(le,Ae={})=>{if(!te)throw new Error(i("projectActions.error.noActiveDirectory"));const Te=fa(te,le.id);v(te);const $e=on.getState(),ye=$e.getDirectoryState(te);let q=B.current[Te]||null;const L=q?!!ye?.tabs.some(Ee=>Ee.id===q):!1;(!q||!L)&&(q=$e.createTab(te),B.current[Te]=q),C(te,q,`Action: ${le.name}`),k(te,q,le.icon||"play"),Ae.revealTerminal!==!1&&(w(te,q),p(!0),b("terminal"));const oe=on.getState().getDirectoryState(te)?.tabs.find(Ee=>Ee.id===q);return{key:Te,tabId:q,sessionId:oe?.terminalSessionId??null}},[v,te,b,w,p,k,C,i]),se=o.useCallback(async le=>{if(c.isVSCode||!a&&d)return;if(!te){K.error(i("projectActions.error.noActiveDirectoryForAction"));return}const Ae=fa(te,le.id),Te=P[Ae];if(!(Te&&Te.status==="running"))try{const $e=le.id===hr?await(async()=>{const[Qe,tt]=await Promise.all([hd({id:de?.id??"",path:te}),hw(te)]),et=await cw(te,Qe.actions,tt);if(!et)throw new Error(i("contextPanel.preview.noDevServer"));return{id:hr,name:i("projectActions.actions.autoDiscover"),command:et.command,icon:"search",autoOpenUrl:!0,openUrl:et.previewUrlHint||""}})():le,ye=$e.autoOpenUrl===!0&&($e.openUrl||"").trim().length>0,{key:q,tabId:L,sessionId:U}=await Ne($e,{revealTerminal:!ye&&le.id!==hr});let oe=U,Ee=!1;if(!oe){N(te,L,!0);try{oe=(await l.createSession({cwd:te})).sessionId,Ee=!0,I(te,L,oe)}finally{N(te,L,!1)}}if(!oe)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));Ee&&await gw(350),$e.id===hr&&(R.current[q]?.(),N(te,L,!0),R.current[q]=mb(oe,Qe=>{Qe.type==="data"&&typeof Qe.data=="string"&&Qe.data.length>0&&on.getState().appendToBuffer(te,L,Qe.data),Qe.type==="exit"&&(on.getState().setTabLifecycle(te,L,"exited"),on.getState().setConnecting(te,L,!1),on.getState().removeProjectActionRun(q),delete G.current[q],R.current[q]?.(),delete R.current[q],window.clearTimeout(H.current[q]),delete H.current[q])},()=>{on.getState().setConnecting(te,L,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const Oe=$e.autoOpenUrl===!0&&f&&($e.desktopOpenSshForward||"").trim().length>0,Ie=$e.autoOpenUrl?jw($e.openUrl):null,z=$e.autoOpenUrl&&f?iw($e.desktopOpenSshForward,m):null;T({key:q,directory:te,actionId:$e.id,tabId:L,sessionId:oe,status:$e.id===hr&&!Ie?"waiting-for-preview":"running"}),window.clearTimeout(H.current[q]),delete H.current[q],$e.id===hr&&!Ie&&(H.current[q]=window.setTimeout(()=>{on.getState().updateProjectActionRunStatus(q,"running"),delete H.current[q]},vw)),z?(E(te,L,null,{locked:!0}),pe(z),K.success(i("projectActions.toast.openedForwardedUrl"))):Ie?(E(te,L,Ie,{locked:!0,autoOpened:!0}),h(te,Ie),K.success(i("projectActions.toast.openedActionUrl"))):ye?(E(te,L,null,{locked:!0}),K.error(i("projectActions.error.invalidCustomUrlFormat"))):Oe?(E(te,L,null,{locked:!0}),K.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):E(te,L,null,{locked:!1,autoOpened:!1}),G.current[q]={lastSeenChunkId:null,openedUrl:!!z||!!Ie||ye,tail:"",openInPreview:$e.id===hr};const De=ww($e.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
+
`));await l.sendInput(oe,`${De}\r`)}catch($e){M(Ae),delete G.current[Ae],R.current[Ae]?.(),delete R.current[Ae],window.clearTimeout(H.current[Ae]),delete H.current[Ae],K.error($e instanceof Error?$e.message:i("projectActions.error.failedToRunAction"))}},[m,Ne,a,d,f,te,pe,h,P,c.isVSCode,M,N,T,E,I,de?.id,i,l]),ie=o.useCallback(async le=>{const Ae=fa(te,le.id),Te=P[Ae];if(!Te)return;S(Ae,"stopping");try{await l.sendInput(Te.sessionId,"")}catch{}if(await new Promise(q=>{window.setTimeout(q,1e3)}),on.getState().getDirectoryState(Te.directory)?.tabs.find(q=>q.id===Te.tabId)?.terminalSessionId===Te.sessionId){if(typeof l.forceKill=="function")try{await l.forceKill({sessionId:Te.sessionId})}catch{}else try{await l.close(Te.sessionId)}catch{}I(Te.directory,Te.tabId,null)}M(Ae),delete G.current[Ae],R.current[Ae]?.(),delete R.current[Ae],window.clearTimeout(H.current[Ae]),delete H.current[Ae]},[te,P,M,I,l,S]),ae=o.useCallback(()=>{const le=X??be[0];if(!le)return;const Ae=fa(te,le.id),Te=P[Ae];if(Te?.status!=="stopping"){if(Te){ie(le);return}se(le)}},[be,te,se,P,X,ie]),xe=o.useCallback((le,Ae=!1)=>{if(V(le.id),!Ae){se(le);return}const Te=fa(te,le.id),$e=P[Te];if($e?.status!=="stopping"){if($e){ie(le);return}se(le)}},[te,se,P,ie]),Z=o.useCallback(()=>{de?.id&&(x(de.id),g("projects"),y(!0))},[y,g,x,de?.id]);if(c.isVSCode||!a&&d||!de||!te)return null;const me=X??be[0]??null;if(!me)return null;const Y=me.icon||"play",Se=me.id===hr?"search":hl[Y]||"play",we=fa(te,me.id),ke=P[we],Fe=ke?.status==="stopping",Ce=ke?.status==="waiting-for-preview",Q=ke?j.get(ke.directory)?.tabs.find(le=>le.id===ke.tabId)?.previewUrl??null:null,ce=!!(ke&&Q),ve=()=>{!ke||!Q||h(ke.directory,Q)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:$||Fe,className:ge("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:ae,"aria-label":ke?i("projectActions.actions.stopNamedAria",{name:me.name}):i("projectActions.actions.runNamedAria",{name:me.name}),children:Fe||Ce?s.jsx(A,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):ke?s.jsx(A,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(A,{name:Se,className:"h-5 w-5"})}),ce?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:ve,children:s.jsx(A,{name:"global",className:"h-4 w-4"})})}),s.jsx(At,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(As,{children:[s.jsx(Is,{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(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(Ps,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Ot,{className:"flex items-center gap-2",onClick:Z,children:[s.jsx(A,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(nr,{}),be.map(le=>{const Ae=le.icon||"play",Te=le.id===hr?"search":hl[Ae]||"play",$e=fa(te,le.id),ye=P[$e],q=!!ye,L=ye?.status==="stopping";return s.jsxs(Ot,{className:"flex items-center gap-2",onClick:()=>{xe(le,!0)},children:[s.jsx(A,{name:Te,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:le.name}),L||ye?.status==="waiting-for-preview"?s.jsx(A,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):q?s.jsx(A,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},le.id)})]})]})]}):s.jsxs("div",{className:ge("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[s.jsx("button",{type:"button",onClick:ae,disabled:$||Fe,className:ge("inline-flex h-full items-center justify-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 px-0":"px-2.5","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":ke?i("projectActions.actions.stopNamedAria",{name:me.name}):i("projectActions.actions.runNamedAria",{name:me.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:Fe||Ce?s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):ke?s.jsx(A,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(A,{name:Se,className:"h-4 w-4"})})}),ce?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ve,className:ge(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(A,{name:"global",className:"h-4 w-4"})})}),s.jsx(At,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(As,{children:[s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:ge(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(A,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Ps,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Ot,{className:"flex items-center gap-2",onClick:Z,children:[s.jsx(A,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(nr,{}),be.map(le=>{const Ae=le.icon||"play",Te=le.id===hr?"search":hl[Ae]||"play",$e=fa(te,le.id),ye=P[$e],q=!!ye,L=ye?.status==="stopping";return s.jsxs(Ot,{className:"flex items-center gap-2",onClick:()=>{xe(le,!0)},children:[s.jsx(A,{name:Te,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:le.name}),L||ye?.status==="waiting-for-preview"?s.jsx(A,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):q?s.jsx(A,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},le.id)})]})]})]})},cc="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",Sw="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",di=o.memo(function(e){const n=ot.c(17),{visible:r,title:a,ariaLabel:i,onClick:l,className:c,Icon:d,iconClassName:f,pressed:m}=e,u=r===void 0?!0:r,p=m===void 0?!1:m;if(!u)return null;const b=c??cc,g=p&&"bg-interactive-selection text-interactive-selection-foreground";let y;n[0]!==b||n[1]!==g?(y=ge(b,g),n[0]=b,n[1]=g,n[2]=y):y=n[2];const x=f??"h-[18px] w-[18px]";let h;n[3]!==d||n[4]!==x?(h=s.jsx(A,{name:d,className:x}),n[3]=d,n[4]=x,n[5]=h):h=n[5];let j;n[6]!==i||n[7]!==l||n[8]!==p||n[9]!==y||n[10]!==h?(j=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,"aria-label":i,"aria-pressed":p,className:y,children:h})}),n[6]=i,n[7]=l,n[8]=p,n[9]=y,n[10]=h,n[11]=j):j=n[11];let v;n[12]!==a?(v=s.jsx(At,{children:s.jsx("p",{children:a})}),n[12]=a,n[13]=v):v=n[13];let C;return n[14]!==j||n[15]!==v?(C=s.jsxs(It,{children:[j,v]}),n[14]=j,n[15]=v,n[16]=C):C=n[16],C}),kw=o.memo(function(e){const n=ot.c(40),{visible:r}=e,{t:a}=pt(),[i,l]=o.useState(!1);let c,d;if(n[0]!==r?(c=()=>{if(!r)return;let P=!1;ra("desktop_get_current_window_state").then(S=>{P||l(!!S?.maximized)}).catch(Dw);const T=S=>{const M=S.detail;l(!!M?.maximized)};return window.addEventListener("openchamber:window-maximized-changed",T),()=>{P=!0,window.removeEventListener("openchamber:window-maximized-changed",T)}},d=[r],n[0]=r,n[1]=c,n[2]=d):(c=n[1],d=n[2]),Ve.useEffect(c,d),!r)return null;let f;n[3]!==a?(f=a("header.windowControls.groupAria"),n[3]=a,n[4]=f):f=n[4];let m;n[5]!==a?(m=a("header.windowControls.minimize"),n[5]=a,n[6]=m):m=n[6];let u;n[7]!==a?(u=a("header.windowControls.minimize"),n[7]=a,n[8]=u):u=n[8];let p;n[9]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(A,{name:"subtract",className:"h-4 w-4"}),n[9]=p):p=n[9];let b;n[10]!==m||n[11]!==u?(b=s.jsx("button",{type:"button",className:"app-region-no-drag inline-flex h-12 w-11 items-center justify-center text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:Tw,title:m,"aria-label":u,children:p}),n[10]=m,n[11]=u,n[12]=b):b=n[12];let g;n[13]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{ra("desktop_toggle_current_window_maximized").then(P=>l(!!P?.maximized)).catch(Ew)},n[13]=g):g=n[13];let y;n[14]!==i||n[15]!==a?(y=a(i?"header.windowControls.restore":"header.windowControls.maximize"),n[14]=i,n[15]=a,n[16]=y):y=n[16];let x;n[17]!==i||n[18]!==a?(x=a(i?"header.windowControls.restore":"header.windowControls.maximize"),n[17]=i,n[18]=a,n[19]=x):x=n[19];const h=i?"fullscreen-exit":"checkbox-blank";let j;n[20]!==h?(j=s.jsx(A,{name:h,className:"h-3.5 w-3.5"}),n[20]=h,n[21]=j):j=n[21];let v;n[22]!==x||n[23]!==j||n[24]!==y?(v=s.jsx("button",{type:"button",className:"app-region-no-drag inline-flex h-12 w-11 items-center justify-center text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:g,title:y,"aria-label":x,children:j}),n[22]=x,n[23]=j,n[24]=y,n[25]=v):v=n[25];let C;n[26]===Symbol.for("react.memo_cache_sentinel")?(C=ge("app-region-no-drag inline-flex h-12 w-11 items-center justify-center text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","hover:bg-status-error hover:text-status-error-foreground"),n[26]=C):C=n[26];let k;n[27]!==a?(k=a("header.windowControls.close"),n[27]=a,n[28]=k):k=n[28];let w;n[29]!==a?(w=a("header.windowControls.close"),n[29]=a,n[30]=w):w=n[30];let N;n[31]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(A,{name:"close",className:"h-4 w-4"}),n[31]=N):N=n[31];let I;n[32]!==k||n[33]!==w?(I=s.jsx("button",{type:"button",className:C,onClick:Mw,title:k,"aria-label":w,children:N}),n[32]=k,n[33]=w,n[34]=I):I=n[34];let E;return n[35]!==v||n[36]!==I||n[37]!==f||n[38]!==b?(E=s.jsxs("div",{className:"app-region-no-drag -mr-3 ml-2 flex h-12 shrink-0 items-center","aria-label":f,children:[b,v,I]}),n[35]=v,n[36]=I,n[37]=f,n[38]=b,n[39]=E):E=n[39],E}),Cw=o.memo(function(e){const n=ot.c(42),{isMobile:r,githubAuthStatus:a,githubAccounts:i,githubAvatarUrl:l,githubLogin:c,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:f}=e,{t:m}=pt();if(!a?.connected||r)return null;if(i.length>1){let g;n[0]===Symbol.for("react.memo_cache_sentinel")?(g=ge(cc,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=g):g=n[0];let y;n[1]!==c||n[2]!==m?(y=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[1]=c,n[2]=m,n[3]=y):y=n[3];let x;n[4]!==l||n[5]!==c||n[6]!==m?(x=l?s.jsx("img",{src:l,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(A,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=l,n[5]=c,n[6]=m,n[7]=x):x=n[7];let h;n[8]!==d||n[9]!==y||n[10]!==x?(h=s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:g,title:y,disabled:d,children:x})}),n[8]=d,n[9]=y,n[10]=x,n[11]=h):h=n[11];let j;n[12]!==m?(j=m("header.github.accountsTitle"),n[12]=m,n[13]=j):j=n[13];let v;n[14]!==j?(v=s.jsx(gh,{className:"typography-ui-header font-semibold text-foreground",children:j}),n[14]=j,n[15]=v):v=n[15];let C;n[16]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(nr,{}),n[16]=C):C=n[16];let k;if(n[17]!==i||n[18]!==f||n[19]!==d||n[20]!==m){let I;n[22]!==f||n[23]!==d||n[24]!==m?(I=E=>{const P=E.user,T=!!E.current;return s.jsxs(Ot,{className:"gap-2",disabled:T||d,onSelect:()=>{T||f(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(A,{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]}),T?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null]},E.id)},n[22]=f,n[23]=d,n[24]=m,n[25]=I):I=n[25],k=i.map(I),n[17]=i,n[18]=f,n[19]=d,n[20]=m,n[21]=k}else k=n[21];let w;n[26]!==v||n[27]!==k?(w=s.jsxs(Ps,{align:"end",className:"w-64",children:[v,C,k]}),n[26]=v,n[27]=k,n[28]=w):w=n[28];let N;return n[29]!==h||n[30]!==w?(N=s.jsxs(As,{children:[h,w]}),n[29]=h,n[30]=w,n[31]=N):N=n[31],N}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 p;n[35]!==l||n[36]!==c||n[37]!==m?(p=l?s.jsx("img",{src:l,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(A,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=l,n[36]=c,n[37]=m,n[38]=p):p=n[38];let b;return n[39]!==u||n[40]!==p?(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:p}),n[39]=u,n[40]=p,n[41]=b):b=n[41],b}),Iw=o.memo(function(e){const n=ot.c(77),{isDesktopApp:r,currentInstanceLabel:a,compactCurrentInstanceLabel:i,isDesktopServicesOpen:l,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,desktopServicesTab:f,setDesktopServicesTab:m,quotaResultsLength:u,fetchAllQuotas:p,servicesTabItems:b,quotaLastUpdated:g,quotaDisplayMode:y,quotaDisplayTabItems:x,handleDisplayModeChange:h,handleUsageRefresh:j,isQuotaLoading:v,isUsageRefreshSpinning:C,hasRateLimits:k,rateLimitGroups:w,expandedFamilies:N,toggleFamilyExpanded:I,shortcutLabel:E,showDevShutdown:P,isDevShutdownInFlight:T,onDevShutdown:S,showPredValues:M}=e,{t:D}=pt();let F;n[0]!==f||n[1]!==p||n[2]!==u||n[3]!==d||n[4]!==c?(F=fe=>{c(fe),fe&&(d(),f==="usage"&&u===0&&p())},n[0]=f,n[1]=p,n[2]=u,n[3]=d,n[4]=c,n[5]=F):F=n[5];let _;n[6]!==a||n[7]!==r||n[8]!==D?(_=r?D("header.services.openWithCurrent",{current:a}):D("header.services.open"),n[6]=a,n[7]=r,n[8]=D,n[9]=_):_=n[9];const V=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let $;n[10]!==V?($=ge(cc,V),n[10]=V,n[11]=$):$=n[11];let O;n[12]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(A,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=O):O=n[12];let B;n[13]!==i||n[14]!==r?(B=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[13]=i,n[14]=r,n[15]=B):B=n[15];let G;n[16]!==_||n[17]!==$||n[18]!==B?(G=s.jsx(Pt,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":_,className:$,children:[O,B]})})}),n[16]=_,n[17]=$,n[18]=B,n[19]=G):G=n[19];let R;n[20]!==a||n[21]!==r||n[22]!==E||n[23]!==D?(R=r?D("header.services.tooltip.currentInstanceWithShortcuts",{current:a,toggle:E("toggle_services_menu"),nextTab:E("cycle_services_tab")}):D("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]=D,n[24]=R):R=n[24];let H;n[25]!==R?(H=s.jsx(At,{children:s.jsx("p",{children:R})}),n[25]=R,n[26]=H):H=n[26];let J;n[27]!==G||n[28]!==H?(J=s.jsxs(It,{children:[G,H]}),n[27]=G,n[28]=H,n[29]=J):J=n[29];let ne;n[30]!==p||n[31]!==u||n[32]!==m?(ne=fe=>{const be=fe;m(be),be==="usage"&&u===0&&p()},n[30]=p,n[31]=u,n[32]=m,n[33]=ne):ne=n[33];let ue;n[34]!==f||n[35]!==b||n[36]!==ne?(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(Fr,{items:b,activeId:f,onSelect:ne,layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),n[34]=f,n[35]=b,n[36]=ne,n[37]=ue):ue=n[37];let de;n[38]!==f||n[39]!==r||n[40]!==l||n[41]!==c?(de=r&&f==="instance"?s.jsx(wb,{embedded:!0,open:l&&f==="instance",onOpenChange:Rw,onHostSwitched:()=>c(!1)}):null,n[38]=f,n[39]=r,n[40]=l,n[41]=c,n[42]=de):de=n[42];let pe;n[43]!==f||n[44]!==l?(pe=f==="mcp"?s.jsx(eg,{active:l&&f==="mcp"}):null,n[43]=f,n[44]=l,n[45]=pe):pe=n[45];let W;n[46]!==f||n[47]!==N||n[48]!==h||n[49]!==j||n[50]!==k||n[51]!==v||n[52]!==C||n[53]!==y||n[54]!==x||n[55]!==g||n[56]!==w||n[57]!==M||n[58]!==D||n[59]!==I?(W=f==="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:D("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:rg(g)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(Fr,{items:x,activeId:y,onSelect:fe=>{h(fe)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:ge("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:j,disabled:v||C,"aria-label":D("header.services.refreshRateLimitsAria"),children:s.jsx(A,{name:"refresh",className:ge("h-4 w-4",C&&"animate-spin")})})]})]}),k?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:D("header.services.noRateLimits")})}),s.jsx("div",{className:"py-2",children:w.map((fe,be)=>{const Ne=N[fe.providerId]??[];return s.jsxs(o.Fragment,{children:[be>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(wr,{providerId:fe.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:fe.providerName})]}),fe.entries.length===0&&(!fe.modelFamilies||fe.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:fe.error??D("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[fe.entries.map(se=>{const[ie,ae]=se,xe=y==="remaining"?ae.remainingPercent:ae.usedPercent,Z=vo(ae.usedPercent,ae.resetAt,ae.windowSeconds,ie),me=Z?.dailyAllocationPercent!=null?y==="remaining"?100-na(Z.elapsedRatio):na(Z.elapsedRatio):null,Y=yo(ae.valueLabel,xe),Se=mu(ae.resetAt,ae.resetAfterFormatted??ae.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:pu(ie)}),Se?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Se}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:Y==="-"?"":Y})]}),s.jsx(jo,{percent:xe,tonePercent:ae.usedPercent,className:"h-1.5",expectedMarkerPercent:me}),Z&&M?s.jsx(No,{paceInfo:Z,compact:!0}):null]},`${fe.providerId}-${ie}`)}),fe.modelFamilies&&fe.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:fe.modelFamilies.map(se=>{const ie=se.familyId??"other",ae=Ne.includes(ie);return s.jsxs(jr,{open:ae,onOpenChange:()=>I(fe.providerId,ie),children:[s.jsxs(Lr,{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:se.familyLabel}),ae?s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(Nr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:se.models.map(xe=>{const[Z,me]=xe,Y=y==="remaining"?me.remainingPercent:me.usedPercent,Se=vo(me.usedPercent,me.resetAt,me.windowSeconds),we=Se?.dailyAllocationPercent!=null?y==="remaining"?100-na(Se.elapsedRatio):na(Se.elapsedRatio):null,ke=yo(me.valueLabel,Y);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:Ll(Z)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:ke==="-"?"":ke})]}),s.jsx(jo,{percent:Y,tonePercent:me.usedPercent,className:"h-1.5",expectedMarkerPercent:we}),Se&&M?s.jsx(No,{paceInfo:Se,compact:!0}):null]},`${fe.providerId}-${Z}`)})})})]},ie)})}):null]})]},fe.providerId)})})]}):null,n[46]=f,n[47]=N,n[48]=h,n[49]=j,n[50]=k,n[51]=v,n[52]=C,n[53]=y,n[54]=x,n[55]=g,n[56]=w,n[57]=M,n[58]=D,n[59]=I,n[60]=W):W=n[60];let te;n[61]!==T||n[62]!==S||n[63]!==P||n[64]!==D?(te=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(Ot,{disabled:T,onSelect:()=>{S()},children:D("header.services.shutdownDev")})})]}):null,n[61]=T,n[62]=S,n[63]=P,n[64]=D,n[65]=te):te=n[65];let X;n[66]!==ue||n[67]!==de||n[68]!==pe||n[69]!==W||n[70]!==te?(X=s.jsxs(Ps,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[ue,de,pe,W,te]}),n[66]=ue,n[67]=de,n[68]=pe,n[69]=W,n[70]=te,n[71]=X):X=n[71];let ee;return n[72]!==l||n[73]!==F||n[74]!==J||n[75]!==X?(ee=s.jsxs(As,{open:l,onOpenChange:F,children:[J,X]}),n[72]=l,n[73]=F,n[74]=J,n[75]=X,n[76]=ee):ee=n[76],ee}),Pw=(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??""),Aw=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},rg=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},cr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},ui=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,Dm=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r})=>{const{t:a}=pt(),i=_e(Be=>Be.setSessionSwitcherOpen),l=_e(Be=>Be.toggleSidebar),c=_e(Be=>Be.toggleBottomTerminal),d=_e(Be=>Be.toggleRightSidebar),f=_e(Be=>Be.openContextOverview),m=_e(Be=>Be.openContextPlan),u=_e(Be=>Be.openContextBrowser),p=_e(Be=>Be.closeContextPanel),b=_e(Be=>Be.contextPanelByDirectory),g=_e(Be=>Be.activeMainTab),y=_e(Be=>Be.setActiveMainTab),x=_e(Be=>Be.shortcutOverrides),h=jt(Be=>Be.getCurrentModel),j=Wn(),[v,C]=o.useState(!1),k=Lt(Be=>Be.getContextUsage),w=Lt(Be=>!!Be.newSessionDraft?.open),N=Lt(Be=>Be.currentSessionId),I=jb(N??""),E=xh(N??null),P=wa(Be=>Be.activeSessions),T=Qd(),S=Ss(Be=>Be.activeProjectId?Be.projects.find(St=>St.id===Be.activeProjectId)??null:null),M=o.useMemo(()=>{if(!S)return null;const Be=S.label?.trim();if(Be)return Be;const St=S.path.split(/[\\/]/).filter(Boolean);return St[St.length-1]??null},[S]),D=Ns(Be=>Be.results),F=Ns(Be=>Be.fetchAllQuotas),_=Ns(Be=>Be.isLoading),V=Ns(Be=>Be.lastUpdated),$=Ns(Be=>Be.displayMode),O=Ns(Be=>Be.showPredValues),B=Ns(Be=>Be.dropdownProviderIds),G=Ns(Be=>Be.loadSettings),R=Ns(Be=>Be.setDisplayMode),{isMobile:H}=an(),J=Yn(Be=>Be.status),ne=Yn(Be=>Be.setStatus),ue=o.useRef(null),[de,pe]=o.useState(()=>typeof window>"u"?!1:In()),W=o.useMemo(()=>Xd(),[]),te=bh(),[X,ee]=o.useState(!1),fe=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),be=o.useMemo(()=>typeof window>"u"?!1:!!window.__OPENCHAMBER_ELECTRON__&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),Ne=o.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 St=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!St)return null;const Gt=Number.parseInt(St[1],10),Yt=Number.parseInt(St[2],10);return Number.isNaN(Gt)?null:Gt===10?Yt:Gt},[]);Ve.useEffect(()=>{typeof window>"u"||pe(In())},[]);const se=h(),ie=se&&typeof se.limit=="object"&&se.limit!==null?se.limit:null,ae=ie&&typeof ie.context=="number"?ie.context:0,xe=ie&&typeof ie.output=="number"?ie.output:0,Z=k(ae,xe),[me,Y]=o.useState(null),Se=!N||I;Ve.useEffect(()=>{if(!N){Y(Be=>Be===null?Be:null);return}if(Z&&Z.totalTokens>0){Y(Be=>Pw(Be,Z)?Be:Z);return}Se&&Y(Be=>Be===null?Be:null)},[Z,N,Se]);const we=_e(Be=>Be.isSessionSwitcherOpen),ke=J?.connected?J.user?.avatarUrl??null:null,Fe=J?.connected?J.user?.login??null:null,Ce=J?.accounts??[],[Q,ce]=o.useState(!1),[ve,le]=o.useState(!1),[Ae,Te]=o.useState(!1),[$e,ye]=o.useState(!1),[q,L]=o.useState("Local"),U=o.useMemo(()=>Aw(q),[q]),[oe,Ee]=o.useState(de?"instance":"usage"),[Oe,Ie]=o.useState("usage");Ve.useEffect(()=>{!de&&oe==="instance"&&Ee("usage")},[oe,de]);const z=o.useMemo(()=>un(),[]),De=!z&&g==="chat"&&!!me&&me.totalTokens>0,Qe=me&&me.contextLimit>0?Math.min(999,me.totalTokens/me.contextLimit*100):0,tt=o.useCallback(async()=>{if(!(typeof window>"u"||!de))try{const Be=await Nb(),St=window.location.href,Gt=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin;if(Ku(St,Gt)){L("Local");return}const Yt=Be.hosts.find(ks=>Ku(St,ks.url));if(Yt?.label?.trim()){L(Sb(Yt.label.trim()));return}L("Instance")}catch{L("Local")}},[de]);Ve.useEffect(()=>{tt()},[tt]),Xh();const et=Ns(Be=>Be.selectedModels),We=Ns(Be=>Be.expandedFamilies),at=Ns(Be=>Be.toggleFamilyExpanded),qe=o.useMemo(()=>{const Be=[];for(const St of Gr){if(!B.includes(St.id))continue;const Gt=D.find(Ys=>Ys.providerId===St.id),Yt=Gt?.usage?.windows??{},ks=Gt?.usage?.models,Bs=Object.entries(Yt),Fs={providerId:St.id,providerName:St.name,entries:Bs,error:Gt&&!Gt.ok&&Gt.configured?Gt.error:void 0};if(ks&&Object.keys(ks).length>0){const Ys=et[St.id]??[],nn=Ys.length>0,Xn=D1(ks,St.id),Cr=Yh(St.id),mr=Qh(Cr);Fs.modelFamilies=[];for(const Mn of mr){const wn=Xn.get(Mn.id)??[];if(wn.length===0)continue;const jn=nn?wn.filter(yn=>Ys.includes(yn)):wn;if(jn.length===0)continue;const Vs=[];for(const yn of jn){const pn=ks[yn];if(pn?.windows){const Wr=Object.entries(pn.windows);Wr.length>0&&Vs.push([yn,Wr[0][1]])}}Vs.length>0&&Fs.modelFamilies.push({familyId:Mn.id,familyLabel:Mn.label,models:Vs})}const qr=Xn.get(null)??[],Jr=nn?qr.filter(Mn=>Ys.includes(Mn)):qr;if(Jr.length>0){const Mn=[];for(const wn of Jr){const jn=ks[wn];if(jn?.windows){const Vs=Object.entries(jn.windows);Vs.length>0&&Mn.push([wn,Vs[0][1]])}}Mn.length>0&&Fs.modelFamilies.push({familyId:null,familyLabel:a("header.services.modelFamily.other"),models:Mn})}}(Bs.length>0||Fs.modelFamilies&&Fs.modelFamilies.length>0||Fs.error)&&Be.push(Fs)}return Be},[B,D,et,a]),nt=qe.length>0;o.useEffect(()=>{G()},[G]);const Ze=o.useCallback(async Be=>{R(Be);try{await Cs({usageDisplayMode:Be})}catch(St){console.warn("Failed to update usage display mode:",St)}},[R]),ze=o.useCallback(()=>{if($e)return;ye(!0);const Be=new Promise(St=>setTimeout(St,500));Promise.all([F(),Be]).finally(()=>{ye(!1)})},[F,$e]),rt=o.useMemo(()=>N?T.find(Be=>Be.id===N)??P.find(Be=>Be.id===N)??E??kb().find(Be=>Be.id===N)??null:null,[N,E,P,T]),Ge=o.useRef(null),[ct,Pe]=o.useState(0);o.useEffect(()=>{if(!N){Ge.current&&(Ge.current=null,Pe(Yt=>Yt+1));return}if(rt){Ge.current={sessionId:N,session:rt,expiresAt:Date.now()+2e3};return}const Be=Ge.current;if(!Be||Be.sessionId!==N)return;const St=Be.expiresAt-Date.now();if(St<=0){Ge.current=null,Pe(Yt=>Yt+1);return}const Gt=window.setTimeout(()=>{Ge.current?.sessionId===N&&(Ge.current=null),Pe(Yt=>Yt+1)},St);return()=>{window.clearTimeout(Gt)}},[N,rt]);const Me=(()=>{if(rt)return rt;if(!N)return null;const Be=Ge.current;return Be&&Be.sessionId===N&&Be.expiresAt>Date.now()?Be.session:null})(),Ue=Lt(Be=>N?Be.worktreeMetadata.get(N)?.path??"":""),He=Lt(Be=>N?Be.worktreeMetadata.get(N)?.branch?.trim()??null:null),lt=yh(Be=>N?Be.getAttachment(N):void 0),vt=o.useMemo(()=>lt?Cb(lt):null,[lt]),ft=o.useMemo(()=>lt?lt.legacy?"legacy":lt.degraded?"degraded":lt.worktreeStatus==="missing"?"missing":lt.worktreeStatus==="invalid"?"invalid":lt.attentionReason?"attention":null:null,[lt]),dt=o.useMemo(()=>cr(Ue||""),[Ue]),Dt=o.useMemo(()=>{const Be=typeof Me?.directory=="string"?Me.directory:"";return cr(Be||"")},[Me?.directory]),Qt=Lt(Be=>Be.newSessionDraft?.open?cr(Be.newSessionDraft.bootstrapPendingDirectory??Be.newSessionDraft.directoryOverride??""):""),Ft=o.useMemo(()=>dt||Dt||Qt,[Qt,Dt,dt]),qt=Lt(Be=>{const St=cr(dt||Dt||"");if(!St)return null;for(const Gt of Be.availableWorktreesByProject.values()){const ks=Gt.find(Bs=>cr(Bs.path)===St)?.branch?.trim();if(ks)return ks}return null}),zt=Ib(Ft||null)||He||qt,es=o.useMemo(()=>{if(!N)return M??"OpenChamber";const Be=Me?.title?.trim();return Be&&Be.length>0?Be:"Untitled Session"},[M,Me?.title,N]),is=o.useMemo(()=>vh(Me?.summary),[Me?.summary]),cs=o.useMemo(()=>is||{additions:0,deletions:0},[is]),hs=cs.additions>0||cs.deletions>0,_t=o.useMemo(()=>cr(Ft||S?.path||""),[S?.path,Ft]),Ye=o.useMemo(()=>S?{id:S.id,path:S.path}:null,[S]),Mt=o.useRef(null);o.useEffect(()=>{!Ye||!_t||(Mt.current={projectRef:Ye,directory:_t})},[_t,Ye]);const Bt=o.useMemo(()=>Ye&&_t?{projectRef:Ye,directory:_t}:Mt.current,[_t,Ye]),wt=Zd(Be=>Be.planModeEnabled),Zt=Lt(Be=>Be.isSessionPlanAvailable),us=wt&&N?Zt(N):!1,Es=us,ws=o.useRef("");o.useEffect(()=>{if(!wt){_e.getState().activeMainTab==="plan"&&_e.getState().setActiveMainTab("chat");return}if(!N)return;const Be=`${N||"none"}:${Dt||"none"}:${Me?.time?.created||0}:${Me?.slug||"none"}`;ws.current!==Be&&(ws.current=Be),!us&&_e.getState().activeMainTab==="plan"&&_e.getState().setActiveMainTab("chat")},[wt,us,Me?.slug,Me?.time?.created,N,Dt]);const Ds=o.useCallback(async Be=>{if(!(!Be||Q)){ce(!0);try{const St=j.github?await j.github.authActivate(Be):await(async()=>{const Gt=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:Be})}),Yt=await Gt.json().catch(()=>null);if(!Gt.ok||!Yt)throw new Error(Yt?.error||Gt.statusText);return Yt})();ne(St)}catch(St){console.error("Failed to switch GitHub account:",St)}finally{ce(!1)}}},[Q,j.github,ne]),Xt=o.useCallback(()=>{if(typeof document>"u")return;const Be=document.activeElement;if(!Be)return;const St=Be.tagName;(St==="INPUT"||St==="TEXTAREA"||St==="SELECT"||Be.isContentEditable)&&Be.blur()},[]),en=o.useCallback(()=>{if(H){Xt(),i(!we);return}l()},[Xt,H,we,i,l]),Ks=o.useCallback(Be=>{const St=Be.currentTarget.getBoundingClientRect();ra("desktop_show_app_menu",{x:St.left,y:St.bottom}).catch(Gt=>{console.warn("[header] failed to open app menu",Gt)})},[]),Us=o.useCallback(()=>{ra("desktop_open_draft_mini_chat_window",{directory:cr(Ft||S?.path||""),projectId:S?.id??null}).catch(Be=>{console.warn("[header] failed to open draft mini chat window",Be)})},[S?.id,S?.path,Ft]),Xs=o.useCallback(()=>{if(w){Us();return}N&&ra("desktop_open_session_mini_chat_window",{sessionId:N,directory:cr(Ft||S?.path||"")}).catch(Be=>{console.warn("[header] failed to open session mini chat window",Be)})},[S?.path,N,Us,w,Ft]),re=o.useCallback(()=>{const Be=cr(Ft||"");if(!Be)return;const St=b[Be];if(ui(St)==="context"){p(Be);return}f(Be)},[p,b,f,Ft]),bt=o.useMemo(()=>{const Be=cr(Ft||"");if(!Be)return!1;const St=b[Be];return ui(St)==="context"},[b,Ft]),Et=o.useCallback(()=>{const Be=cr(Ft||"");if(!Be)return;const St=b[Be];if(ui(St)==="plan"){p(Be);return}m(Be)},[p,b,m,Ft]),Wt=o.useCallback(()=>{const Be=cr(Ft||"");if(!Be)return;const St=b[Be];if(ui(St)==="browser"){p(Be);return}u(Be)},[p,b,u,Ft]),ts=o.useMemo(()=>{const Be=cr(Ft||"");if(!Be)return!1;const St=b[Be];return ui(St)==="plan"},[b,Ft]),ss=o.useMemo(()=>{const Be=cr(Ft||"");if(!Be)return!1;const St=b[Be];return ui(St)==="browser"},[b,Ft]),Ke=cc,Je=Sw,Ct=o.useMemo(()=>ve?"services":n?"sessions":r?"git":g,[g,ve,n,r]),kt=o.useCallback(()=>{le(!1),n&&t&&t(),r&&e&&e(),!t&&we&&i(!1)},[we,n,t,e,r,i]),Kt=o.useCallback(()=>{n||le(!1),t?.()},[n,t]),Tt=o.useCallback(()=>{r||le(!1),e?.()},[e,r]),gs=o.useMemo(()=>de&&fe&&!X||te?"pl-[5.5rem]":"pl-3",[de,X,fe,te]);Ve.useEffect(()=>{if(!de||!fe){ee(!1);return}let Be=!1,St=null;const Gt=async()=>{try{const{getCurrentWindow:ks}=await Rr(async()=>{const{getCurrentWindow:Ys}=await import("./vendor-.bun-CV3tusA8.js").then(nn=>nn.bQ);return{getCurrentWindow:Ys}},__vite__mapDeps([0,1])),Fs=await ks().isFullscreen();Be||ee(Fs)}catch{Be||ee(!1)}},Yt=async()=>{try{const{getCurrentWindow:ks}=await Rr(async()=>{const{getCurrentWindow:Fs}=await import("./vendor-.bun-CV3tusA8.js").then(Ys=>Ys.bQ);return{getCurrentWindow:Fs}},__vite__mapDeps([0,1]));St=await ks().onResized(()=>{Gt()})}catch{}};return Gt(),Yt(),()=>{Be=!0,St&&St()}},[de,fe]);const js=o.useMemo(()=>!de||!fe||Ne===null?"":Ne>=26?"h-12":Ne<=15?"h-14":"",[de,fe,Ne]),Ls=o.useMemo(()=>{if(!(de&&!be||z))return{paddingLeft:te?"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))"}},[de,te,z,be]),Os=o.useCallback(()=>{if(typeof document>"u")return;const Be=ue.current?.getBoundingClientRect().height;Be&&document.documentElement.style.setProperty("--oc-header-height",`${Be}px`)},[]);Ve.useEffect(()=>{if(typeof window>"u")return;Os();const Be=ue.current;if(!Be||typeof ResizeObserver>"u")return()=>{};let St=0;const Gt=()=>{St||(St=requestAnimationFrame(()=>{St=0,Os()}))},Yt=new ResizeObserver(Gt);return Yt.observe(Be),window.addEventListener("resize",Gt),window.addEventListener("orientationchange",Gt),()=>{St&&cancelAnimationFrame(St),Yt.disconnect(),window.removeEventListener("resize",Gt),window.removeEventListener("orientationchange",Gt)}},[Os]),Ve.useEffect(()=>{Os()},[Os,H,js]);const tn=o.useCallback(async Be=>{const St=Be.target;St.closest(".app-region-no-drag")||St.closest("button, a, input, select, textarea")||Be.button===0&&de&&await Pb()},[de]),cn=o.useMemo(()=>{if(H){const Be=[{id:"chat",label:a("layout.mainTab.chat"),icon:"chat-4"}];return Es&&Be.push({id:"plan",label:a("layout.mainTab.plan"),icon:"file-text"}),Be.push({id:"diff",label:a("layout.mainTab.diff"),icon:"diff"},{id:"files",label:a("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:a("layout.mainTab.terminal"),icon:"terminal-box"},{id:"context",label:a("layout.mainTab.context"),icon:"file-list-2"}),Be}return[]},[H,Es,a]),Zs=o.useCallback(Be=>ec(sa(Be,x)),[x]);Ve.useEffect(()=>{!H&&(g==="git"||g==="terminal"||g==="diff"||g==="files"||g==="context")&&y("chat")},[g,H,y]);const sn=o.useMemo(()=>{const Be=[];return de&&Be.push({value:"instance",label:a("layout.services.instance"),icon:"server"}),Be.push({value:"usage",label:a("layout.services.usage"),icon:"timer"},{value:"mcp",label:"MCP",icon:"plug-2"}),Be},[de,a]),mn=o.useMemo(()=>sn.map(Be=>({id:Be.value,label:Be.label,icon:s.jsx(A,{name:Be.icon,className:"h-3.5 w-3.5"})})),[sn]),gn=o.useMemo(()=>{if(typeof window>"u"||de||z)return!1;const Be=window.location.hostname;return Be==="localhost"||Be==="127.0.0.1"||Be==="::1"},[de,z]),$s=o.useCallback(async()=>{if(v)return;C(!0),Te(!1);const Be=[];let St=!1;try{try{for(const[,Gt]of on.getState().sessions.entries())for(const Yt of Gt.tabs)Yt.previewUrl&&Be.push(Yt.previewUrl)}catch{}try{await pb({})}catch{}try{(await fetch("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:Be})})).ok?St=!0:St=(await fetch("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{St||C(!1)}},[v,Te]),Hs=o.useMemo(()=>[{value:"usage",label:a("header.services.used")},{value:"remaining",label:a("header.services.remaining")}],[a]),dn=o.useMemo(()=>Hs.map(Be=>({id:Be.value,label:Be.label})),[Hs]),Kn=o.useMemo(()=>[{id:"usage",label:a("layout.services.usage"),icon:s.jsx(A,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(A,{name:"command",className:"h-3.5 w-3.5"})}],[a]);Ve.useEffect(()=>{const Be=St=>{if(eu(St)&&!St.shiftKey&&!St.altKey){const Gt=parseInt(St.key,10);Gt>=1&&Gt<=cn.length&&(St.preventDefault(),H&&(Xt(),kt()),y(cn[Gt-1].id))}};return window.addEventListener("keydown",Be),()=>window.removeEventListener("keydown",Be)},[Xt,kt,H,y,cn]),Ve.useEffect(()=>{const Be=St=>{const Gt=sa("toggle_services_menu",x);if(ul(St,Gt)){St.preventDefault(),Ae?Te(!1):(Te(!0),tt(),oe==="usage"&&D.length===0&&F());return}const Yt=sa("cycle_services_tab",x);if(ul(St,Yt)){St.preventDefault();const Bs=sn.map(Xn=>Xn.value);if(Bs.length===0)return;const Fs=Bs.indexOf(oe),Ys=Fs===-1?0:(Fs+1)%Bs.length,nn=Bs[Ys];Ee(nn),Te(!0),tt(),nn==="usage"&&D.length===0&&F();return}const ks=sa("toggle_context_plan",x);ul(St,ks)&&(St.preventDefault(),Et())};return window.addEventListener("keydown",Be),()=>window.removeEventListener("keydown",Be)},[x,Ae,oe,sn,D.length,F,tt,Et]);const Hn=Be=>{const St=g===Be.id,Gt=Be.icon==="diff",Yt=Gt?null:Be.icon,ks=Be.id==="chat",Bs=Ys=>Gt?s.jsx(bm,{size:Ys}):Yt?s.jsx(A,{name:Yt,className:`h-${Ys/4} w-${Ys/4}`}):null,Fs=s.jsxs("button",{type:"button",onClick:()=>y(Be.id),className:ge("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",St?"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",ks&&!H&&"min-w-[100px] justify-center"),"aria-label":Be.label,"aria-selected":St,role:"tab",children:[H?Bs(20):s.jsxs(s.Fragment,{children:[Bs(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(o.Fragment,{children:Fs},Be.id)},kr=s.jsxs(s.Fragment,{children:[Es&&s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.actions.openPlanAria"),onClick:Et,className:ge(Ke,ts&&"bg-[var(--interactive-hover)]"),children:s.jsx(A,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(At,{children:s.jsx("p",{children:a("header.actions.planWithShortcut",{shortcut:Zs("toggle_context_plan")})})})]}),s.jsx(H1,{directory:_t,className:"mr-1"}),s.jsx(Iw,{isDesktopApp:de,currentInstanceLabel:q,compactCurrentInstanceLabel:U,isDesktopServicesOpen:Ae,setIsDesktopServicesOpen:Te,refreshCurrentInstanceLabel:tt,desktopServicesTab:oe,setDesktopServicesTab:Ee,quotaResultsLength:D.length,fetchAllQuotas:F,servicesTabItems:mn,quotaLastUpdated:V,quotaDisplayMode:$,showPredValues:O,quotaDisplayTabItems:dn,handleDisplayModeChange:Ze,handleUsageRefresh:ze,isQuotaLoading:_,isUsageRefreshSpinning:$e,hasRateLimits:nt,rateLimitGroups:qe,expandedFamilies:We,toggleFamilyExpanded:at,shortcutLabel:Zs,showDevShutdown:gn,isDevShutdownInFlight:v,onDevShutdown:$s}),s.jsx(di,{title:a("header.actions.terminalPanelWithShortcut",{shortcut:Zs("toggle_terminal")}),ariaLabel:a("header.actions.toggleTerminalPanelAria"),onClick:c,Icon:"terminal-box"}),W?s.jsx(di,{title:a("contextPanel.browser.open"),ariaLabel:a("contextPanel.browser.open"),onClick:Wt,pressed:ss,Icon:"global"}):null,s.jsx(di,{title:a("header.actions.rightSidebarWithShortcut",{shortcut:Zs("toggle_right_sidebar")}),ariaLabel:a("header.actions.toggleRightSidebarAria"),onClick:d,Icon:"layout-right"}),s.jsx(Cw,{isMobile:H,githubAuthStatus:J,githubAccounts:Ce,githubAvatarUrl:ke,githubLogin:Fe,isSwitchingGitHubAccount:Q,handleGitHubAccountSwitch:Ds})]}),ir=W&&(w||!!N),bn=()=>s.jsxs("div",{onMouseDown:tn,className:ge("app-region-drag relative flex h-12 select-none items-center pr-3",gs,js),style:Ls,role:"tablist","aria-label":a("header.navigation.mainAria"),children:[be?s.jsx(di,{title:a("header.actions.openAppMenu"),ariaLabel:a("header.actions.openAppMenuAria"),onClick:Ks,className:`${Ke} shrink-0`,Icon:"menu-2"}):null,s.jsx(di,{title:a("header.actions.openSessionsWithShortcut",{shortcut:Zs("toggle_sidebar")}),ariaLabel:a("header.actions.openSessionsAria"),onClick:en,className:`${Ke} shrink-0`,Icon:"layout-left"}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center pl-3",children:[Bt&&s.jsx(Am,{projectRef:Bt.projectRef,directory:Bt.directory,className:"mr-2"}),s.jsx(Ab,{children:s.jsxs("button",{type:"button","aria-label":a("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:w?a("sessions.switcher.draftTitle"):es}),M||zt||!w&&(hs||ft)?s.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[M?s.jsx("span",{className:"truncate",children:M}):null,zt?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:zt})]}):null,!w&&hs?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:["+",cs.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",cs.deletions]})]}):null,!w&&ft?s.jsxs("span",{className:ge("inline-flex min-w-0 items-center gap-0.5",ft==="attention"||ft==="invalid"||ft==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(A,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:vt})]}):null]}):null]})}),cn.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:cn.map(Be=>Hn(Be))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[De&&me?s.jsx(Db,{totalTokens:me.totalTokens,percentage:Qe,colorPercentage:me.percentage,contextLimit:me.contextLimit,outputLimit:me.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:re,pressed:bt,className:ir?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,s.jsx(di,{visible:ir,title:a(w?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:a(w?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:Xs,className:ge(Ke,De?"mr-3.5":"mr-1"),Icon:"picture-in-picture-2"}),kr,s.jsx(kw,{visible:be})]})]})]}),On=()=>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:Kt,className:ge(Je,Ct==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":a(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(A,{name:"layout-left",className:"h-5 w-5"})}):we?s.jsx("button",{type:"button",onClick:()=>i(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":a("header.actions.backAria"),children:s.jsx(A,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:en,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":a("header.actions.openSessionsAria"),children:s.jsx(A,{name:"play-list-add",className:"h-5 w-5"})}),!t&&we&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:a("header.sessions.title")})]}),(!we||!!t)&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":a("header.navigation.mainAria"),children:cn.map(Be=>{const St=g===Be.id,Gt=Be.icon==="diff",Yt=Gt?null:Be.icon;return s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{H&&(Xt(),kt()),y(Be.id)},"aria-label":Be.label,"aria-selected":St,role:"tab",className:ge(Je,"relative rounded-lg",Ct===Be.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[Gt?s.jsx(bm,{className:"h-5 w-5"}):Yt?s.jsx(A,{name:Yt,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":a("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:[Bt&&s.jsx(Am,{projectRef:Bt.projectRef,directory:Bt.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(As,{open:ve,onOpenChange:Be=>{Be&&(n&&t&&t(),r&&e&&e()),le(Be),Be&&D.length===0&&F()},children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.services.viewAria"),className:ge(Je,Ct==="services"&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(A,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(At,{children:s.jsx("p",{children:a("header.services.title")})})]}),s.jsx(Ps,{align:"end",sideOffset:0,positionerClassName:"!fixed !bottom-0 !left-0 !right-0 !top-[var(--oc-header-height,56px)] !transform-none",className:"h-full w-screen max-h-none rounded-none border-0 p-0 pt-1 overflow-hidden",children:s.jsxs("div",{className:"flex h-full flex-col bg-[var(--surface-elevated)]",children:[s.jsx("div",{className:"sticky top-0 z-20 bg-[var(--surface-elevated)] px-2 py-px",children:s.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-0",children:[s.jsx("div",{className:"h-10 min-w-0 flex-1",children:s.jsx(Fr,{items:Kn,activeId:Oe,onSelect:Be=>{const St=Be;Ie(St),St==="usage"&&D.length===0&&F()},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:()=>le(!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":a("header.services.closeAria"),children:s.jsx(A,{name:"close",className:"h-5 w-5"})})]})}),Oe==="mcp"&&s.jsx(eg,{active:ve&&Oe==="mcp"}),Oe==="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:a("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:rg(V)})]}),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:()=>Ze("usage"),className:ge("typography-ui-label px-1 pb-0.5 transition-colors",$==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:a("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>Ze("remaining"),className:ge("typography-ui-label px-1 pb-0.5 transition-colors",$==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:a("header.services.remaining")})]}),s.jsx("button",{type:"button",className:ge("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:ze,disabled:_||$e,"aria-label":a("header.services.refreshRateLimitsAria"),children:s.jsx(A,{name:"refresh",className:ge("h-4 w-4",$e&&"animate-spin")})})]})]})}),!nt&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:a("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:qe.map((Be,St)=>s.jsxs(o.Fragment,{children:[St>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(wr,{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??a("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Be.entries.map(([Gt,Yt])=>{const ks=$==="remaining"?Yt.remainingPercent:Yt.usedPercent,Bs=vo(Yt.usedPercent,Yt.resetAt,Yt.windowSeconds,Gt),Fs=Bs?.dailyAllocationPercent!=null?$==="remaining"?100-na(Bs.elapsedRatio):na(Bs.elapsedRatio):null,Ys=yo(Yt.valueLabel,ks),nn=mu(Yt.resetAt,Yt.resetAfterFormatted??Yt.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:pu(Gt)}),nn?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:nn}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Ys==="-"?"":Ys})]}),s.jsx(jo,{percent:ks,tonePercent:Yt.usedPercent,className:"h-1.5",expectedMarkerPercent:Fs}),Bs&&O?s.jsx(No,{paceInfo:Bs,compact:!0}):null]},`${Be.providerId}-${Gt}`)}),Be.modelFamilies&&Be.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:Be.modelFamilies.map(Gt=>{const ks=(We[Be.providerId]??[]).includes(Gt.familyId??"other");return s.jsxs(jr,{open:ks,onOpenChange:()=>at(Be.providerId,Gt.familyId??"other"),children:[s.jsxs(Lr,{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:Gt.familyLabel}),ks?s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(Nr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Gt.models.map(([Bs,Fs])=>{const Ys=$==="remaining"?Fs.remainingPercent:Fs.usedPercent,nn=vo(Fs.usedPercent,Fs.resetAt,Fs.windowSeconds),Xn=nn?.dailyAllocationPercent!=null?$==="remaining"?100-na(nn.elapsedRatio):na(nn.elapsedRatio):null,Cr=yo(Fs.valueLabel,Ys);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:Ll(Bs)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Cr==="-"?"":Cr})]}),s.jsx(jo,{percent:Ys,tonePercent:Fs.usedPercent,className:"h-1.5",expectedMarkerPercent:Xn}),nn&&O?s.jsx(No,{paceInfo:nn,compact:!0}):null]},`${Be.providerId}-${Bs}`)})})})]},Gt.familyId??"other")})})]})]},Be.providerId))})]})]})})]}),e?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Tt,className:ge(Je,"relative",Ct==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(A,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(At,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),ur=ge("header-safe-area relative z-10",H?"border-b border-border/50 bg-background":"bg-sidebar");return s.jsx("header",{ref:ue,className:ur,style:{"--padding-scale":"1"},children:H?On():bn()})};function Dw(){}function Tw(){ra("desktop_minimize_current_window")}function Ew(){}function Mw(){ra("desktop_close_current_window")}function Rw(){}const Tm=180,Em=640,Fw=110,Lw=t=>{const e=ot.c(44),{isOpen:n,isMobile:r,children:a}=t,{t:i}=pt(),l=_e(Ow),c=_e($w),d=_e(_w),f=_e(Bw),[m,u]=o.useState(null),[p,b]=o.useState(!1),g=o.useRef(null),y=o.useRef(0),x=o.useRef(l||300),h=Math.min(Em,Math.max(Tm,l||300));let j,v;e[0]!==n?(j=()=>{n||(u(null),b(!1))},v=[n],e[0]=n,e[1]=j,e[2]=v):(j=e[1],v=e[2]),o.useEffect(j,v);let C,k;e[3]!==c||e[4]!==r||e[5]!==n?(C=()=>{if(r||!n||!c)return;const J=()=>{const de=g.current?.parentElement?.getBoundingClientRect().height;if(!de||de<=0)return;const pe=Math.max(0,Math.round(de));u(W=>W===pe?W:pe)};J();const ne=g.current?.parentElement;if(!ne)return;const ue=new ResizeObserver(J);return ue.observe(ne),()=>{ue.disconnect()}},k=[c,r,n],e[3]=c,e[4]=r,e[5]=n,e[6]=C,e[7]=k):(C=e[6],k=e[7]),o.useEffect(C,k);let w,N;if(e[8]!==c||e[9]!==r||e[10]!==p||e[11]!==d||e[12]!==f?(w=()=>{if(r||!p||c)return;const J=ue=>{const de=y.current-ue.clientY,pe=Math.min(Em,Math.max(Tm,x.current+de));d(pe)},ne=()=>{b(!1),_e.getState().bottomTerminalHeight<=Fw&&f(!1)};return window.addEventListener("pointermove",J),window.addEventListener("pointerup",ne,{once:!0}),()=>{window.removeEventListener("pointermove",J),window.removeEventListener("pointerup",ne)}},N=[c,r,p,d,f],e[8]=c,e[9]=r,e[10]=p,e[11]=d,e[12]=f,e[13]=w,e[14]=N):(w=e[13],N=e[14]),o.useEffect(w,N),r)return null;const I=n?c?Math.max(0,m??h):h:0,E=n&&c;let P;e[15]!==I||e[16]!==c||e[17]!==n?(P=J=>{!n||c||(b(!0),y.current=J.clientY,x.current=I,J.preventDefault())},e[15]=I,e[16]=c,e[17]=n,e[18]=P):P=e[18];const T=P,S=E?"absolute inset-x-0 bottom-0 z-40":"relative",M=p?"transition-none":"transition-[height] duration-300 ease-in-out",D=(!n||E)&&"border-t-0";let F;e[19]!==D||e[20]!==S||e[21]!==M?(F=ge("flex overflow-hidden border-t border-border bg-sidebar",S,M,D),e[19]=D,e[20]=S,e[21]=M,e[22]=F):F=e[22];let _;e[23]!==I||e[24]!==E?(_=E?{top:0}:{height:`${I}px`,minHeight:`${I}px`,maxHeight:`${I}px`},e[23]=I,e[24]=E,e[25]=_):_=e[25];const V=!n||!c&&I===0;let $;e[26]!==T||e[27]!==c||e[28]!==n||e[29]!==p||e[30]!==i?($=n&&!c&&s.jsx("div",{className:ge("absolute left-0 top-0 z-20 h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",p&&"bg-[var(--interactive-border)]"),onPointerDown:T,role:"separator","aria-orientation":"horizontal","aria-label":i("terminalView.bottomDock.resizeAria")}),e[26]=T,e[27]=c,e[28]=n,e[29]=p,e[30]=i,e[31]=$):$=e[31];const O=!n&&"pointer-events-none select-none opacity-0";let B;e[32]!==O?(B=ge("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",O),e[32]=O,e[33]=B):B=e[33];const G=!n;let R;e[34]!==a||e[35]!==B||e[36]!==G?(R=s.jsx("div",{className:B,"aria-hidden":G,children:a}),e[34]=a,e[35]=B,e[36]=G,e[37]=R):R=e[37];let H;return e[38]!==F||e[39]!==_||e[40]!==V||e[41]!==$||e[42]!==R?(H=s.jsxs("section",{ref:g,className:F,style:_,"aria-hidden":V,children:[$,R]}),e[38]=F,e[39]=_,e[40]=V,e[41]=$,e[42]=R,e[43]=H):H=e[43],H};function Ow(t){return t.bottomTerminalHeight}function $w(t){return t.isBottomTerminalExpanded}function _w(t){return t.setBottomTerminalHeight}function Bw(t){return t.setBottomTerminalOpen}const Sd=280,Mm=280,Rm=500,Vw=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:a}=pt(),i=_e(w=>w.sidebarWidth),l=_e(w=>w.setSidebarWidth),[c,d]=o.useState(!1),f=o.useRef(0),m=o.useRef(i||Sd),u=o.useRef(null),p=o.useRef(null),b=o.useRef(null),g=o.useCallback(w=>Math.min(Rm,Math.max(Mm,w)),[]),y=o.useCallback(w=>{const N=b.current;N&&(N.style.width=`${w}px`,N.style.minWidth=`${w}px`,N.style.maxWidth=`${w}px`,N.style.setProperty("--oc-left-sidebar-width",`${w}px`))},[]);if(o.useEffect(()=>{e&&c&&d(!1)},[e,c]),o.useEffect(()=>{c||(u.current=null,p.current=null)},[c]),e)return null;const x=Math.min(Rm,Math.max(Mm,i||Sd)),h=t?x:0,j=w=>{if(t){try{w.currentTarget.setPointerCapture(w.pointerId)}catch{}p.current=w.pointerId,d(!0),f.current=w.clientX,m.current=h,u.current=h,y(h),w.preventDefault()}},v=w=>{if(e||!c||p.current!==w.pointerId)return;const N=w.clientX-f.current,I=g(m.current+N);u.current!==I&&(u.current=I,y(I))},C=w=>{if(p.current!==w.pointerId||e)return;try{w.currentTarget.releasePointerCapture(w.pointerId)}catch{}const N=g(u.current??h);p.current=null,u.current=null,d(!1),l(N)},k=c?u.current??h:h;return s.jsxs("aside",{ref:b,className:ge("relative flex h-full overflow-hidden border-r border-border/40 will-change-[width] motion-reduce:transition-none","bg-sidebar",!t&&"border-r-0",r),style:{width:`${k}px`,minWidth:`${k}px`,maxWidth:`${k}px`,"--oc-left-sidebar-width":`${c?k:x}px`,overflowX:"clip",transitionProperty:c?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||h===0,children:[t&&s.jsx("div",{className:ge("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:j,onPointerMove:v,onPointerUp:C,onPointerCancel:C,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.leftPanelAria")}),s.jsx("div",{className:ge("relative z-10 flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",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(Qs,{children:n})})})]})},kd=420,Fm=360,Lm=860,zw=({isOpen:t,children:e,className:n})=>{const{t:r}=pt(),a=_e(k=>k.rightSidebarWidth),i=_e(k=>k.setRightSidebarWidth),[l,c]=o.useState(!1),d=o.useRef(0),f=o.useRef(a||kd),m=o.useRef(null),u=o.useRef(null),p=o.useRef(null),b=o.useCallback(k=>Math.min(Lm,Math.max(Fm,k)),[]),g=o.useCallback(k=>{const w=p.current;w&&(w.style.width=`${k}px`,w.style.minWidth=`${k}px`,w.style.maxWidth=`${k}px`,w.style.setProperty("--oc-right-sidebar-width",`${k}px`))},[]),y=Math.min(Lm,Math.max(Fm,a||kd)),x=t?y:0,h=k=>{if(t){try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}u.current=k.pointerId,c(!0),d.current=k.clientX,f.current=x,m.current=x,g(x),k.preventDefault()}},j=k=>{if(!l||u.current!==k.pointerId)return;const w=d.current-k.clientX,N=b(f.current+w);m.current!==N&&(m.current=N,g(N))},v=k=>{if(u.current!==k.pointerId)return;try{k.currentTarget.releasePointerCapture(k.pointerId)}catch{}const w=b(m.current??x);u.current=null,m.current=null,c(!1),i(w)};o.useEffect(()=>{l||(m.current=null,u.current=null)},[l]);const C=l?m.current??x:x;return s.jsxs("aside",{ref:p,className:ge("relative flex h-full overflow-hidden border-l border-border/40 will-change-[width] motion-reduce:transition-none","bg-sidebar",!t&&"border-l-0",n),style:{width:`${C}px`,minWidth:`${C}px`,maxWidth:`${C}px`,"--oc-right-sidebar-width":`${l?C:y}px`,overflowX:"clip",transitionProperty:l?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||x===0,children:[t&&s.jsx("div",{className:ge("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",l&&"bg-[var(--interactive-border)]"),onPointerDown:h,onPointerMove:j,onPointerUp:v,onPointerCancel:v,role:"separator","aria-orientation":"vertical","aria-label":r("sidebar.resize.rightPanelAria")}),s.jsx("div",{className:ge("relative z-10 flex h-full min-h-0 shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",l&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-right-sidebar-width)"},"aria-hidden":!t,children:t?e:null})]})},Eo=t=>{const e=ot.c(129),{providerId:n,modelId:r,onChange:a,className:i,allowedProviderIds:l,placeholder:c,tooltipsEnabled:d,dropdownPortalToBody:f}=t,m=d===void 0?!0:d,u=f===void 0?!1:f,{t:p}=pt(),{isReady:b,isUnavailable:g}=wh(),y=jt(Uw),x=jt(Ww),h=_e(Kw),j=_e(Hw),v=_e(Gw),C=_e(qw),k=_e(Jw),{favoriteModelsList:w,recentModelsList:N}=jh(),{isMobile:I}=an(),E=h||I,[P,T]=o.useState(!1),[S,M]=o.useState(!1),[D,F]=o.useState("");let _;e[0]===Symbol.for("react.memo_cache_sentinel")?(_=()=>{T(!1),M(!1),F("")},e[0]=_):_=e[0];const V=_;let $;e[1]!==k||e[2]!==a?($=q=>{a(q.providerID,q.modelID),k(q.providerID,q.modelID),V()},e[1]=k,e[2]=a,e[3]=$):$=e[3];const O=$;let B;e[4]!==a?(B=()=>{a("",""),V()},e[4]=a,e[5]=B):B=e[5];const G=B;let R;e[6]!==p?(R=p("settings.agents.modelSelector.searchPlaceholder"),e[6]=p,e[7]=R):R=e[7];let H;e[8]!==p?(H=p("settings.agents.modelSelector.state.noModelsFound"),e[8]=p,e[9]=H):H=e[9];let J;e[10]!==p?(J=p("settings.agents.modelSelector.section.favorites"),e[10]=p,e[11]=J):J=e[11];let ne;e[12]!==p?(ne=p("settings.agents.modelSelector.section.recent"),e[12]=p,e[13]=ne):ne=e[13];let ue;e[14]!==p?(ue=p("settings.agents.modelSelector.keyboardHints"),e[14]=p,e[15]=ue):ue=e[15];let de;e[16]!==c||e[17]!==p?(de=c||p("settings.agents.modelSelector.notSelected"),e[16]=c,e[17]=p,e[18]=de):de=e[18];let pe;e[19]!==p?(pe=p("settings.agents.modelSelector.actions.favorite"),e[19]=p,e[20]=pe):pe=e[20];let W;e[21]!==p?(W=p("settings.agents.modelSelector.actions.unfavorite"),e[21]=p,e[22]=W):W=e[22];let te;e[23]!==p?(te=p("chat.modelControls.capabilities"),e[23]=p,e[24]=te):te=e[24];let X;e[25]!==p?(X=p("chat.modelControls.capability.toolCalling"),e[25]=p,e[26]=X):X=e[26];let ee;e[27]!==p?(ee=p("chat.modelControls.capability.reasoning"),e[27]=p,e[28]=ee):ee=e[28];let fe;e[29]!==p?(fe=p("chat.modelControls.input"),e[29]=p,e[30]=fe):fe=e[30];let be;e[31]!==p?(be=p("chat.modelControls.output"),e[31]=p,e[32]=be):be=e[32];let Ne;e[33]!==p?(Ne=p("chat.modelControls.costPerMillion"),e[33]=p,e[34]=Ne):Ne=e[34];let se;e[35]!==ue||e[36]!==de||e[37]!==pe||e[38]!==W||e[39]!==te||e[40]!==X||e[41]!==ee||e[42]!==fe||e[43]!==be||e[44]!==Ne||e[45]!==R||e[46]!==H||e[47]!==J||e[48]!==ne?(se={searchPlaceholder:R,noResults:H,favorites:J,recent:ne,keyboardHint:ue,notSelected:de,favorite:pe,unfavorite:W,capabilities:te,capabilityToolCalling:X,capabilityReasoning:ee,input:fe,output:be,costPerMillion:Ne},e[35]=ue,e[36]=de,e[37]=pe,e[38]=W,e[39]=te,e[40]=X,e[41]=ee,e[42]=fe,e[43]=be,e[44]=Ne,e[45]=R,e[46]=H,e[47]=J,e[48]=ne,e[49]=se):se=e[49];const ie=se;let ae;e[50]!==r||e[51]!==n?(ae=n&&r?{providerID:n,modelID:r}:null,e[50]=r,e[51]=n,e[52]=ae):ae=e[52];const xe=ae;let Z;e[53]!==r||e[54]!==c||e[55]!==n||e[56]!==p?(Z=n&&r?`${n}/${r}`:c||p("settings.agents.modelSelector.notSelected"),e[53]=r,e[54]=c,e[55]=n,e[56]=p,e[57]=Z):Z=e[57];const me=Z,Y=m&&(E?P:S);let Se;e[58]!==C?(Se=q=>C(q.providerID,q.modelID),e[58]=C,e[59]=Se):Se=e[59];let we;e[60]!==v?(we=q=>v(q.providerID,q.modelID),e[60]=v,e[61]=we):we=e[61];let ke;e[62]!==l||e[63]!==w||e[64]!==O||e[65]!==G||e[66]!==j||e[67]!==ie||e[68]!==x||e[69]!==y||e[70]!==N||e[71]!==D||e[72]!==xe||e[73]!==Y||e[74]!==Se||e[75]!==we?(ke=s.jsx(Nh,{providers:y,favoriteModels:w,recentModels:N,modelsMetadata:x,searchQuery:D,onSearchQueryChange:F,onSelect:O,labels:ie,selectedModel:xe,hiddenModels:j,allowedProviderIds:l,includeNotSelected:!0,onSelectNone:G,onEscape:V,tooltipsEnabled:Y,isFavorite:Se,onToggleFavorite:we}),e[62]=l,e[63]=w,e[64]=O,e[65]=G,e[66]=j,e[67]=ie,e[68]=x,e[69]=y,e[70]=N,e[71]=D,e[72]=xe,e[73]=Y,e[74]=Se,e[75]=we,e[76]=ke):ke=e[76];const Fe=ke;if(E){let q;e[77]!==b?(q=b?()=>T(!0):void 0,e[77]=b,e[78]=q):q=e[78];const L=!b,U=!b&&"opacity-60 cursor-not-allowed";let oe;e[79]!==i||e[80]!==U?(oe=ge("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",U,i),e[79]=i,e[80]=U,e[81]=oe):oe=e[81];let Ee;e[82]!==b||e[83]!==g||e[84]!==n||e[85]!==p?(Ee=b?n?s.jsx(wr,{providerId:n,className:"h-3.5 w-3.5 flex-shrink-0"}):s.jsx(A,{name:"pencil-ai",className:"h-3 w-3 text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(A,{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:p(g?"common.unavailable":"common.loading")})]}),e[82]=b,e[83]=g,e[84]=n,e[85]=p,e[86]=Ee):Ee=e[86];let Oe;e[87]!==b||e[88]!==me?(Oe=b?s.jsx("span",{className:"typography-meta font-medium text-foreground truncate",children:me}):null,e[87]=b,e[88]=me,e[89]=Oe):Oe=e[89];let Ie;e[90]!==Ee||e[91]!==Oe?(Ie=s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[Ee,Oe]}),e[90]=Ee,e[91]=Oe,e[92]=Ie):Ie=e[92];let z;e[93]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(A,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),e[93]=z):z=e[93];let De;e[94]!==q||e[95]!==L||e[96]!==oe||e[97]!==Ie?(De=s.jsxs("button",{type:"button",onClick:q,disabled:L,className:oe,children:[Ie,z]}),e[94]=q,e[95]=L,e[96]=oe,e[97]=Ie,e[98]=De):De=e[98];let Qe;e[99]!==p?(Qe=p("settings.agents.modelSelector.title"),e[99]=p,e[100]=Qe):Qe=e[100];let tt;e[101]!==P||e[102]!==Fe||e[103]!==Qe?(tt=s.jsx(Ur,{open:P,onClose:V,title:Qe,children:Fe}),e[101]=P,e[102]=Fe,e[103]=Qe,e[104]=tt):tt=e[104];let et;return e[105]!==De||e[106]!==tt?(et=s.jsxs(s.Fragment,{children:[De,tt]}),e[105]=De,e[106]=tt,e[107]=et):et=e[107],et}const Ce=b&&S,Q=b?M:void 0,ce=!b&&"opacity-60 cursor-not-allowed";let ve;e[108]!==i||e[109]!==ce?(ve=ge("border-input data-[placeholder]:text-muted-foreground flex min-w-0 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",ce,i),e[108]=i,e[109]=ce,e[110]=ve):ve=e[110];let le;e[111]!==b||e[112]!==g||e[113]!==n||e[114]!==p||e[115]!==me?(le=b?s.jsxs(s.Fragment,{children:[n?s.jsx(wr,{providerId:n,className:"h-3.5 w-3.5 flex-shrink-0"}):s.jsx(A,{name:"pencil-ai",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 truncate font-normal text-foreground",children:me})]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{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:p(g?"common.unavailable":"common.loading")})]}),e[111]=b,e[112]=g,e[113]=n,e[114]=p,e[115]=me,e[116]=le):le=e[116];let Ae;e[117]===Symbol.for("react.memo_cache_sentinel")?(Ae=s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"}),e[117]=Ae):Ae=e[117];let Te;e[118]!==ve||e[119]!==le?(Te=s.jsx(Is,{asChild:!0,children:s.jsxs("div",{className:ve,children:[le,Ae]})}),e[118]=ve,e[119]=le,e[120]=Te):Te=e[120];let $e;e[121]!==u||e[122]!==Fe?($e=s.jsx(Ps,{className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",align:"start",portalToBody:u,children:Fe}),e[121]=u,e[122]=Fe,e[123]=$e):$e=e[123];let ye;return e[124]!==Ce||e[125]!==Q||e[126]!==Te||e[127]!==$e?(ye=s.jsxs(As,{open:Ce,onOpenChange:Q,children:[Te,$e]}),e[124]=Ce,e[125]=Q,e[126]=Te,e[127]=$e,e[128]=ye):ye=e[128],ye};function Uw(t){return t.providers}function Ww(t){return t.modelsMetadata}function Kw(t){return t.isMobile}function Hw(t){return t.hiddenModels}function Gw(t){return t.toggleFavoriteModel}function qw(t){return t.isFavoriteModel}function Jw(t){return t.addRecentModel}const dc=t=>{const e=ot.c(34),{agentName:n,onChange:r,className:a,filter:i}=t,{t:l}=pt(),{isReady:c,isUnavailable:d}=wh(),f=jt(Yw),m=ki(Qw),u=ki(Xw),p=jt(Zw);let b;e:{if(Array.isArray(f)&&f.length>0){b=f;break e}let V;e[0]!==m?(V=Array.isArray(m)?m:[],e[0]=m,e[1]=V):V=e[1],b=V}const g=b;let y;if(e[2]!==i||e[3]!==g){const V=Tb(g);y=i?V.filter(i):V,e[2]=i,e[3]=g,e[4]=y}else y=e[4];const x=y,h=_e(ej),{isMobile:j}=an(),v=h||j,[C,k]=o.useState(!1);let w,N;e[5]!==u||e[6]!==p||e[7]!==g.length?(w=()=>{g.length>0||(p(),u())},N=[g.length,p,u],e[5]=u,e[6]=p,e[7]=g.length,e[8]=w,e[9]=N):(w=e[8],N=e[9]),o.useEffect(w,N);let I;e[10]===Symbol.for("react.memo_cache_sentinel")?(I=()=>k(!1),e[10]=I):I=e[10];const E=I;let P;e[11]!==r?(P=V=>{r(V)},e[11]=r,e[12]=P):P=e[12];const T=P;let S;e[13]!==n||e[14]!==x||e[15]!==T||e[16]!==v||e[17]!==C||e[18]!==l?(S=()=>v?s.jsx(Ur,{open:C,onClose:E,title:l("settings.commands.agentSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",className:ge("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:()=>{T(""),E()},children:[s.jsx("span",{className:ge("typography-meta",n?"text-muted-foreground":"font-medium"),children:l("settings.commands.agentSelector.notSelected")}),!n&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]}),x.map(V=>{const $=V.name===n;return s.jsxs("button",{type:"button",className:ge("flex w-full items-center justify-between rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",$?"bg-primary/10 text-primary":"text-foreground"),onClick:()=>{T(V.name),E()},children:[s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-meta font-medium",children:V.name}),V.description&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:V.description})]}),$&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]},V.name)})]})}):null,e[13]=n,e[14]=x,e[15]=T,e[16]=v,e[17]=C,e[18]=l,e[19]=S):S=e[19];const M=S;let D;e[20]!==n||e[21]!==x||e[22]!==a||e[23]!==T||e[24]!==v||e[25]!==c||e[26]!==d||e[27]!==l?(D=v?s.jsxs("button",{type:"button",onClick:c?()=>k(!0):void 0,disabled:!c,className:ge("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(A,{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||l("settings.commands.agentSelector.selectAgentPlaceholder")})]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{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:l(d?"common.unavailable":"common.loading")})]})}),s.jsx(A,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):c?s.jsxs(As,{children:[s.jsx(Is,{asChild:!0,children:s.jsxs("div",{className:ge("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(A,{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||l("settings.commands.agentSelector.notSelected")}),s.jsx(A,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsxs(Ps,{className:"max-w-[300px]",children:[s.jsx(Ot,{className:"typography-meta",onSelect:()=>T(""),children:s.jsx("span",{className:"text-muted-foreground",children:l("settings.commands.agentSelector.notSelected")})}),x.map(V=>s.jsx(Ot,{className:"typography-meta",onSelect:()=>T(V.name),children:s.jsx("span",{className:"font-medium",children:V.name})},V.name))]})]}):s.jsxs("div",{className:ge("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(A,{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:l(d?"common.unavailable":"common.loading")})]}),e[20]=n,e[21]=x,e[22]=a,e[23]=T,e[24]=v,e[25]=c,e[26]=d,e[27]=l,e[28]=D):D=e[28];let F;e[29]!==M?(F=M(),e[29]=M,e[30]=F):F=e[30];let _;return e[31]!==D||e[32]!==F?(_=s.jsxs(s.Fragment,{children:[D,F]}),e[31]=D,e[32]=F,e[33]=_):_=e[33],_};function Yw(t){return t.agents}function Qw(t){return t.agents}function Xw(t){return t.loadAgents}function Zw(t){return t.loadAgents}function ej(t){return t.isMobile}const Om=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent}),tj=t=>{const e=ot.c(38),{value:n,options:r,disabled:a,onChange:i}=t,{t:l}=pt();let c;e[0]!==l||e[1]!==n?(c=n||l("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[0]=l,e[1]=n,e[2]=c):c=e[2];const d=c,f=a?"cursor-not-allowed opacity-60":"cursor-pointer hover:bg-interactive-hover/30";let m;e[3]!==f?(m=ge("flex h-6 w-fit items-center gap-1.5 rounded-lg border border-border/20 bg-interactive-selection/20 px-2",f),e[3]=f,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 p;e[7]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(A,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),e[7]=p):p=e[7];let b;e[8]!==m||e[9]!==u?(b=s.jsxs("div",{className:m,children:[u,p]}),e[8]=m,e[9]=u,e[10]=b):b=e[10];const g=b;if(a)return g;let y;e[11]!==g?(y=s.jsx(Is,{asChild:!0,children:g}),e[11]=g,e[12]=y):y=e[12];let x;e[13]!==i?(x=()=>i(""),e[13]=i,e[14]=x):x=e[14];const h=!n&&"text-primary";let j;e[15]!==h?(j=ge("font-medium",h),e[15]=h,e[16]=j):j=e[16];let v;e[17]!==l?(v=l("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[17]=l,e[18]=v):v=e[18];let C;e[19]!==j||e[20]!==v?(C=s.jsx("span",{className:j,children:v}),e[19]=j,e[20]=v,e[21]=C):C=e[21];let k;e[22]!==C||e[23]!==x?(k=s.jsx(Ot,{className:"typography-meta",onSelect:x,children:C}),e[22]=C,e[23]=x,e[24]=k):k=e[24];let w;if(e[25]!==i||e[26]!==r||e[27]!==n){let E;e[29]!==i||e[30]!==n?(E=P=>s.jsx(Ot,{className:"typography-meta",onSelect:()=>i(P),children:s.jsx("span",{className:ge("font-medium capitalize",n===P&&"text-primary"),children:P})},P),e[29]=i,e[30]=n,e[31]=E):E=e[31],w=r.map(E),e[25]=i,e[26]=r,e[27]=n,e[28]=w}else w=e[28];let N;e[32]!==k||e[33]!==w?(N=s.jsxs(Ps,{align:"start",className:"max-w-[220px]",children:[k,w]}),e[32]=k,e[33]=w,e[34]=N):N=e[34];let I;return e[35]!==N||e[36]!==y?(I=s.jsxs(As,{children:[y,N]}),e[35]=N,e[36]=y,e[37]=I):I=e[37],I};function ag(t){const e=ot.c(120),{t:n}=pt(),{open:r,onOpenChange:a,target:i,projectDirectory:l,submitting:c,onConfirm:d}=t,f=c===void 0?!1:c,m=jt(uj),u=jt(dj),p=ki(cj),b=jt(lj),g=jt(oj),y=jt(ij),x=jt(aj),h=jt(rj);let j;e[0]!==h||e[1]!==y||e[2]!==g||e[3]!==x?(j=()=>Om({providerID:g,modelID:y,variant:x,agent:h}),e[0]=h,e[1]=y,e[2]=g,e[3]=x,e[4]=j):j=e[4];const[v,C]=o.useState(j);let k,w;e[5]!==p||e[6]!==u||e[7]!==m||e[8]!==r||e[9]!==l?(k=()=>{r&&(m({directory:l}),u({directory:l}),p())},w=[r,m,u,p,l],e[5]=p,e[6]=u,e[7]=m,e[8]=r,e[9]=l,e[10]=k,e[11]=w):(k=e[10],w=e[11]),o.useEffect(k,w);let N,I;e[12]!==h||e[13]!==y||e[14]!==g||e[15]!==x||e[16]!==r?(N=()=>{r&&C(Om({providerID:g,modelID:y,variant:x,agent:h}))},I=[r,g,y,x,h],e[12]=h,e[13]=y,e[14]=g,e[15]=x,e[16]=r,e[17]=N,e[18]=I):(N=e[17],I=e[18]),o.useEffect(N,I);let E,P;e[19]!==v.modelID||e[20]!==v.providerID||e[21]!==r||e[22]!==b?(E=()=>{if(!r||b.length===0)return;const ye=b.find(oe=>oe.id===v.providerID)??b[0],q=Array.isArray(ye?.models)?ye.models:[],L=q.some(oe=>oe.id===v.modelID),U=q[0]?.id??"";ye?.id===v.providerID&&L||C(oe=>({...oe,providerID:ye?.id??"",modelID:L?oe.modelID:U,variant:""}))},P=[r,b,v.providerID,v.modelID],e[19]=v.modelID,e[20]=v.providerID,e[21]=r,e[22]=b,e[23]=E,e[24]=P):(E=e[23],P=e[24]),o.useEffect(E,P);const T=nj;let S;if(e[25]!==v.modelID||e[26]!==v.providerID||e[27]!==b){let ye;e[29]!==v.providerID?(ye=L=>L.id===v.providerID,e[29]=v.providerID,e[30]=ye):ye=e[30],S=b.find(ye)?.models?.find(L=>L.id===v.modelID),e[25]=v.modelID,e[26]=v.providerID,e[27]=b,e[28]=S}else S=e[28];const M=S;let D;e[31]!==M?(D=M?.variants?Object.keys(M.variants):[],e[31]=M,e[32]=D):D=e[32];const F=D,_=F.length>0;let V,$;e[33]!==v.variant||e[34]!==_?(V=()=>{_||!v.variant||C(sj)},$=[_,v.variant],e[33]=v.variant,e[34]=_,e[35]=V,e[36]=$):(V=e[35],$=e[36]),o.useEffect(V,$);let O;e[37]!==v.modelID||e[38]!==v.providerID?(O=v.providerID.trim().length>0&&v.modelID.trim().length>0,e[37]=v.modelID,e[38]=v.providerID,e[39]=O):O=e[39];const B=O;let G;e[40]!==B||e[41]!==v||e[42]!==d||e[43]!==f?(G=()=>{!B||f||d(v)},e[40]=B,e[41]=v,e[42]=d,e[43]=f,e[44]=G):G=e[44];const R=G;let H,J;e[45]!==R||e[46]!==r?(H=()=>{if(!r)return;const ye=q=>{(q.metaKey||q.ctrlKey)&&q.key==="Enter"&&(q.preventDefault(),R())};return window.addEventListener("keydown",ye),()=>window.removeEventListener("keydown",ye)},J=[r,R],e[45]=R,e[46]=r,e[47]=H,e[48]=J):(H=e[47],J=e[48]),o.useEffect(H,J);let ne;e[49]!==n||e[50]!==i?(ne=n(i==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=i,e[51]=ne):ne=e[51];const ue=ne;let de;e[52]!==a||e[53]!==f?(de=ye=>{f||a(ye)},e[52]=a,e[53]=f,e[54]=de):de=e[54];let pe;e[55]!==ue?(pe=s.jsx(ps,{children:s.jsx(ds,{children:ue})}),e[55]=ue,e[56]=pe):pe=e[56];let W;e[57]!==n?(W=n("chat.modelControls.model"),e[57]=n,e[58]=W):W=e[58];let te;e[59]!==W?(te=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:W}),e[59]=W,e[60]=te):te=e[60];let X;e[61]===Symbol.for("react.memo_cache_sentinel")?(X=(ye,q)=>{C(L=>({...L,providerID:ye,modelID:q,variant:""}))},e[61]=X):X=e[61];let ee;e[62]!==v.modelID||e[63]!==v.providerID?(ee=s.jsx(Eo,{providerId:v.providerID,modelId:v.modelID,className:"w-full justify-between",dropdownPortalToBody:!0,onChange:X}),e[62]=v.modelID,e[63]=v.providerID,e[64]=ee):ee=e[64];let fe;e[65]!==te||e[66]!==ee?(fe=s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[te,ee]}),e[65]=te,e[66]=ee,e[67]=fe):fe=e[67];let be;e[68]!==n?(be=n("sessions.scheduledTasks.editor.thinkingLevel.label"),e[68]=n,e[69]=be):be=e[69];let Ne;e[70]!==be?(Ne=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:be}),e[70]=be,e[71]=Ne):Ne=e[71];const se=!_;let ie;e[72]===Symbol.for("react.memo_cache_sentinel")?(ie=ye=>C(q=>({...q,variant:ye})),e[72]=ie):ie=e[72];let ae;e[73]!==v.variant||e[74]!==se||e[75]!==F?(ae=s.jsx(tj,{value:v.variant,options:F,disabled:se,onChange:ie}),e[73]=v.variant,e[74]=se,e[75]=F,e[76]=ae):ae=e[76];let xe;e[77]!==Ne||e[78]!==ae?(xe=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[Ne,ae]}),e[77]=Ne,e[78]=ae,e[79]=xe):xe=e[79];let Z;e[80]!==n?(Z=n("sessions.scheduledTasks.editor.agent.label"),e[80]=n,e[81]=Z):Z=e[81];let me;e[82]!==Z?(me=s.jsx("span",{className:"typography-meta font-medium text-muted-foreground",children:Z}),e[82]=Z,e[83]=me):me=e[83];let Y;e[84]===Symbol.for("react.memo_cache_sentinel")?(Y=ye=>C(q=>({...q,agent:ye})),e[84]=Y):Y=e[84];let Se;e[85]!==v.agent?(Se=s.jsx(dc,{agentName:v.agent,filter:T,onChange:Y}),e[85]=v.agent,e[86]=Se):Se=e[86];let we;e[87]!==me||e[88]!==Se?(we=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[me,Se]}),e[87]=me,e[88]=Se,e[89]=we):we=e[89];let ke;e[90]!==fe||e[91]!==xe||e[92]!==we?(ke=s.jsxs("div",{className:"grid gap-4 sm:grid-cols-[minmax(0,1fr)_auto_auto]",children:[fe,xe,we]}),e[90]=fe,e[91]=xe,e[92]=we,e[93]=ke):ke=e[93];let Fe;e[94]!==a?(Fe=()=>a(!1),e[94]=a,e[95]=Fe):Fe=e[95];let Ce;e[96]!==n?(Ce=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[96]=n,e[97]=Ce):Ce=e[97];let Q;e[98]!==f||e[99]!==Fe||e[100]!==Ce?(Q=s.jsx(he,{variant:"ghost",size:"sm",onClick:Fe,disabled:f,children:Ce}),e[98]=f,e[99]=Fe,e[100]=Ce,e[101]=Q):Q=e[101];const ce=!B||f;let ve;e[102]!==f||e[103]!==n?(ve=n(f?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[102]=f,e[103]=n,e[104]=ve):ve=e[104];let le;e[105]!==R||e[106]!==ce||e[107]!==ve?(le=s.jsx(he,{size:"sm",onClick:R,disabled:ce,children:ve}),e[105]=R,e[106]=ce,e[107]=ve,e[108]=le):le=e[108];let Ae;e[109]!==Q||e[110]!==le?(Ae=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[Q,le]}),e[109]=Q,e[110]=le,e[111]=Ae):Ae=e[111];let Te;e[112]!==pe||e[113]!==ke||e[114]!==Ae?(Te=s.jsxs(os,{className:"max-w-2xl overflow-visible",children:[pe,ke,Ae]}),e[112]=pe,e[113]=ke,e[114]=Ae,e[115]=Te):Te=e[115];let $e;return e[116]!==r||e[117]!==de||e[118]!==Te?($e=s.jsx(ls,{open:r,onOpenChange:de,children:Te}),e[116]=r,e[117]=de,e[118]=Te,e[119]=$e):$e=e[119],$e}function sj(t){return{...t,variant:""}}function nj(t){return Sh(t.mode)}function rj(t){return t.currentAgentName||""}function aj(t){return t.currentVariant||""}function ij(t){return t.currentModelId}function oj(t){return t.currentProviderId}function lj(t){return t.providers}function cj(t){return t.loadAgents}function dj(t){return t.loadAgents}function uj(t){return t.loadProviders}const Cd=5,ig=15,gl=t=>{const e=Math.sqrt(t/100),n=12*e,r=24*e;return Math.ceil(n+r+1)},mj=(t,e)=>{const n=gl(e);return Math.max(n*Cd,Math.min(n*ig,n*t))},pj=async(t,e)=>{const n=await Fb(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},fj=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,$m=t=>[...t.filter(e=>!e.completed),...t.filter(e=>e.completed)],_m=(t,e)=>{const n=t.findIndex(r=>r.completed);return n===-1?[...t,e]:[...t.slice(0,n),e,...t.slice(n)]},hj=t=>{const e=ot.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:l,setNodeRef:c,setActivatorNodeRef:d,transform:f,transition:m,isDragging:u}=Xl(a);let p;e[2]!==f?(p=Zl.Transform.toString(f),e[2]=f,e[3]=p):p=e[3];let b;e[4]!==p||e[5]!==m?(b={transform:p,transition:m},e[4]=p,e[5]=m,e[6]=b):b=e[6];const g=u&&"opacity-60";let y;e[7]!==g?(y=ge(g),e[7]=g,e[8]=y):y=e[8];let x;e[9]!==i||e[10]!==r||e[11]!==u||e[12]!==l||e[13]!==d?(x=r({attributes:i,listeners:l,setActivatorNodeRef:d,isDragging:u}),e[9]=i,e[10]=r,e[11]=u,e[12]=l,e[13]=d,e[14]=x):x=e[14];let h;return e[15]!==c||e[16]!==b||e[17]!==y||e[18]!==x?(h=s.jsx("li",{ref:c,style:b,className:y,children:x}),e[15]=c,e[16]=b,e[17]=y,e[18]=x,e[19]=h):h=e[19],h},gj=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:a})=>{const{t:i}=pt(),[l,c]=o.useState(!1),[d,f]=o.useState(""),[m,u]=o.useState([]),[p,b]=o.useState(""),[g,y]=o.useState(null),[x,h]=o.useState(()=>new Set),[j,v]=o.useState([]),[C,k]=o.useState(null),[w,N]=o.useState(!1),[I,E]=o.useState(0),P=o.useRef(!1),T=o.useRef(""),S=_e(L=>L.todoPanelHeight),M=_e(L=>L.setTodoPanelHeight),D=_e(L=>L.notesPanelHeight),F=_e(L=>L.setNotesPanelHeight),[_,V]=o.useState(!1),$=o.useRef(0),O=o.useRef(S),B=Lt(L=>L.currentSessionId),G=Lt(L=>L.createSession),R=Lt(L=>L.initializeNewOpenChamberSession),H=Lt(L=>L.sendMessage),J=Lt(L=>L.setCurrentSession),ne=qa(L=>L.setPendingInputText),ue=Ms(L=>L.currentDirectory),de=_e(L=>L.openContextPanelTab),pe=_e(L=>L.setActiveMainTab),W=_e(L=>L.setSessionSwitcherOpen),te=_e(L=>L.padding),X=o.useCallback(async(L,U)=>{if(!t)return!1;const oe=await Eb(t,{notes:L,todos:U});return oe||K.error(i("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),oe},[t,i]);o.useEffect(()=>{if(!t){f(""),u([]),v([]),b(""),h(new Set);return}let L=!1;return c(!0),(async()=>{try{const U=await Mb(t),oe=await Promise.all(U.plans.map(Ee=>pj(Ee,i("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(L)return;f(U.notes),u($m(U.todos)),v(oe),T.current=U.notes,P.current=!0,b(""),h(new Set)}catch{L||(K.error(i("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),f(""),u([]),v([]),T.current="",P.current=!0)}finally{L||c(!1)}})(),()=>{L=!0}},[I,t,i]),o.useEffect(()=>{if(!t)return;const L=U=>{const oe=U.detail;oe?.projectId&&oe.projectId!==t.id||E(Ee=>Ee+1)};return window.addEventListener("openchamber:project-plan-saved",L),window.addEventListener("openchamber:project-notes-updated",L),()=>{window.removeEventListener("openchamber:project-plan-saved",L),window.removeEventListener("openchamber:project-notes-updated",L)}},[t]),o.useEffect(()=>{if(m.length<7)return;const L=mj(m.length,te),U=gl(te)*Cd;(S<U||S>L)&&M(L)},[m.length,te,S,M]),o.useEffect(()=>{if(!_)return;const L=oe=>{const Ee=oe.clientY-$.current,Oe=Math.min(gl(te)*ig,Math.max(gl(te)*Cd,O.current+Ee));M(Oe)},U=()=>{V(!1)};return window.addEventListener("pointermove",L),window.addEventListener("pointerup",U,{once:!0}),window.addEventListener("pointercancel",U,{once:!0}),()=>{window.removeEventListener("pointermove",L),window.removeEventListener("pointerup",U),window.removeEventListener("pointercancel",U)}},[_,te,M]);const ee=o.useCallback(L=>{V(!0),$.current=L.clientY,O.current=S,L.preventDefault()},[S]),fe=o.useCallback(()=>{T.current=d,X(d,m)},[d,X,m]);o.useEffect(()=>{if(!t||!P.current||d===T.current)return;const L=window.setTimeout(()=>{T.current=d,X(d,m)},400);return()=>{window.clearTimeout(L)}},[d,X,t,m]);const be=o.useCallback(()=>{const L=p.trim();if(!L)return;const U=_m(m,{id:fj(),text:L.slice(0,Oo),completed:!1,createdAt:Date.now()});u(U),b(""),X(d,U)},[p,d,X,m]),Ne=o.useCallback(L=>{h(U=>{const oe=new Set(U);return oe.has(L)?oe.delete(L):oe.add(L),oe})},[]),se=o.useCallback((L,U)=>{const oe=m.find(z=>z.id===L);if(!oe||oe.completed===U)return;const Ee=m.filter(z=>z.id!==L),Oe={...oe,completed:U},Ie=U?[...Ee,Oe]:_m(Ee,Oe);u(Ie),X(d,Ie)},[d,X,m]),ie=o.useCallback(L=>{const U=m.filter(oe=>oe.id!==L);u(U),X(d,U)},[d,X,m]),ae=o.useCallback(()=>{const L=m.filter(U=>!U.completed);L.length!==m.length&&(u(L),X(d,L))},[d,X,m]),xe=o.useCallback(L=>{const{active:U,over:oe}=L;if(!oe||U.id===oe.id)return;const Ee=m.findIndex(z=>z.id===U.id),Oe=m.findIndex(z=>z.id===oe.id);if(Ee===-1||Oe===-1)return;const Ie=$m(uh(m,Ee,Oe));u(Ie),X(d,Ie)},[d,X,m]),Z=mo(bi(po,{activationConstraint:{distance:8}})),me=p.slice(0,Oo),Y=m.reduce((L,U)=>L+(U.completed?1:0),0),Se=o.useCallback(()=>{pe("chat"),W(!1)},[pe,W]),we=o.useCallback((L,U)=>{!t||g||k({kind:"session",todoId:L,todoText:U})},[t,g]),ke=o.useCallback(L=>{if(!B){K.error(i("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}Se();const U=`\`\`\`md
|
|
4
|
+
${L}
|
|
5
|
+
\`\`\``;ne(U,"append"),K.success(i("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[B,r,Se,ne,i]),Fe=o.useCallback((L,U)=>{if(!(!t||g)){if(!n){K.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}k({kind:"worktree",todoId:L,todoText:U})}},[n,t,g,i]),Ce=o.useCallback(async L=>{if(!t||!C)return;const U=await Cn("plan.todo.visible",{todo_text:C.todoText}),Ee=[{synthetic:!0,text:await Cn("plan.todo.instructions",{todo_text:C.todoText})}];N(!0),y(C.todoId);try{Se();let Oe=null,Ie=t.path;if(C.kind==="worktree"){if(!n){K.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const De=await kh(t.path,Ch());if(!De?.id)return;Oe=De.id,Ie=null}else{const De=await G(void 0,t.path,null);if(!De?.id){K.error(i("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}Oe=De.id,Ie=De.directory??t.path,R(De.id,jt.getState().agents??[])}if(!Oe)return;const z=tc.getState();z.saveSessionModelSelection(Oe,L.providerID,L.modelID),L.agent.trim()&&(z.saveSessionAgentSelection(Oe,L.agent),z.saveAgentModelForSession(Oe,L.agent,L.providerID,L.modelID),z.saveAgentModelVariantForSession(Oe,L.agent,L.providerID,L.modelID,L.variant||void 0)),J(Oe,Ie),await H(U,L.providerID,L.modelID,L.agent.trim()||void 0,void 0,void 0,Ee,L.variant||void 0),K.success(C.kind==="worktree"?i("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):i("rightSidebar.contextNotesTodo.toast.sentToNewSession")),k(null),r?.()}catch(Oe){const Ie=Oe instanceof Error?Oe.message:void 0;K.error(i("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),Ie?{description:Ie}:void 0)}finally{N(!1),y(null)}},[n,G,R,r,C,t,Se,H,J,i]),Q=o.useRef(null),[ce,ve]=o.useState(!1),[le,Ae]=o.useState(null),Te=o.useCallback(async L=>{if(!(!t||le)){Ae(L);try{if(!await Rb(t,L)){K.error(i("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}v(oe=>oe.filter(Ee=>Ee.id!==L)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}}))}finally{Ae(null)}}},[le,t,i]),$e=o.useCallback(async()=>{if(!t||ce)return;const L=await Ih({defaultPath:t.path,filters:[{name:"Plan files",extensions:["md","markdown","txt"]},{name:"All files",extensions:["*"]}]});if(L.success&&L.path){ve(!0);try{const U=new URLSearchParams({path:L.path,allowOutsideWorkspace:"true"}),oe=await fetch(`/api/fs/read?${U.toString()}`,{cache:"no-store"});if(!oe.ok){K.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"));return}const Ee=await oe.text();if(!Ee.trim()){K.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const Oe=L.path.split("/").pop()?.replace(/\.(md|markdown|txt)$/i,"").trim()||"";if(!await Hu(t,Ee,Oe)){K.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),K.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(U){const oe=U instanceof Error?U.message:void 0;K.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),oe?{description:oe}:void 0)}finally{ve(!1)}}else L.error==="Native file picker not available"&&Q.current?.click()},[ce,t,i]),ye=o.useCallback(async L=>{if(!(!t||!L)){ve(!0);try{const U=await L.text();if(!U.trim()){K.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const oe=L.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await Hu(t,U,oe)){K.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),K.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(U){const oe=U instanceof Error?U.message:void 0;K.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),oe?{description:oe}:void 0)}finally{ve(!1)}}},[t,i]),q=o.useCallback(L=>{const U=t?.path?.trim(),oe=ue?.trim()||U;oe&&de(oe,{mode:"plan",targetPath:L.path,dedupeKey:L.path,label:L.title})},[ue,de,t]);return t?s.jsxs("div",{className:ge("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,"/",Gu]})]}),s.jsx(ln,{value:d,onChange:L=>f(L.target.value.slice(0,Gu)),onBlur:fe,placeholder:i("rightSidebar.contextNotesTodo.notes.placeholder"),resizedHeight:D,onResizeHeightChange:F,useScrollShadow:!0,scrollShadowSize:56,disabled:l})]}),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:ae,disabled:l||Y===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:[me.length,"/",Oo]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx($t,{value:me,onChange:L=>b(L.target.value.slice(0,Oo)),onKeyDown:L=>{L.key==="Enter"&&(L.preventDefault(),be())},placeholder:i("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:l,className:"h-8"}),s.jsx("button",{type:"button",onClick:be,disabled:l||me.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(A,{name:"add",className:"h-4 w-4"})})]}),s.jsx("div",{className:ge("overflow-y-auto rounded-lg border border-border/60 bg-background/40",_&&"transition-none"),style:m.length<7?void 0:{height:`${S}px`,maxHeight:`${S}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(fo,{sensors:Z,collisionDetection:ho,onDragEnd:xe,children:s.jsx(Al,{items:m.map(L=>L.id),strategy:fd,children:s.jsx("ul",{className:"divide-y divide-border/50",children:m.map(L=>{const U=x.has(L.id);return s.jsx(hj,{id:L.id,children:oe=>s.jsxs("div",{className:ge("flex gap-1.5 px-2.5 py-1.5",U?"items-start":"items-center"),children:[s.jsx("button",{type:"button",ref:oe.setActivatorNodeRef,...oe.attributes,...oe.listeners,onClick:Ee=>{Ee.preventDefault(),Ee.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:L.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:L.text}),children:s.jsx(A,{name:"draggable",className:"h-3.5 w-3.5"})}),s.jsx("div",{className:"flex h-6 items-center",children:s.jsx(fs,{checked:L.completed,onChange:Ee=>se(L.id,Ee),ariaLabel:i("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:L.text})})}),s.jsx("button",{type:"button",onClick:()=>Ne(L.id),className:ge("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-normal text-foreground",U?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",L.completed&&"text-muted-foreground line-through"),title:U?void 0:L.text,"aria-label":U?i("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:L.text}):i("rightSidebar.contextNotesTodo.todo.actions.expand",{text:L.text}),children:L.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>ie(L.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:L.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:L.text}),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(As,{children:[s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",disabled:g===L.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:L.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.send",{text:L.text}),children:s.jsx(A,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs(Ps,{align:"end",className:"w-56",children:[s.jsx(Ot,{onClick:()=>ke(L.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx(Ot,{onClick:()=>we(L.id,L.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx(Ot,{onClick:()=>{Fe(L.id,L.text)},disabled:!n,children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]})},L.id)})})})})}),m.length>=7&&s.jsx("div",{className:ge("h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",_&&"bg-[var(--interactive-border)]"),onPointerDown:ee,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:j.length===1?i("rightSidebar.contextNotesTodo.plans.filesSingle",{count:j.length}):i("rightSidebar.contextNotesTodo.plans.filesPlural",{count:j.length})})]}),s.jsx("input",{ref:Q,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:L=>{const U=L.target.files?.[0]??null;ye(U),L.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:$e,disabled:!t||ce,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(A,{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:j.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:j.map(L=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>q(L),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:L.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(L.createdAt).toLocaleDateString()})]}),s.jsx("button",{type:"button",onClick:()=>{Te(L.id)},disabled:le===L.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:L.title}),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},L.id))})})]}),s.jsx(ag,{open:C!==null,onOpenChange:L=>{!L&&!w&&k(null)},target:C?.kind??"session",projectDirectory:t?.path??null,submitting:w,onConfirm:Ce})]}):s.jsx("div",{className:ge("w-full min-w-0 p-3",a),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.empty.selectProject")})})},og=12,xj=[{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"}],bj=t=>{const e=ot.c(18),{isActive:n,burstKey:r,className:a,durationMs:i,bursts:l,onComplete:c}=t,d=r===void 0?0:r,f=i===void 0?900:i,m=l===void 0?xj:l,u=Ve.useRef(!1);let p,b;e[0]!==n||e[1]!==c?(p=()=>{!n&&u.current&&c?.(),n&&(u.current=!0)},b=[n,c],e[0]=n,e[1]=c,e[2]=p,e[3]=b):(p=e[2],b=e[3]),Ve.useEffect(p,b);let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=Array.from({length:og},yj),e[4]=g):g=e[4];const y=g;if(!n)return null;let x;e[5]!==a?(x=ge("fireworks-overlay pointer-events-none",a),e[5]=a,e[6]=x):x=e[6];let h;if(e[7]!==d||e[8]!==m||e[9]!==f){let v;e[11]!==d||e[12]!==f?(v=C=>{const k={"--burst-delay":`${C.delay}ms`,"--burst-x":`${C.x}%`,"--burst-y":`${C.y}%`,"--firework-color":`var(${C.colorVar})`,"--firework-duration":`${f}ms`};return s.jsx("div",{className:"firework-burst",style:k,children:y.map((w,N)=>{const I=w.x*C.radius,E=w.y*C.radius,P={"--translate-x":`${I}px`,"--translate-y":`${E}px`,"--particle-delay":`${w.delay}ms`,color:`var(${C.colorVar})`};return s.jsx("span",{className:"firework-particle",style:P},`${C.id}-${N}-${d}`)})},`${C.id}-${d}`)},e[11]=d,e[12]=f,e[13]=v):v=e[13],h=m.map(v),e[7]=d,e[8]=m,e[9]=f,e[10]=h}else h=e[10];let j;return e[14]!==d||e[15]!==x||e[16]!==h?(j=s.jsx("div",{className:x,"aria-hidden":"true","data-burst-key":d,children:h}),e[14]=d,e[15]=x,e[16]=h,e[17]=j):j=e[17],j};function yj(t,e){const n=Math.PI*2*e/og;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const vj=t=>{const e=ot.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[l,c]=Ve.useState(i),d=Ve.useRef(null);let f;e[3]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=f):f=e[3];const m=f;let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{m(),c(wj)},e[4]=u):u=e[4];const p=u;let b;e[5]!==a?(b=()=>{m(),c(jj),d.current=window.setTimeout(()=>{c(Nj),d.current=null},a)},e[5]=a,e[6]=b):b=e[6];const g=b;let y,x;e[7]===Symbol.for("react.memo_cache_sentinel")?(y=()=>()=>m(),x=[m],e[7]=y,e[8]=x):(y=e[7],x=e[8]),Ve.useEffect(y,x);let h;return e[9]!==l.cycle||e[10]!==l.isActive||e[11]!==g?(h={isActive:l.isActive,burstKey:l.cycle,triggerFireworks:g,dismissFireworks:p},e[9]=l.cycle,e[10]=l.isActive,e[11]=g,e[12]=h):h=e[12],h};function wj(t){return t.isActive?{...t,isActive:!1}:t}function jj(t){return{isActive:!0,cycle:t.cycle+1}}function Nj(t){return t.isActive?{...t,isActive:!1}:t}const lg=o.createContext(void 0),Sj=t=>{const e=ot.c(10),{children:n}=t,{isActive:r,burstKey:a,triggerFireworks:i,dismissFireworks:l}=vj();let c;e[0]!==l||e[1]!==i?(c={triggerFireworks:i,dismissFireworks:l},e[0]=l,e[1]=i,e[2]=c):c=e[2];const d=c;let f;e[3]!==a||e[4]!==r?(f=s.jsx(bj,{isActive:r,burstKey:a}),e[3]=a,e[4]=r,e[5]=f):f=e[5];let m;return e[6]!==n||e[7]!==f||e[8]!==d?(m=s.jsxs(lg.Provider,{value:d,children:[n,f]}),e[6]=n,e[7]=f,e[8]=d,e[9]=m):m=e[9],m},kj=()=>{const t=o.useContext(lg);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},tr=ar()(ei(Fi((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 Vb();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 Bb();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 _b();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=dr()?.settings;if(a)try{const l=(await a.load())?.settings||{};r=n(l.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 Cs({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 $b(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(l=>l.id===n);if(!a)throw new Error("Profile not found");const i={...a,...r};return await Ob(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 Lb(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:Co(()=>vr()),partialize:t=>({selectedProfileId:t.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=tr);function Ya(t){const e=ot.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 l;e[6]!==n?(l=ge("flex h-full w-full flex-col overflow-hidden rounded-xl",n),e[6]=n,e[7]=l):l=e[7];let c;return e[8]!==r||e[9]!==i||e[10]!==l?(c=s.jsx(ti,{"data-slot":"command",style:i,className:l,...r}),e[8]=r,e[9]=i,e[10]=l,e[11]=c):c=e[11],c}const Sa=Ve.forwardRef((t,e)=>{const n=ot.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(A,{name:"search",className:"size-4 shrink-0 opacity-50"}),n[3]=i):i=n[3];let l;n[4]!==r?(l=ge("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]=l):l=n[5];let c;return n[6]!==a||n[7]!==e||n[8]!==l?(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(ti.Input,{ref:e,"data-slot":"command-input",className:l,...a})]}),n[6]=a,n[7]=e,n[8]=l,n[9]=c):c=n[9],c});Sa.displayName="CommandInput";function Qa(t){const e=ot.c(14);let n,r,a,i,l;e[0]!==t?({className:r,children:n,scrollbarClassName:l,disableHorizontal:a,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i,e[5]=l):(n=e[1],r=e[2],a=e[3],i=e[4],l=e[5]);let c;e[6]!==r?(c=ge("scroll-py-1 overflow-x-hidden h-full min-h-0",r),e[6]=r,e[7]=c):c=e[7];const d=l??"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",f=a??!0;let m;return e[8]!==n||e[9]!==i||e[10]!==c||e[11]!==d||e[12]!==f?(m=s.jsx(vs,{as:ti.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:f,...i,children:n}),e[8]=n,e[9]=i,e[10]=c,e[11]=d,e[12]=f,e[13]=m):m=e[13],m}function Xa(t){const e=ot.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(ti.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 Vn(t){const e=ot.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=ge("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(ti.Group,{"data-slot":"command-group",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function Va(t){const e=ot.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=ge("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(ti.Separator,{"data-slot":"command-separator",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function En(t){const e=ot.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=ge("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(ti.Item,{"data-slot":"command-item",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function Cj(t){const e=ot.c(12);let n,r,a,i;if(e[0]!==t){const{className:c,...d}=t,f=Pj,m=typeof d.children=="string"?d.children:"",u=m?m.split("+").map(Ij).filter(Boolean):[];n="command-shortcut",e[5]!==c?(r=ge("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((p,b)=>s.jsxs(Ve.Fragment,{children:[b>0&&s.jsx("span",{className:"opacity-60 text-xs",children:"+"}),f(p)]},`${p}-${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 l;return e[7]!==n||e[8]!==r||e[9]!==a||e[10]!==i?(l=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]=l):l=e[11],l}function Ij(t){return t.trim()}function Pj(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(A,{name:"command",className:"size-3.5"}):e==="shift"||e==="⇧"?s.jsx(A,{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(/\/+$/,"")},Aj=t=>{const e=Id(t);if(!e)return null;const r=e.indexOf("/.git/worktrees/");return r>0&&e.slice(0,r)||null};function Dj(t,e,n){const r=ot.c(5),[a,i]=o.useState();let l,c;return r[0]!==n||r[1]!==t||r[2]!==e?(l=()=>{if(e){i(void 0);return}if(!t){i(void 0);return}i(void 0);let d=!1;return(async()=>{const[f,m]=await Promise.all([_s("git rev-parse --absolute-git-dir",t),_s("git rev-parse --show-toplevel",t)]);if(d||!f.success||!m.success)return;const u=Id((f.stdout||"").trim()),p=Aj(u);if(!p)return;const b=Id((m.stdout||"").trim());if(!b||b===p)return;const g=n||"",y=b.split("/").filter(Boolean).pop()||b;i({source:"sdk",path:b,projectDirectory:p,branch:g,label:g||y,name:y,worktreeRoot:b,worktreeStatus:"ready",headState:g?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},c=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=l,r[4]=c):(l=r[3],c=r[4]),o.useEffect(l,c),e??a}const sr=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},Ei=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),oa=t=>!!t.success,uc=t=>(t.stdout||"").trim(),Wa=t=>(t.stderr||"").trim();async function Tj(t){const n=((await _s("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 Ej(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),a=(await Tj(t.repoRoot)).filter(l=>l.branchRef===e).map(l=>l.path).filter(l=>l&&!n.has(l)),i=[];for(const l of a){const c=await _s("git status --porcelain",l);uc(c)||i.push(l)}return i}async function cg(t,e){for(const n of e)await _s("git reset --hard",n).catch(()=>{})}async function Mj(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await _s(`git show-ref --verify --quiet ${sr(`refs/heads/${n}`)}`,t);if(oa(r))return n;if(n.startsWith("remotes/")){const l=n.slice(8).split("/"),c=l[0]||"origin",d=l.slice(1).join("/");if(d)return await _s(`git branch --track ${sr(d)} ${sr(`${c}/${d}`)}`,t),d}const a=await _s(`git show-ref --verify --quiet ${sr(`refs/remotes/origin/${n}`)}`,t);return oa(a)&&await _s(`git branch --track ${sr(n)} ${sr(`origin/${n}`)}`,t),n}async function Wi(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 Mj(e,r),i=await _s(`git cherry ${sr(a)} ${sr(n)}`,e),l=Ei(i.stdout),c=new Set;for(const u of l){const p=u.match(/^\+\s+([0-9a-f]{7,40})\b/i);p&&c.add(p[1])}const d=await _s(`git rev-list --reverse ${sr(`${a}..${n}`)}`,e),m=Ei(d.stdout).filter(u=>c.has(u));return{repoRoot:e,sourceBranch:n,targetBranch:a,commits:m}}async function Rj(t,e){const n=await _s('mkdir -p "$HOME/.config/openchamber/tmp"',t);if(!oa(n))throw new Error(Wa(n)||"Failed to create temp directory parent");const r=await _s('mktemp -d "$HOME/.config/openchamber/tmp/oc-integrate-XXXXXX"',t),a=uc(r);if(!a)throw new Error(Wa(r)||"Failed to create temp directory");const i=await _s(`git worktree add --force ${sr(a)} ${sr(e)}`,t);if(!oa(i))throw new Error(Wa(i)||"Failed to create temp worktree");return a}async function _l(t,e){await _s(`git worktree remove --force ${sr(e)}`,t).catch(()=>{}),await _s("git worktree prune",t).catch(()=>{})}async function Fj(t){const e=await _s("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=uc(e);if(!n)return;await _s("git fetch",t);const r=await _s(`git merge --ff-only ${sr(n)}`,t);if(!oa(r))throw new Error(Wa(r)||"Fast-forward failed")}async function Bl(t){const e=await _s("git status --porcelain",t),n=await _s("git diff --name-only --diff-filter=U",t),r=await _s("git diff",t),a=await _s("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),i=await _s("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:Ei(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:a.stdout||a.stderr||"",currentPatch:i.stdout||i.stderr||""}}async function Lj(t){return Bl(t)}async function Oj(t){const e=await _s("git rev-parse --verify --quiet CHERRY_PICK_HEAD",t);return oa(e)}async function $j(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await Rj(t.repoRoot,t.targetBranch);let n=[];try{await Fj(e);const r=await _s("git status --porcelain",e);if(uc(r))throw new Error("Target branch has local changes; abort integration and retry");const a=await Ej({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const i=n[0],l=await _s(`git cherry-pick ${sr(i)}`,e);if(oa(l)){n.shift();continue}const c=await _s("git diff --name-only --diff-filter=U",e);if(Ei(c.stdout).length>0){const f=await Bl(e);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:e,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:a,remainingCommits:n,currentCommit:i},details:f}}throw new Error(Wa(l)||"Cherry-pick failed")}return await _l(t.repoRoot,e),await cg(t.repoRoot,a).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await _l(t.repoRoot,e).catch(()=>{}),r}}async function _j(t){await _s("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await _l(t.repoRoot,t.tempWorktreePath)}async function Bj(t){const e=await _s("git cherry-pick --continue",t.tempWorktreePath);if(!oa(e)){const i=await _s("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(Ei(i.stdout).length>0){const c=await Bl(t.tempWorktreePath);return{kind:"conflict",state:t,details:c}}throw new Error(Wa(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],l=await _s(`git cherry-pick ${sr(i)}`,n);if(oa(l)){a.shift();continue}const c=await _s("git diff --name-only --diff-filter=U",n);if(Ei(c.stdout).length>0){const f=await Bl(n);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:n,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:t.cleanTargetWorktrees,remainingCommits:a,currentCommit:i},details:f}}throw new Error(Wa(l)||"Cherry-pick failed")}return await _l(t.repoRoot,t.tempWorktreePath),await cg(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:t.remainingCommits.length}}const Vj=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:a,refreshKey:i,onRefresh:l})=>{const{t:c}=pt(),d=Lt(O=>O.currentSessionId),f=_e(O=>O.setActiveMainTab),[m,u]=Ve.useState(!1),p=Ve.useRef(null),[b,g]=Ve.useState(a);Ve.useEffect(()=>{g(a)},[a]),Ve.useEffect(()=>{if(m){const O=setTimeout(()=>{p.current?.focus()},0);return()=>clearTimeout(O)}},[m]);const y=!!(t&&e&&b&&b!=="HEAD"&&e!==b),[x,h]=Ve.useState({kind:"idle"}),[j,v]=Ve.useState(!1),[C,k]=Ve.useState([]),w=Ve.useMemo(()=>d?`openchamber.integrate.conflict:${d}`:null,[d]);Ve.useEffect(()=>{if(!w||typeof window>"u")return;const O=window.localStorage.getItem(w);if(!O)return;let B=!1;try{const G=JSON.parse(O);if(!G?.tempWorktreePath||G.repoRoot!==t){window.localStorage.removeItem(w);return}(async()=>{const R=await Oj(G.tempWorktreePath).catch(()=>!1);if(B)return;if(!R){window.localStorage.removeItem(w);return}const H=await Lj(G.tempWorktreePath).catch(()=>null);B||H&&h({kind:"conflict",state:G,details:H})})()}catch{window.localStorage.removeItem(w)}return()=>{B=!0}},[w,t]),Ve.useEffect(()=>{if(!y){h({kind:"idle"});return}let O=!1;return h({kind:"loading"}),(async()=>{try{const B=await Wi({repoRoot:t,sourceBranch:e,targetBranch:b});if(O)return;if(h({kind:"ready",plan:B}),B.commits.length>0){const H=B.commits.slice(-50).reverse().map(de=>JSON.stringify(de)).join(" "),ne=((await _s(`git show -s --format=%H%x09%h%x09%s ${H}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),ue=[];for(const de of ne){const[pe,W,te]=de.split(" ");!pe||!W||ue.push({sha:pe,short:W,subject:te||""})}O||(k(ue),v(!1))}else O||(k([]),v(!1))}catch{O||h({kind:"idle"})}})(),()=>{O=!0}},[y,t,e,b,i]);const N=Ve.useCallback(O=>{d&&Lt.getState().setWorktreeMetadata(d,{...n,createdFromBranch:O})},[d,n]),I=Lt(O=>O.openNewSessionDraft),E=Ve.useCallback(async O=>{const B=await Cn("git.integrate.cherrypick.resolve.visible",{current_commit:O.state.currentCommit,target_branch:O.state.targetBranch}),G=await Cn("git.integrate.cherrypick.resolve.instructions",{repo_root:O.state.repoRoot,temp_worktree_path:O.state.tempWorktreePath,source_branch:O.state.sourceBranch,target_branch:O.state.targetBranch,current_commit:O.state.currentCommit}),R=`Cherry-pick conflict context (JSON)
|
|
6
|
+
${JSON.stringify({repoRoot:O.state.repoRoot,tempWorktreePath:O.state.tempWorktreePath,sourceBranch:O.state.sourceBranch,targetBranch:O.state.targetBranch,currentCommit:O.state.currentCommit,remainingCommits:O.state.remainingCommits,statusPorcelain:O.details.statusPorcelain,unmergedFiles:O.details.unmergedFiles,currentPatchMeta:O.details.currentPatchMeta,currentPatch:O.details.currentPatch,diff:O.details.diff},null,2)}`;return{visibleText:B,instructionsText:G,payloadText:R}},[]),P=qa(O=>O.setPendingInputText),T=qa(O=>O.setPendingSyntheticParts),S=Ve.useCallback(async(O,B)=>{const G=await E(O);if(B){I({directoryOverride:O.state.tempWorktreePath,initialPrompt:G.visibleText,syntheticParts:[{text:G.instructionsText,synthetic:!0},{text:G.payloadText,synthetic:!0}]}),f("chat");return}if(!d){K.error(c("gitView.integrate.noActiveSession"),{description:c("gitView.integrate.noActiveSessionDescription")});return}P(G.visibleText,"replace"),T([{text:G.instructionsText,synthetic:!0},{text:G.payloadText,synthetic:!0}]),f("chat")},[d,f,E,I,P,T,c]),M=Ve.useCallback(async()=>{if(x.kind==="ready"){if(x.plan.commits.length===0){K.message(c("gitView.integrate.noCommitsToMoveToast"));return}h({kind:"running",plan:x.plan});try{const O=await $j(x.plan);if(O.kind==="success"){K.success(c("gitView.integrate.commitsMovedToast"),{description:O.moved===1?c("gitView.integrate.commitsMovedDescriptionSingle",{count:O.moved,branch:x.plan.targetBranch}):c("gitView.integrate.commitsMovedDescriptionPlural",{count:O.moved,branch:x.plan.targetBranch})});const B=await Wi(x.plan);h({kind:"ready",plan:B}),l?.();return}O.kind==="conflict"&&(K.error(c("gitView.integrate.cherryPickConflictToast"),{description:c("gitView.integrate.cherryPickConflictDescription")}),h({kind:"conflict",state:O.state,details:O.details}),w&&typeof window<"u"&&window.localStorage.setItem(w,JSON.stringify(O.state)))}catch(O){const B=O instanceof Error?O.message:String(O);K.error(c("gitView.integrate.failedToMoveToast"),{description:B});const G=await Wi({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);h(G?{kind:"ready",plan:G}:{kind:"idle"})}}},[x,l,t,e,b,w,c]),D=Ve.useCallback(async()=>{if(x.kind==="conflict")try{await _j(x.state),K.message(c("gitView.integrate.cherryPickAbortedToast")),w&&typeof window<"u"&&window.localStorage.removeItem(w)}finally{const O=await Wi({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);h(O?{kind:"ready",plan:O}:{kind:"idle"})}},[x,t,e,b,w,c]),F=Ve.useCallback(async()=>{if(x.kind==="conflict")try{const O=await Bj(x.state);if(O.kind==="success"){K.success(c("gitView.integrate.cherryPickFinishedToast"));const B=await Wi({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);h(B?{kind:"ready",plan:B}:{kind:"idle"}),w&&typeof window<"u"&&window.localStorage.removeItem(w),l?.();return}O.kind==="conflict"&&(h({kind:"conflict",state:O.state,details:O.details}),w&&typeof window<"u"&&window.localStorage.setItem(w,JSON.stringify(O.state)))}catch(O){const B=O instanceof Error?O.message:String(O);K.error(c("gitView.integrate.cherryPickContinueFailedToast"),{description:B})}},[x,t,e,b,l,w,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(A,{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(A,{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(As,{open:m,onOpenChange:u,children:[s.jsx(Is,{asChild:!0,children:s.jsxs(he,{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(A,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),s.jsx(Ps,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(Ya,{className:"h-full min-h-0",children:[s.jsx(Sa,{ref:p,placeholder:c("gitView.branch.searchPlaceholder"),onKeyDown:O=>O.stopPropagation()}),s.jsxs(Qa,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(Xa,{children:c("gitView.branch.empty")}),s.jsx(Vn,{heading:c("gitView.branch.localBranches"),children:r.map(O=>s.jsx(En,{value:O,onSelect:()=>{g(O),N(O),u(!1)},children:O},O))})]})]})})]}),x.kind==="ready"?s.jsx(he,{size:"sm",onClick:()=>{M()},disabled:!y||x.plan.commits.length===0,children:c("gitView.integrate.move")}):x.kind==="loading"?s.jsx(he,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.checking")}):x.kind==="running"?s.jsx(he,{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,")"]})]}),C.length>0&&x.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>v(O=>!O),className:"typography-micro text-muted-foreground hover:text-foreground",children:c(j?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),s.jsxs("div",{className:"space-y-1",children:[(j?C:C.slice(0,5)).map(O=>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:O.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:O.subject||O.sha})]},O.sha)),C.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.previewUnavailable")}),x.plan.commits.length>C.length&&s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c("gitView.integrate.showingFirstCommits",{count:C.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(O=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:O},O)),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(he,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{D()},children:c("gitView.operation.abort")}),s.jsxs(he,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!d,onClick:()=>{S({state:x.state,details:x.details},!1)},children:[s.jsx(A,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.currentSession")]}),s.jsxs(he,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{S({state:x.state,details:x.details},!0)},children:[s.jsx(A,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.newSession")]}),s.jsx(he,{size:"sm",className:"typography-meta",onClick:()=>{F()},children:c("gitView.operation.continue")})]})]})]})]})},zj=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Uj=({currentBranch:t,localBranches:e,remoteBranches:n,branchInfo:r,onCheckout:a,onCreate:i,remotes:l=[],disabled:c=!1})=>{const{t:d}=pt(),[f,m]=o.useState(!1),[u,p]=o.useState(""),[b,g]=o.useState(!1),[y,x]=o.useState(!1),[h,j]=o.useState(""),[v,C]=o.useState(!1),k=o.useRef(null),w=o.useCallback(V=>{V.stopPropagation()},[]),N=l.length>1,I=o.useMemo(()=>zj(h),[h]),E=o.useMemo(()=>{const V=u.toLowerCase();return V?e.filter($=>$.toLowerCase().includes(V)):e},[u,e]),P=o.useMemo(()=>{const V=u.toLowerCase();return V?n.filter($=>$.toLowerCase().includes(V)):n},[u,n]),T=V=>{if(V===t){m(!1);return}a(V),m(!1),p("")},S=()=>{g(!0),setTimeout(()=>k.current?.focus(),50)},M=async()=>{if(!(!I||v)){if(N){x(!0);return}C(!0);try{await i(I,l[0]),j(""),g(!1),m(!1)}finally{C(!1)}}},D=async V=>{if(!(!I||v)){C(!0);try{await i(I,V),j(""),g(!1),x(!1),m(!1)}finally{C(!1)}}},F=()=>{x(!1)},_=()=>{j(""),g(!1),x(!1)};return o.useEffect(()=>{f||(p(""),g(!1),x(!1),j(""))},[f]),s.jsxs(As,{open:f,onOpenChange:m,children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsxs(he,{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(A,{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(A,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),s.jsx(At,{sideOffset:8,children:d("gitView.branch.currentBranchTooltip")})]}),s.jsx(Ps,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:s.jsxs(Ya,{className:"h-full min-h-0",children:[s.jsx(Sa,{placeholder:d("gitView.branch.searchPlaceholder"),value:u,onValueChange:p,onKeyDown:w}),s.jsxs(Qa,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(Xa,{children:d("gitView.branch.empty")}),s.jsx(Vn,{children:y?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:F,disabled:v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(A,{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:I})," ",d("gitView.branch.pushToSuffix")]})]}),s.jsx("div",{className:"flex flex-col gap-1",children:l.map(V=>s.jsxs("button",{type:"button",onClick:()=>D(V),disabled:v,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:[v?s.jsx(A,{name:"loader-4",className:"inline size-3 mr-1.5 animate-spin"}):null,V.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:V.pushUrl})]},V.name))})]}):b?s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[s.jsx("input",{ref:k,placeholder:d("gitView.branch.newBranchPlaceholder"),value:h,onChange:V=>j(V.target.value),onClick:V=>V.stopPropagation(),onKeyDown:V=>{w(V),V.key==="Enter"?(V.preventDefault(),M()):V.key==="Escape"&&(V.preventDefault(),_())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"button",onClick:M,disabled:!I||v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:v?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"add",className:"size-4"})}),s.jsx("button",{type:"button",onClick:_,disabled:v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(A,{name:"close",className:"size-4"})})]}):s.jsxs(En,{onSelect:S,children:[s.jsx(A,{name:"add",className:"size-4"}),s.jsx("span",{children:d("gitView.branch.create")})]})}),s.jsx(Va,{}),s.jsxs(Vn,{heading:d("gitView.branch.localBranches"),children:[E.map(V=>s.jsxs(En,{onSelect:()=>T(V),children:[s.jsxs("span",{className:"flex flex-1 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:V}),(r?.[V]?.ahead||r?.[V]?.behind)&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[r[V].ahead||0," ahead ·"," ",r[V].behind||0," behind"]})]}),t===V&&s.jsx("span",{className:"typography-micro text-primary",children:d("gitView.branch.currentBadge")})]},`local-${V}`)),E.length===0&&s.jsx(En,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noLocalBranches")})})]}),s.jsx(Va,{}),s.jsxs(Vn,{heading:d("gitView.branch.remoteBranches"),children:[P.map(V=>s.jsx(En,{onSelect:()=>T(V),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:V})},`remote-${V}`)),P.length===0&&s.jsx(En,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noRemoteBranches")})})]})]})]})})]})},Wj=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Kj=({currentBranch:t,onRename:e,showEditButton:n=!0})=>{const{t:r}=pt(),[a,i]=o.useState(!1),[l,c]=o.useState(t||""),[d,f]=o.useState(!1),m=o.useRef(null),u=()=>{!t||!e||(c(t),i(!0),setTimeout(()=>m.current?.focus(),0))},p=async()=>{if(!t||!e||!l.trim())return;const y=Wj(l);if(y===t){i(!1);return}f(!0);try{await e(t,y),i(!1),c("")}finally{f(!1)}},b=()=>{i(!1),c("")},g=y=>{y.key==="Enter"?(y.preventDefault(),p()):y.key==="Escape"&&(y.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:y=>{y.preventDefault(),p()},children:[s.jsx(A,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("input",{ref:m,value:l,onChange:y=>c(y.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:g,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(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{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(A,{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(A,{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(he,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:u,title:r("gitView.branch.renameTitle"),children:s.jsx(A,{name:"edit",className:"size-4"})})]})]})},Hj=t=>{const e=ot.c(41),{syncAction:n,remotes:r,onFetch:a,onSync:i,onRemoveRemote:l,disabled:c,removingRemoteName:d,aheadCount:f,behindCount:m,trackingRemoteName:u,hasUncommittedChanges:p}=t,b=r===void 0?[]:r,g=d===void 0?null:d,y=f===void 0?0:f,x=m===void 0?0:m,h=p===void 0?!1:p,{t:j}=pt(),v=o.useRef(!1),C=!!g,k=b.find(ae=>ae.name===u)??b[0],w=x>0&&h,N=c||n!==null||C||!k||w,I=c||n!==null||C||b.length===0,E=y>0||x>0;let P;e[0]!==j?(P=j("gitView.sync.sync"),e[0]=j,e[1]=P):P=e[1];const T=x>0?`↓${x}`:null,S=y>0?`↑${y}`:null;let M;e[2]!==P||e[3]!==T||e[4]!==S?(M=[P,T,S].filter(Boolean),e[2]=P,e[3]=T,e[4]=S,e[5]=M):M=e[5];const D=M.join(" "),F=w?j("gitView.sync.commitOrStashTooltip"):k?E?j("gitView.sync.syncChangesTooltip",{ahead:y,behind:x}):j("gitView.sync.syncChanges"):j("gitView.sync.noRemoteTooltip"),_=()=>{k&&i(k)},V="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 $;e[6]===Symbol.for("react.memo_cache_sentinel")?($=ge("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]=$):$=e[6];let O;e[7]!==j?(O=j("gitView.sync.syncChanges"),e[7]=j,e[8]=O):O=e[8];let B;e[9]!==n?(B=n==="sync"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=B):B=e[10];let G;e[11]!==D?(G=s.jsx("span",{className:"whitespace-nowrap tabular-nums",children:D}),e[11]=D,e[12]=G):G=e[12];let R;e[13]!==_||e[14]!==N||e[15]!==O||e[16]!==B||e[17]!==G?(R=s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:_,disabled:N,className:$,"aria-label":O,children:[B,G]})}),e[13]=_,e[14]=N,e[15]=O,e[16]=B,e[17]=G,e[18]=R):R=e[18];let H;e[19]!==F?(H=s.jsx(At,{sideOffset:8,children:F}),e[19]=F,e[20]=H):H=e[20];let J;e[21]!==R||e[22]!==H?(J=s.jsxs(It,{children:[R,H]}),e[21]=R,e[22]=H,e[23]=J):J=e[23];const ne=As;let ue;e[24]===Symbol.for("react.memo_cache_sentinel")?(ue=ge("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]=ue):ue=e[24];let de;e[25]!==j?(de=j("gitView.sync.moreActionsAria"),e[25]=j,e[26]=de):de=e[26];let pe;e[27]===Symbol.for("react.memo_cache_sentinel")?(pe=s.jsx(A,{name:"arrow-down-s",className:"size-4"}),e[27]=pe):pe=e[27];let W;e[28]!==I||e[29]!==de?(W=s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:ue,disabled:I,"aria-label":de,children:pe})}),e[28]=I,e[29]=de,e[30]=W):W=e[30];const te=Ps,X="start",ee=-40,fe="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",be=b.map(ae=>s.jsx(Ot,{onSelect:xe=>{if(v.current){xe.preventDefault(),v.current=!1;return}a(ae)},children:s.jsxs("div",{className:"flex w-full items-center gap-2",children:[s.jsx(A,{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:j("gitView.sync.fetchFromRemote",{name:ae.name})}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:ae.fetchUrl})]})}),l&&ae.name!==u?s.jsx(he,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||C,onPointerDown:xe=>{v.current=!0,xe.preventDefault(),xe.stopPropagation()},onClick:xe=>{v.current=!0,xe.preventDefault(),xe.stopPropagation(),l(ae)},"aria-label":j("gitView.header.removeRemoteAria",{name:ae.name}),title:j("gitView.header.removeRemoteTitle",{name:ae.name}),children:g===ae.name?s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(A,{name:"close",className:"size-3.5"})}):null]})},ae.name));let Ne;e[31]!==te||e[32]!==be?(Ne=s.jsx(te,{align:X,alignOffset:ee,className:fe,children:be}),e[31]=te,e[32]=be,e[33]=Ne):Ne=e[33];let se;e[34]!==ne||e[35]!==W||e[36]!==Ne?(se=s.jsxs(ne,{children:[W,Ne]}),e[34]=ne,e[35]=W,e[36]=Ne,e[37]=se):se=e[37];let ie;return e[38]!==J||e[39]!==se?(ie=s.jsxs("div",{className:V,children:[J,se]}),e[38]=J,e[39]=se,e[40]=ie):ie=e[40],ie},Gj={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},qj={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 dg(t){return t&&qj[t]||"var(--primary)"}const Bm=t=>{const e=ot.c(8),{icon:n,className:r,colorToken:a}=t,i=Gj[n??"branch"]??"user-3";let l;e[0]!==a?(l=dg(a),e[0]=a,e[1]=l):l=e[1];let c;e[2]!==l?(c={color:l},e[2]=l,e[3]=c):c=e[3];let d;return e[4]!==r||e[5]!==i||e[6]!==c?(d=s.jsx(A,{name:i,className:r,style:c}),e[4]=r,e[5]=i,e[6]=c,e[7]=d):d=e[7],d},ug=t=>{const e=ot.c(35),{activeProfile:n,identities:r,onSelect:a,isApplying:i,iconOnly:l}=t,c=l===void 0?!1:l,{t:d}=pt(),f=i||r.length===0,m=n?.color;let u;e[0]!==m?(u=dg(m),e[0]=m,e[1]=u):u=e[1];let p;e[2]!==u?(p={color:u},e[2]=u,e[3]=p):p=e[3];let b;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==i?(b=i?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(Bm,{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 g;e[8]!==n?.name||e[9]!==c||e[10]!==d?(g=!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]=g):g=e[11];let y;e[12]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=y):y=e[12];let x;e[13]!==f||e[14]!==p||e[15]!==b||e[16]!==g?(x=s.jsx(Pt,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsxs(he,{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:p,disabled:f,children:[b,g,y]})})}),e[13]=f,e[14]=p,e[15]=b,e[16]=g,e[17]=x):x=e[17];let h;e[18]!==d?(h=d("gitView.header.identityTooltip"),e[18]=d,e[19]=h):h=e[19];let j;e[20]!==h?(j=s.jsx(At,{sideOffset:8,children:h}),e[20]=h,e[21]=j):j=e[21];let v;e[22]!==j||e[23]!==x?(v=s.jsxs(It,{children:[x,j]}),e[22]=j,e[23]=x,e[24]=v):v=e[24];let C;e[25]!==n?.id||e[26]!==r||e[27]!==a||e[28]!==d?(C=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(N=>{const I=n?.id===N.id;return s.jsx(Ot,{onSelect:()=>a(N),children:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(Bm,{icon:N.icon,colorToken:N.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:N.name}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:N.userEmail})]}),I?s.jsx(A,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},N.id)}),e[25]=n?.id,e[26]=r,e[27]=a,e[28]=d,e[29]=C):C=e[29];let k;e[30]!==C?(k=s.jsx(Ps,{align:"end",className:"w-64",children:C}),e[30]=C,e[31]=k):k=e[31];let w;return e[32]!==v||e[33]!==k?(w=s.jsxs(As,{children:[v,k]}),e[32]=v,e[33]=k,e[34]=w):w=e[34],w},Jj=t=>{const e=ot.c(21),{comparison:n,trackingBranch:r,tooltipDelayMs:a}=t,i=a===void 0?1e3:a,{t:l}=pt(),c=`${n.remote}/${n.branch}`,d=n.ahead===0&&n.behind===0;let f;e[0]!==l||e[1]!==c||e[2]!==r?(f=r?l("gitView.header.upstreamTooltipTracking",{target:c,tracking:r}):l("gitView.header.upstreamTooltip",{target:c}),e[0]=l,e[1]=c,e[2]=r,e[3]=f):f=e[3];const m=f;let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(A,{name:"git-branch",className:"size-3.5 shrink-0"}),e[4]=u):u=e[4];let p;e[5]!==c?(p=s.jsx("span",{className:"min-w-0 truncate text-foreground/80",children:c}),e[5]=c,e[6]=p):p=e[6];let b;e[7]!==n.ahead||e[8]!==n.behind||e[9]!==d||e[10]!==l?(b=d?s.jsx("span",{className:"tabular-nums text-muted-foreground",children:l("gitView.header.upstreamSynced")}):s.jsxs("span",{className:"inline-flex items-center gap-1 tabular-nums",children:[n.ahead>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["↑",n.ahead]}):null,n.behind>0?s.jsxs("span",{className:"text-[var(--status-warning)]",children:["↓",n.behind]}):null]}),e[7]=n.ahead,e[8]=n.behind,e[9]=d,e[10]=l,e[11]=b):b=e[11];let g;e[12]!==p||e[13]!==b?(g=s.jsx(Pt,{asChild:!0,children:s.jsxs("div",{className:"inline-flex h-8 max-w-full items-center gap-1.5 rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2 typography-micro text-muted-foreground",children:[u,p,b]})}),e[12]=p,e[13]=b,e[14]=g):g=e[14];let y;e[15]!==m?(y=s.jsx(At,{sideOffset:8,children:m}),e[15]=m,e[16]=y):y=e[16];let x;return e[17]!==g||e[18]!==y||e[19]!==i?(x=s.jsxs(It,{delayDuration:i,children:[g,y]}),e[17]=g,e[18]=y,e[19]=i,e[20]=x):x=e[20],x},Yj=t=>{const e=ot.c(54),{status:n,localBranches:r,remoteBranches:a,branchInfo:i,syncAction:l,remotes:c,onFetch:d,onSync:f,onRemoveRemote:m,removingRemoteName:u,onCheckoutBranch:p,onCreateBranch:b,onRenameBranch:g,activeIdentityProfile:y,availableIdentities:x,onSelectIdentity:h,isApplyingIdentity:j,isWorktreeMode:v,onOpenHistory:C,onOpenGraph:k,onOpenStashes:w,actionTabItems:N,activeActionTab:I,onSelectActionTab:E}=t,{t:P}=pt();if(!n)return null;let T;e[0]!==k||e[1]!==C||e[2]!==w||e[3]!==P?(T=C||k||w?s.jsxs(As,{children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsx(he,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0","aria-label":P("gitView.header.repositoryViews"),children:s.jsx(A,{name:"git-repository",className:"size-4"})})})}),s.jsx(At,{sideOffset:8,children:P("gitView.header.repositoryViews")})]}),s.jsxs(Ps,{align:"end",children:[C?s.jsxs(Ot,{onSelect:C,children:[s.jsx(A,{name:"history",className:"size-4"}),P("gitView.history.title")]}):null,k?s.jsxs(Ot,{onSelect:k,children:[s.jsx(A,{name:"git-merge",className:"size-4"}),P("gitView.graph.title")]}):null,w?s.jsxs(Ot,{onSelect:w,children:[s.jsx(A,{name:"archive-stack",className:"size-4"}),P("gitView.stashes.title")]}):null]})]}):null,e[0]=k,e[1]=C,e[2]=w,e[3]=P,e[4]=T):T=e[4];let S;e[5]!==T?(S=s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:T}),e[5]=T,e[6]=S):S=e[6];const M=S,D=!n;let F;e[7]!==n.tracking?(F=n.tracking?.split("/")[0],e[7]=n.tracking,e[8]=F):F=e[8];const _=(n.files?.length??0)>0;let V;e[9]!==d||e[10]!==m||e[11]!==f||e[12]!==c||e[13]!==u||e[14]!==n.ahead||e[15]!==n.behind||e[16]!==l||e[17]!==D||e[18]!==F||e[19]!==_?(V=s.jsx(Hj,{syncAction:l,remotes:c,onFetch:d,onSync:f,onRemoveRemote:m,removingRemoteName:u,disabled:D,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:F,hasUncommittedChanges:_}),e[9]=d,e[10]=m,e[11]=f,e[12]=c,e[13]=u,e[14]=n.ahead,e[15]=n.behind,e[16]=l,e[17]=D,e[18]=F,e[19]=_,e[20]=V):V=e[20];const $=V;let O;e[21]!==n.tracking||e[22]!==n.upstreamComparison?(O=n.upstreamComparison?s.jsx(Jj,{comparison:n.upstreamComparison,trackingBranch:n.tracking,tooltipDelayMs:1e3}):null,e[21]=n.tracking,e[22]=n.upstreamComparison,e[23]=O):O=e[23];const B=O;let G;e[24]!==y||e[25]!==x||e[26]!==j||e[27]!==h?(G=s.jsx(ug,{activeProfile:y,identities:x,onSelect:h,isApplying:j,iconOnly:!0}),e[24]=y,e[25]=x,e[26]=j,e[27]=h,e[28]=G):G=e[28];const R=G;let H;e[29]!==i||e[30]!==v||e[31]!==r||e[32]!==p||e[33]!==b||e[34]!==g||e[35]!==a||e[36]!==c||e[37]!==n.current?(H=s.jsx("div",{className:"min-w-0 flex-1",children:v?s.jsx(Kj,{currentBranch:n.current,onRename:g}):s.jsx(Uj,{currentBranch:n.current,localBranches:r,remoteBranches:a,branchInfo:i,onCheckout:p,onCreate:b,remotes:c})}),e[29]=i,e[30]=v,e[31]=r,e[32]=p,e[33]=b,e[34]=g,e[35]=a,e[36]=c,e[37]=n.current,e[38]=H):H=e[38];let J;e[39]!==R||e[40]!==M?(J=s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[M,R]}),e[39]=R,e[40]=M,e[41]=J):J=e[41];let ne;e[42]!==J||e[43]!==H?(ne=s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[H,J]}),e[42]=J,e[43]=H,e[44]=ne):ne=e[44];let ue;e[45]!==N||e[46]!==I||e[47]!==E||e[48]!==$||e[49]!==B?(ue=N&&I&&E?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(Fr,{items:N,activeId:I,onSelect:E,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),B?s.jsx("div",{className:"min-w-0 shrink",children:B}):null,s.jsx("div",{className:"shrink-0",children:$})]}):null,e[45]=N,e[46]=I,e[47]=E,e[48]=$,e[49]=B,e[50]=ue):ue=e[50];let de;return e[51]!==ne||e[52]!==ue?(de=s.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[ne,ue]}),e[51]=ne,e[52]=ue,e[53]=de):de=e[53],de},Qj=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,hasStagedChanges:a=!1,uncommittedFileCount:i,onChanged:l})=>{const{t:c}=pt(),[d,f]=o.useState([]),[m,u]=o.useState(!1),[p,b]=o.useState(""),[g,y]=o.useState(""),[x,h]=o.useState(null),[j,v]=o.useState({}),C=o.useCallback(async()=>{if(n){u(!0);try{const P=await zb(n);f(P.stashes),v({})}catch(P){K.error(P instanceof Error?P.message:c("gitView.stashes.toast.loadFailed"))}finally{u(!1)}}},[n,c]);o.useEffect(()=>{t&&C()},[C,t]),o.useEffect(()=>{if(!t||!n||d.length===0)return;let P=!1;const T=d.map(S=>S.ref);return Ub(n,T).then(S=>{P||v(S.counts)}).catch(()=>{}),()=>{P=!0}},[n,t,d]);const k=o.useMemo(()=>{const P=p.trim().toLowerCase();return P?d.filter(T=>`${T.ref} ${T.message} ${T.relativeTime}`.toLowerCase().includes(P)):d},[p,d]),w=o.useCallback(async P=>{await C(),await l?.(P)},[C,l]),N=async()=>{if(!(!n||x)){h("create");try{const P=await Wb(n,{message:g.trim()||void 0});P.created?(K.success(c("gitView.stashes.toast.created")),y("")):K.info(c("gitView.stashes.toast.noChanges")),await w({affectsIndex:!!(P.created&&a)})}catch(P){K.error(P instanceof Error?P.message:c("gitView.stashes.toast.createFailed"))}finally{h(null)}}},I=async(P,T)=>{if(!(!n||x)&&!(T==="drop"&&!window.confirm(c("gitView.stashes.confirm.drop",{ref:P.ref})))){h(`${T}:${P.ref}`);try{T==="apply"&&await Kb(n,{ref:P.ref}),T==="pop"&&await Hb(n,{ref:P.ref}),T==="drop"&&await Gb(n,{ref:P.ref});const S=T==="apply"?"gitView.stashes.toast.applySuccess":T==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";K.success(c(S)),await w({affectsIndex:T!=="drop"})}catch(S){const M=T==="apply"?"gitView.stashes.toast.applyFailed":T==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";K.error(S instanceof Error?S.message:c(M)),await w({affectsIndex:T!=="drop"})}finally{h(null)}}},E=x!==null;return s.jsx(ls,{open:t,onOpenChange:e,children:s.jsxs(os,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(ps,{children:[s.jsxs(ds,{className:"flex items-center gap-2",children:[s.jsx(A,{name:"archive-stack",className:"h-5 w-5"}),c("gitView.stashes.title")]}),s.jsx(ys,{children:c("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($t,{value:g,onChange:P=>y(P.target.value),placeholder:c("gitView.stashes.messagePlaceholder"),disabled:E||!r,className:"flex-1"}),s.jsxs(he,{onClick:N,disabled:!r||E||!n,children:[x==="create"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"inbox-archive",className:"size-4"}),c("gitView.stashes.actions.stashCurrentWithCount",{count:i})]})]}),s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:c("gitView.stashes.includeUntrackedHint")})]}),s.jsxs("div",{className:"relative mt-2",children:[s.jsx(A,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx($t,{value:p,onChange:P=>b(P.target.value),placeholder:c("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:m?s.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:s.jsx(A,{name:"loader-4",className:"size-5 animate-spin"})}):k.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:c(p?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):k.map((P,T)=>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:P.message||c("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:T===0&&!p.trim()?c("gitView.stashes.latestLabel"):c("gitView.stashes.itemNumber",{number:T+1})})}),s.jsx(At,{sideOffset:6,children:P.ref})]})," · ",P.relativeTime," · ",typeof j[P.ref]=="number"?c("gitView.stashes.fileCount",{count:j[P.ref]}):c("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(Mc,{label:c("gitView.stashes.actions.apply"),loading:x===`apply:${P.ref}`,onClick:()=>I(P,"apply"),disabled:E,children:s.jsx(A,{name:"inbox-unarchive",className:"size-4"})}),s.jsx(Mc,{label:c("gitView.stashes.actions.pop"),loading:x===`pop:${P.ref}`,onClick:()=>I(P,"pop"),disabled:E,children:s.jsx(A,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx(Mc,{label:c("gitView.stashes.actions.drop"),loading:x===`drop:${P.ref}`,onClick:()=>I(P,"drop"),disabled:E,destructive:!0,children:s.jsx(A,{name:"delete-bin",className:"size-4"})})]})]},P.ref))})]})})},Mc=t=>{const e=ot.c(17),{label:n,loading:r,disabled:a,destructive:i,onClick:l,children:c}=t,d=r||void 0,f=i?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let m;e[0]!==f?(m=ge("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",f),e[0]=f,e[1]=m):m=e[1];let u;e[2]!==c||e[3]!==r?(u=r?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):c,e[2]=c,e[3]=r,e[4]=u):u=e[4];let p;e[5]!==a||e[6]!==n||e[7]!==l||e[8]!==d||e[9]!==m||e[10]!==u?(p=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":n,"aria-busy":d,className:m,onClick:l,disabled:a,children:u})}),e[5]=a,e[6]=n,e[7]=l,e[8]=d,e[9]=m,e[10]=u,e[11]=p):p=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 g;return e[14]!==p||e[15]!==b?(g=s.jsxs(It,{children:[p,b]}),e[14]=p,e[15]=b,e[16]=g):g=e[16],g},mg={"?":{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"}},Xj=mg.M;function Zj(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 e0(t){const e=Zj(t);return mg[e]??Xj}const t0=o.memo(function(e){const n=ot.c(58),{file:r,actionLabel:a,actionSymbol:i,onAction:l,onViewDiff:c,onRevert:d,isReverting:f,stats:m,rowPaddingClassName:u,indentPx:p,actionAtStart:b,showRevert:g}=e,y=p===void 0?0:p,x=b===void 0?!1:b,h=g===void 0?!0:g;let j;n[0]!==r?(j=e0(r),n[0]=r,n[1]=j):j=n[1];const v=j,{t:C}=pt(),k=v.description,w=m?.insertions??0,N=m?.deletions??0;let I;n[2]!==l||n[3]!==c?(I=ee=>{ee.key===" "?(ee.preventDefault(),l()):ee.key==="Enter"&&(ee.preventDefault(),c())},n[2]=l,n[3]=c,n[4]=I):I=n[4];const E=I;let P;n[5]!==l?(P=ee=>{ee.preventDefault(),ee.stopPropagation(),l()},n[5]=l,n[6]=P):P=n[6];const T=P;let S;n[7]!==d?(S=ee=>{ee.preventDefault(),ee.stopPropagation(),d()},n[7]=d,n[8]=S):S=n[8];const M=S;let D;n[9]!==a||n[10]!==i||n[11]!==T?(D=s.jsx("button",{type:"button",onClick:T,className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":a,title:a,children:i}),n[9]=a,n[10]=i,n[11]=T,n[12]=D):D=n[12];const F=D,_=`group flex items-center gap-2 py-1.5 hover:bg-sidebar/40 cursor-pointer ${u??"px-3"}`;let V;n[13]!==y?(V=y>0?{paddingLeft:`${y}px`}:void 0,n[13]=y,n[14]=V):V=n[14];const $=x?F:null;let O;n[15]!==v.color?(O={color:v.color},n[15]=v.color,n[16]=O):O=n[16];let B;n[17]!==v.code||n[18]!==k||n[19]!==O?(B=s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:O,title:k,"aria-label":k,children:v.code}),n[17]=v.code,n[18]=k,n[19]=O,n[20]=B):B=n[20];let G;n[21]!==r.path?(G=s.jsx(Er,{filePath:r.path,className:"h-3.5 w-3.5 shrink-0"}),n[21]=r.path,n[22]=G):G=n[22];let R;if(n[23]!==r.path){e:{const ee=r.path.lastIndexOf("/");if(ee===-1){let xe;n[25]===Symbol.for("react.memo_cache_sentinel")?(xe={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[25]=xe):xe=n[25],R=s.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:xe,title:r.path,children:r.path});break e}const fe=r.path.slice(0,ee),be=r.path.slice(ee);let Ne;n[26]===Symbol.for("react.memo_cache_sentinel")?(Ne={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[26]=Ne):Ne=n[26];let se;n[27]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsx("span",{className:"text-muted-foreground",children:"/"}),n[27]=se):se=n[27];const ie=s.jsx("span",{className:"text-foreground",children:be.slice(1)});let ae;n[28]!==ie?(ae=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[se,ie]}),n[28]=ie,n[29]=ae):ae=n[29],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:Ne,children:fe}),ae]})}n[23]=r.path,n[24]=R}else R=n[24];let H;n[30]===Symbol.for("react.memo_cache_sentinel")?(H={color:"var(--status-success)"},n[30]=H):H=n[30];let J;n[31]!==w?(J=s.jsxs("span",{style:H,children:["+",w]}),n[31]=w,n[32]=J):J=n[32];let ne,ue;n[33]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),ue={color:"var(--status-error)"},n[33]=ne,n[34]=ue):(ne=n[33],ue=n[34]);let de;n[35]!==N?(de=s.jsxs("span",{style:ue,children:["-",N]}),n[35]=N,n[36]=de):de=n[36];let pe;n[37]!==J||n[38]!==de?(pe=s.jsxs("span",{className:"shrink-0 typography-micro",children:[J,ne,de]}),n[37]=J,n[38]=de,n[39]=pe):pe=n[39];let W;n[40]!==r.path||n[41]!==M||n[42]!==f||n[43]!==h||n[44]!==C?(W=h?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:M,disabled:f,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":C("gitView.changes.revertFileAria",{path:r.path}),children:f?s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(A,{name:"arrow-go-back",className:"size-3.5"})})}),s.jsx(At,{sideOffset:8,children:C("gitView.changes.revertFileTooltip")})]}):null,n[40]=r.path,n[41]=M,n[42]=f,n[43]=h,n[44]=C,n[45]=W):W=n[45];const te=x?null:F;let X;return n[46]!==E||n[47]!==c||n[48]!==V||n[49]!==$||n[50]!==B||n[51]!==G||n[52]!==R||n[53]!==pe||n[54]!==W||n[55]!==te||n[56]!==_?(X=s.jsxs("div",{className:_,role:"button",tabIndex:0,onClick:c,onKeyDown:E,style:V,children:[$,B,G,R,pe,W,te]}),n[46]=E,n[47]=c,n[48]=V,n[49]=$,n[50]=B,n[51]=G,n[52]=R,n[53]=pe,n[54]=W,n[55]=te,n[56]=_,n[57]=X):X=n[57],X}),Vm=14,pg=t=>t.replace(/\\/g,"/").replace(/^\/+/,"").trim(),zm=(t,e)=>({id:`dir:${t}`,path:t,name:e,children:new Map,directFiles:[],files:[]}),s0=t=>{const e=zm("","");for(const n of t){const r=pg(n.path);if(!r)continue;const i=r.split("/").filter(Boolean).slice(0,-1);let l=e;if(l.files.push(n),i.length>0){let c="";for(const d of i){c=c?`${c}/${d}`:d;const f=l.children.get(d);if(f){f.files.push(n),l=f;continue}const m=zm(c,d);m.files.push(n),l.children.set(d,m),l=m}}l.directFiles.push(n)}return e},n0=(t,e)=>{const n=[],r=(a,i)=>{const l=Array.from(a.children.values()).sort((d,f)=>d.path.localeCompare(f.path));for(const d of l)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,f)=>d.path.localeCompare(f.path));for(const d of c)n.push({key:`file:${pg(d.path)}`,kind:"file",depth:i,file:d})};return r(t,0),n},r0=1e3,a0=34,i0=30,zo="pl-0 pr-2",Rc=(t,e)=>`${t} ${e}`,o0=({groups:t,diffStats:e,revertingPaths:n,isRevertingAll:r=!1,onVisiblePathsChange:a,onRevertAll:i})=>{const{t:l}=pt(),c=o.useRef(null),f=_e($=>$.gitChangesViewMode)==="tree",m=o.useMemo(()=>t.filter($=>$.entries.length>0),[t]),[u,p]=o.useState(new Set),[b,g]=o.useState(new Set),[y,x]=o.useState(!1),h=o.useMemo(()=>m.map($=>s0($.entries)),[m]),j=o.useMemo(()=>{const $=[];return m.forEach((O,B)=>{Array.from(h[B]?.children.values()??[]).forEach(G=>{$.push(Rc(O.id,G.path))})}),$},[h,m]);o.useEffect(()=>{f&&g($=>{const O=new Set,B=new Set(j);return $.forEach(G=>{(G.slice(G.indexOf(" ")+1).includes("/")||B.has(G))&&O.add(G)}),j.forEach(G=>O.add(G)),O})},[f,j]);const v=o.useMemo(()=>{const $=[];return m.forEach((O,B)=>{if($.push({type:"header",key:`header:${O.id}`,groupIndex:B}),!u.has(O.id)){if(f){const G=new Set;b.forEach(H=>{H.startsWith(`${O.id} `)&&G.add(H.slice(O.id.length+1))}),n0(h[B],G).forEach(H=>{H.kind==="file"?$.push({type:"file",key:`${O.id}:${H.key}`,groupIndex:B,file:H.file,depth:H.depth}):$.push({type:"directory",key:`${O.id}:${H.key}`,groupIndex:B,directory:H.directory,depth:H.depth})});return}O.entries.forEach(G=>{$.push({type:"file",key:`${O.id}:file:${G.path}`,groupIndex:B,file:G,depth:0})})}}),i&&m.length>0&&$.push({type:"revert-all",key:"revert-all"}),$},[u,b,f,i,h,m]),C=v.length,k=C>=r0,w=mh({count:C,getScrollElement:()=>c.current,estimateSize:()=>a0,overscan:12,enabled:k});o.useEffect(()=>{if(!k)return;const $=c.current;if(!$)return;const O=new ResizeObserver(()=>w.measure());return O.observe($),()=>O.disconnect()},[k,w]);const N=w.getTotalSize(),I=o.useMemo(()=>k&&N>=0?w.getVirtualItems():[],[k,w,N]);o.useEffect(()=>{if(!a)return;const $=O=>O&&O.type==="file"?O.file.path:null;if(C===0){a([]);return}if(!k){const O=[];for(const B of v)if(B.type==="file"&&(O.push(B.file.path),O.length>=i0))break;a(O);return}a(I.map(O=>$(v[O.index])).filter(O=>!!O))},[a,C,v,k,I]);const E=o.useCallback($=>{p(O=>{const B=new Set(O);return B.has($)?B.delete($):B.add($),B})},[]),P=o.useCallback(($,O)=>{g(B=>{const G=new Set(B),R=Rc($,O);return G.has(R)?G.delete(R):G.add(R),G})},[]),T=o.useMemo(()=>{const $=new Set;return m.forEach(O=>O.entries.forEach(B=>$.add(B.path))),Array.from($)},[m]),S=T.length,M=o.useCallback(async()=>{!i||r||T.length===0||(await i(T),x(!1))},[T,r,i]),D=o.useCallback(($,O)=>{const B=u.has($.id),G=$.entries.length;return s.jsxs("div",{className:ge("sticky top-0 z-10 flex items-center gap-2 bg-sidebar py-2",zo,!O&&"mt-1 border-t border-border/40"),children:[s.jsx("button",{type:"button",onClick:()=>$.onActionAll($.entries.map(R=>R.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":$.actionAllLabel,title:$.actionAllLabel,children:$.actionSymbol}),s.jsxs("button",{type:"button",onClick:()=>E($.id),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-[var(--interactive-focus-ring)]","aria-expanded":!B,children:[s.jsx("h3",{className:"truncate typography-ui-header font-semibold text-foreground",children:$.title}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:G}),s.jsx(A,{name:"arrow-down-s",className:ge("size-3.5 shrink-0 text-muted-foreground transition-transform",B&&"-rotate-90")})]})]})},[u,E]),F=o.useCallback(($,O,B)=>{const G=b.has(Rc($.id,O.path));return s.jsxs("div",{className:ge("group flex items-center gap-2 py-1.5 hover:bg-sidebar/40",zo),style:{paddingLeft:`${B*Vm}px`},children:[s.jsxs("button",{type:"button",onClick:()=>P($.id,O.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":G?l("gitView.changes.collapseDirectoryAria",{path:O.path}):l("gitView.changes.expandDirectoryAria",{path:O.path}),children:[G?s.jsx(A,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(A,{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:O.path,children:O.name}),s.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:O.files.length})]}),s.jsx("button",{type:"button",onClick:()=>$.onActionAll(O.files.map(R=>R.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":l($.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:O.path}),title:l($.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:O.path}),children:$.actionSymbol})]})},[b,l,P]),_=o.useCallback(($,O)=>{if($.type==="revert-all")return s.jsx("div",{className:ge("flex justify-end py-2",zo),children:s.jsxs(he,{variant:"ghost",size:"sm",onClick:()=>x(!0),disabled:r,className:"gap-1.5 text-[var(--status-error)] hover:bg-[var(--status-error)]/10 hover:text-[var(--status-error)]",children:[s.jsx(A,{name:"arrow-go-back",className:"size-3.5"}),l("gitView.changes.revertAll")]})});const B=m[$.groupIndex];if(!B)return null;if($.type==="header")return D(B,O);if($.type==="directory")return F(B,$.directory,$.depth);const G=$.file;return s.jsx(t0,{file:G,actionLabel:B.getActionLabel(G.path),actionSymbol:B.actionSymbol,onAction:()=>B.onActionFile(G.path),stats:e?.[G.path],onViewDiff:()=>B.onViewDiff(G.path),onRevert:()=>B.onRevertFile(G.path),isReverting:n.has(G.path)||r,rowPaddingClassName:zo,indentPx:$.depth*Vm,actionAtStart:!f,showRevert:B.showRevertActions!==!1})},[e,r,f,F,D,n,l,m]),V=o.useCallback($=>{const O=v[$],B=v[$-1];return!O||!B||O.type!=="file"&&O.type!=="directory"||B.type!=="file"&&B.type!=="directory"?!1:B.groupIndex===O.groupIndex},[v]);return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-col overflow-hidden",children:[s.jsx(Io,{ref:c,className:"overlay-scrollbar-target overlay-scrollbar-container min-h-0 w-full flex-1 overflow-x-hidden overflow-y-auto",children:k?s.jsx("div",{className:"relative w-full",style:{height:`${w.getTotalSize()}px`},children:I.map($=>{const O=v[$.index];return O?s.jsx("div",{ref:w.measureElement,"data-index":$.index,className:ge("absolute left-0 top-0 w-full",V($.index)&&"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(${$.start}px)`},children:_(O,$.index===0)},O.key):null})}):s.jsx("div",{role:"list","aria-label":l("gitView.changes.changedFilesAria"),children:v.map(($,O)=>s.jsx("div",{className:ge("relative",V(O)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:_($,O===0)},$.key))})}),s.jsx(qb,{containerRef:c,disableHorizontal:!0})]}),s.jsx(ls,{open:y,onOpenChange:$=>{!r&&!$&&x(!1)},children:s.jsxs(os,{className:"max-w-md",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:l("gitView.changes.revertAllDialogTitle")}),s.jsx(ys,{children:S===1?l("gitView.changes.revertAllDescriptionSingle",{count:S}):l("gitView.changes.revertAllDescriptionPlural",{count:S})})]}),s.jsxs(Rs,{children:[s.jsx(he,{variant:"outline",size:"sm",onClick:()=>x(!1),disabled:r,children:l("gitView.common.cancel")}),s.jsx(he,{variant:"destructive",size:"sm",onClick:()=>{M()},disabled:r,children:l(r?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})})]})},Fc=38,Uo=200,l0=t=>{const e=ot.c(20),{value:n,onChange:r,placeholder:a,disabled:i,hasTouchInput:l,isMobile:c}=t,d=i===void 0?!1:i,f=l===void 0?!1:l,m=c===void 0?!1:c,{t:u}=pt(),p=o.useRef(null),b=_e(c0);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{const E=p.current;if(!E)return;const P=document.activeElement===E,T=()=>{E.style.height=`${Fc}px`;const M=E.scrollHeight,D=Math.min(Math.max(M,Fc),Uo);E.style.height=`${D}px`,E.style.overflowY=M>Uo?"auto":"hidden",M>Uo&&!P&&(E.scrollTop=E.scrollHeight)};T();const S=window.requestAnimationFrame(T);return()=>{window.cancelAnimationFrame(S)}},e[0]=g):g=e[0];let y;e[1]!==n?(y=[n],e[1]=n,e[2]=y):y=e[2],o.useLayoutEffect(g,y);let x;e[3]!==r?(x=E=>r(E.target.value),e[3]=r,e[4]=x):x=e[4];let h;e[5]!==a||e[6]!==u?(h=a??u("gitView.commit.messagePlaceholder"),e[5]=a,e[6]=u,e[7]=h):h=e[7];const j=f?"on":"off",v=f?"sentences":"off",C=m||b,k=d&&"opacity-50";let w;e[8]!==k?(w=ge("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)]",k),e[8]=k,e[9]=w):w=e[9];let N;e[10]===Symbol.for("react.memo_cache_sentinel")?(N={minHeight:Fc,maxHeight:Uo},e[10]=N):N=e[10];let I;return e[11]!==d||e[12]!==C||e[13]!==w||e[14]!==x||e[15]!==h||e[16]!==j||e[17]!==v||e[18]!==n?(I=s.jsx("textarea",{ref:p,value:n,onChange:x,placeholder:h,rows:1,disabled:d,autoCorrect:j,autoCapitalize:v,spellCheck:C,className:w,style:N}),e[11]=d,e[12]=C,e[13]=w,e[14]=x,e[15]=h,e[16]=j,e[17]=v,e[18]=n,e[19]=I):I=e[19],I};function c0(t){return t.inputSpellcheckEnabled}const d0=t=>{const e=ot.c(30),{highlights:n,onInsert:r}=t,{t:a}=pt();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 l=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 f;e[7]!==a?(f=a("gitView.commit.aiHighlights.insertAria"),e[7]=a,e[8]=f):f=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(A,{name:"arrow-down",className:"size-4"}),e[9]=m):m=e[9];let u;e[10]!==l||e[11]!==f?(u=s.jsx(Pt,{asChild:!0,children:s.jsx(he,{variant:"ghost",size:"icon",className:"size-6",onClick:l,"aria-label":f,children:m})}),e[10]=l,e[11]=f,e[12]=u):u=e[12];let p;e[13]!==a?(p=a("gitView.commit.aiHighlights.insertTooltip"),e[13]=a,e[14]=p):p=e[14];let b;e[15]!==p?(b=s.jsx(At,{sideOffset:8,children:p}),e[15]=p,e[16]=b):b=e[16];let g;e[17]!==u||e[18]!==b?(g=s.jsxs(It,{children:[u,b]}),e[17]=u,e[18]=b,e[19]=g):g=e[19];let y;e[20]!==d||e[21]!==g?(y=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d,g]}),e[20]=d,e[21]=g,e[22]=y):y=e[22];let x;e[23]!==n?(x=n.map(u0),e[23]=n,e[24]=x):x=e[24];let h;e[25]!==x?(h=s.jsx("ul",{className:"space-y-1",children:x}),e[25]=x,e[26]=h):h=e[26];let j;return e[27]!==y||e[28]!==h?(j=s.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[y,h]}),e[27]=y,e[28]=h,e[29]=j):j=e[29],j};function u0(t,e){return s.jsx("li",{className:"typography-meta text-foreground",children:t},`${t}-${e}`)}const m0=t=>{const e=ot.c(75),{stagedCount:n,commitMessage:r,onCommitMessageChange:a,generatedHighlights:i,onInsertHighlights:l,onGenerateMessage:c,isGeneratingMessage:d,onCommit:f,onCommitAndPush:m,commitAction:u,hasPendingIndexMutation:p,gitmojiEnabled:b,onOpenGitmojiPicker:g}=t,y=p===void 0?!1:p,{t:x}=pt(),h=n>0;let j;e[0]!==u||e[1]!==r||e[2]!==y||e[3]!==h?(j=r.trim()&&h&&u===null&&!y,e[0]=u,e[1]=r,e[2]=y,e[3]=h,e[4]=j):j=e[4];const v=j,{isMobile:C,hasTouchInput:k}=an();let w;e[5]!==x?(w=x("gitView.commit.title"),e[5]=x,e[6]=w):w=e[6];let N;e[7]!==w?(N=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:w}),e[7]=w,e[8]=N):N=e[8];let I;e[9]!==h||e[10]!==x?(I=h?null:s.jsx("span",{className:"min-w-0 truncate typography-meta text-muted-foreground",children:x("gitView.commit.stageFilesHint")}),e[9]=h,e[10]=x,e[11]=I):I=e[11];let E;e[12]!==N||e[13]!==I?(E=s.jsxs("div",{className:"flex w-full items-baseline gap-2 px-0 pt-2 pb-1",children:[N,I]}),e[12]=N,e[13]=I,e[14]=E):E=e[14];let P;e[15]!==i||e[16]!==l?(P=s.jsx(d0,{highlights:i,onInsert:l}),e[15]=i,e[16]=l,e[17]=P):P=e[17];let T;e[18]!==x?(T=x("gitView.commit.messagePlaceholder"),e[18]=x,e[19]=T):T=e[19];const S=u!==null;let M;e[20]!==r||e[21]!==k||e[22]!==C||e[23]!==a||e[24]!==T||e[25]!==S?(M=s.jsx(l0,{value:r,onChange:a,placeholder:T,disabled:S,hasTouchInput:k,isMobile:C}),e[20]=r,e[21]=k,e[22]=C,e[23]=a,e[24]=T,e[25]=S,e[26]=M):M=e[26];let D;e[27]!==b||e[28]!==g||e[29]!==x?(D=b&&s.jsxs(he,{variant:"outline",size:"sm",onClick:g,className:"w-fit",type:"button",children:[s.jsx(A,{name:"emotion-happy",className:"size-4"}),x("gitView.commit.addGitmoji")]}),e[27]=b,e[28]=g,e[29]=x,e[30]=D):D=e[30];const F=d||u!==null||y||n===0;let _;e[31]!==x?(_=x("gitView.commit.generateAria"),e[31]=x,e[32]=_):_=e[32];let V;e[33]!==d?(V=d?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"ai-generate-2",className:"size-4 text-primary"}),e[33]=d,e[34]=V):V=e[34];let $;e[35]!==x?($=x("gitView.commit.generate"),e[35]=x,e[36]=$):$=e[36];let O;e[37]!==$?(O=s.jsx("span",{className:"commit-actions__label",children:$}),e[37]=$,e[38]=O):O=e[38];let B;e[39]!==c||e[40]!==F||e[41]!==_||e[42]!==V||e[43]!==O?(B=s.jsxs(he,{variant:"outline",size:"sm",onClick:c,disabled:F,type:"button","aria-label":_,className:"commit-actions__btn",children:[V,O]}),e[39]=c,e[40]=F,e[41]=_,e[42]=V,e[43]=O,e[44]=B):B=e[44];let G;e[45]===Symbol.for("react.memo_cache_sentinel")?(G=s.jsx("div",{className:"flex-1"}),e[45]=G):G=e[45];const R=!v||d;let H;e[46]!==x?(H=x("gitView.commit.commitAria"),e[46]=x,e[47]=H):H=e[47];let J;e[48]!==u||e[49]!==x?(J=u==="commit"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:x("gitView.commit.committing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"git-commit",className:"size-4"}),s.jsx("span",{className:"commit-actions__label",children:x("gitView.commit.commit")})]}),e[48]=u,e[49]=x,e[50]=J):J=e[50];let ne;e[51]!==f||e[52]!==R||e[53]!==H||e[54]!==J?(ne=s.jsx(he,{size:"sm",variant:"outline",onClick:f,disabled:R,className:"commit-actions__btn whitespace-nowrap","aria-label":H,children:J}),e[51]=f,e[52]=R,e[53]=H,e[54]=J,e[55]=ne):ne=e[55];let ue;e[56]!==v||e[57]!==u||e[58]!==d||e[59]!==C||e[60]!==m||e[61]!==x?(ue=C?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(he,{variant:"default",size:"sm",onClick:()=>m(),disabled:!v||d,className:"h-7 w-7 p-0","aria-label":x("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"arrow-up",className:"size-3.5"})})}),s.jsx(At,{side:"top",children:s.jsx("p",{children:x("gitView.commit.push")})})]}):s.jsx(he,{size:"sm",variant:"default",onClick:()=>m(),disabled:!v||d,className:"commit-actions__btn","aria-label":x("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:x("gitView.commit.pushing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"arrow-up",className:"size-3.5"}),s.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:x("gitView.commit.push")})]})}),e[56]=v,e[57]=u,e[58]=d,e[59]=C,e[60]=m,e[61]=x,e[62]=ue):ue=e[62];let de;e[63]!==B||e[64]!==ne||e[65]!==ue?(de=s.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[B,G,ne,ue]}),e[63]=B,e[64]=ne,e[65]=ue,e[66]=de):de=e[66];let pe;e[67]!==M||e[68]!==D||e[69]!==de||e[70]!==P?(pe=s.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[P,M,D,de]}),e[67]=M,e[68]=D,e[69]=de,e[70]=P,e[71]=pe):pe=e[71];let W;return e[72]!==pe||e[73]!==E?(W=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[E,pe]}),e[72]=pe,e[73]=E,e[74]=W):W=e[74],W},p0=t=>{const e=ot.c(16),{onOpenStashes:n}=t,{t:r}=pt();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(A,{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 l;e[3]!==i?(l=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:i}),e[3]=i,e[4]=l):l=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 f;e[9]!==n||e[10]!==r?(f=n?s.jsxs(he,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(A,{name:"archive-stack",className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=f):f=e[11];let m;return e[12]!==l||e[13]!==d||e[14]!==f?(m=s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[a,l,d,f]}),e[12]=l,e[13]=d,e[14]=f,e[15]=m):m=e[15],m};function fg(t){const e=ot.c(63),{draft:n,onEdit:r,onDelete:a,className:i,maxWidth:l}=t,{t:c}=pt(),f=sc()?.currentTheme,[m,u]=Ve.useState(!1),p=typeof n.text=="string"?n.text:"";let b;e[0]!==p?(b=p.length>150||p.split(`
|
|
7
|
+
`).length>3,e[0]=p,e[1]=b):b=e[1];const g=b;let y;e[2]!==i?(y=ge("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]=y):y=e[3];const x=f?.colors?.surface?.elevated,h=f?.colors?.interactive?.border,j=l?`${Math.max(200,Math.floor(l))}px`:void 0;let v;e[4]!==x||e[5]!==h||e[6]!==j?(v={backgroundColor:x,borderColor:h,maxWidth:j},e[4]=x,e[5]=h,e[6]=j,e[7]=v):v=e[7];let C;e[8]!==n.fileLabel?(C=s.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),e[8]=n.fileLabel,e[9]=C):C=e[9];let k;e[10]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx("span",{children:"•"}),e[10]=k):k=e[10];let w;e[11]!==n.endLine||e[12]!==n.startLine||e[13]!==c?(w=c("inlineComment.range.lines",{start:n.startLine,end:n.endLine}),e[11]=n.endLine,e[12]=n.startLine,e[13]=c,e[14]=w):w=e[14];let N;e[15]!==w?(N=s.jsx("span",{children:w}),e[15]=w,e[16]=N):N=e[16];let I;e[17]!==n.side?(I=n.side&&s.jsxs("span",{children:["(",n.side,")"]}),e[17]=n.side,e[18]=I):I=e[18];let E;e[19]!==N||e[20]!==I||e[21]!==C?(E=s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[C,k,N,I]}),e[19]=N,e[20]=I,e[21]=C,e[22]=E):E=e[22];const P=m||!g,T=!m&&g&&"line-clamp-3";let S;e[23]!==T?(S=ge("text-sm whitespace-pre-wrap break-words leading-relaxed",T),e[23]=T,e[24]=S):S=e[24];let M;e[25]!==p||e[26]!==S?(M=s.jsx("div",{className:S,children:p}),e[25]=p,e[26]=S,e[27]=M):M=e[27];let D;e[28]!==g||e[29]!==m||e[30]!==c?(D=g&&s.jsx(Lr,{asChild:!0,children:s.jsx(he,{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(A,{name:"arrow-up-s",className:"size-3 mr-1"}),c("inlineComment.actions.showLess")]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"arrow-down-s",className:"size-3 mr-1"}),c("inlineComment.actions.showMore")]})})}),e[28]=g,e[29]=m,e[30]=c,e[31]=D):D=e[31];let F;e[32]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(Nr,{}),e[32]=F):F=e[32];let _;e[33]!==P||e[34]!==M||e[35]!==D?(_=s.jsxs(jr,{open:P,onOpenChange:u,children:[M,D,F]}),e[33]=P,e[34]=M,e[35]=D,e[36]=_):_=e[36];let V;e[37]!==E||e[38]!==_?(V=s.jsxs("div",{className:"flex-1 min-w-0",children:[E,_]}),e[37]=E,e[38]=_,e[39]=V):V=e[39];let $;e[40]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(Is,{asChild:!0,children:s.jsx(he,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"more",className:"size-4"})})}),e[40]=$):$=e[40];let O;e[41]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(A,{name:"edit",className:"size-4 mr-2"}),e[41]=O):O=e[41];let B;e[42]!==c?(B=c("inlineComment.actions.editComment"),e[42]=c,e[43]=B):B=e[43];let G;e[44]!==r||e[45]!==B?(G=s.jsxs(Ot,{onClick:r,children:[O,B]}),e[44]=r,e[45]=B,e[46]=G):G=e[46];let R;e[47]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(A,{name:"delete-bin",className:"size-4 mr-2"}),e[47]=R):R=e[47];let H;e[48]!==c?(H=c("inlineComment.actions.deleteComment"),e[48]=c,e[49]=H):H=e[49];let J;e[50]!==a||e[51]!==H?(J=s.jsxs(Ot,{onClick:a,className:"text-destructive",children:[R,H]}),e[50]=a,e[51]=H,e[52]=J):J=e[52];let ne;e[53]!==G||e[54]!==J?(ne=s.jsxs(As,{children:[$,s.jsxs(Ps,{align:"end",children:[G,J]})]}),e[53]=G,e[54]=J,e[55]=ne):ne=e[55];let ue;e[56]!==V||e[57]!==ne?(ue=s.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[V,ne]}),e[56]=V,e[57]=ne,e[58]=ue):ue=e[58];let de;return e[59]!==y||e[60]!==ue||e[61]!==v?(de=s.jsx("div",{className:y,style:v,"data-comment-card":"true",children:ue}),e[59]=y,e[60]=ue,e[61]=v,e[62]=de):de=e[62],de}function Vl(t){const e=ot.c(57),{initialText:n,onSave:r,onCancel:a,fileLabel:i,lineRange:l,isEditing:c,className:d,maxWidth:f}=t,m=n===void 0?"":n,u=c===void 0?!1:c,{t:p}=pt(),g=sc()?.currentTheme,{isMobile:y}=an(),[x,h]=o.useState(m),j=Ve.useRef(null),v=Ve.useRef(l);let C,k;e[0]!==l?(C=()=>{l&&(v.current=l)},k=[l],e[0]=l,e[1]=C,e[2]=k):(C=e[1],k=e[2]),Ve.useEffect(C,k);const w=v0,N=w(l);let I,E;e[3]!==y?(I=()=>{const xe=j.current;if(!xe)return;const Z=xe.closest(".overlay-scrollbar-container"),me=Z?.scrollTop??window.scrollY,Y=Z?.scrollLeft??window.scrollX;if(y){xe.scrollIntoView({behavior:"auto",block:"nearest"});try{xe.focus({preventScroll:!0})}catch{xe.focus()}return}try{xe.focus({preventScroll:!0})}catch{xe.focus()}const Se=xe.value.length;try{xe.setSelectionRange(Se,Se)}catch{}requestAnimationFrame(()=>{Z?(Z.scrollTop=me,Z.scrollLeft=Y):window.scrollTo({top:me,left:Y})})},E=[y],e[3]=y,e[4]=I,e[5]=E):(I=e[4],E=e[5]),Ve.useEffect(I,E);let P;e[6]!==a||e[7]!==r||e[8]!==x?(P=xe=>{(xe.metaKey||xe.ctrlKey)&&xe.key==="Enter"?(xe.preventDefault(),x.trim()&&r(x,w(v.current))):xe.key==="Escape"&&(xe.preventDefault(),a())},e[6]=a,e[7]=r,e[8]=x,e[9]=P):P=e[9];const T=P;let S;e[10]!==r||e[11]!==x?(S=xe=>{xe.stopPropagation(),x.trim()&&r(x,w(v.current))},e[10]=r,e[11]=x,e[12]=S):S=e[12];const M=S;let D;e[13]!==d?(D=ge("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]=D):D=e[14];const F=g?.colors?.surface?.elevated,_=g?.colors?.interactive?.border,V=f?`${Math.max(200,Math.floor(f))}px`:void 0;let $;e[15]!==F||e[16]!==_||e[17]!==V?($={backgroundColor:F,borderColor:_,maxWidth:V},e[15]=F,e[16]=_,e[17]=V,e[18]=$):$=e[18];const O="true",B=y0,G=b0,R="p-3",H=(i||l)&&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&&l&&s.jsx("span",{children:"•"}),N&&s.jsx("span",{children:p("inlineComment.range.lines",{start:N.start,end:N.end})})]});let J;e[19]===Symbol.for("react.memo_cache_sentinel")?(J=xe=>h(xe.target.value),e[19]=J):J=e[19];let ne;e[20]!==p?(ne=p("inlineComment.input.placeholder"),e[20]=p,e[21]=ne):ne=e[21];let ue;e[22]!==T||e[23]!==ne||e[24]!==x?(ue=s.jsx(ln,{simple:!0,ref:j,value:x,onChange:J,onKeyDown:T,placeholder:ne,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]=T,e[23]=ne,e[24]=x,e[25]=ue):ue=e[25];let de;e[26]!==p?(de=p("inlineComment.actions.cancel"),e[26]=p,e[27]=de):de=e[27];let pe;e[28]!==a||e[29]!==de?(pe=s.jsx(he,{variant:"ghost",size:"sm",onClick:a,onPointerDown:x0,onTouchStart:g0,className:"h-8 text-muted-foreground hover:text-foreground",children:de}),e[28]=a,e[29]=de,e[30]=pe):pe=e[30];let W;e[31]!==x?(W=x.trim(),e[31]=x,e[32]=W):W=e[32];const te=!W,X=g?.colors?.status?.success,ee=g?.colors?.status?.successForeground;let fe;e[33]!==X||e[34]!==ee?(fe={backgroundColor:X,color:ee},e[33]=X,e[34]=ee,e[35]=fe):fe=e[35];let be;e[36]!==u||e[37]!==p?(be=p(u?"inlineComment.actions.save":"inlineComment.actions.comment"),e[36]=u,e[37]=p,e[38]=be):be=e[38];let Ne;e[39]!==M||e[40]!==te||e[41]!==fe||e[42]!==be?(Ne=s.jsx(he,{size:"sm",onClick:M,onPointerDown:h0,onTouchStart:f0,disabled:te,className:"h-8 min-w-[80px]",style:fe,children:be}),e[39]=M,e[40]=te,e[41]=fe,e[42]=be,e[43]=Ne):Ne=e[43];let se;e[44]!==pe||e[45]!==Ne?(se=s.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[pe,Ne]}),e[44]=pe,e[45]=Ne,e[46]=se):se=e[46];let ie;e[47]!==H||e[48]!==ue||e[49]!==se?(ie=s.jsxs("div",{className:R,children:[H,ue,se]}),e[47]=H,e[48]=ue,e[49]=se,e[50]=ie):ie=e[50];let ae;return e[51]!==$||e[52]!==B||e[53]!==G||e[54]!==ie||e[55]!==D?(ae=s.jsx("div",{className:D,style:$,"data-comment-input":O,onPointerDown:B,onTouchStart:G,children:ie}),e[51]=$,e[52]=B,e[53]=G,e[54]=ie,e[55]=D,e[56]=ae):ae=e[56],ae}function f0(t){return t.stopPropagation()}function h0(t){return t.stopPropagation()}function g0(t){return t.stopPropagation()}function x0(t){return t.stopPropagation()}function b0(t){return t.stopPropagation()}function y0(t){return t.stopPropagation()}function v0(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 w0=t=>{const e=Math.min(t.startLine,t.endLine),n=Math.max(t.startLine,t.endLine);return{...t,startLine:e,endLine:n}},zl=t=>{const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}};function gu(t){const e=ot.c(40),{t:n}=pt(),{source:r,fileLabel:a,language:i,getCodeForRange:l,toStoreRange:c,fromDraftRange:d}=t,f=Lt(I0),m=Lt(C0),u=gi(k0),p=gi(S0),b=gi(N0),g=gi(j0),[y,x]=o.useState(null),[h,j]=o.useState(""),[v,C]=o.useState(null),k=f??(m?"draft":null);let w;e:{if(!k||!a){let R;e[0]===Symbol.for("react.memo_cache_sentinel")?(R=[],e[0]=R):R=e[0],w=R;break e}let O;e[1]!==g||e[2]!==k?(O=g[k]??[],e[1]=g,e[2]=k,e[3]=O):O=e[3];const B=O;let G;if(e[4]!==a||e[5]!==B||e[6]!==r){let R;e[8]!==a||e[9]!==r?(R=H=>H.source===r&&H.fileLabel===a,e[8]=a,e[9]=r,e[10]=R):R=e[10],G=B.filter(R),e[4]=a,e[5]=B,e[6]=r,e[7]=G}else G=e[7];w=G}const N=w;let I;e[11]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{x(null),j(""),C(null)},e[11]=I):I=e[11];const E=I;let P;e[12]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{E()},e[12]=P):P=e[12];const T=P;let S;e[13]!==d?(S=O=>{const B=zl(d(O));x(B),j(O.text),C(O.id)},e[13]=d,e[14]=S):S=e[14];const M=S;let D;e[15]!==v||e[16]!==b?(D=O=>{b(O.sessionKey,O.id),v===O.id&&E()},e[15]=v,e[16]=b,e[17]=D):D=e[17];const F=D;let _;e[18]!==u||e[19]!==v||e[20]!==a||e[21]!==l||e[22]!==i||e[23]!==y||e[24]!==k||e[25]!==r||e[26]!==n||e[27]!==c||e[28]!==p?(_=(O,B)=>{const G=B??y,R=O.trim();if(!G||!R||!a)return;if(!k){K.error(n("inlineComment.toast.selectSessionToSave"));return}const H=zl(G),J=w0(c(H)),ne=l(H);v?p(k,v,{fileLabel:a,startLine:J.startLine,endLine:J.endLine,side:J.side,code:ne,language:i,text:R}):u({sessionKey:k,source:r,fileLabel:a,startLine:J.startLine,endLine:J.endLine,side:J.side,code:ne,language:i,text:R}),E()},e[18]=u,e[19]=v,e[20]=a,e[21]=l,e[22]=i,e[23]=y,e[24]=k,e[25]=r,e[26]=n,e[27]=c,e[28]=p,e[29]=_):_=e[29];const V=_;let $;return e[30]!==h||e[31]!==F||e[32]!==N||e[33]!==v||e[34]!==d||e[35]!==V||e[36]!==y||e[37]!==k||e[38]!==M?($={sessionKey:k,drafts:N,selection:y,setSelection:x,commentText:h,setCommentText:j,editingDraftId:v,setEditingDraftId:C,reset:E,cancel:T,startEdit:M,deleteDraft:F,saveComment:V,fromDraftRange:d},e[30]=h,e[31]=F,e[32]=N,e[33]=v,e[34]=d,e[35]=V,e[36]=y,e[37]=k,e[38]=M,e[39]=$):$=e[39],$}function j0(t){return t.drafts}function N0(t){return t.removeDraft}function S0(t){return t.updateDraft}function k0(t){return t.addDraft}function C0(t){return t.newSessionDraft?.open}function I0(t){return t.currentSessionId}function hg(t){const{drafts:e,editingDraftId:n,commentText:r,selection:a,isDragging:i,fileLabel:l,newWidgetId:c,mapDraftToRange:d,onSave:f,onCancel:m,onEdit:u,onDelete:p}=t,b=[];for(const g of e){const y=d(g);if(g.id===n){b.push({afterLine:y.end,id:`edit-${g.id}`,content:s.jsx(Vl,{initialText:r,fileLabel:l,lineRange:y,isEditing:!0,onSave:f,onCancel:m},`edit-${g.id}`)});continue}b.push({afterLine:y.end,id:`card-${g.id}`,content:s.jsx(fg,{draft:g,onEdit:()=>u(g),onDelete:()=>p(g)},`card-${g.id}`)})}if(a&&!n&&!i){const g={...a,start:Math.min(a.start,a.end),end:Math.max(a.start,a.end)};b.push({afterLine:g.end,id:c,content:s.jsx(Vl,{initialText:r,fileLabel:l,lineRange:g,isEditing:!1,onSave:f,onCancel:m},c)})}return b}const xl=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}`},P0=t=>{const{drafts:e,editingDraftId:n,selection:r}=t,a=[];for(const i of e){if(!Number.isFinite(i.endLine))continue;const l=Math.max(1,Math.floor(i.endLine)),c=i.side==="original"?"deletions":"additions";a.push({lineNumber:l,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 A0(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 Um(t){if(!(!t||t<=0))return Math.max(200,Math.floor(t))}function D0(t){const{diffRootRef:e,drafts:n,selection:r,editingDraftId:a,commentText:i,fileLabel:l,onSave:c,onCancel:d,onEdit:f,onDelete:m}=t,[u,p]=o.useState(0),[b,g]=o.useState(null),y=o.useMemo(()=>!r||a?null:xl({type:"new",selection:r}),[a,r]),x=o.useMemo(()=>{const v=n.map(C=>xl({type:C.id===a?"edit":"saved",draft:C}));return y&&v.push(y),v},[n,a,y]),h=o.useCallback(v=>{const C=e.current;if(!C)return null;const k=C.querySelector("diffs-container");if(!(k instanceof HTMLElement))return null;const w=k.querySelector(`[data-annotation-id="${v}"]`);if(w instanceof HTMLElement)return w;const N=k.shadowRoot;return N?N.querySelector(`[data-annotation-id="${v}"]`):null},[e]);o.useEffect(()=>{if(x.length===0)return;let v=!1,C=0;const k=12,w=()=>{v||x.every(I=>!!h(I))||C>=k||(C+=1,requestAnimationFrame(()=>{v||(p(I=>I+1),w())}))};return w(),()=>{v=!0}},[x,h]),o.useEffect(()=>{const v=e.current;if(!v)return;const C=()=>{const w=getComputedStyle(v),N=A0(w.getPropertyValue("--oc-context-panel-width")),I=v.getBoundingClientRect(),E=N??I.width;g(E>0?E:null)};C();const k=new ResizeObserver(()=>{C()});return k.observe(v),window.addEventListener("resize",C),()=>{k.disconnect(),window.removeEventListener("resize",C)}},[e]);const j=o.useCallback(v=>{const k=e.current?.getBoundingClientRect(),w=v.closest("[data-annotation-content]"),N=w instanceof HTMLElement?w.getBoundingClientRect():v.getBoundingClientRect(),I=[N.width];k&&I.push(k.right-N.left);const E=I.filter(P=>Number.isFinite(P)&&P>0);return E.length>0?Um(Math.min(...E)):Um(b)},[e,b]);return s.jsxs(s.Fragment,{children:[n.map(v=>{const C=xl({type:v.id===a?"edit":"saved",draft:v}),k=h(C);if(!k)return null;const w=j(k);return v.id===a?ol.createPortal(s.jsx(Vl,{initialText:i,fileLabel:l,lineRange:{start:v.startLine,end:v.endLine,side:v.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:d,maxWidth:w}),k,`draft-edit-${v.id}`):ol.createPortal(s.jsx(fg,{draft:v,onEdit:()=>f(v),onDelete:()=>m(v),maxWidth:w}),k,`draft-card-${v.id}`)}),r&&!a&&y&&(()=>{const v=h(y);if(!v)return null;const C=j(v);return ol.createPortal(s.jsx(Vl,{initialText:i,fileLabel:l,lineRange:r,isEditing:!1,onSave:c,onCancel:d,maxWidth:C}),v,y)})()]})}function T0(){return new Worker(Mx,{type:"module"})}const E0=["typescript","javascript","tsx","jsx","json","markdown"],Pd={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let Wm,Km;const Hm=t=>{const e=Pd[t],n=new Rx({workerFactory:T0,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:E0,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},M0=t=>{if(!(typeof window>"u"))return t==="split"?(Km??=Hm("split"),Km):(Wm??=Hm("unified"),Wm)},R0=t=>{const e=ot.c(7),{children:n,renderTheme:r}=t,a=Ad("unified"),i=Ad("split");let l,c;e[0]!==r||e[1]!==i||e[2]!==a?(l=()=>{a&&a.setRenderOptions({theme:r,lineDiffType:Pd.unified.lineDiffType}),i&&i.setRenderOptions({theme:r,lineDiffType:Pd.split.lineDiffType})},c=[r,i,a],e[0]=r,e[1]=i,e[2]=a,e[3]=l,e[4]=c):(l=e[3],c=e[4]),Ve.useEffect(l,c);let d;return e[5]!==n?(d=s.jsx(s.Fragment,{children:n}),e[5]=n,e[6]=d):d=e[6],d},F0=t=>{const e=ot.c(11),{children:n}=t,r=sc();let a,i;if(e[0]!==r?.availableThemes||e[1]!==r?.darkThemeId||e[2]!==r?.lightThemeId){const f=Ci(!1),m=Ci(!0),u=r?.lightThemeId??f.metadata.id,p=r?.darkThemeId??m.metadata.id;i=r?.availableThemes.find(b=>b.metadata.id===u)??f,a=r?.availableThemes.find(b=>b.metadata.id===p)??m,Ii(i),Ii(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 l;e[5]!==a.metadata.id||e[6]!==i.metadata.id?(l={light:i.metadata.id,dark:a.metadata.id},e[5]=a.metadata.id,e[6]=i.metadata.id,e[7]=l):l=e[7];const c=l;let d;return e[8]!==n||e[9]!==c?(d=s.jsx(R0,{renderTheme:c,children:n}),e[8]=n,e[9]=c,e[10]=d):d=e[10],d},Ad=t=>{const e=ot.c(2),n=t===void 0?"unified":t;let r;return e[0]!==n?(r=M0(n),e[0]=n,e[1]=r):r=e[1],r},L0=5e5,O0=`
|
|
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 $0(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 Gm(t){const e=t.length>400?`${t.slice(0,200)}${t.slice(-200)}`:t;return`${t.length}:${$0(e)}`}const _0=(t,e,n)=>{const i=(n.side==="deletions"?t:e).split(`
|
|
37
|
+
`),l=Math.min(n.start,n.end),c=Math.max(n.start,n.end),d=Math.max(1,l),f=Math.min(i.length,c);return d>f?"":i.slice(d-1,f).join(`
|
|
38
|
+
`)},B0=(t,e)=>t===e?!0:!t||!e?!1:t.start===e.start&&t.end===e.end&&t.side===e.side,Wo=new WeakMap,V0={lineHeight:24,hunkSeparatorHeight:24,fileGap:0};function z0(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 U0(t){if(typeof document>"u")return null;const e=z0(t);let n=Wo.get(e.key);if(!n){const a=new Ox;a.setup(e.root,e.content),n={virtualizer:a,refs:0},Wo.set(e.key,n)}n.refs+=1;let r=!1;return{virtualizer:n.virtualizer,release:()=>{if(r)return;r=!0;const a=Wo.get(e.key);a&&(a.refs-=1,!(a.refs>0)&&(a.virtualizer.cleanUp(),Wo.delete(e.key)))}}}const xu=({original:t,modified:e,language:n,fileName:r,renderSideBySide:a,wrapLines:i,layout:l="fill"})=>{const c=sc(),d=c?.currentTheme.metadata.variant==="dark",f=c?.availableThemes.find(X=>X.metadata.id===c.lightThemeId)??Ci(!1),m=c?.availableThemes.find(X=>X.metadata.id===c.darkThemeId)??Ci(!0),{isMobile:u}=an(),p=gu({source:"diff",fileLabel:r||"unknown",language:n,getCodeForRange:X=>_0(t,e,X),toStoreRange:X=>({startLine:X.start,endLine:X.end,side:X.side==="deletions"?"original":"modified"}),fromDraftRange:X=>({start:X.startLine,end:X.endLine,side:X.side==="original"?"deletions":"additions"})}),{drafts:b,selection:g,setSelection:y,commentText:x,setCommentText:h,editingDraftId:j,saveComment:v,cancel:C,startEdit:k,deleteDraft:w}=p,N=Ve.useRef(null),I=Ve.useRef(null),E=Ve.useRef(!1),P=Ve.useRef(null);Ve.useEffect(()=>{N.current=g},[g]),Ve.useEffect(()=>{I.current=j},[j]);const T=Ve.useCallback(X=>{if(E.current)return;const ee=N.current;if(u&&ee&&X&&X.side===ee.side){const fe=Math.min(ee.start,X.start),be=Math.max(ee.end,X.end);y({...X,start:fe,end:be})}else y(X);X&&(I.current||h(""))},[u,h,y]),S=Ve.useCallback(()=>{C()},[C]),M=Ve.useCallback(X=>{const ee=document.createElement("div");ee.style.position="relative";const fe=xl(X.metadata);return ee.dataset.annotationId=fe,ee.dataset.annotationSide=X.side,ee.dataset.annotationLine=String(X.lineNumber),ee},[]),D=Ve.useCallback((X,ee)=>{v(X,ee??g??void 0)},[v,g]),F=Ve.useCallback(X=>{y(X);const ee=B.current;if(ee)try{E.current=!0,ee.setSelectedLines(X),P.current=X}catch{}finally{E.current=!1}},[y]),_=Ve.useCallback(X=>{const ee=X.closest("[data-line-type]")?.getAttribute("data-line-type")??X.getAttribute("data-line-type");if(ee==="change-deletion")return"deletions";if(ee==="change-addition")return"additions";const fe=X.getAttribute("data-column-side")??X.getAttribute("data-side")??X.closest("[data-column-side]")?.getAttribute("data-column-side");if(fe==="deletions"||fe==="left"||fe==="original")return"deletions";if(fe==="additions"||fe==="right"||fe==="modified")return"additions";const be=X.closest("[data-line-type]");if(be instanceof HTMLElement){const Ne=be.getBoundingClientRect(),se=X.getBoundingClientRect(),ie=Ne.left+Ne.width/2;return se.left+se.width/2<ie?"deletions":"additions"}return"additions"},[]);Ii(f),Ii(m);const V=`${f.metadata.id}:${m.metadata.id}:${d?"dark":"light"}`,$=Ve.useRef(null),O=Ve.useRef(null),B=Ve.useRef(null),G=Ve.useRef(null),[,R]=o.useReducer(X=>X+1,0),H=Ad(a?"split":"unified"),J=Ve.useMemo(()=>qu(f),[f]),ne=Ve.useMemo(()=>qu(m),[m]);o.useLayoutEffect(()=>{const X=$.current;if(!X)return;const ee=X.querySelector("diffs-container");if(!ee)return;const fe=d?ne:J,be=(ke,Fe)=>ke.colors?.[Fe],Ne=be(J,"terminal.ansiGreen"),se=be(J,"terminal.ansiRed"),ie=be(J,"terminal.ansiBlue"),ae=be(ne,"terminal.ansiGreen"),xe=be(ne,"terminal.ansiRed"),Z=be(ne,"terminal.ansiBlue");ee.style.setProperty("--shiki-light",J.fg),ee.style.setProperty("--shiki-light-bg",J.bg),Ne&&ee.style.setProperty("--shiki-light-addition-color",Ne),se&&ee.style.setProperty("--shiki-light-deletion-color",se),ie&&ee.style.setProperty("--shiki-light-modified-color",ie),ee.style.setProperty("--shiki-dark",ne.fg),ee.style.setProperty("--shiki-dark-bg",ne.bg),ae&&ee.style.setProperty("--shiki-dark-addition-color",ae),xe&&ee.style.setProperty("--shiki-dark-deletion-color",xe),Z&&ee.style.setProperty("--shiki-dark-modified-color",Z),ee.style.setProperty("--diffs-bg",fe.bg),ee.style.setProperty("--diffs-fg",fe.fg);const me=d?ae:Ne,Y=d?xe:se,Se=d?Z:ie;me&&ee.style.setProperty("--diffs-addition-color-override",me),Y&&ee.style.setProperty("--diffs-deletion-color-override",Y),Se&&ee.style.setProperty("--diffs-modified-color-override",Se);const we=ee.shadowRoot?.querySelector("pre");we&&(we.style.setProperty("--shiki-light",J.fg),we.style.setProperty("--shiki-light-bg",J.bg),Ne&&we.style.setProperty("--shiki-light-addition-color",Ne),se&&we.style.setProperty("--shiki-light-deletion-color",se),ie&&we.style.setProperty("--shiki-light-modified-color",ie),we.style.setProperty("--shiki-dark",ne.fg),we.style.setProperty("--shiki-dark-bg",ne.bg),ae&&we.style.setProperty("--shiki-dark-addition-color",ae),xe&&we.style.setProperty("--shiki-dark-deletion-color",xe),Z&&we.style.setProperty("--shiki-dark-modified-color",Z),we.style.setProperty("--diffs-bg",fe.bg),we.style.setProperty("--diffs-fg",fe.fg),me&&we.style.setProperty("--diffs-addition-color-override",me),Y&&we.style.setProperty("--diffs-deletion-color-override",Y),Se&&we.style.setProperty("--diffs-modified-color-override",Se))},[ne,V,d,J]);const ue=Ve.useMemo(()=>Math.max(t.length,e.length)>L0,[t.length,e.length]),de=Ve.useMemo(()=>({theme:{dark:m.metadata.id,light:f.metadata.id},themeType:d?"dark":"light",diffStyle:a?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:ue?0:1e3,maxLineLengthForHighlighting:ue?1:1e3,expansionLineCount:20,overflow:i?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:!0,enableHoverUtility:!1,onLineSelected:T,unsafeCSS:O0,renderAnnotation:M}),[m.metadata.id,d,ue,f.metadata.id,a,i,T,M]),pe=Ve.useMemo(()=>P0({drafts:b,editingDraftId:j,selection:g}),[j,b,g]),W=Ve.useRef(pe);if(Ve.useEffect(()=>{W.current=pe},[pe]),Ve.useEffect(()=>{if(typeof window>"u")return;const X=O.current;if(!X||!H)return;B.current?.cleanUp(),B.current=null,G.current?.release(),G.current=null,X.innerHTML="";const ee=U0(X);G.current=ee;const fe=ee?new Fx(de,ee.virtualizer,V0,H):new Lx(de,H);B.current=fe,P.current=null;const be={name:r||"",contents:t,lang:n,cacheKey:`old:${V}:${r}:${Gm(t)}`},Ne={name:r||"",contents:e,lang:n,cacheKey:`new:${V}:${r}:${Gm(e)}`};return fe.render({oldFile:be,newFile:Ne,lineAnnotations:W.current,containerWrapper:X}),requestAnimationFrame(()=>{R()}),()=>{fe.cleanUp(),B.current===fe&&(B.current=null),ee?.release(),ee&&G.current===ee&&(G.current=null),X.innerHTML=""}},[V,r,n,e,de,t,H]),Ve.useEffect(()=>{const X=B.current;if(X){try{X.setLineAnnotations(pe)}catch(ee){console.error("Failed to apply diff line annotations",ee);try{X.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(B.current===X){try{X.rerender()}catch{}R()}})}},[pe]),Ve.useEffect(()=>{const X=B.current;if(!X||g!==null)return;const ee=P.current;if(!B0(g,ee))try{E.current=!0,X.setSelectedLines(g),P.current=g}catch{}finally{E.current=!1}},[g]),Ve.useEffect(()=>{const X=O.current;if(!X)return;let ee=null,fe=()=>{};const be=()=>{const se=X.querySelector("diffs-container")?.shadowRoot;if(!se){ee=requestAnimationFrame(be);return}const ie=ae=>{if(!(ae instanceof MouseEvent)||ae.button!==0||!(ae.target instanceof Element))return;const xe=ae.target.closest("[data-column-number]");if(!(xe instanceof HTMLElement))return;const Z=xe.getAttribute("data-column-number"),me=Z?parseInt(Z,10):NaN;if(Number.isNaN(me))return;const Y=_(xe);T({start:me,end:me,side:Y}),ae.preventDefault(),ae.stopPropagation()};se.addEventListener("click",ie,!0),fe=()=>{se.removeEventListener("click",ie,!0)}};return be(),()=>{ee!==null&&cancelAnimationFrame(ee),fe()}},[V,r,T,_]),Ve.useEffect(()=>{const X=O.current;if(!X)return;let ee=null,fe=null;const Ne=setTimeout(()=>{const se=X.querySelector("diffs-container");if(!(se instanceof HTMLElement))return;const ie=se.shadowRoot;ee=new MutationObserver(()=>{fe&&cancelAnimationFrame(fe),fe=requestAnimationFrame(()=>{R(),fe=null})}),ee.observe(se,{childList:!0,subtree:!0}),ie&&ee.observe(ie,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(Ne),fe&&cancelAnimationFrame(fe),ee?.disconnect()}},[V,r]),typeof window>"u")return null;const te=s.jsx(D0,{diffRootRef:$,drafts:b,selection:g,editingDraftId:j,commentText:x,fileLabel:r?.split("/").pop()??"",onSave:D,onCancel:S,onEdit:X=>{F({start:X.startLine,end:X.endLine,side:X.side==="original"?"deletions":"additions"}),k(X)},onDelete:w});return l==="fill"?s.jsx("div",{className:ge("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(vs,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:s.jsx("div",{ref:$,className:"size-full relative",children:s.jsx("div",{ref:O,className:"size-full"})})}),te]})}):s.jsxs("div",{className:ge("relative","w-full"),children:[s.jsx("div",{ref:$,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:s.jsx("div",{ref:O,className:"w-full"})}),te]})},ha=8,W0=t=>{const e=ot.c(18),{laned:n,totalLanes:r,isExpanded:a}=t,{lane:i,color:l,connectors:c}=n,f=Math.max(r,i+1)*ha+ha/2,m=o.useRef(null),u=o.useRef(null);let p;e[0]!==l||e[1]!==c||e[2]!==i||e[3]!==f?(p=()=>{const h=m.current,j=u.current;if(!h||!j)return;const v=h.offsetHeight;if(v===0)return;const C=window.devicePixelRatio||1;j.width=f*C,j.height=v*C;const k=j.getContext("2d");if(!k)return;k.scale(C,C),k.clearRect(0,0,f,v);const w=v/2,N=i*ha+ha/2,I=getComputedStyle(j),E=I.getPropertyValue("--surface-muted-foreground").trim()||I.color,P=M=>{if(!M.startsWith("var("))return M;const D=M.slice(4,-1).trim();return I.getPropertyValue(D).trim()||E},T=[...c].sort(H0);for(const M of T){const D=M.fromLane*ha+ha/2,F=M.toLane*ha+ha/2,_=M.type==="passing"?.72:M.type==="branch-out"||M.type==="merge-in"?.95:1;k.beginPath(),k.strokeStyle=P(M.color),k.globalAlpha=_,k.lineWidth=1.25,k.lineCap="round";e:switch(M.type){case"passing":case"commit-lane":{k.moveTo(D,0),k.lineTo(D,v);break e}case"top-stub":{k.moveTo(D,0),k.lineTo(D,w);break e}case"bottom-stub":{k.moveTo(D,w),k.lineTo(D,v);break e}case"branch-out":{const V=(w+v)/2;k.moveTo(N,w),k.bezierCurveTo(N,V,F,V,F,v);break e}case"merge-in":{const V=w/2;k.moveTo(D,0),k.bezierCurveTo(D,V,N,V,N,w);break e}default:continue}k.stroke(),k.globalAlpha=1}const S=I.getPropertyValue("--background").trim()||I.getPropertyValue("--surface-background").trim();k.beginPath(),k.arc(N,w,4,0,Math.PI*2),k.fillStyle=P(l),k.fill(),k.beginPath(),k.arc(N,w,5,0,Math.PI*2),k.strokeStyle=S||E,k.lineWidth=2,k.stroke()},e[0]=l,e[1]=c,e[2]=i,e[3]=f,e[4]=p):p=e[4];let b;e[5]!==l||e[6]!==c||e[7]!==a||e[8]!==i||e[9]!==n||e[10]!==r||e[11]!==f?(b=[n,i,l,c,r,a,f],e[5]=l,e[6]=c,e[7]=a,e[8]=i,e[9]=n,e[10]=r,e[11]=f,e[12]=b):b=e[12],o.useLayoutEffect(p,b);let g;e[13]!==f?(g={width:f,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=f,e[14]=g):g=e[14];let y;e[15]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("canvas",{ref:u,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=y):y=e[15];let x;return e[16]!==g?(x=s.jsx("div",{ref:m,style:g,children:y}),e[16]=g,e[17]=x):x=e[17],x};function K0(t){return t==="branch-out"||t==="merge-in"}function H0(t,e){const n=K0;return(n(t.type)?1:0)-(n(e.type)?1:0)}const qm=15e3,Jm=500,Ym=12,Qm=8*1024*1024,Xm=t=>typeof t=="string"?0:(t.original?.length??0)+(t.modified?.length??0),Zm=t=>{if(t.size<=Ym){let a=0;for(const i of t.values())a+=Xm(i);if(a<=Qm)return t}const e=Array.from(t.entries()).reverse(),n=new Map;let r=0;for(const[a,i]of e){if(n.size>=Ym)continue;const l=Xm(i);r+l>Qm&&n.size>0||(n.set(a,i),r+=l)}return new Map(Array.from(n.entries()).reverse())};function ep(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 G0(t){switch(t){case"A":return"text-[var(--status-success)]";case"D":return"text-[var(--status-error)]";case"M":return"text-[var(--status-warning)]";case"R":return"text-[var(--status-info)]";default:return"text-muted-foreground"}}function q0(t){return t?t.split(",").map(e=>e.trim()).filter(Boolean).map(e=>{const n=e.startsWith("HEAD ->");return{label:n?e.replace("HEAD -> ",""):e.replace("tag: ",""),isHead:n,isTag:e.startsWith("tag: ")}}):[]}const J0=o.memo(({entry:t,mode:e="history",laned:n,totalLanes:r,isExpanded:a,onToggle:i,files:l,isLoadingFiles:c,onCopyHash:d,directory:f,onConflict:m,onActionSuccess:u})=>{const{t:p}=pt(),b=e==="graph",[g,y]=o.useState(null),[x,h]=o.useState(!1),[j,v]=o.useState(""),[C,k]=o.useState(null),[w,N]=o.useState(new Set),[I,E]=o.useState(new Map),[P,T]=o.useState(new Set),S=async()=>{if(f){y("checkout");try{await sy(f,t.hash),K.success(p("gitView.history.actions.detachedHead")),u?.()}catch(R){K.error(String(R.message))}finally{y(null)}}},M=async()=>{if(!(!f||!j.trim())){y("createBranch");try{await Yb(f,j.trim(),t.hash),h(!1),v(""),u?.()}catch(R){K.error(String(R.message))}finally{y(null)}}},D=async()=>{if(f){y("cherryPick");try{const R=await ty(f,t.hash);R.conflict?m?.({conflict:!0,conflictFiles:R.conflictFiles,operation:"cherry-pick"}):u?.()}catch(R){K.error(String(R.message))}finally{y(null)}}},F=async()=>{if(f){y("revert");try{const R=await ey(f,t.hash);R.conflict?m?.({conflict:!0,conflictFiles:R.conflictFiles,operation:"revert"}):u?.()}catch(R){K.error(String(R.message))}finally{y(null)}}},_=async(R,H=!1)=>{if(!(!f||g!==null)){y("reset");try{await Qb(f,t.hash,R,H),u?.()}catch(J){K.error(String(J.message))}finally{y(null)}}},V=async()=>{if(!C)return;const R=C;switch(k(null),R){case"checkout":return S();case"cherryPick":return D();case"revert":return F();case"merge":return $();case"rebase":return O();case"resetSoft":return _("soft");case"resetMixed":return _("mixed");case"resetHard":return _("hard",!0)}},$=async()=>{if(f){y("merge");try{const R=await Zb(f,{branch:t.hash});R.conflict?m?.({conflict:!0,conflictFiles:R.conflictFiles,operation:"merge"}):u?.()}catch(R){K.error(String(R.message))}finally{y(null)}}},O=async()=>{if(f){y("rebase");try{const R=await Xb(f,{onto:t.hash});R.conflict?m?.({conflict:!0,conflictFiles:R.conflictFiles,operation:"rebase"}):u?.()}catch(R){K.error(String(R.message))}finally{y(null)}}},B=o.useCallback(async R=>{const H=R.path;if(!f){E(J=>new Map(J).set(H,"error"));return}E(J=>Zm(new Map(J).set(H,"loading")));try{const J=Jb(f,t.hash,R.path,!1),ne=new Promise((de,pe)=>{setTimeout(()=>pe(new Error(`Timed out after ${qm}ms`)),qm)}),ue=await Promise.race([J,ne]);E(de=>Zm(new Map(de).set(H,ue)))}catch{E(J=>new Map(J).set(H,"error"))}},[f,t.hash]),G=o.useCallback(async R=>{const H=R.path;if(R.changeType==="R"||R.isBinary){N(de=>{const pe=new Set(de);return pe.has(H)?pe.delete(H):pe.add(H),pe});return}const J=I.get(H);if(w.has(H)&&J&&J!=="error"){N(de=>{const pe=new Set(de);return pe.delete(H),pe});return}N(de=>{const pe=new Set(de);return pe.add(H),pe}),!(J&&J!=="error"||R.insertions+R.deletions>Jm&&!P.has(H))&&await B(R)},[I,P,B,w]);return s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:i,className:ge("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",b?"hover:bg-[var(--interactive-hover)]/40":a?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[b&&n&&r!==void 0?s.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:s.jsx(W0,{laned:n,totalLanes:r,isExpanded:a})}):s.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),s.jsxs("div",{className:"min-w-0 flex-1",children:[b?(()=>{const R=q0(t.refs);return R.length>0?s.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:R.map(H=>s.jsx("span",{className:ge("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",H.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":H.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:H.label},H.label))}):null})():null,s.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:t.message}),s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[s.jsx("span",{className:"truncate min-w-[3ch]",title:t.author_name,children:t.author_name}),s.jsx("span",{className:"shrink-0",children:"·"}),s.jsx("span",{className:"truncate min-w-0",title:ep(t.date),children:ep(t.date)})]}),s.jsx("span",{className:"shrink-0",children:"·"}),s.jsx("code",{className:"shrink-0 font-mono",children:t.hash.slice(0,8)}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(he,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:R=>{R.stopPropagation(),d(t.hash)},children:s.jsx(A,{name:"file-copy",className:"size-3"})})}),s.jsx(At,{sideOffset:8,children:p("gitView.history.copySha")})]})]})]})]}),a&&s.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[b&&C?s.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:p(`gitView.history.actions.${C}Confirm`)}),s.jsxs(he,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:g!==null,onClick:R=>{R.stopPropagation(),V()},children:[g!==null?s.jsx(A,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,p("gitView.history.actions.confirmButton")]}),s.jsx(he,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:g!==null,onClick:R=>{R.stopPropagation(),k(null)},children:p("gitView.history.actions.cancelButton")})]}):b?s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[s.jsx(he,{variant:"outline",size:"xs",className:"h-6",disabled:g!==null,onClick:R=>{R.stopPropagation(),k("checkout")},children:p("gitView.history.actions.checkout")}),x?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("input",{autoFocus:!0,value:j,onChange:R=>v(R.target.value),onKeyDown:R=>{R.key==="Enter"&&M(),R.key==="Escape"&&(h(!1),v(""))},placeholder:p("gitView.history.actions.createBranchPlaceholder"),className:"h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32"}),s.jsxs(he,{variant:"outline",size:"xs",className:"h-6",disabled:!j.trim()||g!==null,onClick:R=>{R.stopPropagation(),M()},children:[g==="createBranch"?s.jsx(A,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,p("gitView.history.actions.createBranchConfirm")]})]}):s.jsx(he,{variant:"outline",size:"xs",className:"h-6",onClick:R=>{R.stopPropagation(),h(!0)},children:p("gitView.history.actions.createBranch")}),s.jsx(he,{variant:"outline",size:"xs",className:"h-6",disabled:g!==null,onClick:R=>{R.stopPropagation(),k("cherryPick")},children:p("gitView.history.actions.cherryPick")}),s.jsx(he,{variant:"outline",size:"xs",className:"h-6",disabled:g!==null,onClick:R=>{R.stopPropagation(),k("revert")},children:p("gitView.history.actions.revert")}),s.jsxs(As,{children:[s.jsx(Is,{asChild:!0,children:s.jsxs(he,{variant:"outline",size:"xs",className:"h-6",disabled:g!==null,onClick:R=>R.stopPropagation(),children:[g==="reset"?s.jsx(A,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,p("gitView.history.actions.reset")]})}),s.jsx(Ps,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(R=>s.jsx(Ot,{disabled:g!==null,onSelect:H=>{H.stopPropagation(),k(`reset${R.charAt(0).toUpperCase()+R.slice(1)}`)},children:p(`gitView.history.actions.reset${R.charAt(0).toUpperCase()+R.slice(1)}`)},R))})]}),s.jsx(he,{variant:"outline",size:"xs",className:"h-6",disabled:g!==null,onClick:R=>{R.stopPropagation(),k("merge")},children:p("gitView.history.actions.merge")}),s.jsx(he,{variant:"outline",size:"xs",className:"h-6",disabled:g!==null,onClick:R=>{R.stopPropagation(),k("rebase")},children:p("gitView.history.actions.rebase")})]}):null,c?s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(A,{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")})]}):l.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:l.map(R=>s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>G(R),className:ge("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",w.has(R.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[s.jsx("span",{className:ge("font-semibold w-3 text-center shrink-0",G0(R.changeType)),children:R.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:R.path,children:R.path}),!R.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",R.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",R.deletions]})]}),R.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:p("gitView.history.binary")}),s.jsx(A,{name:w.has(R.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),w.has(R.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:R.changeType==="R"?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.renamedNoDiff")}):R.isBinary?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.binaryNoDiff")}):(()=>{const H=R.insertions+R.deletions;if(!P.has(R.path)&&H>Jm)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:H})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:p("gitView.history.largeDiffDescription")}),s.jsx(he,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{T(ne=>new Set(ne).add(R.path)),B(R)},children:p("gitView.history.renderDiffAnyway")})]});const J=I.get(R.path);return J==="loading"||J===void 0?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.loadingDiff")}):J==="error"?s.jsx("button",{type:"button",onClick:()=>G(R),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(xu,{original:J.original,modified:J.modified,language:Pi(R.path)||"",fileName:R.path,renderSideBySide:!1,layout:"inline"})})()})]},R.path))})]})]})}),tp=["var(--chart-1)","var(--chart-2)","var(--chart-3)","var(--chart-4)","var(--chart-5)","var(--syntax-keyword)","var(--syntax-string)","var(--status-info)"];function Ko(t){return tp[t%tp.length]}function Y0(t){if(t.length===0)return[];const e=[],n=[];for(let r=0;r<t.length;r++){const a=t[r],i=[];for(let b=0;b<e.length;b++)e[b]===a.hash&&i.push(b);let l=i.length>0?i[0]:-1;if(l===-1){const b=e.indexOf(null);b!==-1?l=b:(l=e.length,e.push(null))}const c=i.slice(1),d=Ko(l),f=e[l]===a.hash,m=a.parents.length>0;m?e[l]=a.parents[0]:e[l]=null;const u=[];for(let b=1;b<a.parents.length;b++){const g=a.parents[b],y=e.indexOf(g);if(y!==-1)u.push(y);else{const x=e.indexOf(null),h=x!==-1?x:e.length;e[h]=g,h===e.length&&e.push(g),u.push(h)}}const p=[];f&&m?p.push({fromLane:l,toLane:l,color:d,type:"commit-lane"}):f&&!m?p.push({fromLane:l,toLane:l,color:d,type:"top-stub"}):!f&&m&&p.push({fromLane:l,toLane:l,color:d,type:"bottom-stub"});for(const b of c)p.push({fromLane:b,toLane:l,color:Ko(b),type:"merge-in"}),e[b]=null;for(const b of u)p.push({fromLane:l,toLane:b,color:Ko(b),type:"branch-out"});for(let b=0;b<e.length;b++)e[b]!==null&&b!==l&&(u.includes(b)||p.push({fromLane:b,toLane:b,color:Ko(b),type:"passing"}));n.push({commit:a,lane:l,color:d,connectors:p})}return n}const Q0=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],X0=t=>{const e=ot.c(84),{mode:n,log:r,isLogLoading:a,logMaxCount:i,onLogMaxCountChange:l,expandedCommitHashes:c,onToggleCommit:d,commitFilesMap:f,loadingCommitHashes:m,onCopyHash:u,directory:p,showHeader:b,contentMaxHeightClassName:g,branchDivider:y,onConflict:x,onActionSuccess:h}=t,j=n===void 0?"history":n,v=b===void 0?!0:b,C=g===void 0?"max-h-[50vh]":g,k=y===void 0?null:y,{t:w}=pt(),[N,I]=o.useState(!0),E=j==="graph";let P;e[0]!==E||e[1]!==r?(P=E&&r?Y0(r.all):[],e[0]=E,e[1]=r,e[2]=P):P=e[2];const T=P;let S;e[3]!==T?(S=Math.max(1,...T.map(Z0)),e[3]=T,e[4]=S):S=e[4];const M=S;let D;e[5]!==T?(D=new Map(T.map(eN)),e[5]=T,e[6]=D):D=e[6];const F=D;if(!r)return null;const _=k!==null&&k.insertBeforeIndex>0&&k.insertBeforeIndex<r.all.length,V=k!==null&&k.insertBeforeIndex===r.all.length,$=_||V;let O;e[7]!==k||e[8]!==_||e[9]!==V||e[10]!==r.all?(O=_?r.all.slice(0,k.insertBeforeIndex):V?r.all:[],e[7]=k,e[8]=_,e[9]=V,e[10]=r.all,e[11]=O):O=e[11];const B=O;let G;if(e[12]!==k||e[13]!==f||e[14]!==C||e[15]!==p||e[16]!==c||e[17]!==_||e[18]!==$||e[19]!==E||e[20]!==a||e[21]!==F||e[22]!==m||e[23]!==r.all||e[24]!==i||e[25]!==M||e[26]!==j||e[27]!==h||e[28]!==x||e[29]!==u||e[30]!==l||e[31]!==d||e[32]!==w||e[33]!==B){const X=_?r.all.slice(k.insertBeforeIndex):[];let ee;e[35]!==k?.direction?(ee=k?.direction==="down"?s.jsx(A,{name:"arrow-down-s",className:"size-3.5"}):s.jsx(A,{name:"arrow-up",className:"size-3.5"}),e[35]=k?.direction,e[36]=ee):ee=e[36];const fe=ee;let be;e[37]!==f||e[38]!==p||e[39]!==c||e[40]!==E||e[41]!==F||e[42]!==m||e[43]!==M||e[44]!==j||e[45]!==h||e[46]!==x||e[47]!==u||e[48]!==d?(be=ae=>s.jsx("ul",{className:"divide-y divide-border/60",children:ae.map(xe=>s.jsx(J0,{entry:xe,mode:j,laned:E?F.get(xe.hash):void 0,totalLanes:E?M:void 0,isExpanded:c.has(xe.hash),onToggle:()=>d(xe.hash),files:f.get(xe.hash)??[],isLoadingFiles:m.has(xe.hash),onCopyHash:u,directory:p,onConflict:x,onActionSuccess:h},xe.hash))}),e[37]=f,e[38]=p,e[39]=c,e[40]=E,e[41]=F,e[42]=m,e[43]=M,e[44]=j,e[45]=h,e[46]=x,e[47]=u,e[48]=d,e[49]=be):be=e[49];const Ne=be;let se;e[50]!==a||e[51]!==r.all.length||e[52]!==i||e[53]!==l||e[54]!==w?(se=r.all.length>=i?s.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:s.jsx(he,{type:"button",variant:"ghost",size:"xs",onClick:()=>l(i+25),disabled:a,className:"px-3 text-muted-foreground hover:text-foreground",children:a?s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(A,{name:"loader-4",className:"size-3 animate-spin"}),w("gitView.history.loadingMore")]}):w("gitView.history.loadMore")})}):null,e[50]=a,e[51]=r.all.length,e[52]=i,e[53]=l,e[54]=w,e[55]=se):se=e[55];const ie=se;G=s.jsx(vs,{outerClassName:`min-h-0 ${C}`,className:"h-full w-full",children:r.all.length===0?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:w("gitView.history.noCommits")})}):$&&k?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-col gap-0",children:[B.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:Ne(B)}):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:k.branchName,children:k.branchName}),fe]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),X.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:Ne(X)}):null]}),ie]}):s.jsxs(s.Fragment,{children:[Ne(r.all),ie]})}),e[12]=k,e[13]=f,e[14]=C,e[15]=p,e[16]=c,e[17]=_,e[18]=$,e[19]=E,e[20]=a,e[21]=F,e[22]=m,e[23]=r.all,e[24]=i,e[25]=M,e[26]=j,e[27]=h,e[28]=x,e[29]=u,e[30]=l,e[31]=d,e[32]=w,e[33]=B,e[34]=G}else G=e[34];const R=G;if(!v){if($){let ee;return e[56]!==R?(ee=s.jsx("section",{className:"h-full min-h-0",children:R}),e[56]=R,e[57]=ee):ee=e[57],ee}let X;return e[58]!==R?(X=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:R}),e[58]=R,e[59]=X):X=e[59],X}let H;e[60]!==w?(H=w("gitView.history.title"),e[60]=w,e[61]=H):H=e[61];let J;e[62]!==H?(J=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:H}),e[62]=H,e[63]=J):J=e[63];let ne;e[64]!==a||e[65]!==N||e[66]!==i||e[67]!==l||e[68]!==w?(ne=N&&s.jsx("div",{onClick:tN,onPointerDown:sN,children:s.jsxs(ns,{value:String(i),onValueChange:X=>l(Number(X)),disabled:a,children:[s.jsx(rs,{size:"sm",className:"data-[size=sm]:h-auto h-7 min-h-7 w-auto justify-between px-2 py-0",disabled:a,children:s.jsx(ms,{placeholder:w("gitView.history.commitsPlaceholder")})}),s.jsx(as,{children:Q0.map(X=>s.jsx(Rt,{value:String(X.value),children:w(X.labelKey)},X.value))})]})}),e[64]=a,e[65]=N,e[66]=i,e[67]=l,e[68]=w,e[69]=ne):ne=e[69];let ue;e[70]!==N?(ue=N?s.jsx(A,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=N,e[71]=ue):ue=e[71];let de;e[72]!==ne||e[73]!==ue?(de=s.jsxs("div",{className:"flex items-center gap-2",children:[ne,ue]}),e[72]=ne,e[73]=ue,e[74]=de):de=e[74];let pe;e[75]!==J||e[76]!==de?(pe=s.jsxs(Lr,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[J,de]}),e[75]=J,e[76]=de,e[77]=pe):pe=e[77];let W;e[78]!==R?(W=s.jsx(Nr,{children:R}),e[78]=R,e[79]=W):W=e[79];let te;return e[80]!==N||e[81]!==pe||e[82]!==W?(te=s.jsxs(jr,{open:N,onOpenChange:I,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[pe,W]}),e[80]=N,e[81]=pe,e[82]=W,e[83]=te):te=e[83],te};function Z0(t){return t.lane+1}function eN(t){return[t.commit.hash,t]}function tN(t){return t.stopPropagation()}function sN(t){return t.stopPropagation()}const gg=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 l=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},()=>l())),a},nN=9e4,rN=15e3,aN=5*6e4,iN=[2e3,5e3],oN=6e4,lN=2*6e4,cN=5*6e4,dN=4,uN=720*6e4,mN="openchamber.github-pr-status",pN=t=>t==="closed"||t==="merged",fN=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},lo=(t,e,n)=>`${t}::${e}`,Ho=new Map,Go=new Map,Ki=new Set,sp=new Map,to=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),Ul=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,bu=t=>{const e=Ul(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},xg=(t,e)=>Object.entries(t).filter(([,n])=>bu(n)===e).map(([n])=>n),hN=(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}}},qo=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},gN=(t,e,n)=>{const r=xg(t,e),a=r.map(d=>qo(t[d])).filter(d=>!!d);if(a.length===0)return null;const i=qo(t[n]);if(i&&bu(t[n])===e)return i;const l=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&qo(d)));if(l)return qo(l);const c=a.find(d=>!!d.remoteName);return c||(a[0]??null)},xN=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:Ul(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),bN=t=>({...to(),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}),yr=ar()(Fi((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:to()}})},setParams:(n,r)=>{t(a=>{const i=a.entries[n]??to();return{entries:{...a.entries,[n]:hN(i,r)}}})},startWatching:n=>{if(t(i=>{const l=i.entries[n]??to();return{entries:{...i.entries,[n]:{...l,watchers:l.watchers+1}}}}),Ho.has(n))return;const r=i=>{const l=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=Go.get(n)??[];c.push(l),Go.set(n,c)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),iN.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 f=Date.now();if(f-i.lastDiscoveryPollAt<aN)return;t(m=>{const u=m.entries[n];return u?{entries:{...m.entries,[n]:{...u,lastDiscoveryPollAt:f}}}:m}),e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}if(pN(i.status?.pr?.state))return;const c=Date.now()-i.lastRefreshAt,d=fN(i.status)?oN:i.status?.checks&&i.status.checks.state!=="pending"?cN:lN;c<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},rN);Ho.set(n,a)},stopWatching:n=>{t(l=>{const c=l.entries[n];if(!c)return l;const d=Math.max(0,c.watchers-1);return{entries:{...l.entries,[n]:{...c,watchers:d}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const a=Ho.get(n);typeof a=="number"&&window.clearInterval(a),Ho.delete(n);const i=Go.get(n);i&&i.length>0&&i.forEach(l=>{window.clearTimeout(l)}),Go.delete(n)},refresh:async(n,r)=>{const a=e(),i=a.entries[n],l=bu(i);if(!i||!l)return;const c=xg(a.entries,l),d=c.some(u=>!!a.entries[u]?.status?.pr);if(r?.onlyExistingPr&&!d)return;const f=sp.get(l)??0;if(!r?.force&&Date.now()-f<nN||Ki.has(l))return;const m=gN(a.entries,l,n);if(m){if(Ki.add(l),sp.set(l,Date.now()),t(u=>{const p={...u.entries};return c.forEach(b=>{const g=p[b];g&&(p[b]={...g,lastRefreshAt:Date.now(),isLoading:r?.silent?g.isLoading:!0,error:null})}),{entries:p}}),m.githubAuthChecked&&m.githubConnected===!1){t(u=>{const p={...u.entries};return c.forEach(b=>{const g=p[b];g&&(p[b]={...g,status:{connected:!1},error:null,isLoading:r?.silent?g.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?g.isInitialStatusResolved:!0})}),{entries:p}}),Ki.delete(l);return}if(!m.github?.prStatus){t(u=>{const p={...u.entries};return c.forEach(b=>{const g=p[b];g&&(p[b]={...g,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?g.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?g.isInitialStatusResolved:!0})}),{entries:p}}),Ki.delete(l);return}try{t(p=>({...p,activeRequestCount:p.activeRequestCount+1,totalRequestCount:p.totalRequestCount+1}));const u=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0,{force:r?.force});t(p=>{const b={...p.entries};return c.forEach(g=>{const y=b[g];if(!y)return;const x=y.status?.pr,h=u.pr,v=!!(h&&x&&h.number===x.number&&(!h.body||!h.body.trim())&&typeof x.body=="string"&&x.body.trim().length>0)&&h&&x?.body?{...u,pr:{...h,body:x.body}}:u,C=v.resolvedRemoteName??y.resolvedRemoteName??m.remoteName??null,k=Ul(y)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};b[g]={...y,status:v,error:null,isLoading:r?.silent?y.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?y.isInitialStatusResolved:!0,resolvedRemoteName:C,identity:{...k,remoteName:C??k.remoteName??null}}}),{entries:b}})}catch(u){const p=u instanceof Error?u.message:String(u);t(b=>{const g={...b.entries};return c.forEach(y=>{const x=g[y];x&&(g[y]={...x,error:p||"Failed to load PR status",isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0})}),{entries:g}})}finally{Ki.delete(l),t(u=>({...u,activeRequestCount:Math.max(0,u.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const a=Array.from(new Set(n.map(i=>{const l=i.directory.trim(),c=i.branch.trim();return!l||!c?null:lo(l,c,i.remoteName??null)}).filter(i=>!!i)));await gg(a,dN,i=>e().refresh(i,r))},updateStatus:(n,r)=>{t(a=>{const i=a.entries[n]??to();return{entries:{...a.entries,[n]:{...i,status:r(i.status)}}}})}}),{name:mN,storage:Co(()=>vr()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=Ul(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<uN}).map(([e,n])=>[e,xN(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([a,i])=>[a,bN(i)]))}}})),yN=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"},vN=t=>{const e=yN(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}},wN=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 Lc=new Map,np=new Map;const jN=t=>{const e=ot.c(2);let n;return e[0]!==t?(n=r=>{const a=new Map,i=new Map;for(const l of t){const c=r.entries[l];if(!c)continue;const d=vN(c);if(!d)continue;const f=wN(d);a.set(l,f),i.set(l,d)}if(a.size===Lc.size){let l=!0;for(const[c,d]of a)if(Lc.get(c)!==d){l=!1;break}if(l)return np}return Lc=a,np=i,i},e[0]=t,e[1]=n):n=e[1],yr(n)},NN=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"}},SN=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"},kN=[2e3,5e3],rp=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),ba=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):""},CN=(t,e)=>{const n=ba(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},IN=(t,e)=>`${t}::${e}`,yu=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},Oc=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const i=t.find(l=>l.name===n);if(i)return i}const r=yu(e.trackingBranch);if(r){const i=r==="origin"?t.find(c=>c.name==="upstream"):null;if(i)return i;const l=t.find(c=>c.name===r);if(l)return l}const a=t.find(i=>i.name==="origin");return a||(t[0]??null)},PN=t=>t.startsWith("pr-"),AN=(t,e)=>{const n=yu(e),r=new Map(t.map(l=>[l.name,l])),a=[],i=l=>{l&&(a.some(c=>c.name===l.name)||a.push(l))};return n&&i(r.get(n)),i(r.get("upstream")),i(r.get("origin")),t.filter(l=>!PN(l.name)).forEach(l=>i(l)),t.forEach(l=>i(l)),a},$c=new Map,_c=rr;function DN(t,e){const[n,r]=o.useState(null),[a,i]=o.useState([]),l=o.useRef(null);return o.useEffect(()=>{r(null),i([])},[t]),o.useEffect(()=>{if(!t||!e?.repoUpstream||l.current===t)return;l.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 f=await e.repoBranches(d.upstream.owner,d.upstream.repo);c||i(f)}catch{}}catch{}})(),()=>{c=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:a}}const TN=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:a=[],remoteBranches:i=[],onGeneratedDescription:l})=>{const{t:c}=pt(),{github:d}=Wn(),f=Yn(Ke=>Ke.status),m=Yn(Ke=>Ke.hasChecked),u=_e(Ke=>Ke.setSettingsDialogOpen),p=_e(Ke=>Ke.setSettingsPage),b=_e(Ke=>Ke.setActiveMainTab),g=Lt(Ke=>Ke.currentSessionId),{isMobile:y,hasTouchInput:x}=an(),h=o.useCallback(()=>{p("github"),u(!0)},[u,p]),j=o.useMemo(()=>IN(t,e),[t,e]),v=o.useMemo(()=>$c.get(j)??null,[j]),C=yr(Ke=>Ke.ensureEntry),k=yr(Ke=>Ke.setParams),w=yr(Ke=>Ke.startWatching),N=yr(Ke=>Ke.stopWatching),I=yr(Ke=>Ke.refresh),E=yr(Ke=>Ke.updateStatus),[P,T]=o.useState(()=>v?.title??rp(e)),[S,M]=o.useState(()=>v?.body??""),[D,F]=o.useState(()=>v?.draft??!1),[_,V]=o.useState(()=>v?.additionalContext??""),[$,O]=o.useState(()=>{const Ke=typeof v?.targetBaseBranch=="string"?ba(v.targetBaseBranch):"";return Ke||ba(n)}),[B,G]=o.useState("squash"),[R,H]=o.useState(!1),[J,ne]=o.useState(!1),[ue,de]=o.useState(!1),[pe,W]=o.useState(!1),[te,X]=o.useState(!1),[ee,fe]=o.useState(!1),[be,Ne]=o.useState(null),[se,ie]=o.useState(""),[ae,xe]=o.useState(""),[Z,me]=o.useState(!1),[Y,Se]=o.useState(!1),[we,ke]=o.useState(()=>Oc(a,{selectedRemoteName:v?.selectedRemoteName,trackingBranch:r})),[Fe,Ce]=o.useState(!1),{detectedUpstream:Q,upstreamBranches:ce}=DN(t,d);o.useEffect(()=>{Ce(!1)},[t]);const ve=a.some(Ke=>Ke.name==="upstream"),Ae=!!(t&&e&&n&&(e!==n||(ve||Q!==null))),Te=o.useMemo(()=>lo(t,e),[t,e]),$e=yr(Ke=>Ke.entries[Te]),ye=$e?.isLoading??!1,q=$e?.status??null,L=$e?.error??null,U=$e?.isInitialStatusResolved??!1,oe=o.useMemo(()=>{const Ke=Fe?null:we?.name?.trim()||null,Je=new Set;for(const Kt of i){const Tt=CN(Kt,Ke);!Tt||Tt==="HEAD"||Je.add(Tt)}if(Fe)for(const Kt of ce)Kt&&Kt!=="HEAD"&&Je.add(Kt);const Ct=ba(n);Ct&&Ct!=="HEAD"&&Je.add(Ct);const kt=ba($);return kt&&kt!=="HEAD"&&Je.add(kt),Array.from(Je).sort((Kt,Tt)=>Kt.localeCompare(Tt))},[n,i,we?.name,$,ce,Fe]);o.useEffect(()=>{if(a.length===0){we&&ke(null);return}(!we||!a.some(Ke=>Ke.name===we.name))&&ke(Oc(a,{selectedRemoteName:v?.selectedRemoteName,trackingBranch:r}))},[v?.selectedRemoteName,a,we,r]),o.useEffect(()=>{const Ke=ba(n);if(!$&&Ke){O(Ke);return}if(oe.length!==0&&!oe.includes($)){const Je=oe.includes(Ke)?Ke:oe[0];Je&&O(Je)}},[oe,n,$]);const[Ee,Oe]=o.useState(!1),[Ie,z]=o.useState(null),[De,Qe]=o.useState(!1),[tt,et]=o.useState(new Set),[We,at]=o.useState(!1),[qe,nt]=o.useState(null),[Ze,ze]=o.useState(!1),rt=o.useRef(new Set),Ge=o.useRef(null),ct=o.useRef(!1),Pe=o.useRef(new Set),Me=o.useRef([]);o.useEffect(()=>{Q&&!ve&&Ce(!0)},[Q,ve]),o.useEffect(()=>{Fe&&Q?.defaultBranch&&O(Q.defaultBranch)},[Fe,Q?.defaultBranch]);const Ue=q?.pr??null,He=Ue?`${t}#${Ue.number}`:null,lt=!!(He&&be===He);o.useEffect(()=>{if(!d?.prContext||!Ue||typeof Ue.body=="string"&&Ue.body.length>0)return;const Ke=`${t}#${Ue.number}`;if(rt.current.has(Ke))return;rt.current.add(Ke),Ne(Ke);let Je=!1;return d.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!1}).then(Ct=>{if(Je)return;const kt=Ct?.pr;kt&&E(Te,Kt=>!Kt?.pr||Kt.pr.number!==Ue.number?Kt:{...Kt,pr:{...Kt.pr,body:kt.body||""}})}).catch(()=>{}).finally(()=>{Je||Ne(Ct=>Ct===Ke?null:Ct)}),()=>{Je=!0}},[t,d,Ue,Te,E]),o.useEffect(()=>{if(!Ue){fe(!1),ie(""),xe(""),Ge.current=null;return}const Ke=Ge.current!==null&&Ge.current!==Ue.number;Ke&&fe(!1),(!ee||Ke)&&(ie(Ue.title||""),xe(Ue.body||"")),Ge.current=Ue.number},[ee,Ue]);const vt=o.useCallback(async()=>{if(!d?.prContext){K.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(Ue){Oe(!0),et(new Set),Qe(!0);try{const Ke=await d.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!0});z(Ke)}catch(Ke){const Je=Ke instanceof Error?Ke.message:String(Ke);K.error(c("gitView.pr.toast.loadCheckDetailsFailed"),{description:Je})}finally{Qe(!1)}}},[t,d,Ue,c]),ft=o.useCallback(async()=>{if(!d?.prContext){K.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(Ue){at(!0),ze(!0);try{const Ke=await d.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!1});nt(Ke)}catch(Ke){const Je=Ke instanceof Error?Ke.message:String(Ke);K.error(c("gitView.pr.toast.loadCommentsFailed"),{description:Je})}finally{ze(!1)}}},[t,d,Ue,c]),dt=o.useCallback(Ke=>{if(!Ke)return"";const Je=Date.parse(Ke);return Number.isFinite(Je)?new Date(Je).toLocaleString():Ke},[]),Dt=o.useMemo(()=>{const Ke=f?.user?.login;return typeof Ke=="string"?Ke.trim():""},[f]),Qt=o.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),Ft=o.useCallback(Ke=>{const Je=Dt.toLowerCase(),Ct=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return Ke.replace(Ct,(kt,Kt,Tt)=>{const gs=`@${Tt}`,js=Tt.toLowerCase();return`${Kt}[${gs}](https://github.com/${js}${Je&&js===Je?"?oc-self-mention=1":""})`})},[Dt]),qt=o.useMemo(()=>{const Ke=(qe?.issueComments??[]).map(kt=>({id:`issue-${kt.id}`,body:kt.body||"",authorName:kt.author?.name||kt.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:kt.author?.login||null,avatarUrl:kt.author?.avatarUrl||null,createdAt:kt.createdAt,context:c("gitView.pr.comments.generalContext"),path:null,line:null})),Je=(qe?.reviewComments??[]).map(kt=>({id:`review-${kt.id}`,body:kt.body||"",authorName:kt.author?.name||kt.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:kt.author?.login||null,avatarUrl:kt.author?.avatarUrl||null,createdAt:kt.createdAt,context:c("gitView.pr.comments.reviewContext"),path:kt.path||null,line:kt.line??null})),Ct=[...Ke,...Je];return Ct.sort((kt,Kt)=>{const Tt=kt.createdAt?Date.parse(kt.createdAt):0,gs=Kt.createdAt?Date.parse(Kt.createdAt):0,js=Number.isFinite(Tt)?Tt:0,Ls=Number.isFinite(gs)?gs:0;return js-Ls}),Ct},[qe,c]),gt=o.useCallback(()=>{if(!g)return K.error(c("gitView.pr.toast.noActiveSession"),{description:c("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:Ke,currentModelId:Je,currentAgentName:Ct,currentVariant:kt}=jt.getState(),Kt=tc.getState().lastUsedProvider,Tt=Ke||Kt?.providerID,gs=Je||Kt?.modelID;return!Tt||!gs?(K.error(c("gitView.pr.toast.noModelSelected")),null):{sessionId:g,providerID:Tt,modelID:gs,currentAgentName:Ct??null,currentVariant:kt??null}},[g,c]),zt=o.useCallback((Ke,Je,Ct,kt)=>{Lt.getState().sendMessage(Je,Ke.providerID,Ke.modelID,Ke.currentAgentName??void 0,void 0,void 0,[{text:Ct,synthetic:!0},{text:kt,synthetic:!0}],Ke.currentVariant??void 0).catch(Kt=>{const Tt=Kt instanceof Error?Kt.message:String(Kt);K.error(c("gitView.pr.toast.sendMessageFailed"),{description:Tt})})},[c]),es=o.useCallback(Ke=>{const Je=Ke.status||"unknown",Ct=Ke.conclusion??void 0,kt=Ct?`${Je} / ${Ct}`:Je,Kt=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:Kt?`${Kt} · ${kt}`:kt})]}),Ke.detailsUrl?s.jsx(he,{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(A,{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((Tt,gs)=>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:[Tt.title||Tt.level||"Issue",Tt.path?` · ${Tt.path}`:"",typeof Tt.startLine=="number"?`:${Tt.startLine}`:"",typeof Tt.endLine=="number"&&Tt.endLine!==Tt.startLine?`-${Tt.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:Tt.message}),Tt.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:Tt.rawDetails}):null]},`${Tt.path||"file"}:${Tt.startLine||gs}:${gs}`))})]}):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((Tt,gs)=>{const js=(Tt.conclusion||"").toLowerCase(),Ls=js&&!["success","neutral","skipped"].includes(js),Os=`${Ke.id??"run"}:${Ke.job?.jobId??"job"}:${Tt.number??gs}:${Tt.name}`,tn=tt.has(Os);return Ls?s.jsxs(jr,{open:tn,children:[s.jsxs("button",{type:"button",onClick:()=>{et(cn=>{const Zs=new Set(cn);return Zs.has(Os)?Zs.delete(Os):Zs.add(Os),Zs})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(Ls?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[tn?s.jsx(A,{name:"arrow-down-s",className:"size-4"}):s.jsx(A,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:Tt.name}),Tt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Tt.conclusion}):null]}),s.jsx(Nr,{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 Tt.number=="number"?s.jsxs("div",{children:[c("gitView.pr.checks.stepLabel"),": ",Tt.number]}):null,Tt.status?s.jsxs("div",{children:[c("gitView.pr.checks.statusLabel"),": ",Tt.status]}):null,Tt.conclusion?s.jsxs("div",{children:[c("gitView.pr.checks.conclusionLabel"),": ",Tt.conclusion]}):null,Tt.startedAt?s.jsxs("div",{children:[c("gitView.pr.checks.startedLabel"),": ",dt(Tt.startedAt)]}):null,Tt.completedAt?s.jsxs("div",{children:[c("gitView.pr.checks.completedLabel"),": ",dt(Tt.completedAt)]}):null]})})]},Os):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:Tt.name}),Tt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Tt.conclusion}):null]},Os)})})]}):null]})},[tt,dt,c]),is=o.useCallback(async()=>{if(b("chat"),!d?.prContext){K.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Ue)return;const Ke=gt();if(Ke)try{const Je=await d.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!0}),kt=(Je.checkRuns??[]).filter(Ls=>{const Os=typeof Ls.conclusion=="string"?Ls.conclusion.toLowerCase():"";return Os?!["success","neutral","skipped"].includes(Os):!1});if(kt.length===0){K.message(c("gitView.pr.toast.noFailedChecks"));return}const Kt=await Cn("github.pr.checks.review.visible"),Tt=await Cn("github.pr.checks.review.instructions"),gs=kt.flatMap(Ls=>(Array.isArray(Ls.annotations)?Ls.annotations:[]).map(tn=>({run:Ls.name,level:tn.level,title:tn.title,path:tn.path,startLine:tn.startLine,endLine:tn.endLine,message:tn.message,rawDetails:tn.rawDetails}))),js=`GitHub PR failed checks (JSON)
|
|
39
|
+
${JSON.stringify({repo:Je.repo??null,pr:Je.pr??null,failedChecks:kt,failedAnnotations:gs},null,2)}`;zt(Ke,Kt,Tt,js)}catch(Je){const Ct=Je instanceof Error?Je.message:String(Je);K.error(c("gitView.pr.toast.loadChecksFailed"),{description:Ct})}},[t,zt,d,Ue,gt,b,c]),cs=o.useCallback(async()=>{if(b("chat"),!d?.prContext){K.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Ue)return;const Ke=gt();if(Ke)try{const Je=await d.prContext(t,Ue.number,{includeDiff:!1,includeCheckDetails:!1}),Ct=Je.issueComments??[],kt=Je.reviewComments??[];if(Ct.length+kt.length===0){K.message(c("gitView.pr.toast.noPrComments"));return}const Tt=await Cn("github.pr.comments.review.visible"),gs=await Cn("github.pr.comments.review.instructions"),js=`GitHub PR comments (JSON)
|
|
40
|
+
${JSON.stringify({repo:Je.repo??null,pr:Je.pr??null,issueComments:Ct,reviewComments:kt},null,2)}`;zt(Ke,Tt,gs,js)}catch(Je){const Ct=Je instanceof Error?Je.message:String(Je);K.error(c("gitView.pr.toast.loadPrCommentsFailed"),{description:Ct})}},[t,zt,d,Ue,gt,b,c]),hs=o.useCallback(async Ke=>{at(!1),b("chat");const Je=gt();if(!Je)return;const Ct=await Cn("github.pr.comment.single.visible"),kt=await Cn("github.pr.comment.single.instructions"),Kt=`GitHub PR comment (JSON)
|
|
41
|
+
${JSON.stringify({repo:qe?.repo??null,pr:qe?.pr??Ue??null,comment:Ke},null,2)}`;zt(Je,Ct,kt,Kt)},[qe,zt,Ue,gt,b]),_t=o.useCallback(async Ke=>{await I(Te,Ke)},[Te,I]),Ye=o.useCallback(()=>{Me.current.forEach(Ke=>{window.clearTimeout(Ke)}),Me.current=kN.map(Ke=>window.setTimeout(()=>{_t({force:!0,silent:!0,markInitialResolved:!0})},Ke))},[_t]);o.useEffect(()=>{if(!d?.prStatus||!Ae||a.length<=1||ct.current||q?.pr)return;const Ke=`${j}::${we?.name??""}`;if(Pe.current.has(Ke))return;Pe.current.add(Ke);const Je=AN(a,r).filter(Kt=>Kt.name!==we?.name);if(Je.length===0)return;let Ct=!1;return(async()=>{for(const Kt of Je){if(Ct)return;try{if(!(await d.prStatus(t,e,Kt.name))?.pr)continue;if(Ct)return;ke(gs=>gs?.name===Kt.name?gs:Kt);return}catch{}}})(),()=>{Ct=!0}},[e,Ae,t,d,a,we?.name,j,q?.pr,r]),o.useEffect(()=>{C(Te),k(Te,{directory:t,branch:e,remoteName:we?.name??null,canShow:Ae,github:d,githubAuthChecked:m,githubConnected:f?.connected??null})},[e,Ae,t,C,d,m,f?.connected,Te,we?.name,k]),o.useEffect(()=>(w(Te),()=>{N(Te)}),[Te,w,N]),o.useEffect(()=>{const Ke=$c.get(j)??null;T(Ke?.title??rp(e)),M(Ke?.body??""),F(Ke?.draft??!1),O(Ke?.targetBaseBranch?ba(Ke.targetBaseBranch):ba(n));const Je=Oc(a,{selectedRemoteName:Ke?.selectedRemoteName,trackingBranch:r});ke(Ct=>Ct?.name===Je?.name?Ct:Je)},[n,e,a,j,r]),o.useEffect(()=>{_t({markInitialResolved:!0})},[Te,_t]),o.useEffect(()=>{!Ae||!we?.name||_t({force:!0,silent:!0,markInitialResolved:!0})},[Ae,_t,we?.name]),o.useEffect(()=>{const Ke=q?.resolvedRemoteName?.trim();if(!Ke||ct.current)return;const Je=a.find(Ct=>Ct.name===Ke);Je&&ke(Ct=>Ct?.name===Je.name?Ct:Je)},[a,q?.resolvedRemoteName]),o.useEffect(()=>{const Ke=q?.pr?.state==="closed"||q?.pr?.state==="merged",Je=$e?.lastRefreshAt??0,Ct=Date.now()-Je>6e4,kt=!Ke&&Ct,Kt=()=>{kt&&_t({force:!0,silent:!0})},Tt=()=>{document.visibilityState==="visible"&&kt&&_t({force:!0,silent:!0})};return window.addEventListener("focus",Kt),document.addEventListener("visibilitychange",Tt),()=>{window.removeEventListener("focus",Kt),document.removeEventListener("visibilitychange",Tt)}},[_t,q?.pr?.state,$e?.lastRefreshAt]),o.useEffect(()=>{m&&f?.connected===!1&&_t({force:!0,silent:!0,markInitialResolved:!0})},[m,f,_t]),o.useEffect(()=>{!t||!e||$c.set(j,{title:P,body:S,draft:D,additionalContext:_,targetBaseBranch:$,selectedRemoteName:we?.name})},[j,P,S,D,_,$,we?.name,t,e]),o.useEffect(()=>{const Ke=Me.current;return()=>{Ke.forEach(Je=>{window.clearTimeout(Je)}),Me.current=[]}},[]);const Mt=o.useCallback(async()=>{if(!R&&t){H(!0);try{const Je={base:Fe&&Q?.defaultBranchSha?Q.defaultBranchSha:$,head:e};_&&(Je.context=_);const Ct=await ny(t,Je);Ct.title?.trim()&&T(Ct.title.trim()),Ct.body?.trim()&&M(Ct.body.trim()),l?.()}catch(Ke){const Je=Ke instanceof Error?Ke.message:String(Ke);K.error(c("gitView.pr.toast.generateDescriptionFailed"),{description:Je})}finally{H(!1)}}},[_,e,Q?.defaultBranchSha,t,R,l,$,c,Fe]),Bt=o.useCallback(async()=>{if(!d?.prCreate){K.error(c("gitView.pr.toast.githubApiUnavailable"));return}const Ke=P.trim();if(!Ke){K.error(c("gitView.pr.toast.titleRequired"));return}const Je=$.trim();if(!Je){K.error(c("gitView.pr.toast.baseBranchRequired"));return}if(!Fe&&Je===e){K.error(c("gitView.pr.toast.baseMustDifferFromHead"));return}ne(!0);try{const Ct=yu(r),kt=Fe&&Q,Kt=await d.prCreate({directory:t,title:Ke,head:e,base:Je,...S.trim()?{body:S}:{},draft:D,...kt?{targetRepo:{owner:Q.owner,repo:Q.repo},headRemote:"origin"}:{...we?{remote:we.name}:{},...Ct&&Ct!==we?.name?{headRemote:Ct}:{}}});K.success(c("gitView.pr.toast.prCreated")),E(Te,Tt=>Tt&&{...Tt,pr:Kt}),await _t({force:!0}),Ye()}catch(Ct){const kt=Ct instanceof Error?Ct.message:String(Ct);K.error(c("gitView.pr.toast.createPrFailed"),{description:kt})}finally{ne(!1)}},[S,e,Q,t,D,d,Te,_t,Ye,we,$,P,r,E,Fe,c]),wt=o.useCallback(async Ke=>{if(!d?.prMerge){K.error(c("gitView.pr.toast.githubApiUnavailable"));return}W(!0);try{const Je=await d.prMerge({directory:t,number:Ke.number,method:B});Je.merged?K.success(c("gitView.pr.toast.prMerged")):K.message(c("gitView.pr.toast.prNotMerged"),{description:Je.message||c("gitView.pr.notMergeable")}),await _t({force:!0}),Ye()}catch(Je){const Ct=Je instanceof Error?Je.message:String(Je);K.error(c("gitView.pr.toast.mergeFailed"),{description:Ct}),Ke.url&&_c(Ke.url)}finally{W(!1)}},[t,d,B,_t,Ye,c]),Zt=o.useCallback(async Ke=>{if(!d?.prReady){K.error(c("gitView.pr.toast.githubApiUnavailable"));return}X(!0);try{await d.prReady({directory:t,number:Ke.number}),K.success(c("gitView.pr.toast.markedReady")),await _t({force:!0}),Ye()}catch(Je){const Ct=Je instanceof Error?Je.message:String(Je);K.error(c("gitView.pr.toast.markReadyFailed"),{description:Ct}),Ke.url&&_c(Ke.url)}finally{X(!1)}},[t,d,_t,Ye,c]),us=o.useCallback(async Ke=>{if(!d?.prUpdate){K.error(c("gitView.pr.toast.githubApiUnavailable"));return}const Je=se.trim();if(!Je){K.error(c("gitView.pr.toast.titleRequired"));return}de(!0);try{const Ct=await d.prUpdate({directory:t,number:Ke.number,title:Je,body:ae});E(Te,kt=>kt&&{...kt,pr:{...kt.pr??Ke,...Ct}}),fe(!1),K.success(c("gitView.pr.toast.prUpdated")),await _t({force:!0}),Ye()}catch(Ct){const kt=Ct instanceof Error?Ct.message:String(Ct);K.error(c("gitView.pr.toast.updatePrFailed"),{description:kt})}finally{de(!1)}},[t,ae,se,d,Te,_t,Ye,E,c]);if(!Ae)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 Es=q?.repo?.url||null,ws=Fe&&Q?.url?Q.url:Es,Ds=q?.checks??null,Xt=!!q?.canMerge,en=!!q?.connected,Ks=m&&q?.connected===!1,Us=SN(q),Xs=Us?`var(--pr-${Us})`:"var(--status-info)",re=Us==="draft"?"git-pr-draft":Us==="merged"?"git-merge":Us==="closed"?"git-close-pull-request":"git-pull-request",bt=Ue?[`${Ue.state}${Ue.draft?" (draft)":""}`,Ue.mergeable===!1?c("gitView.pr.notMergeable"):null,Ue.state==="open"&&typeof Ue.mergeableState=="string"&&Ue.mergeableState&&Ue.mergeableState!=="unknown"?Ue.mergeableState:null].filter(Boolean).join(" · "):"",Et=Ds?Ds.total>0?`${Ds.success}/${Ds.total} ${c("gitView.pr.checks.label")}`:`${Ds.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:[Ue?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:()=>{_c(Ue.url)},"aria-label":c("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(A,{name:re,className:"size-4 shrink-0",style:{color:Xs}})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(A,{name:re,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")}),Ue?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",Ue.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[ye?s.jsx(A,{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:ye,onClick:()=>{_t({force:!0})},"aria-label":c("gitView.pr.actions.refreshAria"),children:s.jsx(A,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.refresh")})})]})]})]}),Ue?s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 typography-micro text-muted-foreground",children:[s.jsx("span",{style:{color:Xs},children:bt}),Ds?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${NN(Ds.state)}`}),Et]}):null,r&&we&&r.split("/")[0]!==we.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",we.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[Ks?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.githubNotConnected")}),s.jsx(he,{variant:"outline",size:"sm",onClick:h,className:"w-fit",children:c("gitView.pr.actions.openSettings")})]}):null,L?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:L}),ws?s.jsx(he,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:ws,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(A,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!Ue&&!U&&!L&&!Ks?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),c("gitView.pr.checkingStatus")]}):Ue?s.jsx("div",{className:"flex flex-col gap-2",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[ee?s.jsxs("div",{className:"space-y-2",children:[s.jsx($t,{value:se,onChange:Ke=>ie(Ke.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x}),s.jsx(ln,{value:ae,onChange:Ke=>xe(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:Ue.title}),Ue.body?.trim()?s.jsx(Na,{content:Ue.body,className:"typography-markdown-body text-muted-foreground break-words mt-1"}):s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:c(lt?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),Xt&&Ue.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.draftMustBeReady")}):null,Xt?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:[Ue.state==="open"?ee?s.jsxs(s.Fragment,{children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(he,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{fe(!1),ie(Ue.title||""),xe(Ue.body||"")},disabled:ue,"aria-label":c("gitView.pr.actions.cancelEditingAria"),children:s.jsx(A,{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(he,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>us(Ue),disabled:ue||!se.trim(),"aria-label":c("gitView.pr.actions.savePrAria"),children:ue?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{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(he,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>fe(!0),"aria-label":c("gitView.pr.actions.editPrAria"),children:s.jsx(A,{name:"edit",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.editPr")})})]}):null,Ds?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(he,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:vt,disabled:De,"aria-label":c("gitView.pr.actions.openChecksAria"),children:De?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"information",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.openChecks")})})]}):null,Ds?.failure?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(he,{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:is,"aria-label":c("gitView.pr.actions.resolveFailedChecksAria"),children:s.jsx(A,{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(he,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:ft,"aria-label":c("gitView.pr.actions.openCommentsAria"),children:s.jsx(A,{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(he,{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:cs,"aria-label":c("gitView.pr.actions.shareCommentsAria"),children:s.jsx(A,{name:"ai-generate-2",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.shareComments")})})]}),Xt&&Ue.draft&&Ue.state==="open"?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(he,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Zt(Ue),disabled:te||pe||ue||ee,"aria-label":c("gitView.pr.actions.markReadyAria"),children:te?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{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:Xt?s.jsxs(s.Fragment,{children:[s.jsxs(ns,{value:B,onValueChange:Ke=>G(Ke),disabled:pe||Ue.state!=="open",children:[s.jsx(rs,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(ms,{})}),s.jsxs(as,{children:[s.jsx(Rt,{value:"squash",children:c("gitView.pr.mergeMethod.squash")}),s.jsx(Rt,{value:"merge",children:c("gitView.pr.mergeMethod.merge")}),s.jsx(Rt,{value:"rebase",children:c("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(he,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>wt(Ue),disabled:pe||te||Ue.state!=="open"||Ue.draft||ue||ee,"aria-label":c("gitView.pr.actions.mergePrAria"),children:pe?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{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)"})," → ",$," ",s.jsxs("span",{className:"opacity-60",children:["(",Fe&&Q?"upstream":"remote",")"]})]})]}),ws?s.jsx(he,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:ws,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(A,{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($t,{value:P,onChange:Ke=>T(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")}),oe.length>0?s.jsxs(ns,{value:$,onValueChange:O,children:[s.jsx(rs,{className:"h-9",children:s.jsx(ms,{placeholder:c("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(as,{children:oe.map(Ke=>s.jsx(Rt,{value:Ke,children:Ke},Ke))})]}):s.jsx($t,{value:$,onChange:Ke=>O(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(ln,{value:S,onChange:Ke=>M(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":D,onClick:()=>F(Ke=>!Ke),onKeyDown:Ke=>{(Ke.key===" "||Ke.key==="Enter")&&(Ke.preventDefault(),F(Je=>!Je))},children:[s.jsx(fs,{size:"sm",checked:D,onChange:Ke=>F(Ke),ariaLabel:c("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:c("gitView.pr.field.draft")})]}),y?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(he,{variant:"outline",size:"sm",onClick:()=>Se(!0),children:_.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),_.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(jr,{open:Z,onOpenChange:me,children:[s.jsxs(Lr,{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:Z?c("gitView.pr.actions.hide"):_.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),s.jsx(Nr,{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(ln,{value:_,onChange:Ke=>V(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(Ur,{open:Y,onClose:()=>Se(!1),title:c("gitView.pr.additionalContext.title"),footer:s.jsx(he,{size:"sm",onClick:()=>Se(!1),className:"w-full",children:c("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(ln,{value:_,onChange:Ke=>V(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(he,{variant:"outline",size:"sm",onClick:Mt,disabled:R||J,children:[R?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"ai-generate-2",className:"size-4 text-primary"}),c("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(he,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Bt,disabled:J||!en||!$.trim()||!Fe&&$.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:J?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:c("gitView.pr.actions.createPr")})]})]})]})]}),s.jsx(ls,{open:Ee,onOpenChange:Oe,children:s.jsxs(os,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(ps,{children:[s.jsxs(ds,{className:"flex items-center gap-2",children:[s.jsx(A,{name:"git-pull-request",className:"h-5 w-5"}),c("gitView.pr.checkDetails.title")]}),s.jsx(ys,{children:Ue?c("gitView.pr.numberLabel",{number:Ue.number}):c("gitView.pullRequest.title")})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto mt-2",children:[De?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,De?null:s.jsx("div",{className:"space-y-3",children:Array.isArray(Ie?.checkRuns)&&Ie?.checkRuns.length>0?Ie.checkRuns.map((Ke,Je)=>{const Ct=`${Ke.id??"run"}:${Ke.job?.jobId??"job"}:${Ke.name}:${Je}`;return s.jsx("div",{className:"p-1",children:es(Ke)},Ct)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(ls,{open:We,onOpenChange:at,children:s.jsxs(os,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(ps,{children:s.jsxs(ds,{className:"flex items-center gap-2",children:[s.jsx(A,{name:"git-pull-request",className:"h-5 w-5"}),c("gitView.pr.comments.title"),Ue?s.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.numberLabel",{number:Ue.number})}):null]})}),s.jsxs(Io,{className:"mt-2 max-h-[66vh] overflow-y-auto overlay-scrollbar-target overlay-scrollbar-container",children:[Ze?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,Ze?null:s.jsx("div",{className:"space-y-4",children:qt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:qt.map((Ke,Je)=>{const Ct=(Ke.authorName||"?").charAt(0).toUpperCase(),kt=Je===qt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[kt?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:dt(Ke.createdAt)}):null,s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs(he,{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:()=>{hs(Ke)},"aria-label":c("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(A,{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(Na,{content:Ft(Ke.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",Qt].filter(Boolean).join(" ")})]})]},Ke.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.comments.empty")})})]})]})})]})},EN=t=>{const e=ot.c(150),{open:n,onOpenChange:r,conflictFiles:a,directory:i,operation:l,onAbort:c,onClearState:d}=t;let f;e[0]!==a?(f=a===void 0?[]:a,e[0]=a,e[1]=f):f=e[1];const m=f,{t:u}=pt(),p=Lt(MN),b=Lt(RN),g=qa(FN),y=qa(LN),x=_e(ON),[h,j]=o.useState(!1),[v,C]=o.useState(null),[k,w]=o.useState(null);let N,I;e[2]!==i||e[3]!==n||e[4]!==u?(N=()=>{!n||!i||(j(!0),w(null),C(null),ry(i).then(Ce=>{C(Ce)}).catch(Ce=>{const Q=Ce instanceof Error?Ce.message:u("gitView.conflict.loadFailed");w(Q)}).finally(()=>{j(!1)}))},I=[n,i,u],e[2]=i,e[3]=n,e[4]=u,e[5]=N,e[6]=I):(N=e[5],I=e[6]),o.useEffect(N,I);let E;e[7]!==v||e[8]!==i||e[9]!==l?(E=async()=>{if(!v)return null;const Ce=l==="merge"?"merge":"rebase",Q=v.headInfo||(l==="merge"?"MERGE_HEAD":"REBASE_HEAD"),ce=l==="merge"?"git commit --no-edit":"git rebase --continue",ve=await Cn("git.conflict.resolve.visible",{operation_label:Ce,head_ref:Q}),le=await Cn("git.conflict.resolve.instructions",{operation_label:Ce,directory:i,operation:l,head_info:v.headInfo||"N/A",continue_cmd:ce}),Ae=`${Ce} conflict context (JSON)
|
|
42
|
+
${JSON.stringify({directory:i,operation:v.operation,headInfo:v.headInfo,statusPorcelain:v.statusPorcelain,unmergedFiles:v.unmergedFiles,diff:v.diff},null,2)}`;return{visibleText:ve,instructionsText:le,payloadText:Ae}},e[7]=v,e[8]=i,e[9]=l,e[10]=E):E=e[10];const P=E;let T;e[11]!==c||e[12]!==r?(T=()=>{c(),r(!1)},e[11]=c,e[12]=r,e[13]=T):T=e[13];const S=T;let M;e[14]!==d||e[15]!==r?(M=()=>{d?.(),r(!1)},e[14]=d,e[15]=r,e[16]=M):M=e[16];const D=M;let F;e[17]!==P||e[18]!==b||e[19]!==d||e[20]!==r||e[21]!==x||e[22]!==g||e[23]!==y||e[24]!==u?(F=async()=>{const Ce=await P();if(!Ce){K.error(u("gitView.conflict.noDetailsAvailable"));return}if(!b){K.error(u("gitView.conflict.noActiveSession"),{description:u("gitView.conflict.noActiveSessionDescription")});return}g(Ce.visibleText,"replace"),y([{text:Ce.instructionsText,synthetic:!0},{text:Ce.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]=g,e[23]=y,e[24]=u,e[25]=F):F=e[25];const _=F;let V;e[26]!==P||e[27]!==i||e[28]!==d||e[29]!==r||e[30]!==p||e[31]!==x||e[32]!==u?(V=async()=>{const Ce=await P();if(!Ce){K.error(u("gitView.conflict.noDetailsAvailable"));return}p({directoryOverride:i,initialPrompt:Ce.visibleText,syntheticParts:[{text:Ce.instructionsText,synthetic:!0},{text:Ce.payloadText,synthetic:!0}]}),x("chat"),d?.(),r(!1)},e[26]=P,e[27]=i,e[28]=d,e[29]=r,e[30]=p,e[31]=x,e[32]=u,e[33]=V):V=e[33];const $=V;let O,B,G,R,H,J,ne,ue,de,pe,W,te,X,ee,fe,be,Ne,se,ie,ae,xe,Z;if(e[34]!==v||e[35]!==m||e[36]!==b||e[37]!==S||e[38]!==D||e[39]!==_||e[40]!==$||e[41]!==h||e[42]!==k||e[43]!==r||e[44]!==n||e[45]!==l||e[46]!==u){const Ce=u(l==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),Q=v?.unmergedFiles||m;G=ls,xe=n,Z=r,B=os,ae="max-w-md w-[calc(100vw-2rem)]",ee="flex flex-col gap-4 overflow-hidden";let ce;e[69]===Symbol.for("react.memo_cache_sentinel")?(ce=s.jsx(A,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=ce):ce=e[69];const ve=s.jsxs("div",{className:"flex items-center gap-2",children:[ce,s.jsx(ds,{children:u("gitView.conflict.detectedTitle",{operation:Ce})})]});let le;e[70]!==l||e[71]!==u?(le=u("gitView.conflict.detectedDescription",{operation:l}),e[70]=l,e[71]=u,e[72]=le):le=e[72];let Ae;e[73]!==le?(Ae=s.jsx(ys,{children:le}),e[73]=le,e[74]=Ae):Ae=e[74],e[75]!==ve||e[76]!==Ae?(fe=s.jsxs(ps,{children:[ve,Ae]}),e[75]=ve,e[76]=Ae,e[77]=fe):fe=e[77],e[78]!==h||e[79]!==u?(be=h&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:u("gitView.conflict.loading")})]}),e[78]=h,e[79]=u,e[80]=be):be=e[80],e[81]!==k||e[82]!==u?(Ne=k&&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:k})}),e[81]=k,e[82]=u,e[83]=Ne):Ne=e[83],e[84]!==Q||e[85]!==u?(se=Q.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:Q.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:Q.map($N)})})]}),e[84]=Q,e[85]=u,e[86]=se):se=e[86],e[87]!==v||e[88]!==u?(ie=v?.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:v.headInfo})]}),e[87]=v,e[88]=u,e[89]=ie):ie=e[89],W="flex flex-col gap-2 pt-2";let Te;e[90]!==$?(Te=()=>{$()},e[90]=$,e[91]=Te):Te=e[91];const $e=h||!v;let ye;e[92]!==h?(ye=h?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"add",className:"size-4"}),e[92]=h,e[93]=ye):ye=e[93];let q;e[94]!==u?(q=u("gitView.conflict.resolveNewSession"),e[94]=u,e[95]=q):q=e[95],e[96]!==Te||e[97]!==$e||e[98]!==ye||e[99]!==q?(te=s.jsxs(he,{variant:"default",onClick:Te,disabled:$e,className:"w-full gap-2",children:[ye,q]}),e[96]=Te,e[97]=$e,e[98]=ye,e[99]=q,e[100]=te):te=e[100];let L;e[101]!==_?(L=()=>{_()},e[101]=_,e[102]=L):L=e[102];const U=h||!v||!b;let oe;e[103]!==h?(oe=h?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"chat-1",className:"size-4"}),e[103]=h,e[104]=oe):oe=e[104];let Ee;e[105]!==u?(Ee=u("gitView.conflict.resolveCurrentSession"),e[105]=u,e[106]=Ee):Ee=e[106],e[107]!==L||e[108]!==U||e[109]!==oe||e[110]!==Ee?(X=s.jsxs(he,{variant:"outline",onClick:L,disabled:U,className:"w-full gap-2",children:[oe,Ee]}),e[107]=L,e[108]=U,e[109]=oe,e[110]=Ee,e[111]=X):X=e[111],de="flex gap-2 pt-1";let Oe;e[112]!==u?(Oe=u("gitView.conflict.continueLater"),e[112]=u,e[113]=Oe):Oe=e[113],e[114]!==D||e[115]!==Oe?(pe=s.jsx(he,{variant:"ghost",size:"sm",onClick:D,className:"flex-1",children:Oe}),e[114]=D,e[115]=Oe,e[116]=pe):pe=e[116],O=he,R="destructive",H="sm",J=S,ne="flex-1",ue=u("gitView.conflict.abortOperation",{operation:Ce}),e[34]=v,e[35]=m,e[36]=b,e[37]=S,e[38]=D,e[39]=_,e[40]=$,e[41]=h,e[42]=k,e[43]=r,e[44]=n,e[45]=l,e[46]=u,e[47]=O,e[48]=B,e[49]=G,e[50]=R,e[51]=H,e[52]=J,e[53]=ne,e[54]=ue,e[55]=de,e[56]=pe,e[57]=W,e[58]=te,e[59]=X,e[60]=ee,e[61]=fe,e[62]=be,e[63]=Ne,e[64]=se,e[65]=ie,e[66]=ae,e[67]=xe,e[68]=Z}else O=e[47],B=e[48],G=e[49],R=e[50],H=e[51],J=e[52],ne=e[53],ue=e[54],de=e[55],pe=e[56],W=e[57],te=e[58],X=e[59],ee=e[60],fe=e[61],be=e[62],Ne=e[63],se=e[64],ie=e[65],ae=e[66],xe=e[67],Z=e[68];let me;e[117]!==O||e[118]!==R||e[119]!==H||e[120]!==J||e[121]!==ne||e[122]!==ue?(me=s.jsx(O,{variant:R,size:H,onClick:J,className:ne,children:ue}),e[117]=O,e[118]=R,e[119]=H,e[120]=J,e[121]=ne,e[122]=ue,e[123]=me):me=e[123];let Y;e[124]!==de||e[125]!==pe||e[126]!==me?(Y=s.jsxs("div",{className:de,children:[pe,me]}),e[124]=de,e[125]=pe,e[126]=me,e[127]=Y):Y=e[127];let Se;e[128]!==W||e[129]!==te||e[130]!==X||e[131]!==Y?(Se=s.jsxs("div",{className:W,children:[te,X,Y]}),e[128]=W,e[129]=te,e[130]=X,e[131]=Y,e[132]=Se):Se=e[132];let we;e[133]!==ee||e[134]!==fe||e[135]!==be||e[136]!==Ne||e[137]!==se||e[138]!==ie||e[139]!==Se?(we=s.jsxs("div",{className:ee,children:[fe,be,Ne,se,ie,Se]}),e[133]=ee,e[134]=fe,e[135]=be,e[136]=Ne,e[137]=se,e[138]=ie,e[139]=Se,e[140]=we):we=e[140];let ke;e[141]!==B||e[142]!==ae||e[143]!==we?(ke=s.jsx(B,{className:ae,children:we}),e[141]=B,e[142]=ae,e[143]=we,e[144]=ke):ke=e[144];let Fe;return e[145]!==G||e[146]!==xe||e[147]!==Z||e[148]!==ke?(Fe=s.jsx(G,{open:xe,onOpenChange:Z,children:ke}),e[145]=G,e[146]=xe,e[147]=Z,e[148]=ke,e[149]=Fe):Fe=e[149],Fe};function MN(t){return t.openNewSessionDraft}function RN(t){return t.currentSessionId}function FN(t){return t.setPendingInputText}function LN(t){return t.setPendingSyntheticParts}function ON(t){return t.setActiveMainTab}function $N(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const _N=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:a})=>{const{t:i}=pt(),[l,c]=o.useState(!0),[d,f]=o.useState(!1),m=i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),u=async()=>{f(!0);try{await a(l),e(!1)}catch(b){const g=b instanceof Error?b.message:`Failed to ${n}`;K.error(g)}finally{f(!1)}},p=()=>{d||e(!1)};return s.jsx(ls,{open:t,onOpenChange:d?void 0:e,children:s.jsxs(os,{className:"max-w-md",children:[s.jsxs(ps,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),s.jsx(ds,{children:i("gitView.stash.title")})]}),s.jsx(ys,{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})]}),l&&s.jsx("li",{children:i("gitView.stash.stepRestore")})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(fs,{checked:l,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(!l),children:i("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(Rs,{className:"gap-2",children:[s.jsx(he,{variant:"ghost",size:"sm",onClick:p,disabled:d,children:i("gitView.common.cancel")}),s.jsx(he,{variant:"default",size:"sm",onClick:u,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),i("gitView.common.processing")]}):i("gitView.stash.confirmButton",{operation:m})})]})]})})},BN=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:a,hasUnresolvedConflicts:i=!1,isLoading:l=!1})=>{const{t:c}=pt(),[d,f]=o.useState(null),m=t&&t.head,u=e&&(e.headName||e.onto),p=m?"merge":u?"rebase":null;if(!p)return null;const b=async()=>{f("continue");try{await n()}finally{f(null)}},g=async()=>{f("abort");try{await r()}finally{f(null)}},y=d!==null,x=c(p==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),h=p==="merge"?"git-merge":"git-branch";let j="";return t?j=t.message?c("gitView.operation.mergingMessage",{message:t.message}):c("gitView.operation.mergeInProgressWithHead",{head:t.head}):e&&(j=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(A,{name:h,className:"size-4 text-[var(--status-warning)] shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:c("gitView.operation.inProgressTitle",{operation:x})}),j&&s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:j})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i&&a&&s.jsxs(he,{variant:"outline",size:"sm",onClick:a,disabled:y||l,className:"gap-1.5",children:[s.jsx(A,{name:"sparkling",className:"size-4"}),c("gitView.operation.resolveWithAi")]}),d!=="continue"&&s.jsxs(he,{variant:"ghost",size:"sm",onClick:g,disabled:y||l,className:"gap-1.5",children:[d==="abort"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"close",className:"size-4"}),c("gitView.operation.abort")]}),!i&&s.jsxs(he,{variant:"default",size:"sm",onClick:b,disabled:y||l,className:"gap-1.5",children:[d==="continue"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{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")})]})})},VN=t=>{const e=ot.c(104),{currentBranch:n,localBranches:r,remoteBranches:a,onMerge:i,onRebase:l,disabled:c,isOperating:d,operationLogs:f,onOperationComplete:m,mode:u,defaultTargetBranch:p}=t,b=c===void 0?!1:c,g=d===void 0?!1:d,y=f===void 0?[]:f,x=u===void 0?"dialog":u,{t:h}=pt(),[j,v]=o.useState(!1),[C,k]=o.useState("merge"),[w,N]=o.useState(null),[I,E]=o.useState(!1),[P,T]=o.useState(""),S=o.useRef(null),M=o.useRef(null),D=b||g,F=n||h("gitView.branch.currentBranchFallback"),_=y.length>0&&y.every(zN),V=y.some(UN);let $;e[0]===Symbol.for("react.memo_cache_sentinel")?($=()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight)},e[0]=$):$=e[0],o.useEffect($,[y]);let O;if(e[1]!==P||e[2]!==n||e[3]!==r||e[4]!==a){e:{const L=P.toLowerCase();let U;e[6]!==a?(U=new Set(a.map(WN).filter(Boolean)),e[6]=a,e[7]=U):U=e[7];const oe=U;let Ee;e[8]!==n||e[9]!==oe?(Ee=Ie=>Ie!==n&&!oe.has(Ie),e[8]=n,e[9]=oe,e[10]=Ee):Ee=e[10];const Oe=r.filter(Ee);if(!L){O=Oe;break e}O=Oe.filter(Ie=>Ie.toLowerCase().includes(L))}e[1]=P,e[2]=n,e[3]=r,e[4]=a,e[5]=O}else O=e[5];const B=O;let G;if(e[11]!==P||e[12]!==a){e:{const L=P.toLowerCase();if(!L){G=a;break e}G=a.filter(U=>U.toLowerCase().includes(L))}e[11]=P,e[12]=a,e[13]=G}else G=e[13];const R=G;let H;e[14]!==p||e[15]!==r||e[16]!==a?(H=()=>p&&(a.includes(p)||r.includes(p))?p:null,e[14]=p,e[15]=r,e[16]=a,e[17]=H):H=e[17];const J=H;let ne;e[18]!==J||e[19]!==v?(ne=()=>{v(!0),N(J()),k("merge"),T("")},e[18]=J,e[19]=v,e[20]=ne):ne=e[20];const ue=ne;let de;e[21]===Symbol.for("react.memo_cache_sentinel")?(de=L=>{N(L),E(!1),T("")},e[21]=de):de=e[21];const pe=de;let W;e[22]!==i||e[23]!==l||e[24]!==C||e[25]!==w?(W=()=>{w&&(C==="merge"?i(w):l(w))},e[22]=i,e[23]=l,e[24]=C,e[25]=w,e[26]=W):W=e[26];const te=W;let X;e[27]!==g||e[28]!==v?(X=()=>{g||(N(null),k("merge"),T(""),v(!1))},e[27]=g,e[28]=v,e[29]=X):X=e[29];const ee=X,fe=()=>{g&&!_||(_&&m?.(),N(null),k("merge"),T(""),v(!1))};let be,Ne;e[30]!==I?(be=()=>{I||T("")},Ne=[I],e[30]=I,e[31]=be,e[32]=Ne):(be=e[31],Ne=e[32]),o.useEffect(be,Ne);let se,ie;e[33]!==x||e[34]!==J||e[35]!==w?(se=()=>{x!=="inline"||w||N(J())},ie=[x,J,w],e[33]=x,e[34]=J,e[35]=w,e[36]=se,e[37]=ie):(se=e[36],ie=e[37]),o.useEffect(se,ie);const Z=g?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:M,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:s.jsx("div",{className:"space-y-2",children:y.map(KN)})}),_?x==="dialog"?s.jsx(Rs,{children:s.jsx(he,{variant:"default",size:"sm",onClick:fe,children:h(V?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(he,{variant:"default",size:"sm",onClick:fe,children:h(V?"gitView.common.close":"gitView.common.done")})}):null]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:h("gitView.branch.operation")}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>k("merge"),className:ge("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",C==="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(A,{name:"git-merge",className:ge("size-4",C==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:ge("typography-ui-label",C==="merge"?"text-foreground":"text-muted-foreground"),children:h("gitView.operation.merge")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:h("gitView.branch.mergeDescription")})]}),s.jsxs("button",{type:"button",onClick:()=>k("rebase"),className:ge("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",C==="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(A,{name:"git-branch",className:ge("size-4",C==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:ge("typography-ui-label",C==="rebase"?"text-foreground":"text-muted-foreground"),children:h("gitView.operation.rebase")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:h("gitView.branch.rebaseDescription")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:C==="merge"?h("gitView.branch.branchToMergeInto",{branch:F}):h("gitView.branch.branchToRebaseOnto")}),s.jsxs(As,{open:I,onOpenChange:E,modal:!1,children:[s.jsx(Is,{asChild:!0,children:s.jsxs(he,{variant:"outline",size:"lg",className:"w-full justify-between",children:[s.jsx("span",{className:ge("truncate",!w&&"text-muted-foreground"),children:w||h("gitView.branch.selectBranch")}),s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),s.jsx(Ps,{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(Ya,{className:"h-full min-h-0",children:[s.jsx(Sa,{ref:S,placeholder:h("gitView.branch.searchPlaceholder"),value:P,onValueChange:T,onKeyDown:HN}),s.jsxs(Qa,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(Xa,{children:h("gitView.branch.empty")}),B.length>0&&s.jsx(Vn,{heading:h("gitView.branch.localBranches"),children:B.map(L=>s.jsx(En,{onSelect:()=>pe(L),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:L})},`local-${L}`))}),B.length>0&&R.length>0?s.jsx(Va,{}):null,R.length>0&&s.jsx(Vn,{heading:h("gitView.branch.remoteBranches"),children:R.map(L=>s.jsx(En,{onSelect:()=>pe(L),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:L})},`remote-${L}`))})]})]})})]})]}),w?s.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:C==="merge"?s.jsxs(s.Fragment,{children:[h("gitView.branch.summaryMergePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:w})," ",h("gitView.branch.summaryMergeInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:F})]}):s.jsxs(s.Fragment,{children:[h("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:F})," ",h("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:w})]})})}):null,x==="dialog"?s.jsxs(Rs,{className:"gap-2 pt-1",children:[s.jsx(he,{variant:"ghost",size:"sm",onClick:ee,children:h("gitView.common.cancel")}),s.jsx(he,{variant:"default",size:"sm",onClick:te,disabled:!w,className:"gap-1.5",children:C==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"git-merge",className:"size-4"}),h("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"git-branch",className:"size-4"}),h("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(he,{variant:"destructive",size:"sm",onClick:ee,disabled:D,children:h("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(he,{variant:"default",size:"sm",onClick:te,disabled:D||!w,children:h(C==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(x==="inline"){let L;e[38]!==h?(L=h("gitView.branch.updateTitle"),e[38]=h,e[39]=L):L=e[39];let U;e[40]!==L?(U=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:L}),e[40]=L,e[41]=U):U=e[41];let oe;e[42]!==h?(oe=h("gitView.branch.updateDescriptionPrefix"),e[42]=h,e[43]=oe):oe=e[43];let Ee;e[44]!==F?(Ee=s.jsx("span",{className:"font-mono text-foreground",children:F}),e[44]=F,e[45]=Ee):Ee=e[45];let Oe;e[46]!==oe||e[47]!==Ee?(Oe=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[oe," ",Ee,"."]}),e[46]=oe,e[47]=Ee,e[48]=Oe):Oe=e[48];let Ie;e[49]!==U||e[50]!==Oe?(Ie=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[U,Oe]})}),e[49]=U,e[50]=Oe,e[51]=Ie):Ie=e[51];let z;e[52]!==Z?(z=s.jsx("div",{className:"pt-3",children:Z}),e[52]=Z,e[53]=z):z=e[53];let De;return e[54]!==Ie||e[55]!==z?(De=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[Ie,z]}),e[54]=Ie,e[55]=z,e[56]=De):De=e[56],De}let me;e[57]!==g?(me=g?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"git-merge",className:"size-4"}),e[57]=g,e[58]=me):me=e[58];let Y;e[59]!==h?(Y=h("gitView.branch.mergeRebase"),e[59]=h,e[60]=Y):Y=e[60];let Se;e[61]!==Y?(Se=s.jsx("span",{children:Y}),e[61]=Y,e[62]=Se):Se=e[62];let we;e[63]!==ue||e[64]!==D||e[65]!==me||e[66]!==Se?(we=s.jsx(Pt,{asChild:!0,children:s.jsxs(he,{variant:"outline",size:"sm",className:"gap-1.5",onClick:ue,disabled:D,children:[me,Se]})}),e[63]=ue,e[64]=D,e[65]=me,e[66]=Se,e[67]=we):we=e[67];let ke;e[68]!==h?(ke=h("gitView.branch.mergeRebaseTooltip"),e[68]=h,e[69]=ke):ke=e[69];let Fe;e[70]!==ke?(Fe=s.jsx(At,{sideOffset:8,children:ke}),e[70]=ke,e[71]=Fe):Fe=e[71];let Ce;e[72]!==we||e[73]!==Fe?(Ce=s.jsxs(It,{children:[we,Fe]}),e[72]=we,e[73]=Fe,e[74]=Ce):Ce=e[74];let Q;e[75]!==fe||e[76]!==v?(Q=L=>{L?v(!0):fe()},e[75]=fe,e[76]=v,e[77]=Q):Q=e[77];let ce;e[78]!==h?(ce=h("gitView.branch.updateTitle"),e[78]=h,e[79]=ce):ce=e[79];let ve;e[80]!==ce?(ve=s.jsx(ds,{children:ce}),e[80]=ce,e[81]=ve):ve=e[81];let le;e[82]!==V||e[83]!==g||e[84]!==C||e[85]!==_||e[86]!==h||e[87]!==F?(le=g?h(_?V?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":C==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):s.jsxs(s.Fragment,{children:[h("gitView.branch.dialogDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:F}),"."]}),e[82]=V,e[83]=g,e[84]=C,e[85]=_,e[86]=h,e[87]=F,e[88]=le):le=e[88];let Ae;e[89]!==le?(Ae=s.jsx(ys,{children:le}),e[89]=le,e[90]=Ae):Ae=e[90];let Te;e[91]!==ve||e[92]!==Ae?(Te=s.jsxs(ps,{children:[ve,Ae]}),e[91]=ve,e[92]=Ae,e[93]=Te):Te=e[93];let $e;e[94]!==Z||e[95]!==Te?($e=s.jsxs(os,{className:"max-w-md",children:[Te,Z]}),e[94]=Z,e[95]=Te,e[96]=$e):$e=e[96];let ye;e[97]!==j||e[98]!==Q||e[99]!==$e?(ye=s.jsx(ls,{open:j,onOpenChange:Q,children:$e}),e[97]=j,e[98]=Q,e[99]=$e,e[100]=ye):ye=e[100];let q;return e[101]!==Ce||e[102]!==ye?(q=s.jsxs(s.Fragment,{children:[Ce,ye]}),e[101]=Ce,e[102]=ye,e[103]=q):q=e[103],q};function zN(t){return t.status==="done"||t.status==="error"}function UN(t){return t.status==="error"}function WN(t){return t.slice(t.indexOf("/")+1)}function KN(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(A,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),t.status==="done"&&s.jsx(A,{name:"check",className:"size-3.5 text-success"}),t.status==="error"&&s.jsx(A,{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:ge("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 HN(t){return t.stopPropagation()}const GN=({runMutation:t,onMutationComplete:e,onMutationError:n,onPathsComplete:r,scheduleFlush:a})=>{const i=[];let l=!1;return{enqueue:d=>{const f=i[i.length-1];if(f?.directory===d.directory&&f.direction===d.direction){d.paths.forEach(m=>f.paths.add(m));return}i.push(d)},flush:()=>{if(l)return;const d=i.shift();if(!d)return;l=!0;const f={directory:d.directory,direction:d.direction,paths:Array.from(d.paths),rollback:d.rollback};(async()=>{try{await t(f),e(f)}catch(m){n(f,m)}finally{r(f.paths),l=!1,i.length>0&&a()}})()},clear:()=>{i.length=0},size:()=>i.length,isRunning:()=>l}},ap="oc.git.actionTab",qN=15e3,JN=t=>t==="commit"||t==="branch"||t==="pr",bg="gitmojiCache",YN=1e3*60*60*24*7,yg="1",QN=40,XN=20,ZN="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",ip={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:"},vg=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},e2=()=>{if(typeof window>"u")return null;try{const t=localStorage.getItem(bg);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==yg||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(vg),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},t2=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:yg};localStorage.setItem(bg,JSON.stringify(e))}catch{return}},s2=t=>Date.now()-t.fetchedAt<YN,n2=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,a=n.match(r);if(a){const c=a[1],d=ip[c];if(d)return e.find(f=>f.code===d)||null}const i=n.split(" ")[0],l=ip[i];return l&&e.find(c=>c.code===l)||null},op=new Map,Zr=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),lp=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},r2=t=>{const e=t.working_dir?.trim(),n=t.index?.trim();return!!(e||n==="?")},wg=()=>{const{t}=pt(),{git:e}=Wn(),n=la(),[r,a]=o.useState(null),[i,l]=o.useState(!1),c=Lt(Re=>Re.currentSessionId),d=Lt(Re=>Re.newSessionDraft),f=Lt(Re=>Re.setDraftBootstrapPendingDirectory),m=Lt(Re=>Re.worktreeMetadata),u=Lt(Re=>Re.availableWorktrees),p=Zr(n),b=o.useMemo(()=>{if(!p)return;const Re=u.find(Xe=>Zr(Xe.path)===p);if(Re)return Re;for(const Xe of m.values())if(Zr(Xe.path)===p)return Xe},[u,p,m]),g=o.useMemo(()=>{if(c)return m.get(c)??b;if(d?.open)return b},[c,b,d?.open,m]),{profiles:y,globalIdentity:x,defaultGitIdentityId:h,loadProfiles:j,loadGlobalIdentity:v,loadDefaultGitIdentityId:C}=tr(Qn(Re=>({profiles:Re.profiles,globalIdentity:Re.globalIdentity,defaultGitIdentityId:Re.defaultGitIdentityId,loadProfiles:Re.loadProfiles,loadGlobalIdentity:Re.loadGlobalIdentity,loadDefaultGitIdentityId:Re.loadDefaultGitIdentityId}))),k=tu(n??null),w=nc(n??null),N=yh(Re=>c?Re.getAttachment(c):void 0),I=N?ay(N):[],E=N&&!N.degraded&&!N.legacy?N.worktreeRoot??void 0:void 0,P=Dj(n,g,w?.current??void 0),T=su(n??null),S=iy(n??null),M=oy(n??null),D=nu(n??null),F=ly(n??null),_=qs(Re=>Re.setActiveDirectory),V=qs(Re=>Re.fetchAll),$=qs(Re=>Re.ensureAll),O=qs(Re=>Re.fetchStatus),B=qs(Re=>Re.fetchBranches),G=qs(Re=>Re.fetchLog),R=qs(Re=>Re.setLogMaxCount),H=qs(Re=>Re.fetchIdentity),J=qs(Re=>Re.prefetchDiffs),ne=qs(Re=>Re.moveStatusPathsOptimistically),ue=qs(Re=>Re.restoreStatus),de=qs(Re=>Re.bumpIndexRevision),pe=_e(Re=>Re.isMobile),W=_e(Re=>Re.openContextDiff),te=_e(Re=>Re.navigateToDiff),X=_e(Re=>Re.setRightSidebarOpen),ee=o.useRef(null),fe=o.useRef(null),be=o.useRef(null),Ne=o.useRef(null),se=o.useCallback(()=>{fe.current!==null&&(window.clearTimeout(fe.current),fe.current=null)},[]),ie=o.useCallback(Re=>{se(),fe.current=window.setTimeout(()=>{fe.current=null,Zr(Re)===Zr(n)&&O(Re,e,{silent:!0})},qN)},[se,n,O,e]);o.useEffect(()=>se,[se]);const ae=o.useCallback(()=>{be.current!==null&&(window.clearTimeout(be.current),be.current=null)},[]),xe=o.useCallback(()=>{be.current===null&&(be.current=window.setTimeout(()=>{be.current=null,Ne.current?.()},0))},[]),Z=o.useCallback(async(Re,Xe,st)=>{if(Xe==="stage"){if(e.stageGitFiles){await e.stageGitFiles(Re,st);return}await Promise.all(st.map(ht=>e.stageGitFile(Re,ht)));return}if(e.unstageGitFiles){await e.unstageGitFiles(Re,st);return}await Promise.all(st.map(ht=>e.unstageGitFile(Re,ht)))},[e]),me=o.useMemo(()=>GN({runMutation:({directory:Re,direction:Xe,paths:st})=>Z(Re,Xe,st),onMutationComplete:({directory:Re})=>{de(Re),ie(Re)},onMutationError:({directory:Re,direction:Xe,rollback:st},ht)=>{st?.(),de(Re),ie(Re);const Vt=t(Xe==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");K.error(ht instanceof Error?ht.message:Vt)},onPathsComplete:Re=>{Ge(Xe=>{const st=new Set(Xe);return Re.forEach(ht=>st.delete(ht)),st})},scheduleFlush:xe}),[de,Z,xe,ie,t]);o.useEffect(()=>(Ne.current=me.flush,()=>{Ne.current=null}),[me]),o.useEffect(()=>()=>me.clear(),[me]),o.useEffect(()=>ae,[ae]),o.useEffect(()=>{if(!n){a(null),l(!1);return}let Re=!1,Xe=null;const st=async()=>{try{const ht=await dy(n);if(Re)return;a(ht.status),ht.status==="pending"&&(Xe=window.setTimeout(()=>{st()},500))}catch{Re||a(null)}};return st(),()=>{Re=!0,Xe!==null&&window.clearTimeout(Xe)}},[n]),o.useEffect(()=>{const Re=ee.current;ee.current=r,!(!n||!e)&&(Re==="pending"&&r==="ready"&&(l(!0),V(n,e).finally(()=>{window.setTimeout(()=>{l(!1)},1200)})),r==="failed"&&(f(null),l(!1)))},[n,V,e,f,r]);const Y=Zr(d?.bootstrapPendingDirectory??null),Se=!!(n&&Y&&Y===Zr(n)),ke=!!(n&&(r==="pending"||Se))||i,Fe=o.useMemo(()=>n?op.get(n)??null:null,[n]),Ce=jt(Re=>Re.settingsGitmojiEnabled),[Q,ce]=o.useState(null);o.useEffect(()=>{const Re=E||P?.projectDirectory;if(!Re){ce(null);return}let Xe=!1;return Po(Re).then(st=>{if(Xe)return;const ht=st.trim();ce(ht&&ht!=="HEAD"?ht:null)}).catch(()=>{Xe||ce(null)}),()=>{Xe=!0}},[E,P?.projectDirectory]);const[ve,le]=o.useState(Fe?.commitMessage??""),[Ae,Te]=o.useState([]),[$e,ye]=o.useState(!1),q=o.useRef(null),[L,U]=o.useState(null),[oe,Ee]=o.useState(!1),[Oe,Ie]=o.useState(null),[z,De]=o.useState(25),[Qe,tt]=o.useState(!1),{triggerFireworks:et}=kj(),We=o.useRef(new Map),at=o.useRef(0),qe=o.useCallback(()=>{at.current+=1,tt(!0)},[]),nt=o.useCallback(()=>{at.current=Math.max(0,at.current-1),at.current===0&&tt(!1)},[]),[Ze,ze]=o.useState(new Set),[rt,Ge]=o.useState(new Set),[ct,Pe]=o.useState(!1),[Me,Ue]=o.useState(0),[He,lt]=o.useState(!1),[vt,ft]=o.useState(Fe?.generatedHighlights??[]),dt=rt.size>0||me.size()>0||me.isRunning(),Dt=o.useCallback(()=>{const Re=q.current;Re&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{Re.scrollTo({top:Re.scrollHeight,behavior:"smooth"})})})},[]),Qt=E||P?.projectDirectory||null,Ft=w?.current||null,qt=o.useMemo(()=>{const Re=w?.tracking;return Re?Re.startsWith("origin/"):!0},[w?.tracking]),gt=o.useMemo(()=>{const Re=P?.createdFromBranch,Xe=typeof Re=="string"?Re.trim():"",st=typeof w?.current=="string"?w.current.trim():"",ht=typeof Q=="string"?Q.trim():"";return Xe?Xe===st&&Xe.startsWith("opencode/")&&ht.length>0&&ht!==Xe?ht:Xe:ht||st||"HEAD"},[P?.createdFromBranch,w,Q]),zt=o.useCallback(()=>{ft([])},[]),[es,is]=o.useState(new Set),[cs,hs]=o.useState(new Map),[_t,Ye]=o.useState(new Set),[Mt,Bt]=o.useState(null),[wt,Zt]=o.useState(null),[us,Es]=o.useState([]),[ws,Ds]=o.useState(""),[Xt,en]=o.useState(null),Ks=o.useMemo(()=>[{id:"commit",label:t("gitView.tabs.commit"),icon:s.jsx(A,{name:"git-commit",className:"h-3.5 w-3.5"})},{id:"branch",label:t("gitView.tabs.update"),icon:s.jsx(A,{name:"git-merge",className:"h-3.5 w-3.5"})},{id:"pr",label:t("gitView.tabs.pr"),icon:s.jsx(A,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],[t]),[Us,Xs]=o.useState(()=>{if(typeof window>"u")return"commit";const Re=window.localStorage.getItem(ap);return Re==="worktree"?"branch":JN(Re)?Re:"commit"}),[re,bt]=o.useState([]),[Et,Wt]=o.useState(null),[ts,ss]=o.useState(null),[Ke,Je]=o.useState([]),[Ct,kt]=o.useState(!1),[Kt,Tt]=o.useState([]),[gs,js]=o.useState("merge"),[Ls,Os]=o.useState(null),[tn,cn]=o.useState(!1),[Zs,sn]=o.useState(100),mn=o.useMemo(()=>c?`openchamber.conflict:${c}`:null,[c]),gn=o.useCallback((Re,Xe,st)=>{if(!mn||typeof window>"u")return;const ht={directory:Re,conflictFiles:Xe,operation:st};window.localStorage.setItem(mn,JSON.stringify(ht))},[mn]),$s=o.useCallback(()=>{!mn||typeof window>"u"||window.localStorage.removeItem(mn)},[mn]);o.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(ap,Us)},[Us]),o.useEffect(()=>{if(!mn||typeof window>"u"||!n)return;const Re=window.localStorage.getItem(mn);if(Re)try{const Xe=JSON.parse(Re);if(Xe.directory!==n){window.localStorage.removeItem(mn);return}Tt(Xe.conflictFiles??[]),js(Xe.operation??"merge"),kt(!0)}catch{window.localStorage.removeItem(mn)}},[mn,n]);const[Hs,dn]=o.useState(!1),[Kn,Hn]=o.useState("merge"),[kr,ir]=o.useState(""),bn=o.useCallback(Re=>{Ln(Re).then(Xe=>{if(Xe.ok){K.success(t("gitView.toast.commitHashCopied"));return}K.error(t("gitView.toast.copyFailed"))})},[t]),On=o.useCallback(Re=>{is(Xe=>{const st=new Set(Xe);return st.has(Re)?st.delete(Re):st.add(Re),st})},[]);o.useEffect(()=>{if(!n||!e)return;const Re=Array.from(es).filter(Xe=>!cs.has(Xe)&&!_t.has(Xe));if(Re.length!==0){Ye(Xe=>{const st=new Set(Xe);for(const ht of Re)st.add(ht);return st});for(const Xe of Re)e.getCommitFiles(n,Xe).then(st=>{hs(ht=>new Map(ht).set(Xe,st.files))}).catch(st=>{console.error("Failed to fetch commit files:",st),hs(ht=>new Map(ht).set(Xe,[]))}).finally(()=>{Ye(st=>{const ht=new Set(st);return ht.delete(Xe),ht})})}},[es,n,e,cs,_t]),o.useEffect(()=>{n&&op.set(n,{directory:n,commitMessage:ve,generatedHighlights:vt})},[ve,n,vt]),o.useEffect(()=>{j(),v(),C()},[j,v,C]),o.useEffect(()=>{if(!n||!e?.getRemoteUrl){Zt(null);return}e.getRemoteUrl(n).then(Zt).catch(()=>Zt(null))},[n,e]);const ur=o.useCallback(async()=>{if(!n||!e?.getRemotes){bt([]);return}try{const Re=await e.getRemotes(n);bt(Re)}catch{bt([])}},[n,e]);o.useEffect(()=>{ur()},[ur]),o.useEffect(()=>{if(!Ce){Es([]);return}let Re=!1;const Xe=e2();return Xe&&(Es(Xe.gitmojis),s2(Xe))?()=>{Re=!0}:((async()=>{try{const ht=await fetch(ZN);if(!ht.ok)throw new Error(`Failed to load gitmojis: ${ht.statusText}`);const Vt=await ht.json(),je=Array.isArray(Vt.gitmojis)?Vt.gitmojis.filter(vg):[];Re||(Es(je),t2(je))}catch(ht){Re||console.warn("Failed to load gitmoji list:",ht)}})(),()=>{Re=!0})},[Ce]),o.useEffect(()=>{n&&(_(n),$(n,e))},[n,_,$,e]),o.useEffect(()=>{if(n)return Mr.onGitRefreshHint(Re=>{Zr(Re.directory)===Zr(n)&&O(n,e)})},[n,O,e]);const Be=o.useCallback(async(Re=!0)=>{if(n)try{await Promise.all([O(n,e),B(n,e)])}catch(Xe){if(Re){const st=Xe instanceof Error?Xe.message:t("gitView.toast.refreshRepositoryFailed");K.error(st)}}},[n,e,O,B,t]),St=o.useCallback(async()=>{n&&await G(n,e,z)},[n,e,G,z]),Gt=o.useCallback(async()=>{n&&await H(n,e)},[n,e,H]);o.useEffect(()=>{if(!n||!e?.hasLocalIdentity||k!==!0)return;const Re=typeof h=="string"?h.trim():"";if(!Re||Re==="global"||We.current.get(n)===Re)return;let st=!1;return(async()=>{try{const Vt=await e.hasLocalIdentity?.(n);if(st||Vt===!0)return;qe(),await e.setGitIdentity(n,Re),We.current.set(n,Re),await Gt()}catch(Vt){console.warn("Failed to auto-apply default git identity:",Vt)}finally{st||nt()}})(),()=>{st=!0}},[qe,n,h,nt,e,k,Gt]);const Yt=o.useMemo(()=>{if(!w)return[];const Re=w.files??[],Xe=new Map;for(const st of Re)Xe.set(st.path,st);return Array.from(Xe.values()).sort((st,ht)=>st.path.localeCompare(ht.path))},[w]),ks=o.useMemo(()=>Yt.filter(lp),[Yt]),Bs=o.useMemo(()=>Yt.filter(r2),[Yt]);o.useEffect(()=>{if(!n||Yt.length===0)return;const Re=[],Xe=new Set,st=Vt=>{!Vt||Xe.has(Vt)||(Xe.add(Vt),Re.push(Vt))};if(ks.forEach(Vt=>st(Vt.path)),Ae.forEach(st),Yt.slice(0,XN).forEach(Vt=>st(Vt.path)),Re.length===0)return;const ht=window.setTimeout(()=>{J(n,e,Re,{maxFiles:QN})},120);return()=>{window.clearTimeout(ht)}},[Yt,n,e,J,ks,Ae]);const Fs=Re=>Re?.pushed[0]?.remote||w?.tracking?.split("/")[0]||yn.find(Xe=>Xe.name==="origin")?.name||yn[0]?.name||"origin",Ys=async(Re,Xe)=>{if(n){U(Re);try{const st=ht=>{const Vt=`${ht.name}/`,je=w?.tracking?.startsWith(Vt)?w.tracking.slice(Vt.length):void 0;return{remote:ht.name,branch:je,rebase:!0}};if(Re==="fetch"){if(!Xe)throw new Error("No remote available for fetch");await e.gitFetch(n,{remote:Xe.name}),K.success(t("gitView.toast.fetchedFromRemote",{name:Xe.name}))}else if(Re==="pull"){if(!Xe)throw new Error("No remote available for pull");const ht=await e.gitPull(n,st(Xe));K.success(ht.files.length===1?t("gitView.toast.pulledFilesSingle",{count:ht.files.length,name:Xe.name}):t("gitView.toast.pulledFilesPlural",{count:ht.files.length,name:Xe.name}))}else if(Re==="push"){const ht=await e.gitPush(n);K.success(t("gitView.toast.pushedToUpstream",{name:Fs(ht)}))}else if(Re==="sync"){if(!Xe)throw new Error("No remote available for sync");let ht=0,Vt=!1;await e.gitFetch(n,{remote:Xe.name});const je=await e.getGitStatus(n);if((je.behind??0)>0){if((je.files?.length??0)>0){K.error(t("gitView.toast.commitOrStashBeforeSync"));return}ht=(await e.gitPull(n,st(Xe))).files.length}((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),Vt=!0),ht>0&&Vt?K.success(ht===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:ht,name:Xe.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:ht,name:Xe.name})):ht>0?K.success(ht===1?t("gitView.toast.pulledFilesSingle",{count:ht,name:Xe.name}):t("gitView.toast.pulledFilesPlural",{count:ht,name:Xe.name})):Vt?K.success(t("gitView.toast.pushedToUpstream",{name:Xe.name})):K.success(t("gitView.toast.alreadyUpToDate"))}await Be(!1),await St()}catch(st){const ht=st instanceof Error?st.message:t("gitView.toast.syncActionFailed",{action:Re==="sync"?t("gitView.sync.syncChanges"):Re==="pull"?t("gitView.sync.pull"):Re});K.error(ht)}finally{U(null)}}},nn=o.useCallback(async Re=>{if(!n)return;const Xe=Re.name.trim();if(!Xe){K.error(t("gitView.toast.remoteNameRequired"));return}if(Xe==="origin"){K.error(t("gitView.toast.cannotRemoveOriginRemote"));return}Wt(Xe);try{await e.removeRemote(n,{remote:Xe}),K.success(t("gitView.toast.removedRemote",{name:Xe})),await Promise.all([Be(!1),ur()])}catch(st){const ht=st instanceof Error?st.message:`Failed to remove ${Xe}`;K.error(ht)}finally{Wt(null)}},[n,e,ur,Be,t]),Xn=async(Re={})=>{if(!n)return;if(!ve.trim()){K.error(t("gitView.toast.enterCommitMessage"));return}const Xe=ks.map(ht=>ht.path).sort();if(Xe.length===0){K.error(t("gitView.toast.stageFileToCommit"));return}const st=Re.pushAfter?"commitAndPush":"commit";Ie(st);try{if(await e.createGitCommit(n,ve.trim(),{files:Xe,stageFiles:[]}),de(n),K.success(t("gitView.toast.commitCreated")),le(""),zt(),await Be(),Re.pushAfter){const ht=await e.gitPush(n);K.success(t("gitView.toast.pushedToUpstream",{name:Fs(ht)})),et(),await Be(!1)}else await Be(!1);await St(),Ue(ht=>ht+1)}catch(ht){const Vt=ht instanceof Error?ht.message:t("gitView.toast.createCommitFailed");K.error(Vt)}finally{Ie(null),Re.pushAfter&&U(null)}},Cr=o.useCallback(async()=>{if(!n)return;const Re=ks.map(Xe=>Xe.path).sort();if(Re.length===0){K.error(t("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:n,selectedFiles:Re.length}),lt(!0);try{const{message:Xe}=await cy(n,Re),st=Xe.subject?.trim()??"",ht=Array.isArray(Xe.highlights)?Xe.highlights:[];if(st){let Vt=st;if(Ce&&us.length>0){const je=n2(st,us);if(je){const{code:yt,emoji:mt}=je;!st.startsWith(yt)&&!st.startsWith(mt)&&(Vt=`${yt} ${st}`)}}le(Vt)}ft(ht),Dt()}catch(Xe){console.error("[git-generation][browser] GitView generate handler failed",{message:Xe instanceof Error?Xe.message:String(Xe),error:Xe});const st=Xe instanceof Error?Xe.message:t("gitView.toast.generateCommitMessageFailed");K.error(st)}finally{lt(!1)}},[n,ks,Ce,us,Dt,t]),mr=Re=>Re.reason==="attention"?`${Re.attentionReason} in progress`:Re.reason==="missing"?"worktree is missing":"worktree is invalid",qr=async(Re,Xe)=>{if(!n||!w)return;const st=gc(N);if(st.length>0){K.error(t("gitView.toast.cannotCreateBranch",{reason:mr(st[0])}));return}const ht=w.current??null,Vt=Xe?.name??"origin";try{await e.createBranch(n,Re,ht??"HEAD"),K.success(t("gitView.toast.createdBranch",{name:Re})),await e.checkoutBranch(n,Re);let je=!1;try{await e.gitPush(n,{remote:Vt,branch:Re,options:["--set-upstream"]}),je=!0}catch(yt){const mt=yt instanceof Error?yt.message:`Unable to push new branch to ${Vt}.`;K.warning(t("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",mt]})})}await Be(),await St(),je&&K.success(t("gitView.toast.upstreamSet",{branch:Re,remote:Vt}))}catch(je){const yt=je instanceof Error?je.message:t("gitView.toast.createBranchFailed");throw K.error(yt),je}},Jr=async(Re,Xe)=>{if(!n)return;const st=gc(N);if(st.length>0){K.error(t("gitView.toast.cannotRenameBranch",{reason:mr(st[0])}));return}try{await e.renameBranch(n,Re,Xe),K.success(t("gitView.toast.renamedBranch",{oldName:Re,newName:Xe})),await Be(),await St()}catch(ht){const Vt=ht instanceof Error?ht.message:t("gitView.toast.renameBranchFailed",{oldName:Re,newName:Xe});K.error(Vt)}},Mn=async Re=>{if(!n)return;const Xe=gc(N);if(Xe.length>0){K.error(t("gitView.toast.cannotCheckout",{reason:mr(Xe[0])}));return}const st=Re.replace(/^remotes\//,"");if(w?.current!==st)try{await e.checkoutBranch(n,st),K.success(t("gitView.toast.checkedOut",{name:st})),await Be(),await St()}catch(ht){const Vt=ht instanceof Error?ht.message:t("gitView.toast.checkoutFailed",{name:st});K.error(Vt)}},wn=async Re=>{if(n){qe();try{await e.setGitIdentity(n,Re.id),K.success(t("gitView.toast.appliedIdentity",{name:Re.name})),await Gt()}catch(Xe){const st=Xe instanceof Error?Xe.message:t("gitView.toast.applyIdentityFailed");K.error(st)}finally{nt()}}},jn=o.useMemo(()=>T?.all?T.all.filter(Re=>!Re.startsWith("remotes/")).sort():[],[T]),Vs=o.useMemo(()=>T?.all?T.all.filter(Re=>Re.startsWith("remotes/")).map(Re=>Re.replace(/^remotes\//,"")).sort():[],[T]),yn=o.useMemo(()=>{if(re.length>0)return re;const Re=new Set,Xe=w?.tracking?.trim();Xe&&Xe.includes("/")&&Re.add(Xe.split("/")[0]);for(const st of Vs){const ht=st.indexOf("/");ht>0&&Re.add(st.slice(0,ht))}return Re.size===0&&wt&&Re.add("origin"),Array.from(Re).map(st=>({name:st,fetchUrl:wt??"",pushUrl:wt??""}))},[re,Vs,wt,w?.tracking]),pn=o.useMemo(()=>{const Re=new Set(yn.map(Vt=>Vt.name)),Xe=Vt=>{if(!Vt)return"";let je=Vt.trim();if(!je||je==="HEAD")return"";if(jn.includes(je))return je;je.startsWith("refs/heads/")&&(je=je.slice(11)),je.startsWith("heads/")&&(je=je.slice(6)),je.startsWith("remotes/")&&(je=je.slice(8));const yt=je.indexOf("/");if(yt>0){const mt=je.slice(0,yt);if(Re.has(mt)){const Ut=je.slice(yt+1).trim();Ut&&(je=Ut)}}return je},st=Xe(typeof P?.createdFromBranch=="string"?P.createdFromBranch:"");if(st)return st;const ht=Xe(typeof Q=="string"?Q:"");return ht||(jn.includes("main")?"main":jn.includes("master")?"master":jn.includes("develop")?"develop":"main")},[yn,jn,Q,P?.createdFromBranch]),Wr=o.useMemo(()=>yn.map(st=>st.name).map(st=>`${st}/${pn}`).find(st=>Vs.includes(st))??pn,[pn,yn,Vs]),si=o.useMemo(()=>{const Re=new Map;x&&Re.set(x.id,x);let Xe=null;if(wt)try{let st=wt.trim();st.startsWith("git@")&&(st=`https://${st.slice(4).replace(":","/")}`),st.endsWith(".git")&&(st=st.slice(0,-4));const ht=new URL(st);Xe=ht.hostname+ht.pathname}catch{}for(const st of y){if(st.authType!=="token"){Re.set(st.id,st);continue}const ht=st.host;if(!ht){Re.set(st.id,st);continue}if(!ht.includes("/")){Re.set(st.id,st);continue}Xe&&Xe===ht&&Re.set(st.id,st)}return Array.from(Re.values())},[y,x,wt]),ni=o.useMemo(()=>{if(M?.userName&&M?.userEmail){const Re=y.find(Xe=>Xe.userName===M.userName&&Xe.userEmail===M.userEmail);return Re||(x&&x.userName===M.userName&&x.userEmail===M.userEmail?x:{id:"local-config",name:M.userName,userName:M.userName,userEmail:M.userEmail,sshKey:M.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return x??null},[M,y,x]),ka=ks.length,Nn=D||L!==null||Oe!==null,Pn=w?.current??null,Sn=!!(P&&Qt&&Ft&&qt),Ir=!!(n&&Pn),Yr=!!Pn,Kr=Sn&&Qt&&Ft&&P?{repoRoot:Qt,sourceBranch:Ft,worktreeMetadata:P}:null,or=o.useMemo(()=>!Ir||!n||!Pn?null:{directory:n,branch:Pn},[Ir,Pn,n]);o.useEffect(()=>{if(!n||!e||!S?.all?.length||!Pn||!pn||Pn===pn){Bt(null);return}let Re=!1;return(async()=>{try{const st=await e.getGitLog(n,{from:pn,to:"HEAD",maxCount:z});if(Re)return;const ht=new Set((st?.all??[]).map(je=>je.hash).filter(je=>typeof je=="string"&&je.length>0));if(ht.size===0){Bt(null);return}const Vt=S.all.findIndex(je=>!ht.has(je.hash));if(Vt===0){Bt(null);return}if(Vt===-1){Bt({insertBeforeIndex:S.all.length,branchName:Pn,direction:"up"});return}Bt({insertBeforeIndex:Vt,branchName:Pn,direction:"up"})}catch{Re||Bt(null)}})(),()=>{Re=!0}},[pn,Pn,n,e,S,z]),o.useEffect(()=>{Os(null)},[n]),o.useEffect(()=>{if(Xt!=="graph"||!n){Xt!=="graph"&&Os(null);return}let Re=!1;return cn(!0),e.getGitLog(n,{maxCount:Zs,all:!0}).then(Xe=>{Re||Os(Xe)}).catch(Xe=>{console.error("Failed to fetch graph log:",Xe)}).finally(()=>{Re||cn(!1)}),()=>{Re=!0}},[Xt,n,Zs,e]);const Hr=o.useCallback((Re,Xe)=>{if(!n||Re.length===0)return;const st=Array.from(new Set(Re));Ge(Vt=>{const je=new Set(Vt);return st.forEach(yt=>je.add(yt)),je});const ht=ne(n,st,Xe);me.enqueue({directory:n,direction:Xe,paths:new Set(st),rollback:()=>ue(n,ht)}),xe()},[n,me,ne,ue,xe]),fn=o.useCallback(async Re=>{if(n){ze(Xe=>{const st=new Set(Xe);return st.add(Re),st});try{await e.revertGitFile(n,Re,{scope:"working"}),K.success(t("gitView.toast.revertedFile",{path:Re})),await Be(!1)}catch(Xe){const st=Xe instanceof Error?Xe.message:t("gitView.toast.revertFailed");K.error(st)}finally{ze(Xe=>{const st=new Set(Xe);return st.delete(Re),st})}}},[n,Be,e,t]),$i=o.useCallback(async Re=>{if(!n||Re.length===0||ct)return;const Xe=Array.from(new Set(Re)),st=new Set(ks.map(je=>je.path)),ht=Xe.some(je=>st.has(je));Pe(!0),ze(je=>{const yt=new Set(je);return Xe.forEach(mt=>yt.add(mt)),yt});const Vt=[];try{if(await Promise.all(Xe.map(async je=>{try{await e.revertGitFile(n,je)}catch(yt){Vt.push({path:je,message:yt instanceof Error?yt.message:t("gitView.toast.revertFailed")})}})),ht&&Vt.length<Xe.length&&de(n),await Be(!1),Vt.length===0)K.success(Xe.length===1?t("gitView.toast.revertedFilesSingle",{count:Xe.length}):t("gitView.toast.revertedFilesPlural",{count:Xe.length}));else if(Vt.length===Xe.length)K.error(Vt[0]?.message||t("gitView.toast.revertFailed"));else{const je=Xe.length-Vt.length;K.warning(je===1?t("gitView.toast.revertedSomeSingle",{success:je,failed:Vt.length}):t("gitView.toast.revertedSomePlural",{success:je,failed:Vt.length}))}}finally{ze(je=>{const yt=new Set(je);return Xe.forEach(mt=>yt.delete(mt)),yt}),Pe(!1)}},[de,n,e,ct,Be,ks,t]),ri=o.useCallback((Re,Xe)=>{if(n&&!pe){W(n,Re,Xe);return}te(Re,Xe),pe&&X(!1)},[n,pe,te,W,X]),_i=o.useCallback(()=>Ee(!0),[]),ai=o.useMemo(()=>{const Re=[];return ks.length>0&&Re.push({id:"staged",title:t("gitView.changes.stagedTitle"),entries:ks,actionSymbol:"-",actionAllLabel:t("gitView.changes.unstageAllAria"),getActionLabel:Xe=>t("gitView.changes.unstageFileAria",{path:Xe}),onActionFile:Xe=>{Hr([Xe],"unstage")},onActionAll:Xe=>{Hr(Xe,"unstage")},onViewDiff:Xe=>ri(Xe,!0),onRevertFile:fn,showRevertActions:!1,accent:!0}),Bs.length>0&&Re.push({id:"unstaged",title:t("gitView.changes.title"),entries:Bs,actionSymbol:"+",actionAllLabel:t("gitView.changes.stageAllAria"),getActionLabel:Xe=>t("gitView.changes.stageFileAria",{path:Xe}),onActionFile:Xe=>{Hr([Xe],"stage")},onActionAll:Xe=>{Hr(Xe,"stage")},onViewDiff:Xe=>ri(Xe,!1),onRevertFile:fn}),Re},[fn,ri,Hr,ks,t,Bs]),Bi=o.useCallback(Re=>{if(Re.length===0)return;const Xe=Re.map(st=>st.trim()).filter(Boolean);if(Xe.length===0){zt();return}le(st=>{const ht=st.trim(),Vt=ht.length>0?`
|
|
43
|
+
|
|
44
|
+
`:"";return`${ht}${Vt}${Xe.join(`
|
|
45
|
+
`)}`.trim()}),zt()},[zt]),da=o.useCallback((Re,Xe)=>{const st=Xe||Re;le(ht=>{const Vt=ht.trimStart();return Vt.startsWith(Re)||Xe&&Vt.startsWith(Xe)?ht:`${st.endsWith(" ")?st:`${st} `}${ht}`.trimStart()}),Ds(""),ye(!1)},[]),Qr=o.useCallback(Re=>{const Xe=Re instanceof Error?Re.message.toLowerCase():"";return Xe.includes("uncommitted changes")||Xe.includes("local changes")||Xe.includes("your local changes would be overwritten")||Xe.includes("please commit your changes or stash them")||Xe.includes("cannot rebase: you have unstaged changes")||Xe.includes("error: cannot pull with rebase")},[]),pr=o.useCallback((Re,Xe)=>{Je(st=>[...st,{message:Re,status:Xe,timestamp:Date.now()}])},[]),An=o.useCallback((Re,Xe)=>{Je(st=>{if(st.length===0)return st;const ht=[...st];return ht[ht.length-1]={...ht[ht.length-1],status:Re,...Xe?{message:Xe}:{}},ht})},[]),vn=o.useCallback(()=>{Je([])},[]),Or=o.useCallback(()=>{Je([]),ss(null)},[]),Pr=o.useCallback(Re=>{const Xe=Re.trim(),st=new Set(yn.map(Vt=>Vt.name)),ht=Xe.indexOf("/");if(ht>0){const Vt=Xe.slice(0,ht),je=Xe.slice(ht+1);if(st.has(Vt)&&je)return{branch:Xe,remote:Vt,remoteBranch:je}}for(const Vt of yn){const je=`${Vt.name}/${Xe}`;if(Vs.includes(je))return{branch:je,remote:Vt.name,remoteBranch:Xe}}return{branch:Xe,remote:null,remoteBranch:null}},[yn,Vs]),zs=o.useCallback(async Re=>{if(!n)return;ss("merge"),vn();const Xe=w?.current,st=Pr(Re);try{st.remote&&st.remoteBranch&&(pr(`Fetching ${st.remote}/${st.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:st.remote,branch:st.remoteBranch}),An("done",`Fetched ${st.remote}/${st.remoteBranch}`)),pr(`Merging ${st.branch} into ${Xe}...`,"running");const ht=await e.merge(n,{branch:st.branch});ht.conflict?(An("error","Merge conflicts detected"),Tt(ht.conflictFiles??[]),js("merge"),kt(!0),gn(n,ht.conflictFiles??[],"merge")):(An("done",`Merged ${st.branch} into ${Xe}`),$s(),pr("Refreshing repository status...","running"),await Be(),await St(),An("done","Repository status updated"))}catch(ht){if(Qr(ht))An("error","Uncommitted changes detected"),Hn("merge"),ir(st.branch),dn(!0);else{const Vt=ht instanceof Error?ht.message:`Failed to merge ${st.branch}`;An("error",Vt)}}},[n,e,w,Pr,Be,St,Qr,gn,$s,pr,An,vn]),$r=o.useCallback(async Re=>{if(!n)return;ss("rebase"),vn();const Xe=w?.current,st=Pr(Re);try{st.remote&&st.remoteBranch&&(pr(`Fetching ${st.remote}/${st.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:st.remote,branch:st.remoteBranch}),An("done",`Fetched ${st.remote}/${st.remoteBranch}`)),pr(`Rebasing ${Xe} onto ${st.branch}...`,"running");const ht=await e.rebase(n,{onto:st.branch});ht.conflict?(An("error","Rebase conflicts detected"),Tt(ht.conflictFiles??[]),js("rebase"),kt(!0),gn(n,ht.conflictFiles??[],"rebase")):(An("done",`Rebased ${Xe} onto ${st.branch}`),$s(),pr("Refreshing repository status...","running"),await Be(),await St(),An("done","Repository status updated"))}catch(ht){if(Qr(ht))An("error","Uncommitted changes detected"),Hn("rebase"),ir(st.branch),dn(!0);else{const Vt=ht instanceof Error?ht.message:`Failed to rebase onto ${st.branch}`;An("error",Vt)}}},[n,e,w,Pr,Be,St,Qr,gn,$s,pr,An,vn]),Ca=o.useCallback(async()=>{if(n)try{gs==="merge"?(await e.abortMerge(n),K.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),K.success(t("gitView.toast.rebaseAborted"))),$s(),await Be(),await St()}catch(Re){const Xe=Re instanceof Error?Re.message:`Failed to abort ${gs}`;K.error(Xe)}},[n,e,gs,Be,St,$s,t]),Vi=o.useMemo(()=>w?.files?w.files.some(Re=>Re.index==="U"||Re.working_dir==="U"||Re.index==="A"&&Re.working_dir==="A"||Re.index==="D"&&Re.working_dir==="D"):!1,[w?.files]),Gn=o.useCallback(async()=>{if(n)try{const Re=!!w?.mergeInProgress?.head,Xe=!!(w?.rebaseInProgress?.headName||w?.rebaseInProgress?.onto);if(Re){const st=await e.continueMerge(n);st.conflict?(Tt(st.conflictFiles??[]),js("merge"),kt(!0),gn(n,st.conflictFiles??[],"merge"),K.error(t("gitView.toast.mergeConflictsDetected"))):($s(),K.success(t("gitView.toast.mergeCompleted")),await Be(),await St())}else if(Xe){const st=await e.continueRebase(n);st.conflict?(Tt(st.conflictFiles??[]),js("rebase"),kt(!0),gn(n,st.conflictFiles??[],"rebase"),K.error(t("gitView.toast.rebaseConflictsDetected"))):($s(),K.success(t("gitView.toast.rebaseStepCompleted")),await Be(),await St())}}catch(Re){const Xe=Re instanceof Error?Re.message:t("gitView.toast.continueOperationFailed");K.error(Xe)}},[n,e,w,Be,St,gn,$s,t]),fr=o.useCallback(async()=>{if(n)try{!!w?.mergeInProgress?.head?(await e.abortMerge(n),K.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),K.success(t("gitView.toast.rebaseAborted"))),$s(),await Be(),await St()}catch(Re){const Xe=Re instanceof Error?Re.message:t("gitView.toast.abortOperationFailed");K.error(Xe)}},[n,e,w,Be,St,$s,t]),hn=o.useCallback(()=>{if(!n)return;const Xe=!!w?.mergeInProgress?.head?"merge":"rebase",st=w?.files?.filter(ht=>ht.index==="U"||ht.working_dir==="U").map(ht=>ht.path)??[];st.length>0&&Tt(st),js(Xe),kt(!0)},[n,w]),Ia=o.useCallback(async Re=>{if(!n)return;const Xe=w?.current,st=Kn,ht=kr,Vt=(w?.files??[]).some(lp);try{await e.stash(n,{message:`Auto-stash before ${st} with ${ht}`,includeUntracked:!0}),Vt&&de(n)}catch(mt){const Ut=mt instanceof Error?mt.message:"Failed to stash changes";K.error(Ut);return}let je=!1,yt=!1;try{if(st==="merge"){const mt=await e.merge(n,{branch:ht});mt.conflict?(yt=!0,Tt(mt.conflictFiles??[]),js("merge"),kt(!0)):(je=!0,K.success(t("gitView.toast.mergedIntoBranch",{branch:ht,currentBranch:Xe||""})))}else{const mt=await e.rebase(n,{onto:ht});mt.conflict?(yt=!0,Tt(mt.conflictFiles??[]),js("rebase"),kt(!0)):(je=!0,K.success(t("gitView.toast.rebasedOntoBranch",{currentBranch:Xe||"",branch:ht})))}if(Re&&je)try{await e.stashPop(n),de(n),K.success(t("gitView.toast.stashedRestored"))}catch(mt){const Ut=mt instanceof Error?mt.message:t("gitView.toast.restoreStashFailed");K.error(Ut)}else Re&&yt&&K.info(t("gitView.toast.restoreStashManually"));await Be(),await St()}catch(mt){if(Re)try{await e.stashPop(n),de(n)}catch{}throw mt}},[de,n,e,w,Kn,kr,Be,St,t]),Ro=o.useCallback(Re=>{De(Re),n&&(R(n,Re),G(n,e,Re))},[n,G,e,R]),Pa=o.useCallback(Re=>{sn(Re)},[]),ua=o.useCallback(()=>{en(null),n&&(O(n,e),B(n,e),G(n,e,z))},[n,O,B,G,z,e]),ii=o.useCallback(Re=>{if(Re.conflict){if(Re.operation==="cherry-pick"||Re.operation==="revert"){K.error(t("gitView.history.actions.conflictToastTitle"),{description:t("gitView.history.actions.conflictToastDescription",{files:Re.conflictFiles?.join(", ")??"unknown files"})}),n&&(O(n,e),B(n,e),G(n,e,z));return}Tt(Re.conflictFiles??[]),js(Re.operation),kt(!0),n&&gn(n,Re.conflictFiles??[],Re.operation)}},[t,Tt,js,kt,gn,n,O,B,G,z,e]);return n?k===null||k===!0&&!w?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(A,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:t("gitView.loading.checkingRepository")})]})}):k===!1?ke?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(A,{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(A,{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")}),I.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:ge("flex h-full flex-col overflow-hidden","bg-sidebar"),children:[s.jsx(Yj,{status:w,localBranches:jn,remoteBranches:Vs,branchInfo:T?.branches,syncAction:L,remotes:yn,onFetch:Re=>Ys("fetch",Re),onSync:Re=>Ys("sync",Re),onRemoveRemote:nn,removingRemoteName:Et,onCheckoutBranch:Mn,onCreateBranch:qr,onRenameBranch:Jr,activeIdentityProfile:ni,availableIdentities:si,onSelectIdentity:wn,isApplyingIdentity:Qe,isWorktreeMode:!!P,onOpenHistory:()=>en("history"),onOpenGraph:()=>en("graph"),onOpenStashes:_i,actionTabItems:Ks,activeActionTab:Us,onSelectActionTab:Re=>Xs(Re)}),n&&(w?.mergeInProgress?.head||w?.rebaseInProgress?.headName||w?.rebaseInProgress?.onto)&&s.jsx(BN,{mergeInProgress:w?.mergeInProgress,rebaseInProgress:w?.rebaseInProgress,onContinue:Gn,onAbort:fr,onResolveWithAI:hn,hasUnresolvedConflicts:Vi,isLoading:D}),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:ge("min-w-0 min-h-0 h-full flex flex-col","bg-sidebar"),children:s.jsxs(vs,{as:Io,ref:q,outerClassName:"flex-1 min-h-0",className:ge("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:[Us==="commit"?s.jsx("div",{className:"flex h-full min-h-0 flex-col gap-3",children:(Yt?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(o0,{groups:ai,diffStats:w?.diffStats,revertingPaths:Ze,isRevertingAll:ct,onVisiblePathsChange:Te,onRevertAll:$i})}),s.jsx(m0,{stagedCount:ka,commitMessage:ve,onCommitMessageChange:le,generatedHighlights:vt,onInsertHighlights:Bi,onGenerateMessage:Cr,isGeneratingMessage:He,onCommit:()=>Xn({pushAfter:!1}),onCommitAndPush:()=>Xn({pushAfter:!0}),commitAction:Oe,hasPendingIndexMutation:dt,gitmojiEnabled:Ce,onOpenGitmojiPicker:()=>ye(!0)})]}):s.jsx(p0,{onOpenStashes:()=>Ee(!0)})}):null,Us==="branch"?s.jsx("div",{className:"space-y-4",children:Yr?s.jsxs(s.Fragment,{children:[s.jsx(VN,{mode:"inline",currentBranch:w?.current,localBranches:jn,remoteBranches:Vs,defaultTargetBranch:Wr,onMerge:zs,onRebase:$r,disabled:Nn,isOperating:ts!==null,operationLogs:Ke,onOperationComplete:Or}),Kr?s.jsx(Vj,{repoRoot:Kr.repoRoot,sourceBranch:Kr.sourceBranch,worktreeMetadata:Kr.worktreeMetadata,localBranches:jn,defaultTargetBranch:gt,refreshKey:Me,onRefresh:()=>{n&&(O(n,e),B(n,e),G(n,e,z))}},Kr.worktreeMetadata.path):null]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("gitView.branch.actionsUnavailable")})}):null,Us==="pr"?s.jsx("div",{className:"space-y-4",children:or?s.jsx(TN,{directory:or.directory,branch:or.branch,baseBranch:pn,trackingBranch:w?.tracking??void 0,remotes:re,remoteBranches:Vs,onGeneratedDescription:Dt}):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(ls,{open:Xt!==null,onOpenChange:Re=>{Re||en(null)},children:s.jsxs(os,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:t(Xt==="graph"?"gitView.graph.title":"gitView.history.title")}),s.jsx(ys,{children:t("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(X0,{mode:Xt==="graph"?"graph":"history",log:Xt==="graph"?Ls??S:S,isLogLoading:Xt==="graph"&&tn||F,logMaxCount:Xt==="graph"?Zs:z,onLogMaxCountChange:Xt==="graph"?Pa:Ro,expandedCommitHashes:es,onToggleCommit:On,commitFilesMap:cs,loadingCommitHashes:_t,onCopyHash:bn,directory:n??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:Xt==="graph"?null:Mt,onConflict:Xt==="graph"?ii:void 0,onActionSuccess:Xt==="graph"?ua:void 0})})]})}),s.jsx(Qj,{open:oe,onOpenChange:Ee,directory:n,hasUncommittedChanges:(w?.files?.length??0)>0,hasStagedChanges:ks.length>0,uncommittedFileCount:w?.files?.length??0,onChanged:async Re=>{n&&Re?.affectsIndex&&de(n),await Be(!1),await St()}}),s.jsx(ls,{open:$e,onOpenChange:ye,children:s.jsxs(os,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(ps,{className:"px-4 pt-4",children:s.jsx(ds,{children:t("gitView.gitmoji.title")})}),s.jsxs(Ya,{className:"h-[420px]",children:[s.jsx(Sa,{placeholder:t("gitView.gitmoji.searchPlaceholder"),value:ws,onValueChange:Ds}),s.jsxs(Qa,{children:[s.jsx(Xa,{children:t("gitView.gitmoji.empty")}),s.jsx(Vn,{children:(us.length===0?[]:us.filter(Re=>{const Xe=ws.trim().toLowerCase();return Xe?Re.emoji.includes(Xe)||Re.code.toLowerCase().includes(Xe)||Re.description.toLowerCase().includes(Xe):!0})).map(Re=>s.jsxs(En,{onSelect:()=>da(Re.emoji,Re.code),children:[s.jsx("span",{className:"text-lg",children:Re.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Re.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:Re.description})]},Re.code))})]})]})]})}),n&&s.jsx(EN,{open:Ct,onOpenChange:kt,conflictFiles:Kt,directory:n,operation:gs,onAbort:Ca,onClearState:$s}),s.jsx(_N,{open:Hs,onOpenChange:dn,operation:Kn,targetBranch:kr,onConfirm:Ia})]}):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")})})},a2=Object.freeze(Object.defineProperty({__proto__:null,GitView:wg},Symbol.toStringTag,{value:"Module"})),Dd=5e3,i2=(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},o2=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"},l2=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()},vu=async(t,e)=>{try{const n=await l2(t,e);return i2(n,Dd)>Dd?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:o2(n)}}},wu=t=>t==="too-large"?`File is too large to open (>${Dd.toLocaleString()} lines)`:t==="missing"?"File not found":"Failed to open file",c2=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Jn=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},jg=(t,e)=>{const n=Jn(e),r=Jn(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},d2=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),u2=new Set(["node_modules"]),m2=t=>u2.has(t),p2=t=>{const e=Jn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Ng=(t,e)=>s.jsx(Er,{filePath:t,extension:e}),f2=t=>{const e=ot.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},h2=t=>{const e=ot.c(63),{node:n,root:r,isExpanded:a,isActive:i,status:l,badge:c,permissions:d,downloadFile:f,contextMenuPath:m,setContextMenuPath:u,onSelect:p,onToggle:b,onRevealPath:g,onOpenDialog:y}=t,{t:x}=pt(),h=n.type==="directory",{canRename:j,canCreateFile:v,canCreateFolder:C,canDelete:k,canReveal:w}=d;let N;e[0]!==v||e[1]!==C||e[2]!==k||e[3]!==j||e[4]!==w||e[5]!==n.path||e[6]!==u?(N=J=>{!j&&!v&&!C&&!k&&!w||(J?.preventDefault(),u(n.path))},e[0]=v,e[1]=C,e[2]=k,e[3]=j,e[4]=w,e[5]=n.path,e[6]=u,e[7]=N):N=e[7];const I=N;let E;e[8]!==h||e[9]!==n||e[10]!==p||e[11]!==b?(E=()=>{h?b(n.path):p(n)},e[8]=h,e[9]=n,e[10]=p,e[11]=b,e[12]=E):E=e[12];const P=E;let T;e[13]!==n.path||e[14]!==u?(T=J=>{J.stopPropagation(),u(n.path)},e[13]=n.path,e[14]=u,e[15]=T):T=e[15];const S=T;let M;e[16]!==n.path||e[17]!==r?(M=J=>{const ne=jg(r,n.path);!ne||ne==="."||(J.dataTransfer.setData("application/x-openchamber-file-path",ne),J.dataTransfer.effectAllowed="copy")},e[16]=n.path,e[17]=r,e[18]=M):M=e[18];const D=M,F=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let _;e[19]!==F?(_=ge("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",F,"cursor-grab active:cursor-grabbing"),e[19]=F,e[20]=_):_=e[20];let V;e[21]!==h||e[22]!==a||e[23]!==n.extension||e[24]!==n.path?(V=h?a?s.jsx(A,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(A,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):Ng(n.path,n.extension),e[21]=h,e[22]=a,e[23]=n.extension,e[24]=n.path,e[25]=V):V=e[25];let $;e[26]!==n.name||e[27]!==n.path?($=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]=$):$=e[28];let O;e[29]!==h||e[30]!==l?(O=!h&&l&&s.jsx(f2,{status:l}),e[29]=h,e[30]=l,e[31]=O):O=e[31];let B;e[32]!==c||e[33]!==h?(B=h&&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]=h,e[34]=B):B=e[34];let G;e[35]!==I||e[36]!==D||e[37]!==P||e[38]!==B||e[39]!==_||e[40]!==V||e[41]!==$||e[42]!==O?(G=s.jsxs("button",{type:"button",onClick:P,onContextMenu:I,draggable:!0,onDragStart:D,className:_,children:[V,$,O,B]}),e[35]=I,e[36]=D,e[37]=P,e[38]=B,e[39]=_,e[40]=V,e[41]=$,e[42]=O,e[43]=G):G=e[43];let R;e[44]!==v||e[45]!==C||e[46]!==k||e[47]!==j||e[48]!==w||e[49]!==m||e[50]!==f||e[51]!==S||e[52]!==h||e[53]!==n||e[54]!==y||e[55]!==g||e[56]!==u||e[57]!==x?(R=(j||v||C||k||w)&&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(As,{open:m===n.path,onOpenChange:J=>u(J?n.path:null),children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(Is,{asChild:!0,children:s.jsx(he,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:S,title:x("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":x("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(A,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(At,{side:"bottom",sideOffset:6,children:x("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsxs(Ps,{align:"end",side:"bottom",onCloseAutoFocus:()=>u(null),children:[j&&s.jsxs(Ot,{onClick:J=>{J.stopPropagation(),y("rename",n)},children:[s.jsx(A,{name:"edit",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.rename")]}),s.jsxs(Ot,{onClick:J=>{J.stopPropagation(),Ln(n.path).then(ne=>{if(ne.ok){K.success(x("sidebarFilesTree.toast.pathCopied"));return}K.error(x("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(A,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.copyPath")]}),!h&&f&&s.jsxs(Ot,{onClick:J=>{J.stopPropagation(),f(n.path)},children:[s.jsx(A,{name:"download",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.save")]}),w&&s.jsxs(Ot,{onClick:J=>{J.stopPropagation(),g(n.path)},children:[s.jsx(A,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",x(iu())]}),h&&(v||C)&&s.jsxs(s.Fragment,{children:[s.jsx(nr,{}),v&&s.jsxs(Ot,{onClick:J=>{J.stopPropagation(),y("createFile",n)},children:[s.jsx(A,{name:"file-add",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFile")]}),C&&s.jsxs(Ot,{onClick:J=>{J.stopPropagation(),y("createFolder",n)},children:[s.jsx(A,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFolder")]})]}),k&&s.jsxs(s.Fragment,{children:[s.jsx(nr,{}),s.jsxs(Ot,{onClick:J=>{J.stopPropagation(),y("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.delete")]})]})]})]})}),e[44]=v,e[45]=C,e[46]=k,e[47]=j,e[48]=w,e[49]=m,e[50]=f,e[51]=S,e[52]=h,e[53]=n,e[54]=y,e[55]=g,e[56]=u,e[57]=x,e[58]=R):R=e[58];let H;return e[59]!==I||e[60]!==G||e[61]!==R?(H=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:I,children:[G,R]}),e[59]=I,e[60]=G,e[61]=R,e[62]=H):H=e[62],H},g2=()=>{const t=ot.c(251),{t:e}=pt(),{files:n}=Wn(),r=la()??"";let a;t[0]!==r?(a=Jn(r.trim()),t[0]=r,t[1]=a):a=t[1];const i=a,l=rc(),c=ru(),d=au(x2),f=_e(b2),m=nc(r),[u,p]=o.useState(""),b=ac(u,200),g=o.useRef(null);let y;t[2]===Symbol.for("react.memo_cache_sentinel")?(y=[],t[2]=y):y=t[2];const[x,h]=o.useState(y),[j,v]=o.useState(!1);let C;t[3]===Symbol.for("react.memo_cache_sentinel")?(C={},t[3]=C):C=t[3];const[k,w]=o.useState(C);let N;t[4]===Symbol.for("react.memo_cache_sentinel")?(N={},t[4]=N):N=t[4];const[I,E]=o.useState(N);let P;t[5]===Symbol.for("react.memo_cache_sentinel")?(P=new Set,t[5]=P):P=t[5];const T=o.useRef(P);let S;t[6]===Symbol.for("react.memo_cache_sentinel")?(S=new Set,t[6]=S):S=t[6];const M=o.useRef(S);let D;t[7]===Symbol.for("react.memo_cache_sentinel")?(D=[],t[7]=D):D=t[7];const F=D;let _;t[8]===Symbol.for("react.memo_cache_sentinel")?(_=[],t[8]=_):_=t[8];const V=_;let $;t[9]!==i?($=re=>i?re.byRoot[i]?.expandedPaths??F:F,t[9]=i,t[10]=$):$=t[10];const O=Bn($);let B;t[11]!==i?(B=re=>i?re.byRoot[i]?.selectedPath??null:null,t[11]=i,t[12]=B):B=t[12];const G=Bn(B),R=Bn(y2),H=Bn(v2),J=Bn(w2),ne=Bn(j2);let ue;t[13]!==i?(ue=re=>i?re.contextPanelByDirectory[i]?.tabs??V:V,t[13]=i,t[14]=ue):ue=t[14];const de=_e(ue);let pe;t[15]!==de?(pe=new Set(de.map(N2).filter(S2).map(k2)),t[15]=de,t[16]=pe):pe=t[16];const W=pe,[te,X]=o.useState(null),[ee,fe]=o.useState(null),[be,Ne]=o.useState(null),[se,ie]=o.useState(""),[ae,xe]=o.useState(!1),Z=!!n.writeFile,me=!!n.createDirectory,Y=!!n.rename,Se=!!n.delete,we=!!n.revealPath;let ke;t[17]!==Z||t[18]!==me||t[19]!==Se||t[20]!==Y||t[21]!==we?(ke={canRename:Y,canCreateFile:Z,canCreateFolder:me,canDelete:Se,canReveal:we},t[17]=Z,t[18]=me,t[19]=Se,t[20]=Y,t[21]=we,t[22]=ke):ke=t[22];const Fe=ke;let Ce;t[23]!==n||t[24]!==e?(Ce=re=>{n.revealPath&&n.revealPath(re).catch(()=>{K.error(e("sidebarFilesTree.toast.revealFailed"))})},t[23]=n,t[24]=e,t[25]=Ce):Ce=t[25];const Q=Ce;let ce;t[26]===Symbol.for("react.memo_cache_sentinel")?(ce=(re,bt)=>{fe(re),Ne(bt),ie(re==="rename"&&bt.name||""),xe(!1)},t[26]=ce):ce=t[26];const ve=ce;let le;t[27]!==c||t[28]!==l?(le=(re,bt)=>{const Et=bt.filter(C2).filter(Wt=>l||!Wt.name.startsWith(".")).filter(Wt=>c||!m2(Wt.name)).map(Wt=>{const ts=Wt.name,ss=Jn(Wt.path||""),Ke=ss?d2(ss)?ss:Jn(`${re}/${ss}`):Jn(`${re}/${ts}`),Je=Wt.isDirectory?"directory":"file",Ct=Je==="file"&&ts.includes(".")?ts.split(".").pop()?.toLowerCase():void 0;return{name:ts,path:Ke,type:Je,extension:Ct}});return c2(Et)},t[27]=c,t[28]=l,t[29]=le):le=t[29];const Ae=le;let Te;t[30]!==n||t[31]!==Ae||t[32]!==c?(Te=async re=>{const bt=Jn(re.trim());if(!bt||T.current.has(bt)||M.current.has(bt))return;M.current=new Set(M.current),M.current.add(bt);const Et=!c;await(n.listDirectory?n.listDirectory(bt,{respectGitignore:Et}).then(P2):rn.listLocalDirectory(bt,{respectGitignore:Et}).then(D2)).then(ts=>{const ss=Ae(bt,ts);T.current=new Set(T.current),T.current.add(bt),E(Ke=>{if(!Ke[bt])return Ke;const Je={...Ke};return delete Je[bt],Je}),w(Ke=>({...Ke,[bt]:ss}))}).catch(ts=>{const ss=ts instanceof Error?ts.message:String(ts??"");console.error("Failed to load sidebar directory:",ts),E(Ke=>({...Ke,[bt]:ss}))}).finally(()=>{M.current=new Set(M.current),M.current.delete(bt)})},t[30]=n,t[31]=Ae,t[32]=c,t[33]=Te):Te=t[33];const $e=Te;let ye;t[34]!==$e||t[35]!==i?(ye=async()=>{i&&(T.current=new Set,M.current=new Set,E({}),w(T2),await $e(i))},t[34]=$e,t[35]=i,t[36]=ye):ye=t[36];const q=ye;let L;t[37]!==$e||t[38]!==q?(L=async re=>{if(!re){await q();return}const bt=Jn(re);T.current=new Set(T.current),T.current.delete(bt),M.current=new Set(M.current),M.current.delete(bt),await $e(bt)},t[37]=$e,t[38]=q,t[39]=L):L=t[39];const U=L;let oe;t[40]!==$e||t[41]!==i?(oe=()=>{i&&(T.current=new Set,M.current=new Set,E({}),w(E2),$e(i))},t[40]=$e,t[41]=i,t[42]=oe):oe=t[42];let Ee;t[43]!==$e||t[44]!==i||t[45]!==c||t[46]!==l?(Ee=[$e,i,l,c],t[43]=$e,t[44]=i,t[45]=c,t[46]=l,t[47]=Ee):Ee=t[47],o.useEffect(oe,Ee);let Oe,Ie;t[48]!==O||t[49]!==$e||t[50]!==i?(Oe=()=>{if(!i||O.length===0)return;const re=O.map(M2).filter(Et=>!!Et&&Et!==i&&Et.startsWith(`${i}/`)&&!T.current.has(Et)&&!M.current.has(Et)).sort(R2);if(re.length===0)return;let bt=!1;return(async()=>{for(let Et=0;Et<re.length&&!bt;Et=Et+3,Et){const Wt=re.slice(Et,Et+3);await Promise.all(Wt.map(ts=>$e(ts)))}})(),()=>{bt=!0}},Ie=[O,$e,i],t[48]=O,t[49]=$e,t[50]=i,t[51]=Oe,t[52]=Ie):(Oe=t[51],Ie=t[52]),o.useEffect(Oe,Ie);let z,De;t[53]!==r||t[54]!==b||t[55]!==d||t[56]!==c||t[57]!==l?(z=()=>{if(!r){h([]),v(!1);return}const re=b.trim();if(!re){h([]),v(!1);return}let bt=!1;return v(!0),d(r,re,150,{includeHidden:l,respectGitignore:!c,type:"file"}).then(Et=>{if(bt)return;const ts=Et.filter(ss=>c||!p2(ss.path)).map(F2);h(ts)}).catch(()=>{bt||h([])}).finally(()=>{bt||v(!1)}),()=>{bt=!0}},De=[r,b,d,l,c],t[53]=r,t[54]=b,t[55]=d,t[56]=c,t[57]=l,t[58]=z,t[59]=De):(z=t[58],De=t[59]),o.useEffect(z,De);let Qe;t[60]!==m||t[61]!==W||t[62]!==i?(Qe=re=>{if(W.has(re))return"open";if(m?.files){const bt=re.startsWith(i+"/")?re.slice(i.length+1):re,Et=m.files.find(Wt=>Wt.path===bt);if(Et){if(Et.index==="A"||Et.working_dir==="?")return"git-added";if(Et.index==="D")return"git-deleted";if(Et.index==="M"||Et.working_dir==="M")return"git-modified"}}return null},t[60]=m,t[61]=W,t[62]=i,t[63]=Qe):Qe=t[63];const tt=Qe;let et;t[64]!==m||t[65]!==i?(et=re=>{if(!m?.files)return null;const bt=re.startsWith(i+"/")?re.slice(i.length+1):re,Et=bt?`${bt}/`:"";let Wt=0,ts=0;for(const ss of m.files)ss.path.startsWith(Et)&&((ss.index==="M"||ss.working_dir==="M")&&Wt++,(ss.index==="A"||ss.working_dir==="?")&&ts++);return Wt+ts>0?{modified:Wt,added:ts}:null},t[64]=m,t[65]=i,t[66]=et):et=t[66];const We=et;let at;t[67]!==H||t[68]!==n||t[69]!==f||t[70]!==i||t[71]!==R?(at=async re=>{if(!i)return;const bt=await vu(n,re.path);if(!bt.ok){K.error(wu(bt.reason));return}R(i,re.path),H(i,re.path),f(i,re.path)},t[67]=H,t[68]=n,t[69]=f,t[70]=i,t[71]=R,t[72]=at):at=t[72];const qe=at;let nt;t[73]!==$e||t[74]!==i||t[75]!==ne?(nt=async re=>{const bt=Jn(re);i&&(ne(i,bt),T.current.has(bt)||await $e(bt))},t[73]=$e,t[74]=i,t[75]=ne,t[76]=nt):nt=t[76];const Ze=nt;let ze;t[77]!==ee||t[78]!==be||t[79]!==se||t[80]!==n||t[81]!==U||t[82]!==J||t[83]!==i||t[84]!==G||t[85]!==R||t[86]!==e?(ze=async re=>{if(re?.preventDefault(),!be||!ee)return;xe(!0);const bt=()=>xe(!1),Et=()=>fe(null);if(ee==="createFile"){if(!se.trim()){K.error(e("sidebarFilesTree.toast.filenameRequired")),bt();return}if(!n.writeFile){K.error(e("sidebarFilesTree.toast.writeNotSupported")),bt();return}const Wt=be.path,ts=Wt?`${Wt}/`:"",ss=Jn(`${ts}${se.trim()}`);await n.writeFile(ss,"").then(async Ke=>{Ke.success&&(K.success(e("sidebarFilesTree.toast.fileCreated")),await U(Wt)),Et()}).catch(()=>K.error(e("sidebarFilesTree.toast.operationFailed"))).finally(bt);return}if(ee==="createFolder"){if(!se.trim()){K.error(e("sidebarFilesTree.toast.folderNameRequired")),bt();return}const Wt=be.path,ts=Wt?`${Wt}/`:"",ss=Jn(`${ts}${se.trim()}`);await n.createDirectory(ss).then(async Ke=>{Ke.success&&(K.success(e("sidebarFilesTree.toast.folderCreated")),await U(Wt)),Et()}).catch(()=>K.error(e("sidebarFilesTree.toast.operationFailed"))).finally(bt);return}if(ee==="rename"){if(!se.trim()){K.error(e("sidebarFilesTree.toast.nameRequired")),bt();return}if(!n.rename){K.error(e("sidebarFilesTree.toast.renameNotSupported")),bt();return}const Wt=be.path,ts=Wt.split("/").slice(0,-1).join("/"),ss=ts?`${ts}/`:"",Ke=Jn(`${ss}${se.trim()}`);await n.rename(Wt,Ke).then(async Je=>{Je.success&&(K.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await U(ts),i&&J(i,Wt),(G===Wt||G&&G.startsWith(`${Wt}/`))&&R(i,null)),Et()}).catch(()=>K.error(e("sidebarFilesTree.toast.operationFailed"))).finally(bt);return}if(ee==="delete"){if(!n.delete){K.error(e("sidebarFilesTree.toast.deleteNotSupported")),bt();return}const Wt=be.path,ts=Wt.split("/").slice(0,-1).join("/");await n.delete(Wt).then(async ss=>{ss.success&&(K.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await U(ts),i&&J(i,Wt),(G===Wt||G&&G.startsWith(Wt+"/"))&&R(i,null)),Et()}).catch(()=>K.error(e("sidebarFilesTree.toast.operationFailed"))).finally(bt);return}bt()},t[77]=ee,t[78]=be,t[79]=se,t[80]=n,t[81]=U,t[82]=J,t[83]=i,t[84]=G,t[85]=R,t[86]=e,t[87]=ze):ze=t[87];const rt=ze;let Ge,ct,Pe,Me,Ue,He,lt;if(t[88]!==Z||t[89]!==me||t[90]!==k||t[91]!==te||t[92]!==r||t[93]!==O||t[94]!==Fe||t[95]!==n.downloadFile||t[96]!==tt||t[97]!==We||t[98]!==qe||t[99]!==Q||t[100]!==I||t[101]!==q||t[102]!==i||t[103]!==u||t[104]!==x||t[105]!==j||t[106]!==G||t[107]!==e||t[108]!==Ze){let re=function(sn,mn){const gn=k[sn]??[];return gn.map(($s,Hs)=>{const dn=$s.type==="directory",Kn=dn&&O.includes($s.path),Hn=G===$s.path,kr=Hs===gn.length-1;return s.jsxs("li",{className:"relative",children:[mn>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),kr&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(h2,{node:$s,root:i,isExpanded:Kn,isActive:Hn,status:dn?void 0:tt($s.path),badge:dn?We($s.path):void 0,permissions:Fe,downloadFile:n.downloadFile,contextMenuPath:te,setContextMenuPath:X,onSelect:qe,onToggle:Ze,onRevealPath:Q,onOpenDialog:ve}),dn&&Kn&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:re($s.path,mn+1)})]},$s.path)})};const bt=!!(i&&k[i]),Et=i?I[i]:null;He="flex h-full min-h-0 flex-col overflow-hidden bg-sidebar";let Wt;t[116]===Symbol.for("react.memo_cache_sentinel")?(Wt=s.jsx(A,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),t[116]=Wt):Wt=t[116];let ts;t[117]===Symbol.for("react.memo_cache_sentinel")?(ts=sn=>p(sn.target.value),t[117]=ts):ts=t[117];let ss;t[118]!==e?(ss=e("sidebarFilesTree.search.placeholder"),t[118]=e,t[119]=ss):ss=t[119];let Ke;t[120]!==u||t[121]!==ss?(Ke=s.jsx($t,{ref:g,value:u,onChange:ts,placeholder:ss,className:"h-8 pl-8 pr-8 typography-meta"}),t[120]=u,t[121]=ss,t[122]=Ke):Ke=t[122];let Je;t[123]!==u||t[124]!==e?(Je=u.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:()=>{p(""),g.current?.focus()},children:s.jsx(A,{name:"close",className:"h-4 w-4"})}):null,t[123]=u,t[124]=e,t[125]=Je):Je=t[125];let Ct;t[126]!==Ke||t[127]!==Je?(Ct=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Wt,Ke,Je]}),t[126]=Ke,t[127]=Je,t[128]=Ct):Ct=t[128];let kt;t[129]!==Z||t[130]!==r||t[131]!==e?(kt=Z&&s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>ve("createFile",{path:r,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFileTitle"),"aria-label":e("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(A,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(At,{side:"bottom",sideOffset:6,children:e("sidebarFilesTree.actions.newFileTitle")})]}),t[129]=Z,t[130]=r,t[131]=e,t[132]=kt):kt=t[132];let Kt;t[133]!==me||t[134]!==r||t[135]!==e?(Kt=me&&s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>ve("createFolder",{path:r,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFolderTitle"),"aria-label":e("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(A,{name:"folder-add",className:"h-4 w-4"})})})}),s.jsx(At,{side:"bottom",sideOffset:6,children:e("sidebarFilesTree.actions.newFolderTitle")})]}),t[133]=me,t[134]=r,t[135]=e,t[136]=Kt):Kt=t[136];let Tt;t[137]!==q?(Tt=()=>{q()},t[137]=q,t[138]=Tt):Tt=t[138];let gs;t[139]!==e?(gs=e("sidebarFilesTree.actions.refreshTitle"),t[139]=e,t[140]=gs):gs=t[140];let js;t[141]!==e?(js=e("sidebarFilesTree.actions.refreshTitle"),t[141]=e,t[142]=js):js=t[142];let Ls;t[143]===Symbol.for("react.memo_cache_sentinel")?(Ls=s.jsx(A,{name:"refresh",className:"h-4 w-4"}),t[143]=Ls):Ls=t[143];let Os;t[144]!==Tt||t[145]!==gs||t[146]!==js?(Os=s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(he,{variant:"ghost",size:"sm",onClick:Tt,className:"h-8 w-8 p-0 flex-shrink-0",title:gs,"aria-label":js,children:Ls})})}),t[144]=Tt,t[145]=gs,t[146]=js,t[147]=Os):Os=t[147];let tn;t[148]!==e?(tn=e("sidebarFilesTree.actions.refreshTitle"),t[148]=e,t[149]=tn):tn=t[149];let cn;t[150]!==tn?(cn=s.jsx(At,{side:"bottom",sideOffset:6,children:tn}),t[150]=tn,t[151]=cn):cn=t[151];let Zs;t[152]!==Os||t[153]!==cn?(Zs=s.jsxs(It,{children:[Os,cn]}),t[152]=Os,t[153]=cn,t[154]=Zs):Zs=t[154],t[155]!==Ct||t[156]!==kt||t[157]!==Kt||t[158]!==Zs?(lt=s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[Ct,kt,Kt,Zs]}),t[155]=Ct,t[156]=kt,t[157]=Kt,t[158]=Zs,t[159]=lt):lt=t[159],Ge=vs,Me="flex-1 min-h-0",Ue="p-2",ct="flex flex-col",Pe=j?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("sidebarFilesTree.state.searching")]}):x.length>0?x.map(sn=>{const mn=G===sn.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>qe(sn),draggable:!0,onDragStart:gn=>{const $s=sn.relativePath||jg(i??"",sn.path);!$s||$s==="."||(gn.dataTransfer.setData("application/x-openchamber-file-path",$s),gn.dataTransfer.effectAllowed="copy")},className:ge("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",mn?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:sn.path,children:[Ng(sn.path,sn.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:sn.relativePath??sn.path})]})},sn.path)}):Et?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{children:Et}),s.jsxs(he,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{q()},children:[s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"}),e("sidebarFilesTree.actions.refreshTitle")]})]}):bt&&i?re(i,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("sidebarFilesTree.state.loading")}),t[88]=Z,t[89]=me,t[90]=k,t[91]=te,t[92]=r,t[93]=O,t[94]=Fe,t[95]=n.downloadFile,t[96]=tt,t[97]=We,t[98]=qe,t[99]=Q,t[100]=I,t[101]=q,t[102]=i,t[103]=u,t[104]=x,t[105]=j,t[106]=G,t[107]=e,t[108]=Ze,t[109]=Ge,t[110]=ct,t[111]=Pe,t[112]=Me,t[113]=Ue,t[114]=He,t[115]=lt}else Ge=t[109],ct=t[110],Pe=t[111],Me=t[112],Ue=t[113],He=t[114],lt=t[115];let vt;t[160]!==ct||t[161]!==Pe?(vt=s.jsx("ul",{className:ct,children:Pe}),t[160]=ct,t[161]=Pe,t[162]=vt):vt=t[162];let ft;t[163]!==Ge||t[164]!==Me||t[165]!==Ue||t[166]!==vt?(ft=s.jsx(Ge,{outerClassName:Me,className:Ue,children:vt}),t[163]=Ge,t[164]=Me,t[165]=Ue,t[166]=vt,t[167]=ft):ft=t[167];const dt=!!ee;let Dt;t[168]===Symbol.for("react.memo_cache_sentinel")?(Dt=re=>!re&&fe(null),t[168]=Dt):Dt=t[168];let Qt;t[169]!==ee||t[170]!==e?(Qt=ee==="createFile"&&e("sidebarFilesTree.dialog.createFile.title"),t[169]=ee,t[170]=e,t[171]=Qt):Qt=t[171];let Ft;t[172]!==ee||t[173]!==e?(Ft=ee==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.title"),t[172]=ee,t[173]=e,t[174]=Ft):Ft=t[174];let qt;t[175]!==ee||t[176]!==e?(qt=ee==="rename"&&e("sidebarFilesTree.dialog.rename.title"),t[175]=ee,t[176]=e,t[177]=qt):qt=t[177];let gt;t[178]!==ee||t[179]!==e?(gt=ee==="delete"&&e("sidebarFilesTree.dialog.delete.title"),t[178]=ee,t[179]=e,t[180]=gt):gt=t[180];let zt;t[181]!==Qt||t[182]!==Ft||t[183]!==qt||t[184]!==gt?(zt=s.jsxs(ds,{children:[Qt,Ft,qt,gt]}),t[181]=Qt,t[182]=Ft,t[183]=qt,t[184]=gt,t[185]=zt):zt=t[185];let es;t[186]!==ee||t[187]!==be?.path||t[188]!==e?(es=ee==="createFile"&&e("sidebarFilesTree.dialog.createFile.description",{path:be?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[186]=ee,t[187]=be?.path,t[188]=e,t[189]=es):es=t[189];let is;t[190]!==ee||t[191]!==be?.path||t[192]!==e?(is=ee==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.description",{path:be?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[190]=ee,t[191]=be?.path,t[192]=e,t[193]=is):is=t[193];let cs;t[194]!==ee||t[195]!==be?.name||t[196]!==e?(cs=ee==="rename"&&e("sidebarFilesTree.dialog.rename.description",{name:be?.name??""}),t[194]=ee,t[195]=be?.name,t[196]=e,t[197]=cs):cs=t[197];let hs;t[198]!==ee||t[199]!==be?.name||t[200]!==e?(hs=ee==="delete"&&e("sidebarFilesTree.dialog.delete.description",{name:be?.name??""}),t[198]=ee,t[199]=be?.name,t[200]=e,t[201]=hs):hs=t[201];let _t;t[202]!==es||t[203]!==is||t[204]!==cs||t[205]!==hs?(_t=s.jsxs(ys,{children:[es,is,cs,hs]}),t[202]=es,t[203]=is,t[204]=cs,t[205]=hs,t[206]=_t):_t=t[206];let Ye;t[207]!==zt||t[208]!==_t?(Ye=s.jsxs(ps,{children:[zt,_t]}),t[207]=zt,t[208]=_t,t[209]=Ye):Ye=t[209];let Mt;t[210]!==ee||t[211]!==se||t[212]!==rt||t[213]!==e?(Mt=ee!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx($t,{value:se,onChange:re=>ie(re.target.value),placeholder:e(ee==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:re=>{re.key==="Enter"&&rt()},autoFocus:!0})}),t[210]=ee,t[211]=se,t[212]=rt,t[213]=e,t[214]=Mt):Mt=t[214];let Bt;t[215]===Symbol.for("react.memo_cache_sentinel")?(Bt=()=>fe(null),t[215]=Bt):Bt=t[215];let wt;t[216]!==e?(wt=e("sidebarFilesTree.dialog.cancel"),t[216]=e,t[217]=wt):wt=t[217];let Zt;t[218]!==ae||t[219]!==wt?(Zt=s.jsx(he,{variant:"outline",onClick:Bt,disabled:ae,children:wt}),t[218]=ae,t[219]=wt,t[220]=Zt):Zt=t[220];const us=ee==="delete"?"destructive":"default";let Es;t[221]!==rt?(Es=()=>{rt()},t[221]=rt,t[222]=Es):Es=t[222];let ws;t[223]!==ee||t[224]!==se||t[225]!==ae?(ws=ae||ee!=="delete"&&!se.trim(),t[223]=ee,t[224]=se,t[225]=ae,t[226]=ws):ws=t[226];let Ds;t[227]!==ee||t[228]!==ae||t[229]!==e?(Ds=ae?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):e(ee==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm"),t[227]=ee,t[228]=ae,t[229]=e,t[230]=Ds):Ds=t[230];let Xt;t[231]!==us||t[232]!==Es||t[233]!==ws||t[234]!==Ds?(Xt=s.jsx(he,{variant:us,onClick:Es,disabled:ws,children:Ds}),t[231]=us,t[232]=Es,t[233]=ws,t[234]=Ds,t[235]=Xt):Xt=t[235];let en;t[236]!==Zt||t[237]!==Xt?(en=s.jsxs(Rs,{children:[Zt,Xt]}),t[236]=Zt,t[237]=Xt,t[238]=en):en=t[238];let Ks;t[239]!==Ye||t[240]!==Mt||t[241]!==en?(Ks=s.jsxs(os,{children:[Ye,Mt,en]}),t[239]=Ye,t[240]=Mt,t[241]=en,t[242]=Ks):Ks=t[242];let Us;t[243]!==dt||t[244]!==Ks?(Us=s.jsx(ls,{open:dt,onOpenChange:Dt,children:Ks}),t[243]=dt,t[244]=Ks,t[245]=Us):Us=t[245];let Xs;return t[246]!==He||t[247]!==lt||t[248]!==ft||t[249]!==Us?(Xs=s.jsxs("section",{className:He,children:[lt,ft,Us]}),t[246]=He,t[247]=lt,t[248]=ft,t[249]=Us,t[250]=Xs):Xs=t[250],Xs};function x2(t){return t.searchFiles}function b2(t){return t.openContextFile}function y2(t){return t.setSelectedPath}function v2(t){return t.addOpenPath}function w2(t){return t.removeOpenPathsByPrefix}function j2(t){return t.toggleExpandedPath}function N2(t){return t.mode==="file"?t.targetPath:null}function S2(t){return typeof t=="string"&&t.length>0}function k2(t){return Jn(t)}function C2(t){return t&&typeof t.name=="string"&&t.name.length>0}function I2(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function P2(t){return t.entries.map(I2)}function A2(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function D2(t){return t.map(A2)}function T2(t){return Object.keys(t).length===0?t:{}}function E2(t){return Object.keys(t).length===0?t:{}}function M2(t){return Jn(t)}function R2(t,e){return t.split("/").length-e.split("/").length}function F2(t){return{name:t.name,path:Jn(t.path),type:"file",extension:t.extension,relativePath:t.relativePath}}function L2(t,e){const n=ot.c(6),{git:r}=Wn(),a=qs(O2);let i,l;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)},l=[t,r,e,a],n[0]=t,n[1]=a,n[2]=r,n[3]=e,n[4]=i,n[5]=l):(i=n[4],l=n[5]),o.useEffect(i,l)}function O2(t){return t.ensureStatus}const Sg=()=>{const t=ot.c(17),e=Ss(_2),n=Ss(B2),r=Ms(V2),a=qs(z2);let i;e:{if(e){let g;t[0]!==e||t[1]!==n?(g=n.find(y=>y.id===e)??n[0]??null,t[0]=e,t[1]=n,t[2]=g):g=t[2],i=g;break e}i=n[0]??null}const l=i;let c;e:{if(!l){c=null;break e}let g;t[3]!==l.id||t[4]!==l.path?(g={id:l.id,path:l.path},t[3]=l.id,t[4]=l.path,t[5]=g):g=t[5],c=g}const d=c;let f;e:{if(!l){f=null;break e}let g;t[6]!==l.label||t[7]!==l.path||t[8]!==r?(g=l.label?.trim()||Ja(l.path,r)||l.path,t[6]=l.label,t[7]=l.path,t[8]=r,t[9]=g):g=t[9],f=g}const m=f;let u;e:{if(!l){u=!1;break e}let g;t[10]!==l.path||t[11]!==a?(g=a.get(l.path)?.isGitRepo,t[10]=l.path,t[11]=a,t[12]=g):g=t[12],u=g===!0}const p=u;let b;return t[13]!==p||t[14]!==m||t[15]!==d?(b=s.jsx("div",{className:"h-full min-h-0 overflow-auto bg-sidebar",children:s.jsx(gj,{projectRef:d,projectLabel:m,canCreateWorktree:p})}),t[13]=p,t[14]=m,t[15]=d,t[16]=b):b=t[16],b},$2=()=>{const t=ot.c(38),{t:e}=pt(),n=_e(U2),r=_e(W2),a=_e(K2),i=la();L2(i,a);let l;t[0]!==e?(l=e("layout.rightSidebar.git"),t[0]=e,t[1]=l):l=t[1];let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"}),t[2]=c):c=t[2];let d;t[3]!==l?(d={id:"git",label:l,icon:c},t[3]=l,t[4]=d):d=t[4];let f;t[5]!==e?(f=e("layout.rightSidebar.files"),t[5]=e,t[6]=f):f=t[6];let m;t[7]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(A,{name:"folder-3",className:"h-3.5 w-3.5"}),t[7]=m):m=t[7];let u;t[8]!==f?(u={id:"files",label:f,icon:m},t[8]=f,t[9]=u):u=t[9];let p;t[10]!==e?(p=e("layout.rightSidebar.context"),t[10]=e,t[11]=p):p=t[11];let b;t[12]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(A,{name:"file-list-2",className:"h-3.5 w-3.5"}),t[12]=b):b=t[12];let g;t[13]!==p?(g={id:"context",label:p,icon:b},t[13]=p,t[14]=g):g=t[14];let y;t[15]!==d||t[16]!==u||t[17]!==g?(y=[d,u,g],t[15]=d,t[16]=u,t[17]=g,t[18]=y):y=t[18];const x=y;let h;t[19]!==r?(h=I=>r(I),t[19]=r,t[20]=h):h=t[20];let j;t[21]!==n||t[22]!==h||t[23]!==x?(j=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx(Fr,{items:x,activeId:n,onSelect:h,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[21]=n,t[22]=h,t[23]=x,t[24]=j):j=t[24];let v;t[25]!==n?(v=n==="git"&&s.jsx(wg,{}),t[25]=n,t[26]=v):v=t[26];let C;t[27]!==n?(C=n==="files"&&s.jsx(g2,{}),t[27]=n,t[28]=C):C=t[28];let k;t[29]!==n?(k=n==="context"&&s.jsx(Sg,{}),t[29]=n,t[30]=k):k=t[30];let w;t[31]!==v||t[32]!==C||t[33]!==k?(w=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[v,C,k]}),t[31]=v,t[32]=C,t[33]=k,t[34]=w):w=t[34];let N;return t[35]!==j||t[36]!==w?(N=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[j,w]}),t[35]=j,t[36]=w,t[37]=N):N=t[37],N};function _2(t){return t.activeProjectId}function B2(t){return t.projects}function V2(t){return t.homeDirectory}function z2(t){return t.directories}function U2(t){return t.rightSidebarTab}function W2(t){return t.setRightSidebarTab}function K2(t){return t.isRightSidebarOpen}const H2=1100,Td=15e3,cp=500,G2=t=>t<=6?t:t<=12?6:t<=25?4:2,kg=o.memo(()=>{const t=ot.c(4),{t:e}=pt();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}),Cg={"?":{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"}},q2=Cg.M,bl=[{value:"single",labelKey:"diffView.mode.single.label",descriptionKey:"diffView.mode.single.description"},{value:"stacked",labelKey:"diffView.mode.stacked.label",descriptionKey:"diffView.mode.stacked.description"}],J2=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"},Ig=t=>{const e=J2(t);return Cg[e]??q2},Y2=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},Q2=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},X2=t=>!!t.working_dir?.trim()||t.index==="?",Z2=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),eS=(t,e)=>{const n=t.replace(/\\/g,"/").replace(/\/+$/g,""),r=e.replace(/\\/g,"/");if(Z2(r))return r;const a=r.replace(/^\/+/,"");return n?`${n}/${a}`:a},dp=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),up=(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},tS=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},Wl=(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]})},sS=o.memo(t=>{const e=ot.c(29),{changedFiles:n,selectedFile:r,selectedFileEntry:a,onSelectFile:i,isMobile:l,showModeSelector:c,mode:d,onModeChange:f}=t,m=c===void 0?!1:c,{t:u}=pt();let p;e[0]!==l?(p=N=>{if(!l)return N;const I=N.lastIndexOf("/");return I>=0?N.slice(I+1):N},e[0]=l,e[1]=p):p=e[1];const b=p;if(n.length===0)return null;let g;e[2]!==b||e[3]!==a||e[4]!==u?(g=a?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx(Er,{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)}),Wl(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]=g):g=e[5];let y;e[6]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[6]=y):y=e[6];let x;e[7]!==g?(x=s.jsx(Is,{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:[g,y]})}),e[7]=g,e[8]=x):x=e[8];let h;e[9]!==d||e[10]!==f||e[11]!==m||e[12]!==u?(h=m&&d&&f?s.jsxs(s.Fragment,{children:[s.jsx(gh,{className:"typography-meta text-muted-foreground",children:u("diffView.selector.viewMode")}),s.jsx(Ml,{value:d,onValueChange:N=>f(N),children:bl.map(N=>s.jsx(Rl,{value:N.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:u(N.labelKey)})},N.value))}),s.jsx(nr,{})]}):null,e[9]=d,e[10]=f,e[11]=m,e[12]=u,e[13]=h):h=e[13];const j=r??"";let v;if(e[14]!==n||e[15]!==b){let N;e[17]!==b?(N=I=>s.jsx(Rl,{value:I.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(Er,{filePath:I.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(I.path)}),s.jsx("span",{className:"ml-auto",children:Wl(I.insertions,I.deletions)})]})},I.path),e[17]=b,e[18]=N):N=e[18],v=n.map(N),e[14]=n,e[15]=b,e[16]=v}else v=e[16];let C;e[19]!==i||e[20]!==j||e[21]!==v?(C=s.jsx(Ml,{value:j,onValueChange:i,children:v}),e[19]=i,e[20]=j,e[21]=v,e[22]=C):C=e[22];let k;e[23]!==h||e[24]!==C?(k=s.jsxs(Ps,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[h,C]}),e[23]=h,e[24]=C,e[25]=k):k=e[25];let w;return e[26]!==k||e[27]!==x?(w=s.jsxs(As,{children:[x,k]}),e[26]=k,e[27]=x,e[28]=w):w=e[28],w}),nS=o.memo(t=>{const e=ot.c(31),{mode:n,onModeChange:r}=t,{t:a}=pt();let i,l,c,d,f,m;if(e[0]!==n||e[1]!==a){const v=bl.find(C=>C.value===n)??bl[0];l=As,i=Is,m=!0,f="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(v.labelKey),e[0]=n,e[1]=a,e[2]=i,e[3]=l,e[4]=c,e[5]=d,e[6]=f,e[7]=m}else i=e[2],l=e[3],c=e[4],d=e[5],f=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 p;e[11]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[11]=p):p=e[11];let b;e[12]!==f||e[13]!==u?(b=s.jsxs("button",{className:f,children:[u,p]}),e[12]=f,e[13]=u,e[14]=b):b=e[14];let g;e[15]!==i||e[16]!==m||e[17]!==b?(g=s.jsx(i,{asChild:m,children:b}),e[15]=i,e[16]=m,e[17]=b,e[18]=g):g=e[18];let y;e[19]!==r?(y=v=>r(v),e[19]=r,e[20]=y):y=e[20];let x;e[21]!==a?(x=bl.map(v=>s.jsx(Rl,{value:v.value,children:s.jsx("span",{className:"typography-meta text-foreground",children:a(v.labelKey)})},v.value)),e[21]=a,e[22]=x):x=e[22];let h;e[23]!==n||e[24]!==x||e[25]!==y?(h=s.jsx(Ps,{className:"min-w-[140px]",children:s.jsx(Ml,{value:n,onValueChange:y,children:x})}),e[23]=n,e[24]=x,e[25]=y,e[26]=h):h=e[26];let j;return e[27]!==l||e[28]!==h||e[29]!==g?(j=s.jsxs(l,{children:[g,h]}),e[27]=l,e[28]=h,e[29]=g,e[30]=j):j=e[30],j}),rS=o.memo(t=>{const e=ot.c(11),{changedFiles:n,selectedFile:r,onSelectFile:a}=t,{t:i}=pt();if(n.length===0)return null;let l;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=f=>{const m=Ig(f),u=r===f.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>a(f.path),className:ge("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(Er,{filePath:f.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:f.path,children:f.path}),Wl(f.insertions,f.deletions)]})},f.path)},e[5]=a,e[6]=r,e[7]=i,e[8]=d):d=e[8],l=n.map(d),e[0]=n,e[1]=a,e[2]=r,e[3]=i,e[4]=l}else l=e[4];let c;return e[9]!==l?(c=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:l})}),e[9]=l,e[10]=c):c=e[10],c}),aS=o.memo(t=>{const e=ot.c(21),{filePath:n,diff:r,isVisible:a,renderSideBySide:i}=t,{t:l}=pt(),c=r.original.length>0,d=r.modified.length>0;if(!a){let y;return e[0]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"absolute inset-0 hidden"}),e[0]=y):y=e[0],y}const f=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 p;e[2]!==r.original||e[3]!==n||e[4]!==c||e[5]!==m||e[6]!==i||e[7]!==l?(p=c&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:l("diffView.image.original")}),s.jsx("img",{src:r.original,alt:l("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]=l,e[8]=p):p=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]!==l?(b=d&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:l(c?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:l("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]=l,e[16]=b):b=e[16];let g;return e[17]!==f||e[18]!==p||e[19]!==b?(g=s.jsx("div",{className:"absolute inset-0 overflow-auto p-4",style:u,children:s.jsxs("div",{className:f,children:[p,b]})}),e[17]=f,e[18]=p,e[19]=b,e[20]=g):g=e[20],g}),iS=o.memo(t=>{const e=ot.c(20),{filePath:n,diff:r,renderSideBySide:a}=t,{t:i}=pt(),l=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",f=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]!==l||e[4]!==f||e[5]!==a||e[6]!==i?(u=l&&s.jsxs("div",{className:f,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]=l,e[4]=f,e[5]=a,e[6]=i,e[7]=u):u=e[7];let p;e[8]!==r.modified||e[9]!==n||e[10]!==c||e[11]!==l||e[12]!==f||e[13]!==a||e[14]!==i?(p=c&&s.jsxs("div",{className:f,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i(l?"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]=l,e[12]=f,e[13]=a,e[14]=i,e[15]=p):p=e[15];let b;return e[16]!==d||e[17]!==u||e[18]!==p?(b=s.jsx("div",{className:"w-full overflow-auto p-4",style:m,children:s.jsxs("div",{className:d,children:[u,p]})}),e[16]=d,e[17]=u,e[18]=p,e[19]=b):b=e[19],b}),oS=o.memo(t=>{const e=ot.c(15),{filePath:n,diff:r,renderSideBySide:a,wrapLines:i}=t;let l;e[0]!==n?(l=Pi(n)||"text",e[0]=n,e[1]=l):l=e[1];const c=l;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(kg,{}),e[2]=m):m=e[2],m}if(Ai(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a?(m=s.jsx(iS,{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 f;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==c||e[12]!==a||e[13]!==i?(f=s.jsx("div",{className:"w-full",style:d,children:s.jsx(xu,{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]=f):f=e[14],f}),lS=o.memo(t=>{const e=ot.c(15),{filePath:n,diff:r,isVisible:a,renderSideBySide:i,wrapLines:l}=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(kg,{}),e[2]=m):m=e[2],m}if(!a)return null;if(Ai(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a||e[6]!==i?(m=s.jsx(aS,{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 f;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==d||e[12]!==i||e[13]!==l?(f=s.jsx(vs,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(xu,{original:r.original,modified:r.modified,language:d,fileName:n,renderSideBySide:i,wrapLines:l,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=d,e[12]=i,e[13]=l,e[14]=f):f=e[14],f}),cS=o.memo(t=>{const e=ot.c(129),{directory:n,file:r,layout:a,wrapLines:i,scrollRootRef:l,isSelected:c,onSelect:d,registerSectionRef:f,defaultCollapsed:m,expandRequestPath:u,expandRequestNonce:p,showOpenInEditorAction:b,isOpeningInEditor:g,onOpenInEditor:y,staged:x,stagedRevision:h}=t,j=m===void 0?!1:m,v=u===void 0?null:u,C=p===void 0?0:p,k=b===void 0?!1:b,w=g===void 0?!1:g,N=x===void 0?!1:x,I=h===void 0?0:h,{t:E}=pt(),{git:P}=Wn();let T;e[0]!==n||e[1]!==r.path?(T=ct=>ct.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=T):T=e[2];const S=qs(T),M=qs(uS),D=_e(mS),[F,_]=o.useState(!j),[V,$]=o.useState(!1),[O,B]=o.useState(0),[G,R]=o.useState(null),[H,J]=o.useState(!1),[ne,ue]=o.useState(!1),[de,pe]=o.useState(null),W=o.useRef(null),te=o.useRef(null);let X;e[3]!==r?(X=Ig(r),e[3]=r,e[4]=X):X=e[4];const ee=X,fe=a==="side-by-side";let be;e:{if(N){be=de;break e}if(!S){be=null;break e}let ct;e[5]!==S.isBinary||e[6]!==S.modified||e[7]!==S.original?(ct={original:S.original,modified:S.modified,isBinary:S.isBinary},e[5]=S.isBinary,e[6]=S.modified,e[7]=S.original,e[8]=ct):ct=e[8],be=ct}const Ne=be;let se;e[9]!==r.path||e[10]!==f?(se=ct=>{te.current=ct,f(r.path,ct)},e[9]=r.path,e[10]=f,e[11]=se):se=e[11];const ie=se;let ae;e[12]===Symbol.for("react.memo_cache_sentinel")?(ae=ct=>{_(ct),ct&&$(!0)},e[12]=ae):ae=e[12];const xe=ae;let Z;e[13]!==r.path||e[14]!==d?(Z=()=>{d(r.path)},e[13]=r.path,e[14]=d,e[15]=Z):Z=e[15];const me=Z;let Y,Se;e[16]!==V||e[17]!==F||e[18]!==l?(Y=()=>{if(!F||V)return;const ct=te.current;if(!ct)return;if(!l.current||typeof IntersectionObserver>"u"){$(!0);return}const Pe=new IntersectionObserver(Me=>{Me.some(pS)&&($(!0),Pe.disconnect())},{root:l.current,rootMargin:"200px 0px",threshold:.1});return Pe.observe(ct),()=>Pe.disconnect()},Se=[V,F,l],e[16]=V,e[17]=F,e[18]=l,e[19]=Y,e[20]=Se):(Y=e[19],Se=e[20]),o.useEffect(Y,Se);let we,ke;e[21]!==C||e[22]!==v||e[23]!==r.path?(we=()=>{C<=0||v!==r.path||(_(!0),$(!0))},ke=[C,v,r.path],e[21]=C,e[22]=v,e[23]=r.path,e[24]=we,e[25]=ke):(we=e[24],ke=e[25]),o.useEffect(we,ke);let Fe;e[26]!==N?(Fe=()=>{N&&(pe(null),R(null),W.current=null)},e[26]=N,e[27]=Fe):Fe=e[27];let Ce;e[28]!==N||e[29]!==I?(Ce=[N,I],e[28]=N,e[29]=I,e[30]=Ce):Ce=e[30],o.useEffect(Fe,Ce);let Q,ce;e[31]!==Ne||e[32]!==O||e[33]!==n||e[34]!==r.path||e[35]!==P||e[36]!==V||e[37]!==F||e[38]!==M||e[39]!==N||e[40]!==I?(Q=()=>{if(!F||!V)return;if(!n||Ne){W.current=null,J(!1);return}const ct=`${n}::${r.path}::${N?`staged:${I}`:"unstaged"}::${O}`;if(W.current===ct)return;W.current=ct,R(null),J(!0);let Pe=!1;const Me=P.getGitFileDiff(n,{path:r.path,staged:N}),Ue=new Promise(fS);return Promise.race([Me,Ue]).then(He=>{if(Pe)return;const lt={original:He.original??"",modified:He.modified??"",isBinary:He.isBinary};N?pe(lt):M(n,r.path,lt),J(!1)}).catch(He=>{if(Pe)return;const lt=He instanceof Error?He.message:String(He);R(lt),J(!1)}),()=>{Pe=!0,W.current===ct&&(W.current=null)}},ce=[n,Ne,O,r.path,P,V,F,M,N,I],e[31]=Ne,e[32]=O,e[33]=n,e[34]=r.path,e[35]=P,e[36]=V,e[37]=F,e[38]=M,e[39]=N,e[40]=I,e[41]=Q,e[42]=ce):(Q=e[41],ce=e[42]),o.useEffect(Q,ce);let ve;e[43]!==me||e[44]!==F?(ve=()=>{xe(!F),me()},e[43]=me,e[44]=F,e[45]=ve):ve=e[45];const le=ve,Ae=F?"rounded-b-none":"rounded-b-xl",Te=c?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let $e;e[46]!==Ae||e[47]!==Te?($e=ge("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",Ae,"text-muted-foreground hover:text-foreground",Te),e[46]=Ae,e[47]=Te,e[48]=$e):$e=e[48];let ye;e[49]===Symbol.for("react.memo_cache_sentinel")?(ye=s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-interactive-hover"}),e[49]=ye):ye=e[49];let q;e[50]!==F?(q=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:F?s.jsx(A,{name:"arrow-down-s",className:"size-4"}):s.jsx(A,{name:"arrow-right-s",className:"size-4"})}),e[50]=F,e[51]=q):q=e[51];let L;e[52]!==ee.color?(L={color:ee.color},e[52]=ee.color,e[53]=L):L=e[53];let U;e[54]!==ee.descriptionKey||e[55]!==E?(U=E(ee.descriptionKey),e[54]=ee.descriptionKey,e[55]=E,e[56]=U):U=e[56];let oe;e[57]!==ee.descriptionKey||e[58]!==E?(oe=E(ee.descriptionKey),e[57]=ee.descriptionKey,e[58]=E,e[59]=oe):oe=e[59];let Ee;e[60]!==ee.code||e[61]!==L||e[62]!==U||e[63]!==oe?(Ee=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:L,title:U,"aria-label":oe,children:ee.code}),e[60]=ee.code,e[61]=L,e[62]=U,e[63]=oe,e[64]=Ee):Ee=e[64];const Oe=r.path;let Ie;e[65]!==r.path?(Ie=s.jsx(Er,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[65]=r.path,e[66]=Ie):Ie=e[66];let z;if(e[67]!==r.path){e:{const ct=r.path.lastIndexOf("/");if(ct===-1){let dt;e[69]===Symbol.for("react.memo_cache_sentinel")?(dt={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[69]=dt):dt=e[69],z=s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:dt,children:r.path});break e}const Pe=r.path.slice(0,ct),Me=r.path.slice(ct+1);let Ue;e[70]===Symbol.for("react.memo_cache_sentinel")?(Ue={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[70]=Ue):Ue=e[70];let He;e[71]!==Pe?(He=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:Ue,children:Pe}),e[71]=Pe,e[72]=He):He=e[72];let lt;e[73]===Symbol.for("react.memo_cache_sentinel")?(lt=s.jsx("span",{className:"text-muted-foreground",children:"/"}),e[73]=lt):lt=e[73];let vt;e[74]!==Me?(vt=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[lt,s.jsx("span",{className:"text-foreground",children:Me})]}),e[74]=Me,e[75]=vt):vt=e[75];let ft;e[76]!==He||e[77]!==vt?(ft=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[He,vt]}),e[76]=He,e[77]=vt,e[78]=ft):ft=e[78],z=ft}e[67]=r.path,e[68]=z}else z=e[68];let De;e[79]!==Ie||e[80]!==z?(De=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[Ie,z]}),e[79]=Ie,e[80]=z,e[81]=De):De=e[81];let Qe;e[82]!==r.path||e[83]!==De?(Qe=s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:Oe,children:De}),e[82]=r.path,e[83]=De,e[84]=Qe):Qe=e[84];let tt;e[85]!==q||e[86]!==Ee||e[87]!==Qe?(tt=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[q,Ee,Qe]}),e[85]=q,e[86]=Ee,e[87]=Qe,e[88]=tt):tt=e[88];let et;e[89]!==r.deletions||e[90]!==r.insertions?(et=Wl(r.insertions,r.deletions),e[89]=r.deletions,e[90]=r.insertions,e[91]=et):et=e[91];let We;e[92]!==Ne||e[93]!==r.path||e[94]!==w||e[95]!==y||e[96]!==k||e[97]!==E?(We=k&&y?s.jsx(he,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:E("diffView.actions.openFileInEditorAtChange"),onClick:ct=>{ct.stopPropagation(),y(r.path,Ne)},disabled:w,children:w?s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(A,{name:"edit",className:"size-3.5"})}):null,e[92]=Ne,e[93]=r.path,e[94]=w,e[95]=y,e[96]=k,e[97]=E,e[98]=We):We=e[98];const at=fe?"side-by-side":"unified";let qe;e[99]!==r.path||e[100]!==D?(qe=ct=>{const Pe=ct==="side-by-side"?"side-by-side":"inline";D(r.path,Pe)},e[99]=r.path,e[100]=D,e[101]=qe):qe=e[101];let nt;e[102]!==at||e[103]!==qe?(nt=s.jsx(Ph,{mode:at,onModeChange:qe,className:"opacity-70"}),e[102]=at,e[103]=qe,e[104]=nt):nt=e[104];let Ze;e[105]!==et||e[106]!==We||e[107]!==nt?(Ze=s.jsxs("div",{className:"relative flex items-center gap-2",children:[et,We,nt]}),e[105]=et,e[106]=We,e[107]=nt,e[108]=Ze):Ze=e[108];let ze;e[109]!==le||e[110]!==$e||e[111]!==tt||e[112]!==Ze?(ze=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:le,className:$e,children:[ye,tt,Ze]})}),e[109]=le,e[110]=$e,e[111]=tt,e[112]=Ze,e[113]=ze):ze=e[113];let rt;e[114]!==Ne||e[115]!==G||e[116]!==r.deletions||e[117]!==r.insertions||e[118]!==r.path||e[119]!==ne||e[120]!==F||e[121]!==H||e[122]!==fe||e[123]!==i?(rt=F&&s.jsxs("div",{className:"relative border border-t-0 border-border/60 bg-background rounded-b-xl overflow-hidden",children:[G?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:G}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>B(hS),children:"Retry"})]}):null,H&&!Ne&&!G?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),"Loading diff…"]}):null,Ne&&!ne&&r.insertions+r.deletions>cp?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:()=>ue(!0),children:"Render anyway"})]}):null,Ne&&(ne||r.insertions+r.deletions<=cp)?s.jsx(oS,{filePath:r.path,diff:Ne,renderSideBySide:fe,wrapLines:i}):null]}),e[114]=Ne,e[115]=G,e[116]=r.deletions,e[117]=r.insertions,e[118]=r.path,e[119]=ne,e[120]=F,e[121]=H,e[122]=fe,e[123]=i,e[124]=rt):rt=e[124];let Ge;return e[125]!==ie||e[126]!==ze||e[127]!==rt?(Ge=s.jsxs("div",{ref:ie,className:"scroll-mt-4",children:[ze,rt]}),e[125]=ie,e[126]=ze,e[127]=rt,e[128]=Ge):Ge=e[128],Ge}),Pg=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:a=!1,diffScope:i="all",targetFilePath:l=null})=>{const{t:c}=pt(),{git:d,files:f}=Wn(),m=la(),{screenWidth:u,isMobile:p}=an(),b=tu(m??null),g=nc(m??null),y=nu(m??null),x=qs(We=>We.setActiveDirectory),h=qs(We=>We.ensureStatus),j=qs(We=>We.fetchStatus),v=qs(We=>We.setDiff),C=qs(o.useCallback(We=>m?We.directories.get(m)?.indexRevision??0:0,[m])),[k,w]=o.useState(null),[N,I]=o.useState(!1),[E,P]=o.useState(null),[T,S]=o.useState(null),[M,D]=o.useState(0),[F,_]=o.useState(null),[V,$]=o.useState(0),[O,B]=o.useState(null),G=o.useRef(null),R=_e(We=>We.pendingDiffFile),H=_e(We=>We.pendingDiffStaged),J=_e(We=>We.setPendingDiffFile),ne=_e(We=>We.diffLayoutPreference),ue=_e(We=>We.diffFileLayout),de=_e(We=>We.setDiffFileLayout),pe=_e(We=>We.diffWrapLines),W=_e(We=>We.setDiffWrapLines),te=_e(We=>We.diffViewMode),X=_e(We=>We.setDiffViewMode),ee=_e(We=>We.openContextFileAtLine),fe=pe,be=i==="staged"?!0:i==="working"?!1:null,Ne=be??N,se=te==="stacked",ie=p||u<=768,ae=!t&&!ie&&u>=1024,xe=o.useRef(null),Z=o.useRef(new Map),me=o.useRef(null),Y=o.useRef(null),Se=o.useRef(!1);o.useEffect(()=>{if(!r||!se||!F)return;const We=xe.current;if(!We)return;let at=null,qe=!1,nt=0;const Ze=Date.now()+1200;let ze=0;const rt=()=>{qe||(qe=!0,_(null))},Ge=()=>{rt()},ct=()=>{if(ze>0){ze-=1;return}rt()};window.addEventListener("wheel",Ge,{passive:!0,capture:!0}),window.addEventListener("touchstart",Ge,{passive:!0,capture:!0}),window.addEventListener("pointerdown",Ge,{capture:!0}),window.addEventListener("keydown",Ge,{capture:!0}),We.addEventListener("scroll",ct,{passive:!0});const Pe=()=>{if(qe||Date.now()>Ze){rt();return}const Me=xe.current,Ue=Z.current.get(F);if(!Me||!Ue){rt();return}const He=Me.getBoundingClientRect(),vt=Ue.getBoundingClientRect().top-He.top;if(Math.abs(vt)<=1){if(nt+=1,nt>=2){rt();return}}else{nt=0;const ft=Math.max(0,Me.scrollHeight-Me.clientHeight),dt=Math.min(ft,Math.max(0,Me.scrollTop+vt));if(Math.abs(dt-Me.scrollTop)<=.5){rt();return}ze+=1,Me.scrollTop=dt}at=window.requestAnimationFrame(Pe)};return at=window.requestAnimationFrame(Pe),()=>{qe=!0,at!==null&&window.cancelAnimationFrame(at),window.removeEventListener("wheel",Ge,!0),window.removeEventListener("touchstart",Ge,!0),window.removeEventListener("pointerdown",Ge,!0),window.removeEventListener("keydown",Ge,!0),We.removeEventListener("scroll",ct)}},[se,r,F]);const we=o.useMemo(()=>{if(!g?.files)return[];const We=g.diffStats??{},at=i==="staged"?Q2:i==="working"?X2:()=>!0;return g.files.filter(at).map(qe=>({...qe,insertions:We[qe.path]?.insertions??0,deletions:We[qe.path]?.deletions??0,isNew:Y2(qe)})).sort((qe,nt)=>qe.path.localeCompare(nt.path))},[i,g]),ke=o.useMemo(()=>k?we.find(We=>We.path===k)??null:null,[we,k]),Fe=o.useCallback(We=>{const at=ue[We.path];if(at)return at;if(ne==="inline")return"inline";if(ne==="side-by-side")return"side-by-side";const qe=u<H2;return We.isNew||qe?"inline":"side-by-side"},[ue,ne,u]),Ce=o.useMemo(()=>ke?Fe(ke):null,[Fe,ke]);o.useEffect(()=>{m&&(x(m),h(m,d))},[m,x,h,d]),o.useEffect(()=>{if(m)return Mr.onGitRefreshHint(We=>{dp(We.directory)===dp(m)&&j(m,d)})},[m,j,d]),o.useEffect(()=>{i==="all"&&R&&(w(R),I(H),P(null),J(null),se&&(Se.current=!0,me.current=R,S(R),D(We=>We+1)))},[i,se,R,H,J]),o.useEffect(()=>{if(i==="all")return;const We=l?.trim();We&&(w(We),I(i==="staged"),P(null),se&&(Se.current=!0,me.current=We,S(We),D(at=>at+1)))},[i,se,l]),o.useEffect(()=>{Ne&&(P(null),B(null),G.current=null)},[Ne,C]),o.useEffect(()=>{!k&&!R&&we.length>0&&w(we[0].path)},[we,k,R]),o.useEffect(()=>{k&&we.length>0&&(we.some(at=>at.path===k)||w(we[0]?.path??null))},[we,k]);const Q=o.useCallback((We,at)=>{const qe=Z.current;at?qe.set(We,at):qe.delete(We)},[]),ce=o.useCallback(We=>{const at=Z.current.get(We),qe=xe.current;if(!at||!qe)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const nt=qe.getBoundingClientRect(),ze=at.getBoundingClientRect().top-nt.top,rt=Math.max(0,qe.scrollHeight-qe.clientHeight),Ge=qe.scrollTop+ze,ct=Math.min(rt,Math.max(0,Ge)),Pe=Math.abs(ct-qe.scrollTop)>.5;qe.scrollTop=ct;const Me=Math.abs(ze)<=1,Ue=ct<=.5||ct>=rt-.5;return{ok:!0,aligned:Me,didMove:Pe,atScrollLimit:Ue,delta:ze}},[]);o.useEffect(()=>{if(!se){me.current=null,Se.current=!1,Y.current!==null&&(window.cancelAnimationFrame(Y.current),Y.current=null);return}if(!me.current)return;let at=0;const qe=120;let nt=!1,Ze=0,ze=!1,rt=0;const Ge=Date.now()+2e3,ct=()=>{ze||(ze=!0,window.removeEventListener("wheel",Me,!0),window.removeEventListener("touchstart",Me,!0),window.removeEventListener("pointerdown",Me,!0),window.removeEventListener("keydown",Me,!0),He?.removeEventListener("scroll",Ue))},Pe=()=>{nt||(nt=!0,ct(),me.current=null,Se.current=!1,Y.current!==null&&(window.cancelAnimationFrame(Y.current),Y.current=null))},Me=()=>{Pe()},Ue=()=>{if(Ze>0){Ze-=1;return}Pe()},He=xe.current;window.addEventListener("wheel",Me,{passive:!0,capture:!0}),window.addEventListener("touchstart",Me,{passive:!0,capture:!0}),window.addEventListener("pointerdown",Me,{capture:!0}),window.addEventListener("keydown",Me,{capture:!0}),He?.addEventListener("scroll",Ue,{passive:!0});const lt=()=>{if(Date.now()>Ge){Pe(),Y.current=null;return}if(nt){Y.current=null;return}const vt=me.current;if(!vt){Pe(),Y.current=null;return}Ze+=1;const ft=ce(vt);if(!ft.ok){Ze=Math.max(0,Ze-1),at+=1,at<qe?Y.current=window.requestAnimationFrame(lt):(Pe(),Y.current=null);return}if(!ft.aligned){if(at+=1,ft.didMove){if(rt=0,at<qe){Y.current=window.requestAnimationFrame(lt);return}}else if(rt+=1,rt<6&&(ft.atScrollLimit||Math.abs(ft.delta)>1)){Y.current=window.requestAnimationFrame(lt);return}}r&&Se.current&&_(vt),Pe()};return Y.current=window.requestAnimationFrame(lt),()=>{nt=!0,ct(),Y.current!==null&&(window.cancelAnimationFrame(Y.current),Y.current=null)}},[se,r,ce,k,M]);const ve=o.useCallback(We=>{w(We),I(!1),P(null)},[]),le=o.useCallback(We=>{if(Y.current!==null&&(window.cancelAnimationFrame(Y.current),Y.current=null),me.current=null,w(We),I(!1),P(null),!se){Se.current=!1;return}Se.current=!0,me.current=We,ce(We)},[se,ce]),Ae=o.useCallback(We=>{X(We),We==="stacked"&&k&&(ce(k).aligned||(me.current=k))},[ce,k,X]),Te=o.useCallback(We=>{const at=We==="side-by-side"?"side-by-side":"inline";if(se){we.forEach(qe=>{de(qe.path,at)});return}ke&&de(ke.path,at)},[we,se,ke,de]),$e=(Ce??"side-by-side")==="side-by-side",ye=!n&&(!se||!ae),q=qs(o.useCallback(We=>!m||!k||Ne?null:We.directories.get(m)?.diffCache.get(k)??null,[Ne,m,k])),L=o.useMemo(()=>Ne?E:q?{original:q.original,modified:q.modified,isBinary:q.isBinary}:null,[Ne,q,E]),[U,oe]=o.useState(null),Ee=o.useCallback(async(We,at)=>{if(!(!m||!We)){oe(We);try{let qe=null;if(at&&!at.isBinary&&!Ai(We)&&(qe=up(at.original,at.modified)),qe===null)try{const Ge=await d.getGitDiff(m,{path:We,staged:Ne,contextLines:3});qe=tS(Ge.diff)}catch{qe=null}let nt=at;if(qe===null||!nt){const Ge=await d.getGitFileDiff(m,{path:We,staged:Ne});nt={original:Ge.original??"",modified:Ge.modified??"",isBinary:Ge.isBinary},Ne||v(m,We,nt)}const Ze=qe??(nt.isBinary||Ai(We)?1:up(nt.original,nt.modified)),ze=eS(m,We),rt=await vu(f,ze);if(!rt.ok){K.error(wu(rt.reason));return}ee(m,ze,Ze,1)}finally{oe(qe=>qe===We?null:qe)}}},[Ne,m,f,d,ee,v]),Oe=o.useCallback(async()=>{k&&await Ee(k,L)},[Ee,L,k]),Ie=!!(k&&U===k),z=Ne?!!E:!!q,De=!se&&!!k&&!z;o.useEffect(()=>{if(se)return;if(B(null),!m||!k){G.current=null;return}if(Ne?E:q){G.current=null;return}const We=`${m}::${k}::${Ne?`staged:${C}`:"unstaged"}::${V}`;if(G.current===We)return;G.current=We;let at=!1;const qe=d.getGitFileDiff(m,{path:k,staged:Ne}),nt=Td,Ze=new Promise((ze,rt)=>{setTimeout(()=>rt(new Error(`Timed out after ${nt}ms`)),nt)});return Promise.race([qe,Ze]).then(ze=>{if(at)return;const rt={original:ze.original??"",modified:ze.modified??"",isBinary:ze.isBinary};Ne?P(rt):v(m,k,rt)}).catch(ze=>{if(at)return;const rt=ze instanceof Error?ze.message:String(ze);B(rt)}),()=>{at=!0,G.current===We&&(G.current=null)}},[Ne,m,C,se,k,q,E,d,v,V]);const Qe=()=>!m||!k||!L?null:s.jsx(lS,{filePath:k,diff:L,isVisible:!0,renderSideBySide:$e,wrapLines:fe},k),tt=()=>{if(!m)return null;const We=G2(we.length),at=qe=>be!==null?be:N&&qe===k;return s.jsxs("div",{className:"flex flex-1 min-h-0 h-full gap-3 px-3 pb-3 pt-2",children:[ae&&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:c("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:we.length})]}),s.jsx(rS,{changedFiles:we,selectedFile:k,onSelectFile:le})]}),s.jsx(vs,{ref:xe,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:we.map((qe,nt)=>s.jsx(cS,{directory:m,file:qe,layout:Fe(qe),wrapLines:fe,scrollRootRef:xe,isSelected:qe.path===k,onSelect:ve,registerSectionRef:Q,defaultCollapsed:e?!0:nt>=We,expandRequestPath:T,expandRequestNonce:M,showOpenInEditorAction:a,isOpeningInEditor:U===qe.path,onOpenInEditor:(Ze,ze)=>{Ee(Ze,ze)},staged:at(qe.path),stagedRevision:C},`${at(qe.path)?"staged":"unstaged"}:${qe.path}`))})})]})},et=()=>m?y&&!g?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),c("diffView.state.loadingRepositoryStatus")]}):b===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:c("diffView.state.notGitRepository")}):we.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:c("diffView.state.cleanWorkingTree")}):se?tt():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:[Qe(),De&&!z&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted-foreground",children:O?s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:c("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:O}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>{B(null),$(We=>We+1)},children:c("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),c("diffView.state.loadingDiff")]})})]}):s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:c("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:[!p&&s.jsxs("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:[s.jsx(A,{name:"git-commit",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:y&&!g?c("diffView.state.loadingChanges"):we.length===1?c("diffView.summary.changedFilesSingle",{count:we.length}):c("diffView.summary.changedFilesPlural",{count:we.length})})]}),!ie&&s.jsx(nS,{mode:te,onModeChange:Ae}),ye&&s.jsx(sS,{changedFiles:we,selectedFile:k,selectedFileEntry:ke,onSelectFile:le,isMobile:ie,showModeSelector:ie,mode:te,onModeChange:Ae}),s.jsx("div",{className:"flex-1"}),ke&&s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>W(!pe),className:ge("h-5 w-5 p-0 transition-opacity",fe?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:c(fe?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(A,{name:"text-wrap",className:"size-4"})}),a&&ke&&!se&&s.jsx(he,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{Oe()},disabled:Ie,title:c("diffView.actions.openFileAtFirstChangedLine"),children:Ie?s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(A,{name:"edit",className:"size-3.5"})}),ke&&Ce&&s.jsx(Ph,{mode:Ce==="side-by-side"?"side-by-side":"unified",onModeChange:Te})]}),et()]})},dS=()=>{const t=ot.c(6),{git:e}=Wn(),n=la(),r=qs(gS),a=qs(xS),i=uy(n??null);let l,c;return t[0]!==n||t[1]!==a||t[2]!==e||t[3]!==r?(l=()=>{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]=l,t[5]=c):(l=t[4],c=t[5]),o.useEffect(l,c),i};function uS(t){return t.setDiff}function mS(t){return t.setDiffFileLayout}function pS(t){return t.isIntersecting}function fS(t,e){setTimeout(()=>e(new Error(`Timed out after ${Td}ms`)),Td)}function hS(t){return t+1}function gS(t){return t.setActiveDirectory}function xS(t){return t.ensureStatus}const bS=Object.freeze(Object.defineProperty({__proto__:null,DiffView:Pg,useDiffFileCount:dS},Symbol.toStringTag,{value:"Module"})),yS={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},vS={case:"Match case",re:"Regular expression",word:"Match whole word"};function wS(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(yS)){const a=e.querySelector(`button[name="${n}"]`);a&&!a.title&&(a.title=r)}for(const[n,r]of Object.entries(vS)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=r)}}}const Bc=new WeakMap;function jS(t,e){const n=Tl(t.state);if(!n.valid)return Bc.delete(t),0;const r=Bc.get(t);if(!e&&r?.doc===t.state.doc&&r.query.eq(n))return r.total;const a=n.getCursor(t.state);let i=0;for(let l=a.next();!l.done;l=a.next())i+=1;return Bc.set(t,{query:n,doc:t.state.doc,total:i}),i}function NS(t){const e=Tl(t.state);if(!e.valid)return 0;const n=t.state.selection.main,r=e.getCursor(t.state);let a=0,i=0;for(let l=r.next();!l.done;l=r.next()){const c=l.value;if(a+=1,i===0&&(i=a),n.from===c.from&&n.to===c.to||n.from<c.to&&n.to>c.from||c.from>=n.head)return a}return i}function mp(t,e,n=!1){const r=t.querySelector(".cm-search");if(!r)return;let a=r.querySelector(".cm-search-message");if(!a){a=document.createElement("span"),a.className="cm-search-message",a.setAttribute("aria-live","polite");const c=r.querySelector('button[name="next"]'),d=c?.parentNode===r?c:r.firstChild;r.insertBefore(a,d)}const i=jS(e,n),l=i===0?0:NS(e);a.textContent=i===0?"":`${l}/${i}`}const pp=new Li,fp=new Li,hp=new Li,gp=new Li,xp=new Li,bp=new Li,yp=t=>t,Vc=Gx,SS=qx,kS=Jx;class CS 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 vp=(t,e)=>!t||t.length===0?[]:Hx.define({create(n){const r=new ph,a=[...t].sort((i,l)=>i.afterLine-l.afterLine);for(const i of a){const l=n.doc.lines;if(i.afterLine>l)continue;const c=n.doc.line(i.afterLine);r.add(c.to,c.to,fh.widget({widget:new CS(i.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>zn.decorations.from(n)}),wp=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return Kx.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 ph;for(let i=e;i<=n&&i<=r.state.doc.lines;i+=1){const l=r.state.doc.line(i);a.add(l.from,l.from,fh.line({class:"oc-cm-selected-line"}))}return a.finish()}},{decorations:r=>r.decorations})};function So({value:t,onChange:e,extensions:n,className:r,readOnly:a,lineNumbersConfig:i,highlightLines:l,onViewReady:c,onViewDestroy:d,blockWidgets:f,enableSearch:m,searchOpen:u,onSearchOpenChange:p}){const b=o.useRef(null),g=o.useRef(null),y=o.useRef(t),x=o.useRef(e),h=o.useRef(c),j=o.useRef(d),v=o.useRef(p),C=o.useRef(f),k=o.useRef(new Map),[w,N]=o.useState([]),I=o.useCallback(P=>{const T=(P??[]).map(S=>{const M=k.current.get(S.id);return M?{id:S.id,content:S.content,container:M}:null}).filter(S=>S!==null);N(S=>S.length===T.length&&S.every((M,D)=>{const F=T[D];return M.id===F.id&&M.content===F.content&&M.container===F.container})?S:T)},[]),E=o.useCallback(P=>{const T=b.current,S=P??g.current;if(!T||!S)return;const M=S.dom.querySelector(".cm-gutters"),D=M instanceof HTMLElement?M.getBoundingClientRect().width:0;T.style.setProperty("--oc-editor-gutter-width",`${D}px`)},[]);return o.useEffect(()=>{y.current=t},[t]),o.useEffect(()=>{x.current=e},[e]),o.useEffect(()=>{h.current=c,j.current=d},[c,d]),o.useEffect(()=>{v.current=p},[p]),o.useEffect(()=>{C.current=f,I(f)},[f,I]),o.useEffect(()=>{if(!b.current)return;const P=(()=>{if(typeof document>"u")return null;const S=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(S)return S;const M=window.__OPENCHAMBER_CSP_NONCE__;return typeof M=="string"&&M.length>0?M:null})(),T=$x.create({doc:y.current,extensions:[...P?[zn.cspNonce.of(P)]:[],_x({fixed:!0}),pp.of(Ru(i)),Bx(),Vx.of(" "),hc.of([zx,...Ux,...Wx]),zn.updateListener.of(S=>{E(S.view),(S.viewportChanged||S.geometryChanged)&&I(C.current);const M=Fu(S.startState),D=Fu(S.state);M!==D&&v.current?.(D);const F=!Tl(S.startState).eq(Tl(S.state));if(D&&(M!==D||F||S.docChanged||S.selectionSet)&&mp(S.view.dom,S.view,M!==D||F||S.docChanged),!S.docChanged)return;const _=S.state.doc.toString();y.current=_,x.current(_),I(C.current)}),fp.of(zn.editable.of(!a)),hp.of(n??[]),gp.of(wp(l)),xp.of(vp(f,k.current)),bp.of(m?[Lu({top:!0}),hc.of(yp(Ou))]:[])]});return g.current=new zn({state:T,parent:b.current}),Vc(g.current,g.current.state.doc.length,200),g.current.requestMeasure(),requestAnimationFrame(()=>{E(g.current),I(C.current)}),g.current&&h.current?.(g.current),()=>{j.current?.(),g.current?.destroy(),g.current=null,N([])}},[C,E,I]),o.useEffect(()=>{const P=g.current;P&&(P.dispatch({effects:[pp.reconfigure(Ru(i)),fp.reconfigure(zn.editable.of(!a)),hp.reconfigure(n??[]),gp.reconfigure(wp(l)),xp.reconfigure(vp(f,k.current)),bp.reconfigure(m?[Lu({top:!0}),hc.of(yp(Ou))]:[])]}),Vc(P,P.state.doc.length,200),P.requestMeasure(),requestAnimationFrame(()=>{E(P),I(C.current)}))},[n,l,i,a,f,m,E,I]),o.useEffect(()=>{const P=g.current;!P||m===!1||(u?(SS(P),requestAnimationFrame(()=>{wS(P.dom),mp(P.dom,P,!0)})):kS(P))},[u,m]),o.useEffect(()=>{const P=g.current;if(!P)return;const T=P.state.doc.toString();T!==t&&(P.dispatch({changes:{from:0,to:T.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:ge("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)}),w.map(P=>ol.createPortal(P.content,P.container,P.id))]})}const IS=(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)},jp=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},Np=(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:Qx.cursor(i),effects:zn.scrollIntoView(i,{y:"center"})})};function PS({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:a}=pt(),[i,l]=o.useState(""),c=o.useRef(null),d=o.useRef(!1),f=o.useRef(null),m=o.useRef(null),u=o.useMemo(()=>IS(i,n),[i,n]);o.useEffect(()=>{!t||!n||(d.current=!1,c.current=jp(n,n.state.selection),l(""))},[t,n]),o.useEffect(()=>{t&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[t]),o.useEffect(()=>{if(!(!t||!n||!c.current)){if(u===null){const{selection:x}=c.current;n.dispatch({selection:x,effects:zn.scrollIntoView(x.main.from,{y:"center"})});return}Np(n,u,c.current.character)}},[u,t,n]);const p=o.useCallback(()=>{if(!n||d.current||!c.current)return;const{selection:x}=c.current;n.dispatch({selection:x,effects:zn.scrollIntoView(x.main.from,{y:"center"})})},[n]),b=o.useCallback(x=>{x||p(),e(x)},[e,p]),g=o.useCallback(()=>{!n||u===null||!c.current||(d.current=!0,Np(n,u,c.current.character),e(!1),n.focus())},[u,e,n]);o.useEffect(()=>{if(!t)return;const x=j=>{const v=f.current,C=j.target;!v||!(C instanceof Node)||v.contains(C)||b(!1)},h=j=>{j.key==="Escape"&&(j.preventDefault(),b(!1))};return document.addEventListener("pointerdown",x,!0),document.addEventListener("keydown",h,!0),()=>{document.removeEventListener("pointerdown",x,!0),document.removeEventListener("keydown",h,!0)}},[b,t,r]);const y=o.useMemo(()=>{if(!n)return a("goToLineDialog.helper.editorUnavailable");if(u===null){const x=c.current??jp(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:f,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx($t,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:x=>l(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),g())},placeholder:a("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(he,{variant:"outline",size:"xs",onClick:g,disabled:!n||u===null,className:"h-6 px-2",children:a("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:f,className:ge("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($t,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:x=>l(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),g())},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:y})]})})}const Kl=t=>{const e=ot.c(11),{currentMode:n,onToggle:r}=t,a=n==="preview",i=a?"Switch to edit mode":"Switch to preview mode",l=a?"Edit":"Preview";let c;e[0]!==a?(c=a?s.jsx(A,{name:"eye",className:"size-4","aria-hidden":"true"}):s.jsx(A,{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(he,{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 f;e[6]!==l?(f=s.jsx(At,{sideOffset:8,children:l}),e[6]=l,e[7]=f):f=e[7];let m;return e[8]!==d||e[9]!==f?(m=s.jsxs(It,{children:[d,f]}),e[8]=d,e[9]=f,e[10]=m):m=e[10],m};function ko(t){const e=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",r=t.colors.syntax.highlights||{},a=t.colors.syntax.tokens||{},i=zn.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}),l=$u.define([{tag:[xt.comment,xt.docComment,xt.meta,xt.documentMeta],class:"cm-comment"},{tag:[xt.keyword,xt.controlKeyword,xt.moduleKeyword,xt.definitionKeyword,xt.modifier],class:"cm-keyword"},{tag:[xt.operatorKeyword,xt.operator,xt.derefOperator,xt.updateOperator,xt.definitionOperator,xt.typeOperator,xt.controlOperator,xt.logicOperator,xt.bitwiseOperator,xt.arithmeticOperator,xt.compareOperator],class:"cm-operator"},{tag:[xt.punctuation,xt.separator,xt.bracket,xt.paren,xt.brace,xt.squareBracket,xt.angleBracket],class:"cm-punctuation"},{tag:[xt.string,xt.regexp,xt.attributeValue,xt.special(xt.string),xt.monospace],class:"cm-string"},{tag:xt.escape,class:"cm-string-2"},{tag:[xt.number,xt.bool,xt.atom,xt.null,xt.self],class:"cm-number"},{tag:[xt.function(xt.variableName),xt.function(xt.definition(xt.variableName)),xt.function(xt.propertyName),xt.standard(xt.variableName),xt.special(xt.variableName)],class:"cm-builtin"},{tag:xt.definition(xt.variableName),class:"cm-def"},{tag:[xt.variableName,xt.local(xt.variableName),xt.constant(xt.variableName),xt.literal],class:"cm-variable"},{tag:xt.propertyName,class:"cm-property"},{tag:xt.attributeName,class:"cm-attribute"},{tag:[xt.className,xt.typeName,xt.namespace],class:"cm-variable-3"},{tag:[xt.tagName,xt.labelName,xt.annotation,xt.macroName],class:"cm-tag"},{tag:xt.link,class:"cm-link"},{tag:[xt.heading,xt.heading1,xt.heading2,xt.heading3,xt.heading4,xt.heading5,xt.heading6],class:"cm-keyword"}]),c=$u.define([{tag:[xt.comment,xt.docComment,xt.meta,xt.documentMeta],color:t.colors.syntax.base.comment},{tag:[xt.keyword,xt.controlKeyword,xt.moduleKeyword,xt.definitionKeyword,xt.modifier],color:t.colors.syntax.base.keyword},{tag:[xt.operatorKeyword,xt.operator,xt.derefOperator,xt.updateOperator,xt.definitionOperator,xt.typeOperator,xt.controlOperator,xt.logicOperator,xt.bitwiseOperator,xt.arithmeticOperator,xt.compareOperator],color:t.colors.syntax.base.operator},{tag:[xt.string,xt.regexp,xt.attributeValue,xt.special(xt.string),xt.monospace],color:t.colors.syntax.base.string},{tag:xt.escape,color:a.stringEscape||t.colors.syntax.base.string},{tag:[xt.number,xt.bool,xt.atom,xt.null,xt.self],color:t.colors.syntax.base.number},{tag:[xt.function(xt.variableName),xt.function(xt.definition(xt.variableName)),xt.function(xt.propertyName),xt.standard(xt.variableName),xt.special(xt.variableName)],color:t.colors.syntax.base.function},{tag:xt.definition(xt.variableName),color:a.variableGlobal||t.colors.syntax.base.variable},{tag:[xt.variableName,xt.local(xt.variableName),xt.constant(xt.variableName),xt.literal],color:t.colors.syntax.base.variable},{tag:xt.propertyName,color:a.variableProperty||t.colors.syntax.base.variable},{tag:xt.attributeName,color:a.variableOther||t.colors.syntax.base.variable},{tag:[xt.className,xt.typeName,xt.namespace],color:t.colors.syntax.base.type},{tag:[xt.tagName,xt.labelName,xt.annotation,xt.macroName],color:a.tag||t.colors.syntax.base.keyword},{tag:xt.link,color:a.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[xt.punctuation,xt.separator,xt.bracket,xt.paren,xt.brace,xt.squareBracket,xt.angleBracket],color:a.punctuation||t.colors.syntax.base.comment}]);return[i,Lo(Xx,{fallback:!0}),Lo(Zx),Lo(l),Lo(c)]}const AS=t=>{const e=xn(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},DS=t=>{const e=ot.c(8),{label:n,iconDataUrl:r}=t,[a,i]=o.useState(!1);let l;e[0]!==n?(l=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=l):l=e[1];const c=l;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=ge("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 f;return e[6]!==c?(f=s.jsx("span",{className:d,children:c}),e[6]=c,e[7]=f):f=e[7],f},TS=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),xn=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},ES=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Sp=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,Hl=(t,e)=>{const n=xn(e),r=xn(t);if(!n||!r)return!1;const a=Sp(n),i=Sp(r);return i===a||i.startsWith(`${a}/`)},kp=(t,e)=>{const n=xn(e),r=xn(t);if(!Hl(r,n))return[];const i=r.slice(n.length).replace(/^\//,"").split("/"),l=[];let c=n;for(let d=0;d<i.length-1;d++)c=c?`${c}/${i[d]}`:i[d],l.push(c);return l},Ed=(t,e)=>{if(!e)return"";const n=xn(e);if(!t||!Hl(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},MS=new Set(["node_modules"]),RS=t=>{const e=ot.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},Cp=t=>{const e=ot.c(11),{name:n}=t,r=o.useRef(null),a=o.useRef(null),[i,l]=o.useState(!1);let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{const p=r.current,b=a.current;if(!p||!b)return;const g=()=>{l(b.scrollWidth>p.clientWidth+1)};g();const y=new ResizeObserver(g);return y.observe(p),y.observe(b),()=>{y.disconnect()}},e[0]=c):c=e[0];let d;e[1]!==n?(d=[n],e[1]=n,e[2]=d):d=e[2],o.useLayoutEffect(c,d);let f;e[3]!==n?(f=s.jsx("span",{ref:a,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:n}),e[3]=n,e[4]=f):f=e[4];let m;e[5]!==n||e[6]!==i?(m=i?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:n}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:n})]}):s.jsx("span",{className:"block min-w-0 truncate",children:n}),e[5]=n,e[6]=i,e[7]=m):m=e[7];let u;return e[8]!==f||e[9]!==m?(u=s.jsxs("span",{ref:r,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[f,m]}),e[8]=f,e[9]=m,e[10]=u):u=e[10],u},FS=t=>MS.has(t),LS=t=>{const e=xn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},OS=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},Ip=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")},Hi=2e5,Ag="openchamber:files:auto-save-enabled",$S=t=>{let e=0,n=0;for(let r=0;r<t.length;r+=1)t.charCodeAt(r)===10&&(r>0&&t.charCodeAt(r-1)===13?e+=1:n+=1);return e>n?`\r
|
|
48
|
+
`:`
|
|
49
|
+
`},Dg=t=>t.replace(/\r\n/g,`
|
|
50
|
+
`).replace(/\r/g,`
|
|
51
|
+
`),_S=(t,e)=>{const n=Dg(t);return e===`\r
|
|
52
|
+
`?n.replace(/\n/g,`\r
|
|
53
|
+
`):n},BS=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(Ag)!=="false"}catch{return!0}},Tg=(t,e)=>s.jsx(Er,{filePath:t,extension:e}),VS=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},zS=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},zc=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},US=t=>{const e=ot.c(62),{node:n,root:r,isExpanded:a,isActive:i,isMobile:l,alwaysShowActions:c,status:d,badge:f,permissions:m,downloadFile:u,contextMenuPath:p,setContextMenuPath:b,onSelect:g,onToggle:y,onRevealPath:x,onOpenDialog:h}=t,{t:j}=pt(),v=n.type==="directory",{canRename:C,canCreateFile:k,canCreateFolder:w,canDelete:N,canReveal:I}=m;let E;e[0]!==k||e[1]!==w||e[2]!==N||e[3]!==C||e[4]!==I||e[5]!==n.path||e[6]!==b?(E=ue=>{!C&&!k&&!w&&!N&&!I||(ue?.preventDefault(),b(n.path))},e[0]=k,e[1]=w,e[2]=N,e[3]=C,e[4]=I,e[5]=n.path,e[6]=b,e[7]=E):E=e[7];const P=E;let T;e[8]!==v||e[9]!==n||e[10]!==g||e[11]!==y?(T=()=>{v?y(n.path):g(n)},e[8]=v,e[9]=n,e[10]=g,e[11]=y,e[12]=T):T=e[12];const S=T;let M;e[13]!==n.path||e[14]!==b?(M=ue=>{ue.stopPropagation(),b(n.path)},e[13]=n.path,e[14]=b,e[15]=M):M=e[15];const D=M,F=l?void 0:P,_=l?void 0:P,V=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let $;e[16]!==V?($=ge("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",V),e[16]=V,e[17]=$):$=e[17];let O;e[18]!==v||e[19]!==a||e[20]!==n.extension||e[21]!==n.path?(O=v?a?s.jsx(A,{name:"folder-open-fill",className:"size-4 flex-shrink-0 text-primary/60"}):s.jsx(A,{name:"folder-3-fill",className:"size-4 flex-shrink-0 text-primary/60"}):Tg(n.path,n.extension),e[18]=v,e[19]=a,e[20]=n.extension,e[21]=n.path,e[22]=O):O=e[22];let B;e[23]!==n.name||e[24]!==n.path?(B=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]=B):B=e[25];let G;e[26]!==v||e[27]!==d?(G=!v&&d&&s.jsx(RS,{status:d}),e[26]=v,e[27]=d,e[28]=G):G=e[28];let R;e[29]!==f||e[30]!==v?(R=v&&f&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[f.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",f.modified]}),f.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",f.added]})]}),e[29]=f,e[30]=v,e[31]=R):R=e[31];let H;e[32]!==S||e[33]!==G||e[34]!==R||e[35]!==_||e[36]!==$||e[37]!==O||e[38]!==B?(H=s.jsxs("button",{type:"button",onClick:S,onContextMenu:_,className:$,children:[O,B,G,R]}),e[32]=S,e[33]=G,e[34]=R,e[35]=_,e[36]=$,e[37]=O,e[38]=B,e[39]=H):H=e[39];let J;e[40]!==c||e[41]!==k||e[42]!==w||e[43]!==N||e[44]!==C||e[45]!==I||e[46]!==p||e[47]!==u||e[48]!==D||e[49]!==v||e[50]!==l||e[51]!==n||e[52]!==h||e[53]!==x||e[54]!==r||e[55]!==b||e[56]!==j?(J=(C||k||w||N||I)&&s.jsx("div",{className:ge("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(As,{open:p===n.path,onOpenChange:ue=>b(ue?n.path:null),children:[s.jsx(Is,{asChild:!0,children:s.jsx(he,{variant:"ghost",size:"icon",className:"size-6",onClick:D,children:s.jsx(A,{name:"more-2-fill",className:"size-4"})})}),s.jsxs(Ps,{align:"end",side:"bottom",onCloseAutoFocus:()=>b(null),children:[C&&s.jsxs(Ot,{onClick:ue=>{ue.stopPropagation(),h("rename",n)},children:[s.jsx(A,{name:"edit",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.rename")]}),s.jsxs(Ot,{onClick:ue=>{ue.stopPropagation(),Ln(n.path).then(de=>{if(de.ok){K.success(j("sidebarFilesTree.toast.pathCopied"));return}K.error(j("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(A,{name:"file-copy",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.copyPath")]}),s.jsxs(Ot,{onClick:ue=>{ue.stopPropagation();const de=Ed(r,n.path)||n.path;Ln(de).then(pe=>{if(pe.ok){K.success(j("filesView.toast.relativePathCopied"));return}K.error(j("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(A,{name:"file-copy-2",className:"mr-2 size-4"})," ",j("filesView.tree.menu.copyRelativePath")]}),!v&&u&&s.jsxs(Ot,{onClick:ue=>{ue.stopPropagation(),u(n.path)},children:[s.jsx(A,{name:"download",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.save")]}),I&&s.jsxs(Ot,{onClick:ue=>{ue.stopPropagation(),x(n.path)},children:[s.jsx(A,{name:"folder-received",className:"mr-2 size-4"})," ",j(iu())]}),v&&(k||w)&&s.jsxs(s.Fragment,{children:[s.jsx(nr,{}),k&&s.jsxs(Ot,{onClick:ue=>{ue.stopPropagation(),h("createFile",n)},children:[s.jsx(A,{name:"file-add",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.newFile")]}),w&&s.jsxs(Ot,{onClick:ue=>{ue.stopPropagation(),h("createFolder",n)},children:[s.jsx(A,{name:"folder-add",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.newFolder")]})]}),N&&s.jsxs(s.Fragment,{children:[s.jsx(nr,{}),s.jsxs(Ot,{onClick:ue=>{ue.stopPropagation(),h("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=c,e[41]=k,e[42]=w,e[43]=N,e[44]=C,e[45]=I,e[46]=p,e[47]=u,e[48]=D,e[49]=v,e[50]=l,e[51]=n,e[52]=h,e[53]=x,e[54]=r,e[55]=b,e[56]=j,e[57]=J):J=e[57];let ne;return e[58]!==H||e[59]!==J||e[60]!==F?(ne=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:F,children:[H,J]}),e[58]=H,e[59]=J,e[60]=F,e[61]=ne):ne=e[61],ne},WS=t=>{const e=ot.c(83),{activeDialog:n,dialogData:r,dialogInputValue:a,onDialogInputChange:i,isDialogSubmitting:l,onDialogSubmit:c,onClose:d,inputRef:f}=t,{t:m}=pt(),u=!!n;let p;e[0]!==d?(p=O=>!O&&d(),e[0]=d,e[1]=p):p=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 g;e[5]!==n||e[6]!==m?(g=n==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=n,e[6]=m,e[7]=g):g=e[7];let y;e[8]!==n||e[9]!==m?(y=n==="rename"&&m("filesView.dialog.rename.title"),e[8]=n,e[9]=m,e[10]=y):y=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 h;e[14]!==b||e[15]!==g||e[16]!==y||e[17]!==x?(h=s.jsxs(ds,{children:[b,g,y,x]}),e[14]=b,e[15]=g,e[16]=y,e[17]=x,e[18]=h):h=e[18];let j;e[19]!==n||e[20]!==r?.path||e[21]!==m?(j=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]=j):j=e[22];let v;e[23]!==n||e[24]!==r?.path||e[25]!==m?(v=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]=v):v=e[26];let C;e[27]!==n||e[28]!==r?.name||e[29]!==m?(C=n==="rename"&&m("filesView.dialog.rename.description",{name:r?.name??""}),e[27]=n,e[28]=r?.name,e[29]=m,e[30]=C):C=e[30];let k;e[31]!==n||e[32]!==r?.name||e[33]!==m?(k=n==="delete"&&m("filesView.dialog.delete.description",{name:r?.name??""}),e[31]=n,e[32]=r?.name,e[33]=m,e[34]=k):k=e[34];let w;e[35]!==C||e[36]!==k||e[37]!==j||e[38]!==v?(w=s.jsxs(ys,{children:[j,v,C,k]}),e[35]=C,e[36]=k,e[37]=j,e[38]=v,e[39]=w):w=e[39];let N;e[40]!==w||e[41]!==h?(N=s.jsxs(ps,{children:[h,w]}),e[40]=w,e[41]=h,e[42]=N):N=e[42];let I;e[43]!==n||e[44]!==a||e[45]!==f||e[46]!==i||e[47]!==c||e[48]!==m?(I=n!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx($t,{value:a,onChange:O=>i(O.target.value),placeholder:m(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:O=>{O.key==="Enter"&&c()},ref:f})}),e[43]=n,e[44]=a,e[45]=f,e[46]=i,e[47]=c,e[48]=m,e[49]=I):I=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]!==l||e[53]!==d||e[54]!==E?(P=s.jsx(he,{variant:"outline",onClick:d,disabled:l,children:E}),e[52]=l,e[53]=d,e[54]=E,e[55]=P):P=e[55];const T=n==="delete"?"destructive":"default";let S;e[56]!==c?(S=()=>{c()},e[56]=c,e[57]=S):S=e[57];let M;e[58]!==n||e[59]!==a||e[60]!==l?(M=l||n!=="delete"&&!a.trim(),e[58]=n,e[59]=a,e[60]=l,e[61]=M):M=e[61];let D;e[62]!==n||e[63]!==l||e[64]!==m?(D=l?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):m(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=l,e[64]=m,e[65]=D):D=e[65];let F;e[66]!==T||e[67]!==S||e[68]!==M||e[69]!==D?(F=s.jsx(he,{variant:T,onClick:S,disabled:M,children:D}),e[66]=T,e[67]=S,e[68]=M,e[69]=D,e[70]=F):F=e[70];let _;e[71]!==P||e[72]!==F?(_=s.jsxs(Rs,{children:[P,F]}),e[71]=P,e[72]=F,e[73]=_):_=e[73];let V;e[74]!==f||e[75]!==N||e[76]!==I||e[77]!==_?(V=s.jsxs(os,{initialFocus:f,children:[N,I,_]}),e[74]=f,e[75]=N,e[76]=I,e[77]=_,e[78]=V):V=e[78];let $;return e[79]!==u||e[80]!==p||e[81]!==V?($=s.jsx(ls,{open:u,onOpenChange:p,children:V}),e[79]=u,e[80]=p,e[81]=V,e[82]=$):$=e[82],$},Eg=({mode:t="full"})=>{const{t:e}=pt(),{files:n,runtime:r}=Wn(),{currentTheme:a,availableThemes:i,lightThemeId:l,darkThemeId:c}=Sr(),{isMobile:d,isTablet:f,screenWidth:m}=an(),u=d||f,p=rc(),b=ru(),g=la()??"",y=xn(g.trim()),x=d||t!=="editor-only",h=t==="editor-only"&&!d,j=au(Le=>Le.searchFiles),v=nc(g),[C,k]=o.useState(""),w=ac(C,200),N=o.useRef(null),[I,E]=o.useState(!1),[P,T]=o.useState(!0),[S,M]=o.useState(!1),[D,F]=o.useState(!1),[_,V]=o.useState(!1),$=o.useRef(null),O=o.useRef(0),B=o.useCallback(Le=>{O.current=Math.max(0,O.current+(Le?1:-1))},[]),G=o.useCallback(Le=>Le instanceof Element?Le.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);o.useEffect(()=>{if(!_)return;const Le=it=>{O.current>0||G(it.target)||$.current&&!$.current.contains(it.target)&&V(!1)};return document.addEventListener("mousedown",Le),()=>document.removeEventListener("mousedown",Le)},[G,_]);const[R,H]=o.useState("edit"),[J,ne]=o.useState("edit"),[ue,de]=o.useState("tree"),[pe,W]=o.useState("edit"),te=o.useRef({}),X=o.useRef({}),ee=o.useRef({}),fe=o.useMemo(()=>i.find(Le=>Le.metadata.id===l)??Ci(!1),[i,l]),be=o.useMemo(()=>i.find(Le=>Le.metadata.id===c)??Ci(!0),[i,c]);o.useEffect(()=>{Ii(fe),Ii(be)},[fe,be]);const Ne=o.useMemo(()=>[],[]),se=Bn(Le=>y?Le.byRoot[y]?.openPaths??Ne:Ne),ie=Bn(Le=>y?Le.byRoot[y]?.selectedPath??null:null),ae=Bn(Le=>y?Le.byRoot[y]?.expandedPaths??Ne:Ne),xe=Bn(Le=>Le.addOpenPath),Z=Bn(Le=>Le.removeOpenPath),me=Bn(Le=>Le.removeOpenPathsByPrefix),Y=Bn(Le=>Le.setSelectedPath),Se=Bn(Le=>Le.toggleExpandedPath),we=Bn(Le=>Le.expandPaths),ke=o.useCallback(Le=>{const it=xn(Le),ut=it.split("/"),Nt=ut[ut.length-1]||it,Ht=Nt.includes(".")?Nt.split(".").pop()?.toLowerCase():void 0;return{name:Nt,path:it,type:"file",extension:Ht}},[]),Fe=o.useMemo(()=>se.map(ke),[se,ke]),Ce=o.useMemo(()=>ie??se[0]??null,[se,ie]),Q=o.useMemo(()=>Ce?ke(Ce):null,[Ce,ke]),ce=Q?.path??"",ve=!!(y&&ce&&!Hl(ce,y)),le=o.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&ve}),[t,ve]),Ae=o.useRef(null),[Te,$e]=o.useState({left:!1,right:!1}),ye=o.useCallback(()=>{const Le=Ae.current;Le&&$e({left:Le.scrollLeft>2,right:Le.scrollLeft+Le.clientWidth<Le.scrollWidth-2})},[]),q=o.useRef(ye);q.current=ye,o.useEffect(()=>{const Le=Ae.current;if(!Le)return;const it=()=>q.current();it(),Le.addEventListener("scroll",it,{passive:!0});const ut=new ResizeObserver(it);return ut.observe(Le),()=>{Le.removeEventListener("scroll",it),ut.disconnect()}},[Fe.length]);const[L,U]=o.useState({}),oe=o.useRef(new Set),Ee=o.useRef(new Set),Oe=o.useRef(new Map),Ie=o.useRef(0),[z,De]=o.useState([]),[Qe,tt]=o.useState(!1),[et,We]=o.useState(""),[at,qe]=o.useState(!1),[nt,Ze]=o.useState(null),[ze,rt]=o.useState(""),[Ge,ct]=o.useState(null),[Pe,Me]=o.useState(""),[Ue,He]=o.useState(!1),[lt,vt]=o.useState(`
|
|
54
|
+
`),ft=o.useRef(null),dt=o.useRef(null),Dt=o.useRef(null),Qt=o.useRef(0),[Ft,qt]=o.useState("idle"),[gt,zt]=o.useState(BS),[es,is]=o.useState(!1),cs=o.useRef(null),hs=o.useRef(null),_t=o.useRef(null),Ye=o.useRef(!1),Mt=o.useRef(null),Bt=o.useRef(null),wt=o.useRef(null),Zt=o.useRef(null),[us,Es]=o.useState(0),ws=o.useRef(null),Ds=o.useRef({key:"",attempts:0});o.useEffect(()=>()=>{ws.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(ws.current),ws.current=null)},[]);const[Xt,en]=o.useState(null),[Ks,Us]=o.useState(null),[Xs,re]=o.useState(""),[bt,Et]=o.useState(!1),[Wt,ts]=o.useState(null),[ss,Ke]=o.useState(!1),[Je,Ct]=o.useState(!1),[kt,Kt]=o.useState(!1),Tt=!!n.writeFile,gs=!!n.createDirectory,js=!!n.rename,Ls=!!n.delete,Os=!!n.revealPath,tn=Vr(Le=>Le.availableApps),cn=Vr(Le=>Le.isCacheStale),Zs=Vr(Le=>Le.initialize),sn=Vr(Le=>Le.loadInstalledApps);o.useEffect(()=>{Zs()},[Zs]);const mn=o.useCallback(Le=>{n.revealPath&&n.revealPath(Le).catch(()=>{K.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),gn=o.useCallback(async Le=>{if(!Q?.path||await my(Q.path,Le.id,Le.appName)||await El(Q.path,Le.appName))return;const Nt=AS(Q.path)||y;Nt&&await El(Nt,Le.appName)||K.error(e("filesView.toast.openInAppFailed",{app:Le.appName}))},[y,Q?.path,e]),$s=o.useCallback((Le,it)=>{en(Le),Us(it),re(Le==="rename"&&it.name||""),Et(!1)},[]),[Hs,dn]=o.useState(null),Kn=o.useRef(!1),Hn=o.useRef(null),[kr,ir]=o.useState(!1),bn=_e(Le=>Le.setMainTabGuard),On=_e(Le=>Le.pendingFileNavigation),ur=_e(Le=>Le.setPendingFileNavigation),Be=_e(Le=>Le.pendingFileFocusPath),St=_e(Le=>Le.setPendingFileFocusPath),Gt=_e(Le=>Le.shortcutOverrides),Yt=jt(Le=>Le.settingsDefaultFileViewerPreview);o.useEffect(()=>{const Le=()=>{Kn.current=!1,Hn.current=null,ir(!1)};return document.addEventListener("mouseup",Le),()=>document.removeEventListener("mouseup",Le)},[]),o.useEffect(()=>()=>{Mt.current!==null&&window.clearTimeout(Mt.current),Bt.current!==null&&window.clearTimeout(Bt.current)},[]);const ks=o.useCallback((Le,it)=>{const ut=Le.split(`
|
|
55
|
+
`),Nt=Math.max(1,it.start),Ht=Math.min(ut.length,it.end);return Nt>Ht?"":ut.slice(Nt-1,Ht).join(`
|
|
56
|
+
`)},[]),Bs=gu({source:"file",fileLabel:Q?.path??null,language:Q?.path&&Pi(Q.path)||"text",getCodeForRange:Le=>ks(et,zl(Le)),toStoreRange:Le=>({startLine:Le.start,endLine:Le.end}),fromDraftRange:Le=>({start:Le.startLine,end:Le.endLine})}),{drafts:Fs,commentText:Ys,editingDraftId:nn,setSelection:Xn,saveComment:Cr,cancel:mr,reset:qr,startEdit:Jr,deleteDraft:Mn}=Bs;o.useEffect(()=>{dn(null),qr(),bn(null),Me(""),He(!1)},[Q?.path,qr,bn]),o.useEffect(()=>{Xn(Hs)},[Hs,Xn]),o.useEffect(()=>{if(!Hs&&!nn)return;const Le=ut=>{const Nt=ut.target;Nt.closest('[data-comment-input="true"]')||Nt.closest('[data-comment-card="true"]')||Nt.closest(".cm-gutterElement")||Nt.closest("[data-sonner-toast]")||Nt.closest("[data-sonner-toaster]")||(dn(null),mr())},it=setTimeout(()=>{document.addEventListener("click",Le)},100);return()=>{clearTimeout(it),document.removeEventListener("click",Le)}},[mr,nn,Hs]);const wn=o.useCallback((Le,it)=>{const ut=it??Hs??void 0;it&&dn(it),Cr(Le,ut),dn(null)},[Hs,Cr]),jn=o.useCallback((Le,it)=>{const ut=[];for(const Nt of it){if(!(Nt&&typeof Nt.name=="string"&&Nt.name.length>0)||!p&&Nt.name.startsWith(".")||!b&&FS(Nt.name))continue;const Ht=Nt.name,Jt=xn(Nt.path||""),Ts=Jt?ES(Jt)?Jt:xn(`${Le}/${Jt}`):xn(`${Le}/${Ht}`),Ws=Nt.isDirectory?"directory":"file",Dn=Ws==="file"&&Ht.includes(".")?Ht.split(".").pop()?.toLowerCase():void 0;ut.push({name:Ht,path:Ts,type:Ws,extension:Dn})}return TS(ut)},[b,p]),Vs=o.useCallback(async Le=>{const it=xn(Le.trim());if(!it||oe.current.has(it)||Ee.current.has(it))return;Ee.current=new Set(Ee.current),Ee.current.add(it);const ut=Ie.current+1;Ie.current=ut,Oe.current=new Map(Oe.current),Oe.current.set(it,ut);const Nt=()=>Oe.current.get(it)===ut,Ht=!b;await(n.listDirectory?n.listDirectory(it,{respectGitignore:Ht}).then(Ts=>Ts.entries.map(Ws=>({name:Ws.name,path:Ws.path,isDirectory:Ws.isDirectory}))):rn.listLocalDirectory(it,{respectGitignore:Ht}).then(Ts=>Ts.map(Ws=>({name:Ws.name,path:Ws.path,isDirectory:Ws.isDirectory})))).then(Ts=>{if(!Nt())return;const Ws=jn(it,Ts);oe.current=new Set(oe.current),oe.current.add(it),U(Dn=>({...Dn,[it]:Ws}))}).catch(()=>{Nt()&&U(Ts=>({...Ts,[it]:Ts[it]??[]}))}).finally(()=>{Nt()&&(Oe.current=new Map(Oe.current),Oe.current.delete(it),Ee.current=new Set(Ee.current),Ee.current.delete(it))})},[n,jn,b]),yn=o.useCallback(async()=>{y&&(oe.current=new Set,Ee.current=new Set,Oe.current=new Map,U(Le=>Object.keys(Le).length===0?Le:{}),await Vs(y))},[Vs,y]),pn=o.useCallback(async Le=>{if(!Le){await yn();return}const it=xn(Le);oe.current=new Set(oe.current),oe.current.delete(it),Ee.current=new Set(Ee.current),Ee.current.delete(it),await Vs(it)},[Vs,yn]),Wr=o.useRef(""),si=o.useRef("");o.useEffect(()=>{if(!y)return;const Le=`${y}|h${p?"1":"0"}|g${b?"1":"0"}`,it=Wr.current!==y,ut=si.current!==Le;!it&&!ut||(it&&(Wr.current=y,We(""),Ze(null),rt(""),ct(null),E(!1)),ut&&(si.current=Le,oe.current=new Set,Ee.current=new Set,Oe.current=new Map,U(Nt=>Object.keys(Nt).length===0?Nt:{}),Vs(y)))},[Vs,y,b,p]),o.useEffect(()=>{if(!n.listDirectory)return;const Le=()=>{if(!document.hidden&&ae.length>0)for(const it of ae)pn(it)};return document.addEventListener("visibilitychange",Le),()=>document.removeEventListener("visibilitychange",Le)},[ae,n.listDirectory,pn]),o.useEffect(()=>{if(!n.listDirectory||ae.length===0)return;const Le=setInterval(()=>{if(!document.hidden)for(const it of ae)pn(it)},8e3);return()=>clearInterval(Le)},[ae,n.listDirectory,pn]);const ni=o.useCallback(async Le=>{if(Le?.preventDefault(),!Ks||!Xt)return;Et(!0);const it=()=>{en(null)},ut=Ht=>{K.error(Ht)},Nt=()=>{Et(!1)};if(Xt==="createFile"){if(!Xs.trim()){ut(e("sidebarFilesTree.toast.filenameRequired")),Nt();return}if(!n.writeFile){ut(e("sidebarFilesTree.toast.writeNotSupported")),Nt();return}const Ht=Ks.path,Jt=Ht?`${Ht}/`:"",Ts=xn(`${Jt}${Xs.trim()}`);await n.writeFile(Ts,"").then(async Ws=>{Ws.success&&(K.success(e("sidebarFilesTree.toast.fileCreated")),await pn(Ht)),it()}).catch(()=>ut(e("sidebarFilesTree.toast.operationFailed"))).finally(Nt);return}if(Xt==="createFolder"){if(!Xs.trim()){ut(e("sidebarFilesTree.toast.folderNameRequired")),Nt();return}const Ht=Ks.path,Jt=Ht?`${Ht}/`:"",Ts=xn(`${Jt}${Xs.trim()}`);await n.createDirectory(Ts).then(async Ws=>{Ws.success&&(K.success(e("sidebarFilesTree.toast.folderCreated")),await pn(Ht)),it()}).catch(()=>ut(e("sidebarFilesTree.toast.operationFailed"))).finally(Nt);return}if(Xt==="rename"){if(!Xs.trim()){ut(e("sidebarFilesTree.toast.nameRequired")),Nt();return}if(!n.rename){ut(e("sidebarFilesTree.toast.renameNotSupported")),Nt();return}const Ht=Ks.path,Jt=Ht.split("/").slice(0,-1).join("/"),Ts=Jt?`${Jt}/`:"",Ws=xn(`${Ts}${Xs.trim()}`);await n.rename(Ht,Ws).then(async Dn=>{Dn.success&&(K.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await pn(Jt),y&&me(y,Ht),(Q?.path===Ht||Q?.path.startsWith(`${Ht}/`))&&(y&&Y(y,null),We(""),Ze(null),rt(""),ct(null),d&&E(!1))),it()}).catch(()=>ut(e("sidebarFilesTree.toast.operationFailed"))).finally(Nt);return}if(Xt==="delete"){if(!n.delete){ut(e("sidebarFilesTree.toast.deleteNotSupported")),Nt();return}const Ht=Ks.path,Jt=Ht.split("/").slice(0,-1).join("/");await n.delete(Ht).then(async Ts=>{Ts.success&&(K.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await pn(Jt),y&&me(y,Ht),(Q?.path===Ht||Q?.path.startsWith(`${Ht}/`))&&(y&&Y(y,null),We(""),Ze(null),rt(""),ct(null),d&&E(!1))),it()}).catch(()=>ut(e("sidebarFilesTree.toast.operationFailed"))).finally(Nt);return}Nt()},[Xt,Ks,Xs,n,pn,d,me,y,Q?.path,Y,e]);o.useEffect(()=>{if(!g){De([]),tt(!1);return}const Le=w.trim();if(!Le){De([]),tt(!1);return}let it=!1;return tt(!0),j(g,Le,150,{includeHidden:p,respectGitignore:!b,type:"file"}).then(ut=>{if(it)return;const Ht=ut.filter(Jt=>b||!LS(Jt.path)).map(Jt=>({name:Jt.name,path:xn(Jt.path),type:"file",extension:Jt.extension,relativePath:Jt.relativePath}));De(Ht)}).catch(()=>{it||De([])}).finally(()=>{it||tt(!1)}),()=>{it=!0}},[g,w,j,p,b]);const ka=o.useCallback(async(Le,it)=>{if(n.readFile)return(await n.readFile(Le,it)).content??"";const ut=new URLSearchParams({path:Le});it?.allowOutsideWorkspace&&ut.set("allowOutsideWorkspace","true"),it?.optional&&ut.set("optional","true");const Nt=await fetch(`/api/fs/read?${ut.toString()}`,{cache:it?.optional?"no-store":"default"});if(!Nt.ok){const Ht=await Nt.json().catch(()=>({error:Nt.statusText}));throw new Error(Ht.error||e("filesView.error.readFileFailed"))}return Nt.text()},[n,e]),Nn=o.useCallback(async(Le,it)=>{if(n.statFile){const ut=await n.statFile(Le,it);return{path:ut.path,size:ut.size,mtimeMs:ut.mtimeMs}}return null},[n]);o.useEffect(()=>{if(!y||!n.statFile||se.length===0)return;let Le=!1;const it=[...se];return Promise.all(it.map(async ut=>{try{const Nt=await n.statFile?.(ut);!Le&&Nt&&!Nt.isFile&&me(y,ut)}catch(Nt){!Le&&Ip(Nt)&&me(y,ut)}})),()=>{Le=!0}},[n,se,me,y]);const Pn=o.useMemo(()=>et.length>Hi?`${et.slice(0,Hi)}
|
|
57
|
+
|
|
58
|
+
… truncated …`:et,[et]),Sn=Pe!==Pn,Ir=o.useCallback(async()=>{if(!Q||!n.writeFile)return K.error(e("filesView.toast.savingNotSupported")),!1;if(!Sn)return!0;He(!0);try{const Le=_S(Pe,lt);return(await n.writeFile(Q.path,Le))?.success?(We(Pe),Nn(Q.path).then(ut=>{ut&&(Dt.current=ut)}).catch(()=>{}),!0):(K.error(e("filesView.toast.writeFileFailed")),!1)}catch(Le){return K.error(Le instanceof Error?Le.message:e("filesView.toast.saveFailed")),!1}finally{He(!1)}},[Pe,n,Sn,lt,Nn,Q,e]);o.useEffect(()=>{if(!Sn){bn(null);return}const Le=it=>Ye.current?(Ye.current=!1,!0):(is(!0),hs.current=it,!1);return bn(Le),()=>{_e.getState().mainTabGuard===Le&&bn(null)}},[Sn,bn]),o.useEffect(()=>{try{window.localStorage.setItem(Ag,gt?"true":"false")}catch{}},[gt]),o.useEffect(()=>{gt||(qt("idle"),dt.current&&(clearTimeout(dt.current),dt.current=null))},[gt]);const Yr=1500;o.useEffect(()=>{const Le=!!(Q&&n.writeFile);if(!(!gt||!Sn||!Le||Ue))return dt.current=setTimeout(()=>{Ir().then(it=>{it&&(qt("saved"),setTimeout(()=>qt("idle"),2e3))})},Yr),()=>{dt.current&&(clearTimeout(dt.current),dt.current=null)}},[gt,Pe,Sn,Q,n.writeFile,Ue,Ir]),o.useEffect(()=>{qt("idle")},[Q?.path]),o.useEffect(()=>{const Le=it=>{eu(it)&&(it.key.toLowerCase()==="s"?(it.preventDefault(),dt.current&&(clearTimeout(dt.current),dt.current=null),Ue||Ir().then(ut=>{ut&&(qt("saved"),setTimeout(()=>qt("idle"),2e3))})):it.key.toLowerCase()==="f"&&(it.preventDefault(),F(!0)))};return window.addEventListener("keydown",Le),()=>window.removeEventListener("keydown",Le)},[Ue,Ir]);const Kr=o.useCallback(async Le=>{const it=Qt.current+1;Qt.current=it;const ut=()=>{if(!y)return!1;const Ts=Bn.getState().byRoot[y],Ws=Ts?.selectedPath??Ts?.openPaths[0]??null;return Qt.current===it&&Ws===Le.path};Ze(null),rt(""),ct(null);const Nt=Ai(Le.path),Ht=Le.path.toLowerCase().endsWith(".svg");if(d&&E(!0),r.isDesktop&&Nt&&!Ht){We(""),Me(""),qe(!0);return}if(!r.isDesktop&&Nt&&!Ht){We(""),Me(""),ct(Le.path),qe(!1);return}qe(!0);const Jt={allowOutsideWorkspace:t==="editor-only"&&!!y&&!Hl(Le.path,y)};await ka(Le.path,Jt).then(Ts=>{if(!ut())return;const Ws=Dg(Ts);vt($S(Ts)),We(Ws),Me(Ws.length>Hi?`${Ws.slice(0,Hi)}
|
|
59
|
+
|
|
60
|
+
… truncated …`:Ws),ct(Le.path),Nn(Le.path,Jt).then(Dn=>{Dn&&ut()&&(Dt.current=Dn)}).catch(()=>{})}).catch(Ts=>{if(ut()){if(OS(Ts)){if(qe(!1),y&&Y(y,null),Ze(null),We(""),Me(""),ct(null),Dt.current=null,C.trim().length>0&&k(""),d&&E(!1),y){const Dn=[...kp(Le.path,y),Le.path];Dn.length>0&&we(y,Dn);for(const Fo of Dn)oe.current.has(Fo)||Vs(Fo)}return}if(Ip(Ts)){y&&me(y,Le.path),We(""),Me(""),Ze(null),Dt.current=null,d&&E(!1);return}We(""),Me(""),Ze(Ts instanceof Error?Ts.message:e("filesView.error.readFileFailed")),Dt.current=null}}).finally(()=>{ut()&&qe(!1)})},[we,d,Vs,t,ka,Nn,me,y,r.isDesktop,C,Y,e]),or=o.useCallback(async(Le,it)=>{if(!y)return;const ut=kp(Le,y),Nt=it?[...ut,Le]:ut;Nt.length>0&&we(y,Nt);const Ht=Nt.map(Jt=>{if(!oe.current.has(Jt))return Vs(Jt)}).filter(Boolean);await Promise.all(Ht)},[we,Vs,y]),Hr=o.useCallback((Le,it)=>{const ut=it.findIndex(Nt=>Nt.path===Le);return ut===-1||it.length<=1?null:it[ut+1]??it[ut-1]??null},[]),fn=o.useCallback(async Le=>{if(Ye.current)Ye.current=!1;else if(Sn){is(!0),cs.current=Le;return}y&&(Y(y,Le.path),xe(y,Le.path),or(Le.path,!1)),Ze(null),rt(""),We(""),Me(""),ct(null),d&&E(!0)},[xe,or,Sn,d,y,Y]);o.useEffect(()=>{Q?.path&&or(Q.path,!1)},[or,Q?.path]),o.useEffect(()=>{if(!Q){Qt.current+=1,qe(!1);return}Ge!==Q.path&&Kr(Q)},[Kr,Ge,Q]);const $i=o.useRef(Sn);$i.current=Sn,o.useEffect(()=>{if(!Q?.path||Ge!==Q.path)return;let Le=!1;const it=window.setInterval(()=>{document.hidden||Nn(Q.path,le).then(ut=>{if(Le||!ut)return;const Nt=Dt.current;if(!Nt||Nt.path!==Q.path){Dt.current=ut;return}const Ht=ut.mtimeMs!==void 0&&Nt.mtimeMs!==void 0&&ut.mtimeMs!==Nt.mtimeMs,Jt=ut.size!==Nt.size;!Ht&&!Jt||$i.current||(Dt.current=ut,ct(null))}).catch(()=>{})},2e3);return()=>{Le=!0,window.clearInterval(it)}},[Ge,Nn,Q?.path,le]);const ri=o.useCallback(()=>{const Le=cs.current,it=hs.current,ut=_t.current;if(cs.current=null,hs.current=null,_t.current=null,Ye.current=!0,is(!1),Me(Pn),ut){y&&Z(y,ut),Q?.path===ut&&(Le?fn(Le):(y&&Y(y,null),We(""),Ze(null),rt(""),ct(null),d&&E(!1)));return}if(Le){fn(Le);return}it&&(bn(null),_e.getState().setActiveMainTab(it))},[Pn,fn,d,Z,y,Q?.path,bn,Y]),_i=o.useCallback(async()=>{const Le=cs.current,it=hs.current,ut=_t.current;if(!await Ir()){Ye.current=!1;return}if(cs.current=null,hs.current=null,_t.current=null,Ye.current=!0,is(!1),ut){y&&Z(y,ut),Q?.path===ut&&(Le?await fn(Le):(y&&Y(y,null),We(""),Ze(null),rt(""),ct(null),d&&E(!1)));return}if(Le){await fn(Le);return}it&&(bn(null),_e.getState().setActiveMainTab(it))},[fn,d,Z,y,Ir,Q?.path,bn,Y]),ai=o.useCallback(Le=>{const it=Q?.path===Le,ut=Hr(Le,Fe);if(it&&Sn){is(!0),cs.current=ut,_t.current=Le;return}if(y&&Z(y,Le),!!it){if(ut){fn(ut);return}y&&Y(y,null),We(""),Ze(null),rt(""),ct(null),d&&E(!1)}},[Hr,fn,Sn,d,Fe,Z,y,Q?.path,Y]),Bi=o.useCallback(Le=>{if(se.includes(Le))return"open";if(v?.files){const it=Le.startsWith(y+"/")?Le.slice(y.length+1):Le,ut=v.files.find(Nt=>Nt.path===it);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},[se,v,y]),da=o.useCallback(Le=>{if(!v?.files)return null;const it=Le.startsWith(y+"/")?Le.slice(y.length+1):Le,ut=it?`${it}/`:"";let Nt=0,Ht=0;for(const Jt of v.files)Jt.path.startsWith(ut)&&((Jt.index==="M"||Jt.working_dir==="M")&&Nt++,(Jt.index==="A"||Jt.working_dir==="?")&&Ht++);return Nt+Ht>0?{modified:Nt,added:Ht}:null},[v,y]),Qr=o.useCallback(async Le=>{const it=xn(Le);y&&(Se(y,it),oe.current.has(it)||await Vs(it))},[Vs,y,Se]),pr=o.useMemo(()=>({canRename:js,canCreateFile:Tt,canCreateFolder:gs,canDelete:Ls,canReveal:Os}),[js,Tt,gs,Ls,Os]);function An(Le,it){const ut=L[Le]??[];return ut.map((Nt,Ht)=>{const Jt=Nt.type==="directory",Ts=Jt&&ae.includes(Nt.path),Ws=Q?.path===Nt.path,Dn=Ht===ut.length-1;return s.jsxs("li",{className:"relative",children:[it>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Dn&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(US,{node:Nt,root:y,isExpanded:Ts,isActive:Ws,isMobile:d,alwaysShowActions:u,status:Jt?void 0:Bi(Nt.path),badge:Jt?da(Nt.path):void 0,permissions:pr,downloadFile:n.downloadFile,contextMenuPath:Wt,setContextMenuPath:ts,onSelect:fn,onToggle:Qr,onRevealPath:mn,onOpenDialog:$s}),Jt&&Ts&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:An(Nt.path,it+1)})]},Nt.path)})}const vn=!!(Q?.path&&Ai(Q.path)),Or=!!(Q?.path&&Q.path.toLowerCase().endsWith(".svg")),Pr=o.useMemo(()=>xn(On?.path??""),[On?.path]),zs=!!(On&&Pr&&ce&&ce===Pr&&!at&&!nt&&!vn),$r=o.useMemo(()=>Ed(y,ce),[ce,y]),Ca=!!(Q&&(!vn||Or)&&et.length>0),Vi=!!(Q&&$r.length>0),Gn=!!(Q&&!ve&&!vn&&n.writeFile&&et.length<=Hi),fr=!!(Q?.path&&VS(Q.path)),hn=!!(Q?.path&&zS(Q.path)),Ia=!!(Q?.path&&zc(Q.path)),Pa=!!(Q&&!vn)&&!fr&&!(Ia&&pe==="preview"),ua=o.useMemo(()=>ce?Fl(ce):null,[ce]),[ii,Re]=o.useState(null);o.useEffect(()=>{let Le=!1;const it=Q?.path;if(!it||ua){Re(null);return}return Re(null),py(it).then(ut=>{Le||Re(ut)}),()=>{Le=!0}},[Q?.path,ua]),o.useEffect(()=>{!Gn&&R==="edit"&&H("view")},[Gn,R]);const Xe="openchamber:files:md-viewer-mode",st="openchamber:files:html-viewer-mode",ht="openchamber:files:json-viewer-mode";o.useEffect(()=>{const Le=Q?.path;if(!Le)return;const it=Yt?"view":"edit";H(te.current[Le]??it);let ut=Yt?"preview":"edit";try{const Jt=localStorage.getItem(Xe);(Jt==="preview"||Jt==="edit")&&(ut=Jt)}catch{}ne(X.current[Le]??ut);let Nt=Yt?"preview":"edit";try{const Jt=localStorage.getItem(st);(Jt==="preview"||Jt==="edit")&&(Nt=Jt)}catch{}W(ee.current[Le]??Nt);let Ht=Yt?"tree":"text";try{const Jt=localStorage.getItem(ht);(Jt==="tree"||Jt==="text")&&(Ht=Jt)}catch{}de(Ht)},[Q?.path,Yt]);const Vt=o.useCallback(Le=>{const it=Q?.path;it&&(te.current[it]=Le),H(Le)},[Q?.path]),je=o.useCallback(Le=>{const it=Q?.path;it&&(X.current[it]=Le),ne(Le);try{localStorage.setItem(Xe,Le)}catch{}},[Q?.path]),yt=o.useCallback(()=>J,[J]),mt=o.useCallback(Le=>{de(Le);try{localStorage.setItem(ht,Le)}catch{}},[]),Ut=o.useCallback(Le=>{const it=Q?.path;it&&(ee.current[it]=Le),W(Le);try{localStorage.setItem(st,Le)}catch{}},[Q?.path]),bs=o.useCallback(()=>pe,[pe]);o.useEffect(()=>{if(!On||!y)return;const Le=()=>{typeof window>"u"||ws.current===null&&(ws.current=window.requestAnimationFrame(()=>{ws.current=null,Es(Xr=>Xr+1)}))},it=(Xr,Aa)=>{if(Xr.state.doc.length!==Aa.length)return!1;if(Aa.length===0)return!0;const fc=Math.min(128,Aa.length);if(Xr.state.sliceDoc(0,fc)!==Aa.slice(0,fc))return!1;const Mu=Math.max(0,Aa.length-fc);return Xr.state.sliceDoc(Mu,Aa.length)===Aa.slice(Mu)},ut=xn(On.path);if(!ut){ur(null),Ds.current={key:"",attempts:0};return}const Nt=`${ut}:${On.line}:${On.column??1}`;if(Ds.current.key!==Nt&&(Ds.current={key:Nt,attempts:0}),Q?.path!==ut){if(es)return;fn(ke(ut));return}if(at||Ge!==ut)return;if(nt||vn){ur(null),Ds.current={key:"",attempts:0};return}if(!Gn)return;if(R!=="edit"){H("edit");return}const Ht=wt.current;if(!Ht){Le();return}if(!it(Ht,Pe)){Le();return}const Jt=Math.max(1,Math.min(On.line,Ht.state.doc.lines)),Ts=Ht.state.doc.line(Jt),Ws=Math.max(1,On.column||1),Dn=Math.max(0,Ts.to-Ts.from),Fo=Math.min(Dn,Ws-1),Ui=Ts.from+Fo;if(!(Ht.state.selection.main.head===Ui)||Ds.current.attempts===0){Ds.current.attempts+=1,Ht.dispatch({selection:{anchor:Ui},effects:zn.scrollIntoView(Ui,{y:"center"})}),Ht.focus(),Le();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const Xr=wt.current;Xr&&(Xr.dispatch({selection:{anchor:Ui},effects:zn.scrollIntoView(Ui,{y:"center"})}),Xr.focus())}),ur(null),Ds.current={key:"",attempts:0}},[Gn,es,Pe,us,nt,at,vn,Ge,fn,On,y,Q?.path,ur,R,ke]),o.useEffect(()=>{if(!Be||!y)return;const Le=xn(Be);if(!Le){St(null);return}if(Q?.path!==Le){if(es)return;fn(ke(Le));return}if(!(at||Ge!==Le||nt||vn)){if(Gn&&R==="edit"){const it=wt.current;if(!it)return;it.focus()}St(null)}},[Gn,es,nt,at,fn,vn,Ge,Be,y,Q?.path,St,R,ke]);const Gs=o.useCallback(Le=>{if(!d||!Le||!Le.hasFocus||typeof window>"u")return;const it=window.visualViewport;if(!it)return;const ut=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,ut-(it.offsetTop+it.height))<=0)return;const Ht=Le.state.selection.main.head,Jt=Le.coordsAtPos(Ht);if(!Jt)return;const Ts=Math.round(it.offsetTop+it.height),Dn=Jt.bottom+20-Ts;Dn<=0||(Le.scrollDOM.scrollTop+=Dn)},[d]);o.useEffect(()=>{if(!d||typeof window>"u")return;const Le=()=>{window.requestAnimationFrame(()=>{Gs(wt.current)})},it=window.visualViewport;return it?.addEventListener("resize",Le),it?.addEventListener("scroll",Le,{passive:!0}),document.addEventListener("selectionchange",Le),()=>{it?.removeEventListener("resize",Le),it?.removeEventListener("scroll",Le),document.removeEventListener("selectionchange",Le)}},[d,Gs]),o.useEffect(()=>{if(!Gn||R!=="edit"||d)return;const Le=sa("open_go_to_line",Gt),it=ut=>{const Nt=ut.target;if(Nt?.closest('[role="dialog"]'))return;const Ht=!!Nt?.closest(".cm-editor");Nt?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!Ht||!document.activeElement?.closest(".cm-editor")||ul(ut,Le)&&(ut.preventDefault(),Kt(!0))};return window.addEventListener("keydown",it),()=>window.removeEventListener("keydown",it)},[Gn,d,Gt,R]);const Rn=o.useMemo(()=>{if(!Q?.path)return[ko(a)];const Le=[ko(a)],it=ua??ii;return it&&Le.push(it),P&&Le.push(zn.lineWrapping),d&&Le.push(zn.updateListener.of(ut=>{ut.view.hasFocus&&(ut.selectionSet||ut.focusChanged||ut.viewportChanged||ut.geometryChanged)&&window.requestAnimationFrame(()=>{Gs(ut.view)})})),Le},[a,Q?.path,ua,ii,P,d,Gs]),Ar=o.useMemo(()=>({light:fe.metadata.id,dark:be.metadata.id}),[fe.metadata.id,be.metadata.id]),lr=Q?.path&&vn?r.isDesktop?Or?`data:${Ju(Q.path)};utf8,${encodeURIComponent(et)}`:ze:Or?`data:${Ju(Q.path)};utf8,${encodeURIComponent(et)}`:`/api/fs/raw?${new URLSearchParams({path:Q.path,...le.allowOutsideWorkspace?{allowOutsideWorkspace:"true"}:{}}).toString()}`:"";o.useEffect(()=>{let Le=!1;return(async()=>{if(!r.isDesktop||!Q?.path||!vn||Or){rt("");return}Ze(null),await(n.readFileBinary?n.readFileBinary(Q.path,le).then(Nt=>Nt.dataUrl):Promise.resolve(tb(Q.path,"asset"))).then(Nt=>{Le||(rt(Nt),ct(Q.path))}).catch(Nt=>{Le||(rt(""),Ze(Nt instanceof Error?Nt.message:e("filesView.error.readFileFailed")),ct(null))}).finally(()=>{Le||qe(!1)})})(),()=>{Le=!0}},[n,vn,Or,r.isDesktop,Q?.path,le,e]);const $n=o.useCallback(()=>en(null),[]),Fn=o.useMemo(()=>hg({drafts:Fs,editingDraftId:nn,commentText:Ys,selection:Hs,isDragging:kr,fileLabel:Q?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:Le=>({start:Le.startLine,end:Le.endLine}),onSave:wn,onCancel:()=>{dn(null),mr()},onEdit:Le=>{Jr(Le),dn({start:Le.startLine,end:Le.endLine})},onDelete:Mn}),[mr,Ys,Mn,nn,Fs,wn,kr,Hs,Q?.path,Jr]),oi=o.useCallback((Le,it)=>s.jsx("div",{className:"h-full",children:s.jsx(eb,{file:{name:Le.name,contents:it,lang:Pi(Le.path)||void 0},options:{disableFileHeader:!0,overflow:P?"wrap":"scroll",theme:Ar,themeType:a.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[a.metadata.variant,Ar,P]),zi=({exitFullscreenOnly:Le=!1}={})=>{if(!Q)return null;const it=(ut,Nt)=>s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:Nt})}),s.jsx(At,{side:"bottom",sideOffset:6,children:ut})]});return s.jsxs("div",{className:"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",children:[Gn&&R==="edit"&&s.jsxs(s.Fragment,{children:[Ue?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):gt&&Ft==="saved"&&!Sn?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(A,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):Sn?it(e(gt?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${ro()}+S`}),s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>{Ir()},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(gt?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${ro()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${ro()}+S`}),children:s.jsx(A,{name:"save-3",className:"size-4"})})):null,it(e(gt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>zt(ut=>!ut),className:ge("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",gt?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(gt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(gt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:gt?s.jsx(A,{name:"file-check-fill",className:"size-4"}):s.jsx(A,{name:"file-check",className:"size-4"})}))]}),s.jsxs(As,{onOpenChange:B,children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(Is,{asChild:!0,children:s.jsx(he,{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(A,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(At,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(Ps,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[tn.map(ut=>s.jsxs(Ot,{className:"flex items-center gap-2",onClick:()=>{gn(ut)},children:[s.jsx(DS,{label:ut.label,iconDataUrl:ut.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:ut.label})]},ut.id)),cn?s.jsxs(Ot,{className:"flex items-center gap-2",onClick:()=>{sn(!0)},children:[s.jsx(A,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!vn&&s.jsxs(s.Fragment,{children:[it(e(P?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>T(!P),className:ge("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(A,{name:"text-wrap",className:"size-4"})})),R==="edit"&&s.jsxs(s.Fragment,{children:[it(e("filesView.editor.findInFile"),s.jsx(he,{variant:"ghost",size:"sm",onClick:ut=>{F(!D),ut.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(A,{name:"search",className:"size-4"})})),it(e("filesView.editor.goToLine"),s.jsx(he,{variant:"ghost",size:"sm",onClick:ut=>{Kt(Nt=>!Nt),ut.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(A,{name:"menu-fold-2",className:"size-4"})})),s.jsx(PS,{open:kt,onOpenChange:Kt,view:wt.current,variant:"inline"})]})]}),Pa&&Gn&&!hn&&!Ia&&s.jsx(Kl,{currentMode:R==="view"?"preview":"edit",onToggle:()=>{Vt(R==="view"?"edit":"view")}}),(fr||zc(Q?.path??""))&&s.jsx(Kl,{currentMode:fr?yt():bs(),onToggle:()=>{zc(Q?.path??"")?Ut(bs()==="preview"?"edit":"preview"):je(yt()==="preview"?"edit":"preview")}}),hn&&it(e(ue==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>mt(ue==="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(ue==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:ue==="tree"?s.jsx(A,{name:"code-sslash",className:"size-4"}):s.jsx(A,{name:"node-tree",className:"size-4"})})),Ca&&it(e("filesView.editor.copyFileContents"),s.jsx(he,{variant:"ghost",size:"sm",onClick:async()=>{(await Ln(et)).ok?(Ke(!0),Mt.current!==null&&window.clearTimeout(Mt.current),Mt.current=window.setTimeout(()=>{Ke(!1)},1200)):K.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:ss?s.jsx(A,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(A,{name:"clipboard",className:"size-4"})})),Vi&&it(e("filesView.editor.copyFilePathTitle",{path:$r}),s.jsx(he,{variant:"ghost",size:"sm",onClick:async()=>{(await Ln($r)).ok?(Ct(!0),Bt.current!==null&&window.clearTimeout(Bt.current),Bt.current=window.setTimeout(()=>{Ct(!1)},1200)):K.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:Je?s.jsx(A,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(A,{name:"file-copy-2",className:"size-4"})})),n.downloadFile&&it(e("filesView.editor.saveFile"),s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>{const ut=n.downloadFile;ut&&ut(Q.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(A,{name:"download",className:"size-4"})})),Le?it(e("filesView.editor.exitFullscreen"),s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>M(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(A,{name:"fullscreen-exit",className:"size-4"})})):!d&&t==="full"&&it(e(S?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>M(!S),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(S?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(S?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:S?s.jsx(A,{name:"fullscreen-exit",className:"size-4"}):s.jsx(A,{name:"fullscreen",className:"size-4"})}))]})},pc=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(ls,{open:es,onOpenChange:Le=>{Le||is(!0)},children:s.jsxs(os,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:e("filesView.unsaved.title")}),s.jsx(ys,{children:e("filesView.unsaved.description")})]}),s.jsxs(Rs,{children:[s.jsx(he,{variant:"outline",onClick:()=>{_i()},disabled:Ue,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(he,{variant:"destructive",onClick:ri,children:e("filesView.unsaved.discard")})]})]})}),s.jsx("div",{className:ge("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&&I&&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(A,{name:"arrow-left-s",className:"size-5"})}),d?Q?s.jsxs(As,{children:[s.jsx(Is,{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(Er,{filePath:Q.path,extension:Q.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Cp,{name:Q.name}),s.jsx(A,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Ps,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Fe.map(Le=>{const it=Q?.path===Le.path;return s.jsxs(Ot,{onSelect:ut=>{if(ut.target.closest("[data-close-open-file]")){ut.preventDefault();return}it||fn(Le)},className:ge("flex min-w-0 items-center justify-between gap-2 overflow-hidden",it&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[s.jsx(Er,{filePath:Le.path,extension:Le.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Cp,{name:Le.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:ut=>{ut.preventDefault(),ut.stopPropagation()},onClick:ut=>{ut.preventDefault(),ut.stopPropagation(),ai(Le.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:Le.name}),children:s.jsx(A,{name:"close",className:"size-3.5"})})]},Le.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Fe.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Te.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"}),Te.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:Ae,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Fe.map(Le=>{const it=Q?.path===Le.path;return s.jsxs("div",{title:Ed(y,Le.path),className:ge("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",it?"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(Er,{filePath:Le.path,extension:Le.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{it||fn(Le)},className:"max-w-[12rem] truncate text-left",children:Le.name}),s.jsx("button",{type:"button",onClick:ut=>{ut.stopPropagation(),ai(Le.path)},className:ge("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!it&&!u&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:Le.name}),children:s.jsx(A,{name:"close",className:"size-3.5"})})]},Le.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:[Q&&!D&&s.jsx("div",{ref:$,className:"absolute right-3 top-3 z-30",onMouseEnter:()=>V(!0),onMouseLeave:()=>{O.current>0||V(!1)},children:_?zi():s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>V(!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(A,{name:"more-2-fill",className:"size-4"})})})}),s.jsx(At,{side:"bottom",sideOffset:6,children:e("filesView.editor.controlsTitle")})]})}),s.jsx(vs,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:Q?at?h?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):nt?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:nt}):vn?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:lr,alt:Q?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"})}):Q&&hn&&ue==="tree"?s.jsx(Qs,{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(fy,{jsonString:et,maxHeight:"100%",initiallyExpandedDepth:2})})}):Q&&fr&&yt()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[et.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(et.length/1024)})}),s.jsx(Qs,{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(Na,{content:et,className:"typography-markdown-body",stripFrontmatter:!0})})]}):Q&&Ia&&pe==="preview"?s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{srcDoc:(()=>{const Le=Q.path.substring(0,Q.path.lastIndexOf("/")+1);if(!Le)return et;const it=`<base href="${r.isDesktop,Le}">`;return et.replace(/<head([^>]*)>/i,`<head$1>${it}`)})(),className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")})}):Q&&Pa&&R==="view"?oi(Q,Pe):s.jsxs("div",{className:ge("relative h-full",zs&&"overflow-hidden"),ref:Zt,children:[s.jsx("div",{className:ge("h-full",zs&&"invisible"),children:s.jsx(So,{value:Pe,onChange:Me,readOnly:!Gn,extensions:Rn,className:"h-full",blockWidgets:Fn,onViewReady:Le=>{wt.current=Le,Es(it=>it+1),window.requestAnimationFrame(()=>{Gs(Le)})},onViewDestroy:()=>{wt.current&&(wt.current=null),Es(Le=>Le+1)},enableSearch:!0,searchOpen:D,onSearchOpenChange:F,highlightLines:Hs?{start:Math.min(Hs.start,Hs.end),end:Math.max(Hs.start,Hs.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(Le,it,ut)=>{if(!(ut instanceof MouseEvent)||ut.button!==0)return!1;ut.preventDefault();const Nt=Le.state.doc.lineAt(it.from).number;if(d&&Hs&&!ut.shiftKey){const Ht=Math.min(Hs.start,Hs.end,Nt),Jt=Math.max(Hs.start,Hs.end,Nt);return dn({start:Ht,end:Jt}),Kn.current=!1,Hn.current=null,ir(!1),!0}if(Kn.current=!0,Hn.current=Nt,ir(!0),Hs&&ut.shiftKey){const Ht=Math.min(Hs.start,Nt),Jt=Math.max(Hs.end,Nt);dn({start:Ht,end:Jt})}else dn({start:Nt,end:Nt});return!0},mouseover:(Le,it,ut)=>{if(!(ut instanceof MouseEvent)||ut.buttons!==1||!Kn.current||Hn.current===null)return!1;const Nt=Le.state.doc.lineAt(it.from).number,Ht=Math.min(Hn.current,Nt),Jt=Math.max(Hn.current,Nt);return dn({start:Ht,end:Jt}),ir(!0),!1},mouseup:()=>(Kn.current=!1,Hn.current=null,ir(!1),!1)}}})}),zs&&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(A,{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")})})]})]}),kx=!!(y&&L[y]),Eu=s.jsxs("section",{className:ge("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:ge("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(A,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx($t,{ref:N,value:C,onChange:Le=>k(Le.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),C.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:()=>{k(""),N.current?.focus()},children:s.jsx(A,{name:"close",className:"size-4"})})]}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>$s("createFile",{path:g,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(A,{name:"file-add",className:"size-4"})})})}),s.jsx(At,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>$s("createFolder",{path:g,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(A,{name:"folder-add",className:"size-4"})})})}),s.jsx(At,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>{yn()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(A,{name:"refresh",className:"size-4"})})})}),s.jsx(At,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:ge("py-2",d?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:Qe?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):z.length>0?z.map(Le=>{const it=Q?.path===Le.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{fn(Le)},className:ge("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",it?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[Tg(Le.path,Le.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:Le.path,children:Le.relativePath??Le.path})]})},Le.path)}):kx?An(y,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Cx=t==="full"&&S&&Q&&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:zi({exitFullscreenOnly:!0})}),s.jsx(vs,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:at?h?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):nt?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:nt}):vn?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:lr,alt:Q.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"})}):fr&&yt()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[et.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(et.length/1024)})}),s.jsx(Qs,{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(Na,{content:et,className:"typography-markdown-body",stripFrontmatter:!0})})]}):Pa&&R==="view"?oi(Q,Pe):s.jsxs("div",{className:ge("relative h-full",zs&&"overflow-hidden"),children:[s.jsx("div",{className:ge("h-full",zs&&"invisible"),children:s.jsx(So,{value:Pe,onChange:Me,readOnly:!Gn,extensions:Rn,className:"h-full",onViewReady:Le=>{wt.current=Le,window.requestAnimationFrame(()=>{Gs(Le)})},onViewDestroy:()=>{wt.current&&(wt.current=null)}})}),zs&&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(A,{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(WS,{activeDialog:Xt,dialogData:Ks,dialogInputValue:Xs,onDialogInputChange:re,isDialogSubmitting:bt,onDialogSubmit:ni,onClose:$n,inputRef:ft}),Cx,d?I?pc:Eu: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:pc})}):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:Eu}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:pc})]})]})},KS=Object.freeze(Object.defineProperty({__proto__:null,FilesView:Eg},Symbol.toStringTag,{value:"Module"})),zr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Uc=(t,e)=>{const n=zr(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},HS=(t,e,n)=>Uc(Uc(Uc(t,".opencode"),"plans"),`${e}-${n}.md`),GS=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,qS=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},JS=(t,e)=>{const n=zr(e.currentDirectory),r=zr(e.homeDirectory),a=zr(t);return n&&a.startsWith(n+"/")?a.slice(n.length+1):r&&a===r?"~":r&&a.startsWith(r+"/")?`~${a.slice(r.length)}`:a},YS=(t,e,n)=>{const r=zr(t.trim());if(!r)return null;const a=n?e.find(l=>l.id===n)??null:null;if(a?.path){const l=zr(a.path);if(r===l||r.startsWith(`${l}/`))return{id:a.id,path:a.path}}const i=e.filter(l=>{const c=zr(l.path);return r===c||r.startsWith(`${c}/`)}).sort((l,c)=>zr(c.path).length-zr(l.path).length)[0];return i?{id:i.id,path:i.path}:null},Mg=({targetPath:t=null})=>{const{t:e}=pt(),n=Lt(q=>q.currentSessionId),r=Lt(q=>q.createSession),a=Lt(q=>q.initializeNewOpenChamberSession),i=Lt(q=>q.sendMessage),l=Lt(q=>q.setCurrentSession),c=ic(),d=Ms(q=>q.homeDirectory),f=Zd(q=>q.planModeEnabled),m=Ss(q=>q.projects),u=Ss(q=>q.activeProjectId),p=qs(q=>q.directories),b=la()??"",g=_e(q=>q.setActiveMainTab),y=_e(q=>q.setSessionSwitcherOpen),x=Wn(),{isMobile:h}=an(),{currentTheme:j}=Sr();o.useMemo(()=>Ah(j),[j]);const v=o.useMemo(()=>n?c.find(q=>q.id===n)??null:null,[n,c]),C=o.useMemo(()=>{const q=typeof v?.directory=="string"?v.directory:"";return zr(q||"")},[v?.directory]),k=o.useMemo(()=>zr(b||C),[b,C]),w=o.useMemo(()=>YS(k,m,u),[u,k,m]),N=o.useMemo(()=>w?p.get(w.path)?.isGitRepo===!0:!1,[w,p]),[I,E]=o.useState(null),[P,T]=o.useState(!1),[S,M]=o.useState(null),D=o.useMemo(()=>!S||!C||!d?S:JS(S,{currentDirectory:C,homeDirectory:d}),[S,C,d]),[F,_]=o.useState(""),[V,$]=o.useState(null),O=o.useMemo(()=>D&&D.split("/").pop()||e("planView.file.defaultName"),[D,e]),B=o.useMemo(()=>F.trim()&&hy(F).title||e("planView.title.default"),[F,e]),G=o.useMemo(()=>B.trim()||e("planView.title.default"),[B,e]),[R,H]=o.useState(!1),[J,ne]=o.useState(!1),[ue,de]=o.useState("edit"),pe=o.useRef(null),[W,te]=o.useState(null),X=o.useRef(null),ee=o.useRef(null),fe="openchamber:plan:md-viewer-mode";o.useEffect(()=>{try{const q=localStorage.getItem(fe);if(!q)return;const L=JSON.parse(q);(L==="preview"||L==="edit")&&de(L)}catch{}},[]);const be=o.useCallback(q=>{de(q);try{localStorage.setItem(fe,JSON.stringify(q))}catch{}},[]),Ne=o.useRef(!1),se=o.useRef(null),[ie,ae]=o.useState(!1);o.useEffect(()=>{const q=()=>{Ne.current=!1,se.current=null,ae(!1)};return document.addEventListener("mouseup",q),()=>document.removeEventListener("mouseup",q)},[]);const xe=o.useCallback((q,L)=>{const U=q.split(`
|
|
61
|
+
`),oe=Math.max(1,L.start),Ee=Math.min(U.length,L.end);return oe>Ee?"":U.slice(oe-1,Ee).join(`
|
|
62
|
+
`)},[]),Z=gu({source:"plan",fileLabel:O,language:S&&Pi(S)||"markdown",getCodeForRange:q=>xe(F,zl(q)),toStoreRange:q=>({startLine:q.start,endLine:q.end}),fromDraftRange:q=>({start:q.startLine,end:q.endLine})}),{drafts:me,commentText:Y,editingDraftId:Se,setSelection:we,saveComment:ke,cancel:Fe,reset:Ce,startEdit:Q,deleteDraft:ce}=Z;o.useEffect(()=>{te(null),Ce()},[F,Ce]),o.useEffect(()=>{we(W)},[W,we]);const ve=o.useCallback(()=>{te(null),Fe()},[Fe]),le=o.useCallback((q,L)=>{L&&te(L),ke(q,L??W??void 0),te(null)},[W,ke]);o.useEffect(()=>{if(!W)return;const q=U=>{const oe=U.target;oe.closest('[data-comment-card="true"]')||oe.closest('[data-comment-input="true"]')||oe.closest(".oc-block-widget")||oe.closest(".cm-gutterElement")||oe.closest("[data-sonner-toast]")||oe.closest("[data-sonner-toaster]")||(te(null),Fe())},L=window.setTimeout(()=>{document.addEventListener("click",q)},100);return()=>{window.clearTimeout(L),document.removeEventListener("click",q)}},[Fe,Se,h,W]);const Ae=o.useMemo(()=>{const q=[ko(j)],L=Fl(S||"plan.md");return L&&q.push(L),q.push(zn.lineWrapping),q},[j,S]);o.useEffect(()=>{if(!f&&!t){M(null),_(""),H(!1);return}let q=!1;const L=async oe=>{if(x.files?.readFile)return(await x.files.readFile(oe))?.content??"";const Ee=dr()?.files;if(Ee?.readFile)return(await Ee.readFile(oe,{optional:!0}))?.content??"";const Oe=await fetch(`/api/fs/read?path=${encodeURIComponent(oe)}&optional=true`,{cache:"no-store"});if(!Oe.ok)throw new Error(`Failed to read plan file (${Oe.status})`);return Oe.text()};return(async()=>{if(M(null),_(""),$(null),t){H(!0);try{const oe=await L(t);if(q)return;M(t),_(oe)}catch{if(q)return;M(null),_("")}finally{q||H(!1)}return}if(!v?.slug||!v?.time?.created||!C){M(null),_("");return}H(!0);try{const oe=HS(C,v.time.created,v.slug),Ee=qS(GS(v.time.created,v.slug),d||null);let Oe=null,Ie=null;try{Ie=await L(oe),Oe=oe}catch{}if(!Oe)try{Ie=await L(Ee),Oe=Ee}catch{}if(q)return;if(!Oe||Ie===null){M(null),_("");return}M(Oe),_(Ie)}catch{if(q)return;M(null),_("")}finally{q||H(!1)}})(),()=>{q=!0}},[d,f,x.files,C,v?.slug,v?.time?.created,t]),o.useEffect(()=>{if(!S){$(null);return}const q=window.setTimeout(async()=>{$(null);try{if(x.files?.writeFile){if(!(await x.files.writeFile(S,F))?.success)throw new Error(e("planView.error.writeFailed"))}else{const L=await fetch("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:S,content:F})});if(!L.ok)throw new Error(e("planView.error.writePlanFileFailed",{status:L.status}))}}catch(L){$(L instanceof Error?L.message:e("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(q)}},[F,S,x.files,e]),o.useEffect(()=>()=>{pe.current!==null&&window.clearTimeout(pe.current)},[]);const Te=o.useCallback(()=>{g("chat"),y(!1)},[g,y]),$e=o.useCallback(async q=>{if(!w||!I)return;const L=await Cn(I.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:G}),oe=[{synthetic:!0,text:await Cn(I.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:G,plan_path:S??""})}];T(!0);try{Te();let Ee=null,Oe=w.path;if(I.target==="worktree"){if(!N)return;const z=await kh(w.path,Ch());if(!z?.id)return;Ee=z.id,Oe=null}else{const z=await r(void 0,w.path,null);if(!z?.id)return;Ee=z.id,Oe=z.directory??w.path,a(z.id,jt.getState().agents??[])}if(!Ee)return;const Ie=tc.getState();Ie.saveSessionModelSelection(Ee,q.providerID,q.modelID),q.agent.trim()&&(Ie.saveSessionAgentSelection(Ee,q.agent),Ie.saveAgentModelForSession(Ee,q.agent,q.providerID,q.modelID),Ie.saveAgentModelVariantForSession(Ee,q.agent,q.providerID,q.modelID,q.variant||void 0)),l(Ee,Oe),await i(L,q.providerID,q.modelID,q.agent.trim()||void 0,void 0,void 0,oe,q.variant||void 0),E(null)}finally{T(!1)}},[N,r,w,a,I,S,Te,i,G,l]),ye=o.useMemo(()=>hg({drafts:me,editingDraftId:Se,commentText:Y,selection:W,isDragging:ie,fileLabel:O,newWidgetId:"plan-new-comment-input",mapDraftToRange:q=>({start:q.startLine,end:q.endLine}),onSave:le,onCancel:ve,onEdit:q=>{Q(q),te({start:q.startLine,end:q.endLine})},onDelete:ce}),[Y,ce,Se,ve,le,ie,W,me,O,Q]);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:B}),V?s.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:V,children:e("planView.error.saveFailed")}):null]}),S?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(As,{children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsx(he,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.improvePlanAria"),disabled:!F.trim(),children:s.jsx(A,{name:"loop-right-ai",className:"size-4"})})})}),s.jsx(At,{sideOffset:8,children:e("planView.actions.improve")})]}),s.jsxs(Ps,{align:"end",children:[s.jsx(Ot,{onClick:()=>E({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(Ot,{onClick:()=>E({action:"improve",target:"worktree"}),disabled:!N,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsxs(As,{children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsx(he,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.implementPlanAria"),disabled:!F.trim(),children:s.jsx(A,{name:"code-ai",className:"size-4"})})})}),s.jsx(At,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs(Ps,{align:"end",children:[s.jsx(Ot,{onClick:()=>E({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(Ot,{onClick:()=>E({action:"implement",target:"worktree"}),disabled:!N,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(Kl,{currentMode:ue,onToggle:()=>be(ue==="preview"?"edit":"preview")}),s.jsx(he,{variant:"ghost",size:"sm",onClick:async()=>{(await Ln(F)).ok&&(ne(!0),pe.current!==null&&window.clearTimeout(pe.current),pe.current=window.setTimeout(()=>{ne(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:J?s.jsx(A,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(A,{name:"clipboard",className:"h-4 w-4"})})]}):null]}),s.jsx(ag,{open:I!==null,onOpenChange:q=>{!q&&!P&&E(null)},target:I?.target??"session",projectDirectory:w?.path??null,submitting:P,onConfirm:$e}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(vs,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:R?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:ue==="preview"?s.jsx("div",{className:"h-full overflow-auto p-3",children:s.jsx(Qs,{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(Na,{content:F,className:"typography-markdown-body"})})}):s.jsx("div",{className:"relative h-full",ref:ee,children:s.jsx(So,{value:F,onChange:_,readOnly:!1,className:"h-full",extensions:Ae,onViewReady:q=>{X.current=q},onViewDestroy:()=>{X.current=null},blockWidgets:ye,highlightLines:W?{start:Math.min(W.start,W.end),end:Math.max(W.start,W.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(q,L,U)=>{if(!(U instanceof MouseEvent)||U.button!==0)return!1;U.preventDefault();const oe=q.state.doc.lineAt(L.from).number;if(h&&W&&!U.shiftKey){const Ee=Math.min(W.start,W.end,oe),Oe=Math.max(W.start,W.end,oe);return te({start:Ee,end:Oe}),Ne.current=!1,se.current=null,ae(!1),!0}if(Ne.current=!0,se.current=oe,ae(!0),W&&U.shiftKey){const Ee=Math.min(W.start,oe),Oe=Math.max(W.end,oe);te({start:Ee,end:Oe})}else te({start:oe,end:oe});return!0},mouseover:(q,L,U)=>{if(!(U instanceof MouseEvent)||U.buttons!==1||!Ne.current||se.current===null)return!1;const oe=q.state.doc.lineAt(L.from).number,Ee=Math.min(se.current,oe),Oe=Math.max(se.current,oe);return te({start:Ee,end:Oe}),ae(!0),!1},mouseup:()=>(Ne.current=!1,se.current=null,ae(!1),!1)}}})})})})})})]})},QS=Object.freeze(Object.defineProperty({__proto__:null,PlanView:Mg},Symbol.toStringTag,{value:"Module"})),Md={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},yl={user:0,assistant:0,tool:0,other:0},Fa=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,Pp=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(f=>f.tokens!==void 0)?.tokens;if(typeof n=="number")return{...Md,total:Fa(n)};if(!n||typeof n!="object")return Md;const r=n,a=Fa(r.input),i=Fa(r.output),l=Fa(r.reasoning),c=Fa(r.cache?.read),d=Fa(r.cache?.write);return{input:a,output:i,reasoning:l,cacheRead:c,cacheWrite:d,total:a+i+l+c+d}},XS=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},gr=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+gr(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+gr(n),0):0,ZS=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...yl,assistant:gr(n.text)+gr(n.content)};const a=XS(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:gr(n.input)+gr(n.output)+gr(n.error)+gr(n.call?.input)+gr(n.call?.output)+gr(n.call?.error)+gr(n.raw)+Math.round(gr(n.metadata)*.25)+Math.round(gr(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}},Ap=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),ek=t=>{const e=Ao(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},tk=(t,e)=>{if(t.length===0)return{...yl};const n=t.reduce((r,a)=>{const i=ek(a);let l={...yl};for(const c of a.parts)l=Ap(l,ZS(c,i));return Ap(r,l)},{...yl});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)}},fi=t=>t.toLocaleString(),sk=t=>!Number.isFinite(t)||t<=0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`,nk=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),rk=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),ak=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,ik=(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}},ok=()=>{const t=ot.c(199),{t:e}=pt(),{currentTheme:n}=Sr();let r;t[0]!==n?(r=Ah(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[l,c]=o.useState(i),[d,f]=o.useState(null),m=o.useRef(null),u=Lt(lk),p=ic(),b=gy(u??""),g=jt(ck);let y;t[3]===Symbol.for("react.memo_cache_sentinel")?(y=()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null),c(dk),f(null)},t[3]=y):y=t[3];let x;t[4]!==u?(x=[u],t[4]=u,t[5]=x):x=t[5],o.useEffect(y,x);let h,j;t[6]===Symbol.for("react.memo_cache_sentinel")?(h=()=>()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},j=[],t[6]=h,t[7]=j):(h=t[6],j=t[7]),o.useEffect(h,j);let v;t[8]===Symbol.for("react.memo_cache_sentinel")?(v=async(dt,Dt)=>{(await Ln(Dt)).ok?(f(dt),m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{f(Ft=>Ft===dt?null:Ft),m.current=null},2e3)):f(null)},t[8]=v):v=t[8];const C=v;let k;t[9]!==u||t[10]!==p?(k=u?p.find(dt=>dt.id===u)??null:null,t[9]=u,t[10]=p,t[11]=k):k=t[11];const w=k;let N,I,E,P,T;if(t[12]!==g||t[13]!==b){N=b.filter(uk);let dt;t[19]!==b?(dt=b.filter(mk),t[19]=b,t[20]=dt):dt=t[20],T=dt;let Dt=null;for(let Ft=N.length-1;Ft>=0;Ft=Ft-1,Ft){const qt=N[Ft];if(Pp(qt).total>0){Dt=qt;break}}E=Dt?Pp(Dt):Md,P=N.reduce(pk,0);const Qt=Dt?.info??null;I=ik(g,Qt?.providerID||"",Qt?.modelID||""),t[12]=g,t[13]=b,t[14]=N,t[15]=I,t[16]=E,t[17]=P,t[18]=T}else N=t[14],I=t[15],E=t[16],P=t[17],T=t[18];const S=I,M=S.contextLimit,D=M&&M>0?Math.min(999,E.total/M*100):0;let F;if(t[21]!==b){const dt=[...b].reverse().find(fk)?.info?.system||"";F=tk(b,dt),t[21]=b,t[22]=F}else F=t[22];const _=F,V=_.user,$=_.assistant,O=_.tool,B=Math.max(0,E.input-V-$-O),G=V+$+O+B,R=b[0]?.info?.time?.created,H=b.length>0?b[b.length-1]?.info?.time?.created:null;let J;t[23]!==w?.title||t[24]!==e?(J=w?.title||e("contextSidebar.session.untitled"),t[23]=w?.title,t[24]=e,t[25]=J):J=t[25];const ne=w?.time?.created??R??null,ue=H??w?.time?.created??null;let de;t[26]!==$||t[27]!==B||t[28]!==O||t[29]!==V?(de={user:V,assistant:$,tool:O,other:B},t[26]=$,t[27]=B,t[28]=O,t[29]=V,t[30]=de):de=t[30];let pe;t[31]!==N.length||t[32]!==G||t[33]!==M||t[34]!==S||t[35]!==b.length||t[36]!==J||t[37]!==ne||t[38]!==ue||t[39]!==de||t[40]!==E||t[41]!==P||t[42]!==D||t[43]!==T.length?(pe={sessionTitle:J,messagesCount:b.length,userMessagesCount:T.length,assistantMessagesCount:N.length,createdAt:ne,lastActivityAt:ue,providerModel:S,tokenBreakdown:E,usagePercent:D,totalAssistantCost:P,contextLimit:M,breakdown:de,breakdownTotal:G},t[31]=N.length,t[32]=G,t[33]=M,t[34]=S,t[35]=b.length,t[36]=J,t[37]=ne,t[38]=ue,t[39]=de,t[40]=E,t[41]=P,t[42]=D,t[43]=T.length,t[44]=pe):pe=t[44];const W=pe;if(!u){let dt;t[45]!==e?(dt=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=dt):dt=t[46];let Dt;return t[47]!==dt?(Dt=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:dt}),t[47]=dt,t[48]=Dt):Dt=t[48],Dt}let te;t[49]!==e?(te=e("contextSidebar.breakdown.user"),t[49]=e,t[50]=te):te=t[50];let X;t[51]!==te||t[52]!==W.breakdown.user?(X={key:"user",label:te,value:W.breakdown.user,color:"var(--status-success)"},t[51]=te,t[52]=W.breakdown.user,t[53]=X):X=t[53];let ee;t[54]!==e?(ee=e("contextSidebar.breakdown.assistant"),t[54]=e,t[55]=ee):ee=t[55];let fe;t[56]!==ee||t[57]!==W.breakdown.assistant?(fe={key:"assistant",label:ee,value:W.breakdown.assistant,color:"var(--primary-base)"},t[56]=ee,t[57]=W.breakdown.assistant,t[58]=fe):fe=t[58];let be;t[59]!==e?(be=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=be):be=t[60];let Ne;t[61]!==be||t[62]!==W.breakdown.tool?(Ne={key:"tool",label:be,value:W.breakdown.tool,color:"var(--status-warning)"},t[61]=be,t[62]=W.breakdown.tool,t[63]=Ne):Ne=t[63];let se;t[64]!==e?(se=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=se):se=t[65];let ie;t[66]!==se||t[67]!==W.breakdown.other?(ie={key:"other",label:se,value:W.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=se,t[67]=W.breakdown.other,t[68]=ie):ie=t[68];let ae;t[69]!==X||t[70]!==fe||t[71]!==Ne||t[72]!==ie?(ae=[X,fe,Ne,ie],t[69]=X,t[70]=fe,t[71]=Ne,t[72]=ie,t[73]=ae):ae=t[73];const xe=ae;let Z;t[74]!==W.sessionTitle?(Z=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:W.sessionTitle}),t[74]=W.sessionTitle,t[75]=Z):Z=t[75];let me;t[76]!==W.providerModel.modelName||t[77]!==W.providerModel.providerName?(me=s.jsxs("span",{children:[W.providerModel.providerName," / ",W.providerModel.modelName]}),t[76]=W.providerModel.modelName,t[77]=W.providerModel.providerName,t[78]=me):me=t[78];let Y;t[79]!==W.createdAt?(Y=W.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:nk(W.createdAt)})]}),t[79]=W.createdAt,t[80]=Y):Y=t[80];let Se;t[81]!==me||t[82]!==Y?(Se=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:[me,Y]}),t[81]=me,t[82]=Y,t[83]=Se):Se=t[83];let we;t[84]!==Z||t[85]!==Se?(we=s.jsxs("div",{className:"mb-6",children:[Z,Se]}),t[84]=Z,t[85]=Se,t[86]=we):we=t[86];let ke;t[87]!==e?(ke=e("contextSidebar.section.context"),t[87]=e,t[88]=ke):ke=t[88];let Fe;t[89]!==ke?(Fe=s.jsx("span",{className:"typography-micro text-muted-foreground",children:ke}),t[89]=ke,t[90]=Fe):Fe=t[90];let Ce;t[91]!==W.tokenBreakdown.total?(Ce=fi(W.tokenBreakdown.total),t[91]=W.tokenBreakdown.total,t[92]=Ce):Ce=t[92];let Q;t[93]!==W.contextLimit?(Q=W.contextLimit?` / ${fi(W.contextLimit)}`:"",t[93]=W.contextLimit,t[94]=Q):Q=t[94];let ce;t[95]!==Ce||t[96]!==Q?(ce=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[Ce,Q]}),t[95]=Ce,t[96]=Q,t[97]=ce):ce=t[97];let ve;t[98]!==Fe||t[99]!==ce?(ve=s.jsxs("div",{className:"flex items-baseline justify-between",children:[Fe,ce]}),t[98]=Fe,t[99]=ce,t[100]=ve):ve=t[100];let le;t[101]!==W.usagePercent?(le=W.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,W.usagePercent)}%`,backgroundColor:W.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[101]=W.usagePercent,t[102]=le):le=t[102];let Ae;t[103]!==le?(Ae=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:le}),t[103]=le,t[104]=Ae):Ae=t[104];let Te;t[105]!==e||t[106]!==W.usagePercent?(Te=e("contextSidebar.context.percentUsed",{percent:W.usagePercent.toFixed(1)}),t[105]=e,t[106]=W.usagePercent,t[107]=Te):Te=t[107];let $e;t[108]!==Te?($e=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Te}),t[108]=Te,t[109]=$e):$e=t[109];let ye;t[110]!==ve||t[111]!==Ae||t[112]!==$e?(ye=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[ve,Ae,$e]}),t[110]=ve,t[111]=Ae,t[112]=$e,t[113]=ye):ye=t[113];let q;t[114]!==e?(q=e("contextSidebar.stats.messages"),t[114]=e,t[115]=q):q=t[115];let L;t[116]!==W.messagesCount?(L=fi(W.messagesCount),t[116]=W.messagesCount,t[117]=L):L=t[117];let U;t[118]!==q||t[119]!==L?(U={label:q,value:L},t[118]=q,t[119]=L,t[120]=U):U=t[120];let oe;t[121]!==e?(oe=e("contextSidebar.stats.user"),t[121]=e,t[122]=oe):oe=t[122];let Ee;t[123]!==W.userMessagesCount?(Ee=fi(W.userMessagesCount),t[123]=W.userMessagesCount,t[124]=Ee):Ee=t[124];let Oe;t[125]!==oe||t[126]!==Ee?(Oe={label:oe,value:Ee},t[125]=oe,t[126]=Ee,t[127]=Oe):Oe=t[127];let Ie;t[128]!==e?(Ie=e("contextSidebar.stats.assistant"),t[128]=e,t[129]=Ie):Ie=t[129];let z;t[130]!==W.assistantMessagesCount?(z=fi(W.assistantMessagesCount),t[130]=W.assistantMessagesCount,t[131]=z):z=t[131];let De;t[132]!==Ie||t[133]!==z?(De={label:Ie,value:z},t[132]=Ie,t[133]=z,t[134]=De):De=t[134];let Qe;t[135]!==e?(Qe=e("contextSidebar.stats.cost"),t[135]=e,t[136]=Qe):Qe=t[136];let tt;t[137]!==W.totalAssistantCost?(tt=sk(W.totalAssistantCost),t[137]=W.totalAssistantCost,t[138]=tt):tt=t[138];let et;t[139]!==Qe||t[140]!==tt?(et={label:Qe,value:tt},t[139]=Qe,t[140]=tt,t[141]=et):et=t[141];let We;t[142]!==U||t[143]!==Oe||t[144]!==De||t[145]!==et?(We=[U,Oe,De,et],t[142]=U,t[143]=Oe,t[144]=De,t[145]=et,t[146]=We):We=t[146];const at=We;let qe;t[147]!==at?(qe=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:at.map(hk)}),t[147]=at,t[148]=qe):qe=t[148];let nt;t[149]!==e?(nt=e("contextSidebar.section.lastAssistantMessage"),t[149]=e,t[150]=nt):nt=t[150];let Ze;t[151]!==nt?(Ze=s.jsx("div",{className:"typography-micro text-muted-foreground",children:nt}),t[151]=nt,t[152]=Ze):Ze=t[152];let ze;t[153]!==e||t[154]!==W.tokenBreakdown.cacheRead||t[155]!==W.tokenBreakdown.cacheWrite||t[156]!==W.tokenBreakdown.input||t[157]!==W.tokenBreakdown.output||t[158]!==W.tokenBreakdown.reasoning?(ze=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:W.tokenBreakdown.input},{label:e("contextSidebar.tokens.output"),value:W.tokenBreakdown.output},{label:e("contextSidebar.tokens.reasoning"),value:W.tokenBreakdown.reasoning},{label:e("contextSidebar.tokens.cacheRead"),value:W.tokenBreakdown.cacheRead},{label:e("contextSidebar.tokens.cacheWrite"),value:W.tokenBreakdown.cacheWrite}].map(gk)}),t[153]=e,t[154]=W.tokenBreakdown.cacheRead,t[155]=W.tokenBreakdown.cacheWrite,t[156]=W.tokenBreakdown.input,t[157]=W.tokenBreakdown.output,t[158]=W.tokenBreakdown.reasoning,t[159]=ze):ze=t[159];let rt;t[160]!==Ze||t[161]!==ze?(rt=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Ze,ze]}),t[160]=Ze,t[161]=ze,t[162]=rt):rt=t[162];let Ge;t[163]!==xe||t[164]!==W.breakdownTotal?(Ge=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:xe.map(dt=>dt.value<=0||W.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${dt.value/W.breakdownTotal*100}%`,backgroundColor:dt.color}},dt.key))}),t[163]=xe,t[164]=W.breakdownTotal,t[165]=Ge):Ge=t[165];let ct;t[166]!==xe||t[167]!==W.breakdownTotal?(ct=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:xe.map(dt=>{const Dt=W.breakdownTotal>0?dt.value/W.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:dt.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[dt.label," ",s.jsxs("span",{className:"tabular-nums",children:[Dt.toFixed(0),"%"]})]})]},dt.key)})}),t[166]=xe,t[167]=W.breakdownTotal,t[168]=ct):ct=t[168];let Pe;t[169]!==Ge||t[170]!==ct?(Pe=s.jsxs("div",{className:"mb-6",children:[Ge,ct]}),t[169]=Ge,t[170]=ct,t[171]=Pe):Pe=t[171];let Me;t[172]!==e?(Me=e("contextSidebar.section.rawMessages"),t[172]=e,t[173]=Me):Me=t[173];let Ue;t[174]!==Me?(Ue=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Me}),t[174]=Me,t[175]=Ue):Ue=t[175];let He;if(t[176]!==d||t[177]!==l||t[178]!==b||t[179]!==a||t[180]!==e){let dt;t[182]!==d||t[183]!==l||t[184]!==a||t[185]!==e?(dt=Dt=>{const Qt=Ao(Dt.info).role,Ft=l[Dt.info.id]===!0,qt=d===Dt.info.id,gt=Dt.info.time?.created??null,zt=Ft?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":Ft,onClick:()=>{c(es=>({...es,[Dt.info.id]:es[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:ak(Qt)}),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:rk(gt)})]})}),Ft&&s.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:s.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[s.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:s.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:es=>{es.stopPropagation(),C(Dt.info.id,zt)},"aria-label":e(qt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(qt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:qt?s.jsx(A,{name:"check",className:"size-3.5"}):s.jsx(A,{name:"file-copy",className:"size-3.5"})})}),s.jsx(sb,{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:zt})]})})]},Dt.info.id)},t[182]=d,t[183]=l,t[184]=a,t[185]=e,t[186]=dt):dt=t[186],He=[...b].reverse().map(dt),t[176]=d,t[177]=l,t[178]=b,t[179]=a,t[180]=e,t[181]=He}else He=t[181];let lt;t[187]!==He?(lt=s.jsx("div",{className:"mt-2.5 space-y-1",children:He}),t[187]=He,t[188]=lt):lt=t[188];let vt;t[189]!==Ue||t[190]!==lt?(vt=s.jsxs("div",{children:[Ue,lt]}),t[189]=Ue,t[190]=lt,t[191]=vt):vt=t[191];let ft;return t[192]!==we||t[193]!==ye||t[194]!==qe||t[195]!==rt||t[196]!==Pe||t[197]!==vt?(ft=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:[we,ye,qe,rt,Pe,vt]})}),t[192]=we,t[193]=ye,t[194]=qe,t[195]=rt,t[196]=Pe,t[197]=vt,t[198]=ft):ft=t[198],ft};function lk(t){return t.currentSessionId}function ck(t){return t.providers}function dk(t){return Object.keys(t).length>0?{}:t}function uk(t){return Ao(t.info).role==="assistant"}function mk(t){return Ao(t.info).isUser}function pk(t,e){const n=Fa(e.info.cost);return t+n}function fk(t){return Ao(t.info).isUser&&typeof t.info.system=="string"}function hk(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 gk(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:fi(t.value)})]},t.label)}const Rg=380,xk=1400,Fg=600,bk=24,Dp=200,yk=(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",Rd=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 l=r.text.trim(),c=Object.entries(r.attributes).map(([b,g])=>`${b}="${g}"`).join(" "),d=r.computedStyle,f=r.bounds,m=r.center,u=i.replace(/[.:]+$/g,""),p=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}`,l?`Text: ${l}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,p?`- Ancestry: ${p}`:null,c?`- Attributes: ${c}`:null,`- Bounds: x=${Math.round(f.x)}, y=${Math.round(f.y)}, width=${Math.round(f.width)}, height=${Math.round(f.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(`
|
|
63
|
+
`)},vk=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((y,x)=>{i.onload=()=>y(),i.onerror=()=>x(new Error("Failed to load desktop preview screenshot")),i.src=`data:${a.mime};base64,${a.base64}`});const l=Math.max(1,i.naturalWidth||a.width||Math.floor(r.width)),c=Math.max(1,i.naturalHeight||a.height||Math.floor(r.height)),f=Math.min(1,1200/l),m=document.createElement("canvas");m.width=Math.floor(l*f),m.height=Math.floor(c*f);const u=m.getContext("2d");if(!u)return null;u.scale(f,f),u.drawImage(i,0,0,l,c);const p=l/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*p),u.fillRect(e.bounds.x*p,e.bounds.y*b,e.bounds.width*p,e.bounds.height*b),u.strokeRect(e.bounds.x*p,e.bounds.y*b,e.bounds.width*p,e.bounds.height*b);const g=await new Promise(y=>m.toBlob(y,"image/jpeg",.82));return g?new File([g],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(r){return console.warn("[preview] failed to capture annotation screenshot:",r),null}return null},wk=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},Og=t=>Number.isFinite(t)?Math.min(xk,Math.max(Rg,Math.round(t))):Fg,jk=t=>{const e=t?.parentElement?.clientWidth;return!e||e<=0?null:e},Wc=(t,e)=>{const n=Og(t),r=jk(e);return r===null?n:Math.min(n,Math.max(1,r))},Nk=(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},Sk=(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"),kk=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},Ck=(t,e)=>{if(t.label)return t.label;if(t.mode==="file")return kk(t.targetPath)||e("contextPanel.mode.files");if(t.mode==="preview"){const n=t.targetPath;if(n)try{const r=new URL(n);return r.host||r.hostname||e("contextPanel.mode.preview")}catch{}return e("contextPanel.mode.preview")}return t.mode==="diff"?t.stagedDiff?e("contextPanel.mode.stagedDiff"):e("contextPanel.mode.workingDiff"):Sk(t.mode,e)},Ik=t=>{if(t.mode==="file")return t.targetPath?s.jsx(Er,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(A,{name:"arrow-left-right",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(A,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(A,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(A,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="preview")return s.jsx(A,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return s.jsx(A,{name:"global",className:"h-3.5 w-3.5"})},Pk=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,Ak=`new Promise((resolve) => {
|
|
64
|
+
const existing = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
65
|
+
if (existing) existing.remove();
|
|
66
|
+
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
67
|
+
try { window.__openchamberDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
|
|
68
|
+
}
|
|
69
|
+
const overlay = document.createElement('div');
|
|
70
|
+
overlay.id = '__openchamber_desktop_browser_overlay';
|
|
71
|
+
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;';
|
|
72
|
+
document.documentElement.appendChild(overlay);
|
|
73
|
+
const cssEscape = (value) => {
|
|
74
|
+
try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
|
|
75
|
+
};
|
|
76
|
+
const selectorPart = (element) => {
|
|
77
|
+
const tag = element.tagName.toLowerCase();
|
|
78
|
+
if (element.id) return tag + '#' + cssEscape(element.id);
|
|
79
|
+
const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
|
|
80
|
+
return tag + className;
|
|
81
|
+
};
|
|
82
|
+
const metadata = (element) => {
|
|
83
|
+
const rect = element.getBoundingClientRect();
|
|
84
|
+
const style = getComputedStyle(element);
|
|
85
|
+
const ancestry = [];
|
|
86
|
+
let current = element;
|
|
87
|
+
while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
|
|
88
|
+
ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
|
|
89
|
+
current = current.parentElement;
|
|
90
|
+
}
|
|
91
|
+
const attrs = {};
|
|
92
|
+
for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
|
|
93
|
+
const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
|
|
94
|
+
return {
|
|
95
|
+
frame: 'top',
|
|
96
|
+
tag: element.tagName.toLowerCase(),
|
|
97
|
+
text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
|
|
98
|
+
selector: element.id ? '#' + cssEscape(element.id) : path,
|
|
99
|
+
path,
|
|
100
|
+
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
101
|
+
center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
|
|
102
|
+
attributes: attrs,
|
|
103
|
+
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 },
|
|
104
|
+
ancestry,
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
const move = (event) => {
|
|
108
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
109
|
+
if (!element || element === overlay || element === document.documentElement || element === document.body) return;
|
|
110
|
+
const rect = element.getBoundingClientRect();
|
|
111
|
+
overlay.style.display = 'block';
|
|
112
|
+
overlay.style.left = rect.left + 'px';
|
|
113
|
+
overlay.style.top = rect.top + 'px';
|
|
114
|
+
overlay.style.width = rect.width + 'px';
|
|
115
|
+
overlay.style.height = rect.height + 'px';
|
|
116
|
+
};
|
|
117
|
+
const cleanup = () => {
|
|
118
|
+
window.removeEventListener('mousemove', move, true);
|
|
119
|
+
window.removeEventListener('click', click, true);
|
|
120
|
+
window.removeEventListener('keydown', keydown, true);
|
|
121
|
+
if (window.__openchamberDesktopBrowserCancelInspect === cancel) {
|
|
122
|
+
delete window.__openchamberDesktopBrowserCancelInspect;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const cancel = () => {
|
|
126
|
+
cleanup();
|
|
127
|
+
overlay.remove();
|
|
128
|
+
resolve(null);
|
|
129
|
+
};
|
|
130
|
+
const click = (event) => {
|
|
131
|
+
event.preventDefault();
|
|
132
|
+
event.stopPropagation();
|
|
133
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
134
|
+
const result = element ? metadata(element) : null;
|
|
135
|
+
cleanup();
|
|
136
|
+
overlay.remove();
|
|
137
|
+
resolve(result);
|
|
138
|
+
};
|
|
139
|
+
const keydown = (event) => {
|
|
140
|
+
if (event.key !== 'Escape') return;
|
|
141
|
+
cancel();
|
|
142
|
+
};
|
|
143
|
+
window.__openchamberDesktopBrowserCancelInspect = cancel;
|
|
144
|
+
window.addEventListener('mousemove', move, true);
|
|
145
|
+
window.addEventListener('click', click, true);
|
|
146
|
+
window.addEventListener('keydown', keydown, true);
|
|
147
|
+
});`,Kc=`(() => {
|
|
148
|
+
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
149
|
+
window.__openchamberDesktopBrowserCancelInspect();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
153
|
+
if (overlay) overlay.remove();
|
|
154
|
+
})()`,Hc=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"}},Dk=async(t,e,n,r,a,i)=>{if(!t)return null;try{const l=new Image;await new Promise((x,h)=>{l.onload=()=>x(),l.onerror=()=>h(new Error("Failed to load desktop browser screenshot")),l.src=`data:image/jpeg;base64,${t}`});const c=Math.max(1,l.naturalWidth||e),d=Math.max(1,l.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 p=u.getContext("2d");if(!p)return null;p.scale(m,m),p.drawImage(l,0,0,c,d);const b=c/Math.max(1,r||c),g=d/Math.max(1,a||d);p.fillStyle="rgba(37, 99, 235, 0.14)",p.strokeStyle="rgb(37, 99, 235)",p.lineWidth=Math.max(2,2*b),p.fillRect(i.bounds.x*b,i.bounds.y*g,i.bounds.width*b,i.bounds.height*g),p.strokeRect(i.bounds.x*b,i.bounds.y*g,i.bounds.width*b,i.bounds.height*g);const y=await new Promise(x=>u.toBlob(x,"image/jpeg",.82));return y?new File([y],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},Tk=(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()},Ek=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,$a=new Map,Mk=3e4,Rk=t=>{const e=$a.get(t);return e?e.expiresAt-Date.now()<=Mk?($a.delete(t),null):e:null},Fk=({rawUrl:t,onNavigate:e})=>{const{t:n}=pt(),{currentTheme:r}=Sr(),[a,i]=o.useReducer(se=>se+1,0),[l,c]=o.useReducer(se=>se+1,0),[d,f]=o.useState({status:"idle"}),m=o.useRef(null),u=o.useRef(1),[p,b]=o.useState(!1),[g,y]=o.useState(!1),[x,h]=o.useState("all"),[j,v]=o.useState([]),[C,k]=o.useState(!1),[w,N]=o.useState(null),I=Lt(se=>se.currentSessionId),E=Lt(se=>se.newSessionDraft?.open),P=gi(se=>se.addDraft),T=qa(se=>se.addAttachedFile);let S=null;try{S=t?new URL(t):null}catch{S=null}const M=S?S.hostname==="localhost"||S.hostname==="127.0.0.1"||S.hostname==="::1"||S.hostname==="[::1]"||S.hostname==="0.0.0.0":!1,D=S?S.hostname==="0.0.0.0"?new URL(S.toString().replace("0.0.0.0","127.0.0.1")):S:null,F=D?D.toString():"",_=r.metadata.variant;o.useEffect(()=>{if(!F||!M){f({status:"idle"});return}const se=Rk(F);if(se){f({status:"ready",proxyBasePath:se.proxyBasePath,expiresAt:se.expiresAt});return}let ie=!1;return f({status:"loading"}),(async()=>{try{const ae=await fetch("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:F})});if(!ae.ok){$a.delete(F);const Y=await ae.json().catch(()=>({})),Se=typeof Y?.error=="string"?Y.error:`HTTP ${ae.status}`;ie||f({status:"error",message:Se});return}const xe=await ae.json(),Z=typeof xe.proxyBasePath=="string"?xe.proxyBasePath:"",me=typeof xe.expiresAt=="number"?xe.expiresAt:0;if(!Z){$a.delete(F),ie||f({status:"error",message:n("contextPanel.preview.proxyError")});return}$a.set(F,{proxyBasePath:Z,expiresAt:me}),ie||f({status:"ready",proxyBasePath:Z,expiresAt:me})}catch(ae){if($a.delete(F),!ie){const xe=ae instanceof Error?ae.message:String(ae);f({status:"error",message:xe})}}})(),()=>{ie=!0}},[M,l,n,F]);const V=D&&(D.protocol==="http:"||D.protocol==="https:")?D.toString():"",$=M&&d.status==="ready"&&D?(()=>{const se=D.pathname||"/",ie=new URLSearchParams(D.search);ie.set("ocPreview",String(a));const ae=ie.toString(),xe=D.hash||"";return`${d.proxyBasePath}${se}${ae?`?${ae}`:""}${xe}`})():"",O=M?$:V,B=O||V,G=M&&(d.status==="loading"||d.status==="idle"),R=M&&d.status==="error",H=o.useCallback(se=>{const ie=I??(E?"draft":null);if(!ie){K.error(n("contextPanel.preview.inspect.attachNoSession"));return}const ae=t||O||"",xe=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},Z=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let me=!1;try{const Y=m.current,Se=Y?await vk(Y,se):null;Se&&(await T(Se),me=!0)}catch{me=!1}P({sessionKey:ie,source:"preview-annotation",fileLabel:ae||"preview",startLine:1,endLine:1,code:Lg({pageUrl:ae,viewport:xe,devicePixelRatio:Z,target:se,screenshotAttached:me,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),K.success(n("contextPanel.preview.inspect.attached"))})()},[T,P,I,O,E,t,n]);o.useEffect(()=>{b(!1),v([]),y(!1),h("all"),k(!1),N(null),u.current=1},[O]),o.useEffect(()=>{const se=m.current?.contentWindow;!p||!se||se.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:C},window.location.origin)},[p,C]),o.useEffect(()=>{const se=m.current?.contentWindow;!p||!se||se.postMessage({source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:_},window.location.origin)},[p,_]),o.useEffect(()=>{if(!C||typeof window>"u")return;const se=ie=>{ie.key==="Escape"&&(ie.preventDefault(),ie.stopImmediatePropagation(),k(!1))};return window.addEventListener("keydown",se,!0),()=>window.removeEventListener("keydown",se,!0)},[C]),o.useEffect(()=>{if(!M||typeof window>"u")return;const se=xe=>{if(typeof xe=="string")return xe;if(xe==null)return"";try{return JSON.stringify(xe)}catch{return String(xe)}},ie=xe=>{const Z=u.current;u.current+=1,v(me=>{const Y=[...me,{...xe,id:Z}];return Y.length>Dp?Y.slice(Y.length-Dp):Y})},ae=xe=>{if(xe.source!==m.current?.contentWindow)return;const Z=xe.data;if(!(!Z||Z.source!=="openchamber-preview-bridge"||Z.version!==1)){if(Z.type==="ready"){b(!0);return}if(Z.type==="console"){const me=Z.level==="error"||Z.level==="warn"||Z.level==="info"||Z.level==="debug"?Z.level:"log",Y=Array.isArray(Z.args)?Z.args.map(se).filter(Boolean):[];ie({level:me,message:Y.join(" "),ts:typeof Z.ts=="number"?Z.ts:Date.now()});return}if(Z.type==="runtime-error"){const me=se(Z.filename),Y=typeof Z.line=="number"?Z.line:null,Se=typeof Z.column=="number"?Z.column:null,we=me?`${me}${Y!==null?`:${Y}${Se!==null?`:${Se}`:""}`:""}`:"",ke=se(Z.stack);ie({level:"runtime",message:se(Z.message)||n("contextPanel.preview.console.runtimeError"),details:[we,ke].filter(Boolean).join(`
|
|
155
|
+
`),ts:typeof Z.ts=="number"?Z.ts:Date.now()});return}if(Z.type==="resource-error"){const me=se(Z.tag)||"resource",Y=se(Z.url);ie({level:"resource",message:Y?`${me}: ${Y}`:me,details:se(Z.outerHTML),ts:typeof Z.ts=="number"?Z.ts:Date.now()});return}if(Z.type==="hover"){N(Rd(Z.target)?Z.target:null);return}if(Z.type==="select"&&Rd(Z.target)){N(Z.target),k(!1),H(Z.target);return}if(Z.type==="navigate-preview"){const me=typeof Z.url=="string"?Z.url:"",Y=Z.navigation==="external"?"external":"proxy";if(me&&Y==="external"){rr(me);return}me&&e(me)}}};return window.addEventListener("message",ae),()=>{window.removeEventListener("message",ae)}},[H,M,e,n]);const J=j.filter(se=>se.level==="error"||se.level==="runtime"||se.level==="resource").length,ne=j.filter(se=>yk(se,x)),ue=o.useCallback(()=>{const se=[`Preview URL: ${t||O||""}`,`Events: ${j.length}`,""].join(`
|
|
156
|
+
`),ie=j.map(ae=>{const xe=new Date(ae.ts).toISOString(),Z=ae.details?`
|
|
157
|
+
${ae.details}`:"";return`[${xe}] [${ae.level}] ${ae.message}${Z}`}).join(`
|
|
158
|
+
`);Ln(`${se}${ie}`).then(ae=>{ae.ok?K.success(n("contextPanel.preview.console.copied")):K.error(n("contextPanel.preview.console.copyFailed"))})},[j,O,t,n]),de=o.useCallback(()=>{const se=I??(E?"draft":null);if(!se){K.error(n("contextPanel.preview.console.attachNoSession"));return}const ie=[`Preview URL: ${t||O||""}`,`Events: ${j.length}`,""].join(`
|
|
159
|
+
`),ae=j.map(xe=>{const Z=new Date(xe.ts).toISOString(),me=xe.details?`
|
|
160
|
+
${xe.details}`:"";return`[${Z}] [${xe.level}] ${xe.message}${me}`}).join(`
|
|
161
|
+
`);P({sessionKey:se,source:"preview-console",fileLabel:t||O||"preview",startLine:1,endLine:Math.max(1,j.length),code:`${ie}${ae}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),K.success(n("contextPanel.preview.console.attached"))},[P,j,I,O,E,t,n]),[pe,W]=o.useState("unknown"),te=o.useRef(0),X=o.useRef(0),ee=15e3;o.useEffect(()=>{if(!$){W("unknown"),te.current=0,X.current=0;return}let se=!1;return te.current||(te.current=Date.now(),X.current=0),W("unknown"),(async()=>{const ae=await(async()=>{try{return await fetch($,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(se)return;if(!ae){W("unreachable");return}if(ae.status===403||ae.status===404){$a.delete(F),f({status:"loading"}),c();return}if(ae.status!==502){W("reachable");return}const xe=te.current||Date.now();if(Date.now()-xe<ee){W("starting"),X.current+=1;const me=X.current,Y=Math.min(2e3,250*Math.pow(2,Math.min(4,me)));setTimeout(()=>{se||i()},Y).unref?.();return}W("unreachable")})(),()=>{se=!0}},[$,a,F]);const fe=M&&d.status==="ready"&&(pe==="unknown"||pe==="starting"),be=M&&d.status==="ready"&&pe==="unreachable",Ne=o.useCallback(se=>{if(!M||d.status!=="ready"||typeof window>"u")return;const ie=se.currentTarget.contentWindow;if(ie)try{const ae=ie.location;if(ae.origin!==window.location.origin||ae.pathname.startsWith(d.proxyBasePath))return;const xe=`${d.proxyBasePath}${ae.pathname}${ae.search}${ae.hash}`;ie.location.replace(xe)}catch{}},[M,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:B||t,children:B||t||n("contextPanel.preview.empty")}),s.jsx(he,{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:!O,children:s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(he,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{V&&rr(V)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!V,children:s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"})}),M?s.jsx(he,{type:"button",size:"sm",variant:C?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>k(se=>!se),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!p,children:s.jsx(A,{name:"cursor",className:"h-3.5 w-3.5"})}):null,M?s.jsxs(he,{type:"button",size:"sm",variant:g?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>y(se=>!se),title:n(p?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),"aria-label":n(p?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),disabled:!p&&j.length===0,children:[s.jsx(A,{name:"terminal-box",className:"h-3.5 w-3.5"}),J>0?s.jsx("span",{className:"typography-micro text-status-error",children:J}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[fe?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")})]}):be?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(he,{type:"button",size:"sm",variant:"outline",onClick:()=>i(),children:n("contextPanel.preview.actions.retry")})]}):O&&(!M||pe==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:m,src:O,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:_},onLoad:Ne,sandbox:M?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${O}:${a}`),C&&w?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:w.bounds.x,top:w.bounds.y,width:w.bounds.width,height:w.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:[w.tag,w.text?` · ${w.text}`:""]})}):null]}):G?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):R?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")}),g?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(he,{type:"button",size:"xs",variant:"ghost",onClick:de,disabled:j.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(he,{type:"button",size:"xs",variant:"ghost",onClick:ue,disabled:j.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(he,{type:"button",size:"xs",variant:"ghost",onClick:()=>v([]),disabled:j.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(se=>s.jsx(he,{type:"button",size:"xs",variant:x===se?"secondary":"ghost",onClick:()=>h(se),children:n(se==="all"?"contextPanel.preview.console.filter.all":se==="errors"?"contextPanel.preview.console.filter.errors":se==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},se))}),s.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:j.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.empty")}):ne.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):ne.map(se=>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:ge("shrink-0 uppercase",se.level==="error"||se.level==="runtime"||se.level==="resource"?"text-status-error":se.level==="warn"?"text-status-warning":"text-muted-foreground"),children:se.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:se.message})]})},se.id))})]}):null]})]})},Lk=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=pt(),a=o.useRef(null),i=_e(E=>E.setContextPanelTabTargetPath),l=Hc(t),c=l!=="about:blank"?l:"",[d,f]=o.useState(c),[m,u]=o.useState(c),[p,b]=o.useState(!1),[g,y]=o.useState(!0),x=o.useRef(null),h=g,j=o.useCallback(E=>{!E||E==="about:blank"||!e||!n||i(e,n,E)},[e,n,i]),v=Lt(E=>E.currentSessionId),C=Lt(E=>E.newSessionDraft?.open),k=gi(E=>E.addDraft),w=qa(E=>E.addAttachedFile);o.useEffect(()=>{const E=a.current;if(!E)return;const P=()=>{try{const F=E.getURL();F&&F!=="about:blank"&&(u(F),f(F),j(F))}catch{}},T=F=>{const _=F.detail;typeof _?.url=="string"&&_.url&&(u(_.url),f(_.url),j(_.url))},S=()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>y(!0),200)},M=()=>{x.current&&clearTimeout(x.current),y(!1),P()},D=F=>{const _=F.detail;if(_?.disposition==="new-window"||_?.disposition==="foreground-tab"||_?.disposition==="background-tab"){F.preventDefault();const V=a.current;typeof V?.loadURL=="function"&&_.url&&V.loadURL(_.url)}};E.addEventListener("did-navigate",T),E.addEventListener("did-navigate-in-page",T),E.addEventListener("did-start-loading",S),E.addEventListener("did-stop-loading",M),E.addEventListener("new-window",D);try{E.isLoading()||(y(!1),P())}catch{}return()=>{x.current&&clearTimeout(x.current),E.removeEventListener("did-navigate",T),E.removeEventListener("did-navigate-in-page",T),E.removeEventListener("did-start-loading",S),E.removeEventListener("did-stop-loading",M),E.removeEventListener("new-window",D)}},[j]),o.useEffect(()=>{const E=setTimeout(()=>y(!1),3e4);return()=>clearTimeout(E)},[]),o.useEffect(()=>{if(!p)return;const E=P=>{if(P.key!=="Escape")return;P.preventDefault(),P.stopImmediatePropagation(),b(!1);const T=a.current;try{T?.executeJavaScript?.(Kc).catch(()=>{})}catch{}};return window.addEventListener("keydown",E,!0),()=>window.removeEventListener("keydown",E,!0)},[p]),o.useEffect(()=>{const E=a.current;return()=>{try{const P=E?.getURL?.();P&&P!=="about:blank"&&i(e,n,P)}catch{}try{E?.executeJavaScript?.(Kc).catch(()=>{})}catch{}}},[e,n,i]);const N=o.useCallback(E=>{const P=a.current;if(typeof P?.loadURL!="function")return;const T=Hc(E);try{P.loadURL(T)}catch{}},[]),I=o.useCallback(()=>{const E=a.current;if(E){if(p){b(!1);try{E.executeJavaScript?.(Kc).catch(()=>{})}catch{}return}b(!0),E.executeJavaScript?.(Ak,!0).then(async P=>{if(b(!1),!P||!Rd(P))return;const T=v??(C?"draft":null);if(!T){K.error(r("contextPanel.preview.inspect.attachNoSession"));return}const S=typeof E.getWebContentsId=="function"?E.getWebContentsId():null;if(S==null)return;const M=await xy("desktop_browser_capture_page",{webContentsId:S}),D=await E.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),F=Number.isFinite(D?.width)?D.width:M.width,_=Number.isFinite(D?.height)?D.height:M.height,V=await Dk(M.base64,M.width,M.height,F,_,P),$=!!V;V&&await w(V),k({sessionKey:T,source:"preview-annotation",fileLabel:m||"browser",startLine:1,endLine:1,code:Lg({pageUrl:m,viewport:{width:F,height:_},devicePixelRatio:window.devicePixelRatio||1,target:P,screenshotAttached:$,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),K.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>b(!1))}},[w,k,v,m,p,C,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(he,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.goBack?.()}catch{}},children:s.jsx(A,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(he,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.goForward?.()}catch{}},children:s.jsx(A,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(he,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.reload?.()}catch{}},children:s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:E=>{E.preventDefault(),N(d)},children:s.jsx("input",{value:d,onChange:E=>f(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(he,{type:"button",variant:p?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:I,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(A,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(he,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{rr(m)},children:s.jsx(A,{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:Hc(t),partition:"persist:openchamber-browser",style:{width:"100%",height:"100%",border:"none"}}),(!m||m==="about:blank")&&!g?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(ou,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")})]}):null,h?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},Ok=()=>{const{t}=pt(),e=la()??"",n=o.useMemo(()=>wk(e),[e]),r=_e(ie=>n?ie.contextPanelByDirectory[n]:void 0),a=_e(ie=>ie.closeContextPanel),i=_e(ie=>ie.closeContextPanelTab),l=_e(ie=>ie.toggleContextPanelExpanded),c=_e(ie=>ie.setContextPanelWidth),d=_e(ie=>ie.setActiveContextPanelTab),f=_e(ie=>ie.reorderContextPanelTabs),m=Bn(ie=>ie.setSelectedPath),u=_e(ie=>ie.openContextPreview),{themeMode:p,lightThemeId:b,darkThemeId:g,currentTheme:y}=Sr(),x=o.useMemo(()=>r?.tabs??[],[r?.tabs]),h=x.find(ie=>ie.id===r?.activeTabId)??x[x.length-1]??null,j=!!(r?.isOpen&&h),v=!!(j&&r?.expanded),C=Og(r?.width??Fg),[k,w]=o.useState(!1),[N,I]=o.useState(!1),E=o.useRef(0),P=o.useRef(C),T=o.useRef(null),S=o.useRef(null),M=o.useRef(null),D=o.useRef(new Map),F=o.useRef(!1),_=o.useRef(j),V=o.useRef(null),$=o.useCallback(()=>{I(!0),V.current!==null&&window.cancelAnimationFrame(V.current),V.current=window.requestAnimationFrame(()=>{V.current=null,I(!1)})},[]);o.useEffect(()=>()=>{V.current!==null&&window.cancelAnimationFrame(V.current)},[]),o.useLayoutEffect(()=>{const ie=_.current;if(_.current=j,!j){I(!1);return}ie||$()},[j,$]),o.useEffect(()=>{if(!j||F.current){F.current=j;return}const ie=window.requestAnimationFrame(()=>{M.current?.focus({preventScroll:!0})});return F.current=!0,()=>window.cancelAnimationFrame(ie)},[j]);const O=o.useCallback(ie=>{const ae=M.current;ae&&ae.style.setProperty("--oc-context-panel-width",`${Wc(ie,ae)}px`)},[]),B=o.useCallback(ie=>{if(!(!j||v||!n)){try{ie.currentTarget.setPointerCapture(ie.pointerId)}catch{}S.current=ie.pointerId,w(!0),E.current=ie.clientX,P.current=C,T.current=C,O(C),ie.preventDefault()}},[O,n,v,j,C]),G=o.useCallback(ie=>{if(!k||S.current!==ie.pointerId)return;const ae=E.current-ie.clientX,xe=Wc(P.current+ae,M.current);T.current!==xe&&(T.current=xe,O(xe))},[O,k]),R=o.useCallback(ie=>{if(S.current!==ie.pointerId||!n)return;try{ie.currentTarget.releasePointerCapture(ie.pointerId)}catch{}const ae=Wc(T.current??C,M.current);$(),O(ae),T.current=ae,c(n,ae),w(!1),S.current=null},[O,n,c,$,C]);o.useEffect(()=>{k||(T.current=null)},[k]);const H=o.useCallback(()=>{n&&a(n)},[a,n]),J=o.useCallback(()=>{n&&l(n)},[n,l]),ne=o.useCallback(ie=>{ie.key==="Escape"&&(ie.preventDefault(),ie.stopPropagation(),H())},[H]);o.useEffect(()=>{if(!(!n||!h)&&h.mode==="file"&&h.targetPath){m(n,h.targetPath);return}},[h,n,m]);const ue=h?.mode==="chat"?h.id:null,de=o.useCallback(()=>{if(typeof window>"u")return;const ie={themeMode:p,lightThemeId:b,darkThemeId:g,currentTheme:y};for(const ae of D.current.values()){const xe=ae.contentWindow;if(!xe)continue;const Z=xe.__openchamberApplyThemeSync;if(typeof Z=="function")try{Z(ie);continue}catch{}xe.postMessage({type:"openchamber:theme-sync",payload:ie},window.location.origin)}},[y,g,b,p]),pe=o.useCallback(()=>{if(!(typeof window>"u"))for(const[ie,ae]of D.current.entries()){const xe=ae.contentWindow;if(!xe)continue;const Z={visible:ue===ie},me=xe.__openchamberSetEmbeddedVisibility;if(typeof me=="function")try{me(Z);continue}catch{}xe.postMessage({type:"openchamber:embedded-visibility",payload:Z},window.location.origin)}},[ue]);o.useLayoutEffect(()=>{x.some(ae=>ae.mode==="chat")&&(de(),pe())},[g,b,pe,de,x,p]);const W=o.useMemo(()=>x.map(ie=>{const ae=Ck(ie,t),xe=Ek(ae,bk),Z=Nk(ie.targetPath,e);return{id:ie.id,label:xe,icon:Ik(ie),title:Z?`${ae}: ${Z}`:ae,closeLabel:t("contextPanel.tab.closeTabAria",{label:xe})}}),[e,t,x]),te=h?.mode==="diff"?s.jsx(Pg,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,hideFileSelector:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:h.stagedDiff?"staged":"working",targetFilePath:h.targetPath},h.id):h?.mode==="context"?s.jsx(ok,{}):h?.mode==="plan"?s.jsx(Mg,{targetPath:h.targetPath}):h?.mode==="preview"?s.jsx(Fk,{rawUrl:h.targetPath??"",onNavigate:ie=>u(e,ie)}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(A,{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")})]}),X=o.useMemo(()=>x.filter(ie=>ie.mode==="chat"),[x]),ee=o.useMemo(()=>x.filter(ie=>ie.mode==="browser"),[x]),fe=o.useMemo(()=>x.some(ie=>ie.mode==="file"),[x]),be=h?.mode==="file",Ne=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-transparent",children:[s.jsx(Fr,{items:W,activeId:h?.id??null,onSelect:ie=>{n&&d(n,ie)},onClose:ie=>{n&&i(n,ie)},onReorder:(ie,ae)=>{n&&f(n,ie,ae)},layoutMode:"scrollable",variant:"default"}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[s.jsx(he,{type:"button",variant:"ghost",size:"sm",onClick:J,className:"h-7 w-7 p-0",title:t(v?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(v?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:v?s.jsx(A,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(he,{type:"button",variant:"ghost",size:"sm",onClick:H,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]}),se=j?v?{"--oc-context-panel-width":"100%",width:"100%",minWidth:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",minWidth:`min(${Rg}px, 100%)`,maxWidth:"100%","--oc-context-panel-width":`${k?T.current??C:C}px`}:{"--oc-context-panel-width":`${k?T.current??C:C}px`,width:0,minWidth:0,maxWidth:0,opacity:0,overflow:"hidden",visibility:"hidden"};return s.jsxs("aside",{ref:M,"data-context-panel":"true",tabIndex:-1,inert:!j||void 0,className:ge("flex min-h-0 flex-col overflow-hidden bg-background",!v&&"border-l border-border/40",v?"absolute inset-0 z-20 min-w-0":"relative h-full flex-shrink-0",!j&&"pointer-events-none",k||!j||N?"transition-none":"transition-[width] duration-200 ease-in-out"),onKeyDownCapture:ne,style:se,children:[!v&&s.jsx("div",{className:ge("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",k&&"bg-[var(--interactive-border)]"),onPointerDown:B,onPointerMove:G,onPointerUp:R,onPointerCancel:R,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),Ne,s.jsxs("div",{className:ge("relative min-h-0 flex-1 overflow-hidden",k&&"pointer-events-none"),children:[fe?s.jsx("div",{className:ge("absolute inset-0",be?"block":"hidden"),children:s.jsx(Eg,{mode:"editor-only"})}):null,X.map(ie=>{const ae=Pk(ie.dedupeKey);if(!ae)return null;const xe=Tk(ae,n||null,ie.readOnly);return xe?s.jsx("iframe",{ref:Z=>{if(!Z){D.current.delete(ie.id);return}D.current.set(ie.id,Z)},src:xe,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:ae}),className:ge("absolute inset-0 h-full w-full border-0 bg-background",ue===ie.id?"block":"hidden"),onLoad:()=>{de(),pe()}},ie.id):null}),ee.map(ie=>s.jsx("div",{className:ge("absolute inset-0",h?.mode!=="browser"&&"hidden"),children:s.jsx(Lk,{initialUrl:ie.targetPath??"",directory:n,tabID:ie.id})},ie.id)),h?.mode!=="chat"&&!be&&h?.mode!=="browser"?te:null]})]})},ju=[{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:"plugins",title:"Plugins",group:"opencode",kind:"split",keywords:["plugin","plugins","extensions","addons","npm","opencode-wakatime"]},{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:"snippets",title:"Snippets",group:"general",kind:"split",keywords:["prompt","templates","multi-run","strategy","approach"]},{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}],$k={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function so(t){const e=t.trim().toLowerCase();return ju.find(n=>n.slug===e)??null}function Nu(t){const e=(t??"").trim().toLowerCase();if(!e)return"home";const n=$k[e];if(n)return n;const r=so(e);return r?r.slug:"home"}const $g=t=>t.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),Mo=t=>{const e=ot.c(39),{className:n}=t,{t:r}=pt(),a=Ss(_k),i=Ss(Bk),l=Ss(Vk),c=un();let d;e[0]!==a?(d=[...a].sort(zk),e[0]=a,e[1]=d):d=e[1];const f=d;let m;e:{if(f.length===0){m=null;break e}let D;e[2]!==i||e[3]!==f?(D=f.find(F=>F.id===i)??f[0],e[2]=i,e[3]=f,e[4]=D):D=e[4],m=D}const u=m;if(c||f.length===0)return null;let p;e[5]!==u||e[6]!==r?(p=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]=p):p=e[7];const b=p;let g;e[8]!==b?(g=$g(b),e[8]=b,e[9]=g):g=e[9];const y=g;let x;e[10]!==n?(x=ge(n),e[10]=n,e[11]=x):x=e[11];let h;e[12]!==r?(h=r("settings.shared.projectSelector.switchProjectAria"),e[12]=r,e[13]=h):h=e[13];let j;e[14]!==r?(j=r("settings.shared.projectSelector.switchProjectTitle"),e[14]=r,e[15]=j):j=e[15];let v,C;e[16]===Symbol.for("react.memo_cache_sentinel")?(v=ge("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"),C=s.jsx(A,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=v,e[17]=C):(v=e[16],C=e[17]);let k;e[18]!==y?(k=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:y}),e[18]=y,e[19]=k):k=e[19];let w;e[20]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=w):w=e[20];let N;e[21]!==k||e[22]!==h||e[23]!==j?(N=s.jsx(Is,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":h,title:j,className:v,children:[C,k,w]})}),e[21]=k,e[22]=h,e[23]=j,e[24]=N):N=e[24];const I=u?.id??"";let E;e[25]!==l?(E=D=>{D&&l(D)},e[25]=l,e[26]=E):E=e[26];let P;e[27]!==f?(P=f.map(Uk),e[27]=f,e[28]=P):P=e[28];let T;e[29]!==I||e[30]!==E||e[31]!==P?(T=s.jsx(Ps,{align:"start",className:"w-auto",children:s.jsx(Ml,{value:I,onValueChange:E,children:P})}),e[29]=I,e[30]=E,e[31]=P,e[32]=T):T=e[32];let S;e[33]!==N||e[34]!==T?(S=s.jsxs(As,{children:[N,T]}),e[33]=N,e[34]=T,e[35]=S):S=e[35];let M;return e[36]!==S||e[37]!==x?(M=s.jsx("div",{className:x,children:S}),e[36]=S,e[37]=x,e[38]=M):M=e[38],M};function _k(t){return t.projects}function Bk(t){return t.activeProjectId}function Vk(t){return t.setActiveProject}function zk(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function Uk(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,n=$g(e);return s.jsx(Rl,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},t.id)}function Wk(t,e){return`opencode:sidebar-group:${t}:${e}`}const Fd=t=>{const e=ot.c(33),{label:n,count:r,storageKey:a,defaultExpanded:i,children:l}=t,c=i===void 0?!0:i;let d;e[0]!==n||e[1]!==a?(d=Wk(a,n),e[0]=n,e[1]=a,e[2]=d):d=e[2];const f=d,m=o.useId();let u;e[3]!==c||e[4]!==f?(u=()=>{try{const T=localStorage.getItem(f);if(T!==null)return T==="true"}catch{}return c},e[3]=c,e[4]=f,e[5]=u):u=e[5];const[p,b]=Ve.useState(u);let g,y;e[6]!==p||e[7]!==f?(g=()=>{try{localStorage.setItem(f,String(p))}catch{}},y=[f,p],e[6]=p,e[7]=f,e[8]=g,e[9]=y):(g=e[8],y=e[9]),Ve.useEffect(g,y);let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=()=>b(Kk),e[10]=x):x=e[10];let h;e[11]===Symbol.for("react.memo_cache_sentinel")?(h=ge("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]=h):h=e[11];const j=!p&&"-rotate-90";let v;e[12]!==j?(v=ge("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",j),e[12]=j,e[13]=v):v=e[13];let C;e[14]!==v?(C=s.jsx(A,{name:"arrow-down-s",className:v}),e[14]=v,e[15]=C):C=e[15];let k;e[16]!==n?(k=s.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=k):k=e[17];let w;e[18]!==r?(w=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:r}),e[18]=r,e[19]=w):w=e[19];let N;e[20]!==m||e[21]!==p||e[22]!==C||e[23]!==k||e[24]!==w?(N=s.jsxs("button",{type:"button",onClick:x,"aria-expanded":p,"aria-controls":m,className:h,children:[C,k,w]}),e[20]=m,e[21]=p,e[22]=C,e[23]=k,e[24]=w,e[25]=N):N=e[25];const I=!p;let E;e[26]!==l||e[27]!==m||e[28]!==I?(E=s.jsx("div",{id:m,hidden:I,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:l}),e[26]=l,e[27]=m,e[28]=I,e[29]=E):E=e[29];let P;return e[30]!==N||e[31]!==E?(P=s.jsxs("div",{children:[N,E]}),e[30]=N,e[31]=E,e[32]=P):P=e[32],P};function Kk(t){return!t}const Hk=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},Gk=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())},Tp=t=>{const e=Gk(Hk(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 l=Object.keys(i);if(l.length===1&&l[0]==="*"){r[a]=i["*"];continue}r[a]=i}return Object.keys(r).length>0?r:void 0},qk=({onItemSelect:t})=>{const{t:e}=pt(),[n,r]=o.useState(null),[a,i]=o.useState(""),[l,c]=o.useState(null),[d,f]=o.useState(null),[m,u]=o.useState(!1),[p,b]=o.useState(null),{selectedAgentName:g,agents:y,setSelectedAgent:x,setAgentDraft:h,createAgent:j,deleteAgent:v,loadAgents:C}=ki(Qn(B=>({selectedAgentName:B.selectedAgentName,agents:B.agents,setSelectedAgent:B.setSelectedAgent,setAgentDraft:B.setAgentDraft,createAgent:B.createAgent,deleteAgent:B.deleteAgent,loadAgents:B.loadAgents})));o.useEffect(()=>{C()},[C]);const k="bg-background",w=()=>{const B="new-agent";let G=B,R=1;for(;y.some(H=>H.name===G);)G=`${B}-${R}`,R++;h({name:G,scope:"user"}),x(G),t?.()},N=async B=>{if(xi(B)){K.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}c(B),f("delete")},I=async B=>{xi(B)&&(c(B),f("reset"))},E=()=>{c(null),f(null)},P=async()=>{if(!l||!d)return;u(!0),await v(l.name)?(d==="delete"?K.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):K.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),E()):d==="delete"?K.error(e("settings.agents.sidebar.toast.deleteFailed")):K.error(e("settings.agents.sidebar.toast.resetFailed")),u(!1)},T=B=>{const G=B.name;let R=1,H=`${G}-copy`;for(;y.some(de=>de.name===H);)R++,H=`${G}-copy-${R}`;const J=B,ne=B.model?.providerID&&B.model?.modelID?`${B.model.providerID}/${B.model.modelID}`:null,ue=B;h({name:H,scope:J.scope||"user",description:B.description,model:ne,temperature:B.temperature,top_p:B.topP,prompt:B.prompt,mode:B.mode,permission:Tp(B.permission),disable:ue.disable}),x(H)},S=B=>{i(B.name),r(B)},M=async()=>{if(!n)return;const B=a.trim().replace(/\s+/g,"-");if(!B){K.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(B===n.name){r(null);return}if(y.some(J=>J.name===B)){K.error(e("settings.agents.sidebar.toast.agentExists"));return}const G=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,R=n;await j({name:B,description:n.description,model:G,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:Tp(n.permission),disable:R.disable,scope:R.scope})?await v(n.name)?(K.success(`Agent renamed to "${B}"`),x(B)):K.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):K.error(e("settings.agents.sidebar.toast.renameFailed")),r(null)},D=B=>{switch(B){case"primary":return s.jsx(A,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(A,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(A,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},F=y.filter(B=>!by(B)),_=F.filter(xi),V=F.filter(B=>!xi(B)),{groupedCustomAgents:$,ungroupedCustomAgents:O}=Ve.useMemo(()=>{const B={},G=[];for(const H of V){const J=H;J.group?(B[J.group]||(B[J.group]=[]),B[J.group].push(H)):G.push(H)}return{groupedCustomAgents:Object.keys(B).sort((H,J)=>H.localeCompare(J)).map(H=>({name:H,agents:B[H]})),ungroupedCustomAgents:G}},[V]);return s.jsxs("div",{className:ge("flex h-full flex-col",k),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:F.length})}),s.jsx(he,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:w,children:s.jsx(A,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:F.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(A,{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:[_.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")}),_.map(B=>s.jsx(Gc,{agent:B,isSelected:g===B.name,onSelect:()=>{x(B.name),t?.()},onReset:()=>I(B),onDuplicate:()=>T(B),getAgentModeIcon:D,isMenuOpen:p===B.name,onMenuOpenChange:G=>b(G?B.name:null)},B.name))]}),V.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")}),$.map(({name:B,agents:G})=>s.jsx(Fd,{label:B,count:G.length,storageKey:"agents",children:G.map(R=>s.jsx(Gc,{agent:R,isSelected:g===R.name,onSelect:()=>{x(R.name),t?.()},onRename:()=>S(R),onDelete:()=>N(R),onDuplicate:()=>T(R),getAgentModeIcon:D,isMenuOpen:p===R.name,onMenuOpenChange:H=>b(H?R.name:null)},R.name))},B)),O.map(B=>s.jsx(Gc,{agent:B,isSelected:g===B.name,onSelect:()=>{x(B.name),t?.()},onRename:()=>S(B),onDelete:()=>N(B),onDuplicate:()=>T(B),getAgentModeIcon:D,isMenuOpen:p===B.name,onMenuOpenChange:G=>b(G?B.name:null)},B.name))]})]})}),s.jsx(ls,{open:l!==null&&d!==null,onOpenChange:B=>{!B&&!m&&E()},children:s.jsxs(os,{className:"max-w-md",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(ys,{children:d==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(Rs,{children:[s.jsx(he,{size:"sm",variant:"ghost",onClick:E,disabled:m,children:e("settings.common.actions.cancel")}),s.jsx(he,{size:"sm",onClick:P,disabled:m,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(ls,{open:n!==null,onOpenChange:B=>!B&&r(null),children:s.jsxs(os,{children:[s.jsxs(ps,{children:[s.jsx(ds,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(ys,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),s.jsx($t,{value:a,onChange:B=>i(B.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:B=>{B.key==="Enter"&&M()}}),s.jsxs(Rs,{children:[s.jsx(he,{size:"sm",variant:"ghost",onClick:()=>r(null),children:e("settings.common.actions.cancel")}),s.jsx(he,{size:"sm",onClick:M,children:e("settings.common.actions.rename")})]})]})})]})},Gc=t=>{const e=ot.c(58),{agent:n,isSelected:r,onSelect:a,onDelete:i,onReset:l,onRename:c,onDuplicate:d,getAgentModeIcon:f,isMenuOpen:m,onMenuOpenChange:u}=t,{t:p}=pt(),b=n;let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=go(),e[0]=g):g=e[0];const y=g,x=r?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[1]!==x?(h=ge("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",x),e[1]=x,e[2]=h):h=e[2];let j;e[3]!==u?(j=y?void 0:G=>{G.preventDefault(),u(!0)},e[3]=u,e[4]=j):j=e[4];let v;e[5]!==n.name?(v=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=v):v=e[6];let C;e[7]!==n.mode||e[8]!==f?(C=f(n.mode),e[7]=n.mode,e[8]=f,e[9]=C):C=e[9];let k;e[10]!==n||e[11]!==b.scope||e[12]!==p?(k=(b.scope||xi(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:xi(n)?p("settings.agents.sidebar.badge.system"):b.scope}),e[10]=n,e[11]=b.scope,e[12]=p,e[13]=k):k=e[13];let w;e[14]!==v||e[15]!==C||e[16]!==k?(w=s.jsxs("div",{className:"flex items-center gap-1.5",children:[v,C,k]}),e[14]=v,e[15]=C,e[16]=k,e[17]=w):w=e[17];let N;e[18]!==n.description?(N=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[18]=n.description,e[19]=N):N=e[19];let I;e[20]!==a||e[21]!==w||e[22]!==N?(I=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:[w,N]}),e[20]=a,e[21]=w,e[22]=N,e[23]=I):I=e[23];let E;e[24]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(Is,{asChild:!0,children:s.jsx(he,{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(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[24]=E):E=e[24];let P;e[25]!==c||e[26]!==p?(P=c&&s.jsxs(Ot,{onClick:G=>{G.stopPropagation(),c()},children:[s.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}),e[25]=c,e[26]=p,e[27]=P):P=e[27];let T;e[28]!==d?(T=G=>{G.stopPropagation(),d()},e[28]=d,e[29]=T):T=e[29];let S;e[30]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(A,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[30]=S):S=e[30];let M;e[31]!==p?(M=p("settings.common.actions.duplicate"),e[31]=p,e[32]=M):M=e[32];let D;e[33]!==T||e[34]!==M?(D=s.jsxs(Ot,{onClick:T,children:[S,M]}),e[33]=T,e[34]=M,e[35]=D):D=e[35];let F;e[36]!==l||e[37]!==p?(F=l&&s.jsxs(Ot,{onClick:G=>{G.stopPropagation(),l()},children:[s.jsx(A,{name:"restart",className:"h-4 w-4 mr-px"}),p("settings.common.actions.reset")]}),e[36]=l,e[37]=p,e[38]=F):F=e[38];let _;e[39]!==i||e[40]!==p?(_=i&&s.jsxs(Ot,{onClick:G=>{G.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]}),e[39]=i,e[40]=p,e[41]=_):_=e[41];let V;e[42]!==P||e[43]!==D||e[44]!==F||e[45]!==_?(V=s.jsxs(Ps,{align:"end",className:"w-fit min-w-20",children:[P,D,F,_]}),e[42]=P,e[43]=D,e[44]=F,e[45]=_,e[46]=V):V=e[46];let $;e[47]!==m||e[48]!==u||e[49]!==V?($=s.jsxs(As,{open:m,onOpenChange:u,children:[E,V]}),e[47]=m,e[48]=u,e[49]=V,e[50]=$):$=e[50];let O;e[51]!==I||e[52]!==$?(O=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[I,$]}),e[51]=I,e[52]=$,e[53]=O):O=e[53];let B;return e[54]!==O||e[55]!==h||e[56]!==j?(B=s.jsx("div",{className:h,onContextMenu:j,children:O}),e[54]=O,e[55]=h,e[56]=j,e[57]=B):B=e[57],B};function Ep(t,e,n){return Math.min(n,Math.max(e,t))}function Jk(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 Mp(t,e){const n=Jk(e);return n<=0?t:Number(t.toFixed(n))}const Un=Ve.forwardRef((t,e)=>{const n=ot.c(125);let r,a,i,l,c,d,f,m,u,p,b,g,y;n[0]!==t?({value:y,onValueChange:f,min:u,max:p,step:b,className:r,containerClassName:a,onBlur:c,disabled:i,fallbackValue:l,onClear:d,emptyLabel:g,...m}=t,n[0]=t,n[1]=r,n[2]=a,n[3]=i,n[4]=l,n[5]=c,n[6]=d,n[7]=f,n[8]=m,n[9]=u,n[10]=p,n[11]=b,n[12]=g,n[13]=y):(r=n[1],a=n[2],i=n[3],l=n[4],c=n[5],d=n[6],f=n[7],m=n[8],u=n[9],p=n[10],b=n[11],g=n[12],y=n[13]);const x=u===void 0?-1/0:u,h=p===void 0?1/0:p,j=b===void 0?1:b,v=g===void 0?"—":g,{t:C}=pt();let k;n[14]!==y?(k=()=>y===void 0?"":String(y),n[14]=y,n[15]=k):k=n[15];const[w,N]=Ve.useState(k),{isMobile:I}=an(),E=Ve.useRef(!1),P=Ve.useRef(null);let T;n[16]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{if(typeof document>"u"||typeof window>"u")return;P.current?.();const Ce=ve=>{ve.preventDefault(),ve.stopPropagation(),ve.stopImmediatePropagation?.(),P.current?.()},Q=window.setTimeout(()=>{P.current?.()},700),ce=()=>{window.clearTimeout(Q),document.removeEventListener("click",Ce,!0),P.current=null};P.current=ce,document.addEventListener("click",Ce,!0)},n[16]=T):T=n[16];const S=T;let M,D;n[17]===Symbol.for("react.memo_cache_sentinel")?(M=()=>()=>{P.current?.()},D=[],n[17]=M,n[18]=D):(M=n[17],D=n[18]),Ve.useEffect(M,D);let F,_;n[19]!==y?(_=()=>{N(y===void 0?"":String(y))},F=[y],n[19]=y,n[20]=F,n[21]=_):(F=n[20],_=n[21]),Ve.useEffect(_,F);let V;e:{if(y!==void 0){V=y;break e}if(l!==void 0){V=l;break e}if(Number.isFinite(x)){V=x;break e}V=0}const $=V;let O;n[22]!==h||n[23]!==x||n[24]!==f||n[25]!==j?(O=Ce=>{const Q=Ep(Ce,x,h);f(Mp(Q,j))},n[22]=h,n[23]=x,n[24]=f,n[25]=j,n[26]=O):O=n[26];const B=O;let G;n[27]!==B||n[28]!==d?(G=Ce=>{const Q=Ce.target.value;if(N(Q),Q.trim()===""){d?.();return}const ce=Number(Q);Number.isFinite(ce)&&B(ce)},n[27]=B,n[28]=d,n[29]=G):G=n[29];const R=G;let H;n[30]!==w||n[31]!==h||n[32]!==x||n[33]!==c||n[34]!==d||n[35]!==f||n[36]!==j||n[37]!==y?(H=Ce=>{if(w.trim()===""){d||N(y===void 0?"":String(y)),c?.(Ce);return}const Q=Number(w);if(!Number.isFinite(Q))N(y===void 0?"":String(y));else{const ce=Ep(Q,x,h),ve=Mp(ce,j);ve!==y&&f(ve),N(String(ve))}c?.(Ce)},n[30]=w,n[31]=h,n[32]=x,n[33]=c,n[34]=d,n[35]=f,n[36]=j,n[37]=y,n[38]=H):H=n[38];const J=H,ne=!!(i||$>=h),ue=!!(i||$<=x);let de;n[39]!==$||n[40]!==B||n[41]!==ue||n[42]!==j?(de=()=>{ue||B($-j)},n[39]=$,n[40]=B,n[41]=ue,n[42]=j,n[43]=de):de=n[43];const pe=de;let W;n[44]!==$||n[45]!==B||n[46]!==ne||n[47]!==j?(W=()=>{ne||B($+j)},n[44]=$,n[45]=B,n[46]=ne,n[47]=j,n[48]=W):W=n[48];const te=W;let X;if(n[49]!==r||n[50]!==a||n[51]!==ue||n[52]!==w||n[53]!==v||n[54]!==pe||n[55]!==te||n[56]!==ne||n[57]!==I||n[58]!==C||n[59]!==y){X=Symbol.for("react.early_return_sentinel");e:{const Ce=ce=>ve=>{ve.preventDefault(),ve.stopPropagation(),E.current=!0,S(),ce()},Q=ce=>ve=>{if(E.current){E.current=!1,ve.preventDefault(),ve.stopPropagation();return}ce()};if(I){let ce;n[61]!==a?(ce=ge("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]=ce):ce=n[62];let ve;n[63]!==C?(ve=C("numberInput.actions.decreaseAria"),n[63]=C,n[64]=ve):ve=n[64];const le=Ce(pe),Ae=Q(pe),Te=!ue&&"active:bg-interactive-hover";let $e;n[65]!==Te?($e=ge("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",Te),n[65]=Te,n[66]=$e):$e=n[66];let ye;n[67]===Symbol.for("react.memo_cache_sentinel")?(ye=s.jsx(A,{name:"subtract",className:"block h-4 w-4"}),n[67]=ye):ye=n[67];const q=s.jsx("button",{type:"button","aria-label":ve,disabled:ue,onTouchStart:le,onClick:Ae,className:$e,children:ye});let L;n[68]!==r?(L=ge("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]=L):L=n[69];const U=y===void 0?v:w;let oe;n[70]!==L||n[71]!==U?(oe=s.jsx("div",{className:L,"aria-live":"polite",children:U}),n[70]=L,n[71]=U,n[72]=oe):oe=n[72];let Ee;n[73]!==C?(Ee=C("numberInput.actions.increaseAria"),n[73]=C,n[74]=Ee):Ee=n[74];const Oe=Ce(te),Ie=Q(te),z=!ne&&"active:bg-interactive-hover";let De;n[75]!==z?(De=ge("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",z),n[75]=z,n[76]=De):De=n[76];let Qe;n[77]===Symbol.for("react.memo_cache_sentinel")?(Qe=s.jsx(A,{name:"add",className:"block h-4 w-4"}),n[77]=Qe):Qe=n[77];const tt=s.jsx("button",{type:"button","aria-label":Ee,disabled:ne,onTouchStart:Oe,onClick:Ie,className:De,children:Qe});let et;n[78]!==ce||n[79]!==q||n[80]!==oe||n[81]!==tt?(et=s.jsxs("div",{className:ce,children:[q,oe,tt]}),n[78]=ce,n[79]=q,n[80]=oe,n[81]=tt,n[82]=et):et=n[82],X=et;break e}}n[49]=r,n[50]=a,n[51]=ue,n[52]=w,n[53]=v,n[54]=pe,n[55]=te,n[56]=ne,n[57]=I,n[58]=C,n[59]=y,n[60]=X}else X=n[60];if(X!==Symbol.for("react.early_return_sentinel"))return X;let ee;n[83]!==a?(ee=ge("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]=ee):ee=n[84];let fe;n[85]!==C?(fe=C("numberInput.actions.decreaseAria"),n[85]=C,n[86]=fe):fe=n[86];let be;n[87]!==$||n[88]!==B||n[89]!==j?(be=()=>B($-j),n[87]=$,n[88]=B,n[89]=j,n[90]=be):be=n[90];let Ne,se;n[91]===Symbol.for("react.memo_cache_sentinel")?(Ne=ge("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"),se=s.jsx(A,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=Ne,n[92]=se):(Ne=n[91],se=n[92]);let ie;n[93]!==ue||n[94]!==fe||n[95]!==be?(ie=s.jsx("button",{type:"button","aria-label":fe,disabled:ue,onClick:be,className:Ne,children:se}),n[93]=ue,n[94]=fe,n[95]=be,n[96]=ie):ie=n[96];const ae=m.inputMode??"numeric";let xe;n[97]!==r?(xe=ge("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]=xe):xe=n[98];let Z;n[99]!==i||n[100]!==w||n[101]!==J||n[102]!==R||n[103]!==m||n[104]!==e||n[105]!==ae||n[106]!==xe?(Z=s.jsx("input",{...m,ref:e,type:"text",inputMode:ae,value:w,onChange:R,onBlur:J,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:xe}),n[99]=i,n[100]=w,n[101]=J,n[102]=R,n[103]=m,n[104]=e,n[105]=ae,n[106]=xe,n[107]=Z):Z=n[107];let me;n[108]!==C?(me=C("numberInput.actions.increaseAria"),n[108]=C,n[109]=me):me=n[109];let Y;n[110]!==$||n[111]!==B||n[112]!==j?(Y=()=>B($+j),n[110]=$,n[111]=B,n[112]=j,n[113]=Y):Y=n[113];let Se,we;n[114]===Symbol.for("react.memo_cache_sentinel")?(Se=ge("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"),we=s.jsx(A,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=Se,n[115]=we):(Se=n[114],we=n[115]);let ke;n[116]!==ne||n[117]!==me||n[118]!==Y?(ke=s.jsx("button",{type:"button","aria-label":me,disabled:ne,onClick:Y,className:Se,children:we}),n[116]=ne,n[117]=me,n[118]=Y,n[119]=ke):ke=n[119];let Fe;return n[120]!==ee||n[121]!==ie||n[122]!==Z||n[123]!==ke?(Fe=s.jsxs("div",{className:ee,children:[ie,Z,ke]}),n[120]=ee,n[121]=ie,n[122]=Z,n[123]=ke,n[124]=Fe):Fe=n[124],Fe});Un.displayName="NumberInput";const Rp=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],vl=t=>t==="allow"||t==="ask"||t==="deny",_a=(t,e)=>`${t}::${e}`,Za=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&vl(n.action)&&e.set(_a(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},Jo=t=>{const e=new Map;for(const n of Za(t))e.set(_a(n.permission,n.pattern),n);return e},Fp=t=>[...t].sort((e,n)=>{const r=e.permission.localeCompare(n.permission);return r!==0?r:e.pattern.localeCompare(n.pattern)}),Yk=(t,e)=>{const n=Fp(Za(t)),r=Fp(Za(e));return n.length!==r.length?!1:n.every((a,i)=>{const l=r[i];return a.permission===l.permission&&a.pattern===l.pattern&&a.action===l.action})},Qk=t=>t.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",Xk=(t,e)=>Za(t).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),Zk=t=>{if(vl(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(vl(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))vl(i)&&e.push({permission:n,pattern:a,action:i})}return e},e3=(t,e)=>{const n=Za(e),r={};for(const i of n)(r[i.permission]||={})[i.pattern]=i.action;const a={"*":t};for(const[i,l]of Object.entries(r))if(i!=="*"){if(Object.keys(l).length===1&&l["*"]){a[i]=l["*"];continue}a[i]=l}return a},t3=()=>{const{t}=pt(),{isMobile:e}=an(),{selectedAgentName:n,getAgentByName:r,createAgent:a,updateAgent:i,agents:l,agentDraft:c,setAgentDraft:d}=ki(Qn(ce=>({selectedAgentName:ce.selectedAgentName,getAgentByName:ce.getAgentByName,createAgent:ce.createAgent,updateAgent:ce.updateAgent,agents:ce.agents,agentDraft:ce.agentDraft,setAgentDraft:ce.setAgentDraft}))),f=n?r(n):null,m=!!(c&&c.name===n&&!f),[u,p]=o.useState(""),[b,g]=o.useState("user"),[y,x]=o.useState(""),[h,j]=o.useState("subagent"),[v,C]=o.useState(""),[k,w]=o.useState(void 0),[N,I]=o.useState(void 0),[E,P]=o.useState(""),[T,S]=o.useState("allow"),[M,D]=o.useState([]),[F,_]=o.useState([]),[V,$]=o.useState(""),[O,B]=o.useState("*"),[G,R]=o.useState(!1),[H,J]=o.useState(!1),ne=o.useRef(null),ue=Ms(ce=>ce.currentDirectory??null),[de,pe]=o.useState([]),W=Dh(ce=>ce.permission);o.useEffect(()=>{let ce=!1;return(async()=>{const le=await rn.listToolIds({directory:ue});if(ce)return;const Ae=new Set(["write","patch","multiedit"]),Te=le.map($e=>typeof $e=="string"?$e.trim():"").filter(Boolean).filter($e=>$e!=="*").filter($e=>$e!=="invalid").filter($e=>!Ae.has($e));pe(Array.from(new Set(Te)).sort(($e,ye)=>$e.localeCompare(ye)))})(),()=>{ce=!0}},[ue]);const te=o.useMemo(()=>{const ce=new Set;for(const ve of l){const le=Za(Array.isArray(ve.permission)?ve.permission:[]);for(const Ae of le)Ae.permission&&Ae.permission!=="*"&&Ae.permission!=="invalid"&&ce.add(Ae.permission)}for(const ve of Object.values(W))for(const le of ve){const Ae=le.permission?.trim();Ae&&Ae!=="invalid"&&ce.add(Ae)}for(const ve of de)ce.add(ve);return Array.from(ce).sort((ve,le)=>ve.localeCompare(le))},[l,W,de]),X=o.useMemo(()=>Jo(M),[M]),ee=o.useMemo(()=>Jo(F),[F]),fe=o.useCallback(ce=>ee.get(_a(ce,"*"))?.action,[ee]),be=o.useCallback(ce=>F.filter(ve=>ve.permission===ce&&ve.pattern!=="*").sort((ve,le)=>ve.pattern.localeCompare(le.pattern)),[F]),Ne=o.useMemo(()=>{const ce=new Set;for(const ve of Rp)ce.add(ve);for(const ve of te)ce.add(ve);return Array.from(ce).sort((ve,le)=>ve.localeCompare(le))},[te]),se=o.useCallback(ce=>{const ve=ce==="*"?T:fe(ce)??T,le=be(ce),Ae=!1,Te=le.reduce((ye,q)=>(ye[q.action]=(ye[q.action]??0)+1,ye),{allow:0,ask:0,deny:0}),$e=["allow","ask","deny"].filter(ye=>Te[ye]>0).map(ye=>`${Te[ye]} ${ye}`).join(", ");return{defaultAction:ve,patternRulesCount:le.length,patternSummary:$e,hasDefaultHint:Ae}},[be,fe,T]),ie=o.useCallback(ce=>t(ce==="allow"?"settings.common.permission.allow":ce==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[t]),ae=o.useCallback(ce=>ce==="global"?t("settings.common.scope.global"):ie(ce),[ie,t]),xe=o.useMemo(()=>{const ce=new Set;for(const ve of Rp)ce.add(ve);for(const ve of te)ce.add(ve);return Array.from(ce).sort((ve,le)=>ve.localeCompare(le))},[te]),Z=o.useCallback((ce,ve,le)=>{_(Ae=>{const Te=Jo(Ae);return Te.set(_a(ce,ve),{permission:ce,pattern:ve,action:le}),Array.from(Te.values())})},[]),me=o.useCallback((ce,ve)=>{_(le=>{const Ae=Jo(le);return Ae.delete(_a(ce,ve)),Array.from(Ae.values())})},[]),Y=o.useCallback((ce,ve)=>{const le=X.get(_a(ce,ve));if(le){Z(ce,ve,le.action);return}me(ce,ve)},[X,me,Z]),Se=o.useCallback((ce,ve,le)=>{Z(ce,ve,le)},[Z]),we=o.useCallback(ce=>{S(ce),_(ve=>ve.filter(le=>!(le.pattern==="*"&&le.action===ce)))},[]),ke=o.useCallback(ce=>{const ve=V.trim();if(!ve){K.error(t("settings.agents.page.toast.permissionNameRequired"));return}const le=O.trim()||"*";if(ve==="*"&&le==="*"){we(ce),$(""),B("*");return}le==="*"&&ve!=="*"&&ce===T?me(ve,"*"):Z(ve,le,ce),$(""),B("*")},[T,V,O,me,we,t,Z]),Fe=o.useCallback(ce=>ce==="*"?t("settings.agents.page.permissions.defaultLabel"):ce==="webfetch"?"WebFetch":ce==="websearch"?"WebSearch":ce==="codesearch"?"CodeSearch":ce==="doom_loop"?"Doom Loop":ce==="external_directory"?"External Directory":ce==="todowrite"?"TodoWrite":ce==="todoread"?"TodoRead":ce.split(/[_-]+/g).filter(Boolean).map(ve=>ve.charAt(0).toUpperCase()+ve.slice(1)).join(" "),[t]);o.useEffect(()=>{$(""),B("*");const ce=ve=>{const le=Za(ve),Ae=Qk(le),Te=Xk(le,Ae);return S(Ae),D(Te),_(Te),{global:Ae,rules:Te}};if(m&&c){const ve=c.name||"",le=c.scope||"user",Ae=c.description||"",Te=c.mode||"subagent",$e=c.model||"",ye=c.temperature,q=c.top_p,L=c.prompt||"";p(ve),g(le),x(Ae),j(Te),C($e),w(ye),I(q),P(L);const U=Zk(c.permission),oe=ce(U);ne.current={draftName:ve,draftScope:le,description:Ae,mode:Te,model:$e,temperature:ye,topP:q,prompt:L,globalPermission:oe.global,permissionRules:oe.rules};return}if(f&&n===f.name){const ve=f.description||"",le=f.mode||"subagent",Ae=f.model?.providerID&&f.model?.modelID?`${f.model.providerID}/${f.model.modelID}`:"",Te=f.temperature,$e=f.topP,ye=f.prompt||"";x(ve),j(le),C(Ae),w(Te),I($e),P(ye);const q=ce(Array.isArray(f.permission)?f.permission:[]);ne.current={draftName:"",draftScope:"user",description:ve,mode:le,model:Ae,temperature:Te,topP:$e,prompt:ye,globalPermission:q.global,permissionRules:q.rules}}},[c,m,f,n]);const Ce=o.useMemo(()=>{const ce=ne.current;return ce?!!(m&&(u!==ce.draftName||b!==ce.draftScope)||y!==ce.description||h!==ce.mode||v!==ce.model||k!==ce.temperature||N!==ce.topP||E!==ce.prompt||T!==ce.globalPermission||!Yk(F,ce.permissionRules)):!1},[y,u,b,T,m,h,v,F,E,k,N]),Q=async()=>{const ce=m?u.trim().replace(/\s+/g,"-"):n?.trim();if(!ce){K.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&l.some(ve=>ve.name===ce)){K.error(t("settings.agents.sidebar.toast.agentExists"));return}J(!0);try{const ve=v.trim(),le=e3(T,F),Ae={name:ce,description:y.trim()||void 0,mode:h,model:ve===""?null:ve,temperature:k,top_p:N,prompt:E.trim()||void 0,permission:le,scope:m?b:void 0};let Te;m?(Te=await a(Ae),Te&&d(null)):Te=await i(ce,Ae),Te?K.success(t(m?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):K.error(t(m?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(ve){console.error("Error saving agent:",ve);const le=ve instanceof Error&&ve.message?ve.message:t("settings.agents.page.toast.saveUnexpectedError");K.error(le)}finally{J(!1)}};return n?s.jsx(vs,{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($t,{value:u,onChange:ce=>p(ce.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(ns,{value:b,onValueChange:ce=>g(ce),children:[s.jsx(rs,{className:"w-fit min-w-[100px]",children:s.jsx(ms,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(as,{align:"end",children:[s.jsx(Rt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Rt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{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(ln,{value:y,onChange:ce=>x(ce.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(A,{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(he,{variant:"chip",size:"xs","aria-pressed":h==="primary",onClick:()=>j("primary"),className:"!font-normal",children:t("settings.agents.page.mode.primary")}),s.jsx(he,{variant:"chip",size:"xs","aria-pressed":h==="subagent",onClick:()=>j("subagent"),className:"!font-normal",children:t("settings.agents.page.mode.subagent")}),s.jsx(he,{variant:"chip",size:"xs","aria-pressed":h==="all",onClick:()=>j("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(Eo,{providerId:Di(v)?.providerId??"",modelId:Di(v)?.modelId??"",onChange:(ce,ve)=>{C(ce&&ve?`${ce}/${ve}`:"")}})})]}),s.jsxs("div",{className:ge("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:ge("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(A,{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:ge("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(Un,{value:k,fallbackValue:.7,onValueChange:w,onClear:()=>w(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),k!==void 0&&s.jsx(he,{size:"sm",type:"button",variant:"ghost",onClick:()=>w(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(A,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:ge("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:ge("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(A,{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:ge("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(Un,{value:N,fallbackValue:.9,onValueChange:I,onClear:()=>I(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),N!==void 0&&s.jsx(he,{size:"sm",type:"button",variant:"ghost",onClick:()=>I(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(A,{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(ln,{value:E,onChange:ce=>P(ce.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(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>R(ce=>!ce),children:t(G?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),G?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(ns,{value:T,onValueChange:ce=>we(ce),children:[s.jsx(rs,{className:"w-[100px]",children:s.jsx(ms,{children:ie(T)})}),s.jsxs(as,{children:[s.jsx(Rt,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Rt,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Rt,{value:"deny",children:t("settings.common.permission.deny")})]})]})]}),s.jsx("div",{className:"space-y-4",children:Ne.filter(ce=>ce!=="*").map(ce=>{const ve=Fe(ce),{defaultAction:le,patternRulesCount:Ae}=se(ce),Te=fe(ce),$e=Te??"global",ye=be(ce),q=["allow","ask","deny"].filter(L=>L!==T);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:ve}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:ce})]}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:Ae>0?t("settings.agents.page.permissions.globalSummary",{summary:le}):le})]}),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:"*"}),Te&&s.jsx(he,{size:"sm",variant:"ghost",onClick:()=>Y(ce,"*"),className:"px-1.5 py-0 h-5",children:s.jsx(A,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(ns,{value:$e,onValueChange:L=>{if(L==="global"){me(ce,"*");return}Z(ce,"*",L)},children:[s.jsx(rs,{className:"w-[90px]",children:s.jsx(ms,{children:ae($e)})}),s.jsxs(as,{children:[s.jsx(Rt,{value:"global",children:t("settings.common.scope.global")}),q.map(L=>s.jsx(Rt,{value:L,className:"capitalize",children:ie(L)},L))]})]})]}),ye.map(L=>{const U=_a(L.permission,L.pattern),oe=X.get(U),Ee=!oe,Oe=!!(oe&&oe.action!==L.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:L.pattern}),Ee&&s.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:t("settings.common.badge.new")}),Oe&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:t("settings.common.badge.modified")}),(Ee||Oe)&&s.jsx(he,{size:"sm",variant:"ghost",onClick:()=>Ee?me(L.permission,L.pattern):Y(L.permission,L.pattern),className:"px-1.5 py-0 h-5",children:s.jsx(A,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(ns,{value:L.action,onValueChange:Ie=>Se(L.permission,L.pattern,Ie),children:[s.jsx(rs,{className:"w-[90px]",children:s.jsx(ms,{children:ie(L.action)})}),s.jsxs(as,{children:[s.jsx(Rt,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Rt,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Rt,{value:"deny",children:t("settings.common.permission.deny")})]})]})]},U)})]})]},ce)})}),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(ns,{value:V,onValueChange:$,children:[s.jsx(rs,{className:"w-full sm:w-[160px]",children:V?s.jsx("span",{className:"truncate",children:Fe(V)}):s.jsx("span",{className:"text-muted-foreground",children:t("settings.agents.page.permissions.permissionPlaceholder")})}),s.jsx(as,{children:xe.map(ce=>s.jsx(Rt,{value:ce,children:s.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:s.jsx("span",{children:Fe(ce)})})},ce))})]}),s.jsx($t,{value:O,onChange:ce=>B(ce.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(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ke("allow"),children:t("settings.common.permission.allow")}),s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ke("ask"),children:t("settings.common.permission.ask")}),s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ke("deny"),children:t("settings.common.permission.deny")})]})]})]})]}):s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:Ne.map((ce,ve)=>{const{defaultAction:le,patternRulesCount:Ae,patternSummary:Te,hasDefaultHint:$e}=se(ce),ye=Fe(ce),q=$e?`${le} (env blocked)`:le;return s.jsxs("div",{className:ge("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",ve>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:ye}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:ce})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[Ae>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:q})}):s.jsx("span",{className:ge("typography-micro capitalize px-1.5 py-0.5 rounded",q==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":q==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:q}),Ae>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:Te})})]})]},ce)})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(he,{onClick:Q,disabled:H||!Ce,size:"xs",className:"!font-normal",children:t(H?"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(A,{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")})]})})},s3="~/.config/opencode/AGENTS.md",_g=async(t,e)=>{const n=await t.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},n3=t=>t.length>0&&!t.endsWith(`
|
|
162
|
+
`)?`${t}
|
|
163
|
+
`:t,Yo={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},r3=(t,e)=>t==="custom"?e:vy(t),a3=t=>t==="custom"?"custom":Th(t)?t:"concise",Lp={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"},Op=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 _g(n,e))},i3=()=>{const{t}=pt(),[e,n]=o.useState(""),[r,a]=o.useState(Yo.responseStyleEnabled),[i,l]=o.useState(Yo.responseStylePreset),[c,d]=o.useState(Yo.responseStyleCustomInstructions),[f,m]=o.useState(!0),[u,p]=o.useState(!1),[b,g]=o.useState(""),y=o.useRef(null);o.useEffect(()=>{const v=new AbortController;return(async()=>{try{const[k,w]=await Promise.all([fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:v.signal}),fetch("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:v.signal})]);let N=Yo;if(k.ok){const I=await k.json();N={...N,responseStyleEnabled:I.responseStyleEnabled===!0,responseStylePreset:a3(I.responseStylePreset),responseStyleCustomInstructions:typeof I.responseStyleCustomInstructions=="string"?I.responseStyleCustomInstructions:""},typeof I.globalBehaviorPrompt=="string"&&(N={...N,prompt:I.globalBehaviorPrompt})}if(!N.prompt.trim()&&w.ok){const I=await w.json();typeof I.content=="string"&&(N={...N,prompt:I.content})}n(N.prompt),a(N.responseStyleEnabled),l(N.responseStylePreset),d(N.responseStyleCustomInstructions),g(N.prompt),y.current={enabled:N.responseStyleEnabled,preset:N.responseStylePreset,custom:N.responseStyleCustomInstructions}}catch(k){k.name!=="AbortError"&&console.warn("Failed to load behavior settings:",k)}finally{m(!1)}})(),()=>v.abort()},[]),o.useEffect(()=>{if(f)return;const v=y.current;if(v&&v.enabled===r&&v.preset===i&&v.custom===c)return;const C={enabled:r,preset:i,custom:c},k=setTimeout(async()=>{try{await Op({responseStyleEnabled:C.enabled,responseStylePreset:C.preset,responseStyleCustomInstructions:C.custom},t("settings.behavior.page.toast.saveFailed")),y.current=C}catch(w){const N=w instanceof Error?w.message:t("settings.behavior.page.toast.saveFailed");K.error(N)}},400);return()=>clearTimeout(k)},[r,i,c,f,t]);const x=r3(i,c),h=e!==b,j=async()=>{p(!0);try{const v=n3(e),C=await fetch("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:v})});if(!C.ok)throw new Error(await _g(C,t("settings.behavior.page.toast.saveFailed")));await Op({globalBehaviorPrompt:v},t("settings.behavior.page.toast.saveFailed")),n(v),g(v),K.success(t("settings.behavior.page.toast.saved"))}catch(v){console.error("Failed to save behavior:",v);const C=v instanceof Error?v.message:t("settings.behavior.page.toast.saveFailed");K.error(C)}finally{p(!1)}};return s.jsx(vs,{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(A,{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:s3})})]})})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsx(ln,{value:e,onChange:v=>n(v.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:f,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(he,{onClick:j,disabled:u||!h||f,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(A,{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:f,ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),t("settings.behavior.page.responseStyle.enable")]}),s.jsxs(ns,{value:i,onValueChange:v=>l(v),disabled:f||!r,children:[s.jsx(rs,{className:"w-full sm:w-56",size:"lg",children:s.jsx(ms,{children:v=>v==="custom"?t("settings.behavior.page.responseStyle.option.custom"):Th(v)?t(Lp[v]):null})}),s.jsxs(as,{children:[yy.map(v=>s.jsx(Rt,{value:v,children:t(Lp[v])},v)),s.jsx(Rt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]}),s.jsx(ln,{value:x,onChange:v=>d(v.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:f||!r||i!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},o3=t=>{const e=ot.c(169),{onItemSelect:n}=t,{t:r}=pt(),[a,i]=o.useState(null),[l,c]=o.useState(""),[d,f]=o.useState(null),[m,u]=o.useState(null),[p,b]=o.useState(!1),[g,y]=o.useState(null),{selectedCommandName:x,commands:h,setSelectedCommand:j,setCommandDraft:v,createCommand:C,deleteCommand:k,loadCommands:w}=lu(Qn(l3)),N=ya(c3),I=ya(d3);let E,P;e[0]!==w||e[1]!==I?(E=()=>{w(),I()},P=[w,I],e[0]=w,e[1]=I,e[2]=E,e[3]=P):(E=e[2],P=e[3]),o.useEffect(E,P);let T;e[4]!==N?(T=new Set(N.map(u3)),e[4]=N,e[5]=T):T=e[5];const S=T;let M;if(e[6]!==h||e[7]!==S){let Ge;e[9]!==S?(Ge=ct=>!S.has(ct.name),e[9]=S,e[10]=Ge):Ge=e[10],M=h.filter(Ge),e[6]=h,e[7]=S,e[8]=M}else M=e[8];const D=M;let F,_;e[11]!==x||e[12]!==j||e[13]!==S?(F=()=>{x&&S.has(x)&&j(null)},_=[x,j,S],e[11]=x,e[12]=j,e[13]=S,e[14]=F,e[15]=_):(F=e[14],_=e[15]),o.useEffect(F,_);let V;e[16]!==h||e[17]!==n||e[18]!==v||e[19]!==j?(V=()=>{let Ge="new-command",ct=1;for(;h.some(Pe=>Pe.name===Ge);)Ge=`new-command-${ct}`,ct++;v({name:Ge,scope:"user"}),j(Ge),n?.()},e[16]=h,e[17]=n,e[18]=v,e[19]=j,e[20]=V):V=e[20];const $=V;let O;e[21]!==r?(O=async Ge=>{if(yi(Ge)){K.error(r("settings.commands.sidebar.toast.builtInCannotDelete"));return}f(Ge),u("delete")},e[21]=r,e[22]=O):O=e[22];const B=O;let G;e[23]===Symbol.for("react.memo_cache_sentinel")?(G=async Ge=>{yi(Ge)&&(f(Ge),u("reset"))},e[23]=G):G=e[23];const R=G;let H;e[24]===Symbol.for("react.memo_cache_sentinel")?(H=()=>{f(null),u(null)},e[24]=H):H=e[24];const J=H;let ne;e[25]!==d||e[26]!==m||e[27]!==k||e[28]!==r?(ne=async()=>{if(!d||!m)return;b(!0),await k(d.name)?(m==="delete"?K.success(r("settings.commands.sidebar.toast.commandDeleted",{name:d.name})):K.success(r("settings.commands.sidebar.toast.commandReset",{name:d.name})),J()):m==="delete"?K.error(r("settings.commands.sidebar.toast.deleteFailed")):K.error(r("settings.commands.sidebar.toast.resetFailed")),b(!1)},e[25]=d,e[26]=m,e[27]=k,e[28]=r,e[29]=ne):ne=e[29];const ue=ne;let de;e[30]!==h||e[31]!==v||e[32]!==j?(de=Ge=>{const ct=Ge.name;let Pe=1,Me=`${ct}-copy`;for(;h.some(Ue=>Ue.name===Me);)Pe++,Me=`${ct}-copy-${Pe}`;v({name:Me,scope:Ge.scope||"user",description:Ge.description,template:Ge.template,agent:Ge.agent,model:Ge.model}),j(Me)},e[30]=h,e[31]=v,e[32]=j,e[33]=de):de=e[33];const pe=de;let W;e[34]===Symbol.for("react.memo_cache_sentinel")?(W=Ge=>{c(Ge.name),i(Ge)},e[34]=W):W=e[34];const te=W;let X;e[35]!==h||e[36]!==C||e[37]!==k||e[38]!==a||e[39]!==l||e[40]!==j||e[41]!==r?(X=async()=>{if(!a)return;const Ge=l.trim().replace(/\s+/g,"-");if(!Ge){K.error(r("settings.commands.sidebar.toast.commandNameRequired"));return}if(Ge===a.name){i(null);return}if(h.some(Pe=>Pe.name===Ge)){K.error(r("settings.commands.sidebar.toast.commandExists"));return}await C({name:Ge,description:a.description,template:a.template,agent:a.agent,model:a.model})?await k(a.name)?(K.success(`Command renamed to "${Ge}"`),j(Ge)):K.error(r("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):K.error(r("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=h,e[36]=C,e[37]=k,e[38]=a,e[39]=l,e[40]=j,e[41]=r,e[42]=X):X=e[42];const ee=X;let fe,be,Ne,se,ie,ae;if(e[43]!==D||e[44]!==$||e[45]!==B||e[46]!==pe||e[47]!==n||e[48]!==g||e[49]!==x||e[50]!==j||e[51]!==r){const Ge=D.filter(yi),ct=D.filter(m3);e[58]===Symbol.for("react.memo_cache_sentinel")?(ie=ge("flex h-full flex-col","bg-background"),e[58]=ie):ie=e[58];let Pe;e[59]!==r?(Pe=r("settings.commands.sidebar.title"),e[59]=r,e[60]=Pe):Pe=e[60];let Me;e[61]!==Pe?(Me=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:Pe}),e[61]=Pe,e[62]=Me):Me=e[62];let Ue;e[63]===Symbol.for("react.memo_cache_sentinel")?(Ue=s.jsx(Mo,{className:"mb-3"}),e[63]=Ue):Ue=e[63];let He;e[64]!==D.length||e[65]!==r?(He=r("settings.commands.sidebar.total",{count:D.length}),e[64]=D.length,e[65]=r,e[66]=He):He=e[66];let lt;e[67]!==He?(lt=s.jsx("span",{className:"typography-meta text-muted-foreground",children:He}),e[67]=He,e[68]=lt):lt=e[68];let vt;e[69]===Symbol.for("react.memo_cache_sentinel")?(vt=s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[69]=vt):vt=e[69];let ft;e[70]!==$?(ft=s.jsx(he,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:$,children:vt}),e[70]=$,e[71]=ft):ft=e[71];let dt;e[72]!==lt||e[73]!==ft?(dt=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[lt,ft]}),e[72]=lt,e[73]=ft,e[74]=dt):dt=e[74],e[75]!==Me||e[76]!==dt?(ae=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Me,Ue,dt]}),e[75]=Me,e[76]=dt,e[77]=ae):ae=e[77],fe=vs,be="flex-1 min-h-0",Ne="space-y-1 px-3 py-2",se=D.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(A,{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:[Ge.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")}),[...Ge].sort(p3).map(Dt=>s.jsx($p,{command:Dt,isSelected:x===Dt.name,onSelect:()=>{j(Dt.name),n?.()},onReset:()=>R(Dt),onDuplicate:()=>pe(Dt),isMenuOpen:g===Dt.name,onMenuOpenChange:Qt=>y(Qt?Dt.name:null)},Dt.name))]}),ct.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")}),[...ct].sort(f3).map(Dt=>s.jsx($p,{command:Dt,isSelected:x===Dt.name,onSelect:()=>{j(Dt.name),n?.()},onRename:()=>te(Dt),onDelete:()=>B(Dt),onDuplicate:()=>pe(Dt),isMenuOpen:g===Dt.name,onMenuOpenChange:Qt=>y(Qt?Dt.name:null)},Dt.name))]})]}),e[43]=D,e[44]=$,e[45]=B,e[46]=pe,e[47]=n,e[48]=g,e[49]=x,e[50]=j,e[51]=r,e[52]=fe,e[53]=be,e[54]=Ne,e[55]=se,e[56]=ie,e[57]=ae}else fe=e[52],be=e[53],Ne=e[54],se=e[55],ie=e[56],ae=e[57];let xe;e[78]!==fe||e[79]!==be||e[80]!==Ne||e[81]!==se?(xe=s.jsx(fe,{outerClassName:be,className:Ne,children:se}),e[78]=fe,e[79]=be,e[80]=Ne,e[81]=se,e[82]=xe):xe=e[82];const Z=d!==null&&m!==null;let me;e[83]!==p?(me=Ge=>{!Ge&&!p&&J()},e[83]=p,e[84]=me):me=e[84];let Y;e[85]!==m||e[86]!==r?(Y=r(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=r,e[87]=Y):Y=e[87];let Se;e[88]!==Y?(Se=s.jsx(ds,{children:Y}),e[88]=Y,e[89]=Se):Se=e[89];let we;e[90]!==d?.name||e[91]!==m||e[92]!==r?(we=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]=we):we=e[93];let ke;e[94]!==we?(ke=s.jsx(ys,{children:we}),e[94]=we,e[95]=ke):ke=e[95];let Fe;e[96]!==Se||e[97]!==ke?(Fe=s.jsxs(ps,{children:[Se,ke]}),e[96]=Se,e[97]=ke,e[98]=Fe):Fe=e[98];let Ce;e[99]!==r?(Ce=r("settings.common.actions.cancel"),e[99]=r,e[100]=Ce):Ce=e[100];let Q;e[101]!==p||e[102]!==Ce?(Q=s.jsx(he,{size:"sm",variant:"ghost",onClick:J,disabled:p,children:Ce}),e[101]=p,e[102]=Ce,e[103]=Q):Q=e[103];let ce;e[104]!==m||e[105]!==r?(ce=r(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=r,e[106]=ce):ce=e[106];let ve;e[107]!==ue||e[108]!==p||e[109]!==ce?(ve=s.jsx(he,{size:"sm",onClick:ue,disabled:p,children:ce}),e[107]=ue,e[108]=p,e[109]=ce,e[110]=ve):ve=e[110];let le;e[111]!==Q||e[112]!==ve?(le=s.jsxs(Rs,{children:[Q,ve]}),e[111]=Q,e[112]=ve,e[113]=le):le=e[113];let Ae;e[114]!==Fe||e[115]!==le?(Ae=s.jsxs(os,{className:"max-w-md",children:[Fe,le]}),e[114]=Fe,e[115]=le,e[116]=Ae):Ae=e[116];let Te;e[117]!==Z||e[118]!==me||e[119]!==Ae?(Te=s.jsx(ls,{open:Z,onOpenChange:me,children:Ae}),e[117]=Z,e[118]=me,e[119]=Ae,e[120]=Te):Te=e[120];const $e=a!==null;let ye;e[121]===Symbol.for("react.memo_cache_sentinel")?(ye=Ge=>!Ge&&i(null),e[121]=ye):ye=e[121];let q;e[122]!==r?(q=r("settings.commands.sidebar.renameDialog.title"),e[122]=r,e[123]=q):q=e[123];let L;e[124]!==q?(L=s.jsx(ds,{children:q}),e[124]=q,e[125]=L):L=e[125];const U=a?.name??"";let oe;e[126]!==r||e[127]!==U?(oe=r("settings.commands.sidebar.renameDialog.description",{name:U}),e[126]=r,e[127]=U,e[128]=oe):oe=e[128];let Ee;e[129]!==oe?(Ee=s.jsx(ys,{children:oe}),e[129]=oe,e[130]=Ee):Ee=e[130];let Oe;e[131]!==L||e[132]!==Ee?(Oe=s.jsxs(ps,{children:[L,Ee]}),e[131]=L,e[132]=Ee,e[133]=Oe):Oe=e[133];let Ie;e[134]===Symbol.for("react.memo_cache_sentinel")?(Ie=Ge=>c(Ge.target.value),e[134]=Ie):Ie=e[134];let z;e[135]!==r?(z=r("settings.commands.sidebar.renameDialog.placeholder"),e[135]=r,e[136]=z):z=e[136];let De;e[137]!==ee?(De=Ge=>{Ge.key==="Enter"&&ee()},e[137]=ee,e[138]=De):De=e[138];let Qe;e[139]!==l||e[140]!==z||e[141]!==De?(Qe=s.jsx($t,{value:l,onChange:Ie,placeholder:z,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:De}),e[139]=l,e[140]=z,e[141]=De,e[142]=Qe):Qe=e[142];let tt;e[143]===Symbol.for("react.memo_cache_sentinel")?(tt=()=>i(null),e[143]=tt):tt=e[143];let et;e[144]!==r?(et=r("settings.common.actions.cancel"),e[144]=r,e[145]=et):et=e[145];let We;e[146]!==et?(We=s.jsx(he,{size:"sm",variant:"ghost",onClick:tt,children:et}),e[146]=et,e[147]=We):We=e[147];let at;e[148]!==r?(at=r("settings.common.actions.rename"),e[148]=r,e[149]=at):at=e[149];let qe;e[150]!==ee||e[151]!==at?(qe=s.jsx(he,{size:"sm",onClick:ee,children:at}),e[150]=ee,e[151]=at,e[152]=qe):qe=e[152];let nt;e[153]!==We||e[154]!==qe?(nt=s.jsxs(Rs,{children:[We,qe]}),e[153]=We,e[154]=qe,e[155]=nt):nt=e[155];let Ze;e[156]!==Oe||e[157]!==Qe||e[158]!==nt?(Ze=s.jsxs(os,{children:[Oe,Qe,nt]}),e[156]=Oe,e[157]=Qe,e[158]=nt,e[159]=Ze):Ze=e[159];let ze;e[160]!==$e||e[161]!==Ze?(ze=s.jsx(ls,{open:$e,onOpenChange:ye,children:Ze}),e[160]=$e,e[161]=Ze,e[162]=ze):ze=e[162];let rt;return e[163]!==ie||e[164]!==ae||e[165]!==xe||e[166]!==Te||e[167]!==ze?(rt=s.jsxs("div",{className:ie,children:[ae,xe,Te,ze]}),e[163]=ie,e[164]=ae,e[165]=xe,e[166]=Te,e[167]=ze,e[168]=rt):rt=e[168],rt},$p=t=>{const e=ot.c(53),{command:n,isSelected:r,onSelect:a,onDelete:i,onReset:l,onRename:c,onDuplicate:d,isMenuOpen:f,onMenuOpenChange:m}=t,{t:u}=pt();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=go(),e[0]=p):p=e[0];const b=p,g=r?"bg-interactive-selection":"hover:bg-interactive-hover";let y;e[1]!==g?(y=ge("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",g),e[1]=g,e[2]=y):y=e[2];let x;e[3]!==m?(x=b?void 0:$=>{$.preventDefault(),m(!0)},e[3]=m,e[4]=x):x=e[4];let h;e[5]!==n.name?(h=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[5]=n.name,e[6]=h):h=e[6];let j;e[7]!==n||e[8]!==u?(j=(n.scope||yi(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:yi(n)?u("settings.agents.sidebar.badge.system"):n.scope}),e[7]=n,e[8]=u,e[9]=j):j=e[9];let v;e[10]!==h||e[11]!==j?(v=s.jsxs("div",{className:"flex items-center gap-2",children:[h,j]}),e[10]=h,e[11]=j,e[12]=v):v=e[12];let C;e[13]!==n.description?(C=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[13]=n.description,e[14]=C):C=e[14];let k;e[15]!==a||e[16]!==v||e[17]!==C?(k=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:[v,C]}),e[15]=a,e[16]=v,e[17]=C,e[18]=k):k=e[18];let w;e[19]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(Is,{asChild:!0,children:s.jsx(he,{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(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[19]=w):w=e[19];let N;e[20]!==c||e[21]!==u?(N=c&&s.jsxs(Ot,{onClick:$=>{$.stopPropagation(),c()},children:[s.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),e[20]=c,e[21]=u,e[22]=N):N=e[22];let I;e[23]!==d?(I=$=>{$.stopPropagation(),d()},e[23]=d,e[24]=I):I=e[24];let E;e[25]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(A,{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 T;e[28]!==I||e[29]!==P?(T=s.jsxs(Ot,{onClick:I,children:[E,P]}),e[28]=I,e[29]=P,e[30]=T):T=e[30];let S;e[31]!==l||e[32]!==u?(S=l&&s.jsxs(Ot,{onClick:$=>{$.stopPropagation(),l()},children:[s.jsx(A,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),e[31]=l,e[32]=u,e[33]=S):S=e[33];let M;e[34]!==i||e[35]!==u?(M=i&&s.jsxs(Ot,{onClick:$=>{$.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]}),e[34]=i,e[35]=u,e[36]=M):M=e[36];let D;e[37]!==N||e[38]!==T||e[39]!==S||e[40]!==M?(D=s.jsxs(Ps,{align:"end",className:"w-fit min-w-20",children:[N,T,S,M]}),e[37]=N,e[38]=T,e[39]=S,e[40]=M,e[41]=D):D=e[41];let F;e[42]!==f||e[43]!==m||e[44]!==D?(F=s.jsxs(As,{open:f,onOpenChange:m,children:[w,D]}),e[42]=f,e[43]=m,e[44]=D,e[45]=F):F=e[45];let _;e[46]!==F||e[47]!==k?(_=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[k,F]}),e[46]=F,e[47]=k,e[48]=_):_=e[48];let V;return e[49]!==_||e[50]!==y||e[51]!==x?(V=s.jsx("div",{className:y,onContextMenu:x,children:_}),e[49]=_,e[50]=y,e[51]=x,e[52]=V):V=e[52],V};function l3(t){return{selectedCommandName:t.selectedCommandName,commands:t.commands,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function c3(t){return t.skills}function d3(t){return t.loadSkills}function u3(t){return t.name}function m3(t){return!yi(t)}function p3(t,e){return t.name.localeCompare(e.name)}function f3(t,e){return t.name.localeCompare(e.name)}const h3=()=>{const{t}=pt(),{selectedCommandName:e,getCommandByName:n,createCommand:r,updateCommand:a,commands:i,commandDraft:l,setCommandDraft:c}=lu(Qn(T=>({selectedCommandName:T.selectedCommandName,getCommandByName:T.getCommandByName,createCommand:T.createCommand,updateCommand:T.updateCommand,commands:T.commands,commandDraft:T.commandDraft,setCommandDraft:T.setCommandDraft}))),d=e?n(e):null,f=!!(l&&l.name===e&&!d),[m,u]=o.useState(""),[p,b]=o.useState("user"),[g,y]=o.useState(""),[x,h]=o.useState(""),[j,v]=o.useState(""),[C,k]=o.useState(""),[w,N]=o.useState(!1),I=o.useRef(null);o.useEffect(()=>{if(f&&l){const T=l.name||"",S=l.scope||"user",M=l.description||"",D=l.agent||"",F=l.model||"",_=l.template||"";u(T),b(S),y(M),h(D),v(F),k(_),I.current={draftName:T,draftScope:S,description:M,agent:D,model:F,template:_}}else if(d){const T=d.description||"",S=d.agent||"",M=d.model||"",D=d.template||"";y(T),h(S),v(M),k(D),I.current={draftName:"",draftScope:"user",description:T,agent:S,model:M,template:D}}},[d,f,e,i,l]);const E=o.useMemo(()=>{const T=I.current;return T?!!(f&&(m!==T.draftName||p!==T.draftScope)||g!==T.description||x!==T.agent||j!==T.model||C!==T.template):!1},[x,g,m,p,f,j,C]),P=async()=>{const T=f?m.trim().replace(/\s+/g,"-"):e?.trim();if(!T){K.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!C.trim()){K.error(t("settings.commands.page.toast.templateRequired"));return}if(f&&i.some(S=>S.name===T)){K.error(t("settings.commands.sidebar.toast.commandExists"));return}N(!0);try{const S=x.trim(),M=j.trim(),D=C.trim(),F={name:T,description:g.trim()||void 0,agent:S===""?null:S,model:M===""?null:M,template:D,scope:f?p:void 0};let _;f?(_=await r(F),_&&c(null)):_=await a(T,F),_?K.success(t(f?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):K.error(t(f?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(S){console.error("Error saving command:",S),K.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{N(!1)}};return e?s.jsx(vs,{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:f?t("settings.commands.page.title.new"):`/${e}`}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t(f?"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:[f&&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($t,{value:m,onChange:T=>u(T.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(ns,{value:p,onValueChange:T=>b(T),children:[s.jsx(rs,{className:"w-fit min-w-[100px]",children:s.jsx(ms,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(as,{align:"end",children:[s.jsx(Rt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Rt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{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(ln,{value:g,onChange:T=>y(T.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(dc,{agentName:x,onChange:T=>h(T)})})]}),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(Eo,{providerId:Di(j)?.providerId??"",modelId:Di(j)?.modelId??"",onChange:(T,S)=>{v(T&&S?`${T}/${S}`:"")}})})]})]})]}),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(ln,{value:C,onChange:T=>k(T.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(he,{onClick:P,disabled:w||!E,size:"xs",className:"!font-normal",children:t(w?"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(A,{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")})]})})},_p=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},Bp=t=>{const e=ot.c(5),{tone:n,enabled:r}=t;if(!r){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=l):l=e[0],l}let a;e[1]!==n?(a=ge("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},g3=t=>{const e=ot.c(116),{onItemSelect:n}=t,{t:r}=pt(),{mcpServers:a,selectedMcpName:i,setSelectedMcp:l,setMcpDraft:c,loadMcpConfigs:d,deleteMcp:f}=wo(Qn(x3)),m=Ms(b3);let u;e[0]!==m?(u=q=>q.getStatusForDirectory(m??null),e[0]=m,e[1]=u):u=e[1];const p=kn(u),b=kn(y3),g=kn(v3),[y,x]=o.useState(null),[h,j]=o.useState(!1),[v,C]=o.useState(null),[k,w]=o.useState(!1);let N;e[2]!==a?(N=a.filter(w3),e[2]=a,e[3]=N):N=e[3];const I=N;let E;e[4]!==a?(E=a.filter(j3),e[4]=a,e[5]=E):E=e[5];const P=E;let T,S;e[6]!==d?(T=()=>{d()},S=[d],e[6]=d,e[7]=T,e[8]=S):(T=e[7],S=e[8]),o.useEffect(T,S);let M;e[9]!==m||e[10]!==g||e[11]!==k||e[12]!==b?(M=()=>{if(k)return;w(!0);const q=new Promise(N3);Promise.all([b({directory:m,silent:!0}),q]).then(()=>{const L=g(m);L&&K.error(L)}).finally(()=>{w(!1)})},e[9]=m,e[10]=g,e[11]=k,e[12]=b,e[13]=M):M=e[13];const D=M;let F;e[14]!==a||e[15]!==n||e[16]!==c||e[17]!==l?(F=()=>{let q="new-mcp-server",L=1;for(;a.some(oe=>oe.name===q);)q=`new-mcp-server-${L}`,L++;c({name:q,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),l(q),n?.()},e[14]=a,e[15]=n,e[16]=c,e[17]=l,e[18]=F):F=e[18];const _=F;let V;e[19]!==f||e[20]!==y||e[21]!==r?(V=async()=>{if(!y)return;j(!0);const q=await f(y.name);q.ok?q.reloadFailed?K.warning(q.message||`MCP server "${y.name}" deleted, but OpenCode reload failed`,{description:q.warning||r("settings.mcp.sidebar.toast.refreshListIfStale")}):K.success(q.message||r("settings.mcp.sidebar.toast.serverDeleted",{name:y.name})):K.error(r("settings.mcp.sidebar.toast.deleteFailed")),x(null),j(!1)},e[19]=f,e[20]=y,e[21]=r,e[22]=V):V=e[22];const $=V;let O;e[23]===Symbol.for("react.memo_cache_sentinel")?(O=ge("flex h-full flex-col","bg-background"),e[23]=O):O=e[23];let B;e[24]!==r?(B=r("settings.mcp.sidebar.title"),e[24]=r,e[25]=B):B=e[25];let G;e[26]!==B?(G=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:B}),e[26]=B,e[27]=G):G=e[27];let R;e[28]!==r?(R=r("settings.mcp.sidebar.actions.refreshStatusAria"),e[28]=r,e[29]=R):R=e[29];let H;e[30]!==r?(H=r("settings.mcp.sidebar.actions.refreshStatusTitle"),e[30]=r,e[31]=H):H=e[31];const J=k&&"animate-spin";let ne;e[32]!==J?(ne=ge("h-4 w-4",J),e[32]=J,e[33]=ne):ne=e[33];let ue;e[34]!==ne?(ue=s.jsx(A,{name:"refresh",className:ne}),e[34]=ne,e[35]=ue):ue=e[35];let de;e[36]!==D||e[37]!==k||e[38]!==R||e[39]!==H||e[40]!==ue?(de=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:k,onClick:D,"aria-label":R,title:H,children:ue}),e[36]=D,e[37]=k,e[38]=R,e[39]=H,e[40]=ue,e[41]=de):de=e[41];let pe;e[42]!==G||e[43]!==de?(pe=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[G,de]}),e[42]=G,e[43]=de,e[44]=pe):pe=e[44];let W;e[45]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx(Mo,{className:"mb-3"}),e[45]=W):W=e[45];let te;e[46]!==a.length||e[47]!==r?(te=r("settings.mcp.sidebar.total",{count:a.length}),e[46]=a.length,e[47]=r,e[48]=te):te=e[48];let X;e[49]!==te?(X=s.jsx("span",{className:"typography-meta text-muted-foreground",children:te}),e[49]=te,e[50]=X):X=e[50];let ee;e[51]!==r?(ee=r("settings.mcp.sidebar.actions.addServerTitle"),e[51]=r,e[52]=ee):ee=e[52];let fe;e[53]===Symbol.for("react.memo_cache_sentinel")?(fe=s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[53]=fe):fe=e[53];let be;e[54]!==_||e[55]!==ee?(be=s.jsx(he,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:_,title:ee,children:fe}),e[54]=_,e[55]=ee,e[56]=be):be=e[56];let Ne;e[57]!==X||e[58]!==be?(Ne=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[X,be]}),e[57]=X,e[58]=be,e[59]=Ne):Ne=e[59];let se;e[60]!==pe||e[61]!==Ne?(se=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[pe,W,Ne]}),e[60]=pe,e[61]=Ne,e[62]=se):se=e[62];let ie;e[63]!==a.length||e[64]!==p||e[65]!==n||e[66]!==v||e[67]!==I||e[68]!==i||e[69]!==c||e[70]!==l||e[71]!==r||e[72]!==P?(ie=s.jsx(vs,{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(A,{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:[I.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")}),I.map(q=>{const L=p[q.name],U=_p(L?.status),oe=i===q.name,Ee=go();return s.jsxs("div",{className:ge("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",oe?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Ee?void 0:Oe=>{Oe.preventDefault(),C(q.name)},children:[s.jsxs("button",{onClick:()=>{l(q.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(Bp,{tone:U,enabled:q.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:q.name}),s.jsx("span",{title:q.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:q.type==="local"?s.jsx(A,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(A,{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:q.type==="local"?q.command?.join(" ")??"":q.url??""})]}),s.jsxs(As,{open:v===q.name,onOpenChange:Oe=>C(Oe?q.name:null),children:[s.jsx(Is,{asChild:!0,children:s.jsx(he,{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(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ps,{align:"end",className:"w-fit min-w-20",children:s.jsxs(Ot,{onClick:Oe=>{Oe.stopPropagation(),x(q)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},q.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(q=>{const L=p[q.name],U=_p(L?.status),oe=i===q.name,Ee=go();return s.jsxs("div",{className:ge("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",oe?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Ee?void 0:Oe=>{Oe.preventDefault(),C(q.name)},children:[s.jsxs("button",{onClick:()=>{l(q.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(Bp,{tone:U,enabled:q.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:q.name}),s.jsx("span",{title:q.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:q.type==="local"?s.jsx(A,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(A,{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:q.type==="local"?q.command?.join(" ")??"":q.url??""})]}),s.jsxs(As,{open:v===q.name,onOpenChange:Oe=>C(Oe?q.name:null),children:[s.jsx(Is,{asChild:!0,children:s.jsx(he,{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(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ps,{align:"end",className:"w-fit min-w-20",children:s.jsxs(Ot,{onClick:Oe=>{Oe.stopPropagation(),x(q)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},q.name)})]})]})}),e[63]=a.length,e[64]=p,e[65]=n,e[66]=v,e[67]=I,e[68]=i,e[69]=c,e[70]=l,e[71]=r,e[72]=P,e[73]=ie):ie=e[73];const ae=y!==null;let xe;e[74]!==h?(xe=q=>{!q&&!h&&x(null)},e[74]=h,e[75]=xe):xe=e[75];let Z;e[76]!==r?(Z=r("settings.mcp.sidebar.deleteDialog.title"),e[76]=r,e[77]=Z):Z=e[77];let me;e[78]!==Z?(me=s.jsx(ds,{children:Z}),e[78]=Z,e[79]=me):me=e[79];const Y=y?.name||"";let Se;e[80]!==r||e[81]!==Y?(Se=r("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:Y}),e[80]=r,e[81]=Y,e[82]=Se):Se=e[82];let we;e[83]===Symbol.for("react.memo_cache_sentinel")?(we=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[83]=we):we=e[83];let ke;e[84]!==Se?(ke=s.jsxs(ys,{children:[Se," ",we,"."]}),e[84]=Se,e[85]=ke):ke=e[85];let Fe;e[86]!==me||e[87]!==ke?(Fe=s.jsxs(ps,{children:[me,ke]}),e[86]=me,e[87]=ke,e[88]=Fe):Fe=e[88];let Ce;e[89]===Symbol.for("react.memo_cache_sentinel")?(Ce=()=>x(null),e[89]=Ce):Ce=e[89];let Q;e[90]!==r?(Q=r("settings.common.actions.cancel"),e[90]=r,e[91]=Q):Q=e[91];let ce;e[92]!==h||e[93]!==Q?(ce=s.jsx(he,{size:"sm",variant:"ghost",onClick:Ce,disabled:h,children:Q}),e[92]=h,e[93]=Q,e[94]=ce):ce=e[94];let ve;e[95]!==h||e[96]!==r?(ve=r(h?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[95]=h,e[96]=r,e[97]=ve):ve=e[97];let le;e[98]!==$||e[99]!==h||e[100]!==ve?(le=s.jsx(he,{size:"sm",onClick:$,disabled:h,children:ve}),e[98]=$,e[99]=h,e[100]=ve,e[101]=le):le=e[101];let Ae;e[102]!==ce||e[103]!==le?(Ae=s.jsxs(Rs,{children:[ce,le]}),e[102]=ce,e[103]=le,e[104]=Ae):Ae=e[104];let Te;e[105]!==Fe||e[106]!==Ae?(Te=s.jsxs(os,{className:"max-w-md",children:[Fe,Ae]}),e[105]=Fe,e[106]=Ae,e[107]=Te):Te=e[107];let $e;e[108]!==ae||e[109]!==xe||e[110]!==Te?($e=s.jsx(ls,{open:ae,onOpenChange:xe,children:Te}),e[108]=ae,e[109]=xe,e[110]=Te,e[111]=$e):$e=e[111];let ye;return e[112]!==se||e[113]!==ie||e[114]!==$e?(ye=s.jsxs("div",{className:O,children:[se,ie,$e]}),e[112]=se,e[113]=ie,e[114]=$e,e[115]=ye):ye=e[115],ye};function x3(t){return{mcpServers:t.mcpServers,selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function b3(t){return t.currentDirectory}function y3(t){return t.refresh}function v3(t){return t.getErrorForDirectory}function w3(t){return t.scope==="project"}function j3(t){return t.scope!=="project"}function N3(t){return setTimeout(t,500)}function ja(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Gi(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function Ta(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function qc(t,e,n){const r=S3(n),a=typeof n.url=="string"?n.url.trim():"",i=Vp(n,"env","environment"),l=Vp(n,"headers"),c=k3(n),d=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientId??"").trim():"",f=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():"",p=C3(n),b=I3(n);return{ok:!0,name:t,type:e,command:r,url:a,environment:i,headers:l,oauthEnabled:c,oauthClientId:d,oauthClientSecret:f,oauthScope:m,oauthRedirectUri:u,timeout:p,enabled:b}}function S3(t){const e=t.command,n=t.args;if(Gi(e)&&Gi(n))return[...e,...n];if(Gi(e))return e;if(typeof e=="string"&&e.trim()){const r=e.trim().split(/\s+/);return Gi(n)?[...r,...n]:r}return Gi(n)?n:[]}function Vp(t,...e){for(const n of e){const r=t[n];if(!ja(r))continue;const a=Object.entries(r).filter(([i,l])=>i&&typeof l=="string");if(a.length>0)return a.map(([i,l])=>({key:i,value:String(l)}))}return[]}function k3(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!ja(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 C3(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 I3(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function P3(t){const e=t.mcpServers;if(ja(e)){const r=Object.keys(e);if(r.length===1){const a=r[0],i=e[a];if(ja(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"&&ja(a)});if(n.length===1){const r=n[0],a=t[r];if(Bg(a))return{name:r,entry:a}}return null}function Bg(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function A3(t,e){let n;try{const l=t.trim();if(!l)return Ta("No JSON content provided");n=JSON.parse(l)}catch(l){return Ta(l instanceof Error?`Invalid JSON: ${l.message}`:"Invalid JSON")}if(!ja(n))return Ta("Expected a JSON object, not an array or primitive");const r=n,a=r.mcpServers;if(ja(a)){const l=Object.keys(a);if(l.length===0)return Ta("mcpServers object is empty",n);if(l.length>1)return Ta("Paste one server at a time. Found "+l.length+" servers in mcpServers",n);const c=l[0],d=a[c];return ja(d)?qc(c,Jc(d),d):Ta("Server entry is not a valid object",n)}const i=P3(r);if(i)return qc(i.name,Jc(i.entry),i.entry);if(Bg(r)){const l=Jc(r),c=typeof r.name=="string"&&r.name.trim()?r.name.trim():e?.fallbackName;return qc(c,l,r)}return Ta("No recognizable MCP server configuration found in JSON",n)}function Jc(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 D3(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 Vg="/mcp/oauth/callback",T3=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}},zg=t=>{const e=E3(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}},Su=t=>{const e=t.get("state");return typeof e!="string"?null:e.trim()||null},E3=t=>{if(typeof t!="string"||!t.trim())return null;const e=T3(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 M3(t){const e=[];let n="",r=!1,a=!1;for(let i=0;i<t.length;i++){const l=t[i];if(l==="'"&&!a){r=!r;continue}if(l==='"'&&!r){a=!a;continue}if((l===" "||l===" ")&&!r&&!a){n&&(e.push(n),n="");continue}n+=l}return n&&e.push(n),e}function R3(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:zg(n.searchParams),stateKey:Su(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const F3=({value:t,onChange:e,pasteCommandTitle:n,pasteCommandLabel:r,pasteSuccess:a,clipboardReadFailed:i,preview:l})=>{const[c,d]=o.useState(()=>t.join(`
|
|
164
|
+
`)),f=o.useRef(t);o.useEffect(()=>{JSON.stringify(f.current)!==JSON.stringify(t)&&(f.current=t,d(t.join(`
|
|
165
|
+
`)))},[t]);const m=p=>{const b=p.split(`
|
|
166
|
+
`).filter(g=>g.trim().length>0);e(b)},u=async()=>{try{const b=(await navigator.clipboard.readText()).trim(),g=b.includes(`
|
|
167
|
+
`)?b.split(`
|
|
168
|
+
`).filter(y=>y.trim()):M3(b);d(g.join(`
|
|
169
|
+
`)),e(g),K.success(a(g.length))}catch{K.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(he,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:u,type:"button",title:n,children:[s.jsx(A,{name:"clipboard",className:"h-3 w-3"}),r]})}),s.jsx(ln,{value:c,onChange:p=>{d(p.target.value),m(p.target.value)},onBlur:()=>{const p=c.split(`
|
|
170
|
+
`).map(b=>b.trimEnd()).join(`
|
|
171
|
+
`);d(p),m(p)},placeholder:`npx
|
|
172
|
+
-y
|
|
173
|
+
@modelcontextprotocol/server-postgres
|
|
174
|
+
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:l(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((p,b)=>s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",b,"]"]}),p]},b))})})]})]})},L3=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),zp=({value:t,onChange:e,keyTransform:n=L3,keyPlaceholder:r="API_KEY",keyInputClassName:a="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:i="Paste .env",pasteTitle:l="Paste KEY=VALUE lines from clipboard",noPairsFoundError:c,importSuccess:d,clipboardReadFailed:f,keyLabel:m,valueLabel:u,valuePlaceholder:p,hideValueTitle:b,showValueTitle:g,addVariable:y,plainTextWarning:x,removeVariableAria:h})=>{const[j,v]=o.useState(new Set),C=()=>e([...t,{key:"",value:""}]),k=P=>{e(t.filter((T,S)=>S!==P)),v(T=>{const S=new Set(T);return S.delete(P),S})},w=(P,T,S)=>{const M=[...t];M[P]={...M[P],[T]:S},e(M)},N=P=>{v(T=>{const S=new Set(T);return S.has(P)?S.delete(P):S.add(P),S})},I=async()=>{try{const P=await navigator.clipboard.readText(),T=[];for(const M of P.split(`
|
|
175
|
+
`)){const D=M.trim();if(!D||D.startsWith("#"))continue;const F=D.indexOf("=");if(F===-1)continue;const _=D.slice(0,F).trim();let V=D.slice(F+1).trim();(V.startsWith('"')&&V.endsWith('"')||V.startsWith("'")&&V.endsWith("'"))&&(V=V.slice(1,-1)),_&&T.push({key:_,value:V})}if(T.length===0){K.error(c);return}const S=[...t];for(const M of T){const D=S.findIndex(F=>F.key===M.key);D!==-1?S[D]=M:S.push(M)}e(S),K.success(d(T.length))}catch{K.error(f)}},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(he,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:I,type:"button",title:l,children:[s.jsx(A,{name:"clipboard",className:"h-3 w-3"}),i]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((P,T)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx($t,{value:P.key,onChange:S=>w(T,"key",n(S.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($t,{type:j.has(T)?"text":"password",value:P.value,onChange:S=>w(T,"value",S.target.value),placeholder:p,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:()=>N(T),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:j.has(T)?b:g,children:j.has(T)?s.jsx(A,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(he,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>k(T),"aria-label":h,children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},T))}),s.jsxs(he,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:C,type:"button",children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),y]}),E&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:x})]})},Up=t=>{const e=ot.c(14),{status:n,enabled:r,getStatusLabel:a,variant:i}=t,l=i===void 0?"compact":i;if(!r||!n)return null;let c,d;if(e[0]!==a||e[1]!==n||e[2]!==l){d=Symbol.for("react.early_return_sentinel");e:{const p={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(l==="pill"){const b=ge("typography-micro font-medium rounded-full px-2 py-0.5",p.text,p.bg);let g;e[5]!==a||e[6]!==n?(g=a(n),e[5]=a,e[6]=n,e[7]=g):g=e[7],d=s.jsxs("span",{className:b,children:["● ",g]});break e}c=ge("typography-micro font-medium",p.text)}e[0]=a,e[1]=n,e[2]=l,e[3]=c,e[4]=d}else c=e[3],d=e[4];if(d!==Symbol.for("react.early_return_sentinel"))return d;let f;e[8]!==a||e[9]!==n?(f=a(n),e[8]=a,e[9]=n,e[10]=f):f=e[10];let m;return e[11]!==c||e[12]!==f?(m=s.jsxs("span",{className:c,children:["● ",f]}),e[11]=c,e[12]=f,e[13]=m):m=e[13],m},O3=(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")}},$3=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)]"}},_3=(t,e,n,r)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||n||r),Wp=(t,e)=>{if(typeof window>"u")return null;const n=new URL(Vg,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()},B3=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")}},V3=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},qi=async t=>{typeof t!="string"||!t.trim()||await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},Yc=(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},z3=(t,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${n}`},U3=()=>{const{t}=pt(),e=o.useCallback((Ye,Mt)=>t(Ye,Mt),[t]),{selectedMcpName:n,mcpServers:r,mcpDraft:a,setMcpDraft:i,setSelectedMcp:l,getMcpByName:c,createMcp:d,updateMcp:f,deleteMcp:m}=wo(Qn(Ye=>({selectedMcpName:Ye.selectedMcpName,mcpServers:Ye.mcpServers,mcpDraft:Ye.mcpDraft,setMcpDraft:Ye.setMcpDraft,setSelectedMcp:Ye.setSelectedMcp,getMcpByName:Ye.getMcpByName,createMcp:Ye.createMcp,updateMcp:Ye.updateMcp,deleteMcp:Ye.deleteMcp}))),u=Ms(Ye=>Ye.currentDirectory),p=o.useMemo(()=>un(),[]),b=kn(Ye=>Ye.getStatusForDirectory(u??null)),g=kn(Ye=>Ye.getDiagnosticForDirectory(u??null)),y=kn(Ye=>Ye.refresh),x=kn(Ye=>Ye.connect),h=kn(Ye=>Ye.disconnect),j=kn(Ye=>Ye.startAuth),v=kn(Ye=>Ye.completeAuth),C=kn(Ye=>Ye.clearAuth),k=kn(Ye=>Ye.testConnection),w=n?c(n):null,N=!!(a&&a.name===n&&!w),[I,E]=o.useState(""),[P,T]=o.useState("user"),[S,M]=o.useState("local"),[D,F]=o.useState([]),[_,V]=o.useState(""),[$,O]=o.useState([]),[B,G]=o.useState([]),[R,H]=o.useState(!0),[J,ne]=o.useState(""),[ue,de]=o.useState(""),[pe,W]=o.useState(""),[te,X]=o.useState(""),[ee,fe]=o.useState(""),[be,Ne]=o.useState(!0),[se,ie]=o.useState(!1),[ae,xe]=o.useState(!1),[Z,me]=o.useState(!1),[Y,Se]=o.useState(!1),[we,ke]=o.useState(!1),[Fe,Ce]=o.useState(!1),[Q,ce]=o.useState(!1),[ve,le]=o.useState(!1),[Ae,Te]=o.useState(null),[$e,ye]=o.useState(null),[q,L]=o.useState(""),[U,oe]=o.useState(!1),Ee=o.useRef(0),Oe=o.useRef(!1),[Ie,z]=o.useState(!1),[De,Qe]=o.useState(!1),[tt,et]=o.useState(""),[We,at]=o.useState(null),qe=o.useMemo(()=>z3(n,u),[u,n]),nt=o.useRef(qe),Ze=o.useRef(null),ze=o.useCallback(()=>{Te(null),ye(null),L(""),oe(!1),Ee.current=0,le(!1),ke(!1),Ce(!1),Oe.current=!1},[]),rt=o.useCallback(()=>{et(""),at(null),Qe(!0)},[]),Ge=o.useCallback(async()=>{try{const Ye=await navigator.clipboard.readText();et(Ye),at(null)}catch{K.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),ct=o.useCallback(()=>{const Ye=A3(tt,{fallbackName:I});if(!Ye.ok){at(Ye.error);return}const Bt=D3(Ye,{name:I,scope:P,type:S,command:D,url:_,environment:$,headers:B,oauthEnabled:R,oauthClientId:J,oauthClientSecret:ue,oauthScope:pe,oauthRedirectUri:te,timeout:ee,enabled:be},{isNewServer:N});E(Bt.name),M(Bt.type),F(Bt.command??[]),V(Bt.url??""),O(Bt.environment??[]),G(Bt.headers??[]),H(Bt.oauthEnabled??!1),ne(Bt.oauthClientId??""),de(Bt.oauthClientSecret??""),W(Bt.oauthScope??""),X(Bt.oauthRedirectUri??""),fe(Bt.timeout??""),Ne(Bt.enabled??!0),Qe(!1),et(""),at(null),K.success(t("settings.mcp.page.toast.configImported"))},[tt,I,P,S,D,_,$,B,R,J,ue,pe,te,ee,be,N,t]);o.useEffect(()=>{if(N&&a){E(a.name),T(a.scope||"user"),M(a.type),F(a.command),V(a.url),O(a.environment),G(a.headers),H(a.oauthEnabled),ne(a.oauthClientId),de(a.oauthClientSecret),W(a.oauthScope),X(a.oauthRedirectUri),fe(a.timeout),Ne(a.enabled),z(!1),Ze.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(w){T(w.scope==="project"?"project":"user");const Ye=wm(w.environment),Mt=w.type==="remote"?w:null,Bt=wm(Mt?.headers),wt=Mt?.oauth,Zt=wt&&typeof wt=="object"?wt:null,us=wt!==!1,Es=w.type,ws=Es==="local"?w.command??[]:[],Ds=Es==="remote"?w.url??"":"",Xt=typeof Mt?.timeout=="number"&&Number.isFinite(Mt.timeout)?String(Mt.timeout):"";M(Es),F(ws),V(Ds),O(Ye),G(Bt),H(us),ne(us?Zt?.clientId??"":""),de(us?Zt?.clientSecret??"":""),W(us?Zt?.scope??"":""),X(us?Zt?.redirectUri??"":""),fe(Xt),Ne(w.enabled),z(!1),Ze.current={mcpType:Es,command:ws,url:Ds,envEntries:Ye,headerEntries:Bt,oauthEnabled:us,oauthClientId:us?Zt?.clientId??"":"",oauthClientSecret:us?Zt?.clientSecret??"":"",oauthScope:us?Zt?.scope??"":"",oauthRedirectUri:us?Zt?.redirectUri??"":"",timeout:Xt,enabled:w.enabled}}},[w,N,a]);const Pe=o.useMemo(()=>{const Ye=Ze.current;return Ye?S!==Ye.mcpType||be!==Ye.enabled||JSON.stringify(D)!==JSON.stringify(Ye.command)||_!==Ye.url||JSON.stringify($)!==JSON.stringify(Ye.envEntries)||JSON.stringify(B)!==JSON.stringify(Ye.headerEntries)||R!==Ye.oauthEnabled||J!==Ye.oauthClientId||ue!==Ye.oauthClientSecret||pe!==Ye.oauthScope||te!==Ye.oauthRedirectUri||ee!==Ye.timeout:!1},[S,D,_,$,B,R,J,ue,pe,te,ee,be]),Me=async()=>{const Ye=N?I.trim():n??"";if(!Ye){K.error(t("settings.mcp.page.toast.nameRequired"));return}if(N&&r.some(Bt=>Bt.name===Ye)){K.error(t("settings.mcp.page.toast.serverNameExists"));return}if(S==="local"&&D.filter(Boolean).length===0){K.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(S==="remote"&&!_.trim()){K.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const Mt={name:Ye,scope:P,type:S,command:D,url:_,environment:$,headers:B,oauthEnabled:R,oauthClientId:J,oauthClientSecret:ue,oauthScope:pe,oauthRedirectUri:te,timeout:ee,enabled:be};ie(!0);try{const Bt=N?await d(Mt):await f(Ye,Mt);Bt.ok?(await qi($e),ze(),N&&(i(null),l(Ye)),await y({directory:u,silent:!0}),Bt.reloadFailed?K.warning(Bt.message||t(N?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:Bt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):K.success(Bt.message||t(N?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):K.error(t("settings.mcp.page.toast.saveFailed"))}catch(Bt){K.error(Bt instanceof Error?Bt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{ie(!1)}},Ue=async()=>{if(!n)return;me(!0);const Ye=await m(n);Ye.ok?(await qi($e),ze(),Ye.reloadFailed?K.warning(Ye.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:Ye.warning||t("settings.mcp.page.toast.refreshListIfStale")}):K.success(Ye.message||t("settings.mcp.page.toast.serverDeleted",{name:n})),xe(!1)):K.error(t("settings.mcp.page.toast.deleteFailed")),me(!1)},He=async()=>{if(n){Se(!0);try{if(b[n]?.status==="connected")await h(n,u),K.success(t("settings.mcp.page.toast.disconnected"));else{await x(n,u),await y({directory:u,silent:!0});const Mt=kn.getState().getStatusForDirectory(u??null)[n];Mt?.status==="connected"?K.success(t("settings.mcp.page.toast.connected")):Mt?.status==="needs_auth"?K.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Mt?.status==="needs_client_registration"?K.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):Mt?.status==="failed"?K.error(Mt.error||t("settings.mcp.page.toast.connectionFailed")):K.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await y({directory:u,silent:!0})}catch(Ye){K.error(Ye instanceof Error?Ye.message:t("settings.mcp.page.toast.connectionFailed"))}finally{Se(!1)}}},lt=o.useCallback(()=>N?(K.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):Pe?(K.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[Pe,N,t]),vt=o.useCallback(async(Ye=!1)=>{try{await y({directory:u,silent:Ye})}catch(Mt){Ye||K.error(Mt instanceof Error?Mt.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[u,y,t]);o.useEffect(()=>{vt(!0)},[vt]),o.useEffect(()=>{nt.current=qe,Se(!1),ce(!1),ze()},[ze,qe]);const ft=o.useCallback(async()=>{if(!n||S!=="remote"||!lt())return;ke(!0);const Ye=qe;let Mt=null;try{const Bt=kn.getState().getStatusForDirectory(u??null)[n]?.status;Oe.current=Bt==="needs_auth"||Bt==="needs_client_registration";const wt=Wp(n,u);if(!wt)throw new Error(t("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!te.trim()&&!p){const ws=await f(n,{oauthEnabled:R,oauthClientId:J,oauthClientSecret:ue,oauthScope:pe,oauthRedirectUri:wt});if(!ws.ok)throw new Error(t("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(ws.reloadFailed)throw new Error(ws.warning||ws.message||t("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(nt.current!==Ye)return;X(wt),Ze.current=Ze.current?{...Ze.current,oauthRedirectUri:wt}:Ze.current}const Zt=await j(n,u),us=Su(new URL(Zt).searchParams);if(us&&(Mt=us,await B3({state:us,name:n,directory:u})),nt.current!==Ye)return;Te(Zt),ye(us??null),oe(!0),Ee.current=0;const Es=await rr(Zt);if(nt.current!==Ye)return;Es?K.message(t(p?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):K.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(Bt){await qi(Mt),nt.current===Ye&&K.error(Yc(Bt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{nt.current===Ye&&ke(!1)}},[u,p,S,J,ue,R,te,pe,lt,qe,n,j,t,e,f]),dt=o.useCallback(async()=>{if(!n||!lt())return;Ce(!0);const Ye=qe;try{if(await C(n,u),nt.current!==Ye)return;Te(null),ye(null),L(""),oe(!1),Ee.current=0,await qi($e),K.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(Mt){nt.current===Ye&&K.error(Yc(Mt,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{nt.current===Ye&&Ce(!1)}},[$e,C,u,lt,qe,n,t,e]),Dt=o.useCallback(async()=>{if(!Ae)return;if((await Ln(Ae)).ok){K.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}K.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Ae,t]),Qt=o.useCallback(async()=>{const Ye=R3(q);if(!Ye.code){K.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const Mt=Ye.stateKey?await V3(Ye.stateKey):null,Bt=Ye.context??Mt,wt=Bt?.name??n,Zt=Bt?.directory??u;if(!wt){K.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!Bt&&!lt())return;le(!0);const us=qe;try{if(await v(wt,Ye.code,Zt),await qi(Ye.stateKey??$e),nt.current!==us)return;L(""),Te(null),ye(null),oe(!1),Ee.current=0,K.success(wt===n?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:wt}))}catch(Es){nt.current===us&&K.error(Yc(Es,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{nt.current===us&&le(!1)}},[q,$e,v,u,lt,qe,n,t,e]),Ft=o.useCallback(async()=>{if(!(!n||!lt())){if(!be){K.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}ce(!0);try{const Ye=await k(n,u),Mt=Ye.status?.status;Ye.warning?K.warning(Ye.warning):Mt==="connected"?K.success(t("settings.mcp.page.toast.connectionTestSucceeded")):Mt==="needs_auth"?K.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Mt==="needs_client_registration"?K.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):Mt==="failed"?K.error(Ye.status?.error||Ye.error||t("settings.mcp.page.toast.connectionTestFailed")):Ye.error?K.error(Ye.error):K.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(Ye){K.error(Ye instanceof Error?Ye.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{ce(!1)}}},[u,be,lt,n,t,k]);if(o.useEffect(()=>{if(!U||!n)return;const Ye=window.setInterval(()=>{(async()=>{Ee.current+=1,await y({directory:u,silent:!0});const Mt=kn.getState().getStatusForDirectory(u??null)[n];if(Mt){if(Oe.current&&Mt.status!=="needs_auth"&&Mt.status!=="needs_client_registration"){oe(!1),Ee.current=0,Oe.current=!1,Te(null),L(""),Mt.status==="connected"&&K.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!Oe.current&&Mt.status==="failed"){oe(!1),Ee.current=0,Oe.current=!1,K.error(Mt.error||t("settings.mcp.page.toast.authorizationFailed"));return}Ee.current>=30&&(oe(!1),Ee.current=0,Oe.current=!1,K.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(Ye)}},[u,U,y,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(A,{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 qt=b[n],gt=n?g[n]:void 0,zt=qt??gt,es=qt?.status==="connected",is=qt?.status==="needs_auth"||qt?.status==="needs_client_registration",cs=p?null:Wp(n,u),hs=O3(zt?.status,e,zt&&"error"in zt?zt.error:void 0),_t=Ye=>{switch(Ye){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 Ye}};return s.jsxs(vs,{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:[N?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(Up,{status:zt?.status,enabled:be,getStatusLabel:_t,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:N?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(S==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")})}),!N&&s.jsxs(s.Fragment,{children:[s.jsx(he,{variant:es?"outline":"default",size:"xs",className:"!font-normal",onClick:He,disabled:Y||!be,children:t(Y?"settings.mcp.page.actions.working":es?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),S==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(he,{variant:is?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{ft()},disabled:we||!be,children:t(we?"settings.mcp.page.actions.starting":is?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),s.jsx(he,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{dt()},disabled:Fe||!be,children:t(Fe?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),es&&s.jsx(he,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{Ft()},disabled:Q||!be,children:t(Q?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!N&&_3(zt?.status,Ae,is,U)&&s.jsx("div",{className:"mb-6 px-2",children:s.jsxs("div",{className:ge("rounded-lg border p-3",$3(zt?.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(Up,{status:zt?.status,enabled:be,getStatusLabel:_t})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:hs}),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:!es&&s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ft()},disabled:Q||!be,children:t(Q?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Ae&&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:Ae}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{rr(Ae)},children:[s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Dt()},children:[s.jsx(A,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),S==="remote"&&(is||U||Ae)&&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(ln,{value:q,onChange:Ye=>L(Ye.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(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Qt()},disabled:ve,children:t(ve?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),U&&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:[N&&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($t,{value:I,onChange:Ye=>E(Ye.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(ns,{value:P,onValueChange:Ye=>T(Ye),children:[s.jsx(rs,{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(A,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5"})}),s.jsxs(as,{align:"end",children:[s.jsx(Rt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Rt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),N&&s.jsx("div",{className:"py-1.5",children:s.jsxs(he,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:rt,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(A,{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":be,onClick:()=>Ne(!be),onKeyDown:Ye=>{(Ye.key===" "||Ye.key==="Enter")&&(Ye.preventDefault(),Ne(!be))},children:[s.jsx(fs,{checked:be,onChange:Ne,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(he,{variant:"chip",size:"xs","aria-pressed":S==="local",onClick:()=>M("local"),className:"!font-normal",children:t("settings.mcp.page.transport.local")}),s.jsx(he,{variant:"chip",size:"xs","aria-pressed":S==="remote",onClick:()=>M("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(S==="local"?"settings.mcp.page.connection.command":"settings.mcp.page.connection.serverUrl")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:S==="local"?s.jsx(F3,{value:D,onChange:F,pasteCommandTitle:t("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:t("settings.mcp.page.connection.pasteCommand"),pasteSuccess:Ye=>t("settings.mcp.page.toast.pastedArgumentsCount",{count:Ye}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),preview:Ye=>t("settings.mcp.page.connection.previewArgs",{count:Ye})}):s.jsx($t,{value:_,onChange:Ye=>V(Ye.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"})})]}),S==="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(jr,{open:Ie,onOpenChange:z,children:[s.jsxs(Lr,{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(R?"settings.mcp.page.advanced.autoDetect":"settings.mcp.page.advanced.custom")," · ",B.length," ",t("settings.mcp.page.advanced.headers"),ee?` · ${ee}ms`:"",")"]})]}),Ie?s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Nr,{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($t,{type:"number",min:"1",step:"1",value:ee,onChange:Ye=>fe(Ye.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"),B.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",B.length,")"]})]}),s.jsx(zp,{value:B,onChange:G,keyTransform:Ye=>Ye.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:Ye=>t("settings.mcp.page.toast.importedVariablesCount",{count:Ye}),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":R,onClick:()=>H(!R),onKeyDown:Ye=>{(Ye.key===" "||Ye.key==="Enter")&&(Ye.preventDefault(),H(!R))},children:[s.jsx(fs,{checked:R,onChange:H,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($t,{value:J,onChange:Ye=>ne(Ye.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientIdPlaceholder"),className:"font-mono typography-meta",disabled:!R,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx($t,{value:ue,onChange:Ye=>de(Ye.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientSecretPlaceholder"),className:"font-mono typography-meta",disabled:!R,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx($t,{value:pe,onChange:Ye=>W(Ye.target.value),placeholder:t("settings.mcp.page.advanced.oauthScopesPlaceholder"),className:"font-mono typography-meta",disabled:!R,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx($t,{value:te,onChange:Ye=>X(Ye.target.value),placeholder:t("settings.mcp.page.advanced.oauthRedirectUriPlaceholder"),className:"font-mono typography-meta",disabled:!R,"data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.advanced.oauthHint")}),cs&&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:cs})]})]})]})})]})})]}),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"),$.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",$.length,")"]})]})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:$.length===0?s.jsxs(he,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>O([{key:"",value:""}]),children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(zp,{value:$,onChange:O,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:Ye=>t("settings.mcp.page.toast.importedVariablesCount",{count:Ye}),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(he,{onClick:Me,disabled:se||!Pe&&!N,size:"xs",className:"!font-normal",children:t(se?"settings.common.actions.saving":N?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!N&&s.jsx(he,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>xe(!0),children:t("settings.common.actions.delete")})]})]}),s.jsx(ls,{open:De,onOpenChange:Ye=>{Ye||(Qe(!1),et(""),at(null))},children:s.jsxs(os,{className:"max-w-md",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(ys,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(ln,{value:tt,onChange:Ye=>{et(Ye.target.value),at(null)},placeholder:`{
|
|
176
|
+
"mcpServers": {
|
|
177
|
+
"postgres": {
|
|
178
|
+
"command": "npx",
|
|
179
|
+
"args": ["-y", "@modelcontextprotocol/server-postgres"]
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}`,rows:8,className:"font-mono typography-meta resize-y",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),We&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:We}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(he,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Ge,type:"button",children:[s.jsx(A,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(Rs,{children:[s.jsx(he,{variant:"outline",onClick:()=>{Qe(!1),et(""),at(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(he,{onClick:ct,disabled:!tt.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(ls,{open:ae,onOpenChange:Ye=>{!Ye&&!Z&&xe(!1)},children:s.jsxs(os,{className:"max-w-md",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:t("settings.mcp.page.deleteDialog.title",{name:n??""})}),s.jsxs(ys,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(Rs,{children:[s.jsx(he,{variant:"outline",onClick:()=>xe(!1),disabled:Z,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(he,{variant:"destructive",size:"sm",onClick:Ue,disabled:Z,children:t(Z?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},wl=()=>{try{const e=Ss.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=rn.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},W3=800,K3=5e3,H3="__default__",Ld=new Map,Qc=new Map,G3=1500,Ug=t=>t?.trim()||H3,q3=t=>{Ld.delete(Ug(t))},Tn=ar()(ei(Fi((t,e)=>({entries:[],files:[],selectedId:null,isLoading:!1,registryInfo:{},isLoadingRegistry:!1,draft:null,setSelected:n=>t({selectedId:n}),setDraft:n=>t({draft:n}),loadPlugins:async n=>{const r=wl(),a=Ug(r),i=Date.now(),l=Ld.get(a)??0,c=e().entries.length>0||e().files.length>0;if(!n?.force&&c&&i-l<K3)return!0;const d=Qc.get(a);if(!n?.force&&d)return d;const f=(async()=>{t({isLoading:!0});try{const m=await fetch(ga("/api/config/plugins",r),{headers:Ji(r)});if(!m.ok)throw new Error("Failed to load plugins");const u=await jl(m);return t({entries:u.entries??[],files:u.files??[],isLoading:!1}),Ld.set(a,Date.now()),n?.force||e().loadRegistryInfo(),!0}catch(m){return console.error("[PluginsStore] Failed to load plugins:",m),t({isLoading:!1}),!1}})();Qc.set(a,f);try{return await f}finally{Qc.delete(a)}},loadRegistryInfo:async n=>{const r=Y3(n?.specs??e().entries.map(a=>a.spec));if(r.length===0){t({isLoadingRegistry:!1});return}t({isLoadingRegistry:!0});try{const a=wl(),i={...e().registryInfo};for(const l of Q3(r)){const c=await fetch(J3(l,n?.force===!0,a),{headers:Ji(a)});if(!c.ok)throw new Error("Failed to load plugin registry info");const d=await jl(c);for(const f of d.results??[])i[f.spec]=f}t({registryInfo:i,isLoadingRegistry:!1})}catch(a){console.error("[PluginsStore] Failed to load plugin registry info:",a),t({isLoadingRegistry:!1})}},updateToLatest:async n=>{const r=e().entries.find(i=>i.id===n);if(!r)return{ok:!1};const a=e().registryInfo[r.spec];return!a||a.kind!=="npm-ok"||!a.hasUpdate||!a.latestVersion?{ok:!1}:await e().updateEntry(n,{spec:`${a.name}@${a.latestVersion}`})},createEntry:async n=>{const r=await mi("Creating plugin entry…",async a=>await fetch(ga("/api/config/plugins/entry",a),{method:"POST",headers:Qo(a),body:JSON.stringify(Kp(n))}),e);return r.ok&&e().loadRegistryInfo({specs:[n.spec],force:!0}),r},updateEntry:async(n,r)=>{const a=e().entries.find(c=>c.id===n)?.spec,i=r.spec??a,l=await mi("Updating plugin entry…",async c=>await fetch(ga(`/api/config/plugins/entry/${encodeURIComponent(n)}`,c),{method:"PATCH",headers:Qo(c),body:JSON.stringify(Kp(r))}),e);return l.ok&&i&&e().loadRegistryInfo({specs:[i],force:!0}),l},deleteEntry:async n=>{const r=e().entries.find(i=>i.id===n),a=await mi("Deleting plugin entry…",async i=>await fetch(ga(`/api/config/plugins/entry/${encodeURIComponent(n)}`,i),{method:"DELETE",headers:Ji(i)}),e);if(a.ok&&e().selectedId===n&&t({selectedId:null}),a.ok&&r){const i={...e().registryInfo};delete i[r.spec],t({registryInfo:i})}return a},readFile:async n=>{try{const r=wl(),a=await fetch(ga(`/api/config/plugins/file/${encodeURIComponent(n)}`,r),{headers:Ji(r)});if(!a.ok)throw new Error("Failed to read plugin file");return await jl(a)}catch(r){return console.error("[PluginsStore] Failed to read plugin file:",r),null}},createFile:async n=>mi("Creating plugin file…",async r=>await fetch(ga("/api/config/plugins/file",r),{method:"POST",headers:Qo(r),body:JSON.stringify(n)}),e),updateFile:async(n,r)=>mi("Updating plugin file…",async a=>await fetch(ga(`/api/config/plugins/file/${encodeURIComponent(n)}`,a),{method:"PUT",headers:Qo(a),body:JSON.stringify(r)}),e),deleteFile:async n=>{const r=await mi("Deleting plugin file…",async a=>await fetch(ga(`/api/config/plugins/file/${encodeURIComponent(n)}`,a),{method:"DELETE",headers:Ji(a)}),e);return r.ok&&e().selectedId===n&&t({selectedId:null}),r},getById:n=>e().entries.find(r=>r.id===n)??e().files.find(r=>r.id===n)}),{name:"plugins-store",storage:Co(()=>vr()),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function ga(t,e){const n=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${n}`}function J3(t,e,n){const r=new URLSearchParams;e&&r.set("refresh","true"),n&&r.set("directory",n);const a=r.toString();return`/api/config/plugins/registry?${`specs=${t.map(encodeURIComponent).join(",")}`}${a?`&${a}`:""}`}function Y3(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function Q3(t){const e=[];let n=[],r=0;for(const a of t){const i=encodeURIComponent(a),l=n.length===0?i.length:r+1+i.length;n.length>0&&l>G3?(e.push(n),n=[a],r=i.length):(n.push(a),r=l)}return n.length>0&&e.push(n),e}function Ji(t){return t?{"x-opencode-directory":t}:void 0}function Qo(t){return{"Content-Type":"application/json",...t?{"x-opencode-directory":t}:{}}}function Kp(t){const e={};return t.spec!==void 0&&(e.spec=t.spec),t.options!==void 0&&(e.options=t.options),t.scope!==void 0&&(e.scope=t.scope),e}async function mi(t,e,n){ll(t);let r=!1;try{const a=wl(),i=await e(a),l=await jl(i).catch(()=>null);if(!i.ok)throw new Error(l?.error||"Failed to update plugin configuration");return q3(a),l?.requiresReload&&(r=!0,await cl({message:l.message,delayMs:l.reloadDelayMs??W3,scopes:["all"]})),await n().loadPlugins({force:!0}),{ok:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}}catch(a){return console.error("[PluginsStore] Failed to update plugin configuration:",a),{ok:!1}}finally{r||dl()}}async function jl(t){return await t.json()}const X3=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function Z3(t){const e=t.trim();if(e==="")return{ok:!0,value:void 0};try{const n=JSON.parse(e);return n===null||typeof n!="object"||Array.isArray(n)?{ok:!1}:{ok:!0,value:n}}catch{return{ok:!1}}}const e5=({open:t,onOpenChange:e,defaultScope:n="user"})=>{const{t:r}=pt(),a=Tn(F=>F.createEntry),i=Tn(F=>F.createFile),[l,c]=o.useState("npm"),[d,f]=o.useState(""),[m,u]=o.useState(""),[p,b]=o.useState(""),[g,y]=o.useState(""),[x,h]=o.useState(n),[j,v]=o.useState(!1),C=o.useCallback(()=>{f(""),u(""),b(""),y(""),h(n)},[n]);o.useEffect(()=>{t&&(c("npm"),C())},[t,C]);const k=F=>{F!==l&&(c(F),C())},w=o.useMemo(()=>Z3(m),[m]),N=!w.ok,I=l==="file"&&p.trim()!==""&&!X3.test(p.trim()),E=(l==="npm"||l==="path")&&d.trim()==="",P=l==="file"&&g.trim()==="",T=l==="file"&&p.trim()==="",S=j||N||l==="npm"&&E||l==="path"&&E||l==="file"&&(T||I||P),M=async()=>{if(!S){v(!0);try{let F;l==="file"?F=await i({fileName:p.trim(),content:g,scope:x}):F=await a({spec:d.trim(),options:w.ok?w.value:void 0,scope:x}),F.ok?(K.success(F.message||r("settings.plugins.toast.created")),F.reloadFailed&&K.warning(r("settings.plugins.toast.reloadFailed")),e(!1)):K.error(F.message||r("settings.plugins.sidebar.toast.deleteFailed"))}finally{v(!1)}}},D=o.useMemo(()=>[{id:"npm",label:r("settings.plugins.dialog.add.tab.npm")},{id:"path",label:r("settings.plugins.dialog.add.tab.path")},{id:"file",label:r("settings.plugins.dialog.add.tab.file")}],[r]);return s.jsx(ls,{open:t,onOpenChange:F=>{!F&&j||e(F)},children:s.jsxs(os,{className:"max-w-xl",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:r("settings.plugins.dialog.add.title")}),s.jsx(ys,{children:r("settings.plugins.sidebar.empty.description")})]}),s.jsx(Fr,{items:D,activeId:l,onSelect:F=>k(F),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),s.jsxs("div",{className:"flex flex-col gap-4",children:[(l==="npm"||l==="path")&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-spec",className:"typography-ui-label text-foreground",children:r("settings.plugins.page.field.spec")}),s.jsx($t,{id:"plugin-spec",value:d,onChange:F=>f(F.target.value),placeholder:r("settings.plugins.page.field.spec.placeholder"),"aria-invalid":E?!1:void 0,disabled:j}),E&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:r("settings.plugins.validation.specRequired")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-options",className:"typography-ui-label text-foreground",children:r("settings.plugins.page.field.options")}),s.jsx(ln,{id:"plugin-options",value:m,onChange:F=>u(F.target.value),rows:5,className:"font-mono",hasError:N,disabled:j}),N&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r("settings.plugins.page.field.options.invalidJson")})]})]}),l==="file"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-filename",className:"typography-ui-label text-foreground",children:r("settings.plugins.page.field.fileName")}),s.jsx($t,{id:"plugin-filename",value:p,onChange:F=>b(F.target.value),placeholder:"my-plugin.ts","aria-invalid":I||void 0,disabled:j}),I&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r("settings.plugins.validation.fileName")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-content",className:"typography-ui-label text-foreground",children:r("settings.plugins.page.field.content")}),s.jsx(ln,{id:"plugin-content",value:g,onChange:F=>y(F.target.value),rows:16,className:"font-mono",disabled:j})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.plugins.page.field.scope")}),s.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(F=>{const _=x===F,V=r(F==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>h(F),disabled:j,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(Oa,{checked:_,onChange:()=>h(F),ariaLabel:V}),s.jsx("span",{className:ge("typography-ui-label font-normal",_?"text-foreground":"text-foreground/60"),children:V})]},F)})})]})]}),s.jsxs(Rs,{children:[s.jsx(he,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:j,children:r("settings.plugins.dialog.add.action.cancel")}),s.jsxs(he,{size:"sm",onClick:()=>{M()},disabled:S,children:[j?s.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,r("settings.plugins.dialog.add.action.submit")]})]})]})})},t5=t=>{const e=ot.c(33),{spec:n}=t;let r;e[0]!==n?(r=c=>c.registryInfo[n],e[0]=n,e[1]=r):r=e[1];const a=Tn(r),{t:i}=pt();if(!a)return null;const l=s5;switch(a.kind){case"npm-ok":{if(!a.hasUpdate||!a.latestVersion)return null;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=c):c=e[2];let d;e[3]!==a.latestVersion?(d=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[c,a.latestVersion]}),e[3]=a.latestVersion,e[4]=d):d=e[4];let f;return e[5]!==a.currentVersion||e[6]!==a.latestVersion||e[7]!==i||e[8]!==d?(f=l(d,i("settings.plugins.registry.badge.update.tooltip",{current:a.currentVersion??"",latest:a.latestVersion})),e[5]=a.currentVersion,e[6]=a.latestVersion,e[7]=i,e[8]=d,e[9]=f):f=e[9],f}case"npm-missing-version":{let c;e[10]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=c):c=e[10];let d;return e[11]!==a.currentVersion||e[12]!==a.name||e[13]!==i?(d=l(c,i("settings.plugins.registry.badge.missingVersion.tooltip",{version:a.currentVersion,name:a.name})),e[11]=a.currentVersion,e[12]=a.name,e[13]=i,e[14]=d):d=e[14],d}case"npm-missing-package":{let c;e[15]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=c):c=e[15];let d;return e[16]!==a.name||e[17]!==i?(d=l(c,i("settings.plugins.registry.badge.missingPackage.tooltip",{name:a.name})),e[16]=a.name,e[17]=i,e[18]=d):d=e[18],d}case"npm-malformed":{let c;e[19]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=c):c=e[19];let d;return e[20]!==i?(d=l(c,i("settings.plugins.registry.badge.malformed.tooltip")),e[20]=i,e[21]=d):d=e[21],d}case"npm-network":{let c;e[22]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=c):c=e[22];let d;return e[23]!==i?(d=l(c,i("settings.plugins.registry.badge.network.tooltip")),e[23]=i,e[24]=d):d=e[24],d}case"path-missing":{let c;e[25]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=c):c=e[25];let d;return e[26]!==a.absolutePath||e[27]!==i?(d=l(c,i("settings.plugins.registry.badge.pathMissing.tooltip",{path:a.absolutePath})),e[26]=a.absolutePath,e[27]=i,e[28]=d):d=e[28],d}case"path-unreadable":{let c;e[29]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=c):c=e[29];let d;return e[30]!==a.absolutePath||e[31]!==i?(d=l(c,i("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:a.absolutePath})),e[30]=a.absolutePath,e[31]=i,e[32]=d):d=e[32],d}case"path-ok":return null;default:return null}};function s5(t,e){return s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(At,{children:e})]})}const ku=t=>{const e=ot.c(26),{header:n,footer:r,children:a,className:i,variant:l}=t,c=l===void 0?"sidebar":l,d=un(),f=o.useRef(null),[m,u]=o.useState(!1),[p,b]=o.useState(!1),g=c==="background"||d?"bg-background":"bg-sidebar",y=g==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const S=f.current;if(!S){u(!1),b(!1);return}if(!(S.scrollHeight>S.clientHeight+1)){u(!1),b(!1);return}u(S.scrollTop>1),b(S.scrollTop+S.clientHeight<S.scrollHeight-1)},e[0]=x):x=e[0];const h=x;let j;e[1]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{h()},e[1]=j):j=e[1];let v;e[2]!==a?(v=[a,h],e[2]=a,e[3]=v):v=e[3],o.useEffect(j,v);let C,k;e[4]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{const S=f.current;if(!S)return;const M=()=>h();return S.addEventListener("scroll",M,{passive:!0}),()=>S.removeEventListener("scroll",M)},k=[h],e[4]=C,e[5]=k):(C=e[4],k=e[5]),o.useEffect(C,k);let w;e[6]!==g||e[7]!==i?(w=ge("flex h-full flex-col",g,i),e[6]=g,e[7]=i,e[8]=w):w=e[8];let N;e[9]!==a?(N=s.jsx(vs,{ref:f,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]=N):N=e[10];let I;e[11]!==y||e[12]!==m?(I=m&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${y} 0%, transparent 100%)`}}),e[11]=y,e[12]=m,e[13]=I):I=e[13];let E;e[14]!==y||e[15]!==p?(E=p&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${y} 0%, transparent 100%)`}}),e[14]=y,e[15]=p,e[16]=E):E=e[16];let P;e[17]!==E||e[18]!==N||e[19]!==I?(P=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[N,I,E]}),e[17]=E,e[18]=N,e[19]=I,e[20]=P):P=e[20];let T;return e[21]!==r||e[22]!==n||e[23]!==P||e[24]!==w?(T=s.jsxs("div",{className:w,children:[n,P,r]}),e[21]=r,e[22]=n,e[23]=P,e[24]=w,e[25]=T):T=e[25],T},Gl=t=>{const e=ot.c(23),{title:n,metadata:r,selected:a,onSelect:i,icon:l,actions:c,className:d}=t,f=a===void 0?!1:a,m=c&&c.length>0,u=f?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==d||e[1]!==u?(p=ge("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]=p):p=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 g;e[5]!==l||e[6]!==b?(g=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,b]}),e[5]=l,e[6]=b,e[7]=g):g=e[7];let y;e[8]!==r?(y=r&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:r}),e[8]=r,e[9]=y):y=e[9];let x;e[10]!==i||e[11]!==g||e[12]!==y?(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:[g,y]}),e[10]=i,e[11]=g,e[12]=y,e[13]=x):x=e[13];let h;e[14]!==c||e[15]!==m?(h=m&&s.jsxs(As,{children:[s.jsx(Is,{asChild:!0,children:s.jsx(he,{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(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ps,{align:"end",className:"w-fit min-w-20",children:c.map(n5)})]}),e[14]=c,e[15]=m,e[16]=h):h=e[16];let j;e[17]!==x||e[18]!==h?(j=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,h]}),e[17]=x,e[18]=h,e[19]=j):j=e[19];let v;return e[20]!==p||e[21]!==j?(v=s.jsx("div",{className:p,children:j}),e[20]=p,e[21]=j,e[22]=v):v=e[22],v};function n5(t){const e=t.icon;return s.jsxs(Ot,{onClick:n=>{n.stopPropagation(),t.onClick()},className:ge(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(A,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const r5=t=>t.parsedKind==="npm"?"code-box":"folder",a5=t=>{const e=ot.c(142),{onItemSelect:n,onAddClick:r}=t,{t:a}=pt(),{entries:i,files:l,selectedId:c,setSelected:d,deleteEntry:f,deleteFile:m,loadPlugins:u}=Tn(Qn(i5)),p=Tn(o5),b=Tn(l5),g=Tn(c5),y=Tn(d5),[x,h]=o.useState(null),[j,v]=o.useState(!1),[C,k]=o.useState(!1);let w,N;e[0]!==u?(w=()=>{u()},N=[u],e[0]=u,e[1]=w,e[2]=N):(w=e[1],N=e[2]),o.useEffect(w,N);let I;if(e[3]!==i||e[4]!==p){I={userEntries:0,projectEntries:0};for(const ze of i){const rt=p[ze.spec];rt?.kind==="npm-ok"&&rt.hasUpdate&&(ze.scope==="user"?I.userEntries=I.userEntries+1:ze.scope==="project"&&(I.projectEntries=I.projectEntries+1))}e[3]=i,e[4]=p,e[5]=I}else I=e[5];const E=I;let P;e[6]!==i?(P=i.filter(u5),e[6]=i,e[7]=P):P=e[7];const T=P;let S;e[8]!==i?(S=i.filter(m5),e[8]=i,e[9]=S):S=e[9];const M=S;let D;e[10]!==l?(D=l.filter(p5),e[10]=l,e[11]=D):D=e[11];const F=D;let _;e[12]!==l?(_=l.filter(f5),e[12]=l,e[13]=_):_=e[13];const V=_,$=i.length+l.length,O=$===0;let B;e[14]!==r?(B=()=>{r?r():k(!0)},e[14]=r,e[15]=B):B=e[15];const G=B;let R;e[16]!==n||e[17]!==d?(R=ze=>{d(ze),n?.()},e[16]=n,e[17]=d,e[18]=R):R=e[18];const H=R;let J;e[19]!==i||e[20]!==p||e[21]!==a||e[22]!==y?(J=async ze=>{const rt=i.find(Me=>Me.id===ze);if(!rt)return;const Ge=p[rt.spec];if(!Ge||Ge.kind!=="npm-ok"||!Ge.hasUpdate||!Ge.latestVersion)return;const ct=Ge.latestVersion;(await y(ze)).ok?K.success(a("settings.plugins.toast.updatedToLatest",{version:ct})):K.error(a("settings.plugins.toast.refreshFailed"))},e[19]=i,e[20]=p,e[21]=a,e[22]=y,e[23]=J):J=e[23];const ne=J;let ue;e[24]!==g||e[25]!==a?(ue=async()=>{K.info(a("settings.plugins.toast.refreshing"));try{await g({force:!0})}catch{K.error(a("settings.plugins.toast.refreshFailed"))}},e[24]=g,e[25]=a,e[26]=ue):ue=e[26];const de=ue;let pe;e[27]!==f||e[28]!==m||e[29]!==x||e[30]!==a?(pe=async()=>{if(!x)return;v(!0);const ze=x.kind==="entry"?await f(x.id):await m(x.id);ze.ok?K.success(ze.message||a("settings.plugins.sidebar.toast.deleted",{name:x.label})):K.error(a("settings.plugins.sidebar.toast.deleteFailed")),h(null),v(!1)},e[27]=f,e[28]=m,e[29]=x,e[30]=a,e[31]=pe):pe=e[31];const W=pe;let te;e[32]!==H||e[33]!==ne||e[34]!==p||e[35]!==c||e[36]!==a?(te=ze=>{const rt=p[ze.spec],Ge=rt?.kind==="npm-ok"&&rt.hasUpdate&&!!rt.latestVersion,ct=[];return Ge&&ct.push({label:a("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{ne(ze.id)}}),ct.push({label:a("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>h({kind:"entry",id:ze.id,label:ze.spec})}),s.jsx(Gl,{title:s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:ze.spec}),s.jsx(t5,{spec:ze.spec})]}),metadata:ze.parsedKind==="npm"?a("settings.plugins.sidebar.kind.npm"):a("settings.plugins.sidebar.kind.path"),selected:c===ze.id,onSelect:()=>H(ze.id),icon:s.jsx(A,{name:r5(ze),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:ct},ze.id)},e[32]=H,e[33]=ne,e[34]=p,e[35]=c,e[36]=a,e[37]=te):te=e[37];const X=te;let ee;e[38]!==H||e[39]!==c||e[40]!==a?(ee=ze=>s.jsx(Gl,{title:ze.fileName,metadata:a("settings.plugins.sidebar.kind.file"),selected:c===ze.id,onSelect:()=>H(ze.id),icon:s.jsx(A,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:a("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>h({kind:"file",id:ze.id,label:ze.fileName})}]},ze.id),e[38]=H,e[39]=c,e[40]=a,e[41]=ee):ee=e[41];const fe=ee;let be;e[42]!==a?(be=(ze,rt,Ge)=>{const ct=Ge===void 0?0:Ge;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[ze,ct>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:a(ct===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:ct})})]}),rt]})},e[42]=a,e[43]=be):be=e[43];const Ne=be;let se;e[44]!==a?(se=a("settings.plugins.sidebar.title"),e[44]=a,e[45]=se):se=e[45];let ie;e[46]!==se?(ie=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:"text-base font-semibold text-foreground",children:se})}),e[46]=se,e[47]=ie):ie=e[47];let ae;e[48]!==a||e[49]!==$?(ae=a("settings.plugins.sidebar.total",{count:$}),e[48]=a,e[49]=$,e[50]=ae):ae=e[50];let xe;e[51]!==ae?(xe=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ae}),e[51]=ae,e[52]=xe):xe=e[52];let Z;e[53]!==de?(Z=()=>{de()},e[53]=de,e[54]=Z):Z=e[54];let me;e[55]!==a?(me=a("settings.plugins.sidebar.actions.refresh"),e[55]=a,e[56]=me):me=e[56];let Y;e[57]!==a?(Y=a("settings.plugins.sidebar.actions.refresh"),e[57]=a,e[58]=Y):Y=e[58];const Se=b?"size-4 animate-spin":"size-4";let we;e[59]!==Se?(we=s.jsx(A,{name:"refresh",className:Se}),e[59]=Se,e[60]=we):we=e[60];let ke;e[61]!==b||e[62]!==Z||e[63]!==me||e[64]!==Y||e[65]!==we?(ke=s.jsx(he,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:Z,disabled:b,"aria-label":me,title:Y,children:we}),e[61]=b,e[62]=Z,e[63]=me,e[64]=Y,e[65]=we,e[66]=ke):ke=e[66];let Fe;e[67]!==a?(Fe=a("settings.plugins.sidebar.actions.addTitle"),e[67]=a,e[68]=Fe):Fe=e[68];let Ce;e[69]!==a?(Ce=a("settings.plugins.sidebar.actions.addTitle"),e[69]=a,e[70]=Ce):Ce=e[70];let Q;e[71]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx(A,{name:"add",className:"size-4"}),e[71]=Q):Q=e[71];let ce;e[72]!==G||e[73]!==Fe||e[74]!==Ce?(ce=s.jsx(he,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:G,"aria-label":Fe,title:Ce,children:Q}),e[72]=G,e[73]=Fe,e[74]=Ce,e[75]=ce):ce=e[75];let ve;e[76]!==ke||e[77]!==ce?(ve=s.jsxs("div",{className:"flex items-center gap-1",children:[ke,ce]}),e[76]=ke,e[77]=ce,e[78]=ve):ve=e[78];let le;e[79]!==xe||e[80]!==ve?(le=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[xe,ve]}),e[79]=xe,e[80]=ve,e[81]=le):le=e[81];let Ae;e[82]!==ie||e[83]!==le?(Ae=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ie,le]}),e[82]=ie,e[83]=le,e[84]=Ae):Ae=e[84];let Te;e[85]!==O||e[86]!==M||e[87]!==V||e[88]!==X||e[89]!==fe||e[90]!==Ne||e[91]!==a||e[92]!==E||e[93]!==T||e[94]!==F?(Te=O?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(A,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.plugins.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.plugins.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[T.length>0&&Ne(a("settings.plugins.sidebar.group.userEntries"),T.map(X),E.userEntries),F.length>0&&Ne(a("settings.plugins.sidebar.group.userFiles"),F.map(fe)),M.length>0&&Ne(a("settings.plugins.sidebar.group.projectEntries"),M.map(X),E.projectEntries),V.length>0&&Ne(a("settings.plugins.sidebar.group.projectFiles"),V.map(fe))]}),e[85]=O,e[86]=M,e[87]=V,e[88]=X,e[89]=fe,e[90]=Ne,e[91]=a,e[92]=E,e[93]=T,e[94]=F,e[95]=Te):Te=e[95];let $e;e[96]!==Ae||e[97]!==Te?($e=s.jsx(ku,{variant:"background",header:Ae,children:Te}),e[96]=Ae,e[97]=Te,e[98]=$e):$e=e[98];let ye;e[99]!==C?(ye=s.jsx(e5,{open:C,onOpenChange:k}),e[99]=C,e[100]=ye):ye=e[100];const q=x!==null;let L;e[101]!==j?(L=ze=>{!ze&&!j&&h(null)},e[101]=j,e[102]=L):L=e[102];let U;e[103]!==a?(U=a("settings.plugins.sidebar.deleteDialog.title"),e[103]=a,e[104]=U):U=e[104];let oe;e[105]!==U?(oe=s.jsx(ds,{children:U}),e[105]=U,e[106]=oe):oe=e[106];const Ee=x?.label??"";let Oe;e[107]!==a||e[108]!==Ee?(Oe=a("settings.plugins.sidebar.deleteDialog.description",{name:Ee}),e[107]=a,e[108]=Ee,e[109]=Oe):Oe=e[109];let Ie;e[110]!==Oe?(Ie=s.jsx(ys,{children:Oe}),e[110]=Oe,e[111]=Ie):Ie=e[111];let z;e[112]!==oe||e[113]!==Ie?(z=s.jsxs(ps,{children:[oe,Ie]}),e[112]=oe,e[113]=Ie,e[114]=z):z=e[114];let De;e[115]===Symbol.for("react.memo_cache_sentinel")?(De=()=>h(null),e[115]=De):De=e[115];let Qe;e[116]!==a?(Qe=a("settings.common.actions.cancel"),e[116]=a,e[117]=Qe):Qe=e[117];let tt;e[118]!==j||e[119]!==Qe?(tt=s.jsx(he,{size:"sm",variant:"ghost",onClick:De,disabled:j,children:Qe}),e[118]=j,e[119]=Qe,e[120]=tt):tt=e[120];let et;e[121]!==j||e[122]!==a?(et=a(j?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[121]=j,e[122]=a,e[123]=et):et=e[123];let We;e[124]!==W||e[125]!==j||e[126]!==et?(We=s.jsx(he,{size:"sm",variant:"destructive",onClick:W,disabled:j,children:et}),e[124]=W,e[125]=j,e[126]=et,e[127]=We):We=e[127];let at;e[128]!==tt||e[129]!==We?(at=s.jsxs(Rs,{children:[tt,We]}),e[128]=tt,e[129]=We,e[130]=at):at=e[130];let qe;e[131]!==z||e[132]!==at?(qe=s.jsxs(os,{className:"max-w-md",children:[z,at]}),e[131]=z,e[132]=at,e[133]=qe):qe=e[133];let nt;e[134]!==q||e[135]!==L||e[136]!==qe?(nt=s.jsx(ls,{open:q,onOpenChange:L,children:qe}),e[134]=q,e[135]=L,e[136]=qe,e[137]=nt):nt=e[137];let Ze;return e[138]!==$e||e[139]!==ye||e[140]!==nt?(Ze=s.jsxs(s.Fragment,{children:[$e,ye,nt]}),e[138]=$e,e[139]=ye,e[140]=nt,e[141]=Ze):Ze=e[141],Ze};function i5(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function o5(t){return t.registryInfo}function l5(t){return t.isLoadingRegistry}function c5(t){return t.loadRegistryInfo}function d5(t){return t.updateToLatest}function u5(t){return t.scope==="user"}function m5(t){return t.scope==="project"}function p5(t){return t.scope==="user"}function f5(t){return t.scope==="project"}const ql=t=>{const e=ot.c(10),{children:n,className:r,outerClassName:a}=t;let i;e[0]!==a?(i=ge("h-full",a),e[0]=a,e[1]=i):i=e[1];let l;e[2]!==r?(l=ge("mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",r),e[2]=r,e[3]=l):l=e[3];let c;e[4]!==n||e[5]!==l?(c=s.jsx("div",{className:l,children:n}),e[4]=n,e[5]=l,e[6]=c):c=e[6];let d;return e[7]!==i||e[8]!==c?(d=s.jsx(vs,{outerClassName:i,className:"w-full",children:c}),e[7]=i,e[8]=c,e[9]=d):d=e[9],d},h5=({entryId:t,spec:e})=>{const{t:n}=pt(),r=Tn(u=>u.registryInfo[e]),a=Tn(u=>u.updateToLatest),[i,l]=o.useState(!1);if(!r)return null;if(r.kind==="npm-ok"){if(!r.hasUpdate||!r.latestVersion)return null;const u=r.latestVersion,p=r.currentVersion??"",b=async()=>{l(!0);try{(await a(t)).ok?K.success(n("settings.plugins.toast.updatedToLatest",{version:u})):K.error(n("settings.plugins.toast.refreshFailed"))}finally{l(!1)}};return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(A,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:n("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:n("settings.plugins.registry.banner.updateAvailable.description",{current:p,latest:u})})]}),s.jsx(he,{variant:"default",size:"sm",onClick:()=>{b()},disabled:i,children:n("settings.plugins.registry.banner.updateAvailable.action",{latest:u})})]})}if(r.kind==="path-ok")return null;if(r.kind==="npm-network")return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(A,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),s.jsx("div",{className:"flex-1 min-w-0",children:s.jsx("p",{className:"typography-micro text-muted-foreground",children:n("settings.plugins.registry.badge.network.tooltip")})})]});const c=r.kind==="path-unreadable",d=c?"var(--status-warning)":"var(--status-error)",f=c?"alert":"error-warning",m=(()=>{switch(r.kind){case"npm-missing-version":return n("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return n("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return n("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return n("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return n("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(A,{name:f,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:d}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:d},children:n("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:m})]})]})};function g5(t){const e=t.trim();if(e.length===0)return{ok:!0,value:void 0};try{const n=JSON.parse(e);return n===null||typeof n!="object"||Array.isArray(n)?{ok:!1}:{ok:!0,value:n}}catch{return{ok:!1}}}function Wg(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function Hp(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Wg(t.options),fileName:"",content:""}}function Gp(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const qp=t=>{const e=ot.c(4),{scope:n,label:r}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=ge("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=a):a=e[0];let i;return e[1]!==r||e[2]!==n?(i=s.jsx("span",{className:a,"data-scope":n,children:r}),e[1]=r,e[2]=n,e[3]=i):i=e[3],i},x5=()=>{const{t}=pt(),e=Tn(x=>x.selectedId),n=Tn(x=>x.entries),r=Tn(x=>x.files),a=Tn(x=>x.draft),i=Tn(x=>x.setDraft),l=Tn(x=>x.updateEntry),c=Tn(x=>x.updateFile),d=Tn(x=>x.readFile),f=o.useMemo(()=>e?n.find(x=>x.id===e)??null:null,[n,e]),m=o.useMemo(()=>e?r.find(x=>x.id===e)??null:null,[r,e]),[u,p]=o.useState(!1),[b,g]=o.useState(!1),y=o.useRef(new Map);if(o.useEffect(()=>{let x=!1;return f?(i(Hp(f)),()=>{x=!0}):m?(g(!0),(async()=>{const h=await d(m.id);if(x)return;g(!1);const j=h?.content??"";y.current.set(m.id,j),i(Gp(m,j))})(),()=>{x=!0}):(i(null),()=>{x=!0})},[f,m,d,i]),!e)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(A,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.plugins.page.empty.select")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.plugins.page.empty.add")})]})});if(f&&a&&a.mode==="entry"){const x=g5(a.optionsJson),h=x.ok,j=a.spec!==f.spec||a.optionsJson!==Wg(f.options),v=()=>{i(Hp(f))},C=async()=>{if(!h)return;const k=a.spec.trim();if(!k){K.error(t("settings.plugins.validation.specRequired"));return}p(!0);try{const w=await l(f.id,{spec:k,options:x.value});w.ok?w.reloadFailed?K.warning(w.message||t("settings.plugins.toast.reloadFailed"),{description:w.warning}):K.success(w.message||t("settings.plugins.toast.updated")):K.error(w.message||t("settings.plugins.toast.reloadFailed"))}finally{p(!1)}};return s.jsxs(ql,{children:[s.jsx("div",{children: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:t("settings.plugins.page.header.entry")}),s.jsx(qp,{scope:f.scope,label:f.scope==="project"?t("settings.plugins.sidebar.group.projectEntries"):t("settings.plugins.sidebar.group.userEntries")})]})}),s.jsx(h5,{entryId:f.id,spec:f.spec}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-meta text-muted-foreground",children:t("settings.plugins.page.field.spec")}),s.jsx($t,{value:a.spec,onChange:k=>i({...a,spec:k.target.value}),placeholder:t("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-meta text-muted-foreground",children:t("settings.plugins.page.field.options")}),s.jsx(ln,{value:a.optionsJson,onChange:k=>i({...a,optionsJson:k.target.value}),rows:10,className:ge("font-mono typography-meta min-h-[200px]",!h&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!h&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:t("settings.plugins.page.field.options.invalidJson")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(he,{variant:"default",size:"sm",onClick:()=>{C()},disabled:!j||!h||u,children:t("settings.plugins.page.action.save")}),s.jsx(he,{variant:"outline",size:"sm",onClick:v,disabled:!j||u,children:t("settings.plugins.page.action.discard")})]})]})}if(m&&a&&a.mode==="file"){const x=y.current.get(m.id)??"",h=a.content!==x||a.fileName!==m.fileName,j=()=>{(async()=>{g(!0);const k=(await d(m.id))?.content??"";g(!1),y.current.set(m.id,k),i(Gp(m,k))})()},v=async()=>{p(!0);try{const C=await c(m.id,{content:a.content});C.ok?(y.current.set(m.id,a.content),C.reloadFailed?K.warning(C.message||t("settings.plugins.toast.reloadFailed"),{description:C.warning}):K.success(C.message||t("settings.plugins.toast.updated"))):K.error(C.message||t("settings.plugins.toast.reloadFailed"))}finally{p(!1)}};return s.jsxs(ql,{children:[s.jsx("div",{children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.plugins.page.header.file")}),s.jsx(qp,{scope:m.scope,label:m.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:ge("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:m.fileName})]})}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-meta text-muted-foreground",children:t("settings.plugins.page.field.content")}),s.jsx(ln,{value:a.content,onChange:C=>i({...a,content:C.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:b})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(he,{variant:"default",size:"sm",onClick:()=>{v()},disabled:!h||u||b,children:t("settings.plugins.page.action.save")}),s.jsx(he,{variant:"outline",size:"sm",onClick:j,disabled:u||b,children:t("settings.plugins.page.action.discard")})]})]})}return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(A,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},b5="<built-in>",hi=t=>t?.path===b5,y5=t=>{const e=ot.c(150),{onItemSelect:n}=t,{t:r}=pt(),[a,i]=o.useState(null),[l,c]=o.useState(""),[d,f]=o.useState(null),[m,u]=o.useState(!1),[p,b]=o.useState(null),{selectedSkillName:g,skills:y,setSelectedSkill:x,setSkillDraft:h,createSkill:j,deleteSkill:v,getSkillDetail:C}=ya(Qn(v5));let k;e[0]!==n||e[1]!==x||e[2]!==h||e[3]!==y?(k=()=>{let Ge="new-skill",ct=1;for(;y.some(Pe=>Pe.name===Ge);)Ge=`new-skill-${ct}`,ct++;h({name:Ge,scope:"user",source:"opencode",description:""}),x(Ge),n?.()},e[0]=n,e[1]=x,e[2]=h,e[3]=y,e[4]=k):k=e[4];const w=k;let N;e[5]===Symbol.for("react.memo_cache_sentinel")?(N=async Ge=>{hi(Ge)||f(Ge)},e[5]=N):N=e[5];const I=N;let E;e[6]!==d||e[7]!==v||e[8]!==r?(E=async()=>{if(!d)return;if(hi(d)){f(null);return}u(!0),await v(d.name)?(K.success(r("settings.skills.sidebar.toast.skillDeleted",{name:d.name})),f(null)):K.error(r("settings.skills.sidebar.toast.deleteSkillFailed")),u(!1)},e[6]=d,e[7]=v,e[8]=r,e[9]=E):E=e[9];const P=E;let T;e[10]!==C||e[11]!==x||e[12]!==h||e[13]!==y||e[14]!==r?(T=async Ge=>{if(hi(Ge))return;const ct=Ge.name;let Pe=1,Me=`${ct}-copy`;for(;y.some(He=>He.name===Me);)Pe++,Me=`${ct}-copy-${Pe}`;const Ue=await C(Ge.name);if(!Ue){K.error(r("settings.skills.sidebar.toast.duplicateLoadFailed"));return}h({name:Me,scope:Ge.scope||"user",source:Ge.source||"opencode",description:(Ue.sources.md.fields.includes("description"),""),instructions:""}),x(Me)},e[10]=C,e[11]=x,e[12]=h,e[13]=y,e[14]=r,e[15]=T):T=e[15];const S=T;let M;e[16]===Symbol.for("react.memo_cache_sentinel")?(M=Ge=>{hi(Ge)||(c(Ge.name),i(Ge))},e[16]=M):M=e[16];const D=M;let F;e[17]!==j||e[18]!==v||e[19]!==C||e[20]!==a||e[21]!==l||e[22]!==x||e[23]!==y||e[24]!==r?(F=async()=>{if(!a)return;if(hi(a)){i(null);return}const Ge=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Ge){K.error(r("settings.skills.page.toast.skillNameRequired"));return}if(Ge===a.name){i(null);return}if(y.some(Me=>Me.name===Ge)){K.error(r("settings.skills.page.toast.skillExists"));return}if(!await C(a.name)){K.error(r("settings.skills.sidebar.toast.renameLoadFailed")),i(null);return}await j({name:Ge,description:"Renamed skill",scope:a.scope,source:a.source})?await v(a.name)?(K.success(`Skill renamed to "${Ge}"`),x(Ge)):K.error(r("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):K.error(r("settings.skills.sidebar.toast.renameFailed")),i(null)},e[17]=j,e[18]=v,e[19]=C,e[20]=a,e[21]=l,e[22]=x,e[23]=y,e[24]=r,e[25]=F):F=e[25];const _=F;let V;e[26]!==y?(V=y.filter(w5),e[26]=y,e[27]=V):V=e[27];const $=V;let O;e[28]!==y?(O=y.filter(j5),e[28]=y,e[29]=O):O=e[29];const B=O;let G;e[30]===Symbol.for("react.memo_cache_sentinel")?(G=function(ct){const Pe={},Me=[];for(const He of ct)He.group?(Pe[He.group]||(Pe[He.group]=[]),Pe[He.group].push(He)):Me.push(He);const Ue=Object.keys(Pe).sort(N5).map(He=>({name:He,skills:[...Pe[He]].sort(S5)}));return Me.sort(k5),{sortedGroups:Ue,ungrouped:Me}},e[30]=G):G=e[30];const R=G;let H;e[31]!==$?(H=R($),e[31]=$,e[32]=H):H=e[32];const J=H;let ne;e[33]!==B?(ne=R(B),e[33]=B,e[34]=ne):ne=e[34];const ue=ne;let de;e[35]===Symbol.for("react.memo_cache_sentinel")?(de=ge("flex h-full flex-col","bg-background"),e[35]=de):de=e[35];let pe;e[36]!==r?(pe=r("settings.skills.sidebar.title"),e[36]=r,e[37]=pe):pe=e[37];let W;e[38]!==pe?(W=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:pe}),e[38]=pe,e[39]=W):W=e[39];let te;e[40]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx(Mo,{className:"mb-3"}),e[40]=te):te=e[40];let X;e[41]!==y.length||e[42]!==r?(X=r("settings.skills.sidebar.total",{count:y.length}),e[41]=y.length,e[42]=r,e[43]=X):X=e[43];let ee;e[44]!==X?(ee=s.jsx("span",{className:"typography-meta text-muted-foreground",children:X}),e[44]=X,e[45]=ee):ee=e[45];let fe;e[46]===Symbol.for("react.memo_cache_sentinel")?(fe=s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[46]=fe):fe=e[46];let be;e[47]!==w?(be=s.jsx(he,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:w,children:fe}),e[47]=w,e[48]=be):be=e[48];let Ne;e[49]!==ee||e[50]!==be?(Ne=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ee,be]}),e[49]=ee,e[50]=be,e[51]=Ne):Ne=e[51];let se;e[52]!==W||e[53]!==Ne?(se=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[W,te,Ne]}),e[52]=W,e[53]=Ne,e[54]=se):se=e[54];let ie;e[55]!==J||e[56]!==ue||e[57]!==S||e[58]!==n||e[59]!==p||e[60]!==$||e[61]!==g||e[62]!==x||e[63]!==y.length||e[64]!==r||e[65]!==B?(ie=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:y.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(A,{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:[$.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")}),J.sortedGroups.map(Ge=>{const{name:ct,skills:Pe}=Ge;return s.jsx(Fd,{label:ct,count:Pe.length,storageKey:"project-skills",children:Pe.map(Me=>s.jsx(Xo,{skill:Me,isSelected:g===Me.name,onSelect:()=>{x(Me.name),n?.()},onRename:()=>D(Me),onDelete:()=>I(Me),onDuplicate:()=>S(Me),isMenuOpen:p===Me.name,onMenuOpenChange:Ue=>b(Ue?Me.name:null)},Me.name))},ct)}),J.ungrouped.map(Ge=>s.jsx(Xo,{skill:Ge,isSelected:g===Ge.name,onSelect:()=>{x(Ge.name),n?.()},onRename:()=>D(Ge),onDelete:()=>I(Ge),onDuplicate:()=>S(Ge),isMenuOpen:p===Ge.name,onMenuOpenChange:ct=>b(ct?Ge.name:null)},Ge.name))]}),B.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")}),ue.sortedGroups.map(Ge=>{const{name:ct,skills:Pe}=Ge;return s.jsx(Fd,{label:ct,count:Pe.length,storageKey:"user-skills",children:Pe.map(Me=>s.jsx(Xo,{skill:Me,isSelected:g===Me.name,onSelect:()=>{x(Me.name),n?.()},onRename:()=>D(Me),onDelete:()=>I(Me),onDuplicate:()=>S(Me),isMenuOpen:p===Me.name,onMenuOpenChange:Ue=>b(Ue?Me.name:null)},Me.name))},ct)}),ue.ungrouped.map(Ge=>s.jsx(Xo,{skill:Ge,isSelected:g===Ge.name,onSelect:()=>{x(Ge.name),n?.()},onRename:()=>D(Ge),onDelete:()=>I(Ge),onDuplicate:()=>S(Ge),isMenuOpen:p===Ge.name,onMenuOpenChange:ct=>b(ct?Ge.name:null)},Ge.name))]})]})}),e[55]=J,e[56]=ue,e[57]=S,e[58]=n,e[59]=p,e[60]=$,e[61]=g,e[62]=x,e[63]=y.length,e[64]=r,e[65]=B,e[66]=ie):ie=e[66];const ae=d!==null;let xe;e[67]!==m?(xe=Ge=>{!Ge&&!m&&f(null)},e[67]=m,e[68]=xe):xe=e[68];let Z;e[69]!==r?(Z=r("settings.skills.sidebar.deleteDialog.title"),e[69]=r,e[70]=Z):Z=e[70];let me;e[71]!==Z?(me=s.jsx(ds,{children:Z}),e[71]=Z,e[72]=me):me=e[72];const Y=d?.name??"";let Se;e[73]!==r||e[74]!==Y?(Se=r("settings.skills.sidebar.deleteDialog.description",{name:Y}),e[73]=r,e[74]=Y,e[75]=Se):Se=e[75];let we;e[76]!==Se?(we=s.jsx(ys,{children:Se}),e[76]=Se,e[77]=we):we=e[77];let ke;e[78]!==me||e[79]!==we?(ke=s.jsxs(ps,{children:[me,we]}),e[78]=me,e[79]=we,e[80]=ke):ke=e[80];let Fe;e[81]===Symbol.for("react.memo_cache_sentinel")?(Fe=()=>f(null),e[81]=Fe):Fe=e[81];let Ce;e[82]!==r?(Ce=r("settings.common.actions.cancel"),e[82]=r,e[83]=Ce):Ce=e[83];let Q;e[84]!==m||e[85]!==Ce?(Q=s.jsx(he,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Fe,disabled:m,children:Ce}),e[84]=m,e[85]=Ce,e[86]=Q):Q=e[86];let ce;e[87]!==r?(ce=r("settings.common.actions.delete"),e[87]=r,e[88]=ce):ce=e[88];let ve;e[89]!==P||e[90]!==m||e[91]!==ce?(ve=s.jsx(he,{size:"sm",onClick:P,disabled:m,children:ce}),e[89]=P,e[90]=m,e[91]=ce,e[92]=ve):ve=e[92];let le;e[93]!==Q||e[94]!==ve?(le=s.jsxs(Rs,{children:[Q,ve]}),e[93]=Q,e[94]=ve,e[95]=le):le=e[95];let Ae;e[96]!==ke||e[97]!==le?(Ae=s.jsxs(os,{className:"max-w-md",children:[ke,le]}),e[96]=ke,e[97]=le,e[98]=Ae):Ae=e[98];let Te;e[99]!==ae||e[100]!==xe||e[101]!==Ae?(Te=s.jsx(ls,{open:ae,onOpenChange:xe,children:Ae}),e[99]=ae,e[100]=xe,e[101]=Ae,e[102]=Te):Te=e[102];const $e=a!==null;let ye;e[103]===Symbol.for("react.memo_cache_sentinel")?(ye=Ge=>!Ge&&i(null),e[103]=ye):ye=e[103];let q;e[104]!==r?(q=r("settings.skills.sidebar.renameDialog.title"),e[104]=r,e[105]=q):q=e[105];let L;e[106]!==q?(L=s.jsx(ds,{children:q}),e[106]=q,e[107]=L):L=e[107];const U=a?.name??"";let oe;e[108]!==r||e[109]!==U?(oe=r("settings.skills.sidebar.renameDialog.description",{name:U}),e[108]=r,e[109]=U,e[110]=oe):oe=e[110];let Ee;e[111]!==oe?(Ee=s.jsx(ys,{children:oe}),e[111]=oe,e[112]=Ee):Ee=e[112];let Oe;e[113]!==L||e[114]!==Ee?(Oe=s.jsxs(ps,{children:[L,Ee]}),e[113]=L,e[114]=Ee,e[115]=Oe):Oe=e[115];let Ie;e[116]===Symbol.for("react.memo_cache_sentinel")?(Ie=Ge=>c(Ge.target.value),e[116]=Ie):Ie=e[116];let z;e[117]!==r?(z=r("settings.skills.sidebar.renameDialog.placeholder"),e[117]=r,e[118]=z):z=e[118];let De;e[119]!==_?(De=Ge=>{Ge.key==="Enter"&&_()},e[119]=_,e[120]=De):De=e[120];let Qe;e[121]!==l||e[122]!==z||e[123]!==De?(Qe=s.jsx($t,{value:l,onChange:Ie,placeholder:z,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:De}),e[121]=l,e[122]=z,e[123]=De,e[124]=Qe):Qe=e[124];let tt;e[125]===Symbol.for("react.memo_cache_sentinel")?(tt=()=>i(null),e[125]=tt):tt=e[125];let et;e[126]!==r?(et=r("settings.common.actions.cancel"),e[126]=r,e[127]=et):et=e[127];let We;e[128]!==et?(We=s.jsx(he,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:tt,children:et}),e[128]=et,e[129]=We):We=e[129];let at;e[130]!==r?(at=r("settings.common.actions.rename"),e[130]=r,e[131]=at):at=e[131];let qe;e[132]!==_||e[133]!==at?(qe=s.jsx(he,{size:"sm",onClick:_,children:at}),e[132]=_,e[133]=at,e[134]=qe):qe=e[134];let nt;e[135]!==We||e[136]!==qe?(nt=s.jsxs(Rs,{children:[We,qe]}),e[135]=We,e[136]=qe,e[137]=nt):nt=e[137];let Ze;e[138]!==Oe||e[139]!==Qe||e[140]!==nt?(Ze=s.jsxs(os,{children:[Oe,Qe,nt]}),e[138]=Oe,e[139]=Qe,e[140]=nt,e[141]=Ze):Ze=e[141];let ze;e[142]!==$e||e[143]!==Ze?(ze=s.jsx(ls,{open:$e,onOpenChange:ye,children:Ze}),e[142]=$e,e[143]=Ze,e[144]=ze):ze=e[144];let rt;return e[145]!==se||e[146]!==ie||e[147]!==Te||e[148]!==ze?(rt=s.jsxs("div",{className:de,children:[se,ie,Te,ze]}),e[145]=se,e[146]=ie,e[147]=Te,e[148]=ze,e[149]=rt):rt=e[149],rt},Xo=t=>{const e=ot.c(38),{skill:n,isSelected:r,onSelect:a,onDelete:i,onRename:l,onDuplicate:c,isMenuOpen:d,onMenuOpenChange:f}=t,{t:m}=pt();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=go(),e[0]=u):u=e[0];const p=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 g=b;let y;e[4]!==n?(y=hi(n),e[4]=n,e[5]=y):y=e[5];const x=y,h=r?"bg-interactive-selection":"hover:bg-interactive-hover";let j;e[6]!==h?(j=ge("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",h),e[6]=h,e[7]=j):j=e[7];let v;e[8]!==f?(v=p?void 0:S=>{S.preventDefault(),f(!0)},e[8]=f,e[9]=v):v=e[9];let C;e[10]!==n.name?(C=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[10]=n.name,e[11]=C):C=e[11];let k;e[12]!==n.scope?(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:n.scope}),e[12]=n.scope,e[13]=k):k=e[13];let w;e[14]!==g?(w=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:g}),e[14]=g,e[15]=w):w=e[15];let N;e[16]!==C||e[17]!==k||e[18]!==w?(N=s.jsxs("div",{className:"flex items-center gap-1.5",children:[C,k,w]}),e[16]=C,e[17]=k,e[18]=w,e[19]=N):N=e[19];let I;e[20]!==a||e[21]!==N?(I=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:N}),e[20]=a,e[21]=N,e[22]=I):I=e[22];let E;e[23]!==x||e[24]!==d||e[25]!==i||e[26]!==c||e[27]!==f||e[28]!==l||e[29]!==m?(E=x?null:s.jsxs(As,{open:d,onOpenChange:f,children:[s.jsx(Is,{asChild:!0,children:s.jsx(he,{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(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs(Ps,{align:"end",className:"w-fit min-w-20",children:[s.jsxs(Ot,{onClick:S=>{S.stopPropagation(),l()},children:[s.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}),s.jsxs(Ot,{onClick:S=>{S.stopPropagation(),c()},children:[s.jsx(A,{name:"file-copy",className:"h-4 w-4 mr-px"}),m("settings.common.actions.duplicate")]}),s.jsxs(Ot,{onClick:S=>{S.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]})]})]}),e[23]=x,e[24]=d,e[25]=i,e[26]=c,e[27]=f,e[28]=l,e[29]=m,e[30]=E):E=e[30];let P;e[31]!==I||e[32]!==E?(P=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[I,E]}),e[31]=I,e[32]=E,e[33]=P):P=e[33];let T;return e[34]!==P||e[35]!==j||e[36]!==v?(T=s.jsx("div",{className:j,onContextMenu:v,children:P}),e[34]=P,e[35]=j,e[36]=v,e[37]=T):T=e[37],T};function v5(t){return{selectedSkillName:t.selectedSkillName,skills:t.skills,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,createSkill:t.createSkill,deleteSkill:t.deleteSkill,getSkillDetail:t.getSkillDetail}}function w5(t){return t.scope==="project"}function j5(t){return t.scope==="user"}function N5(t,e){return t.localeCompare(e)}function S5(t,e){return t.name.localeCompare(e.name)}function k5(t,e){return t.name.localeCompare(e.name)}const C5=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,I5=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},P5=async()=>{try{const t=dr()?.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}},A5=t=>{const e=ot.c(158),{open:n,onOpenChange:r}=t,{t:a}=pt(),i=Ua(D5),l=Ua(T5),c=Ua(E5),d=tr(M5),f=tr(R5),[m,u]=o.useState(""),[p,b]=o.useState(""),[g,y]=o.useState("");let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=[],e[0]=x):x=e[0];const[h,j]=o.useState(x),[v,C]=o.useState(null),[k,w]=o.useState(!1);let N;e[1]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[1]=N):N=e[1];const[I,E]=o.useState(N),[P,T]=o.useState(null),S=o.useRef(0);let M;e[2]===Symbol.for("react.memo_cache_sentinel")?(M=ze=>{S.current=S.current+1,w(!1),C(null),ze?.clearIdentity&&(E([]),T(null))},e[2]=M):M=e[2];const D=M;let F,_;e[3]!==f||e[4]!==n?(F=()=>{n&&(S.current=S.current+1,u(""),b(""),y(""),C(null),w(!1),E([]),T(null),f(),(async()=>{const ze=await P5(),rt=Array.isArray(ze?.skillCatalogs)?ze?.skillCatalogs:[];j(rt||[])})())},_=[n,f],e[3]=f,e[4]=n,e[5]=F,e[6]=_):(F=e[5],_=e[6]),o.useEffect(F,_);let V;e[7]!==p?(V=p.trim(),e[7]=p,e[8]=V):V=e[8];const $=V;let O;e[9]!==g?(O=g.trim(),e[9]=g,e[10]=O):O=e[10];const B=O;let G;if(e[11]!==h||e[12]!==$||e[13]!==B){let ze;e[15]!==$||e[16]!==B?(ze=rt=>{const Ge=(rt.source||"").trim(),ct=(rt.subpath||"").trim();return Ge===$&&ct===B},e[15]=$,e[16]=B,e[17]=ze):ze=e[17],G=h.some(ze),e[11]=h,e[12]=$,e[13]=B,e[14]=G}else G=e[14];const R=G;let H;e[18]!==d||e[19]!==P||e[20]!==m||e[21]!==i||e[22]!==p||e[23]!==g||e[24]!==a?(H=async()=>{const ze=p.trim();if(!ze){K.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||u(I5(ze)),w(!1),C(null);const rt=S.current+1;S.current=rt;const Ge=await i({source:ze,subpath:g.trim()||void 0,gitIdentityId:P||void 0});if(S.current!==rt)return;if(!Ge.ok){if(Ge.error?.kind==="authRequired"){if(un()){K.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const Pe=Ge.error.identities||[];if(E(Pe),!P&&Pe.length>0){const Me=d&&d!=="global"&&Pe.some(Ue=>Ue.id===d)?d:Pe[0].id;T(Me)}K.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}K.error(Ge.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const ct=Ge.items?.length||0;if(C(ct),ct===0){K.error(a("settings.skills.catalog.add.toast.noSkillsFound")),w(!1);return}E([]),w(!0),K.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:ct}))},e[18]=d,e[19]=P,e[20]=m,e[21]=i,e[22]=p,e[23]=g,e[24]=a,e[25]=H):H=e[25];const J=H;let ne;e[26]!==h||e[27]!==P||e[28]!==R||e[29]!==m||e[30]!==l||e[31]!==r||e[32]!==k||e[33]!==p||e[34]!==g||e[35]!==a?(ne=async()=>{const ze=m.trim(),rt=p.trim(),Ge=g.trim();if(!ze){K.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!rt){K.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!k){K.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(R){K.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const ct={id:C5(),label:ze,source:rt,...Ge?{subpath:Ge}:{},...P?{gitIdentityId:P}:{}},Pe=[...h,ct];try{await Cs({skillCatalogs:Pe}),j(Pe),K.success(a("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),r(!1)}catch(Me){const Ue=Me;K.error(Ue instanceof Error?Ue.message:a("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=h,e[27]=P,e[28]=R,e[29]=m,e[30]=l,e[31]=r,e[32]=k,e[33]=p,e[34]=g,e[35]=a,e[36]=ne):ne=e[36];const ue=ne;let de;e[37]!==a?(de=a("settings.skills.catalog.add.title"),e[37]=a,e[38]=de):de=e[38];let pe;e[39]!==de?(pe=s.jsx(ds,{children:de}),e[39]=de,e[40]=pe):pe=e[40];let W;e[41]!==a?(W=a("settings.skills.catalog.add.descriptionPrefix"),e[41]=a,e[42]=W):W=e[42];let te;e[43]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[43]=te):te=e[43];let X;e[44]!==a?(X=a("settings.skills.catalog.add.descriptionSuffix"),e[44]=a,e[45]=X):X=e[45];let ee;e[46]!==W||e[47]!==X?(ee=s.jsxs(ys,{children:[W," ",te,X]}),e[46]=W,e[47]=X,e[48]=ee):ee=e[48];let fe;e[49]!==pe||e[50]!==ee?(fe=s.jsxs(ps,{children:[pe,ee]}),e[49]=pe,e[50]=ee,e[51]=fe):fe=e[51];let be;e[52]!==a?(be=a("settings.skills.catalog.add.field.catalogName"),e[52]=a,e[53]=be):be=e[53];let Ne;e[54]!==be?(Ne=s.jsx("label",{className:"typography-ui-label text-foreground",children:be}),e[54]=be,e[55]=Ne):Ne=e[55];let se;e[56]===Symbol.for("react.memo_cache_sentinel")?(se=ze=>u(ze.target.value),e[56]=se):se=e[56];let ie;e[57]!==a?(ie=a("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[57]=a,e[58]=ie):ie=e[58];let ae;e[59]!==m||e[60]!==ie?(ae=s.jsx($t,{value:m,onChange:se,placeholder:ie}),e[59]=m,e[60]=ie,e[61]=ae):ae=e[61];let xe;e[62]!==Ne||e[63]!==ae?(xe=s.jsxs("div",{className:"space-y-2",children:[Ne,ae]}),e[62]=Ne,e[63]=ae,e[64]=xe):xe=e[64];let Z;e[65]!==a?(Z=a("settings.skills.catalog.add.field.repository"),e[65]=a,e[66]=Z):Z=e[66];let me;e[67]!==Z?(me=s.jsx("label",{className:"typography-ui-label text-foreground",children:Z}),e[67]=Z,e[68]=me):me=e[68];let Y;e[69]===Symbol.for("react.memo_cache_sentinel")?(Y=ze=>{b(ze.target.value),D({clearIdentity:!0})},e[69]=Y):Y=e[69];let Se;e[70]!==a?(Se=a("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[70]=a,e[71]=Se):Se=e[71];let we;e[72]!==p||e[73]!==Se?(we=s.jsx($t,{value:p,onChange:Y,placeholder:Se}),e[72]=p,e[73]=Se,e[74]=we):we=e[74];let ke;e[75]!==a?(ke=a("settings.skills.catalog.add.field.repositoryHint"),e[75]=a,e[76]=ke):ke=e[76];let Fe;e[77]!==ke?(Fe=s.jsx("p",{className:"typography-micro text-muted-foreground",children:ke}),e[77]=ke,e[78]=Fe):Fe=e[78];let Ce;e[79]!==me||e[80]!==we||e[81]!==Fe?(Ce=s.jsxs("div",{className:"space-y-2",children:[me,we,Fe]}),e[79]=me,e[80]=we,e[81]=Fe,e[82]=Ce):Ce=e[82];let Q;e[83]!==a?(Q=a("settings.skills.catalog.add.field.optionalSubpath"),e[83]=a,e[84]=Q):Q=e[84];let ce;e[85]!==Q?(ce=s.jsx("label",{className:"typography-ui-label text-foreground",children:Q}),e[85]=Q,e[86]=ce):ce=e[86];let ve;e[87]===Symbol.for("react.memo_cache_sentinel")?(ve=ze=>{y(ze.target.value),D({clearIdentity:!0})},e[87]=ve):ve=e[87];let le;e[88]!==a?(le=a("settings.skills.catalog.shared.field.subpathPlaceholder"),e[88]=a,e[89]=le):le=e[89];let Ae;e[90]!==g||e[91]!==le?(Ae=s.jsx($t,{value:g,onChange:ve,placeholder:le}),e[90]=g,e[91]=le,e[92]=Ae):Ae=e[92];let Te;e[93]!==ce||e[94]!==Ae?(Te=s.jsxs("div",{className:"space-y-2",children:[ce,Ae]}),e[93]=ce,e[94]=Ae,e[95]=Te):Te=e[95];let $e;e[96]!==P||e[97]!==I||e[98]!==a?($e=I.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(ns,{value:P||"",onValueChange:ze=>{T(ze),D()},children:[s.jsx(rs,{className:"w-fit",children:s.jsx("span",{children:I.find(ze=>ze.id===P)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(as,{align:"start",children:I.map(F5)})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[96]=P,e[97]=I,e[98]=a,e[99]=$e):$e=e[99];let ye;e[100]!==v||e[101]!==a?(ye=v!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:v})}):null,e[100]=v,e[101]=a,e[102]=ye):ye=e[102];let q;e[103]!==R||e[104]!==a?(q=R?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null,e[103]=R,e[104]=a,e[105]=q):q=e[105];let L;e[106]!==xe||e[107]!==Ce||e[108]!==Te||e[109]!==$e||e[110]!==ye||e[111]!==q?(L=s.jsxs("div",{className:"space-y-4",children:[xe,Ce,Te,$e,ye,q]}),e[106]=xe,e[107]=Ce,e[108]=Te,e[109]=$e,e[110]=ye,e[111]=q,e[112]=L):L=e[112];let U;e[113]!==r?(U=()=>r(!1),e[113]=r,e[114]=U):U=e[114];let oe;e[115]!==a?(oe=a("settings.common.actions.cancel"),e[115]=a,e[116]=oe):oe=e[116];let Ee;e[117]!==U||e[118]!==oe?(Ee=s.jsx(he,{size:"sm",variant:"ghost",onClick:U,children:oe}),e[117]=U,e[118]=oe,e[119]=Ee):Ee=e[119];let Oe;e[120]!==J?(Oe=()=>{J()},e[120]=J,e[121]=Oe):Oe=e[121];let Ie;e[122]!==c||e[123]!==p?(Ie=c||!p.trim(),e[122]=c,e[123]=p,e[124]=Ie):Ie=e[124];let z;e[125]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(A,{name:"git-repository",className:"h-4 w-4"}),e[125]=z):z=e[125];let De;e[126]!==c||e[127]!==a?(De=a(c?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[126]=c,e[127]=a,e[128]=De):De=e[128];let Qe;e[129]!==Oe||e[130]!==Ie||e[131]!==De?(Qe=s.jsxs(he,{size:"sm",className:"gap-2",variant:"ghost",onClick:Oe,disabled:Ie,children:[z,De]}),e[129]=Oe,e[130]=Ie,e[131]=De,e[132]=Qe):Qe=e[132];let tt;e[133]!==ue?(tt=()=>{ue()},e[133]=ue,e[134]=tt):tt=e[134];let et;e[135]!==R||e[136]!==m||e[137]!==k||e[138]!==p?(et=!k||R||!m.trim()||!p.trim(),e[135]=R,e[136]=m,e[137]=k,e[138]=p,e[139]=et):et=e[139];let We;e[140]!==a?(We=a("settings.skills.catalog.add.actions.addCatalog"),e[140]=a,e[141]=We):We=e[141];let at;e[142]!==tt||e[143]!==et||e[144]!==We?(at=s.jsx(he,{size:"sm",onClick:tt,disabled:et,children:We}),e[142]=tt,e[143]=et,e[144]=We,e[145]=at):at=e[145];let qe;e[146]!==Ee||e[147]!==Qe||e[148]!==at?(qe=s.jsxs(Rs,{children:[Ee,Qe,at]}),e[146]=Ee,e[147]=Qe,e[148]=at,e[149]=qe):qe=e[149];let nt;e[150]!==fe||e[151]!==L||e[152]!==qe?(nt=s.jsxs(os,{className:"max-w-xl",children:[fe,L,qe]}),e[150]=fe,e[151]=L,e[152]=qe,e[153]=nt):nt=e[153];let Ze;return e[154]!==r||e[155]!==n||e[156]!==nt?(Ze=s.jsx(ls,{open:n,onOpenChange:r,children:nt}),e[154]=r,e[155]=n,e[156]=nt,e[157]=Ze):Ze=e[157],Ze};function D5(t){return t.scanRepo}function T5(t){return t.loadCatalog}function E5(t){return t.isScanning}function M5(t){return t.defaultGitIdentityId}function R5(t){return t.loadDefaultGitIdentityId}function F5(t){return s.jsx(Rt,{value:t.id,children:t.name},t.id)}const L5=t=>{const e=ot.c(85),{open:n,onOpenChange:r,conflicts:a,onConfirm:i}=t,{t:l}=pt();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={},e[0]=c):c=e[0];const[d,f]=o.useState(c);let m,u;e[1]!==a||e[2]!==n?(m=()=>{if(!n)return;const pe={};for(const W of a)pe[W.skillName]="skip";f(pe)},u=[n,a],e[1]=a,e[2]=n,e[3]=m,e[4]=u):(m=e[3],u=e[4]),o.useEffect(m,u);let p;e[5]!==a?(p=pe=>{const W={};for(const te of a)W[te.skillName]=pe;f(W)},e[5]=a,e[6]=p):p=e[6];const b=p;let g;e[7]!==a||e[8]!==d?(g=a.length>0&&a.every(pe=>d[pe.skillName]),e[7]=a,e[8]=d,e[9]=g):g=e[9];const y=g;let x;e[10]!==l?(x=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=x):x=e[11];let h;e[12]!==x?(h=s.jsx(ds,{children:x}),e[12]=x,e[13]=h):h=e[13];let j;e[14]!==l?(j=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=j):j=e[15];let v;e[16]!==j?(v=s.jsx(ys,{children:j}),e[16]=j,e[17]=v):v=e[17];let C;e[18]!==h||e[19]!==v?(C=s.jsxs(ps,{children:[h,v]}),e[18]=h,e[19]=v,e[20]=C):C=e[20];let k;e[21]!==a.length||e[22]!==l?(k=l("settings.skills.catalog.conflicts.count",{count:a.length}),e[21]=a.length,e[22]=l,e[23]=k):k=e[23];let w;e[24]!==k?(w=s.jsx("span",{className:"typography-meta text-muted-foreground",children:k}),e[24]=k,e[25]=w):w=e[25];let N;e[26]!==b?(N=()=>b("skip"),e[26]=b,e[27]=N):N=e[27];let I;e[28]!==l?(I=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=I):I=e[29];let E;e[30]!==N||e[31]!==I?(E=s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:N,children:I}),e[30]=N,e[31]=I,e[32]=E):E=e[32];let P;e[33]!==b?(P=()=>b("overwrite"),e[33]=b,e[34]=P):P=e[34];let T;e[35]!==l?(T=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=T):T=e[36];let S;e[37]!==P||e[38]!==T?(S=s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:P,children:T}),e[37]=P,e[38]=T,e[39]=S):S=e[39];let M;e[40]!==E||e[41]!==S?(M=s.jsxs("div",{className:"flex items-center gap-2",children:[E,S]}),e[40]=E,e[41]=S,e[42]=M):M=e[42];let D;e[43]!==w||e[44]!==M?(D=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w,M]}),e[43]=w,e[44]=M,e[45]=D):D=e[45];let F;if(e[46]!==a||e[47]!==d||e[48]!==l){let pe;e[50]!==d||e[51]!==l?(pe=W=>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:W.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:W.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:W.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(ns,{value:d[W.skillName]||"skip",onValueChange:te=>f(X=>({...X,[W.skillName]:te})),children:[s.jsx(rs,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(d[W.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(as,{align:"end",children:[s.jsx(Rt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(Rt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},W.skillName),e[50]=d,e[51]=l,e[52]=pe):pe=e[52],F=a.map(pe),e[46]=a,e[47]=d,e[48]=l,e[49]=F}else F=e[49];let _;e[53]!==F?(_=s.jsx("div",{className:"space-y-2",children:F}),e[53]=F,e[54]=_):_=e[54];let V;e[55]!==D||e[56]!==_?(V=s.jsxs("div",{className:"space-y-3",children:[D,_]}),e[55]=D,e[56]=_,e[57]=V):V=e[57];let $;e[58]!==r?($=()=>r(!1),e[58]=r,e[59]=$):$=e[59];let O;e[60]!==l?(O=l("settings.common.actions.cancel"),e[60]=l,e[61]=O):O=e[61];let B;e[62]!==$||e[63]!==O?(B=s.jsx(he,{size:"sm",variant:"ghost",onClick:$,children:O}),e[62]=$,e[63]=O,e[64]=B):B=e[64];let G;e[65]!==d||e[66]!==i?(G=()=>i(d),e[65]=d,e[66]=i,e[67]=G):G=e[67];const R=!y;let H;e[68]!==l?(H=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=H):H=e[69];let J;e[70]!==G||e[71]!==R||e[72]!==H?(J=s.jsx(he,{size:"sm",onClick:G,disabled:R,children:H}),e[70]=G,e[71]=R,e[72]=H,e[73]=J):J=e[73];let ne;e[74]!==B||e[75]!==J?(ne=s.jsxs(Rs,{children:[B,J]}),e[74]=B,e[75]=J,e[76]=ne):ne=e[76];let ue;e[77]!==C||e[78]!==V||e[79]!==ne?(ue=s.jsxs(os,{className:"max-w-2xl",children:[C,V,ne]}),e[77]=C,e[78]=V,e[79]=ne,e[80]=ue):ue=e[80];let de;return e[81]!==r||e[82]!==n||e[83]!==ue?(de=s.jsx(ls,{open:n,onOpenChange:r,children:ue}),e[81]=r,e[82]=n,e[83]=ue,e[84]=de):de=e[84],de},Cu=[{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 co(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 Kg(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=Cu.find(n=>n.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const O5=t=>{const e=ot.c(124),{open:n,onOpenChange:r,item:a}=t,{t:i}=pt(),l=Ua($5),c=Ua(_5),[d,f]=o.useState("user"),[m,u]=o.useState("opencode"),p=Ss(B5),b=Ss(V5),[g,y]=o.useState(null),[x,h]=o.useState(!1);let j;e[0]===Symbol.for("react.memo_cache_sentinel")?(j=[],e[0]=j):j=e[0];const[v,C]=o.useState(j),[k,w]=o.useState(null);let N,I;e[1]!==b||e[2]!==n?(N=()=>{n&&(f("user"),u("opencode"),y(b),h(!1),C([]),w(null))},I=[n,b],e[1]=b,e[2]=n,e[3]=N,e[4]=I):(N=e[3],I=e[4]),o.useEffect(N,I);let E;e[5]!==i?(E=ye=>{switch(ye){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 T;e[7]!==i?(T=ye=>{switch(ye){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]=T):T=e[8];const S=T;let M;e:{if(p.length===0){M=null;break e}if(g&&p.some(ye=>ye.id===g)){M=g;break e}if(b&&p.some(ye=>ye.id===b)){M=b;break e}M=p[0]?.id??null}const D=M;let F;e:{if(d!=="project"){F=null;break e}const ye=D;if(!ye){F=null;break e}let q;if(e[9]!==ye||e[10]!==p){let U;e[12]!==ye?(U=oe=>oe.id===ye,e[12]=ye,e[13]=U):U=e[13],q=p.find(U),e[9]=ye,e[10]=p,e[11]=q}else q=e[11];F=q?.path??null}const _=F;let V;e[14]!==l||e[15]!==a||e[16]!==r||e[17]!==i?(V=async ye=>{const q={skillDir:ye.skillDir};a?.clawdhub&&(q.clawdhub={slug:a.clawdhub.slug,version:a.clawdhub.version});const L=await l({source:ye.source,subpath:ye.subpath,gitIdentityId:a?.gitIdentityId,scope:ye.scope,targetSource:ye.targetSource,selections:[q],conflictPolicy:"prompt",conflictDecisions:ye.conflictDecisions},{directory:ye.directoryOverride??null});if(L.ok){K.success(i("settings.skills.catalog.installSkill.toast.installed")),r(!1);return}if(L.error?.kind==="conflicts"){w({source:ye.source,subpath:ye.subpath,scope:ye.scope,targetSource:ye.targetSource,skillDir:ye.skillDir,directoryOverride:ye.directoryOverride??null}),C(L.error.conflicts),h(!0);return}if(L.error?.kind==="authRequired"){K.error(L.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}K.error(L.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=a,e[16]=r,e[17]=i,e[18]=V):V=e[18];const $=V;if(!a)return null;let O;e[19]!==i?(O=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=O):O=e[20];let B;e[21]!==O?(B=s.jsx(ds,{children:O}),e[21]=O,e[22]=B):B=e[22];let G;e[23]!==i?(G=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=G):G=e[24];let R;e[25]!==a.skillName?(R=s.jsx("span",{className:"font-semibold text-foreground",children:a.skillName}),e[25]=a.skillName,e[26]=R):R=e[26];let H;e[27]!==i?(H=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=H):H=e[28];let J;e[29]!==G||e[30]!==R||e[31]!==H?(J=s.jsxs(ys,{children:[G," ",R," ",H]}),e[29]=G,e[30]=R,e[31]=H,e[32]=J):J=e[32];let ne;e[33]!==B||e[34]!==J?(ne=s.jsxs(ps,{children:[B,J]}),e[33]=B,e[34]=J,e[35]=ne):ne=e[35];let ue;e[36]!==i?(ue=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=ue):ue=e[37];let de;e[38]!==ue?(de=s.jsx("span",{className:"typography-ui-label text-foreground",children:ue}),e[38]=ue,e[39]=de):de=e[39];let pe;e[40]!==d||e[41]!==m?(pe=co(d,m),e[40]=d,e[41]=m,e[42]=pe):pe=e[42];let W;e[43]===Symbol.for("react.memo_cache_sentinel")?(W=ye=>{const q=Kg(ye);f(q.scope),u(q.source==="agents"?"agents":"opencode")},e[43]=W):W=e[43];let te;e[44]!==d?(te=d==="user"?s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=d,e[45]=te):te=e[45];let X;e[46]!==m?(X=m==="agents"?s.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=X):X=e[47];let ee;e[48]!==P||e[49]!==d||e[50]!==m?(ee=P(co(d,m)),e[48]=P,e[49]=d,e[50]=m,e[51]=ee):ee=e[51];let fe;e[52]!==ee?(fe=s.jsx("span",{children:ee}),e[52]=ee,e[53]=fe):fe=e[53];let be;e[54]!==te||e[55]!==X||e[56]!==fe?(be=s.jsxs(rs,{className:"w-fit gap-1.5",children:[te,X,fe]}),e[54]=te,e[55]=X,e[56]=fe,e[57]=be):be=e[57];let Ne;e[58]!==S||e[59]!==P?(Ne=Cu.map(ye=>s.jsx(Rt,{value:ye.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:[ye.scope==="user"?s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),ye.source==="agents"?s.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:P(ye.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:S(ye.value)})]})},ye.value)),e[58]=S,e[59]=P,e[60]=Ne):Ne=e[60];let se;e[61]!==Ne?(se=s.jsx(as,{align:"start",children:Ne}),e[61]=Ne,e[62]=se):se=e[62];let ie;e[63]!==pe||e[64]!==be||e[65]!==se?(ie=s.jsxs(ns,{value:pe,onValueChange:W,children:[be,se]}),e[63]=pe,e[64]=be,e[65]=se,e[66]=ie):ie=e[66];let ae;e[67]!==de||e[68]!==ie?(ae=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[de,ie]}),e[67]=de,e[68]=ie,e[69]=ae):ae=e[69];let xe;e[70]!==p||e[71]!==D||e[72]!==d||e[73]!==i?(xe=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")}),p.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(ns,{value:D??"",onValueChange:ye=>y(ye),disabled:p.length===1,children:[s.jsx(rs,{className:"w-fit",children:s.jsx(ms,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(as,{align:"start",children:p.map(z5)})]})]}),e[70]=p,e[71]=D,e[72]=d,e[73]=i,e[74]=xe):xe=e[74];let Z;e[75]!==a.warnings?(Z=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]=Z):Z=e[76];let me;e[77]!==ae||e[78]!==xe||e[79]!==Z?(me=s.jsxs("div",{className:"mt-2 space-y-3",children:[ae,xe,Z]}),e[77]=ae,e[78]=xe,e[79]=Z,e[80]=me):me=e[80];let Y;e[81]!==r?(Y=()=>r(!1),e[81]=r,e[82]=Y):Y=e[82];let Se;e[83]!==i?(Se=i("settings.common.actions.cancel"),e[83]=i,e[84]=Se):Se=e[84];let we;e[85]!==Y||e[86]!==Se?(we=s.jsx(he,{size:"sm",variant:"ghost",onClick:Y,children:Se}),e[85]=Y,e[86]=Se,e[87]=we):we=e[87];const ke=c||!a.installable||d==="project"&&!_;let Fe;e[88]!==_||e[89]!==$||e[90]!==a.repoSource||e[91]!==a.repoSubpath||e[92]!==a.skillDir||e[93]!==d||e[94]!==m?(Fe=()=>{$({source:a.repoSource,subpath:a.repoSubpath,scope:d,targetSource:m,skillDir:a.skillDir,directoryOverride:_})},e[88]=_,e[89]=$,e[90]=a.repoSource,e[91]=a.repoSubpath,e[92]=a.skillDir,e[93]=d,e[94]=m,e[95]=Fe):Fe=e[95];let Ce;e[96]!==c||e[97]!==i?(Ce=i(c?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=c,e[97]=i,e[98]=Ce):Ce=e[98];let Q;e[99]!==ke||e[100]!==Fe||e[101]!==Ce?(Q=s.jsx(he,{size:"sm",disabled:ke,onClick:Fe,children:Ce}),e[99]=ke,e[100]=Fe,e[101]=Ce,e[102]=Q):Q=e[102];let ce;e[103]!==we||e[104]!==Q?(ce=s.jsxs(Rs,{children:[we,Q]}),e[103]=we,e[104]=Q,e[105]=ce):ce=e[105];let ve;e[106]!==ne||e[107]!==me||e[108]!==ce?(ve=s.jsxs(os,{className:"max-w-md",children:[ne,me,ce]}),e[106]=ne,e[107]=me,e[108]=ce,e[109]=ve):ve=e[109];let le;e[110]!==r||e[111]!==n||e[112]!==ve?(le=s.jsx(ls,{open:n,onOpenChange:r,children:ve}),e[110]=r,e[111]=n,e[112]=ve,e[113]=le):le=e[113];let Ae;e[114]!==k||e[115]!==$?(Ae=ye=>{k&&($({source:k.source,subpath:k.subpath,scope:k.scope,targetSource:k.targetSource,skillDir:k.skillDir,conflictDecisions:ye,directoryOverride:k.directoryOverride??null}),h(!1))},e[114]=k,e[115]=$,e[116]=Ae):Ae=e[116];let Te;e[117]!==v||e[118]!==x||e[119]!==Ae?(Te=s.jsx(L5,{open:x,onOpenChange:h,conflicts:v,onConfirm:Ae}),e[117]=v,e[118]=x,e[119]=Ae,e[120]=Te):Te=e[120];let $e;return e[121]!==le||e[122]!==Te?($e=s.jsxs(s.Fragment,{children:[le,Te]}),e[121]=le,e[122]=Te,e[123]=$e):$e=e[123],$e};function $5(t){return t.installSkills}function _5(t){return t.isInstalling}function B5(t){return t.projects}function V5(t){return t.activeProjectId}function z5(t){return s.jsx(Rt,{value:t.id,children:t.label||t.path},t.id)}const U5=async()=>{try{const t=dr()?.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}},W5=({mode:t,onModeChange:e,showModeTabs:n=!0})=>{const{t:r}=pt(),{sources:a,itemsBySource:i,selectedSourceId:l,setSelectedSource:c,loadCatalog:d,loadSource:f,loadMoreClawdHub:m,isLoadingCatalog:u,isLoadingSource:p,isLoadingMore:b,loadedSourceIds:g,clawdhubHasMoreBySource:y,lastCatalogError:x}=Ua(Qn(B=>({sources:B.sources,itemsBySource:B.itemsBySource,selectedSourceId:B.selectedSourceId,setSelectedSource:B.setSelectedSource,loadCatalog:B.loadCatalog,loadSource:B.loadSource,loadMoreClawdHub:B.loadMoreClawdHub,isLoadingCatalog:B.isLoadingCatalog,isLoadingSource:B.isLoadingSource,isLoadingMore:B.isLoadingMore,loadedSourceIds:B.loadedSourceIds,clawdhubHasMoreBySource:B.clawdhubHasMoreBySource,lastCatalogError:B.lastCatalogError}))),[h,j]=o.useState(""),[v,C]=o.useState(!1),[k,w]=o.useState(!1),[N,I]=o.useState(null),[E,P]=o.useState(!1),[T,S]=o.useState(!1);o.useEffect(()=>{d()},[d]),o.useEffect(()=>{l&&(g[l]||f(l))},[l,g,f]);const M=o.useMemo(()=>l?i[l]||[]:[],[i,l]),D=o.useMemo(()=>{const B=h.trim().toLowerCase();return B?M.filter(G=>{const R=G.skillName.toLowerCase(),H=(G.description||"").toLowerCase(),J=(G.frontmatterName||"").toLowerCase();return R.includes(B)||H.includes(B)||J.includes(B)}):M},[M,h]),F=o.useMemo(()=>a.find(B=>B.id===l)||null,[a,l]),_=!!(l&&l.startsWith("custom:")),V=F?.source==="clawdhub:registry"||F?.sourceType==="clawdhub",$=!!(l&&(y[l]??!0)),O=async()=>{if(!(!l||!_)){P(!0);try{const B=await U5(),R=(Array.isArray(B?.skillCatalogs)?B?.skillCatalogs:[]).filter(H=>H.id!==l);await Cs({skillCatalogs:R}),await d({refresh:!0}),S(!1)}finally{P(!1)}}};return s.jsx(vs,{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(Fr,{items:[{id:"manual",label:r("settings.skills.catalog.page.mode.manual")},{id:"external",label:r("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:B=>e(B),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(ns,{value:l||"",onValueChange:B=>c(B),children:[s.jsx(rs,{className:"w-fit",children:s.jsx(ms,{placeholder:r("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:F?.label})}),s.jsx(as,{align:"start",children:a.map(B=>s.jsx(Rt,{value:B.id,children:B.label},B.id))})]}),s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l?f(l,{refresh:!0}):d({refresh:!0})},disabled:u||p,title:r("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(A,{name:"refresh",className:ge("h-3.5 w-3.5",(u||p)&&"animate-spin")})}),_&&s.jsx(he,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>S(!0),disabled:E,title:r("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(he,{size:"xs",className:"!font-normal gap-1",onClick:()=>C(!0),children:[s.jsx(A,{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(A,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx($t,{value:h,onChange:B=>j(B.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:D.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:D.length===0&&!p?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")})]}):p?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(A,{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:D.map(B=>{const G=B.installed?.isInstalled,R=B.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:B.skillName}),G&&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:R||r("settings.skills.catalog.page.badge.unknown")})}),!B.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")})]}),B.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:B.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:r("settings.skills.catalog.shared.noDescription")}),B.clawdhub&&s.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[B.clawdhub.owner&&s.jsxs("span",{children:[r("settings.skills.catalog.page.byOwnerPrefix")," ",s.jsx("span",{className:"font-medium text-foreground/80",children:B.clawdhub.owner})]}),s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(A,{name:"download",className:"h-3 w-3"}),B.clawdhub.downloads?.toLocaleString()??0]}),(B.clawdhub.stars??0)>0&&s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(A,{name:"star",className:"h-3 w-3"}),B.clawdhub.stars]}),s.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",B.clawdhub.version]})]}),B.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:B.warnings.join(" · ")}):null]}),s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!B.installable,onClick:()=>{I(B),w(!0)},children:r("settings.skills.catalog.shared.actions.install")})]})},`${B.sourceId}:${B.skillDir}`)})})}),V&&$&&!p&&D.length>0&&s.jsx("div",{className:"flex justify-center mt-2 px-2",children:s.jsx(he,{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(A5,{open:v,onOpenChange:C}),s.jsx(O5,{open:k,onOpenChange:w,item:N}),s.jsx(ls,{open:T,onOpenChange:B=>{E||S(B)},children:s.jsxs(os,{className:"max-w-md",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:r("settings.skills.catalog.page.removeDialog.title")}),s.jsx(ys,{children:r("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(Rs,{children:[s.jsx(he,{size:"sm",variant:"ghost",onClick:()=>S(!1),disabled:E,children:r("settings.common.actions.cancel")}),s.jsx(he,{size:"sm",variant:"destructive",onClick:()=>{O()},disabled:E,children:r("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})},K5=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(W5,{mode:"external",onModeChange:Q5,showModeTabs:!1}),t[0]=e):e=t[0],e},H5="SKILL.md",G5="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",Nl=(t,e)=>{const n=nb({description:t}).trimEnd(),r=e.trimStart();return`---
|
|
183
|
+
${n}
|
|
184
|
+
---${r?`
|
|
185
|
+
|
|
186
|
+
${r}`:`
|
|
187
|
+
`}`},q5=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Hg=t=>{const e=t.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/);if(!e)return{description:null,instructions:t};let n=null;try{const r=rb(e[1]);if(q5(r)){const a=r.description;typeof a=="string"&&(n=a)}}catch{n=null}return{description:n,instructions:e[2].replace(/^\r?\n/,"")}},J5=(t,e)=>{const n=Hg(t);return Nl(e,n.instructions)},Y5=()=>{const{t}=pt(),{currentTheme:e}=Sr(),{selectedSkillName:n,getSkillByName:r,getSkillDetail:a,createSkill:i,updateSkill:l,skills:c,skillDraft:d,setSkillDraft:f,setSelectedSkill:m}=ya(Qn(ye=>({selectedSkillName:ye.selectedSkillName,getSkillByName:ye.getSkillByName,getSkillDetail:ye.getSkillDetail,createSkill:ye.createSkill,updateSkill:ye.updateSkill,skills:ye.skills,skillDraft:ye.skillDraft,setSkillDraft:ye.setSkillDraft,setSelectedSkill:ye.setSelectedSkill}))),u=n?r(n):null,p=!!(d&&d.name===n&&!u),b=!!(n&&!u&&!d),g=u?.path==="<built-in>";o.useEffect(()=>{b&&m(null)},[b,m]);const[y,x]=o.useState(""),[h,j]=o.useState("user"),[v,C]=o.useState("opencode"),[k,w]=o.useState(""),[N,I]=o.useState(""),[E,P]=o.useState(()=>Nl("","")),[T,S]=o.useState("edit"),[M,D]=o.useState([]),[F,_]=o.useState([]),[V,$]=o.useState(!1),[O,B]=o.useState(!1),[G,R]=o.useState(""),[H,J]=o.useState(""),[ne,ue]=o.useState(!1),[de,pe]=o.useState(""),[W,te]=o.useState(""),[X,ee]=o.useState(null),[fe,be]=o.useState(!1),[Ne,se]=o.useState(""),[ie,ae]=o.useState(null),[xe,Z]=o.useState(!1),me=p?y.trim()!==""||k.trim()!==""||N.trim()!==""||F.length>0:k!==G||N!==H,Y=X?W!==Ne:de.trim()!=="",Se=o.useCallback(ye=>{switch(ye){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]),we=o.useCallback(ye=>{switch(ye){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]);o.useEffect(()=>{(async()=>{if(p&&d){const q=d.description||"",L=d.instructions||"";x(d.name||""),j(d.scope||"user"),C(d.source==="agents"?"agents":"opencode"),w(q),I(L),P(Nl(q,L)),R(""),J(""),D([]),_(d.pendingFiles||[])}else if(n&&u){B(!0);try{const q=await a(n);if(q){const L=q.sources.md,U=L.description||"",oe=L.instructions||"";w(U),I(oe),P(Nl(U,oe)),R(U),J(oe),D(L.supportingFiles||[])}}catch(q){console.error("Failed to load skill details:",q)}finally{B(!1)}}})()},[u,p,n,c,d,a]);const ke=o.useMemo(()=>{const ye=[ko(e)],q=Fl(H5);return q&&ye.push(q),ye.push(zn.lineWrapping),ye},[e]),Fe=o.useMemo(()=>{const ye=de.trim()||"supporting-file.md",q=[ko(e)],L=Fl(ye);return L&&q.push(L),q.push(zn.lineWrapping),q},[e,de]),Ce=o.useCallback(ye=>{w(ye),P(q=>J5(q,ye))},[]),Q=o.useCallback(ye=>{P(ye);const q=Hg(ye);w(q.description??""),I(q.instructions)},[]),ce=async()=>{const ye=p?y.trim().replace(/\s+/g,"-").toLowerCase():n?.trim();if(!ye){K.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(ye)||ye.length>64){K.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!k.trim()){K.error(t("settings.skills.page.toast.descriptionRequired"));return}if(p&&c.some(q=>q.name===ye)){K.error(t("settings.skills.page.toast.skillExists"));return}$(!0);try{const q={name:ye,description:k.trim(),instructions:N.trim()||void 0,scope:p?h:void 0,source:p?v:void 0,targetPath:p?void 0:u?.path,supportingFiles:p&&F.length>0?F:void 0};let L;p?(L=await i(q),L&&(f(null),_([]),m(ye))):(L=await l(ye,q),L&&(R(k.trim()),J(N.trim()))),L?K.success(t(p?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated")):K.error(t(p?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(q){console.error("Error saving skill:",q),K.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{$(!1)}},ve=()=>{ee(null),pe(""),te(""),se(""),ue(!0)},le=async ye=>{if(ee(ye),pe(ye),p){const L=F.find(U=>U.path===ye)?.content||"";te(L),se(L),ue(!0);return}if(n){be(!0),ue(!0);try{const{readSupportingFile:q}=ya.getState(),L=await q(n,ye);te(L||""),se(L||"")}catch{K.error(t("settings.skills.page.toast.loadFileContentFailed")),te(""),se("")}finally{be(!1)}}},Ae=async()=>{if(!de.trim()){K.error(t("settings.skills.page.toast.fileNameRequired"));return}const ye=de.trim(),q=X!==null;if(p){if(q)_(oe=>oe.map(Ee=>Ee.path===X?{path:ye,content:W}:Ee)),K.success(t("settings.skills.page.toast.fileUpdated",{path:ye}));else{if(F.some(oe=>oe.path===ye)){K.error(t("settings.skills.page.toast.fileExists"));return}_(oe=>[...oe,{path:ye,content:W}]),K.success(t("settings.skills.page.toast.fileAdded",{path:ye}))}ue(!1),ee(null);return}if(!n){K.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:L}=ya.getState();if(await L(n,ye,W)){K.success(q?t("settings.skills.page.toast.fileUpdated",{path:ye}):t("settings.skills.page.toast.fileCreated",{path:ye})),ue(!1),ee(null);const oe=await a(n);oe&&D(oe.sources.md.supportingFiles||[])}else K.error(t(q?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Te=ye=>{if(p){_(q=>q.filter(L=>L.path!==ye)),K.success(t("settings.skills.page.toast.fileRemoved",{path:ye}));return}n&&ae(ye)},$e=async()=>{if(!ie||!n)return;Z(!0);const{deleteSupportingFile:ye}=ya.getState();if(await ye(n,ie)){K.success(t("settings.skills.page.toast.fileDeleted",{path:ie}));const L=await a(n);L&&D(L.sources.md.supportingFiles||[]),ae(null)}else K.error(t("settings.skills.page.toast.deleteFileFailed"));Z(!1)};return!n&&!d||b?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(A,{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")})]})}):O?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(vs,{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:p?t("settings.skills.page.title.newSkill"):n}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:u?t("settings.skills.page.subtitle.skillLocation",{location:Se(co(u.scope,u.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:[p&&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($t,{value:y,onChange:ye=>x(ye.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(ns,{value:co(h,v),onValueChange:ye=>{const q=Kg(ye);j(q.scope),C(q.source==="agents"?"agents":"opencode")},children:[s.jsxs(rs,{className:"w-fit gap-1.5",children:[h==="user"?s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),v==="agents"?s.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Se(co(h,v))})]}),s.jsx(as,{align:"start",children:Cu.map(ye=>s.jsx(Rt,{value:ye.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[ye.scope==="user"?s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),ye.source==="agents"?s.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Se(ye.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:we(ye.value)})]})},ye.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(ln,{value:k,onChange:ye=>Ce(ye.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent",disabled:g})})]})]})]}),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.skills.page.section.instructions")}),s.jsx(Kl,{currentMode:T==="preview"?"preview":"edit",onToggle:()=>S(ye=>ye==="preview"?"edit":"preview")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx("div",{className:ge("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",G5),children:T==="preview"?s.jsx(vs,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(Na,{content:E,className:"typography-markdown-body",stripFrontmatter:!0})})}):s.jsx(So,{value:E,onChange:Q,readOnly:g,extensions:ke,className:"h-full",enableSearch:!0})})})]}),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(he,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:ve,disabled:g,children:[s.jsx(A,{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 ye=p?F:M;return ye.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:ye.map(q=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>le(q.path),children:[s.jsx(A,{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:q.path}),p&&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")}),!g&&s.jsx(he,{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:L=>{L.stopPropagation(),Te(q.path)},children:s.jsx(A,{name:"delete-bin",className:"h-3 w-3"})})]},q.path))})})()})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(he,{onClick:ce,disabled:g||V||!me,size:"xs",className:"!font-normal",children:t(V?"settings.common.actions.saving":p?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(ls,{open:ie!==null,onOpenChange:ye=>{!ye&&!xe&&ae(null)},children:s.jsxs(os,{className:"max-w-md",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(ys,{children:t("settings.skills.page.deleteFileDialog.description",{path:ie??""})})]}),s.jsxs(Rs,{children:[s.jsx(he,{size:"sm",variant:"ghost",onClick:()=>ae(null),disabled:xe,children:t("settings.common.actions.cancel")}),s.jsx(he,{size:"sm",variant:"destructive",onClick:$e,disabled:xe,children:t("settings.common.actions.delete")})]})]})}),s.jsx(ls,{open:ne,onOpenChange:ye=>{ue(ye),ye||ee(null)},children:s.jsxs(os,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(ps,{className:"flex-shrink-0",children:[s.jsx(ds,{children:t(X?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(ys,{children:t(X?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),fe?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($t,{value:de,onChange:ye=>pe(ye.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:X!==null}),!X&&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("div",{className:"h-[45vh] min-h-[250px] max-h-[55vh] overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",children:s.jsx(So,{value:W,onChange:te,extensions:Fe,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(Rs,{className:"mt-4",children:[s.jsx(he,{size:"sm",variant:"ghost",onClick:()=>{ue(!1),ee(null)},children:t("settings.common.actions.cancel")}),s.jsx(he,{size:"sm",onClick:Ae,disabled:fe||!Y,children:t(X?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},Jp=t=>{const e=ot.c(2),{view:n}=t,r=n===void 0?"installed":n;let a;return e[0]!==r?(a=r==="catalog"?s.jsx(K5,{}):s.jsx(Y5,{}),e[0]=r,e[1]=a):a=e[1],a};function Q5(){}const X5=t=>{const e=ot.c(41),{onItemSelect:n}=t,{t:r}=pt(),a=Ss(Z5),i=_e(eC),l=_e(tC),{currentTheme:c}=Sr();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[0]=d):d=e[0];const[f,m]=o.useState(d);let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=un(),e[1]=u):u=e[1];const p=u,b=sC;let g,y;e[2]!==a||e[3]!==i||e[4]!==l?(g=()=>{if(a.length===0){i!==null&&l(null);return}i&&a.some(P=>P.id===i)||l(a[0].id)},y=[a,i,l],e[2]=a,e[3]=i,e[4]=l,e[5]=g,e[6]=y):(g=e[5],y=e[6]),o.useEffect(g,y);let x;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=ge("border-b px-3","pt-4 pb-3"),e[7]=x):x=e[7];let h;e[8]!==r?(h=r("settings.page.projects.title"),e[8]=r,e[9]=h):h=e[9];let j;e[10]!==h?(j=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:h}),e[10]=h,e[11]=j):j=e[11];let v;e[12]!==a.length||e[13]!==r?(v=r("settings.projects.sidebar.total",{count:a.length}),e[12]=a.length,e[13]=r,e[14]=v):v=e[14];let C;e[15]!==v?(C=s.jsx("span",{className:"typography-meta text-muted-foreground",children:v}),e[15]=v,e[16]=C):C=e[16];let k;e[17]!==r?(k=!p&&s.jsx(he,{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(A,{name:"add",className:"size-4"})}),e[17]=r,e[18]=k):k=e[18];let w;e[19]!==k||e[20]!==C?(w=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[C,k]}),e[19]=k,e[20]=C,e[21]=w):w=e[21];let N;e[22]!==w||e[23]!==j?(N=s.jsxs("div",{className:x,children:[j,w]}),e[22]=w,e[23]=j,e[24]=N):N=e[24];let I;if(e[25]!==f||e[26]!==c||e[27]!==n||e[28]!==a||e[29]!==i||e[30]!==l){let P;e[32]!==f||e[33]!==c||e[34]!==n||e[35]!==i||e[36]!==l?(P=T=>{const S=T.id===i,M=T.icon?oc[T.icon]:null,D=`${T.id}:${T.iconImage?.updatedAt??0}`,F=f.has(D)?null:Do(T,{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),_=T.color?To[T.color]??null:null,V=F?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:T.iconBackground?{backgroundColor:T.iconBackground}:void 0,children:s.jsx("img",{src:F,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>{m($=>{if($.has(D))return $;const O=new Set($);return O.add(D),O})}})}):M?s.jsx(A,{name:M,className:ge("h-4 w-4",S?"text-foreground":"text-muted-foreground/70"),style:_?{color:_}:void 0}):s.jsx(A,{name:"folder",className:ge("h-4 w-4",S?"text-foreground":"text-muted-foreground/70"),style:_?{color:_}:void 0});return s.jsx(Gl,{title:T.label||T.path,icon:V,selected:S,onSelect:()=>{l(T.id),n?.()}},T.id)},e[32]=f,e[33]=c,e[34]=n,e[35]=i,e[36]=l,e[37]=P):P=e[37],I=a.map(P),e[25]=f,e[26]=c,e[27]=n,e[28]=a,e[29]=i,e[30]=l,e[31]=I}else I=e[31];let E;return e[38]!==N||e[39]!==I?(E=s.jsx(ku,{variant:"background",header:N,children:I}),e[38]=N,e[39]=I,e[40]=E):E=e[40],E};function Z5(t){return t.projects}function eC(t){return t.settingsProjectsSelectedId}function tC(t){return t.setSettingsProjectsSelectedId}function sC(){Mr.requestDirectoryDialog()}const nC=({projectRef:t=null})=>{const{t:e}=pt(),{isMobile:n,isTablet:r}=an(),a=n||r,i=Ss(M=>M.getActiveProject()),l=t?.path??i?.path??null,c=Lt(M=>M.getWorktreeMetadata),d=ic(),f=Ms(M=>M.homeDirectory),[m,u]=o.useState([]),[p,b]=o.useState(!1),[g,y]=o.useState(null),[x,h]=o.useState([]),[j,v]=o.useState(!1),C=o.useMemo(()=>t?.id&&t?.path?{id:t.id,path:t.path}:!i?.id||!l?null:{id:i.id,path:l},[i?.id,l,t?.id,t?.path]),k=o.useCallback(async()=>{if(!(!C||g===!1))try{const M=await gd(C);h(M)}catch{}},[C,g]);o.useEffect(()=>{if(!l)return;let M=!1;return y(null),(async()=>{try{const D=await Eh(l);if(M)return;y(D)}catch{}})(),()=>{M=!0}},[l]),o.useEffect(()=>{if(!C){h([]),v(!1);return}if(g===!1){h([]),v(!1);return}let M=!1;return v(!0),h([]),(async()=>{try{const D=await gd(C);if(M)return;h(D)}catch{}finally{M||v(!1)}})(),()=>{M=!0}},[C,g]),o.useEffect(()=>{if(!C)return;let M=!1;return b(!0),(async()=>{try{const D=await cu(C);M||u(D.length>0?D:[""])}catch{M||u([""])}finally{M||b(!1)}})(),()=>{M=!0}},[C]);const w=o.useCallback((M,D)=>{u(F=>{const _=[...F];return _[M]=D,_})},[]),N=o.useCallback(()=>{u(M=>[...M,""])},[]),I=o.useCallback(async M=>{if(!C)return;const D=M.filter(F=>F.trim().length>0);await Mh(C,D)},[C]),E=o.useCallback(M=>{u(D=>{const F=D.filter((_,V)=>V!==M);return I(F),F.length>0?F:[""]})},[I]),P=o.useCallback(()=>{I(m)},[I,m]),T=o.useCallback(M=>{const D=R=>R.replace(/\\/g,"/").replace(/\/+$/,""),F=D(M.path),_=d.filter(R=>{const H=c(R.id);if(H?.path&&D(H.path)===F)return!0;const J=R.directory;return!!(J&&D(J)===F)}),V=new Set(_.map(R=>R.id)),$=R=>{const H=d.filter(ne=>{const ue=ne.parentID;return ue&&R.has(ue)});if(H.length===0)return[];const J=new Set(H.map(ne=>ne.id));return[...H,...$(J)]},O=$(V),B=new Set,G=[..._,...O].filter(R=>B.has(R.id)?!1:(B.add(R.id),!0));Mr.requestDelete({sessions:G,mode:"worktree",worktree:M})},[d,c]),S=o.useMemo(()=>d.map(M=>M.id).join(","),[d]);return o.useEffect(()=>{g&&l&&k()},[S,g,l,k]),l?g===!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(A,{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")]})]})]})}),p?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((M,D)=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx($t,{value:M,onChange:F=>w(D,F.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(D)},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(A,{name:"close",className:"h-4 w-4"})})]},D)),s.jsxs(he,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:N,children:[s.jsx(A,{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(A,{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")})]})]})}),j?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(M=>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:M.label||M.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:xo(M.path,f)})]}),s.jsx("button",{type:"button",onClick:()=>T(M),className:ge("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:M.branch||M.label||M.path}),children:s.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})]},M.path))})]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.selectProject")})},rC=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,aC=()=>({id:rC(),name:"",command:"",icon:"play"}),iC=({projectRef:t})=>{const{t:e}=pt(),n=o.useMemo(()=>In(),[]),r=Js(N=>N.instances),a=Js(N=>N.load),[i,l]=o.useState([]),[c,d]=o.useState(!1),[f,m]=o.useState(!1),[u,p]=o.useState(null),[b,g]=o.useState({});o.useEffect(()=>{n&&a().catch(()=>{})},[n,a]),o.useEffect(()=>{let N=!1;return d(!0),(async()=>{try{const I=await hd(t);if(N)return;l(I.actions),p(JSON.stringify({actions:I.actions}))}catch{if(N)return;l([]),p(JSON.stringify({actions:[]}))}finally{N||d(!1)}})(),()=>{N=!0}},[t]);const y=o.useMemo(()=>n?ng(r):[],[r,n]),x=o.useMemo(()=>i.some(I=>I.name.trim().length===0||I.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[i,e]),h=o.useMemo(()=>u===null?!1:u!==JSON.stringify({actions:i}),[i,u]),j=o.useCallback(()=>{const N=aC();l(I=>[...I,N]),g(I=>({...I,[N.id]:!0}))},[]),v=o.useCallback(N=>{l(I=>I.filter(E=>E.id!==N)),g(I=>{const E={...I};return delete E[N],E})},[]),C=o.useCallback((N,I)=>{l(E=>E.map(P=>P.id===N?I(P):P))},[]),k=o.useCallback(async()=>{if(x){K.error(x);return}m(!0);try{if(!await wy(t,{actions:i,primaryActionId:null})){K.error(e("settings.projects.actions.toast.saveFailed"));return}p(JSON.stringify({actions:i})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(Nd,{detail:{projectId:t.id}})),K.success(e("settings.projects.actions.toast.saved"))}catch{K.error(e("settings.projects.actions.toast.saveFailed"))}finally{m(!1)}},[i,t,e,x]),w=!f&&!c&&h&&!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(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:j,children:[s.jsx(A,{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(N=>{const I=N.icon||"play",E=hl[I]||"play",P=b[N.id]??!1,T=N.name.trim()||e("settings.projects.actions.state.untitled");return s.jsxs(jr,{open:P,onOpenChange:S=>{g(M=>({...M,[N.id]:S}))},className:ge("py-1.5"),children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs(Lr,{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(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx(A,{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:T})})})]}),s.jsx(he,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>v(N.id),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(Nr,{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(As,{children:[s.jsx(Is,{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(A,{name:E,className:"h-4 w-4"})})}),s.jsx(Ps,{align:"start",className:"w-56 p-2",children:s.jsx("div",{className:"grid grid-cols-6 gap-1",children:tg.map(S=>{const M=S.Icon,D=(N.icon||"play")===S.key;return s.jsx("button",{type:"button",onClick:()=>C(N.id,F=>({...F,icon:S.key})),className:ge("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",D&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:S.label}),children:s.jsx(A,{name:M,className:"h-4 w-4"})},S.key)})})})]}),s.jsx($t,{value:N.name,onChange:S=>C(N.id,M=>({...M,name:S.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(ln,{value:N.command,onChange:S=>C(N.id,M=>({...M,command:S.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":N.autoOpenUrl===!0,onClick:()=>C(N.id,S=>({...S,...S.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:S=>{(S.key===" "||S.key==="Enter")&&(S.preventDefault(),C(N.id,M=>({...M,...M.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[s.jsx(fs,{checked:N.autoOpenUrl===!0,onChange:S=>C(N.id,M=>({...M,...S?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:T})}),s.jsx("span",{className:"typography-ui-label font-normal text-foreground/80",children:e("settings.projects.actions.field.autoOpenUrlDescription")})]})]}),N.autoOpenUrl===!0?s.jsxs("div",{className:"mt-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx($t,{value:N.openUrl||"",onChange:S=>C(N.id,M=>({...M,openUrl:S.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(A,{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")}),y.length>0?s.jsxs(ns,{value:N.desktopOpenSshForward&&y.some(S=>S.id===N.desktopOpenSshForward)?N.desktopOpenSshForward:"__none__",onValueChange:S=>{C(N.id,M=>({...M,...S==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:S}}))},children:[s.jsx(rs,{className:"h-7 w-full max-w-[30rem]",children:s.jsx(ms,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),s.jsxs(as,{children:[s.jsx(Rt,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),y.map(S=>s.jsx(Rt,{value:S.id,children:S.label},S.id))]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.noDesktopSshForwards")})]}):null]}):null]})]})})]},N.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(he,{type:"button",size:"xs",className:"!font-normal",onClick:k,disabled:!w,children:e(f?"settings.common.actions.saving":"settings.projects.actions.actions.save")})]})]})]})},oC=()=>{const t=ot.c(201),{t:e}=pt(),n=Ss(lC),r=Ss(cC),a=Ss(dC),i=Ss(uC),l=Ss(mC),c=_e(pC),d=_e(fC),{currentTheme:f}=Sr();let m;e:{if(!c){m=null;break e}let wt;t[0]!==n||t[1]!==c?(wt=n.find(Zt=>Zt.id===c)??null,t[0]=n,t[1]=c,t[2]=wt):wt=t[2],m=wt}const u=m;let p,b;t[3]!==n||t[4]!==c||t[5]!==d?(p=()=>{if(n.length===0){d(null);return}c&&n.some(wt=>wt.id===c)||d(n[0].id)},b=[n,c,d],t[3]=n,t[4]=c,t[5]=d,t[6]=p,t[7]=b):(p=t[6],b=t[7]),o.useEffect(p,b);const[g,y]=o.useState(""),[x,h]=o.useState(null),[j,v]=o.useState(null),[C,k]=o.useState(null),[w,N]=o.useState(!1),[I,E]=o.useState(!1),[P,T]=o.useState(!1),[S,M]=o.useState(!1),[D,F]=o.useState(null),[_,V]=o.useState(null),[$,O]=o.useState(!1),B=o.useRef(null);let G;t[8]===Symbol.for("react.memo_cache_sentinel")?(G=()=>{F(null),V(hC)},t[8]=G):G=t[8];const R=G;let H;e:{if(!u){H=null;break e}let wt;t[9]!==u.id||t[10]!==u.path?(wt={id:u.id,path:u.path},t[9]=u.id,t[10]=u.path,t[11]=wt):wt=t[11],H=wt}const J=H;let ne,ue;t[12]!==u?(ne=()=>{if(!u){y(""),h(null),v(null),k(null);return}y(u.label??""),h(u.icon??null),v(u.color??null),k(u.iconBackground??null),M(!1),R(),O(!1)},ue=[u,R],t[12]=u,t[13]=ne,t[14]=ue):(ne=t[13],ue=t[14]),o.useEffect(ne,ue);let de,pe;t[15]===Symbol.for("react.memo_cache_sentinel")?(de=()=>()=>{R()},pe=[R],t[15]=de,t[16]=pe):(de=t[15],pe=t[16]),o.useEffect(de,pe);let W;t[17]!==j||t[18]!==x||t[19]!==C||t[20]!==g||t[21]!==S||t[22]!==D||t[23]!==u?(W=!!u&&(g.trim()!==(u?.label??"").trim()||x!==(u?.icon??null)||j!==(u?.color??null)||C!==(u?.iconBackground??null)||S||!!D),t[17]=j,t[18]=x,t[19]=C,t[20]=g,t[21]=S,t[22]=D,t[23]=u,t[24]=W):W=t[24];const te=W;let X;t[25]!==j||t[26]!==x||t[27]!==C||t[28]!==g||t[29]!==S||t[30]!==D||t[31]!==i||t[32]!==u||t[33]!==e||t[34]!==r||t[35]!==a?(X=async()=>{if(!u)return;if(D){N(!0);const Zt=await a(u.id,D);if(N(!1),!Zt.ok){K.error(Zt.error||e("settings.projects.page.toast.uploadIconFailed"));return}K.success(e("settings.projects.page.toast.iconUpdated")),R(),M(!1)}const wt=S&&!!u.iconImage;if(wt){E(!0);const Zt=await i(u.id);if(E(!1),!Zt.ok){K.error(Zt.error||e("settings.projects.page.toast.removeIconFailed"));return}K.success(e("settings.projects.page.toast.iconRemoved")),M(!1),k(null)}r(u.id,{label:g.trim(),icon:x,color:j,iconBackground:wt?null:C})},t[25]=j,t[26]=x,t[27]=C,t[28]=g,t[29]=S,t[30]=D,t[31]=i,t[32]=u,t[33]=e,t[34]=r,t[35]=a,t[36]=X):X=t[36];const ee=X,fe=j?To[j]??null:null,be=!!u?.iconImage,Ne=!!(D&&_),se=u?.iconImage?.source==="custom",ie=be&&!S||Ne,ae=ie;let xe;t[37]!==f||t[38]!==Ne||t[39]!==be||t[40]!==S||t[41]!==_||t[42]!==$||t[43]!==u?(xe=$?null:Ne?_:u&&be&&!S?Do(u,{themeVariant:f.metadata.variant,iconColor:f.colors.surface.foreground}):null,t[37]=f,t[38]=Ne,t[39]=be,t[40]=S,t[41]=_,t[42]=$,t[43]=u,t[44]=xe):xe=t[44];const Z=xe;let me;t[45]!==w||t[46]!==u?(me=wt=>{!u||!wt||w||(M(!1),O(!1),F(wt),V(Zt=>(Zt&&URL.revokeObjectURL(Zt),URL.createObjectURL(wt))))},t[45]=w,t[46]=u,t[47]=me):me=t[47];const Y=me;let Se;t[48]!==Ne||t[49]!==ae||t[50]!==be||t[51]!==I||t[52]!==u?(Se=()=>{!u||!ae||I||(Ne&&R(),M(!!be),O(!1))},t[48]=Ne,t[49]=ae,t[50]=be,t[51]=I,t[52]=u,t[53]=Se):Se=t[53];const we=Se;let ke;t[54]!==l||t[55]!==P||t[56]!==u||t[57]!==e?(ke=async()=>{!u||P||(R(),M(!1),O(!1),T(!0),l(u.id).then(wt=>{if(!wt.ok){K.error(wt.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(wt.skipped){K.success(e("settings.projects.page.toast.customIconAlreadySet"));return}K.success(e("settings.projects.page.toast.iconDiscovered"))}).finally(()=>{T(!1)}))},t[54]=l,t[55]=P,t[56]=u,t[57]=e,t[58]=ke):ke=t[58];const Fe=ke;if(!u){let wt;t[59]!==e?(wt=e("settings.projects.page.empty.noProjects"),t[59]=e,t[60]=wt):wt=t[60];let Zt;return t[61]!==wt?(Zt=s.jsx(vs,{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:wt})})}),t[61]=wt,t[62]=Zt):Zt=t[62],Zt}let Ce;t[63]!==u.label||t[64]!==e?(Ce=u.label??e("settings.projects.page.title.default"),t[63]=u.label,t[64]=e,t[65]=Ce):Ce=t[65];let Q;t[66]!==Ce?(Q=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:Ce}),t[66]=Ce,t[67]=Q):Q=t[67];let ce;t[68]!==u.path?(ce=s.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:u.path,children:u.path}),t[68]=u.path,t[69]=ce):ce=t[69];let ve;t[70]!==Q||t[71]!==ce?(ve=s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[Q,ce]})}),t[70]=Q,t[71]=ce,t[72]=ve):ve=t[72];let le;t[73]!==e?(le=e("settings.projects.page.field.projectName"),t[73]=e,t[74]=le):le=t[74];let Ae;t[75]!==le?(Ae=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:le})}),t[75]=le,t[76]=Ae):Ae=t[76];let Te;t[77]===Symbol.for("react.memo_cache_sentinel")?(Te=wt=>y(wt.target.value),t[77]=Te):Te=t[77];let $e;t[78]!==e?($e=e("settings.projects.page.field.projectNamePlaceholder"),t[78]=e,t[79]=$e):$e=t[79];let ye;t[80]!==g||t[81]!==$e?(ye=s.jsx("div",{className:"mt-1.5 flex min-w-0 items-center gap-2",children:s.jsx($t,{value:g,onChange:Te,placeholder:$e,className:"h-7 min-w-0 w-full sm:max-w-[19rem]"})}),t[80]=g,t[81]=$e,t[82]=ye):ye=t[82];let q;t[83]!==Ae||t[84]!==ye?(q=s.jsxs("div",{className:"py-1.5",children:[Ae,ye]}),t[83]=Ae,t[84]=ye,t[85]=q):q=t[85];let L;t[86]!==e?(L=e("settings.projects.page.field.accentColor"),t[86]=e,t[87]=L):L=t[87];let U;t[88]!==L?(U=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:L})}),t[88]=L,t[89]=U):U=t[89];let oe;t[90]===Symbol.for("react.memo_cache_sentinel")?(oe=()=>v(null),t[90]=oe):oe=t[90];const Ee=j===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let Oe;t[91]!==Ee?(Oe=ge("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Ee),t[91]=Ee,t[92]=Oe):Oe=t[92];let Ie;t[93]!==e?(Ie=e("settings.projects.page.field.none"),t[93]=e,t[94]=Ie):Ie=t[94];let z;t[95]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(A,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[95]=z):z=t[95];let De;t[96]!==Oe||t[97]!==Ie?(De=s.jsx("button",{type:"button",onClick:oe,className:Oe,title:Ie,children:z}),t[96]=Oe,t[97]=Ie,t[98]=De):De=t[98];let Qe;t[99]!==j?(Qe=jy.map(wt=>s.jsx("button",{type:"button",onClick:()=>v(wt.key),className:ge("h-7 w-7 rounded-md border transition-colors",j===wt.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:wt.cssVar},title:wt.label},wt.key)),t[99]=j,t[100]=Qe):Qe=t[100];let tt;t[101]!==De||t[102]!==Qe?(tt=s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[De,Qe]}),t[101]=De,t[102]=Qe,t[103]=tt):tt=t[103];let et;t[104]!==U||t[105]!==tt?(et=s.jsxs("div",{className:"py-1.5",children:[U,tt]}),t[104]=U,t[105]=tt,t[106]=et):et=t[106];let We;t[107]!==e?(We=e("settings.projects.page.field.projectIcon"),t[107]=e,t[108]=We):We=t[108];let at;t[109]!==We?(at=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:We})}),t[109]=We,t[110]=at):at=t[110];let qe;t[111]!==Y?(qe=s.jsx("input",{ref:B,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:wt=>{const Zt=wt.target.files?.[0]??null;Y(Zt),wt.currentTarget.value=""}}),t[111]=Y,t[112]=qe):qe=t[112];let nt;t[113]===Symbol.for("react.memo_cache_sentinel")?(nt=()=>h(null),t[113]=nt):nt=t[113];const Ze=x===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let ze;t[114]!==Ze?(ze=ge("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Ze),t[114]=Ze,t[115]=ze):ze=t[115];let rt;t[116]!==e?(rt=e("settings.projects.page.field.none"),t[116]=e,t[117]=rt):rt=t[117];let Ge;t[118]===Symbol.for("react.memo_cache_sentinel")?(Ge=s.jsx(A,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[118]=Ge):Ge=t[118];let ct;t[119]!==ze||t[120]!==rt?(ct=s.jsx("button",{type:"button",onClick:nt,className:ze,title:rt,children:Ge}),t[119]=ze,t[120]=rt,t[121]=ct):ct=t[121];let Pe;t[122]!==fe||t[123]!==x?(Pe=Ny.map(wt=>{const Zt=wt.Icon;return s.jsx("button",{type:"button",onClick:()=>h(wt.key),className:ge("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",x===wt.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:wt.label,children:s.jsx(A,{name:Zt,className:"w-4 h-4",style:fe&&x===wt.key?{color:fe}:void 0})},wt.key)}),t[122]=fe,t[123]=x,t[124]=Pe):Pe=t[124];let Me;t[125]!==ct||t[126]!==Pe?(Me=s.jsxs("div",{className:"mt-1.5 flex max-w-[22rem] flex-wrap items-center gap-2",children:[ct,Pe]}),t[125]=ct,t[126]=Pe,t[127]=Me):Me=t[127];let Ue;t[128]!==ie||t[129]!==C||t[130]!==Z||t[131]!==e?(Ue=ie&&Z&&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:C?{backgroundColor:C}:void 0,children:s.jsx("img",{src:Z,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>O(!0)})})})]}),t[128]=ie,t[129]=C,t[130]=Z,t[131]=e,t[132]=Ue):Ue=t[132];let He;t[133]!==ie||t[134]!==C||t[135]!==e?(He=ie&&s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[s.jsx("input",{type:"color",value:C??"#000000",onChange:wt=>k(wt.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($t,{value:C??"",onChange:wt=>k(wt.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),s.jsx(he,{type:"button",size:"xs",variant:"outline",onClick:()=>k(null),className:"h-7 w-7 p-0","aria-label":e("settings.projects.page.field.clearIconBackgroundAria"),title:e("settings.projects.page.field.clearBackground"),disabled:!C,children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]}),t[133]=ie,t[134]=C,t[135]=e,t[136]=He):He=t[136];let lt;t[137]!==Fe||t[138]!==se||t[139]!==P||t[140]!==w||t[141]!==e?(lt=!se&&s.jsxs(s.Fragment,{children:[s.jsx(he,{size:"xs",className:"h-6 !font-normal",onClick:()=>B.current?.click(),disabled:w,children:e(w?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),s.jsx(he,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{Fe()},disabled:P,children:e(P?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),t[137]=Fe,t[138]=se,t[139]=P,t[140]=w,t[141]=e,t[142]=lt):lt=t[142];let vt;t[143]!==we||t[144]!==ae||t[145]!==I||t[146]!==e?(vt=ae&&s.jsx(he,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{we()},disabled:I,children:e(I?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),t[143]=we,t[144]=ae,t[145]=I,t[146]=e,t[147]=vt):vt=t[147];let ft;t[148]!==I||t[149]!==S||t[150]!==e?(ft=S&&s.jsx(he,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>M(!1),disabled:I,children:e("settings.projects.page.actions.undoRemove")}),t[148]=I,t[149]=S,t[150]=e,t[151]=ft):ft=t[151];let dt;t[152]!==lt||t[153]!==vt||t[154]!==ft?(dt=s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[lt,vt,ft]}),t[152]=lt,t[153]=vt,t[154]=ft,t[155]=dt):dt=t[155];let Dt;t[156]!==at||t[157]!==qe||t[158]!==Me||t[159]!==Ue||t[160]!==He||t[161]!==dt?(Dt=s.jsxs("div",{className:"py-1.5",children:[at,qe,Me,Ue,He,dt]}),t[156]=at,t[157]=qe,t[158]=Me,t[159]=Ue,t[160]=He,t[161]=dt,t[162]=Dt):Dt=t[162];let Qt;t[163]!==q||t[164]!==et||t[165]!==Dt?(Qt=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[q,et,Dt]}),t[163]=q,t[164]=et,t[165]=Dt,t[166]=Qt):Qt=t[166];let Ft;t[167]!==te||t[168]!==I||t[169]!==w||t[170]!==g?(Ft=!te||g.trim().length===0||w||I,t[167]=te,t[168]=I,t[169]=w,t[170]=g,t[171]=Ft):Ft=t[171];let qt;t[172]!==e?(qt=e("settings.common.actions.saveChanges"),t[172]=e,t[173]=qt):qt=t[173];let gt;t[174]!==ee||t[175]!==Ft||t[176]!==qt?(gt=s.jsx("div",{className:"mt-0.5 px-2 py-1",children:s.jsx(he,{onClick:ee,disabled:Ft,size:"xs",className:"!font-normal",children:qt})}),t[174]=ee,t[175]=Ft,t[176]=qt,t[177]=gt):gt=t[177];let zt;t[178]!==Qt||t[179]!==gt?(zt=s.jsxs("div",{className:"mb-8",children:[Qt,gt]}),t[178]=Qt,t[179]=gt,t[180]=zt):zt=t[180];let es;t[181]!==J?(es=J&&s.jsx(iC,{projectRef:J}),t[181]=J,t[182]=es):es=t[182];let is;t[183]!==es?(is=s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:es})}),t[183]=es,t[184]=is):is=t[184];let cs;t[185]!==e?(cs=e("settings.projects.page.section.worktree"),t[185]=e,t[186]=cs):cs=t[186];let hs;t[187]!==cs?(hs=s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:cs})}),t[187]=cs,t[188]=hs):hs=t[188];let _t;t[189]!==J?(_t=J&&s.jsx(nC,{projectRef:J}),t[189]=J,t[190]=_t):_t=t[190];let Ye;t[191]!==_t?(Ye=s.jsx("section",{className:"px-2 pb-2 pt-0",children:_t}),t[191]=_t,t[192]=Ye):Ye=t[192];let Mt;t[193]!==hs||t[194]!==Ye?(Mt=s.jsxs("div",{className:"mb-8",children:[hs,Ye]}),t[193]=hs,t[194]=Ye,t[195]=Mt):Mt=t[195];let Bt;return t[196]!==ve||t[197]!==zt||t[198]!==is||t[199]!==Mt?(Bt=s.jsx(vs,{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:[ve,zt,is,Mt]})}),t[196]=ve,t[197]=zt,t[198]=is,t[199]=Mt,t[200]=Bt):Bt=t[200],Bt};function lC(t){return t.projects}function cC(t){return t.updateProjectMeta}function dC(t){return t.uploadProjectIcon}function uC(t){return t.removeProjectIcon}function mC(t){return t.discoverProjectIcon}function pC(t){return t.settingsProjectsSelectedId}function fC(t){return t.setSettingsProjectsSelectedId}function hC(t){return t&&URL.revokeObjectURL(t),null}const gC=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`,xC=()=>Math.floor(2e4+Math.random()*3e4),bC=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")},yC=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"}},vC=({onItemSelect:t})=>{const{t:e}=pt(),n=Js(h=>h.instances),r=Js(h=>h.statusesById),a=Js(h=>h.isLoading),i=Js(h=>h.load),l=Js(h=>h.loadImports),c=Js(h=>h.createFromCommand),d=Js(h=>h.connect),f=Js(h=>h.disconnect),m=Js(h=>h.retry),u=Js(h=>h.removeInstance),p=Js(h=>h.upsertInstance),b=_e(h=>h.settingsRemoteInstancesSelectedId),g=_e(h=>h.setSettingsRemoteInstancesSelectedId);o.useEffect(()=>{i(),l()},[i,l]),o.useEffect(()=>{if(!a){if(n.length===0){b!==null&&g(null);return}b&&n.some(h=>h.id===b)||g(n[0].id)}},[n,a,b,g]);const y=o.useCallback(async()=>{const h=gC();try{await c(h,"ssh user@example.com",e("settings.remoteInstances.sidebar.newSshInstanceName")),g(h),t?.()}catch(j){K.error(e("settings.remoteInstances.sidebar.toast.createFailed"),{description:j instanceof Error?j.message:String(j)})}},[c,t,g,e]),x=o.useCallback(async h=>{try{await d(h.id);return}catch(j){if(!bC(j)||!window.confirm(e("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw j;const C={...h,localForward:{...h.localForward,preferredLocalPort:xC()}};await p(C),await d(C.id),K.success(e("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[d,e,p]);return s.jsx(ku,{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(he,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:()=>{y()},"aria-label":e("settings.remoteInstances.sidebar.actions.addSshInstance"),children:s.jsx(A,{name:"add",className:"size-4"})})]})]}),children:n.map(h=>{const j=r[h.id],v=h.id===b,C=h.nickname?.trim()||h.sshParsed?.destination||h.id,k=`${e(yC(j?.phase))}${j?.localUrl?` · ${j.localUrl}`:""}`,w=j?.phase==="ready",N=j?.phase==="error"||j?.phase==="degraded";return s.jsx(Gl,{title:C,metadata:k,selected:v,onSelect:()=>{g(h.id),t?.()},actions:[{label:e(w?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect"),icon:w?"stop":"plug-2",onClick:()=>{(w?f(h.id):x(h)).catch(E=>{K.error(e(w?"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:()=>{N&&m(h.id).catch(I=>{K.error(e("settings.remoteInstances.sidebar.toast.retryFailed"),{description:I instanceof Error?I.message:String(I)})})}},{label:e("settings.remoteInstances.sidebar.actions.remove"),icon:"delete-bin",destructive:!0,onClick:()=>{u(h.id).then(()=>{if(b===h.id){const I=n.find(E=>E.id!==h.id);g(I?.id||null)}}).catch(I=>{K.error(e("settings.remoteInstances.sidebar.toast.removeFailed"),{description:I instanceof Error?I.message:String(I)})})}}]},h.id)})})},Od=()=>Math.floor(2e4+Math.random()*3e4),wC=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")},jC=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"}},NC=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Gg=t=>!!(t&&NC.has(t)),SC=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||Gg(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",kC=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}`,CC=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:Od(),remoteHost:"127.0.0.1",remotePort:80}),IC=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",ea=t=>{const e=ot.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(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),e[2]=i):i=e[2];let l;e[3]!==r?(l=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]=l):l=e[4];let c;return e[5]!==a||e[6]!==l?(c=s.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[a,l]}),e[5]=a,e[6]=l,e[7]=c):c=e[7],c},PC=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"}},Yp=(t,e)=>{const n=(t||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},AC=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},DC=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}`},TC=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},EC=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}},MC=()=>{const{t}=pt(),e=Js(L=>L.instances),n=Js(L=>L.statusesById),r=Js(L=>L.importCandidates),a=Js(L=>L.isImportsLoading),i=Js(L=>L.isSaving),l=Js(L=>L.error),c=Js(L=>L.load),d=Js(L=>L.loadImports),f=Js(L=>L.refreshStatuses),m=Js(L=>L.upsertInstance),u=Js(L=>L.createFromCommand),p=Js(L=>L.removeInstance),b=Js(L=>L.connect),g=Js(L=>L.disconnect),y=Js(L=>L.retry),x=_e(L=>L.settingsRemoteInstancesSelectedId),h=_e(L=>L.setSettingsRemoteInstancesSelectedId),j=o.useMemo(()=>x&&e.find(L=>L.id===x)||null,[e,x]),[v,C]=o.useState(null),[k,w]=o.useState(!1),[N,I]=o.useState(!1),[E,P]=o.useState(null),[T,S]=o.useState([]),[M,D]=o.useState(null),[F,_]=o.useState(""),[V,$]=o.useState(!1),[O,B]=o.useState({}),[G,R]=o.useState(!1),[H,J]=o.useState(!1),[ne,ue]=o.useState(()=>Date.now());o.useEffect(()=>{c(),d()},[c,d]),o.useEffect(()=>{C(j)},[j]),o.useEffect(()=>{if(!x)return;const L=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||f()},2e3);return()=>{window.clearInterval(L)}},[f,x]),o.useEffect(()=>{let L=null,U=Date.now();const oe=()=>{const Oe=Date.now();Oe-U>=1e3&&(ue(Oe),U=Oe),L=requestAnimationFrame(oe)};(typeof document>"u"||document.visibilityState==="visible")&&(L=requestAnimationFrame(oe));const Ee=()=>{document.visibilityState==="visible"&&L===null?L=requestAnimationFrame(oe):document.visibilityState!=="visible"&&L!==null&&(cancelAnimationFrame(L),L=null)};return document.addEventListener("visibilitychange",Ee),()=>{document.removeEventListener("visibilitychange",Ee),L!==null&&cancelAnimationFrame(L)}},[]);const de=x?n[x]:null,pe=de?.phase,W=pe==="ready",te=pe==="degraded",X=Gg(pe),fe=W||(X||te),be=de?Math.max(0,ne-de.updatedAtMs):0,Ne=te&&be>12e3,se=o.useMemo(()=>!v||!j?!1:JSON.stringify(v)!==JSON.stringify(j),[v,j]),ie=o.useCallback(L=>{C(U=>U&&L(U))},[]),ae=o.useCallback(async()=>{if(!v)return;const L=EC(v);if(!L.sshCommand.trim()){K.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(L.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(L.auth.sshPassword?.enabled&&L.auth.sshPassword.value?.trim()&&L.auth.sshPassword.store!=="settings"){const U=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));L.auth.sshPassword.store=U?"settings":"never",U||(L.auth.sshPassword.value=void 0)}if(L.auth.openchamberPassword?.enabled&&L.auth.openchamberPassword.value?.trim()&&L.auth.openchamberPassword.store!=="settings"){const U=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));L.auth.openchamberPassword.store=U?"settings":"never",U||(L.auth.openchamberPassword.value=void 0)}try{await m(L),K.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(U){K.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:U instanceof Error?U.message:String(U)})}}},[v,t,m]),xe=o.useCallback(async(L,U)=>{const oe=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await u(oe,`ssh ${U}`,L),h(oe),K.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Ee){return K.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Ee instanceof Error?Ee.message:String(Ee)}),!1}},[u,h,t]),Z=o.useCallback(()=>{V||(D(null),_(""))},[V]),me=o.useCallback((L,U)=>{if(U){D(L),_(IC(L));return}xe(L,L)},[xe]),Y=o.useCallback(async()=>{const L=M,U=F.trim();if(L){if(!U){K.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}$(!0);try{await xe(L,U)&&(D(null),_(""))}finally{$(!1)}}},[xe,F,M,t]),Se=o.useCallback(async()=>{if(j)try{await b(j.id);return}catch(L){if(!wC(L)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw L;const oe={...j,localForward:{...j.localForward,preferredLocalPort:Od()}};await m(oe),await b(oe.id),K.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[b,j,t,m]),we=o.useCallback(async L=>(await Sy(L,600)).map(oe=>DC(oe)),[]),ke=o.useCallback(async()=>{if(v){w(!0),I(!0),P(null);try{const L=await we(v.id);S(L)}catch(L){S([]),P(L instanceof Error?L.message:String(L))}finally{I(!1)}}},[v,we]);o.useEffect(()=>{if(!k||!v)return;let L=!1;const U=async()=>{try{const Ee=await we(v.id);L||(S(Ee),P(null))}catch(Ee){L||P(Ee instanceof Error?Ee.message:String(Ee))}};U();const oe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||U()},1e3);return()=>{L=!0,window.clearInterval(oe)}},[v,k,we]);const Fe=o.useMemo(()=>T.join(`
|
|
188
|
+
`),[T]),Ce=o.useCallback(()=>{if(!Fe.trim()){K.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Ln(Fe).then(L=>{L.ok&&K.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[Fe,t]),Q=o.useCallback(async()=>{if(v)try{await ky(v.id),S([]),K.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(L){K.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:L instanceof Error?L.message:String(L)})}},[v,t]),ce=o.useCallback(async()=>{if(!de?.localUrl){K.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const L=de.localUrl.trim();if(!L){K.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}TC(L)},[de?.localUrl,t]),ve=o.useCallback(()=>{if(!v)return;R(!0),(fe?g(v.id):Se()).catch(U=>{const oe=fe?W?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";K.error(t(oe),{description:U instanceof Error?U.message:String(U)})}).finally(()=>{R(!1)})},[fe,Se,g,v,W,t]),le=o.useCallback(()=>{if(!v||X)return;J(!0),(te?g(v.id).then(()=>Se()):y(v.id)).catch(U=>{K.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:U instanceof Error?U.message:String(U)})}).finally(()=>{J(!1)})},[Se,g,v,X,te,y,t]),Ae=t(X?"settings.remoteInstances.page.actions.connecting":te?Ne?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Te=!G&&!H&&(pe==="error"||pe==="idle"||!pe||te&&Ne)&&!X,$e=t(W?"settings.remoteInstances.sidebar.actions.disconnect":fe?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!v)return s.jsxs(ql,{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(L=>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:[L.host,L.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[L.source," config"]})]}),s.jsx(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{me(L.host,L.pattern)},children:t("settings.remoteInstances.page.actions.create")})]},`${L.source}:${L.host}`))})})]}),s.jsx(ls,{open:!!M,onOpenChange:L=>{L||Z()},children:s.jsxs(os,{className:"sm:max-w-md",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(ys,{children:M?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:M}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:L=>{L.preventDefault(),Y()},children:[s.jsx($t,{value:F,onChange:L=>_(L.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(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Z,disabled:V,children:t("settings.common.actions.cancel")}),s.jsx(he,{type:"submit",size:"xs",className:"!font-normal",disabled:V,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const ye=v.remoteOpenchamber.mode==="managed",q=v.nickname?.trim()||v.sshParsed?.destination||v.id;return s.jsxs(ql,{children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:q}),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 ${SC(pe)}`}),s.jsx("span",{children:t(jC(pe))}),de?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:de.localUrl}):null,Ne?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(he,{type:"button",variant:fe?"outline":"default",size:"xs",className:"!font-normal",onClick:ve,disabled:G||H,children:[fe?s.jsx(A,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"plug-2",className:"h-3.5 w-3.5"}),$e]}),s.jsxs(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:le,disabled:!Te,children:[s.jsx(A,{name:"refresh",className:`h-3.5 w-3.5 ${X||te&&!Ne?"animate-spin":""}`}),Ae]}),s.jsxs(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ke()},children:[s.jsx(A,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(he,{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"))&&p(v.id).then(()=>{h(null),K.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(U=>{K.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:U instanceof Error?U.message:String(U)})})},children:[s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),de?.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:de.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($t,{className:"h-7 md:max-w-xl",value:v.sshCommand,onChange:L=>ie(U=>({...U,sshCommand:L.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($t,{className:"h-7 md:max-w-sm",value:v.nickname||"",onChange:L=>ie(U=>({...U,nickname:L.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(Un,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:v.connectionTimeoutSec,onValueChange:L=>{ie(U=>({...U,connectionTimeoutSec:Number.isFinite(L)?L:U.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(ea,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(ns,{value:v.remoteOpenchamber.mode,onValueChange:L=>ie(U=>({...U,remoteOpenchamber:{...U.remoteOpenchamber,mode:L==="external"?"external":"managed"}})),children:[s.jsx(rs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ms,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(as,{children:[s.jsx(Rt,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(Rt,{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(ea,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(Un,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:v.remoteOpenchamber.preferredPort,onValueChange:L=>{ie(U=>({...U,remoteOpenchamber:{...U.remoteOpenchamber,preferredPort:Number.isFinite(L)&&L>0?L:void 0}}))},onClear:()=>{ie(L=>({...L,remoteOpenchamber:{...L.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),ye?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(ea,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(ns,{value:v.remoteOpenchamber.installMethod,onValueChange:L=>ie(U=>({...U,remoteOpenchamber:{...U.remoteOpenchamber,installMethod:L==="npm"||L==="download_release"||L==="upload_bundle"?L:"bun"}})),children:[s.jsx(rs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ms,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(as,{children:[s.jsx(Rt,{value:"bun",children:"bun"}),s.jsx(Rt,{value:"npm",children:"npm"}),s.jsx(Rt,{value:"download_release",children:t("settings.remoteInstances.page.field.installMethodDownloadRelease")}),s.jsx(Rt,{value:"upload_bundle",children:t("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,ye?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(ea,{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(Ol,{checked:v.remoteOpenchamber.keepRunning,onCheckedChange:L=>ie(U=>({...U,remoteOpenchamber:{...U.remoteOpenchamber,keepRunning:L}}))})})]}):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(ea,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(ns,{value:v.localForward.bindHost,onValueChange:L=>{L==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||ie(U=>({...U,localForward:{...U.localForward,bindHost:L==="localhost"||L==="0.0.0.0"?L:"127.0.0.1"}}))},children:[s.jsx(rs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ms,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(as,{children:[s.jsx(Rt,{value:"127.0.0.1",children:"127.0.0.1"}),s.jsx(Rt,{value:"localhost",children:"localhost"}),s.jsx(Rt,{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(ea,{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(Un,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:v.localForward.preferredLocalPort,onValueChange:L=>{ie(U=>({...U,localForward:{...U.localForward,preferredLocalPort:Number.isFinite(L)&&L>0?L:void 0}}))},onClear:()=>{ie(L=>({...L,localForward:{...L.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>ie(L=>({...L,localForward:{...L.localForward,preferredLocalPort:Od()}})),children:s.jsx(A,{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($t,{className:"h-7 md:max-w-sm",type:"password",value:v.auth.sshPassword?.value||"",onChange:L=>ie(U=>({...U,auth:{...U.auth,sshPassword:{enabled:L.target.value.trim().length>0,value:L.target.value,store:U.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($t,{className:"h-7 md:max-w-sm",type:"password",value:v.auth.openchamberPassword?.value||"",onChange:L=>ie(U=>({...U,auth:{...U.auth,openchamberPassword:{enabled:L.target.value.trim().length>0,value:L.target.value,store:U.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:[v.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,v.portForwards.map((L,U)=>{const oe=qe=>{ie(nt=>({...nt,portForwards:nt.portForwards.map((Ze,ze)=>ze===U?qe(Ze):Ze)}))},Ee=L.type==="remote"?"Local target":"Local listen",Oe=L.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.",Ie=L.type==="remote"?"Remote listen":"Remote target",z=L.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",De=Yp(L.localHost||"localhost",L.localPort),Qe=Yp(L.remoteHost||"localhost",L.remotePort),tt=L.type==="local"&&typeof L.localPort=="number"&&L.localPort>0,et=tt?`http://${AC(L.localHost)}:${L.localPort}`:"",We=!!O[L.id],at=L.type==="local"?t("settings.remoteInstances.page.forwardType.local"):L.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(jr,{open:We,onOpenChange:qe=>{B(nt=>({...nt,[L.id]:qe}))},className:`${U>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(Lr,{className:"flex items-center gap-2 group",children:[s.jsx(A,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${We?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:kC(L)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:at})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ol,{checked:L.enabled,onCheckedChange:qe=>oe(nt=>({...nt,enabled:qe})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(he,{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:()=>ie(qe=>({...qe,portForwards:qe.portForwards.filter(nt=>nt.id!==L.id)})),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Nr,{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(PC(L.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(ea,{label:t("settings.remoteInstances.page.field.forwardType"),hint:t("settings.remoteInstances.page.field.forwardTypeHint")})}),s.jsxs(ns,{value:L.type,onValueChange:qe=>oe(nt=>({...nt,type:qe==="dynamic"||qe==="remote"?qe:"local"})),children:[s.jsx(rs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ms,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(as,{children:[s.jsx(Rt,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(Rt,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(Rt,{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(ea,{label:Ee,hint:Oe})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx($t,{className:"h-7 w-32",value:L.localHost||"127.0.0.1",onChange:qe=>oe(nt=>({...nt,localHost:qe.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Un,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:L.localPort,onValueChange:qe=>{oe(nt=>({...nt,localPort:Number.isFinite(qe)&&qe>0?qe:void 0}))},onClear:()=>{oe(qe=>({...qe,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),L.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(ea,{label:Ie,hint:z})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx($t,{className:"h-7 w-32",value:L.remoteHost||"",onChange:qe=>oe(nt=>({...nt,remoteHost:qe.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Un,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:L.remotePort,onValueChange:qe=>{oe(nt=>({...nt,remotePort:Number.isFinite(qe)&&qe>0?qe:void 0}))},onClear:()=>{oe(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:L.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:De}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):L.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Qe}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(A,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(A,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:De}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:De}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(A,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(A,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Qe}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),tt?s.jsxs(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{rr(et).then(qe=>{qe||K.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},L.id)}),s.jsxs(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const L=CC();ie(U=>({...U,portForwards:[...U.portForwards,L]})),B(U=>({...U,[L.id]:!0}))},children:[s.jsx(A,{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((L,U)=>s.jsxs("div",{className:`flex items-center justify-between gap-2 px-1 py-2 ${U>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:[L.host,L.pattern?" (pattern)":""]}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:L.sshCommand})]}),s.jsx(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{me(L.host,L.pattern)},children:t("settings.common.actions.import")})]},`${L.source}:${L.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(he,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{ae()},disabled:!se||i,children:t("settings.common.actions.saveChanges")}),de?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ln(de.localUrl||"").then(L=>{L.ok&&K.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(A,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ce()},children:[s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,l?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:l}):null]})}),s.jsx(ls,{open:k,onOpenChange:w,children:s.jsxs(os,{className:"sm:max-w-2xl",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(ys,{children:v?.nickname?.trim()||v?.sshParsed?.destination||v?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ce,disabled:N||!Fe.trim(),children:[s.jsx(A,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Q()},disabled:N,children:[s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),N?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:T.length>0?T.join(`
|
|
189
|
+
`):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(ls,{open:!!M,onOpenChange:L=>{L||Z()},children:s.jsxs(os,{className:"sm:max-w-md",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(ys,{children:M?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:M}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:L=>{L.preventDefault(),Y()},children:[s.jsx($t,{value:F,onChange:L=>_(L.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(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Z,disabled:V,children:t("settings.common.actions.cancel")}),s.jsx(he,{type:"submit",size:"xs",className:"!font-normal",disabled:V,children:t("settings.common.actions.create")})]})]})]})})]})},RC="__add_provider__",FC=()=>{const t=rn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},LC=({onItemSelect:t})=>{const{t:e}=pt(),n=jt(p=>p.providers),r=jt(p=>p.selectedProviderId),a=jt(p=>p.setSelectedProvider),i=Ss(p=>p.activeProjectId),[l,c]=o.useState({}),d=o.useMemo(()=>FC(),[i]);o.useEffect(()=>{if(n.length===0){c({});return}let p=!1;return(async()=>{const g=n.map(async y=>{try{const x=d?`?directory=${encodeURIComponent(d)}`:"",h=await fetch(`/api/provider/${encodeURIComponent(y.id)}/source${x}`,{method:"GET",headers:{Accept:"application/json"}});if(!h.ok)return;const j=await h.json().catch(()=>null),v=j?.sources??j?.data?.sources;if(!v||p)return;c(C=>({...C,[y.id]:v}))}catch{}});await Promise.all(g)})(),()=>{p=!0}},[d,n]);const f="bg-background",m=o.useMemo(()=>n.filter(p=>!!l[p.id]?.project?.exists),[n,l]),u=o.useMemo(()=>n.filter(p=>!l[p.id]?.project?.exists),[n,l]);return s.jsxs("div",{className:ge("flex h-full flex-col",f),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(he,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{a(RC),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(A,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(vs,{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(A,{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(p=>s.jsx(Qp,{provider:p,selectedProviderId:r,onSelect:()=>{a(p.id),t?.()}},p.id))]}),m.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ge("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(p=>s.jsx(Qp,{provider:p,selectedProviderId:r,onSelect:()=>{a(p.id),t?.()}},p.id))]})]})})]})},Qp=t=>{const e=ot.c(17),{provider:n,selectedProviderId:r,onSelect:a}=t,i=Array.isArray(n.models)?n.models.length:0,l=n.id===r,c=n.id,d=l?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[0]!==d?(f=ge("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",d),e[0]=d,e[1]=f):f=e[1];let m;e[2]!==n.id?(m=s.jsx(wr,{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 p;e[4]!==u?(p=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:u}),e[4]=u,e[5]=p):p=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 g;e[8]!==a||e[9]!==m||e[10]!==p||e[11]!==b?(g=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,p,b]}),e[8]=a,e[9]=m,e[10]=p,e[11]=b,e[12]=g):g=e[12];let y;return e[13]!==n.id||e[14]!==f||e[15]!==g?(y=s.jsx("div",{className:f,children:g},c),e[13]=n.id,e[14]=f,e[15]=g,e[16]=y):y=e[16],y},OC=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),Xp=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=OC.format(t);return e.endsWith(".0")?e.slice(0,-2):e},Zo="__add_provider__",Mi=t=>typeof t=="object"&&t!==null,Zp=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()},$C=t=>{if(!Mi(t))return{};const e={};for(const[n,r]of Object.entries(t))Array.isArray(r)&&(e[n]=r.filter(a=>Mi(a)));return e},_C=t=>{if(typeof t=="string")return{id:t};if(!Mi(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}},BC=t=>{let e=[];Array.isArray(t)?e=t:Mi(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const n=e.map(a=>_C(a)).filter(a=>!!a),r=new Set;return n.filter(a=>r.has(a.id)?!1:(r.add(a.id),!0))},VC=()=>{const{t}=pt(),e=jt(Z=>Z.providers),n=jt(Z=>Z.selectedProviderId),r=jt(Z=>Z.setSelectedProvider),a=jt(Z=>Z.getModelMetadata),i=_e(Z=>Z.hiddenModels),l=_e(Z=>Z.toggleHiddenModel),c=_e(Z=>Z.hideAllModels),d=_e(Z=>Z.showAllModels),[f,m]=o.useState({}),[u,p]=o.useState(!1),[b,g]=o.useState({}),[y,x]=o.useState(null),[h,j]=o.useState(""),[v,C]=o.useState(null),[k,w]=o.useState({}),[N,I]=o.useState({}),[E,P]=o.useState([]),[T,S]=o.useState(!1),[M,D]=o.useState(null),[F,_]=o.useState(""),[V,$]=o.useState(""),[O,B]=o.useState(!1),[G,R]=o.useState({}),[H,J]=o.useState(!1);o.useEffect(()=>{!n&&e.length>0&&r(e[0].id)},[e,n,r]),o.useEffect(()=>{let Z=!0;return(async()=>{p(!0);try{const Y=await fetch("/api/provider/auth",{method:"GET",headers:{Accept:"application/json"}});if(!Y.ok)throw new Error(`Auth methods request failed (${Y.status})`);const Se=await Y.json().catch(()=>({}));if(!Z)return;m($C(Se))}catch(Y){if(!Z)return;console.error("Failed to load provider auth methods:",Y),K.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{Z&&p(!1)}})(),()=>{Z=!1}},[t]),o.useEffect(()=>{let Z=!0;return(async()=>{S(!0),D(null);try{const Y=await fetch("/api/provider",{method:"GET",headers:{Accept:"application/json"}});if(!Y.ok)throw new Error(`Provider list request failed (${Y.status})`);const Se=await Y.json().catch(()=>({}));if(!Z)return;P(BC(Se))}catch(Y){if(!Z)return;console.error("Failed to load available providers:",Y),D(t("settings.providers.page.state.unableToLoadProviderList"))}finally{Z&&S(!1)}})(),()=>{Z=!1}},[t]);const ne=o.useMemo(()=>new Set(e.map(Z=>Z.id)),[e]),ue=o.useMemo(()=>E.filter(Z=>!ne.has(Z.id)).sort((Z,me)=>{const Y=(Z.name||Z.id).toLowerCase(),Se=(me.name||me.id).toLowerCase();return Y.localeCompare(Se)}),[E,ne]);o.useEffect(()=>{n===Zo&&F&&!ue.some(Z=>Z.id===F)&&_("")},[n,F,ue]),o.useEffect(()=>{if(n===Zo){J(!0);return}J(!1)},[n,t]),o.useEffect(()=>{if(!n||n===Zo)return;let Z=!1;return(async()=>{try{const Y=await fetch(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),Se=await Y.json().catch(()=>null);if(!Y.ok)throw new Error(Se?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const we=Se?.sources??Se?.data?.sources;!Z&&we&&R(ke=>({...ke,[n]:we}))}catch(Y){Z||console.error("Failed to load provider sources:",Y)}})(),()=>{Z=!0}},[n,t]);const de=e.find(Z=>Z.id===n),pe=n?G[n]:void 0,W=async Z=>{const me=b[Z]?.trim()??"";if(!me){K.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Y=`api:${Z}`;x(Y);try{const Se=await fetch(`/api/auth/${encodeURIComponent(Z)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"api",key:me})}),we=await Se.json().catch(()=>null);if(!Se.ok){const ke=we?.error||t("settings.providers.page.toast.apiKeySaveFailed");throw new Error(ke)}K.success(t("settings.providers.page.toast.apiKeySaved")),g(ke=>({...ke,[Z]:""})),await vi({scopes:["providers"],mode:"active"}),r(Z)}catch(Se){console.error("Failed to save API key:",Se),K.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{x(null)}},te=async(Z,me)=>{const Y=`oauth:${Z}:${me}`;x(Y);try{const Se=await fetch(`/api/provider/${encodeURIComponent(Z)}/oauth/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:me})}),we=await Se.json().catch(()=>null);if(!Se.ok){const le=we?.error||t("settings.providers.page.toast.oauthStartFailed");throw new Error(le)}const ke=Mi(we)?we:{},Fe=Mi(ke.data)?ke.data:ke,Ce=typeof Fe.url=="string"&&Fe.url||typeof Fe.verification_uri_complete=="string"&&Fe.verification_uri_complete||typeof Fe.verification_uri=="string"&&Fe.verification_uri||void 0,Q=typeof Fe.instructions=="string"&&Fe.instructions||typeof Fe.message=="string"&&Fe.message||void 0,ce=typeof Fe.user_code=="string"&&Fe.user_code||typeof Fe.code=="string"&&Fe.code||typeof Fe.userCode=="string"&&Fe.userCode||void 0;if(!Ce&&!Q&&!ce)throw new Error(t("settings.providers.page.toast.oauthDetailsMissing"));const ve=`${Z}:${me}`;I(le=>({...le,[ve]:{url:Ce,instructions:Q,userCode:ce}})),Ce&&rr(Ce),C({providerId:Z,methodIndex:me}),K.message(t("settings.providers.page.toast.completeOAuthInBrowser"))}catch(Se){console.error("Failed to start OAuth flow:",Se),K.error(t("settings.providers.page.toast.oauthStartFailed"))}finally{x(null)}},X=async(Z,me)=>{const Y=`${Z}:${me}`,Se=k[Y]?.trim(),we=`oauth-complete:${Z}:${me}`;x(we);try{const ke={method:me};Se&&(ke.code=Se);const Fe=await fetch(`/api/provider/${encodeURIComponent(Z)}/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(ke)}),Ce=await Fe.json().catch(()=>null);if(!Fe.ok){const Q=Ce?.error||t("settings.providers.page.toast.oauthCompleteFailed");throw new Error(Q)}K.success(t("settings.providers.page.toast.oauthCompleted")),w(Q=>({...Q,[Y]:""})),C(null),await vi({scopes:["providers"],mode:"active"}),r(Z)}catch(ke){console.error("Failed to complete OAuth flow:",ke),K.error(t("settings.providers.page.toast.oauthCompleteFailed"))}finally{x(null)}},ee=async Z=>{const me=await Ln(Z);if(me.ok){K.success(t("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",me.error),K.error(t("settings.providers.page.toast.oauthLinkCopyFailed"))},fe=async Z=>{const me=await Ln(Z);if(me.ok){K.success(t("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",me.error),K.error(t("settings.providers.page.toast.deviceCodeCopyFailed"))},be=async Z=>{const me=`disconnect:${Z}`;x(me);try{const Y=await fetch(`/api/provider/${encodeURIComponent(Z)}/auth?scope=all`,{method:"DELETE",headers:{"Content-Type":"application/json"}}),Se=await Y.json().catch(()=>null);if(!Y.ok){const we=Se?.error||t("settings.providers.page.toast.providerDisconnectFailed");throw new Error(we)}K.success(t("settings.providers.page.toast.providerDisconnected")),await vi({scopes:["providers"],mode:"active"})}catch(Y){console.error("Failed to disconnect provider:",Y),K.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{x(null)}},Ne=n===Zo;if(!Ne&&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(A,{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(Ne)return s.jsx(vs,{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")}),T?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):M?s.jsx("p",{className:"typography-meta text-muted-foreground",children:M}):ue.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connect.allProvidersConnected")}):s.jsxs(As,{open:O,onOpenChange:Z=>{B(Z),Z||$("")},children:[s.jsx(Is,{asChild:!0,children:s.jsxs("button",{type:"button",className:ge("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:[F?s.jsx(wr,{providerId:F,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:ge("truncate typography-ui-label font-normal",F?"text-foreground":"text-muted-foreground"),children:F?ue.find(Z=>Z.id===F)?.name||F:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(Ps,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:Z=>Z.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:Z=>Z.stopPropagation(),children:[s.jsx(A,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:V,onChange:Z=>$(Z.target.value),onKeyDown:Z=>Z.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(vs,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const Z=ue.filter(me=>{const Y=V.toLowerCase();return(me.name||me.id).toLowerCase().includes(Y)||me.id.toLowerCase().includes(Y)});return Z.length===0?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):Z.map(me=>s.jsxs(Ot,{onSelect:()=>{_(me.id),B(!1),$("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(wr,{providerId:me.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:me.name||me.id})]}),F===me.id&&s.jsx(A,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},me.id))})()})]})]})]})})]}),F&&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(A,{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($t,{type:"password",value:b[F]??"",onChange:Z=>g(me=>({...me,[F]:Z.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(he,{size:"xs",className:"!font-normal shrink-0",onClick:()=>W(F),disabled:y===`api:${F}`,children:y===`api:${F}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),(()=>{const me=(f[F]??[]).filter(Y=>Zp(Y)==="oauth");return me.length===0?null:s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:me.map((Y,Se)=>{const we=Y.label||Y.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(Se+1)}),ke=`${F}:${Se}`,Fe=v?.providerId===F&&v?.methodIndex===Se;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:we}),(Y.description||Y.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(Y.description||Y.help)})]}),s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>te(F,Se),disabled:y===`oauth:${F}:${Se}`,children:t("settings.providers.page.actions.connect")})]}),N[ke]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:N[ke]?.instructions}),N[ke]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx($t,{value:N[ke]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>fe(N[ke]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),N[ke]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx($t,{value:N[ke]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>rr(N[ke]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ee(N[ke]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),Fe&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx($t,{value:k[ke]??"",onChange:Ce=>w(Q=>({...Q,[ke]:Ce.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(he,{size:"xs",className:"!font-normal",onClick:()=>X(F,Se),disabled:y===`oauth-complete:${F}:${Se}`,children:y===`oauth-complete:${F}:${Se}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${F}-${we}`)})})})()]})]})]})});if(!de)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(A,{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 se=Array.isArray(de.models)?de.models:[],ae=(f[de.id]??[]).filter(Z=>Zp(Z)==="oauth"),xe=se.filter(Z=>{const me=typeof Z?.name=="string"?Z.name:"",Y=typeof Z?.id=="string"?Z.id:"",Se=h.trim().toLowerCase();return Se?me.toLowerCase().includes(Se)||Y.toLowerCase().includes(Se):!0});return s.jsx(vs,{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(wr,{providerId:de.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:de.name||de.id}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s.jsx("span",{className:"font-mono",children:de.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(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>J(Z=>!Z),children:t(H?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:H?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(A,{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($t,{type:"password",value:b[de.id]??"",onChange:Z=>g(me=>({...me,[de.id]:Z.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(he,{size:"xs",className:"!font-normal shrink-0",onClick:()=>W(de.id),disabled:y===`api:${de.id}`,children:y===`api:${de.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),ae.length>0&&s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:ae.map((Z,me)=>{const Y=Z.label||Z.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(me+1)}),Se=`${de.id}:${me}`,we=v?.providerId===de.id&&v?.methodIndex===me;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:Y}),(Z.description||Z.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(Z.description||Z.help)})]}),s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>te(de.id,me),disabled:y===`oauth:${de.id}:${me}`,children:t("settings.providers.page.actions.connect")})]}),N[Se]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:N[Se]?.instructions}),N[Se]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx($t,{value:N[Se]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>fe(N[Se]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),N[Se]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx($t,{value:N[Se]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>rr(N[Se]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ee(N[Se]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),we&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx($t,{value:k[Se]??"",onChange:ke=>w(Fe=>({...Fe,[Se]:ke.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(he,{size:"xs",className:"!font-normal",onClick:()=>X(de.id,me),disabled:y===`oauth-complete:${de.id}:${me}`,children:y===`oauth-complete:${de.id}:${me}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${de.id}-${Y}`)})})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(A,{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:pe&&(pe.auth.exists||pe.user.exists||pe.project.exists||pe.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[pe.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,pe.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,pe.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,pe.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(he,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>be(de.id),disabled:y===`disconnect:${de.id}`,children:y===`disconnect:${de.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"),se.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",se.length,")"]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const Z=se.map(me=>typeof me?.id=="string"?me.id:"").filter(me=>me.length>0);c(de.id,Z)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(he,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>d(de.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(A,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx($t,{value:h,onChange:Z=>j(Z.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),xe.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:xe.map(Z=>{const me=typeof Z?.id=="string"?Z.id:"",Y=typeof Z?.name=="string"?Z.name:me,Se=me?a(de.id,me):void 0,we=i.some(Q=>Q.providerID===de.id&&Q.modelID===me),ke=Xp(Se?.limit?.context),Fe=Xp(Se?.limit?.output),Ce=[];return Se?.tool_call&&Ce.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Se?.reasoning&&Ce.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Se?.attachment&&Ce.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:ge("flex items-center gap-3",we&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Y}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(ke||Fe)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[ke?`${ke} ${t("settings.providers.page.models.tokenBadge.context")}`:"",ke&&Fe?" · ":"",Fe?`${Fe} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),Ce.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:Ce.map(({key:Q,icon:ce,label:ve})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:ve,"aria-label":ve,children:s.jsx(A,{name:ce,className:"h-3 w-3"})},Q))}),s.jsx("button",{type:"button",onClick:()=>l(de.id,me),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(we?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(we?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:we?s.jsx(A,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},me)})})]})]})]})})},zC=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)},UC=t=>{const e=ot.c(122),{onItemSelect:n}=t,{t:r}=pt(),a=Ns(WC),i=Ns(KC),l=Ns(HC),c=Ns(GC),d=Ns(qC),f=Ns(JC),m=Ns(YC),u=Ns(QC),p=Ns(XC),b=Ns(ZC),g=Ns(e4),y=Ns(t4),x=Ns(s4),h=Ns(n4);let j,v;e[0]!==h?(j=()=>{h()},v=[h],e[0]=h,e[1]=j,e[2]=v):(j=e[1],v=e[2]),o.useEffect(j,v);const C=r4;let k;e[3]!==p?(k=U=>{p(U),C({usageAutoRefresh:U})},e[3]=p,e[4]=k):k=e[4];const w=k;let N;e[5]!==b?(N=U=>{const oe=Number(U);Number.isFinite(oe)&&(b(oe),C({usageRefreshIntervalMs:oe}))},e[5]=b,e[6]=N):N=e[6];const I=N;let E;e[7]!==g?(E=U=>{U!=="usage"&&U!=="remaining"||(g(U),C({usageDisplayMode:U}))},e[7]=g,e[8]=E):E=e[8];const P=E;let T;e[9]!==x?(T=U=>{x(U),C({usageShowPredValues:U})},e[9]=x,e[10]=T):T=e[10];const S=T;let M;e[11]===Symbol.for("react.memo_cache_sentinel")?(M=ge("flex h-full flex-col","bg-background"),e[11]=M):M=e[11];let D;e[12]!==r?(D=r("settings.usage.sidebar.title"),e[12]=r,e[13]=D):D=e[13];let F;e[14]!==D?(F=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:D}),e[14]=D,e[15]=F):F=e[15];let _;e[16]!==r?(_=r("settings.usage.sidebar.total",{count:Gr.length}),e[16]=r,e[17]=_):_=e[17];let V;e[18]!==_?(V=s.jsx("span",{className:"typography-meta text-muted-foreground",children:_}),e[18]=_,e[19]=V):V=e[19];let $;e[20]!==r?($=r("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[20]=r,e[21]=$):$=e[21];let O;e[22]!==w||e[23]!==$||e[24]!==f?(O=s.jsx(Pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(fs,{checked:f,onChange:w,ariaLabel:$})})}),e[22]=w,e[23]=$,e[24]=f,e[25]=O):O=e[25];let B;e[26]!==r?(B=r("settings.usage.sidebar.tooltip.autoRefresh"),e[26]=r,e[27]=B):B=e[27];let G;e[28]!==B?(G=s.jsx(At,{side:"bottom",children:B}),e[28]=B,e[29]=G):G=e[29];let R;e[30]!==O||e[31]!==G?(R=s.jsxs(It,{children:[O,G]}),e[30]=O,e[31]=G,e[32]=R):R=e[32];const H=String(m),J=!f;let ne;e[33]!==r?(ne=r("settings.usage.sidebar.field.intervalPlaceholder"),e[33]=r,e[34]=ne):ne=e[34];let ue;e[35]!==ne?(ue=s.jsx(rs,{className:"w-fit",children:s.jsx(ms,{placeholder:ne})}),e[35]=ne,e[36]=ue):ue=e[36];let de;e[37]===Symbol.for("react.memo_cache_sentinel")?(de=s.jsxs(as,{children:[s.jsx(Rt,{value:"30000",children:"30s"}),s.jsx(Rt,{value:"60000",children:"1m"}),s.jsx(Rt,{value:"300000",children:"5m"})]}),e[37]=de):de=e[37];let pe;e[38]!==I||e[39]!==H||e[40]!==J||e[41]!==ue?(pe=s.jsxs(ns,{value:H,onValueChange:I,disabled:J,children:[ue,de]}),e[38]=I,e[39]=H,e[40]=J,e[41]=ue,e[42]=pe):pe=e[42];let W;e[43]!==c?(W=()=>c(),e[43]=c,e[44]=W):W=e[44];let te;e[45]!==r?(te=r("settings.usage.sidebar.actions.refreshAria"),e[45]=r,e[46]=te):te=e[46];let X;e[47]!==r?(X=r("settings.usage.sidebar.actions.refreshTitle"),e[47]=r,e[48]=X):X=e[48];const ee=d&&"animate-spin";let fe;e[49]!==ee?(fe=ge("h-3.5 w-3.5",ee),e[49]=ee,e[50]=fe):fe=e[50];let be;e[51]!==fe?(be=s.jsx(A,{name:"refresh",className:fe}),e[51]=fe,e[52]=be):be=e[52];let Ne;e[53]!==d||e[54]!==W||e[55]!==te||e[56]!==X||e[57]!==be?(Ne=s.jsx(he,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:W,"aria-label":te,title:X,disabled:d,children:be}),e[53]=d,e[54]=W,e[55]=te,e[56]=X,e[57]=be,e[58]=Ne):Ne=e[58];let se;e[59]!==R||e[60]!==pe||e[61]!==Ne?(se=s.jsxs("div",{className:"flex items-center gap-2",children:[R,pe,Ne]}),e[59]=R,e[60]=pe,e[61]=Ne,e[62]=se):se=e[62];let ie;e[63]!==V||e[64]!==se?(ie=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[V,se]}),e[63]=V,e[64]=se,e[65]=ie):ie=e[65];let ae;e[66]!==r?(ae=r("settings.usage.sidebar.field.display"),e[66]=r,e[67]=ae):ae=e[67];let xe;e[68]!==ae?(xe=s.jsx("span",{className:"typography-micro text-muted-foreground",children:ae}),e[68]=ae,e[69]=xe):xe=e[69];let Z;e[70]!==r?(Z=r("settings.usage.sidebar.field.displayModePlaceholder"),e[70]=r,e[71]=Z):Z=e[71];let me;e[72]!==Z?(me=s.jsx(rs,{className:"w-fit",children:s.jsx(ms,{placeholder:Z})}),e[72]=Z,e[73]=me):me=e[73];let Y;e[74]!==r?(Y=r("settings.usage.sidebar.field.displayModeUsage"),e[74]=r,e[75]=Y):Y=e[75];let Se;e[76]!==Y?(Se=s.jsx(Rt,{value:"usage",children:Y}),e[76]=Y,e[77]=Se):Se=e[77];let we;e[78]!==r?(we=r("settings.usage.sidebar.field.displayModeRemaining"),e[78]=r,e[79]=we):we=e[79];let ke;e[80]!==we?(ke=s.jsx(Rt,{value:"remaining",children:we}),e[80]=we,e[81]=ke):ke=e[81];let Fe;e[82]!==Se||e[83]!==ke?(Fe=s.jsxs(as,{children:[Se,ke]}),e[82]=Se,e[83]=ke,e[84]=Fe):Fe=e[84];let Ce;e[85]!==P||e[86]!==me||e[87]!==Fe||e[88]!==u?(Ce=s.jsxs(ns,{value:u,onValueChange:P,children:[me,Fe]}),e[85]=P,e[86]=me,e[87]=Fe,e[88]=u,e[89]=Ce):Ce=e[89];let Q;e[90]!==xe||e[91]!==Ce?(Q=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[xe,Ce]}),e[90]=xe,e[91]=Ce,e[92]=Q):Q=e[92];let ce;e[93]!==r?(ce=r("settings.usage.sidebar.field.showPredictions"),e[93]=r,e[94]=ce):ce=e[94];let ve;e[95]!==ce?(ve=s.jsx("span",{className:"typography-micro text-muted-foreground",children:ce}),e[95]=ce,e[96]=ve):ve=e[96];let le;e[97]!==r?(le=r("settings.usage.sidebar.field.showPredictions"),e[97]=r,e[98]=le):le=e[98];let Ae;e[99]!==S||e[100]!==y||e[101]!==le?(Ae=s.jsx(fs,{checked:y,onChange:S,ariaLabel:le}),e[99]=S,e[100]=y,e[101]=le,e[102]=Ae):Ae=e[102];let Te;e[103]!==ve||e[104]!==Ae?(Te=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[ve,Ae]}),e[103]=ve,e[104]=Ae,e[105]=Te):Te=e[105];let $e;e[106]!==ie||e[107]!==Q||e[108]!==Te||e[109]!==F?($e=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[F,ie,Q,Te]}),e[106]=ie,e[107]=Q,e[108]=Te,e[109]=F,e[110]=$e):$e=e[110];let ye;e[111]!==n||e[112]!==a||e[113]!==i||e[114]!==l||e[115]!==r?(ye=Gr.map(U=>{const oe=a.find(Qe=>Qe.providerId===U.id),Ee=zC(oe?.usage),Oe=Gh(Ee),Ie=U.id===i,z=oe?.configured??!1,De=z?Oe==="critical"?{backgroundColor:"var(--status-error)"}:Oe==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:ge("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:()=>{l(U.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:De}),s.jsx(wr,{providerId:U.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:U.name}),!z&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r("settings.usage.sidebar.status.notSet")})]})},U.id)}),e[111]=n,e[112]=a,e[113]=i,e[114]=l,e[115]=r,e[116]=ye):ye=e[116];let q;e[117]!==ye?(q=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:ye}),e[117]=ye,e[118]=q):q=e[118];let L;return e[119]!==$e||e[120]!==q?(L=s.jsxs("div",{className:M,children:[$e,q]}),e[119]=$e,e[120]=q,e[121]=L):L=e[121],L};function WC(t){return t.results}function KC(t){return t.selectedProviderId}function HC(t){return t.setSelectedProvider}function GC(t){return t.fetchAllQuotas}function qC(t){return t.isLoading}function JC(t){return t.autoRefresh}function YC(t){return t.refreshIntervalMs}function QC(t){return t.displayMode}function XC(t){return t.setAutoRefresh}function ZC(t){return t.setRefreshInterval}function e4(t){return t.setDisplayMode}function t4(t){return t.showPredValues}function s4(t){return t.setShowPredValues}function n4(t){return t.loadSettings}async function r4(t){try{await Cs(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Xc=t=>{const e=ot.c(53),{title:n,window:r,subtitle:a,showToggle:i,toggleEnabled:l,onToggle:c}=t,d=i===void 0?!1:i,f=l===void 0?!1:l,m=Ns(a4),u=Ns(i4),p=m==="remaining"?r.remainingPercent:r.usedPercent,b=m==="remaining"?"remaining":"used";let g;e[0]!==p||e[1]!==r.valueLabel?(g=yo(r.valueLabel,p),e[0]=p,e[1]=r.valueLabel,e[2]=g):g=e[2];const y=g,x=r.resetAfterFormatted??r.resetAtFormatted;let h;e[3]!==x||e[4]!==r.resetAt?(h=mu(r.resetAt,x),e[3]=x,e[4]=r.resetAt,e[5]=h):h=e[5];const j=h;let v;e[6]!==n?(v=pu(n),e[6]=n,e[7]=v):v=e[7];const C=v;let k;e[8]!==n||e[9]!==r.resetAt||e[10]!==r.usedPercent||e[11]!==r.windowSeconds?(k=vo(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 w=k;let N;e:{if(!w||w.dailyAllocationPercent===null){N=null;break e}const ne=na(w.elapsedRatio);N=m==="remaining"?100-ne:ne}const I=N;let E;e[13]!==c||e[14]!==d||e[15]!==f?(E=d&&s.jsx(fs,{checked:f,onChange:ne=>c?.(ne),ariaLabel:"Show in dropdown"}),e[13]=c,e[14]=d,e[15]=f,e[16]=E):E=e[16];let P;e[17]!==C?(P=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:C}),e[17]=C,e[18]=P):P=e[18];let T;e[19]!==a?(T=a&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:a}),e[19]=a,e[20]=T):T=e[20];let S;e[21]!==P||e[22]!==T?(S=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[P,T]}),e[21]=P,e[22]=T,e[23]=S):S=e[23];let M;e[24]!==S||e[25]!==E?(M=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[E,S]}),e[24]=S,e[25]=E,e[26]=M):M=e[26];const D=y==="-"?"":y;let F;e[27]!==D?(F=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:D}),e[27]=D,e[28]=F):F=e[28];let _;e[29]!==M||e[30]!==F?(_=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[M,F]}),e[29]=M,e[30]=F,e[31]=_):_=e[31];let V;e[32]!==p||e[33]!==I||e[34]!==r.usedPercent?(V=s.jsx(jo,{percent:p,tonePercent:r.usedPercent,expectedMarkerPercent:I,className:"h-1.5"}),e[32]=p,e[33]=I,e[34]=r.usedPercent,e[35]=V):V=e[35];const $=j?`Resets ${j}`:"";let O;e[36]!==$?(O=s.jsx("span",{className:"typography-micro text-muted-foreground",children:$}),e[36]=$,e[37]=O):O=e[37];let B;e[38]!==b?(B=s.jsx("span",{className:"typography-micro text-muted-foreground",children:b}),e[38]=b,e[39]=B):B=e[39];let G;e[40]!==O||e[41]!==B?(G=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[O,B]}),e[40]=O,e[41]=B,e[42]=G):G=e[42];let R;e[43]!==V||e[44]!==G?(R=s.jsxs("div",{className:"mt-2.5",children:[V,G]}),e[43]=V,e[44]=G,e[45]=R):R=e[45];let H;e[46]!==w||e[47]!==u?(H=w&&u&&s.jsx("div",{className:"mt-1.5",children:s.jsx(No,{paceInfo:w})}),e[46]=w,e[47]=u,e[48]=H):H=e[48];let J;return e[49]!==_||e[50]!==R||e[51]!==H?(J=s.jsxs("div",{className:"py-3",children:[_,R,H]}),e[49]=_,e[50]=R,e[51]=H,e[52]=J):J=e[52],J};function a4(t){return t.displayMode}function i4(t){return t.showPredValues}const o4=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},l4=()=>{const{t}=pt(),e=Ns(S=>S.results),n=Ns(S=>S.selectedProviderId),r=Ns(S=>S.setSelectedProvider),a=Ns(S=>S.loadSettings),i=Ns(S=>S.fetchAllQuotas),l=Ns(S=>S.isLoading),c=Ns(S=>S.lastUpdated),d=Ns(S=>S.error),f=Ns(S=>S.dropdownProviderIds),m=Ns(S=>S.setDropdownProviderIds),u=Ns(S=>S.selectedModels),p=Ns(S=>S.toggleModelSelected),b=Ns(S=>S.applyDefaultSelections);Xh(),o.useEffect(()=>{a(),i()},[a,i]),o.useEffect(()=>{if(n||e.length===0)return;const S=e.find(M=>M.configured)?.providerId;r(S??Gr[0]?.id??null)},[e,n,r]);const g=e.find(S=>S.providerId===n)??null,x=Gr.find(S=>S.id===n)?.name??n??t("settings.usage.sidebar.title"),h=g?.usage,j=n?f.includes(n):!1,v=o.useCallback(S=>{if(!n)return;const M=S?Array.from(new Set([...f,n])):f.filter(D=>D!==n);m(M),Cs({usageDropdownProviders:M})},[f,n,m]),C=o.useMemo(()=>h?.models?Object.entries(h.models).map(([S,M])=>({name:S,windows:M})).filter(S=>Object.keys(S.windows.windows).length>0):[],[h?.models]);o.useEffect(()=>{n&&C.length>0&&b(n,C.map(S=>S.name))},[n,C,b]);const k=o.useMemo(()=>!n||C.length===0?new Map:T1(C,S=>S.name,n),[C,n]),w=o.useMemo(()=>{if(!n)return[];const S=Yh(n);return Qh(S)},[n]),[N,I]=o.useState(()=>({})),E=o.useCallback(S=>{I(M=>({...M,[S]:!M[S]}))},[]),P=o.useCallback(S=>{if(!n)return;p(n,S);const M=u[n]??[],F=M.includes(S)?M.filter(V=>V!==S):[...M,S],_={...u,[n]:F};Cs({usageSelectedModels:_})},[n,u,p]),T=n?u[n]??[]:[];return n?s.jsx(vs,{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(wr,{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:l?s.jsx("span",{className:"animate-pulse",children:t("settings.usage.page.header.refreshing")}):t("settings.usage.page.header.lastUpdated",{time:o4(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":j,onClick:()=>v(!j),onKeyDown:S=>{(S.key===" "||S.key==="Enter")&&(S.preventDefault(),v(!j))},children:[s.jsx(fs,{checked:j,onChange:v,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(A,{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")})]})]})]})}),!g&&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})]}),g&&!g.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")})]}),h?.windows&&Object.keys(h.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(h.windows).map(([S,M])=>s.jsx(Xc,{title:S,window:M},S))})})}),C.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:[w.map(S=>{const M=k.get(S.id)??[];if(M.length===0)return null;const D=N[S.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(jr,{open:!D,onOpenChange:()=>E(S.id),children:[s.jsxs(Lr,{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:S.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",M.length,")"]})]}),D?s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Nr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:M.map(F=>{const _=Object.entries(F.windows.windows);if(_.length===0)return null;const[V,$]=_[0],O=T.includes(F.name);return s.jsx(Xc,{title:V,subtitle:Ll(F.name),window:$,showToggle:!0,toggleEnabled:O,onToggle:()=>P(F.name)},F.name)})})})]})},S.id)}),(()=>{const S=k.get(null)??[];if(S.length===0)return null;const M=N.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(jr,{open:!M,onOpenChange:()=>E("other"),children:[s.jsxs(Lr,{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:["(",S.length,")"]})]}),M?s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Nr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:S.map(D=>{const F=Object.entries(D.windows.windows);if(F.length===0)return null;const[_,V]=F[0],$=T.includes(D.name);return s.jsx(Xc,{title:_,subtitle:Ll(D.name),window:V,showToggle:!0,toggleEnabled:$,onToggle:()=>P(D.name)},D.name)})})})]})})})()]})]}),g?.configured&&h&&Object.keys(h.windows??{}).length===0&&C.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")})})},c4="git.commit.generate",$d=ar(t=>({selectedPromptId:c4,setSelectedPromptId:e=>{t(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),d4=t=>{const e=ot.c(23),{onItemSelect:n}=t,{t:r}=pt(),a=$d(u4),i=$d(m4);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={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]=l):l=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 f;e[3]===Symbol.for("react.memo_cache_sentinel")?(f=[l,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]=f):f=e[3];const m=f;let u;e[4]!==r?(u=r("settings.magicPrompts.sidebar.title"),e[4]=r,e[5]=u):u=e[5];let p;e[6]!==u?(p=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:u}),e[6]=u,e[7]=p):p=e[7];let b;e[8]!==r?(b=r("settings.magicPrompts.sidebar.description"),e[8]=r,e[9]=b):b=e[9];let g;e[10]!==b?(g=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:b}),e[10]=b,e[11]=g):g=e[11];let y;e[12]!==p||e[13]!==g?(y=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[p,g]}),e[12]=p,e[13]=g,e[14]=y):y=e[14];let x;e[15]!==n||e[16]!==a||e[17]!==i||e[18]!==r?(x=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(j=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:r(j.groupKey)}),j.items.map(v=>{const C=a===v.id;return s.jsx("button",{type:"button",onClick:()=>{i(v.id),n?.()},className:ge("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",C?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:r(v.titleKey)})},v.id)})]},j.groupKey))}),e[15]=n,e[16]=a,e[17]=i,e[18]=r,e[19]=x):x=e[19];let h;return e[20]!==x||e[21]!==y?(h=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[y,x]}),e[20]=x,e[21]=y,e[22]=h):h=e[22],h};function u4(t){return t.selectedPromptId}function m4(t){return t.setSelectedPromptId}const ef={"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"}]}},tf=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),sf=t=>t.endsWith(".visible"),p4=()=>{const{t}=pt(),e=o.useCallback(w=>t(w),[t]),n=$d(w=>w.selectedPromptId),[r,a]=o.useState(!0),[i,l]=o.useState({}),[c,d]=o.useState({}),[f,m]=o.useState({}),[u,p]=o.useState({}),[b,g]=o.useState(!1);o.useEffect(()=>{let w=!0;return(async()=>{a(!0);try{const I=await Ay();if(!w)return;l(I)}catch(I){console.warn("Failed to load magic prompts:",I),K.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{w&&a(!1)}})(),()=>{w=!1}},[t]);const y=ef[n]??ef["git.commit.generate"],x=o.useCallback(w=>tf(i,w)?i[w]:xc(w),[i]),h=o.useCallback(w=>c[w]??x(w),[c,x]),j=o.useCallback((w,N)=>{d(I=>I[w]===N?I:{...I,[w]:N})},[]),v=o.useCallback(async w=>{const N=h(w);if(sf(w)&&N.trim().length===0){K.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(I=>({...I,[w]:!0}));try{const I=N===xc(w)?await Yu(w):await Cy(w,N);l(I.overrides),K.success(t("settings.magicPrompts.page.toast.saved"))}catch(I){const E=I instanceof Error?I.message:String(I);K.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:E})}finally{m(I=>({...I,[w]:!1}))}},[h,t]),C=o.useCallback(async w=>{p(N=>({...N,[w]:!0}));try{const N=await Yu(w);l(N.overrides),d(I=>({...I,[w]:xc(w)})),K.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(N){const I=N instanceof Error?N.message:String(N);K.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:I})}finally{p(N=>({...N,[w]:!1}))}},[t]),k=o.useCallback(async()=>{g(!0);try{const w=await Iy();l(w.overrides),d({}),K.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(w){const N=w instanceof Error?w.message:String(w);K.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:N})}finally{g(!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(y.titleKey)}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(A,{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(y.descriptionKey)})]})]})}),s.jsx(he,{variant:"outline",size:"sm",onClick:()=>{k()},disabled:b||Object.keys(i).length===0,children:t(b?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")})]}),y.blocks.map((w,N)=>{const I=Py(w.id),E=x(w.id),P=h(w.id),T=tf(i,w.id),S=P!==E,M=sf(w.id)&&P.trim().length===0,D=f[w.id]===!0,F=u[w.id]===!0;return s.jsxs("section",{className:N>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(w.titleKey)}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(A,{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.description})]})]}),I.placeholders&&I.placeholders.length>0&&s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[t("settings.magicPrompts.page.placeholdersLabel")," ",I.placeholders.map(_=>`{{${_.key}}}`).join(", ")]})]}),s.jsx(ln,{value:P,onChange:_=>j(w.id,_.target.value),className:"min-h-[220px] font-mono text-sm"}),M&&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(S?"settings.magicPrompts.page.status.unsavedChanges":T?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(he,{variant:"outline",size:"sm",onClick:()=>{C(w.id)},disabled:!T||D||F,children:t(F?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(he,{size:"sm",onClick:()=>{v(w.id)},disabled:!S||D||F||M,children:t(D?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},w.id)})]})})},f4=t=>{const e=ot.c(87),{onItemSelect:n}=t,{t:r}=pt(),[a,i]=o.useState(null),[l,c]=o.useState(null),{selectedSnippetName:d,snippets:f,setSelectedSnippet:m,setSnippetDraft:u,deleteSnippet:p,loadSnippets:b}=lc(Qn(h4));let g,y;e[0]!==b?(g=()=>{b()},y=[b],e[0]=b,e[1]=g,e[2]=y):(g=e[1],y=e[2]),o.useEffect(g,y);let x;e[3]!==n||e[4]!==m||e[5]!==u||e[6]!==f?(x=async()=>{const Ne=new Set(f.map(g4));let se="new-snippet",ie=1;for(;Ne.has(se);)se=`new-snippet-${ie++}`;u({name:se,scope:"global"}),m(se),n?.()},e[3]=n,e[4]=m,e[5]=u,e[6]=f,e[7]=x):x=e[7];const h=x;let j;e[8]!==a||e[9]!==p||e[10]!==r?(j=async()=>{if(!a)return;await p(a.name)?(K.success(r("settings.snippets.sidebar.toast.deleted")),i(null)):K.error(r("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=a,e[9]=p,e[10]=r,e[11]=j):j=e[11];const v=j;let C;e[12]!==f?(C=[...f].sort(x4),e[12]=f,e[13]=C):C=e[13];const k=C;let w;e[14]===Symbol.for("react.memo_cache_sentinel")?(w=ge("flex h-full flex-col","bg-background"),e[14]=w):w=e[14];let N;e[15]!==r?(N=r("settings.snippets.sidebar.title"),e[15]=r,e[16]=N):N=e[16];let I;e[17]!==N?(I=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:N}),e[17]=N,e[18]=I):I=e[18];let E;e[19]!==f.length||e[20]!==r?(E=r("settings.snippets.sidebar.total",{count:f.length}),e[19]=f.length,e[20]=r,e[21]=E):E=e[21];let P;e[22]!==E?(P=s.jsx("span",{className:"typography-meta text-muted-foreground",children:E}),e[22]=E,e[23]=P):P=e[23];let T;e[24]!==r?(T=r("settings.snippets.sidebar.actions.create"),e[24]=r,e[25]=T):T=e[25];let S;e[26]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[26]=S):S=e[26];let M;e[27]!==h||e[28]!==T?(M=s.jsx(he,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:h,"aria-label":T,children:S}),e[27]=h,e[28]=T,e[29]=M):M=e[29];let D;e[30]!==P||e[31]!==M?(D=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[P,M]}),e[30]=P,e[31]=M,e[32]=D):D=e[32];let F;e[33]!==D||e[34]!==I?(F=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[I,D]}),e[33]=D,e[34]=I,e[35]=F):F=e[35];let _;if(e[36]!==n||e[37]!==l||e[38]!==d||e[39]!==m||e[40]!==k||e[41]!==r){let Ne;e[43]!==n||e[44]!==l||e[45]!==d||e[46]!==m||e[47]!==r?(Ne=se=>s.jsxs("div",{className:ge("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",d===se.name?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsxs("button",{onClick:()=>{m(se.name),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.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["#",se.name]}),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:r(`snippets.source.${se.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:se.description||se.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(As,{open:l===se.name,onOpenChange:ie=>c(ie?se.name:null),children:[s.jsx(Is,{asChild:!0,children:s.jsx(he,{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","aria-label":r("settings.snippets.sidebar.actions.more",{name:se.name}),children:s.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ps,{align:"end",className:"w-fit min-w-20",children:s.jsxs(Ot,{onClick:ie=>{ie.stopPropagation(),i(se)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},`${se.source}:${se.filePath}`),e[43]=n,e[44]=l,e[45]=d,e[46]=m,e[47]=r,e[48]=Ne):Ne=e[48],_=k.map(Ne),e[36]=n,e[37]=l,e[38]=d,e[39]=m,e[40]=k,e[41]=r,e[42]=_}else _=e[42];let V;e[49]!==_?(V=s.jsx(vs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:_}),e[49]=_,e[50]=V):V=e[50];const $=a!==null;let O;e[51]===Symbol.for("react.memo_cache_sentinel")?(O=Ne=>{Ne||i(null)},e[51]=O):O=e[51];let B;e[52]!==r?(B=r("settings.snippets.sidebar.dialog.deleteTitle"),e[52]=r,e[53]=B):B=e[53];let G;e[54]!==B?(G=s.jsx(ds,{children:B}),e[54]=B,e[55]=G):G=e[55];const R=a?.name??"";let H;e[56]!==r||e[57]!==R?(H=r("settings.snippets.sidebar.dialog.deleteDescription",{name:R}),e[56]=r,e[57]=R,e[58]=H):H=e[58];let J;e[59]!==H?(J=s.jsx(ys,{children:H}),e[59]=H,e[60]=J):J=e[60];let ne;e[61]!==G||e[62]!==J?(ne=s.jsxs(ps,{children:[G,J]}),e[61]=G,e[62]=J,e[63]=ne):ne=e[63];let ue;e[64]===Symbol.for("react.memo_cache_sentinel")?(ue=()=>i(null),e[64]=ue):ue=e[64];let de;e[65]!==r?(de=r("settings.common.actions.cancel"),e[65]=r,e[66]=de):de=e[66];let pe;e[67]!==de?(pe=s.jsx(he,{size:"sm",variant:"ghost",onClick:ue,children:de}),e[67]=de,e[68]=pe):pe=e[68];let W;e[69]!==r?(W=r("settings.common.actions.delete"),e[69]=r,e[70]=W):W=e[70];let te;e[71]!==v||e[72]!==W?(te=s.jsx(he,{size:"sm",onClick:v,children:W}),e[71]=v,e[72]=W,e[73]=te):te=e[73];let X;e[74]!==pe||e[75]!==te?(X=s.jsxs(Rs,{children:[pe,te]}),e[74]=pe,e[75]=te,e[76]=X):X=e[76];let ee;e[77]!==ne||e[78]!==X?(ee=s.jsxs(os,{className:"max-w-md",children:[ne,X]}),e[77]=ne,e[78]=X,e[79]=ee):ee=e[79];let fe;e[80]!==$||e[81]!==ee?(fe=s.jsx(ls,{open:$,onOpenChange:O,children:ee}),e[80]=$,e[81]=ee,e[82]=fe):fe=e[82];let be;return e[83]!==F||e[84]!==V||e[85]!==fe?(be=s.jsxs("div",{className:w,children:[F,V,fe]}),e[83]=F,e[84]=V,e[85]=fe,e[86]=be):be=e[86],be};function h4(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function g4(t){return t.name}function x4(t,e){return t.name.localeCompare(e.name)}const b4=()=>{const{t}=pt(),{selectedSnippetName:e,snippets:n,snippetDraft:r,setSnippetDraft:a,updateSnippet:i,createSnippet:l}=lc(Qn(I=>({selectedSnippetName:I.selectedSnippetName,snippets:I.snippets,snippetDraft:I.snippetDraft,setSnippetDraft:I.setSnippetDraft,updateSnippet:I.updateSnippet,createSnippet:I.createSnippet}))),c=o.useMemo(()=>e?n.find(I=>I.name===e||I.aliases.includes(e))??null:null,[e,n]),d=!!(r&&r.name===e&&!c),[f,m]=o.useState(""),[u,p]=o.useState("global"),[b,g]=o.useState(""),[y,x]=o.useState(""),[h,j]=o.useState(""),[v,C]=o.useState(!1),k=o.useRef(null);o.useEffect(()=>{if(d&&r){const I={draftName:r.name||"",draftScope:r.scope||"global",description:r.description||"",aliases:(r.aliases||[]).join(", "),content:r.content||""};m(I.draftName),p(I.draftScope),g(I.description),x(I.aliases),j(I.content),k.current=I}else if(c){const I={draftName:"",draftScope:"global",description:c.description??"",aliases:c.aliases.join(", "),content:c.content};g(I.description),x(I.aliases),j(I.content),k.current=I}},[c,d,e,r]);const w=o.useMemo(()=>{const I=k.current;return I?d&&f!==I.draftName||d&&u!==I.draftScope?!0:b!==I.description||y!==I.aliases||h!==I.content:!1},[y,h,b,f,u,d]),N=async()=>{const I=d?f.trim().replace(/\s+/g,"-"):e?.trim();if(!I){K.error(t("settings.snippets.page.toast.nameRequired"));return}if(!h.trim()){K.error(t("settings.snippets.page.toast.contentRequired"));return}const E=y.split(",").map(P=>P.trim()).filter(Boolean);C(!0);try{if(!(d?await l(I,h,{aliases:E,description:b,scope:u}):await i(I,{content:h,aliases:E,description:b}))){K.error(t("settings.snippets.page.toast.saveFailed"));return}K.success(t("settings.snippets.page.toast.saved")),d&&a(null)}finally{C(!1)}};return e?s.jsx(vs,{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 min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:d?t("settings.snippets.page.title.new"):`#${e}`}),c?s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:c.filePath}):null]}),s.jsxs("div",{className:"mb-8 space-y-3 px-2",children:[s.jsxs("div",{children:[d?s.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"#"}),s.jsx($t,{value:f,onChange:I=>m(I.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(ns,{value:u,onValueChange:I=>p(I),children:[s.jsx(rs,{className:"w-fit min-w-[100px]",children:s.jsx(ms,{})}),s.jsxs(as,{align:"end",children:[s.jsx(Rt,{value:"global",children:t("settings.common.scope.global")}),s.jsx(Rt,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx($t,{value:b,onChange:I=>g(I.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"mt-1.5 h-7 w-full max-w-sm px-2"})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.aliases")}),s.jsx($t,{value:y,onChange:I=>x(I.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"mt-1.5 h-7 w-full max-w-sm px-2"})]})]}),s.jsxs("div",{className:"mb-2 px-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.content")}),s.jsx(ln,{value:h,onChange:I=>j(I.target.value),placeholder:t("settings.snippets.page.field.contentPlaceholder"),rows:12,className:"mt-1.5 w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),s.jsx("p",{className:"mt-2 typography-meta text-muted-foreground",children:t("settings.snippets.page.hint")})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(he,{onClick:N,disabled:v||!w,size:"xs",className:"!font-normal",children:t(v?"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(A,{name:"file-text",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.snippets.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.snippets.page.empty.description")})]})})},qg=()=>{const{t}=pt(),e=jt(u=>u.settingsGitmojiEnabled),n=jt(u=>u.setSettingsGitmojiEnabled),r=ru(),a=_e(u=>u.gitChangesViewMode),i=_e(u=>u.setGitChangesViewMode),[l,c]=o.useState(!0),d=o.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);o.useEffect(()=>{(async()=>{try{let p=null;if(!p){const b=dr()?.settings;if(b)try{const y=(await b.load())?.settings;y&&(p={gitmojiEnabled:typeof y.gitmojiEnabled=="boolean"?y.gitmojiEnabled:void 0,gitChangesViewMode:y.gitChangesViewMode==="flat"||y.gitChangesViewMode==="tree"?y.gitChangesViewMode:void 0})}catch{}}if(!p){const b=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});b.ok&&(p=await b.json())}p&&(typeof p.gitmojiEnabled=="boolean"&&n(p.gitmojiEnabled),(p.gitChangesViewMode==="flat"||p.gitChangesViewMode==="tree")&&i(p.gitChangesViewMode))}catch(p){console.warn("Failed to load git settings:",p)}finally{c(!1)}})()},[i,n]);const f=o.useCallback(async u=>{n(u);try{await Cs({gitmojiEnabled:u})}catch(p){console.warn("Failed to save gitmoji setting:",p)}},[n]),m=o.useCallback(u=>{u!==a&&(i(u),Cs({gitChangesViewMode:u}))},[a,i]);return l?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 p=a===u.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":p,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(Oa,{checked:p,onChange:()=>{m(u.id)},ariaLabel:t("settings.openchamber.git.optionAria",{option:u.label})}),s.jsx("span",{className:p?"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:()=>{f(!e)},onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),f(!e))},children:[s.jsx(fs,{checked:e,onChange:u=>{f(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:()=>bc(!r),onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),bc(!r))},children:[s.jsx(fs,{checked:r,onChange:bc,ariaLabel:t("settings.openchamber.git.showGitignoredAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.showGitignored")})]})]})]})},Jg=()=>{const{t}=pt(),{isMobile:e}=an(),n=dr()?.github,r=Yn(I=>I.status),a=Yn(I=>I.isLoading),i=Yn(I=>I.hasChecked),l=Yn(I=>I.refreshStatus),c=Yn(I=>I.setStatus),d=o.useCallback(async I=>{await rr(I)},[]),[f,m]=o.useState(!1),[u,p]=o.useState(null),[b,g]=o.useState(null),y=o.useRef(null),x=o.useCallback(()=>{y.current!=null&&(window.clearInterval(y.current),y.current=null),g(null)},[]);o.useEffect(()=>((async()=>{try{i||await l(n)}catch(I){console.warn("Failed to load GitHub auth status:",I)}})(),()=>{x()}),[i,l,n,x]);const h=o.useCallback(async()=>{m(!0);try{const I=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({})}),T=await P.json().catch(()=>null);if(!P.ok||!T||!("deviceCode"in T))throw new Error(T?.error||P.statusText);return T})();p(I),g(Math.max(1,I.interval)*1e3);const E=I.verificationUriComplete||I.verificationUri;d(E)}catch(I){console.error("Failed to start GitHub connect:",I),K.error(t("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[d,n,t]),j=o.useCallback(async I=>{if(n)return n.authComplete(I);const E=await fetch("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:I})}),P=await E.json().catch(()=>null);if(!E.ok||!P)throw new Error(P?.error||E.statusText);return P},[n]);o.useEffect(()=>{if(!(!u?.deviceCode||!b)&&y.current==null)return y.current=window.setInterval(()=>{(async()=>{try{const I=await j(u.deviceCode);if(I.connected){K.success(t("settings.github.page.toast.connected")),p(null),x(),await l(n,{force:!0});return}I.status==="slow_down"&&g(E=>E?E+5e3:5e3),(I.status==="expired_token"||I.status==="access_denied")&&(K.error(I.error||t("settings.github.page.toast.authorizationFailed")),p(null),x())}catch(I){console.warn("GitHub polling failed:",I)}})()},b),()=>{y.current!=null&&(window.clearInterval(y.current),y.current=null)}},[u,b,j,l,n,x,t]);const v=o.useCallback(async()=>{m(!0);try{if(x(),p(null),n)await n.authDisconnect();else{const I=await fetch("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!I.ok)throw new Error(I.statusText)}K.success(t("settings.github.page.toast.disconnected")),await l(n,{force:!0})}catch(I){console.error("Failed to disconnect GitHub:",I),K.error(t("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[l,n,x,t]),C=o.useCallback(async I=>{if(I){m(!0);try{const E=n?await n.authActivate(I):await(async()=>{const P=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:I})}),T=await P.json().catch(()=>null);if(!P.ok||!T)throw new Error(T?.error||P.statusText);return T})();c(E),K.success(t("settings.github.page.toast.accountSwitched"))}catch(E){console.error("Failed to switch GitHub account:",E),K.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,c,t]);if(a)return null;const k=!!r?.connected,w=r?.user,N=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(A,{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:[k?s.jsxs("div",{className:ge("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ge("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[w?.avatarUrl?s.jsx("img",{src:w.avatarUrl,alt:w.login?t("settings.github.page.avatarAlt.withLogin",{login:w.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:w?.name?.trim()||w?.login||"GitHub"}),s.jsxs("div",{className:ge("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(A,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:w?.login||t("settings.github.page.label.unknownUser")}),w?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),w?.email&&s.jsx("span",{children:w.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(he,{size:"sm",variant:"outline",onClick:v,disabled:f,className:ge("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(he,{size:"sm",variant:"default",onClick:h,disabled:f,children:t("settings.github.page.actions.connect")})]}),N.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:N.map(I=>{const E=I.user,P=!!I.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(A,{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(he,{size:"sm",variant:"ghost",onClick:()=>C(I.id),disabled:f,children:t("settings.github.page.actions.switchTo")})]},I.id)})})]})]}),k&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(he,{size:"sm",variant:"outline",onClick:h,disabled:f,className:ge(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(he,{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(he,{size:"sm",variant:"ghost",disabled:f,onClick:()=>{x(),p(null)},children:t("settings.common.actions.cancel")})]})]})]})},nf=[{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)"}],y4=[{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"}],v4=({open:t,onOpenChange:e,profileId:n,importData:r})=>{const{t:a}=pt(),i=tr(R=>R.getProfileById),l=tr(R=>R.createProfile),c=tr(R=>R.updateProfile),d=tr(R=>R.deleteProfile),f=o.useMemo(()=>n&&n!=="new"&&!r?i(n):null,[n,i,r]),m=n==="new"||r!=null,u=n==="global",[p,b]=o.useState(""),[g,y]=o.useState(""),[x,h]=o.useState(""),[j,v]=o.useState("ssh"),[C,k]=o.useState(""),[w,N]=o.useState(""),[I,E]=o.useState("keyword"),[P,T]=o.useState("branch"),[S,M]=o.useState(!1),[D,F]=o.useState(!1),[_,V]=o.useState(!1);o.useEffect(()=>{if(t){if(r){const R=r.host.split("/"),H=R.length>=3?R[R.length-1]:r.host;b(H),y(r.username),h(""),v("token"),k(""),N(r.host),E("string"),T("code")}else if(m)b(""),y(""),h(""),v("ssh"),k(""),N(""),E("keyword"),T("branch");else if(f)b(f.name),y(f.userName),h(f.userEmail),v(f.authType||"ssh"),k(f.sshKey||""),N(f.host||""),E(f.color||"keyword"),T(f.icon||"branch");else if(u){const R=i("global");R&&(b(R.name),y(R.userName),h(R.userEmail),v(R.authType||"ssh"),k(R.sshKey||""),N(R.host||""),E(R.color||"keyword"),T(R.icon||"branch"))}}},[t,n,f,m,r,u,i]);const $=async()=>{if(!g.trim()||!x.trim()){K.error(a("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(j==="token"&&!w.trim()){K.error(a("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}M(!0);try{const R={name:p.trim()||g.trim(),userName:g.trim(),userEmail:x.trim(),authType:j,sshKey:j==="ssh"&&C.trim()||null,host:j==="token"&&w.trim()||null,color:I,icon:P};let H;if(m)H=await l(R);else if(n)H=await c(n,R);else return;H?(K.success(a(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):K.error(a(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(R){console.error("Error saving profile:",R),K.error(a("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{M(!1)}},O=async()=>{if(!(!n||m)){V(!0);try{await d(n)?(K.success(a("settings.gitIdentities.editor.toast.profileDeleted")),F(!1),e(!1)):K.error(a("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(R){console.error("Error deleting profile:",R),K.error(a("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{V(!1)}}},B=o.useMemo(()=>nf.find(H=>H.key===I)?.cssVar||"var(--syntax-keyword)",[I]),G=r?a("settings.gitIdentities.editor.title.importCredential"):m?a("settings.gitIdentities.editor.title.newIdentity"):u?a("settings.gitIdentities.editor.title.globalIdentity"):f?.name||a("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(ls,{open:t,onOpenChange:e,children:s.jsxs(os,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:G}),s.jsx(ys,{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($t,{value:p,onChange:R=>b(R.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:nf.map(R=>s.jsx("button",{type:"button",onClick:()=>E(R.key),className:ge("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",I===R.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:R.cssVar},title:R.label},R.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:y4.map(R=>{const H=R.Icon;return s.jsx("button",{type:"button",onClick:()=>T(R.key),className:ge("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",P===R.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:R.label,children:s.jsx(A,{name:H,className:"w-3.5 h-3.5",style:{color:P===R.key?B:"var(--surface-muted-foreground)"}})},R.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(A,{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($t,{value:g,onChange:R=>y(R.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(A,{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($t,{type:"email",value:x,onChange:R=>h(R.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(he,{size:"sm",type:"button",variant:"chip","aria-pressed":j==="ssh",onClick:()=>v("ssh"),children:[s.jsx(A,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(he,{size:"sm",type:"button",variant:"chip","aria-pressed":j==="token",onClick:()=>v("token"),children:[s.jsx(A,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",a("settings.gitIdentities.editor.field.authToken")]})]})]}),j==="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(A,{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($t,{value:C,onChange:R=>k(R.target.value),placeholder:a("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),j==="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(A,{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($t,{value:w,onChange:R=>N(R.target.value),placeholder:a("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(Rs,{className:"gap-2",children:[!u&&!m&&s.jsxs(he,{variant:"outline",size:"sm",onClick:()=>F(!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(A,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",a("settings.common.actions.delete")]}),s.jsx(he,{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(he,{size:"sm",onClick:$,disabled:S,children:a(S?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(ls,{open:D,onOpenChange:R=>{_||F(R)},children:s.jsxs(os,{className:"max-w-md",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:a("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(ys,{children:a("settings.gitIdentities.page.deleteDialog.description",{name:f?.name||p})})]}),s.jsxs(Rs,{children:[s.jsx(he,{variant:"ghost",onClick:()=>F(!1),disabled:_,children:a("settings.common.actions.cancel")}),s.jsx(he,{size:"sm",variant:"destructive",onClick:()=>{O()},disabled:_,children:a("settings.common.actions.delete")})]})]})})]})},w4={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},j4={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},N4=()=>{const t=ot.c(116),{t:e}=pt(),{profiles:n,globalIdentity:r,defaultGitIdentityId:a,deleteProfile:i,loadProfiles:l,loadGlobalIdentity:c,loadDiscoveredCredentials:d,loadDefaultGitIdentityId:f,setDefaultGitIdentityId:m,getUnimportedCredentials:u}=tr(Qn(k4)),[p,b]=o.useState(!1),[g,y]=o.useState(null),[x,h]=o.useState(null),[j,v]=o.useState(null),[C,k]=o.useState(!1);let w,N;t[0]!==f||t[1]!==d||t[2]!==c||t[3]!==l?(w=()=>{l(),c(),d(),f()},N=[l,c,d,f],t[0]=f,t[1]=d,t[2]=c,t[3]=l,t[4]=w,t[5]=N):(w=t[4],N=t[5]),o.useEffect(w,N);let I,E,P,T,S,M,D,F,_,V,$,O,B;if(t[6]!==a||t[7]!==j||t[8]!==i||t[9]!==u||t[10]!==r||t[11]!==n||t[12]!==m||t[13]!==e){const ke=u();let Fe;t[27]===Symbol.for("react.memo_cache_sentinel")?(Fe=(L,U)=>{y(L),h(U??null),b(!0)},t[27]=Fe):Fe=t[27];const Ce=Fe;let Q;t[28]!==a||t[29]!==m||t[30]!==e?(Q=async L=>{const U=a===L?null:L;if(!await m(U)){K.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}K.success(e(U?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[28]=a,t[29]=m,t[30]=e,t[31]=Q):Q=t[31];const ce=Q;let ve;t[32]!==j||t[33]!==i||t[34]!==e?(ve=async()=>{if(!j)return;k(!0),await i(j.id)?(K.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:j.name})),v(null)):K.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),k(!1)},t[32]=j,t[33]=i,t[34]=e,t[35]=ve):ve=t[35],E=ve,I=vs,T="h-full",S="w-full bg-background",B="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(Jg,{}),t[36]=P):P=t[36],$="border-t border-border/40 pt-6";let le;t[37]!==e?(le=e("settings.gitIdentities.page.section.title"),t[37]=e,t[38]=le):le=t[38];let Ae;t[39]!==le?(Ae=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:le})}),t[39]=le,t[40]=Ae):Ae=t[40];let Te,$e;t[41]===Symbol.for("react.memo_cache_sentinel")?(Te=()=>Ce("new"),$e=s.jsx(A,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=Te,t[42]=$e):(Te=t[41],$e=t[42]);let ye;t[43]!==e?(ye=e("settings.common.badge.new"),t[43]=e,t[44]=ye):ye=t[44];let q;t[45]!==ye?(q=s.jsxs(he,{size:"sm",variant:"outline",onClick:Te,children:[$e," ",ye]}),t[45]=ye,t[46]=q):q=t[46],t[47]!==Ae||t[48]!==q?(O=s.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[Ae,q]}),t[47]=Ae,t[48]=q,t[49]=O):O=t[49],M="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",D=r&&s.jsx(rf,{profile:r,isDefault:a==="global",onEdit:()=>Ce("global"),onToggleDefault:()=>ce("global"),isReadOnly:!0,hasBorder:n.length>0||ke.length>0}),F=n.map((L,U)=>s.jsx(rf,{profile:L,isDefault:a===L.id,onEdit:()=>Ce(L.id),onToggleDefault:()=>ce(L.id),onDelete:()=>v(L),hasBorder:U<n.length-1||ke.length>0},L.id)),_=!r&&n.length===0&&ke.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(A,{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")})]}),V=ke.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")})}),ke.map((L,U)=>s.jsx(S4,{credential:L,onImport:()=>Ce("new",{host:L.host,username:L.username}),hasBorder:U<ke.length-1},`${L.host}-${L.username}`))]}),t[6]=a,t[7]=j,t[8]=i,t[9]=u,t[10]=r,t[11]=n,t[12]=m,t[13]=e,t[14]=I,t[15]=E,t[16]=P,t[17]=T,t[18]=S,t[19]=M,t[20]=D,t[21]=F,t[22]=_,t[23]=V,t[24]=$,t[25]=O,t[26]=B}else I=t[14],E=t[15],P=t[16],T=t[17],S=t[18],M=t[19],D=t[20],F=t[21],_=t[22],V=t[23],$=t[24],O=t[25],B=t[26];let G;t[50]!==M||t[51]!==D||t[52]!==F||t[53]!==_||t[54]!==V?(G=s.jsxs("div",{className:M,children:[D,F,_,V]}),t[50]=M,t[51]=D,t[52]=F,t[53]=_,t[54]=V,t[55]=G):G=t[55];let R;t[56]!==G||t[57]!==$||t[58]!==O?(R=s.jsxs("div",{className:$,children:[O,G]}),t[56]=G,t[57]=$,t[58]=O,t[59]=R):R=t[59];let H;t[60]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(qg,{}),t[60]=H):H=t[60];let J;t[61]!==P||t[62]!==R||t[63]!==B?(J=s.jsxs("div",{className:B,children:[P,R,H]}),t[61]=P,t[62]=R,t[63]=B,t[64]=J):J=t[64];let ne;t[65]!==I||t[66]!==T||t[67]!==S||t[68]!==J?(ne=s.jsx(I,{outerClassName:T,className:S,children:J}),t[65]=I,t[66]=T,t[67]=S,t[68]=J,t[69]=ne):ne=t[69];let ue;t[70]!==x||t[71]!==p||t[72]!==g?(ue=s.jsx(v4,{open:p,onOpenChange:b,profileId:g,importData:x}),t[70]=x,t[71]=p,t[72]=g,t[73]=ue):ue=t[73];const de=j!==null;let pe;t[74]!==C?(pe=ke=>{C||ke||v(null)},t[74]=C,t[75]=pe):pe=t[75];let W;t[76]!==e?(W=e("settings.gitIdentities.page.deleteDialog.title"),t[76]=e,t[77]=W):W=t[77];let te;t[78]!==W?(te=s.jsx(ds,{children:W}),t[78]=W,t[79]=te):te=t[79];const X=j?.name??"";let ee;t[80]!==e||t[81]!==X?(ee=e("settings.gitIdentities.page.deleteDialog.description",{name:X}),t[80]=e,t[81]=X,t[82]=ee):ee=t[82];let fe;t[83]!==ee?(fe=s.jsx(ys,{children:ee}),t[83]=ee,t[84]=fe):fe=t[84];let be;t[85]!==te||t[86]!==fe?(be=s.jsxs(ps,{children:[te,fe]}),t[85]=te,t[86]=fe,t[87]=be):be=t[87];let Ne;t[88]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>v(null),t[88]=Ne):Ne=t[88];let se;t[89]!==e?(se=e("settings.common.actions.cancel"),t[89]=e,t[90]=se):se=t[90];let ie;t[91]!==C||t[92]!==se?(ie=s.jsx(he,{variant:"ghost",onClick:Ne,disabled:C,children:se}),t[91]=C,t[92]=se,t[93]=ie):ie=t[93];let ae;t[94]!==E?(ae=()=>{E()},t[94]=E,t[95]=ae):ae=t[95];let xe;t[96]!==e?(xe=e("settings.common.actions.delete"),t[96]=e,t[97]=xe):xe=t[97];let Z;t[98]!==C||t[99]!==ae||t[100]!==xe?(Z=s.jsx(he,{size:"sm",variant:"destructive",onClick:ae,disabled:C,children:xe}),t[98]=C,t[99]=ae,t[100]=xe,t[101]=Z):Z=t[101];let me;t[102]!==ie||t[103]!==Z?(me=s.jsxs(Rs,{children:[ie,Z]}),t[102]=ie,t[103]=Z,t[104]=me):me=t[104];let Y;t[105]!==be||t[106]!==me?(Y=s.jsxs(os,{className:"max-w-md",children:[be,me]}),t[105]=be,t[106]=me,t[107]=Y):Y=t[107];let Se;t[108]!==de||t[109]!==pe||t[110]!==Y?(Se=s.jsx(ls,{open:de,onOpenChange:pe,children:Y}),t[108]=de,t[109]=pe,t[110]=Y,t[111]=Se):Se=t[111];let we;return t[112]!==ne||t[113]!==ue||t[114]!==Se?(we=s.jsxs(s.Fragment,{children:[ne,ue,Se]}),t[112]=ne,t[113]=ue,t[114]=Se,t[115]=we):we=t[115],we},rf=t=>{const e=ot.c(54),{profile:n,isDefault:r,onEdit:a,onToggleDefault:i,onDelete:l,isReadOnly:c,hasBorder:d}=t,{t:f}=pt(),m=w4[n.icon||"branch"]||"git-branch",u=j4[n.color||""],p=n.authType||"ssh";let b;e[0]!==a?(b=O=>{O.currentTarget===O.target&&(O.key!=="Enter"&&O.key!==" "||(O.preventDefault(),a()))},e[0]=a,e[1]=b):b=e[1];const g=b,y=d&&"border-b border-[var(--surface-subtle)]";let x;e[2]!==y?(x=ge("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",y),e[2]=y,e[3]=x):x=e[3];let h;e[4]!==u?(h={color:u},e[4]=u,e[5]=h):h=e[5];let j;e[6]!==m||e[7]!==h?(j=s.jsx(A,{name:m,className:"w-4 h-4 shrink-0",style:h}),e[6]=m,e[7]=h,e[8]=j):j=e[8];let v;e[9]!==n.name?(v=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:n.name}),e[9]=n.name,e[10]=v):v=e[10];let C;e[11]!==p?(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}),e[11]=p,e[12]=C):C=e[12];let k;e[13]!==r||e[14]!==f?(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:f("settings.gitIdentities.page.badge.default")}),e[13]=r,e[14]=f,e[15]=k):k=e[15];let w;e[16]!==c||e[17]!==f?(w=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:f("settings.agents.sidebar.badge.system")}),e[16]=c,e[17]=f,e[18]=w):w=e[18];let N;e[19]!==v||e[20]!==C||e[21]!==k||e[22]!==w?(N=s.jsxs("div",{className:"flex items-center gap-1.5",children:[v,C,k,w]}),e[19]=v,e[20]=C,e[21]=k,e[22]=w,e[23]=N):N=e[23];const I=p==="token"&&n.host?n.host:n.userEmail;let E;e[24]!==I?(E=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:I}),e[24]=I,e[25]=E):E=e[25];let P;e[26]!==N||e[27]!==E?(P=s.jsxs("div",{className:"min-w-0",children:[N,E]}),e[26]=N,e[27]=E,e[28]=P):P=e[28];let T;e[29]!==P||e[30]!==j?(T=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[j,P]}),e[29]=P,e[30]=j,e[31]=T):T=e[31];let S;e[32]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(Is,{asChild:!0,children:s.jsx(he,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:C4,children:s.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[32]=S):S=e[32];let M;e[33]!==i?(M=O=>{O.stopPropagation(),i()},e[33]=i,e[34]=M):M=e[34];let D;e[35]!==r||e[36]!==f?(D=f(r?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault"),e[35]=r,e[36]=f,e[37]=D):D=e[37];let F;e[38]!==M||e[39]!==D?(F=s.jsx(Ot,{onClick:M,children:D}),e[38]=M,e[39]=D,e[40]=F):F=e[40];let _;e[41]!==c||e[42]!==l||e[43]!==f?(_=!c&&l&&s.jsxs(Ot,{onClick:O=>{O.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]}),e[41]=c,e[42]=l,e[43]=f,e[44]=_):_=e[44];let V;e[45]!==F||e[46]!==_?(V=s.jsxs(As,{children:[S,s.jsxs(Ps,{align:"end",className:"w-fit min-w-28",children:[F,_]})]}),e[45]=F,e[46]=_,e[47]=V):V=e[47];let $;return e[48]!==g||e[49]!==a||e[50]!==T||e[51]!==V||e[52]!==x?($=s.jsxs("div",{className:x,onClick:a,role:"button",tabIndex:0,onKeyDown:g,children:[T,V]}),e[48]=g,e[49]=a,e[50]=T,e[51]=V,e[52]=x,e[53]=$):$=e[53],$},S4=t=>{const e=ot.c(21),{credential:n,onImport:r,hasBorder:a}=t,{t:i}=pt();let l;e[0]!==n.host?(l=n.host.split("/"),e[0]=n.host,e[1]=l):l=e[1];const c=l,d=c.length>=3?c[c.length-1]:n.host,f=n.host.includes("/"),m=a&&"border-b border-[var(--surface-subtle)]";let u;e[2]!==m?(u=ge("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 p;e[4]!==d?(p=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:d}),e[4]=d,e[5]=p):p=e[5];const b=f?n.host:n.username;let g;e[6]!==b?(g=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:b}),e[6]=b,e[7]=g):g=e[7];let y;e[8]!==p||e[9]!==g?(y=s.jsxs("div",{className:"min-w-0",children:[p,g]}),e[8]=p,e[9]=g,e[10]=y):y=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(A,{name:"download",className:"h-3 w-3"}),e[11]=x):x=e[11];let h;e[12]!==i?(h=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=h):h=e[13];let j;e[14]!==r||e[15]!==h?(j=s.jsxs(he,{size:"sm",variant:"ghost",onClick:r,className:"gap-1 shrink-0",children:[x,h]}),e[14]=r,e[15]=h,e[16]=j):j=e[16];let v;return e[17]!==j||e[18]!==u||e[19]!==y?(v=s.jsxs("div",{className:u,children:[y,j]}),e[17]=j,e[18]=u,e[19]=y,e[20]=v):v=e[20],v};function k4(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 C4(t){return t.stopPropagation()}const Yg=()=>{const t=Dy();return{displayMode:t,installed:t!=="browser",browserTab:t==="browser"}},Qg=()=>{const t=ot.c(2),[e,n]=o.useState(I4);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)")],l=()=>{n(Yg())};l();for(const c of i)typeof c.addEventListener=="function"?c.addEventListener("change",l):typeof c.addListener=="function"&&c.addListener(l);return window.addEventListener("appinstalled",l),window.addEventListener("focus",l),()=>{for(const c of i)typeof c.removeEventListener=="function"?c.removeEventListener("change",l):typeof c.removeListener=="function"&&c.removeListener(l);window.removeEventListener("appinstalled",l),window.removeEventListener("focus",l)}},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),o.useEffect(r,a),e};function I4(){return Yg()}const P4=[{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"}],A4=[{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"}],D4=[{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"}],T4=[{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"}],Yi="OpenChamber - AI Coding Assistant",af=[{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"}],of=[{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"}],Zc=t=>t==="portrait"||t==="landscape"?t:"system",E4=[{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"}],M4=[{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"}],lf=[{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"}],R4=[{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"}],cf=[{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"}],df=[{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"}],F4=t=>t==="markdown"?"markdown":"plain",Iu=({visibleSettings:t})=>{const{locale:e,locales:n,setLocale:r,label:a,t:i}=pt(),l=o.useCallback(re=>i(re),[i]),{isMobile:c}=an(),{browserTab:d}=Qg(),f=rc(),m=_e(re=>re.showReasoningTraces),u=_e(re=>re.setShowReasoningTraces),p=_e(re=>re.collapsibleThinkingBlocks),b=_e(re=>re.setCollapsibleThinkingBlocks),g=_e(re=>re.mermaidRenderingMode),y=_e(re=>re.setMermaidRenderingMode),x=_e(re=>re.userMessageRenderingMode),h=_e(re=>re.setUserMessageRenderingMode),j=_e(re=>re.stickyUserHeader),v=_e(re=>re.setStickyUserHeader),C=_e(re=>re.wideChatLayoutEnabled),k=_e(re=>re.setWideChatLayoutEnabled),w=_e(re=>re.chatRenderMode),N=_e(re=>re.setChatRenderMode),I=_e(re=>re.activityRenderMode),E=_e(re=>re.setActivityRenderMode),P=_e(re=>re.fontSize),T=_e(re=>re.setFontSize),S=_e(re=>re.terminalFontSize),M=_e(re=>re.setTerminalFontSize),D=_e(re=>re.uiFont),F=_e(re=>re.setUiFont),_=_e(re=>re.monoFont),V=_e(re=>re.setMonoFont),$=_e(re=>re.padding),O=_e(re=>re.setPadding),B=_e(re=>re.inputBarOffset),G=_e(re=>re.setInputBarOffset),R=_e(re=>re.mobileKeyboardMode),H=_e(re=>re.setMobileKeyboardMode),J=_e(re=>re.diffLayoutPreference),ne=_e(re=>re.setDiffLayoutPreference),ue=_e(re=>re.diffViewMode),de=_e(re=>re.setDiffViewMode),pe=_e(re=>re.showTerminalQuickKeysOnDesktop),W=_e(re=>re.setShowTerminalQuickKeysOnDesktop),te=Qu(re=>re.queueModeEnabled),X=Qu(re=>re.setQueueMode),ee=_e(re=>re.persistChatDraft),fe=_e(re=>re.setPersistChatDraft),be=_e(re=>re.inputSpellcheckEnabled),Ne=_e(re=>re.setInputSpellcheckEnabled),se=_e(re=>re.showToolFileIcons),ie=_e(re=>re.setShowToolFileIcons),ae=_e(re=>re.showExpandedBashTools),xe=_e(re=>re.setShowExpandedBashTools),Z=_e(re=>re.showExpandedEditTools),me=_e(re=>re.setShowExpandedEditTools),Y=_e(re=>re.timeFormatPreference),Se=_e(re=>re.setTimeFormatPreference),we=_e(re=>re.weekStartPreference),ke=_e(re=>re.setWeekStartPreference),Fe=_e(re=>re.showSplitAssistantMessageActions),Ce=_e(re=>re.setShowSplitAssistantMessageActions),Q=_e(re=>re.showMobileSessionStatusBar),ce=_e(re=>re.setShowMobileSessionStatusBar),ve=jt(re=>re.settingsMessageStreamTransport),le=jt(re=>re.setSettingsMessageStreamTransport),Ae=_e(re=>re.isSettingsDialogOpen),{themeMode:Te,setThemeMode:$e,availableThemes:ye,customThemesLoading:q,reloadCustomThemes:L,lightThemeId:U,darkThemeId:oe,setLightThemePreference:Ee,setDarkThemePreference:Oe}=Sr(),[Ie,z]=o.useState(!1),[De,Qe]=o.useState(0),tt=_e(re=>re.reportUsage),et=_e(re=>re.setReportUsage),We=o.useCallback(re=>{et(re),Cs({reportUsage:re})},[et]),at=Ae&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!at)return;let re=null,bt=Date.now();const Et=()=>{const ts=Date.now();ts-bt>=420&&(Qe(ss=>(ss+1)%24),bt=ts),re=requestAnimationFrame(Et)};(typeof document>"u"||document.visibilityState==="visible")&&(re=requestAnimationFrame(Et));const Wt=()=>{document.visibilityState==="visible"&&re===null?re=requestAnimationFrame(Et):document.visibilityState!=="visible"&&re!==null&&(cancelAnimationFrame(re),re=null)};return document.addEventListener("visibilitychange",Wt),()=>{document.removeEventListener("visibilitychange",Wt),re!==null&&cancelAnimationFrame(re)}},[at]);const qe=o.useCallback(re=>{h(re),Cs({userMessageRenderingMode:re})},[h]),nt=o.useCallback(re=>{v(re),Cs({stickyUserHeader:re})},[v]),Ze=o.useCallback(re=>{k(re),Cs({wideChatLayoutEnabled:re})},[k]),ze=o.useCallback(re=>{Ce(re),Cs({showSplitAssistantMessageActions:re})},[Ce]),rt=o.useCallback(re=>{Ne(re),Cs({inputSpellcheckEnabled:re})},[Ne]),Ge=o.useCallback(re=>{N(re),Cs({chatRenderMode:re})},[N]),ct=o.useCallback(re=>{le(re),Cs({messageStreamTransport:re})},[le]),Pe=o.useCallback(re=>{E(re),Cs({activityRenderMode:re})},[E]),Me=o.useCallback(re=>{y(re),Cs({mermaidRenderingMode:re})},[y]),Ue=o.useCallback(re=>{ie(re),Cs({showToolFileIcons:re})},[ie]),He=o.useCallback(re=>{xe(re),Cs({showExpandedBashTools:re})},[xe]),lt=o.useCallback(re=>{me(re),Cs({showExpandedEditTools:re})},[me]),vt=o.useCallback(re=>{Se(re),Cs({timeFormatPreference:re})},[Se]),ft=o.useCallback(re=>{ke(re),Cs({weekStartPreference:re})},[ke]),dt=o.useMemo(()=>ye.filter(re=>re.metadata.variant==="light").sort((re,bt)=>re.metadata.name.localeCompare(bt.metadata.name)),[ye]),Dt=o.useMemo(()=>ye.filter(re=>re.metadata.variant==="dark").sort((re,bt)=>re.metadata.name.localeCompare(bt.metadata.name)),[ye]),Qt=o.useMemo(()=>dt.find(re=>re.metadata.id===U)??dt[0],[dt,U]),Ft=o.useMemo(()=>Dt.find(re=>re.metadata.id===oe)??Dt[0],[Dt,oe]),qt=o.useCallback((re,bt)=>{const Et=bt==="dark"?" Dark":" Light";return re.endsWith(Et)?re.slice(0,-Et.length):re},[]),gt=re=>t?t.includes(re):!0,zt=un(),es=gt("theme")&&!zt,is=gt("theme")||gt("timeFormat")||gt("weekStart"),cs=zt?is:gt("theme")||gt("pwaInstallName")||gt("pwaOrientation")||gt("timeFormat")||gt("weekStart"),hs=gt("fontSize")||gt("terminalFontSize")||gt("spacing")||gt("inputBarOffset"),_t=gt("terminalQuickKeys")&&!c,Ye=gt("mermaidRendering")||gt("userMessageRendering")||gt("chatRenderMode")||gt("messageTransport")||gt("activityRenderMode")&&w==="sorted"||gt("stickyUserHeader")||gt("wideChatLayout")||gt("splitAssistantMessageActions")||gt("diffLayout")||gt("mobileStatusBar")&&c||gt("dotfiles")||gt("reasoning")||gt("queueMode")||gt("persistDraft")||gt("showToolFileIcons")||gt("expandedTools")||!c&>("inputSpellcheck"),Mt=gt("pwaInstallName")&&aa()&&d&&!In()&&!zt,Bt=gt("pwaOrientation")&&aa()&&!In()&&!zt,wt=gt("mobileKeyboardMode")&&aa()&&!In()&&!zt&&Ty(),[Zt,us]=o.useState(""),[Es,ws]=o.useState("system"),Ds=o.useMemo(()=>{const re=cf.find(bt=>bt.id===Y);return l(re?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Y,l]),Xt=o.useMemo(()=>{const re=df.find(bt=>bt.id===we);return l(re?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[we,l]),en=o.useMemo(()=>{const re=af.find(bt=>bt.id===Es);return re?l(re.labelKey):void 0},[Es,l]),Ks=o.useMemo(()=>{const re=of.find(bt=>bt.id===R);return re?l(re.labelKey):void 0},[R,l]),Us=o.useCallback(async re=>{if(typeof window>"u")return;const bt=window,Wt=re.trim().replace(/\s+/g," ").slice(0,64);if(await Cs({pwaAppName:Wt}),typeof bt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const ts=bt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Wt);us(ts);return}us(Wt||Yi),bt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Xs=o.useCallback(async re=>{if(typeof window>"u")return;const bt=window,Et=Zc(re);if(await Cs({pwaOrientation:Et}),typeof bt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Wt=bt.__OPENCHAMBER_SET_PWA_ORIENTATION__(Et);ws(Wt);return}ws(Et),bt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!Mt&&!Bt&&!wt)return;let re=!1;return(async()=>{try{const Et=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!Et.ok){re||us(Yi);return}const Wt=await Et.json().catch(()=>({})),ss=(typeof Wt?.pwaAppName=="string"?Wt.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Ke=Zc(Wt?.pwaOrientation),Je=sm(Wt?.mobileKeyboardMode);re||(Mt&&us(ss||Yi),Bt&&ws(Ke),wt&&H(Je))}catch{re||(Mt&&us(Yi),Bt&&ws("system"),wt&&H("native"))}})(),()=>{re=!0}},[H,wt,Mt,Bt]),s.jsxs("div",{className:"space-y-8",children:[cs&&s.jsxs("div",{className:"mb-8 space-y-6",children:[es&&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:P4.map(re=>s.jsx(he,{variant:"chip",size:"xs","aria-pressed":Te===re.value,className:"!font-normal",onClick:()=>$e(re.value),children:l(re.labelKey)},re.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(ns,{value:Qt?.metadata.id??"",onValueChange:Ee,children:[s.jsx(rs,{"aria-label":i("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:s.jsx(ms,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:Qt?qt(Qt.metadata.name,"light"):void 0})}),s.jsx(as,{children:dt.map(re=>s.jsx(Rt,{value:re.metadata.id,children:qt(re.metadata.name,"light")},re.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(ns,{value:Ft?.metadata.id??"",onValueChange:Oe,children:[s.jsx(rs,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:s.jsx(ms,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:Ft?qt(Ft.metadata.name,"dark"):void 0})}),s.jsx(as,{children:Dt.map(re=>s.jsx(Rt,{value:re.metadata.id,children:qt(re.metadata.name,"dark")},re.metadata.id))})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("button",{type:"button",disabled:q||Ie,onClick:()=>{const re=Date.now();z(!0),L().finally(()=>{const bt=Date.now()-re;if(bt<500){window.setTimeout(()=>{z(!1)},500-bt);return}z(!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(Ie?"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(A,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(At,{sideOffset:8,children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),is&&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(ns,{value:e,onValueChange:re=>r(re),children:[s.jsx(rs,{"aria-label":i("settings.appearance.language.select"),className:"w-fit",children:s.jsx(ms,{children:a(e)})}),s.jsx(as,{children:n.map(re=>s.jsx(Rt,{value:re,children:a(re)},re))})]})]}),!zt&&(gt("timeFormat")||gt("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:[gt("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(ns,{value:Y,onValueChange:re=>vt(re),children:[s.jsx(rs,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:s.jsx(ms,{children:Ds})}),s.jsx(as,{children:cf.map(re=>s.jsx(Rt,{value:re.id,children:l(re.labelKey)},re.id))})]})]}),gt("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(ns,{value:we,onValueChange:re=>ft(re),children:[s.jsx(rs,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:s.jsx(ms,{children:Xt})}),s.jsx(as,{children:df.map(re=>s.jsx(Rt,{value:re.id,children:l(re.labelKey)},re.id))})]})]})]})]}),(Mt||Bt||wt)&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[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.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($t,{value:Zt,onChange:re=>{us(re.target.value)},onBlur:()=>{Us(Zt)},onKeyDown:re=>{re.key==="Enter"&&(re.preventDefault(),Us(Zt))},className:"h-7",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(he,{size:"sm",type:"button",variant:"ghost",onClick:()=>{us(Yi),Us("")},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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Bt&&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(ns,{value:Es,onValueChange:re=>{const bt=Zc(re);ws(bt),Xs(bt)},children:[s.jsx(rs,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),className:"w-full",children:s.jsx(ms,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:en})}),s.jsx(as,{children:af.map(re=>s.jsx(Rt,{value:re.id,children:l(re.labelKey)},re.id))})]}),s.jsx(he,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ws("system"),Xs("system")},disabled:Es==="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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),wt&&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(ns,{value:R,onValueChange:re=>{const bt=sm(re);H(bt),Cs({mobileKeyboardMode:bt})},children:[s.jsx(rs,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),className:"w-full",children:s.jsx(ms,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Ks})}),s.jsx(as,{children:of.map(re=>s.jsx(Rt,{value:re.id,children:l(re.labelKey)},re.id))})]}),s.jsx(he,{size:"sm",type:"button",variant:"ghost",onClick:()=>{H("native"),Cs({mobileKeyboardMode:"native"})},disabled:R==="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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]}),hs&&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:[gt("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(ns,{value:D,onValueChange:re=>F(re),children:[s.jsx(rs,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:s.jsx(ms,{children:Xu.find(re=>re.id===D)?.label})}),s.jsx(as,{children:Xu.map(re=>s.jsx(Rt,{value:re.id,children:s.jsx("span",{style:{fontFamily:re.stack},children:re.label})},re.id))})]}),s.jsx(he,{size:"sm",type:"button",variant:"ghost",onClick:()=>F(Zu),disabled:D===Zu,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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),gt("terminalFontSize")&&s.jsxs("div",{className:ge("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ge("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:ge("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsxs(ns,{value:_,onValueChange:re=>V(re),children:[s.jsx(rs,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:s.jsx(ms,{children:em.find(re=>re.id===_)?.label})}),s.jsx(as,{children:em.map(re=>s.jsx(Rt,{value:re.id,children:s.jsx("span",{style:{fontFamily:re.stack},children:re.label})},re.id))})]}),s.jsx(he,{size:"sm",type:"button",variant:"ghost",onClick:()=>V(tm),disabled:_===tm,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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),gt("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(Un,{value:P,onValueChange:T,min:50,max:200,step:5,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria"),className:"w-16"}),s.jsx(he,{size:"sm",type:"button",variant:"ghost",onClick:()=>T(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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),gt("terminalFontSize")&&s.jsxs("div",{className:ge("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ge("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:ge("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(Un,{value:S,onValueChange:M,min:9,max:52,step:1,className:"w-16"}),s.jsx(he,{size:"sm",type:"button",variant:"ghost",onClick:()=>M(13),disabled:S===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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),gt("spacing")&&s.jsxs("div",{className:ge("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ge("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:ge("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(Un,{value:$,onValueChange:O,min:50,max:200,step:5,className:"w-16"}),s.jsx(he,{size:"sm",type:"button",variant:"ghost",onClick:()=>O(100),disabled:$===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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),gt("inputBarOffset")&&s.jsxs("div",{className:ge("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ge("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(A,{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:ge("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(Un,{value:B,onValueChange:G,min:0,max:100,step:5,className:"w-16"}),s.jsx(he,{size:"sm",type:"button",variant:"ghost",onClick:()=>G(0),disabled:B===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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]})}),_t&&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")}),gt("terminalQuickKeys")&&!c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":pe,onClick:()=>W(!pe),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),W(!pe))},children:[s.jsx(fs,{checked:pe,onChange:W,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(A,{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")})]})]})]})]})}),Ye&&s.jsxs("div",{className:"space-y-3",children:[(gt("userMessageRendering")||gt("mermaidRendering")||gt("chatRenderMode")||gt("messageTransport")||gt("activityRenderMode")&&w==="sorted"||gt("diffLayout")&&!zt)&&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:[gt("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:M4.map(re=>{const bt=w===re.id,Et=De%12;return s.jsxs("button",{type:"button",onClick:()=>Ge(re.id),"aria-pressed":bt,className:ge("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",bt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:ge("typography-ui-label",bt?"text-foreground":"text-muted-foreground"),children:l(re.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:re.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Wt=>{const ts=Wt*3+1,ss=Et-ts+1,Ke=ss<=0?0:ss===1?42:ss===2?68:92,Je=Ke>0;return s.jsxs("div",{className:ge("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Je?"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}%`}})]},Wt)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Wt=>{const ts=Et>=(Wt+1)*3;return s.jsxs("div",{className:ge("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",ts?"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%"}})]},Wt)})})})]},re.id)})})]}),gt("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:lf.map(re=>s.jsx(he,{variant:"chip",size:"xs","aria-pressed":ve===re.id,className:"!font-normal",onClick:()=>ct(re.id),children:l(re.labelKey)},re.id))}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const re=lf.find(bt=>bt.id===ve);return re?.descriptionKey?l(re.descriptionKey):""})()})]})]}),gt("activityRenderMode")&&w==="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:R4.map(re=>{const bt=I===re.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>Pe(re.id),onKeyDown:Et=>{(Et.key===" "||Et.key==="Enter")&&(Et.preventDefault(),Pe(re.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Oa,{checked:bt,onChange:()=>Pe(re.id),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(re.labelKey)})}),s.jsx("span",{className:ge("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:l(re.labelKey)})]},re.id)})})]}),gt("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":ae,onClick:()=>He(!ae),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),He(!ae))},children:[s.jsx(fs,{checked:ae,onChange:He,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":Z,onClick:()=>lt(!Z),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),lt(!Z))},children:[s.jsx(fs,{checked:Z,onChange:lt,ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editTools")})]})]}),gt("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:E4.map(re=>{const bt=F4(x)===re.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>qe(re.id),onKeyDown:Et=>{(Et.key===" "||Et.key==="Enter")&&(Et.preventDefault(),qe(re.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Oa,{checked:bt,onChange:()=>qe(re.id),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(re.labelKey)})}),s.jsx("span",{className:ge("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:l(re.labelKey)})]},re.id)})})]}),gt("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:T4.map(re=>{const bt=g===re.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>Me(re.id),onKeyDown:Et=>{(Et.key===" "||Et.key==="Enter")&&(Et.preventDefault(),Me(re.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Oa,{checked:bt,onChange:()=>Me(re.id),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(re.labelKey)})}),s.jsx("span",{className:ge("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:l(re.labelKey)})]},re.id)})})]}),gt("diffLayout")&&!zt&&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:A4.map(re=>{const bt=J===re.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>ne(re.id),onKeyDown:Et=>{(Et.key===" "||Et.key==="Enter")&&(Et.preventDefault(),ne(re.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Oa,{checked:bt,onChange:()=>ne(re.id),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:l(re.labelKey)})}),s.jsx("span",{className:ge("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:l(re.labelKey)})]},re.id)})})]}),gt("diffLayout")&&!zt&&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:D4.map(re=>{const bt=ue===re.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>de(re.id),onKeyDown:Et=>{(Et.key===" "||Et.key==="Enter")&&(Et.preventDefault(),de(re.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Oa,{checked:bt,onChange:()=>de(re.id),ariaLabel:i("settings.openchamber.visual.field.diffViewModeAria",{option:l(re.labelKey)})}),s.jsx("span",{className:ge("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:l(re.labelKey)})]},re.id)})})]})]}),(gt("stickyUserHeader")||gt("wideChatLayout")||gt("splitAssistantMessageActions")||gt("mobileStatusBar")&&c||gt("dotfiles")||gt("queueMode")||gt("persistDraft")||gt("showToolFileIcons")||!c&>("inputSpellcheck")||gt("reasoning"))&&s.jsxs("section",{className:"p-2 space-y-0.5",children:[gt("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:re=>{(re.key===" "||re.key==="Enter")&&(re.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")})]}),gt("reasoning")&&m&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>b(!p),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),b(!p))},children:[s.jsx(fs,{checked:p,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")})]}),gt("stickyUserHeader")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":j,onClick:()=>nt(!j),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),nt(!j))},children:[s.jsx(fs,{checked:j,onChange:nt,ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.stickyUserHeader")})]}),gt("wideChatLayout")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":C,onClick:()=>Ze(!C),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),Ze(!C))},children:[s.jsx(fs,{checked:C,onChange:Ze,ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.wideChatLayout")})]}),gt("splitAssistantMessageActions")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Fe,onClick:()=>ze(!Fe),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),ze(!Fe))},children:[s.jsx(fs,{checked:Fe,onChange:ze,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(A,{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")})]})]})]}),gt("showToolFileIcons")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":se,onClick:()=>Ue(!se),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),Ue(!se))},children:[s.jsx(fs,{checked:se,onChange:Ue,ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showToolFileIcons")})]}),gt("mobileStatusBar")&&c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Q,onClick:()=>ce(!Q),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),ce(!Q))},children:[s.jsx(fs,{checked:Q,onChange:ce,ariaLabel:i("settings.openchamber.visual.field.showMobileStatusBarAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showMobileStatusBar")})]}),gt("dotfiles")&&!un()&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>ml(!f),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),ml(!f))},children:[s.jsx(fs,{checked:f,onChange:ml,ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showDotfiles")})]}),gt("queueMode")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":te,onClick:()=>X(!te),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),X(!te))},children:[s.jsx(fs,{checked:te,onChange:X,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(A,{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:ro()})})]})]})]}),gt("persistDraft")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ee,onClick:()=>fe(!ee),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),fe(!ee))},children:[s.jsx(fs,{checked:ee,onChange:fe,ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.persistDraftMessages")})]}),!c&>("inputSpellcheck")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":be,onClick:()=>rt(!be),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),rt(!be))},children:[s.jsx(fs,{checked:be,onChange:rt,ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs")})]})]})]}),gt("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:tt,onChange:We,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":tt,onClick:()=>We(!tt),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),We(!tt))},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 L4(){if(typeof window>"u")return"unknown";try{const{deviceType:t}=Fy();return t}catch{return"unknown"}}function O4(){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 $4(){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 _4(t){const e=_e.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",L4()),n.set("arch",O4()),n.set("platform",$4()),t==="desktop"?(n.set("appType",Ry()?"desktop-electron":"desktop-tauri"),n.set("instanceMode",ia()?"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 ed(t,e){try{const n=_4(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 B4(){return Ga()?ia()?"desktop":"web":un()?"vscode":aa()?"web":null}const uf={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},Ka=ar()((t,e)=>({...uf,checkForUpdates:async()=>{const n=B4();if(!n)return null;t({checking:!0,error:null,runtimeType:n});try{let r=null,a=null;if(n==="desktop"){let i=await yc();t({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null});const l=await ed("desktop",i?.currentVersion);if(a=l?.nextSuggestedCheckInSec??null,l?.available&&!i?.available){const c=await yc();c&&(i=c)}if(l){const c={...i??{available:!1,currentVersion:l.currentVersion??"unknown"},...l,currentVersion:i?.currentVersion??l.currentVersion??"unknown",available:l.available};t({available:c.available,info:c,nextCheckInSec:a})}else t({nextCheckInSec:a});return a}else n==="web"?(r=await ed("web"),a=r?.nextSuggestedCheckInSec??null):n==="vscode"&&(a=(await ed("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 yc();if(!a?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(t(l=>({info:l.info?{...l.info,...a,body:l.info.body||a.body,available:l.info.available}:a})),!await My(l=>{t({progress:l})}))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 Ey())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(uf)}})),mf="https://github.com/btriapitsyn/openchamber/releases";function V4(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 z4(t){return t.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function pf(t){return t.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function U4(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,l=Number.isFinite(r[a])?r[a]:0;if(i!==l)return l-i}return 0}function W4(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 l=n[i+1]?.start??t.length,c=t.slice(a.start,l).trim();return{version:a.version,date:a.date,start:a.start,end:l,raw:c}})}const ff=2e3,K4=600*1e3;async function H4(){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 G4(){try{return(await fetch("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function q4(t,e=Math.ceil(K4/ff),n=ff){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 G4())return!0}catch{}await new Promise(a=>setTimeout(a,n))}return!1}const _d=({open:t,onOpenChange:e,info:n,downloading:r,downloaded:a,progress:i,error:l,onDownload:c,onRestart:d,runtimeType:f="desktop"})=>{const{t:m}=pt(),[u,p]=Ve.useState(!1),[b,g]=Ve.useState("idle"),[y,x]=Ve.useState(null),h=n?.version?`${mf}/tag/v${n.version}`:mf,j=i?.total?Math.round(i.downloaded/i.total*100):0,v=f==="web",C=n?.updateCommand||"openchamber update";Ve.useEffect(()=>{t||(g("idle"),x(null))},[t]);const k=async()=>{(await Ln(C)).ok&&(p(!0),setTimeout(()=>p(!1),2e3))},w=Ve.useCallback(async P=>{await rr(P)},[]),N=Ve.useCallback(async()=>{g("updating"),x(null);const P=await H4();if(!P.success){g("error"),x(P.error||m("updateDialog.error.updateFailed"));return}P.autoRestart&&(g("restarting"),await new Promise(S=>setTimeout(S,2e3))),g("reconnecting"),await q4(n?.currentVersion)?window.location.reload():(g("error"),x(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),I=b!=="idle"&&b!=="error",E=Ve.useMemo(()=>{if(!n?.body)return null;const P=n.body.trim();if(!P)return null;const T=W4(P);if(T.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:pf(P)};const S=[...T].sort((M,D)=>U4(M.version,D.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:S.map(M=>({version:M.version,dateLabel:V4(M.date),content:pf(z4(M.raw)||P)}))}},[n?.body,m]);return s.jsx(ls,{open:t,onOpenChange:I?void 0:e,children:s.jsxs(os,{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(ds,{className:"flex items-center gap-2.5",children:[s.jsx(A,{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:[v&&I&&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(A,{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&&!I&&s.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:s.jsx(vs,{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 [&_a:hover]:!underline",onClickCapture:P=>{const S=P.target.closest("a");S&&S.href&&(P.preventDefault(),P.stopPropagation(),w(S.href))},children:s.jsx(Na,{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",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 [&_a:hover]:!underline",onClickCapture:T=>{const M=T.target.closest("a");M&&M.href&&(T.preventDefault(),T.stopPropagation(),w(M.href))},children:s.jsx(Na,{content:P.content,disableLinkSafety:!0})})]},P.version))})})}),v&&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(A,{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:C}),s.jsx("button",{onClick:k,className:ge("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(A,{name:"check",className:"h-4 w-4"}):s.jsx(A,{name:"clipboard",className:"h-4 w-4"})})]})]}),!v&&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:[j,"%"]})]}),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:`${j}%`}})})]}),(l||y)&&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:l||y})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[s.jsxs("a",{href:h,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(A,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),s.jsxs("div",{className:"flex-1 flex justify-end",children:[!v&&!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(A,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!v&&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(A,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.downloading")]}),!v&&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(A,{name:"restart",className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),v&&!I&&s.jsxs("button",{onClick:N,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(A,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),v&&I&&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(A,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},hf="https://github.com/btriapitsyn/openchamber",J4=800,Y4=()=>{const t=ot.c(103),{t:e}=pt(),[n,r]=o.useState(!1),[a,i]=o.useState(!1),l=Ka(Qn(Q4)),{isMobile:c}=an(),d=l.info?.currentVersion||"unknown",f=o.useRef(!1);let m,u;t[0]!==a||t[1]!==e||t[2]!==l.available||t[3]!==l.checking||t[4]!==l.error?(m=()=>{if(l.checking)i(!0),f.current=!0;else if(a){const $=setTimeout(()=>{i(!1),f.current&&!l.available&&!l.error&&(K.success(e("settings.openchamber.about.toast.latestVersion")),f.current=!1)},J4);return()=>clearTimeout($)}},u=[e,l.checking,a,l.available,l.error],t[0]=a,t[1]=e,t[2]=l.available,t[3]=l.checking,t[4]=l.error,t[5]=m,t[6]=u):(m=t[5],u=t[6]),o.useEffect(m,u);const p=l.checking||a;if(c){let $;t[7]!==d?($=s.jsxs("span",{className:"typography-meta text-muted-foreground",children:["v",d]}),t[7]=d,t[8]=$):$=t[8];let O;t[9]!==p||t[10]!==e||t[11]!==l?(O=!l.available&&!l.error&&s.jsx("button",{onClick:()=>l.checkForUpdates(),disabled:p,className:ge("typography-meta text-muted-foreground/60 hover:text-muted-foreground disabled:cursor-default",p&&"animate-pulse [animation-duration:1s]"),children:e("settings.openchamber.about.actions.checkUpdates")}),t[9]=p,t[10]=e,t[11]=l,t[12]=O):O=t[12];let B;t[13]!==p||t[14]!==e||t[15]!==l.available?(B=!p&&l.available&&s.jsxs("button",{onClick:()=>r(!0),className:"flex items-center gap-1 typography-meta text-[var(--primary-base)] hover:underline",children:[s.jsx(A,{name:"download",className:"h-3.5 w-3.5"}),e("settings.openchamber.about.actions.update")]}),t[13]=p,t[14]=e,t[15]=l.available,t[16]=B):B=t[16];let G;t[17]!==$||t[18]!==O||t[19]!==B?(G=s.jsxs("div",{className:"flex items-center justify-between",children:[$,O,B]}),t[17]=$,t[18]=O,t[19]=B,t[20]=G):G=t[20];let R;t[21]!==l.error?(R=l.error&&s.jsx("p",{className:"typography-micro text-[var(--status-error)] truncate",children:l.error}),t[21]=l.error,t[22]=R):R=t[22];let H;t[23]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsxs("a",{href:hf,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(A,{name:"github-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"GitHub"})]}),t[23]=H):H=t[23];let J;t[24]===Symbol.for("react.memo_cache_sentinel")?(J=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(A,{name:"discord-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"Discord"})]}),t[24]=J):J=t[24];let ne;t[25]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsxs("div",{className:"flex items-center gap-3",children:[H,J,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(A,{name:"twitter-xfill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[25]=ne):ne=t[25];let ue;t[26]!==n||t[27]!==l.downloadUpdate||t[28]!==l.downloaded||t[29]!==l.downloading||t[30]!==l.error||t[31]!==l.info||t[32]!==l.progress||t[33]!==l.restartToUpdate||t[34]!==l.runtimeType?(ue=s.jsx(_d,{open:n,onOpenChange:r,info:l.info,downloading:l.downloading,downloaded:l.downloaded,progress:l.progress,error:l.error,onDownload:l.downloadUpdate,onRestart:l.restartToUpdate,runtimeType:l.runtimeType}),t[26]=n,t[27]=l.downloadUpdate,t[28]=l.downloaded,t[29]=l.downloading,t[30]=l.error,t[31]=l.info,t[32]=l.progress,t[33]=l.restartToUpdate,t[34]=l.runtimeType,t[35]=ue):ue=t[35];let de;return t[36]!==ue||t[37]!==G||t[38]!==R?(de=s.jsxs("div",{className:"w-full space-y-2",children:[G,R,ne,ue]}),t[36]=ue,t[37]=G,t[38]=R,t[39]=de):de=t[39],de}let b;t[40]!==e?(b=e("settings.openchamber.about.title"),t[40]=e,t[41]=b):b=t[41];let g;t[42]!==b?(g=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]=g):g=t[43];let y;t[44]!==e?(y=e("settings.openchamber.about.field.version"),t[44]=e,t[45]=y):y=t[45];let x;t[46]!==y?(x=s.jsx("span",{className:"typography-ui-label text-foreground",children:y}),t[46]=y,t[47]=x):x=t[47];let h;t[48]!==d?(h=s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:d}),t[48]=d,t[49]=h):h=t[49];let j;t[50]!==x||t[51]!==h?(j=s.jsxs("div",{className:"flex min-w-0 flex-col",children:[x,h]}),t[50]=x,t[51]=h,t[52]=j):j=t[52];let v;t[53]!==e||t[54]!==l.checking?(v=l.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(A,{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]=l.checking,t[55]=v):v=t[55];let C;t[56]!==e||t[57]!==l.available||t[58]!==l.checking||t[59]!==l.info?.version?(C=!l.checking&&l.available&&s.jsxs(he,{size:"sm",variant:"default",onClick:()=>r(!0),children:[s.jsx(A,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:l.info?.version||""})]}),t[56]=e,t[57]=l.available,t[58]=l.checking,t[59]=l.info?.version,t[60]=C):C=t[60];let k;t[61]!==e||t[62]!==l.available||t[63]!==l.checking||t[64]!==l.error?(k=!l.checking&&!l.available&&!l.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),t[61]=e,t[62]=l.available,t[63]=l.checking,t[64]=l.error,t[65]=k):k=t[65];let w;t[66]!==l?(w=()=>l.checkForUpdates(),t[66]=l,t[67]=w):w=t[67];const N=l.checking;let I;t[68]!==e?(I=e("settings.openchamber.about.actions.checkForUpdates"),t[68]=e,t[69]=I):I=t[69];let E;t[70]!==w||t[71]!==I||t[72]!==l.checking?(E=s.jsx(he,{size:"sm",variant:"outline",onClick:w,disabled:N,children:I}),t[70]=w,t[71]=I,t[72]=l.checking,t[73]=E):E=t[73];let P;t[74]!==k||t[75]!==E||t[76]!==v||t[77]!==C?(P=s.jsxs("div",{className:"flex items-center gap-3",children:[v,C,k,E]}),t[74]=k,t[75]=E,t[76]=v,t[77]=C,t[78]=P):P=t[78];let T;t[79]!==P||t[80]!==j?(T=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:[j,P]}),t[79]=P,t[80]=j,t[81]=T):T=t[81];let S;t[82]!==l.error?(S=l.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:l.error})}),t[82]=l.error,t[83]=S):S=t[83];let M;t[84]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsxs("a",{href:hf,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(A,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),t[84]=M):M=t[84];let D;t[85]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[M,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(A,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[85]=D):D=t[85];let F;t[86]!==T||t[87]!==S?(F=s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[T,S,D]}),t[86]=T,t[87]=S,t[88]=F):F=t[88];let _;t[89]!==n||t[90]!==l.downloadUpdate||t[91]!==l.downloaded||t[92]!==l.downloading||t[93]!==l.error||t[94]!==l.info||t[95]!==l.progress||t[96]!==l.restartToUpdate||t[97]!==l.runtimeType?(_=s.jsx(_d,{open:n,onOpenChange:r,info:l.info,downloading:l.downloading,downloaded:l.downloaded,progress:l.progress,error:l.error,onDownload:l.downloadUpdate,onRestart:l.restartToUpdate,runtimeType:l.runtimeType}),t[89]=n,t[90]=l.downloadUpdate,t[91]=l.downloaded,t[92]=l.downloading,t[93]=l.error,t[94]=l.info,t[95]=l.progress,t[96]=l.restartToUpdate,t[97]=l.runtimeType,t[98]=_):_=t[98];let V;return t[99]!==F||t[100]!==_||t[101]!==g?(V=s.jsxs("div",{className:"mb-8",children:[g,F,_]}),t[99]=F,t[100]=_,t[101]=g,t[102]=V):V=t[102],V};function Q4(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 X4=1,Z4=365,gf=30,eI=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Xg=()=>{const t=ot.c(113),{t:e}=pt(),n=_e(tI),r=_e(sI),a=_e(nI),i=_e(rI),l=_e(aI),c=_e(iI);let d;t[0]===Symbol.for("react.memo_cache_sentinel")?(d={autoRun:!1},t[0]=d):d=t[0];const{candidates:f,isRunning:m,runCleanup:u,action:p}=Ly(d),b=f.length;let g;t[1]!==u||t[2]!==e?(g=async()=>{const Y=await u({force:!0});if(Y.completedIds.length===0&&Y.failedIds.length===0){K.message(Y.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}Y.completedIds.length>0&&K.success(Y.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:Y.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:Y.completedIds.length})),Y.failedIds.length>0&&K.error(Y.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:Y.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:Y.failedIds.length}))},t[1]=u,t[2]=e,t[3]=g):g=t[3];const y=g;let x;t[4]!==e?(x=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=x):x=t[5];let h;t[6]!==x?(h=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:x}),t[6]=x,t[7]=h):h=t[7];let j;t[8]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Pt,{asChild:!0,children:s.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[8]=j):j=t[8];let v;t[9]!==e?(v=e("settings.openchamber.sessionRetention.tooltip"),t[9]=e,t[10]=v):v=t[10];let C;t[11]!==v?(C=s.jsxs(It,{children:[j,s.jsx(At,{sideOffset:8,className:"max-w-xs",children:v})]}),t[11]=v,t[12]=C):C=t[12];let k;t[13]!==h||t[14]!==C?(k=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[h,C]})}),t[13]=h,t[14]=C,t[15]=k):k=t[15];let w,N;t[16]!==n||t[17]!==i?(w=()=>i(!n),N=Y=>{(Y.key===" "||Y.key==="Enter")&&(Y.preventDefault(),i(!n))},t[16]=n,t[17]=i,t[18]=w,t[19]=N):(w=t[18],N=t[19]);let I;t[20]!==e?(I=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[20]=e,t[21]=I):I=t[21];let E;t[22]!==n||t[23]!==i||t[24]!==I?(E=s.jsx(fs,{checked:n,onChange:i,ariaLabel:I}),t[22]=n,t[23]=i,t[24]=I,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 T;t[28]!==P?(T=s.jsx("span",{className:"typography-ui-label text-foreground",children:P}),t[28]=P,t[29]=T):T=t[29];let S;t[30]!==n||t[31]!==E||t[32]!==T||t[33]!==w||t[34]!==N?(S=s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":n,onClick:w,onKeyDown:N,children:[E,T]}),t[30]=n,t[31]=E,t[32]=T,t[33]=w,t[34]=N,t[35]=S):S=t[35];let M;t[36]!==e?(M=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[36]=e,t[37]=M):M=t[37];let D;t[38]!==M?(D=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:M})}),t[38]=M,t[39]=D):D=t[39];let F;t[40]!==e?(F=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[40]=e,t[41]=F):F=t[41];let _;t[42]!==r||t[43]!==l||t[44]!==F?(_=s.jsx(Un,{value:r,onValueChange:l,min:X4,max:Z4,step:1,"aria-label":F,className:"w-20 tabular-nums"}),t[42]=r,t[43]=l,t[44]=F,t[45]=_):_=t[45];let V;t[46]!==e?(V=e("settings.openchamber.sessionRetention.field.days"),t[46]=e,t[47]=V):V=t[47];let $;t[48]!==V?($=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:V}),t[48]=V,t[49]=$):$=t[49];let O;t[50]!==l?(O=()=>l(gf),t[50]=l,t[51]=O):O=t[51];const B=r===gf;let G;t[52]!==e?(G=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[52]=e,t[53]=G):G=t[53];let R;t[54]!==e?(R=e("settings.common.actions.reset"),t[54]=e,t[55]=R):R=t[55];let H;t[56]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(A,{name:"restart",className:"h-3.5 w-3.5"}),t[56]=H):H=t[56];let J;t[57]!==O||t[58]!==B||t[59]!==G||t[60]!==R?(J=s.jsx(he,{size:"sm",type:"button",variant:"ghost",onClick:O,disabled:B,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":G,title:R,children:H}),t[57]=O,t[58]=B,t[59]=G,t[60]=R,t[61]=J):J=t[61];let ne;t[62]!==_||t[63]!==$||t[64]!==J?(ne=s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[_,$,J]}),t[62]=_,t[63]=$,t[64]=J,t[65]=ne):ne=t[65];let ue;t[66]!==D||t[67]!==ne?(ue=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[D,ne]}),t[66]=D,t[67]=ne,t[68]=ue):ue=t[68];let de;t[69]!==e?(de=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[69]=e,t[70]=de):de=t[70];let pe;t[71]!==de?(pe=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:de})}),t[71]=de,t[72]=pe):pe=t[72];let W;t[73]!==a||t[74]!==c||t[75]!==e?(W=eI.map(Y=>s.jsx(he,{type:"button",variant:"chip",size:"xs","aria-pressed":a===Y.value,className:"!font-normal",onClick:()=>c(Y.value),children:e(Y.labelKey)},Y.value)),t[73]=a,t[74]=c,t[75]=e,t[76]=W):W=t[76];let te;t[77]!==W?(te=s.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:W}),t[77]=W,t[78]=te):te=t[78];let X;t[79]!==pe||t[80]!==te?(X=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[pe,te]}),t[79]=pe,t[80]=te,t[81]=X):X=t[81];let ee;t[82]!==S||t[83]!==ue||t[84]!==X?(ee=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[S,ue,X]}),t[82]=S,t[83]=ue,t[84]=X,t[85]=ee):ee=t[85];let fe;t[86]!==e?(fe=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[86]=e,t[87]=fe):fe=t[87];let be;t[88]!==fe?(be=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:fe})}),t[88]=fe,t[89]=be):be=t[89];let Ne;t[90]!==m||t[91]!==e?(Ne=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[90]=m,t[91]=e,t[92]=Ne):Ne=t[92];let se;t[93]!==y||t[94]!==m||t[95]!==Ne?(se=s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsx(he,{type:"button",variant:"outline",size:"xs",onClick:y,disabled:m,className:"!font-normal",children:Ne})}),t[93]=y,t[94]=m,t[95]=Ne,t[96]=se):se=t[96];let ie;t[97]!==be||t[98]!==se?(ie=s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[be,se]}),t[97]=be,t[98]=se,t[99]=ie):ie=t[99];let ae;t[100]!==p||t[101]!==b||t[102]!==e?(ae=p==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:b}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:b}),t[100]=p,t[101]=b,t[102]=e,t[103]=ae):ae=t[103];let xe;t[104]!==ae?(xe=s.jsx("p",{className:"typography-meta text-muted-foreground",children:ae}),t[104]=ae,t[105]=xe):xe=t[105];let Z;t[106]!==ie||t[107]!==xe?(Z=s.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[ie,xe]}),t[106]=ie,t[107]=xe,t[108]=Z):Z=t[108];let me;return t[109]!==ee||t[110]!==Z||t[111]!==k?(me=s.jsxs("div",{className:"mb-8",children:[k,ee,Z]}),t[109]=ee,t[110]=Z,t[111]=k,t[112]=me):me=t[112],me};function tI(t){return t.autoDeleteEnabled}function sI(t){return t.autoDeleteAfterDays}function nI(t){return t.sessionRetentionAction}function rI(t){return t.setAutoDeleteEnabled}function aI(t){return t.setAutoDeleteAfterDays}function iI(t){return t.setSessionRetentionAction}const xf=(t,e)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(t),Zg=()=>{const{t}=pt(),[e,n]=o.useState(!1),[r,a]=o.useState(!0),[i,l]=o.useState(!1),[c,d]=o.useState(null),[f,m]=o.useState(!1),[u,p]=o.useState([]),[b,g]=o.useState(Oy),[y,x]=o.useState(""),h=o.useMemo(()=>$y(),[]),j=o.useCallback(async()=>{a(!0),x("");try{const w=await _y();p(w)}catch(w){const N=w instanceof Error?w.message:t("settings.openchamber.passkeys.toast.loadFailed");x(N)}finally{a(!1)}},[t]);o.useEffect(()=>{let w=!1;return(async()=>{try{if(!h.supported){w||(n(!1),a(!1));return}w||n(!0)}catch{w||n(!1)}if(!w){const N=await vc();if(g(N),!N.enabled){p([]),a(!1);return}await j()}})(),()=>{w=!0,nm()}},[j,h.supported]);const v=o.useCallback(async()=>{if(!b.enabled){const w=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");x(w),K.message(w);return}if(!e){x(h.reason),K.message(h.reason);return}if(i){nm(),l(!1);return}x(""),l(!0);try{await By(),g(await vc()),await j(),K.success(t("settings.openchamber.passkeys.toast.added"))}catch(w){if(Vy(w)){K.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const N=w instanceof Error?w.message:t("settings.openchamber.passkeys.toast.addFailed");x(N),K.error(N)}finally{l(!1)}},[i,j,b.enabled,h.reason,e,t]),C=o.useCallback(async w=>{d(w),x("");try{await zy(w),g(await vc()),await j(),K.success(t("settings.openchamber.passkeys.toast.removed"))}catch(N){const I=N instanceof Error?N.message:t("settings.openchamber.passkeys.toast.removeFailed");x(I),K.error(I)}finally{d(null)}},[j,t]),k=o.useCallback(async()=>{m(!0),x("");try{await Uy(),window.location.reload()}catch(w){const N=w instanceof Error?w.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");x(N),K.error(N),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(he,{type:"button",variant:i?"secondary":"outline",size:"xs",onClick:()=>{v()},disabled:r||f,className:"!font-normal",children:t(i?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(he,{type:"button",variant:"ghost",size:"xs",onClick:()=>{k()},disabled:r||i||f,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(f?"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:h.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(w=>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:w.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:w.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:xf(w.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"))}):t("settings.openchamber.passkeys.item.added",{time:xf(w.createdAt,t("settings.openchamber.passkeys.time.neverUsed"))})}),s.jsx(he,{type:"button",variant:"ghost",size:"xs",onClick:()=>{C(w.id)},disabled:c===w.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===w.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]})]},w.id))})]}),y&&s.jsx("div",{className:"mt-1 px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:y})})]})},oI=t=>{const e=Di(t);return e||{providerId:"",modelId:""}},ex=()=>{const{t}=pt(),e=jt(D=>D.setProvider),n=jt(D=>D.setModel),r=jt(D=>D.setAgent),a=jt(D=>D.setCurrentVariant),i=jt(D=>D.setSettingsDefaultModel),l=jt(D=>D.setSettingsDefaultVariant),c=jt(D=>D.setSettingsDefaultAgent),d=jt(D=>D.setSettingsDefaultFileViewerPreview),f=jt(D=>D.settingsDefaultFileViewerPreview),m=_e(D=>D.showDeletionDialog),u=_e(D=>D.setShowDeletionDialog),p=jt(D=>D.providers),[b,g]=o.useState(),[y,x]=o.useState(),[h,j]=o.useState(),[v,C]=o.useState(!0),k=o.useMemo(()=>oI(b),[b]);o.useEffect(()=>{(async()=>{try{let F=null;if(!F){const _=dr()?.settings;if(_)try{const $=(await _.load())?.settings;$&&(F={defaultModel:typeof $.defaultModel=="string"?$.defaultModel:void 0,defaultVariant:typeof $.defaultVariant=="string"?$.defaultVariant:void 0,defaultAgent:typeof $.defaultAgent=="string"?$.defaultAgent:void 0})}catch{}}if(!F){const _=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});_.ok&&(F=await _.json())}if(F){const _=typeof F.defaultModel=="string"&&F.defaultModel.trim().length>0?F.defaultModel.trim():void 0,V=typeof F.defaultVariant=="string"&&F.defaultVariant.trim().length>0?F.defaultVariant.trim():void 0,$=typeof F.defaultAgent=="string"&&F.defaultAgent.trim().length>0?F.defaultAgent.trim():void 0;_!==void 0&&g(_),V!==void 0&&x(V),$!==void 0&&j($)}}catch(F){console.warn("Failed to load defaults settings:",F)}finally{C(!1)}})()},[]);const w=o.useCallback(async(D,F)=>{const _=D&&F?`${D}/${F}`:void 0;g(_),x(void 0),l(void 0),a(void 0),i(_),D&&F&&p.find($=>$.id===D)&&(e(D),n(F));try{await Cs({defaultModel:_??"",defaultVariant:""});const V=await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:_})});V.ok||console.warn("Failed to save default model to server:",V.status,V.statusText)}catch(V){console.warn("Failed to save default model:",V)}},[p,a,n,e,i,l]),N="__default__",I=o.useCallback(D=>D===N?t("settings.openchamber.defaults.option.default"):D.charAt(0).toUpperCase()+D.slice(1),[t]),E=o.useCallback(async D=>{const F=D===N?void 0:D||void 0;x(F),l(F),a(F);try{await Cs({defaultVariant:F??""})}catch(_){console.warn("Failed to save default variant:",_)}},[a,l]),P=o.useCallback(async D=>{const F=D||void 0;j(F),c(F),D&&r(D);try{await Cs({defaultAgent:F??""})}catch(_){console.warn("Failed to save default agent:",_)}},[r,c]),T=o.useCallback(()=>{const D=!f;d(D),Cs({defaultFileViewerPreview:D}).catch(console.warn)},[f,d]),S=o.useMemo(()=>{if(!k.providerId||!k.modelId)return[];const _=p.find(V=>V.id===k.providerId)?.models.find(V=>V.id===k.modelId)?.variants;return _?Object.keys(_):[]},[k.modelId,k.providerId,p]),M=S.length>0;return o.useEffect(()=>{!M&&y&&(x(void 0),l(void 0),a(void 0),Cs({defaultVariant:""}).catch(()=>{}))},[y,a,l,M]),v?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")," ",k.providerId?s.jsxs("span",{className:"text-foreground",children:[k.providerId,"/",k.modelId,M?` (${y??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),h&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:h})]})]}),s.jsxs("div",{className:ge("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(Eo,{providerId:k.providerId,modelId:k.modelId,onChange:w})})]}),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(ns,{value:y??N,onValueChange:E,disabled:!M,children:[s.jsx(rs,{className:"w-fit min-w-[120px]",children:s.jsx(ms,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:I(y??N)})}),s.jsxs(as,{children:[s.jsx(Rt,{value:N,children:t("settings.openchamber.defaults.option.default")}),S.map(D=>s.jsx(Rt,{value:D,children:I(D)},D))]})]})})]}),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(dc,{agentName:h||"",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:D=>{(D.key===" "||D.key==="Enter")&&(D.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":f,onClick:T,onKeyDown:D=>{(D.key===" "||D.key==="Enter")&&(D.preventDefault(),T())},children:[s.jsx(fs,{checked:f,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")})]})]})]})},bf={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"}},lI={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"},cI=()=>{const{t}=pt(),e=o.useMemo(()=>In(),[]),n=o.useMemo(()=>un(),[]),r=!e&&!n,a=_e(R=>R.nativeNotificationsEnabled),i=_e(R=>R.setNativeNotificationsEnabled),l=_e(R=>R.notificationMode),c=_e(R=>R.setNotificationMode),d=_e(R=>R.notifyOnSubtasks),f=_e(R=>R.setNotifyOnSubtasks),m=_e(R=>R.notifyOnCompletion),u=_e(R=>R.setNotifyOnCompletion),p=_e(R=>R.notifyOnError),b=_e(R=>R.setNotifyOnError),g=_e(R=>R.notifyOnQuestion),y=_e(R=>R.setNotifyOnQuestion),x=_e(R=>R.notificationTemplates),h=_e(R=>R.setNotificationTemplates),[j,v]=o.useState("default"),[C,k]=o.useState(!1),[w,N]=o.useState(!1),[I,E]=o.useState(!1);o.useEffect(()=>{if(!r){k(!1),N(!1);return}typeof Notification<"u"&&v(Notification.permission);const R=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;k(R),(async()=>{if(!R){N(!1);return}try{const J=await navigator.serviceWorker.getRegistration();if(!J){N(!1);return}const ne=await J.pushManager.getSubscription();N(!!ne)}catch{N(!1)}})()},[r]);const P=async R=>{if(e){i(R);return}if(!r){i(R);return}if(R&&typeof Notification<"u"&&Notification.permission==="default")try{const H=await Notification.requestPermission();v(H),H==="granted"?i(!0):K.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(H){console.error("Failed to request notification permission:",H),K.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else i(!!(R&&j==="granted"))},T=e||n||r&&typeof Notification<"u"&&Notification.permission==="granted",S=(R,H,J)=>{h({...x,[R]:{...x[R],[H]:J}})},M=R=>{const H="=".repeat((4-R.length%4)%4),J=(R+H).replace(/-/g,"+").replace(/_/g,"/"),ne=atob(J),ue=new Uint8Array(ne.length);for(let de=0;de<ne.length;de+=1)ue[de]=ne.charCodeAt(de);return ue},D=async(R,H,J)=>{let ne=null;const ue=new Promise((de,pe)=>{ne=setTimeout(()=>{pe(new Error(J))},H)});try{return await Promise.race([R,ue])}finally{ne&&clearTimeout(ne)}},F=async R=>{if(R.active)return;const H=R.installing||R.waiting;H&&H.state!=="activated"&&await D(new Promise(J=>{const ne=()=>{H.state==="activated"&&(H.removeEventListener("statechange",ne),J())};H.addEventListener("statechange",ne),ne()}),15e3,"Service worker activation timed out")},_=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const R=[{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 H=null;for(const J of R)try{const ne=J.opts?navigator.serviceWorker.register("/sw.js",J.opts):navigator.serviceWorker.register("/sw.js");return await D(ne,1e4,`Service worker registration timed out (${J.label})`)}catch(ne){H=ne}throw H instanceof Error?H:new Error("Service worker registration failed")},V=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const R=await navigator.serviceWorker.getRegistration();if(R)return R;const H=await _();try{await H.update()}catch{}return await F(H),H},$=R=>{const H=R,J=[`type=${typeof R}`,`toString=${String(R)}`,`name=${String(H?.name??"")}`,`message=${String(H?.message??"")}`];let ne="";try{ne=JSON.stringify(R)}catch{}return{summary:J.filter(Boolean).join(" | "),json:ne,stack:typeof H?.stack=="string"?H.stack:""}},O=async()=>{const R=dr();if(!R?.notifications){K.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await R.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?K.success(t("settings.notifications.page.toast.testNotificationSent")):K.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(H){console.error("Test notification failed:",H),K.error(t("settings.notifications.page.toast.testNotificationFailed"))}},B=async()=>{if(!C){K.error(t("settings.notifications.page.toast.pushUnsupported"));return}const R=dr();if(!R?.push){K.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}E(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const te=await Notification.requestPermission();if(v(te),te!=="granted"){K.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){K.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const H=await R.push.getVapidPublicKey();if(!H?.publicKey){K.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const J=await V();await F(J);const ne=await J.pushManager.getSubscription();if(!("pushManager"in J)||!J.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const de=(ne??await D(J.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:M(H.publicKey)}),15e3,"Push subscription timed out")).toJSON(),pe=de.keys;if(!de.endpoint||!pe?.p256dh||!pe.auth)throw new Error("Push subscription missing keys");if(!(await D(R.push.subscribe({endpoint:de.endpoint,keys:{p256dh:pe.p256dh,auth:pe.auth},origin:typeof window<"u"?window.location.origin:void 0}),15e3,"Push subscribe request timed out"))?.ok){K.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}N(!0),K.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(H){console.error("[Push] Enable failed:",H);const J=$(H);K.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:J.summary})}finally{E(!1)}},G=async()=>{if(!C){N(!1);return}const R=dr();if(!R?.push){K.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}E(!0);try{const J=await(await V()).pushManager.getSubscription();if(!J){N(!1);return}const ne=J.endpoint;await J.unsubscribe(),await R.push.unsubscribe({endpoint:ne}),N(!1),K.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{E(!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":a&&T,onClick:()=>{P(!(a&&T))},onKeyDown:R=>{(R.key===" "||R.key==="Enter")&&(R.preventDefault(),P(!(a&&T)))},children:[s.jsx(fs,{checked:a&&T,onChange:R=>{P(R)},ariaLabel:t("settings.notifications.page.delivery.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.enableLabel")})]}),a&&T&&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":l==="always",onClick:()=>c(l==="always"?"hidden-only":"always"),onKeyDown:R=>{(R.key===" "||R.key==="Enter")&&(R.preventDefault(),c(l==="always"?"hidden-only":"always"))},children:[s.jsx(fs,{checked:l==="always",onChange:R=>c(R?"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(he,{type:"button",variant:"outline",size:"sm",onClick:()=>{O()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),r&&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")}),j==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),j==="granted"&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]}),n&&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")})})]}),a&&T&&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":m,onClick:()=>u(!m),onKeyDown:R=>{(R.key===" "||R.key==="Enter")&&(R.preventDefault(),u(!m))},children:[s.jsx(fs,{checked:m,onChange:u,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":d,onClick:()=>f(!d),onKeyDown:R=>{(R.key===" "||R.key==="Enter")&&(R.preventDefault(),f(!d))},children:[s.jsx(fs,{checked:d,onChange:f,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":p,onClick:()=>b(!p),onKeyDown:R=>{(R.key===" "||R.key==="Enter")&&(R.preventDefault(),b(!p))},children:[s.jsx(fs,{checked:p,onChange:b,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":g,onClick:()=>y(!g),onKeyDown:R=>{(R.key===" "||R.key==="Enter")&&(R.preventDefault(),y(!g))},children:[s.jsx(fs,{checked:g,onChange:y,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(R=>s.jsxs("section",{className:"p-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground font-normal capitalize block",children:t(lI[R])}),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($t,{value:x[R].title,onChange:H=>S(R,"title",H.target.value),className:"h-7",placeholder:t(bf[R].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($t,{value:x[R].message,onChange:H=>S(R,"message",H.target.value),className:"h-7",placeholder:t(bf[R].messageKey)})]})]})]},R))})]})]}),r&&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:C?w:!1,disabled:!C||I,onChange:R=>{R?B():G()},ariaLabel:t("settings.notifications.page.push.enableAria")}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:ge("typography-ui-label",C?"text-foreground":"text-muted-foreground"),children:t("settings.notifications.page.push.enableLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t(C?"settings.notifications.page.push.supportedHint":"settings.notifications.page.push.unsupportedHint")})]}),I&&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")})})]})})]})]})},Zn=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},dI=[{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:"Українська"}],uI=t=>{const e=ot.c(45),{modelId:n}=t,{t:r}=pt();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=eo.getModelStatus(),e[0]=a):a=e[0];const[i,l]=Ve.useState(a),[c,d]=Ve.useState(!1);let f,m;e[1]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{const w=N=>l(N);return eo.onModelStatusChange=w,fI},m=[],e[1]=f,e[2]=m):(f=e[1],m=e[2]),Ve.useEffect(f,m);const u=eo.getCurrentModelId(),p=i.state==="downloading"||i.state==="loading";let b,g;e[3]!==i.state?(b=()=>{i.state!=="downloading"&&i.state!=="loading"&&d(!1)},g=[i.state],e[3]=i.state,e[4]=b,e[5]=g):(b=e[4],g=e[5]),Ve.useEffect(b,g);let y;e[6]!==n?(y=async()=>{d(!0);try{await eo.loadModel(n)}catch{}},e[6]=n,e[7]=y):y=e[7];const x=y;if(i.state==="ready"&&u===n){let w;e[8]!==r?(w=r("settings.voice.page.stt.wasmLoaded"),e[8]=r,e[9]=w):w=e[9];let N;return e[10]!==w?(N=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:w})}),e[10]=w,e[11]=N):N=e[11],N}if(p){let w;e[12]!==i.progress||e[13]!==i.state?(w=i.state==="downloading"?Math.round(i.progress):void 0,e[12]=i.progress,e[13]=i.state,e[14]=w):w=e[14];const N=w;let I;e[15]!==i.state||e[16]!==r?(I=i.state==="downloading"?r("settings.voice.page.stt.wasmDownloading"):r("settings.voice.page.stt.wasmLoading"),e[15]=i.state,e[16]=r,e[17]=I):I=e[17];const E=N!==void 0?` (${N}%)`:"";let P;return e[18]!==I||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:[I,E]})}),e[18]=I,e[19]=E,e[20]=P):P=e[20],P}if(i.state==="error"){let w;e[21]!==i.error?(w=s.jsx("span",{className:"typography-ui-compact text-destructive",children:i.error}),e[21]=i.error,e[22]=w):w=e[22];let N;e[23]!==r?(N=r("settings.voice.page.stt.wasmRetry"),e[23]=r,e[24]=N):N=e[24];let I;e[25]!==x||e[26]!==c||e[27]!==N?(I=s.jsx(he,{variant:"chip",size:"xs",disabled:c,onClick:x,children:N}),e[25]=x,e[26]=c,e[27]=N,e[28]=I):I=e[28];let E;return e[29]!==w||e[30]!==I?(E=s.jsxs("div",{className:"flex items-center gap-2",children:[w,I]}),e[29]=w,e[30]=I,e[31]=E):E=e[31],E}let h;e[32]!==r?(h=r("settings.voice.page.stt.wasmNotLoaded"),e[32]=r,e[33]=h):h=e[33];let j;e[34]!==h?(j=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:h}),e[34]=h,e[35]=j):j=e[35];let v;e[36]!==r?(v=r("settings.voice.page.stt.wasmDownload"),e[36]=r,e[37]=v):v=e[37];let C;e[38]!==x||e[39]!==c||e[40]!==v?(C=s.jsx(he,{variant:"chip",size:"xs",disabled:c,onClick:x,children:v}),e[38]=x,e[39]=c,e[40]=v,e[41]=C):C=e[41];let k;return e[42]!==C||e[43]!==j?(k=s.jsxs("div",{className:"flex items-center gap-2",children:[j,C]}),e[42]=C,e[43]=j,e[44]=k):k=e[44],k},mI=[{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"}],pI=()=>{const{t}=pt(),{isMobile:e}=an(),{isSupported:n,language:r,setLanguage:a}=Wy(),i=jt(z=>z.voiceProvider),l=jt(z=>z.setVoiceProvider),c=jt(z=>z.speechRate),d=jt(z=>z.setSpeechRate),f=jt(z=>z.speechPitch),m=jt(z=>z.setSpeechPitch),u=jt(z=>z.speechVolume),p=jt(z=>z.setSpeechVolume),b=jt(z=>z.sayVoice),g=jt(z=>z.setSayVoice),y=jt(z=>z.browserVoice),x=jt(z=>z.setBrowserVoice),h=jt(z=>z.openaiVoice),j=jt(z=>z.setOpenaiVoice),v=jt(z=>z.openaiApiKey),C=jt(z=>z.setOpenaiApiKey),k=jt(z=>z.openaiCompatibleUrl),w=jt(z=>z.setOpenaiCompatibleUrl),N=jt(z=>z.openaiCompatibleApiKey),I=jt(z=>z.setOpenaiCompatibleApiKey),E=jt(z=>z.openaiCompatibleVoice),P=jt(z=>z.setOpenaiCompatibleVoice),T=jt(z=>z.openaiCompatibleTtsModel),S=jt(z=>z.setOpenaiCompatibleTtsModel),M=jt(z=>z.showMessageTTSButtons),D=jt(z=>z.sttProvider),F=jt(z=>z.setSttProvider),_=jt(z=>z.sttServerUrl),V=jt(z=>z.setSttServerUrl),$=jt(z=>z.sttApiKey),O=jt(z=>z.setSttApiKey),B=jt(z=>z.sttModel),G=jt(z=>z.setSttModel),R=jt(z=>z.wasmSttModel),H=jt(z=>z.setWasmSttModel),J=jt(z=>z.sttLanguage),ne=jt(z=>z.setSttLanguage),ue=jt(z=>z.sttSilenceThresholdDb),de=jt(z=>z.setSttSilenceThresholdDb),pe=jt(z=>z.sttSilenceHoldMs),W=jt(z=>z.setSttSilenceHoldMs),te=jt(z=>z.sttTranscribeOnStop),X=jt(z=>z.setSttTranscribeOnStop),ee=jt(z=>z.setShowMessageTTSButtons),fe=jt(z=>z.voiceModeEnabled),be=jt(z=>z.setVoiceModeEnabled),[Ne,se]=Ve.useState(!1),[ie,ae]=Ve.useState([]),[xe,Z]=Ve.useState(!1),[me,Y]=Ve.useState(null),[Se,we]=Ve.useState(!1),[ke,Fe]=Ve.useState(!1),[Ce,Q]=Ve.useState(null),[ce,ve]=Ve.useState(!1),[le,Ae]=Ve.useState(null),[Te,$e]=Ve.useState([]),[ye,q]=Ve.useState(!1);Ve.useEffect(()=>((async()=>{const De=await wc.waitForVoices();$e(De)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{$e(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const L=Ve.useMemo(()=>Te.filter(z=>z.lang).sort((z,De)=>{const Qe=z.lang.startsWith("en"),tt=De.lang.startsWith("en");if(Qe&&!tt)return-1;if(!Qe&&tt)return 1;const et=z.lang.localeCompare(De.lang);return et!==0?et:z.name.localeCompare(De.name)}),[Te]),U=Ve.useCallback(()=>{if(ye){wc.cancelSpeech(),q(!1);return}const z=Te.find(et=>et.name===y),De=z?.name??t("settings.voice.page.preview.browserVoiceFallback"),Qe=t("settings.voice.page.preview.voiceLine",{voiceName:De});q(!0);const tt=new SpeechSynthesisUtterance(Qe);tt.rate=c,tt.pitch=f,tt.volume=u,z&&(tt.voice=z,tt.lang=z.lang),tt.onend=()=>q(!1),tt.onerror=()=>q(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(tt)},[y,Te,c,f,u,ye,t]);Ve.useEffect(()=>()=>{ye&&wc.cancelSpeech()},[ye]),Ve.useEffect(()=>{if(!fe||i!=="openai"&&i!=="openai-compatible"){we(v.trim().length>0);return}(async()=>{try{const tt=(await(await fetch("/api/tts/status")).json()).available,et=v.trim().length>0;we(tt||et)}catch{we(v.trim().length>0)}})()},[v,fe,i]),Ve.useEffect(()=>{if(!fe){se(!1),ae([]);return}fetch("/api/tts/say/status").then(z=>z.json()).then(z=>{if(se(z.available),z.voices){const De=z.voices.filter((Qe,tt,et)=>et.findIndex(We=>We.name===Qe.name)===tt).sort((Qe,tt)=>Qe.name.localeCompare(tt.name));ae(De)}}).catch(()=>{se(!1)})},[fe]);const oe=Ve.useCallback(async()=>{if(me){Zn(me),Y(null),Z(!1);return}Z(!0);let z=null;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 Qe=await De.blob(),tt=URL.createObjectURL(Qe);z=new Audio(tt),z.onended=()=>{Zn(z),Y(null),Z(!1)},z.onerror=()=>{Zn(z),Y(null),Z(!1)},Y(z),await z.play()}catch{Zn(z),Y(null),Z(!1)}},[b,c,me,t]);Ve.useEffect(()=>()=>{Zn(me)},[me]);const Ee=Ve.useCallback(async()=>{if(Ce){Zn(Ce),Q(null),Fe(!1);return}Fe(!0);let z=null;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:h}),voice:h,speed:c,apiKey:v||void 0})});if(!De.ok){const et=await De.json().catch(()=>({error:"Unknown error"}));throw new Error(et.error||`HTTP ${De.status}`)}const Qe=await De.blob(),tt=URL.createObjectURL(Qe);z=new Audio(tt),z.onended=()=>{Zn(z),Q(null),Fe(!1)},z.onerror=()=>{Zn(z),Q(null),Fe(!1)},Q(z),await z.play()}catch{Zn(z),Q(null),Fe(!1)}},[h,c,Ce,v,t]);Ve.useEffect(()=>()=>{Zn(Ce)},[Ce]);const Oe=Ve.useCallback(async()=>{if(le){Zn(le),Ae(null),ve(!1);return}if(!k.trim())return;ve(!0);let z=null;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:E,model:T||void 0,speed:c,baseURL:k,apiKey:N||void 0})});if(!De.ok){const et=await De.json().catch(()=>({error:"Unknown error"}));throw new Error(et.error||`HTTP ${De.status}`)}const Qe=await De.blob(),tt=URL.createObjectURL(Qe);z=new Audio(tt),z.onended=()=>{Zn(z),Ae(null),ve(!1)},z.onerror=()=>{Zn(z),Ae(null),ve(!1)},Ae(z),await z.play()}catch{Zn(z),Ae(null),ve(!1)}},[k,E,T,N,c,le,t]);Ve.useEffect(()=>()=>{Zn(le)},[le]);const Ie="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":fe,onClick:()=>be(!fe),onKeyDown:z=>{(z.key===" "||z.key==="Enter")&&(z.preventDefault(),be(!fe))},children:[s.jsx(fs,{checked:fe,onChange:be,ariaLabel:t("settings.voice.page.field.enableVoiceModeAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.enableVoiceMode")})]}),fe&&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(A,{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(he,{variant:"chip",size:"xs","aria-pressed":i==="browser",onClick:()=>l("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(he,{variant:"chip",size:"xs","aria-pressed":i==="openai",onClick:()=>l("openai"),className:"!font-normal",children:"OpenAI"}),s.jsx(he,{variant:"chip",size:"xs","aria-pressed":i==="openai-compatible",onClick:()=>l("openai-compatible"),className:"!font-normal",children:t("settings.voice.page.provider.custom")}),Ne&&s.jsxs(he,{variant:"chip",size:"xs","aria-pressed":i==="say",onClick:()=>l("say"),className:"!font-normal",children:[s.jsx(A,{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:ge("typography-ui-label text-foreground",!Se&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:ge("typography-meta ml-2",Se?"text-muted-foreground":"text-[var(--status-error)]/80"),children:t(Se&&!v?"settings.voice.page.field.apiKeyHintUsingConfig":Se?"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:v,onChange:z=>C(z.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"}),v&&s.jsx("button",{type:"button",onClick:()=>C(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(A,{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:ge("typography-ui-label text-foreground",!k.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:k,onChange:z=>w(z.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"}),k&&s.jsx("button",{type:"button",onClick:()=>w(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"API Key"}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:"Optional"}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"password",value:N,onChange:z=>I(z.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"}),N&&s.jsx("button",{type:"button",onClick:()=>I(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(A,{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:T,onChange:z=>S(z.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:E,onChange:z=>P(z.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(he,{size:"xs",variant:"ghost",onClick:Oe,title:t("settings.voice.page.actions.preview"),disabled:!k.trim(),children:ce?s.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(A,{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"&&Se&&s.jsxs(s.Fragment,{children:[s.jsxs(ns,{value:h,onValueChange:j,children:[s.jsx(rs,{className:"w-fit",children:s.jsx(ms,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(as,{children:mI.map(z=>s.jsx(Rt,{value:z.value,children:z.label},z.value))})]}),s.jsx(he,{size:"xs",variant:"ghost",onClick:Ee,title:t("settings.voice.page.actions.preview"),children:ke?s.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(A,{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"&&Ne&&ie.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(ns,{value:b,onValueChange:g,children:[s.jsx(rs,{className:"w-fit",children:s.jsx(ms,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(as,{children:ie.map(z=>s.jsx(Rt,{value:z.name,children:z.name},z.name))})]}),s.jsx(he,{size:"xs",variant:"ghost",onClick:oe,title:t("settings.voice.page.actions.preview"),children:xe?s.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(A,{name:"play",className:"w-3.5 h-3.5"})})]}),i==="browser"&&L.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(ns,{value:y||"$auto",onValueChange:z=>x(z==="$auto"?"":z),children:[s.jsx(rs,{className:"w-fit max-w-[200px]",children:s.jsx(ms,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(as,{children:[s.jsx(Rt,{value:"$auto",children:t("settings.voice.page.field.auto")}),L.map(z=>s.jsxs(Rt,{value:z.name,children:[z.name," (",z.lang,")"]},z.name))]})]}),s.jsx(he,{size:"xs",variant:"ghost",onClick:U,title:t("settings.voice.page.actions.preview"),children:ye?s.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(A,{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:z=>d(Number(z.target.value)),disabled:!n,className:Ie}),s.jsx(Un,{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:f,onChange:z=>m(Number(z.target.value)),disabled:!n,className:Ie}),s.jsx(Un,{value:f,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:z=>p(Number(z.target.value)),disabled:!n,className:Ie}),e?s.jsx(Un,{value:Math.round(u*100),onValueChange:z=>p(z/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(ns,{value:r,onValueChange:a,disabled:!n,children:[s.jsx(rs,{className:"w-fit",children:s.jsx(ms,{placeholder:t("settings.voice.page.field.selectLanguagePlaceholder")})}),s.jsx(as,{children:dI.map(z=>s.jsx(Rt,{value:z.value,children:z.label},z.value))})]})})]})]})]})]}),fe&&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(A,{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(he,{variant:"chip",size:"xs","aria-pressed":D==="browser",onClick:()=>F("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(he,{variant:"chip",size:"xs","aria-pressed":D==="server",onClick:()=>F("server"),className:"!font-normal",children:t("settings.voice.page.provider.server")}),s.jsx(he,{variant:"chip",size:"xs","aria-pressed":D==="wasm",onClick:()=>F("wasm"),className:"!font-normal",children:t("settings.voice.page.provider.wasm")})]})]})}),D==="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":te,onClick:()=>X(!te),onKeyDown:z=>{(z.key===" "||z.key==="Enter")&&(z.preventDefault(),X(!te))},children:[s.jsx(fs,{checked:te,onChange:X,ariaLabel:t("settings.voice.page.field.transcribeOnStopAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.transcribeOnStop")})]}),!Ky.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:ge("typography-ui-label text-foreground",!_.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:_,onChange:z=>V(z.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"}),_&&s.jsx("button",{type:"button",onClick:()=>V(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"API Key"}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:"Optional"}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"password",value:$,onChange:z=>O(z.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"}),$&&s.jsx("button",{type:"button",onClick:()=>O(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(A,{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:B,onChange:z=>G(z.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:J,onChange:z=>ne(z.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:ue,onChange:z=>de(Number(z.target.value)),className:Ie}),s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3.5rem] text-right",children:[ue," 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:pe,onChange:z=>W(Number(z.target.value)),className:Ie}),s.jsx(Un,{value:pe,onValueChange:W,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")})]})]})]}),D==="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(ns,{value:R,onValueChange:H,children:[s.jsx(rs,{className:"mt-0.5",children:s.jsx(ms,{placeholder:t("settings.voice.page.stt.wasmModel")})}),s.jsx(as,{children:rm.map(z=>s.jsx(Rt,{value:z.id,children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{children:z.name}),s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[z.size," · ",z.languages]})]})},z.id))})]}),s.jsx("p",{className:"typography-ui-compact text-muted-foreground mt-0.5",children:rm.find(z=>z.id===R)?.description})]}),s.jsx(uI,{modelId:R})]})]})]}),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.jsx("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":M,onClick:()=>ee(!M),onKeyDown:z=>{(z.key===" "||z.key==="Enter")&&(z.preventDefault(),ee(!M))},children:[s.jsx(fs,{checked:M,onChange:ee,ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.messageReadAloudButton")})]})}),fe&&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 fI(){eo.onModelStatusChange=null}const el=[{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}],tl=[{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}],hI="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",gI="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",td=[{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"}],xI=[".yml",".yaml",".json"],bI="settings.openchamber.tunnel.error.invalidConfigExtension",Qi=t=>{const e=t.trim().toLowerCase();return xI.some(n=>e.endsWith(n))},Bd=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,yf=t=>{const e=ot.c(11),{provider:n}=t;let r;e[0]!==n?(r=Bd(n),e[0]=n,e[1]=r):r=e[1];const a=r,c=n==="cloudflare"||n==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let d;e[2]!==c?(d=ge("size-4 shrink-0",c),e[2]=c,e[3]=d):d=e[3];let f;e[4]!==d?(f=s.jsx(A,{name:"cloud",className:d}),e[4]=d,e[5]=f):f=e[5];let m;e[6]!==a?(m=s.jsx("span",{children:a}),e[6]=a,e[7]=m):m=e[7];let u;return e[8]!==f||e[9]!==m?(u=s.jsxs("span",{className:"flex items-center gap-2",children:[f,m]}),e[8]=f,e[9]=m,e[10]=u):u=e[10],u},xa=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",Vd=(t,e,n)=>t.find(a=>a.ms===e)?.value||n,vf=(t,e,n)=>{const r=Vd(t,e,n);return t.find(a=>a.value===r)?.label||r},wf=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`},yI=t=>new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),Sl=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()}},vI=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,l=typeof i.id=="string"?i.id.trim():"",c=typeof i.name=="string"?i.name.trim():"",d=Sl(typeof i.hostname=="string"?i.hostname:"");!l||!c||!d||e.has(l)||n.has(d)||(e.add(l),n.add(d),r.push({id:l,name:c,hostname:d}))}return r},wI=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,jI=()=>{const{t}=pt(),e=o.useCallback(Pe=>t(Pe),[t]),[n,r]=o.useState("checking"),[a,i]=o.useState(null),[l,c]=o.useState(null),[d,f]=o.useState(null),[m,u]=o.useState(null),[p,b]=o.useState(null),[g,y]=o.useState(!1),[x,h]=o.useState(!1),[j,v]=o.useState(!1),[C,k]=o.useState("cloudflare"),[w,N]=o.useState([]),[I,E]=o.useState("quick"),[P,T]=o.useState(null),[S,M]=o.useState([]),[D,F]=o.useState({}),[_,V]=o.useState(""),[$,O]=o.useState({}),[B,G]=o.useState(new Set),[R,H]=o.useState(!1),[J,ne]=o.useState(""),[ue,de]=o.useState(""),[pe,W]=o.useState(""),[te,X]=o.useState(1800*1e3),[ee,fe]=o.useState(480*60*1e3),[be,Ne]=o.useState(""),[se,ie]=o.useState([]),[ae,xe]=o.useState(()=>Date.now()),[Z,me]=o.useState(null),Y=t(bI),Se=o.useRef(null),we=o.useMemo(()=>P?!Qi(P):!1,[P]),ke=o.useMemo(()=>S.find(Pe=>Pe.id===_)||S[0]||null,[S,_]),Fe=o.useMemo(()=>se.map(Pe=>{const Me=Pe.expiresAt<=ae,Ue=Pe.status==="active"&&!Me,He=Ue?wf(Pe.expiresAt-ae):Pe.inactiveReason==="expired"||Me?"expired":"inactive",lt=He==="expired"?t("settings.openchamber.tunnel.state.expired"):Pe.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),vt=xa(Pe.mode);return{...Pe,isActive:Ue,mode:vt,remainingTextForSession:He,inactiveLabel:lt}}),[ae,se,t]),Ce=o.useMemo(()=>a?.connectUrl?a.bootstrapExpiresAt===null?!0:a.bootstrapExpiresAt>ae:!1,[ae,a?.bootstrapExpiresAt,a?.connectUrl]),Q=o.useMemo(()=>!a||n!=="active"&&n!=="stopping"?!1:l===I,[l,n,a,I]),ce=o.useMemo(()=>!a||n!=="active"||!l?!1:l!==I,[l,n,a,I]),ve=o.useMemo(()=>{if(typeof Z=="number"&&Number.isFinite(Z)&&Z>0)return Z;if(typeof window>"u")return null;const Pe=Number(window.location.port);return Number.isFinite(Pe)&&Pe>0?Pe:null},[Z]),le=o.useMemo(()=>w.find(Pe=>Pe.provider===C)??null,[w,C]),Ae=o.useMemo(()=>{const Pe=new Set(le?.modes?.map(Me=>Me.key).filter(Me=>Me==="quick"||Me==="managed-remote"||Me==="managed-local"));return Pe.size===0?td:td.filter(Me=>Pe.has(Me.value))},[le]),Te=o.useMemo(()=>Ae.some(Pe=>Pe.value==="managed-remote"||Pe.value==="managed-local"),[Ae]),$e=C==="ngrok"?"brew install ngrok":"brew install cloudflared",ye=o.useCallback(async Pe=>{await rr(Pe)},[]),q=o.useCallback(async Pe=>{try{const[Me,Ue,He,lt]=await Promise.all([fetch("/api/openchamber/tunnel/check",{signal:Pe}),fetch("/api/openchamber/tunnel/status",{signal:Pe}),fetch("/api/config/settings",{signal:Pe,headers:{Accept:"application/json"}}),fetch("/api/openchamber/tunnel/providers",{signal:Pe})]),vt=await Me.json(),ft=await Ue.json(),dt=He.ok?await He.json():{},Dt=lt.ok?await lt.json():{},Qt=ft.ttlConfig?.bootstrapTtlMs??(dt?.tunnelBootstrapTtlMs===null?null:typeof dt?.tunnelBootstrapTtlMs=="number"?dt.tunnelBootstrapTtlMs:1800*1e3),Ft=typeof ft.ttlConfig?.sessionTtlMs=="number"?ft.ttlConfig.sessionTtlMs:typeof dt?.tunnelSessionTtlMs=="number"?dt.tunnelSessionTtlMs:480*60*1e3,qt=xa(ft.mode??dt?.tunnelMode),gt=typeof dt?.tunnelProvider=="string"&&dt.tunnelProvider.trim().length>0?dt.tunnelProvider.trim().toLowerCase():"cloudflare",zt=typeof dt?.managedLocalTunnelConfigPath=="string"&&dt.managedLocalTunnelConfigPath.trim()||null,es=vI(ft?.managedRemoteTunnelPresets),is=typeof ft.managedRemoteTunnelHostname=="string"?ft.managedRemoteTunnelHostname:"",cs=es.length>0?es:is?[{id:`legacy-${Sl(is)}`,name:is,hostname:Sl(is)}]:[],hs=cs[0]?.id||"";if(X(Qt),fe(Ft),k(gt),N(Array.isArray(Dt?.providers)?Dt.providers:[]),E(qt),T(zt),M(cs),V(hs),ie(Array.isArray(ft.activeSessions)?ft.activeSessions:[]),c(ft.activeTunnelMode?xa(ft.activeTunnelMode):ft.active&&ft.mode?xa(ft.mode):null),G(new Set(Array.isArray(ft.managedRemoteTunnelTokenPresetIds)?ft.managedRemoteTunnelTokenPresetIds:[])),me(typeof ft.localPort=="number"?ft.localPort:null),ft.active&&ft.url){i({url:ft.url,connectUrl:null,bootstrapExpiresAt:typeof ft.bootstrapExpiresAt=="number"?ft.bootstrapExpiresAt:null}),r("active");return}r(vt.available?"idle":"not-available")}catch{Pe.aborted||(r("error"),u(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[t]);o.useEffect(()=>{const Pe=new AbortController;return q(Pe.signal),()=>Pe.abort()},[q]),o.useEffect(()=>{if(!a?.connectUrl){f(null);return}let Pe=!1;return ab.toDataURL(a.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(Me=>{Pe||f(Me)}).catch(()=>{Pe||f(null)}),()=>{Pe=!0}},[a?.connectUrl]),o.useEffect(()=>{if(!a?.bootstrapExpiresAt){Ne(t("settings.openchamber.tunnel.state.noExpiry"));return}let Pe=null,Me=Date.now();const Ue=()=>{const vt=a.bootstrapExpiresAt?a.bootstrapExpiresAt-Date.now():0;vt<=0?Ne(t("settings.openchamber.tunnel.state.expired")):Ne(wf(vt))},He=()=>{const vt=Date.now();vt-Me>=1e3&&(Ue(),Me=vt),Pe=requestAnimationFrame(He)};Ue(),(typeof document>"u"||document.visibilityState==="visible")&&(Pe=requestAnimationFrame(He));const lt=()=>{document.visibilityState==="visible"&&Pe===null?Pe=requestAnimationFrame(He):document.visibilityState!=="visible"&&Pe!==null&&(cancelAnimationFrame(Pe),Pe=null)};return document.addEventListener("visibilitychange",lt),()=>{document.removeEventListener("visibilitychange",lt),Pe!==null&&cancelAnimationFrame(Pe)}},[t,a?.bootstrapExpiresAt]),o.useEffect(()=>{let Pe=null,Me=Date.now();const Ue=()=>{const lt=Date.now();lt-Me>=1e3&&(xe(lt),Me=lt),Pe=requestAnimationFrame(Ue)};(typeof document>"u"||document.visibilityState==="visible")&&(Pe=requestAnimationFrame(Ue));const He=()=>{document.visibilityState==="visible"&&Pe===null?Pe=requestAnimationFrame(Ue):document.visibilityState!=="visible"&&Pe!==null&&(cancelAnimationFrame(Pe),Pe=null)};return document.addEventListener("visibilitychange",He),()=>{document.removeEventListener("visibilitychange",He),Pe!==null&&cancelAnimationFrame(Pe)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let Pe=!1;const Me=async()=>{try{const He=await fetch("/api/openchamber/tunnel/status");if(!He.ok||Pe)return;const lt=await He.json();if(Pe)return;ie(Array.isArray(lt.activeSessions)?lt.activeSessions:[]),G(new Set(Array.isArray(lt.managedRemoteTunnelTokenPresetIds)?lt.managedRemoteTunnelTokenPresetIds:[])),me(typeof lt.localPort=="number"?lt.localPort:null)}catch{}},Ue=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Me()},5e3);return()=>{Pe=!0,window.clearInterval(Ue)}},[n]);const L=o.useCallback(async Pe=>{v(!0);try{await Cs(Pe),Object.prototype.hasOwnProperty.call(Pe,"tunnelMode")&&Pe.tunnelMode&&E(Pe.tunnelMode),Object.prototype.hasOwnProperty.call(Pe,"tunnelProvider")&&typeof Pe.tunnelProvider=="string"&&k(Pe.tunnelProvider),Object.prototype.hasOwnProperty.call(Pe,"managedLocalTunnelConfigPath")&&T(Pe.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(Pe,"managedRemoteTunnelPresets")&&Pe.managedRemoteTunnelPresets&&M(Pe.managedRemoteTunnelPresets)}catch{K.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{v(!1)}},[t]),U=o.useCallback(async(Pe,Me)=>{h(!0);try{await Cs({tunnelBootstrapTtlMs:Pe,tunnelSessionTtlMs:Me})}catch{K.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{h(!1)}},[t]),oe=o.useCallback(async Pe=>{const Me=Pe.token.trim();if(Me)try{const Ue={...$,[Pe.presetId]:Me};await Cs({managedRemoteTunnelPresetTokens:Ue}),G(He=>{const lt=new Set(He);return lt.add(Pe.presetId),lt})}catch{K.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[$,t]),Ee=o.useCallback(async Pe=>{b(null),u(null);const Me=w.find(He=>He.provider===Pe),Ue=Me?.modes?.some(He=>He.key===I)?I:xa(Me?.modes?.[0]?.key);await L({tunnelProvider:Pe,tunnelMode:Ue})},[w,L,I]),Oe=o.useCallback(async()=>{const Pe=await Ih({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(Pe.success&&typeof Pe.path=="string"&&Pe.path.trim().length>0){const Me=Pe.path.trim();if(!Qi(Me)){K.error(Y);return}T(Me),await L({managedLocalTunnelConfigPath:Me});return}Se.current?.click()},[Y,L]),Ie=o.useCallback(Pe=>{const Me=Pe.trim();T(Me.length>0?Me:null)},[]),z=o.useCallback(async()=>{if(P&&!Qi(P)){K.error(Y);return}await L({managedLocalTunnelConfigPath:P})},[Y,P,L]),De=o.useCallback(async()=>{T(null),await L({managedLocalTunnelConfigPath:null})},[L]),Qe=o.useCallback(async Pe=>{const Me=Pe.target.files?.[0];if(!Me)return;const Ue=Me.name.trim();if(Ue.length!==0){if(!Qi(Ue)){K.error(Y);return}T(Ue),await L({managedLocalTunnelConfigPath:Ue}),Pe.target.value=""}},[Y,L]),tt=o.useCallback(async()=>{if(u(null),b(null),I==="managed-local"&&P&&!Qi(P)){u(Y),K.error(Y);return}r("starting");try{let Pe="",Me="";if(I==="managed-remote"){if(!ke){r("idle"),b(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),K.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}Pe=ke.hostname,Me=($[ke.id]||"").trim(),await L({tunnelMode:"managed-remote",managedRemoteTunnelPresets:S})}const Ue=await fetch("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:C,mode:I,...I==="managed-remote"&&ke?{managedRemoteTunnelPresetId:ke.id,managedRemoteTunnelPresetName:ke.name}:{},...I==="managed-remote"&&Pe?{managedRemoteTunnelHostname:Pe}:{},...I==="managed-remote"&&Me?{managedRemoteTunnelToken:Me}:{},...I==="managed-local"&&P?{configPath:P}:{}})}),He=await Ue.json();if(!Ue.ok||!He.ok){if(I==="managed-remote"&&typeof He.error=="string"&&He.error.includes("Managed remote tunnel token is required")){r("idle"),b(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),K.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),u(He.error||t("settings.openchamber.tunnel.toast.startFailed")),K.error(He.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const lt=typeof He.url=="string"?He.url:"";if(!lt){r("error"),u(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),K.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(i({url:lt,connectUrl:typeof He.connectUrl=="string"?He.connectUrl:null,bootstrapExpiresAt:typeof He.bootstrapExpiresAt=="number"?He.bootstrapExpiresAt:null}),c(He.activeTunnelMode?xa(He.activeTunnelMode):He.mode?xa(He.mode):I),ie(Array.isArray(He.activeSessions)?He.activeSessions:[]),Array.isArray(He.managedRemoteTunnelTokenPresetIds)&&G(new Set(He.managedRemoteTunnelTokenPresetIds)),typeof He.localPort=="number"&&me(He.localPort),typeof He.mode=="string"&&E(xa(He.mode)),r("active"),He.replacedTunnel){const vt=typeof He.revokedBootstrapCount=="number"?He.revokedBootstrapCount:0,ft=typeof He.invalidatedSessionCount=="number"?He.invalidatedSessionCount:0;vt===1&&ft===1?K.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):vt===1?K.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:ft})):ft===1?K.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:vt})):K.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:vt,invalidatedSessionCount:ft}))}else K.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.startFailed")),K.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[Y,S,L,ke,$,t,C,I,P]),et=o.useCallback(async()=>{r("stopping");try{await fetch("/api/openchamber/tunnel/stop",{method:"POST"});const Pe=await fetch("/api/openchamber/tunnel/status");if(Pe.ok){const Me=await Pe.json();ie(Array.isArray(Me.activeSessions)?Me.activeSessions:[]),G(new Set(Array.isArray(Me.managedRemoteTunnelTokenPresetIds)?Me.managedRemoteTunnelTokenPresetIds:[])),me(typeof Me.localPort=="number"?Me.localPort:null)}i(null),c(null),f(null),r("idle"),K.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.stopFailed")),K.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),We=o.useCallback(async()=>{if(a?.connectUrl)try{await navigator.clipboard.writeText(a.connectUrl),y(!0),K.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>y(!1),2e3)}catch{K.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,a?.connectUrl]),at=o.useCallback(async Pe=>{const Me=el.find(Ue=>Ue.value===Pe);Me&&(X(Me.ms),await U(Me.ms,ee))},[U,ee]),qe=o.useCallback(async Pe=>{const Me=tl.find(Ue=>Ue.value===Pe);!Me||Me.ms===null||(fe(Me.ms),await U(te,Me.ms))},[te,U]),nt=o.useCallback(async Pe=>{b(null),u(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await L({tunnelMode:Pe,managedRemoteTunnelPresets:S})},[S,L,n]),Ze=o.useCallback(async(Pe,Me)=>{try{await Cs({managedRemoteTunnelPresets:Me})}catch{K.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),ze=o.useCallback(Pe=>{const Me=S.find(Ue=>Ue.id===Pe);Me&&(V(Me.id),b(null),Ze(Me,S))},[S,Ze]),rt=o.useCallback(async()=>{const Pe=J.trim(),Me=Sl(ue),Ue=pe.trim();if(!Pe){K.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!Me){K.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Ue){K.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(S.some(vt=>vt.hostname===Me)){K.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const He={id:wI(),name:Pe,hostname:Me},lt=[...S,He];M(lt),V(He.id),F(vt=>({...vt,[He.id]:!0})),O(vt=>({...vt,[He.id]:Ue})),b(null),H(!1),ne(""),de(""),W(""),await L({tunnelMode:"managed-remote",managedRemoteTunnelPresets:lt,managedRemoteTunnelPresetTokens:{...$,[He.id]:Ue}}),await oe({presetId:He.id,presetName:He.name,hostname:He.hostname,token:Ue}),K.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[S,ue,J,pe,oe,L,$,t]),Ge=o.useCallback(async Pe=>{const Me=S.find(ft=>ft.id===Pe);if(!Me)return;const Ue=S.filter(ft=>ft.id!==Me.id),He=Ue[0]?.id||"",lt=_===Me.id?He:_,vt=Object.fromEntries(Object.entries($).filter(([ft,dt])=>ft!==Me.id&&dt.trim().length>0));M(Ue),V(lt),F(ft=>{const dt={...ft};return delete dt[Me.id],dt}),O(ft=>{const dt={...ft};return delete dt[Me.id],dt}),G(ft=>{const dt=new Set(ft);return dt.delete(Me.id),dt}),b(null),await L({managedRemoteTunnelPresets:Ue,managedRemoteTunnelPresetTokens:vt}),K.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[S,L,_,$,t]),ct="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")})]}),Fe.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(A,{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:Fe.map(Pe=>{const Me=Pe.mode==="quick",Ue=Pe.mode==="managed-remote",He=Me?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Ue?"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=Pe.isActive?Me?"text-[var(--status-warning)]":Ue?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",vt=t(Me?"settings.openchamber.tunnel.badge.quick":Ue?"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(A,{name:"checkbox-blank-circle-fill",className:ge("size-2.5 shrink-0",lt)}),s.jsx("span",{className:ge("typography-micro rounded border px-1.5 py-0.5 uppercase",He),children:vt}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:yI(Pe.createdAt)})}),s.jsx("span",{className:"typography-meta text-foreground",children:Pe.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:Pe.remainingTextForSession}):Pe.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:Pe.inactiveLabel})})]},Pe.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(A,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsxs("p",{className:"typography-meta font-medium text-foreground",children:[Bd(C)," tunnel dependency was not found."]}),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:$e})]})]})}),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(ns,{value:C,onValueChange:Pe=>{Ee(Pe)},disabled:j||n==="starting"||n==="stopping",children:[s.jsx(rs,{className:"max-w-[16rem]",children:s.jsx(ms,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:Bd(C)})}),s.jsxs(as,{children:[w.length>0?w.map(Pe=>s.jsx(Rt,{value:Pe.provider,children:s.jsx(yf,{provider:Pe.provider})},Pe.provider)):s.jsx(Rt,{value:"cloudflare",children:s.jsx(yf,{provider:"cloudflare"})}),s.jsx(Rt,{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:Ae.map(Pe=>s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(he,{variant:"chip",size:"xs","aria-pressed":I===Pe.value,className:"!font-normal",onClick:()=>{nt(Pe.value)},disabled:j||n==="starting"||n==="stopping",children:e(Pe.labelKey)})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:e(Pe.tooltipKey)})]},Pe.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(ns,{value:Vd(el,te,"1800000"),onValueChange:Pe=>{at(Pe)},disabled:x||j||n==="starting"||n==="stopping",children:[s.jsx(rs,{className:"max-w-[11rem] min-w-0",children:s.jsx(ms,{className:"truncate",children:vf(el,te,"1800000")})}),s.jsx(as,{children:el.map(Pe=>s.jsx(Rt,{value:Pe.value,children:Pe.label},Pe.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(ns,{value:Vd(tl,ee,"28800000"),onValueChange:Pe=>{qe(Pe)},disabled:x||j||n==="starting"||n==="stopping",children:[s.jsx(rs,{className:"max-w-[11rem] min-w-0",children:s.jsx(ms,{className:"truncate",children:vf(tl,ee,"28800000")})}),s.jsx(as,{children:tl.map(Pe=>s.jsx(Rt,{value:Pe.value,children:Pe.label},Pe.value))})]})]})]}),I==="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(A,{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")}),Te&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),I==="managed-remote"&&s.jsxs("div",{className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof ve=="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:",ve]})]})}),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(he,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>H(Pe=>!Pe),disabled:n==="starting"||n==="stopping"||j,children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),S.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:S.map((Pe,Me)=>{const Ue=$[Pe.id]||"",He=B.has(Pe.id),lt=D[Pe.id]??!1;return s.jsx("div",{className:ge(Me<S.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(jr,{open:lt,onOpenChange:vt=>{F(ft=>({...ft,[Pe.id]:vt})),vt&&ze(Pe.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Lr,{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"||j,children:[lt?s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(A,{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:Pe.name})]}),s.jsx(he,{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:Pe.name}),onClick:()=>{Ge(Pe.id)},disabled:n==="starting"||n==="stopping"||j,children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(Nr,{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:Pe.hostname})]}),s.jsx($t,{type:"password",value:Ue,onChange:vt=>{const ft=vt.target.value;b(null),O(dt=>({...dt,[Pe.id]:ft}))},onBlur:vt=>{const ft=vt.currentTarget.value.trim();ft&&oe({presetId:Pe.id,presetName:Pe.name,hostname:Pe.hostname,token:ft})},placeholder:t(He?"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(he,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Ue.trim().length===0,onClick:()=>{oe({presetId:Pe.id,presetName:Pe.name,hostname:Pe.hostname,token:Ue})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},Pe.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),R&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx($t,{value:J,onChange:Pe=>ne(Pe.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:j||n==="starting"||n==="stopping"}),s.jsx($t,{value:ue,onChange:Pe=>de(Pe.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:j||n==="starting"||n==="stopping"}),s.jsx($t,{type:"password",value:pe,onChange:Pe=>W(Pe.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:j||n==="starting"||n==="stopping"}),typeof ve=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",ve]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(he,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{rt()},disabled:j||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(he,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{H(!1),ne(""),de(""),W("")},disabled:j||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(A,{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")})]})]}),!ke&&p&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:p})]}),I==="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:Se,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:Pe=>{Qe(Pe)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx($t,{value:P||"",onChange:Pe=>{Ie(Pe.target.value)},onBlur:()=>{z()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||j}),s.jsx(he,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{Oe()},disabled:n==="starting"||n==="stopping"||j,children:s.jsx(A,{name:"folder",className:"size-3.5"})}),P&&s.jsx(he,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{De()},disabled:n==="starting"||n==="stopping"||j,children:s.jsx(A,{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")}),we&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Y})]})}),!Q&&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(A,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[I==="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:()=>{ye(hI)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(A,{name:"external-link",className:"size-3.5"})]})]}),I==="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:()=>{ye(gI)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(A,{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(td.find(Pe=>Pe.value===I)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),I==="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(ns,{value:_||(S[0]?.id??""),onValueChange:Pe=>{ze(Pe)},disabled:j||n==="starting"||n==="stopping"||S.length<=1,children:[s.jsx(rs,{children:s.jsx(ms,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:ke?.name})}),s.jsx(as,{fitContent:!0,children:S.map(Pe=>s.jsx(Rt,{value:Pe.id,children:Pe.name},Pe.id))})]})]}),ce&&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(A,{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(he,{size:"sm",variant:"outline",onClick:tt,disabled:n==="starting"||j||I==="managed-remote"&&!ke||I==="managed-local"&&we,className:ge(ct,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),Q&&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})]}),Ce&&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(he,{size:"sm",variant:"ghost",onClick:We,className:"shrink-0 gap-1.5",children:[g?s.jsx(A,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(A,{name:"file-copy",className:"size-3.5"}),t(g?"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?be: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(he,{size:"sm",variant:"outline",onClick:tt,disabled:n==="stopping"||j||I==="managed-local"&&we,className:ct,children:[s.jsx(A,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(he,{size:"sm",variant:"ghost",onClick:et,disabled:n==="stopping"||j,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(A,{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(he,{size:"sm",variant:"ghost",onClick:tt,children:t("settings.openchamber.tunnel.actions.retry")})]})]})},tx=()=>{const{t}=pt(),[e,n]=Ve.useState(""),[r,a]=Ve.useState(!0),[i,l]=Ve.useState(!1),c=_e(u=>u.showOpenCodeUpdateNotifications),d=_e(u=>u.setShowOpenCodeUpdateNotifications);Ve.useEffect(()=>{let u=!1;return(async()=>{try{const p=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!p.ok)return;const b=await p.json().catch(()=>null);if(u||!b)return;const g=typeof b.opencodeBinary=="string"?b.opencodeBinary.trim():"";n(g)}catch{}finally{u||a(!1)}})(),()=>{u=!0}},[]);const f=Ve.useCallback(async()=>{if(typeof window>"u"||!In()||!Ga())return;const u=window.__TAURI__;if(u?.dialog?.open)try{const p=await u.dialog.open({title:t("settings.openchamber.opencodeCli.dialog.selectBinaryTitle"),multiple:!1,directory:!1});typeof p=="string"&&p.trim().length>0&&n(p.trim())}catch{}},[t]),m=Ve.useCallback(async()=>{l(!0);try{await Cs({opencodeBinary:e.trim()}),await vi({message:t("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}finally{l(!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(A,{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($t,{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(he,{type:"button",variant:"outline",size:"xs",onClick:f,disabled:r||i||!In()||!Ga(),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(A,{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(he,{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")})})]})]})},sx=()=>{const{t}=pt(),e=In()&&ia(),[n,r]=Ve.useState(!1),[a,i]=Ve.useState(!1),[l,c]=Ve.useState(""),[d,f]=Ve.useState(""),[m,u]=Ve.useState(!0),[p,b]=Ve.useState(!1),[g,y]=Ve.useState(!1),[x,h]=Ve.useState(!1),[j,v]=Ve.useState(!1),[C,k]=Ve.useState(null),[w,N]=Ve.useState(null);Ve.useEffect(()=>{if(!e){u(!1);return}let D=!1;return(async()=>{try{const F=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!F.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const _=await F.json().catch(()=>null);if(D)return;const V=_?.desktopLanAccessEnabled===!0,$=typeof _?.desktopUiPassword=="string"?_.desktopUiPassword:"";r(V),i(V),c($),f($),k(null)}catch(F){D||k(F instanceof Error?F.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{D||u(!1)}})(),()=>{D=!0}},[e,t]),Ve.useEffect(()=>{if(!e){y(!1);return}let D=!1;return(async()=>{const F=await Hy();D||(y(F?.supported===!0),h(F?.enabled===!0))})(),()=>{D=!0}},[e]),Ve.useEffect(()=>{if(!e||!a){N(null);return}let D=!1;return(async()=>{const F=await Gy();D||N(F)})(),()=>{D=!0}},[a,e]);const I=a!==n||d!==l,E=Ve.useMemo(()=>{if(typeof window>"u")return null;const D=Number(window.location.port);return Number.isFinite(D)&&D>0?D:null},[]),P=a&&w&&E?`http://${w}:${E}`:null,T=Ve.useCallback(()=>{i(D=>!D)},[]),S=Ve.useCallback(async()=>{if(!g||j)return;const D=!x;h(D),v(!0),k(null);try{const F=await qy(D);if(!F?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));h(F.enabled)}catch(F){h(!D),k(F instanceof Error?F.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{v(!1)}},[j,x,g,t]),M=Ve.useCallback(async()=>{if(I){b(!0),k(null);try{if(!(await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:a,desktopUiPassword:d})})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(r(a),c(d),!await Rh())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(D){k(D instanceof Error?D.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),b(!1)}}},[d,a,I,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:[g?s.jsxs("div",{className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:S,onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),S())},children:[s.jsx(fs,{checked:x,onChange:S,ariaLabel:t("settings.openchamber.desktopNetwork.field.launchAtLoginAria"),disabled:j}),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.launchAtLogin")}),s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t("settings.openchamber.desktopNetwork.field.launchAtLoginDescription")})]})]}):null,s.jsxs("div",{className:"space-y-1 py-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",htmlFor:"desktop-ui-password",children:t("settings.openchamber.desktopPassword.field.password")}),s.jsx($t,{id:"desktop-ui-password",type:"password",className:"h-7 max-w-sm",value:d,onChange:D=>f(D.target.value),placeholder:t("settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:m||p}),s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t("settings.openchamber.desktopPassword.field.passwordDescription")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:T,onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),T())},children:[s.jsx(fs,{checked:a,onChange:T,ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria"),disabled:m||p}),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")})]})]}),C?s.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:C}):null,P?s.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[t(I&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:P})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(he,{type:"button",size:"xs",onClick:M,disabled:m||p||!I,className:"shrink-0 !font-normal",children:t(p?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})]}):null},NI=new Set(["shift","control","alt","meta"]),SI=t=>{if(NI.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=Yy(t.key);return n?(e.push(n),pi(e.join("+"))):null},kI=()=>{const t=ot.c(58),{t:e}=pt();let n;t[0]!==e?(n=pe=>e(pe),t[0]=e,t[1]=n):n=t[1];const r=n,a=_e(CI),i=_e(II),l=_e(PI),c=_e(AI);let d;t[2]===Symbol.for("react.memo_cache_sentinel")?(d=Jy(),t[2]=d):d=t[2];const f=d;let m;t[3]!==r?(m=(pe,W)=>{const te=`settings.openchamber.keyboardShortcuts.action.${pe}.label`,X=r(te);return X===te?W:X},t[3]=r,t[4]=m):m=t[4];const u=m,[p,b]=o.useState(null);let g;t[5]===Symbol.for("react.memo_cache_sentinel")?(g={},t[5]=g):g=t[5];const[y,x]=o.useState(g),[h,j]=o.useState(""),[v,C]=o.useState(""),[k,w]=o.useState(null);let N;t[6]!==a?(N=(pe,W)=>{const te=pi(W);for(const X of f){if(X.id===pe)continue;const ee=sa(X.id,a);if(pi(ee)===te)return X.id}return null},t[6]=a,t[7]=N):N=t[7];const I=N;let E;t[8]!==I||t[9]!==i||t[10]!==e?(E=(pe,W)=>{const te=pi(W),X=I(pe,te);if(X){w({actionId:pe,combo:te,conflictActionId:X}),j("");return}i(pe,te),w(null),j(""),C(am(te)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(ee=>{const fe={...ee};return delete fe[pe],fe})},t[8]=I,t[9]=i,t[10]=e,t[11]=E):E=t[11];const P=E;let T;t[12]!==k||t[13]!==i||t[14]!==e?(T=()=>{k&&(i(k.conflictActionId,Qy),i(k.actionId,k.combo),w(null),j(""),C(am(k.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(pe=>{const W={...pe};return delete W[k.actionId],W}))},t[12]=k,t[13]=i,t[14]=e,t[15]=T):T=t[15];const S=T;let M;t[16]!==l?(M=pe=>{l(pe),x(W=>{const te={...W};return delete te[pe],te}),w(null),j(""),C("")},t[16]=l,t[17]=M):M=t[17];const D=M;let F;t[18]!==e?(F=e("settings.openchamber.keyboardShortcuts.title"),t[18]=e,t[19]=F):F=t[19];let _;t[20]!==F?(_=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:F}),t[20]=F,t[21]=_):_=t[21];let V;t[22]!==c?(V=()=>{c(),x({}),w(null),j(""),C("")},t[22]=c,t[23]=V):V=t[23];let $;t[24]!==e?($=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),t[24]=e,t[25]=$):$=t[25];let O;t[26]!==V||t[27]!==$?(O=s.jsx(he,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:V,children:$}),t[26]=V,t[27]=$,t[28]=O):O=t[28];let B;t[29]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(Pt,{asChild:!0,children:s.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[29]=B):B=t[29];let G;t[30]!==e?(G=e("settings.openchamber.keyboardShortcuts.tooltip"),t[30]=e,t[31]=G):G=t[31];let R;t[32]!==G?(R=s.jsxs(It,{children:[B,s.jsx(At,{sideOffset:8,className:"max-w-xs",children:G})]}),t[32]=G,t[33]=R):R=t[33];let H;t[34]!==O||t[35]!==R||t[36]!==_?(H=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[_,O,R]})}),t[34]=O,t[35]=R,t[36]=_,t[37]=H):H=t[37];let J;t[38]!==S||t[39]!==h||t[40]!==k||t[41]!==e||t[42]!==v?(J=(h||v||k)&&s.jsxs("div",{className:"mb-2 space-y-2 px-1",children:[k&&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(he,{type:"button",size:"xs",className:"!font-normal",onClick:S,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),s.jsx(he,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>w(null),children:e("settings.common.actions.cancel")})]})]}),h&&s.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:h}),v&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:v})]}),t[38]=S,t[39]=h,t[40]=k,t[41]=e,t[42]=v,t[43]=J):J=t[43];let ne;t[44]!==u||t[45]!==p||t[46]!==y||t[47]!==D||t[48]!==P||t[49]!==a||t[50]!==e?(ne=f.map((pe,W)=>{const te=sa(pe.id,a),X=y[pe.id],ee=X??te,fe=typeof X=="string"&&pi(X)!==pi(te);return s.jsxs("div",{className:ge("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",W>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(pe.id,pe.label)})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx($t,{readOnly:!0,value:p===pe.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):ec(ee),onFocus:()=>{b(pe.id),j("")},onBlur:()=>{p===pe.id&&b(null)},onKeyDown:be=>{if(be.preventDefault(),be.stopPropagation(),be.key==="Escape"){b(null);return}const Ne=SI(be);Ne&&(x(se=>({...se,[pe.id]:Ne})),b(null),w(null),j(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),s.jsx(he,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const be=y[pe.id];if(!be){j(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}P(pe.id,be)},disabled:!fe,children:e("settings.common.actions.saveChanges")}),s.jsx(he,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>D(pe.id),children:e("settings.common.actions.reset")})]})]},pe.id)}),t[44]=u,t[45]=p,t[46]=y,t[47]=D,t[48]=P,t[49]=a,t[50]=e,t[51]=ne):ne=t[51];let ue;t[52]!==ne?(ue=s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:ne}),t[52]=ne,t[53]=ue):ue=t[53];let de;return t[54]!==H||t[55]!==J||t[56]!==ue?(de=s.jsxs("div",{className:"mb-8",children:[H,J,ue]}),t[54]=H,t[55]=J,t[56]=ue,t[57]=de):de=t[57],de};function CI(t){return t.shortcutOverrides}function II(t){return t.setShortcutOverride}function PI(t){return t.clearShortcutOverride}function AI(t){return t.resetAllShortcutOverrides}const DI=t=>{const e=ot.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 l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=un(),e[2]=l):l=e[2];const c=l;let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=In()&&ia(),e[3]=d):d=e[3];const f=d;if(!n){let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(Iu,{}),e[4]=g):g=e[4];let y,x,h;e[5]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(ex,{})}),x=f&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(sx,{})}),h=!c&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(tx,{})}),e[5]=y,e[6]=x,e[7]=h):(y=e[5],x=e[6],h=e[7]);let j;e[8]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Xg,{})}),e[8]=j):j=e[8];let v;e[9]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Zg,{})}),e[9]=v):v=e[9];let C;e[10]!==i?(C=i&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Y4,{})}),e[10]=i,e[11]=C):C=e[11];let k;return e[12]!==C?(k=s.jsx(vs,{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:[g,y,x,h,j,v,C]})}),e[12]=C,e[13]=k):k=e[13],k}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return s.jsx(EI,{});case"chat":return s.jsx(MI,{});case"sessions":return s.jsx(RI,{});case"shortcuts":return s.jsx(TI,{});case"git":return s.jsx(FI,{});case"github":return s.jsx(LI,{});case"notifications":return s.jsx(OI,{});case"voice":return s.jsx($I,{});case"tunnel":return s.jsx(_I,{});default:return null}},e[14]=n,e[15]=m):m=e[15];const u=m;let p;e[16]!==u?(p=u(),e[16]=u,e[17]=p):p=e[17];let b;return e[18]!==p?(b=s.jsx(vs,{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:p})}),e[18]=p,e[19]=b):b=e[19],b},TI=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(kI,{}),t[0]=e):e=t[0],e},EI=()=>{const t=ot.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(Iu,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat","weekStart","fontSize","terminalFontSize","spacing","inputBarOffset",...n?[]:["terminalQuickKeys"],"reportUsage"]}),t[1]=r):r=t[1],r},MI=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Iu,{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},RI=()=>{const t=ot.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=In()&&ia(),t[1]=r):r=t[1];const a=r;let i,l,c;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(ex,{}),l=a&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(sx,{})}),c=!n&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(tx,{})}),t[2]=i,t[3]=l,t[4]=c):(i=t[2],l=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(Xg,{})}),t[5]=d):d=t[5];let f;return t[6]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsxs("div",{className:"space-y-6",children:[i,l,c,d,s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Zg,{})})]}),t[6]=f):f=t[6],f},FI=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"space-y-6",children:s.jsx(qg,{})}),t[0]=e):e=t[0],e},LI=()=>{const t=ot.c(1);if(un())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Jg,{}),t[0]=e):e=t[0],e},OI=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(cI,{}),t[0]=e):e=t[0],e},$I=()=>{const t=ot.c(1);if(un())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(pI,{}),t[0]=e):e=t[0],e},_I=()=>{const t=ot.c(1);if(un())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(jI,{}),t[0]=e):e=t[0],e},zd=176,Ud=280,jf=8,nx="__openchamberSettingsDetail";function sd(t){return Math.min(Ud,Math.max(zd,t))}const BI=["appearance","chat","notifications","sessions","shortcuts","git","magic-prompts","snippets","projects","remote-instances","agents","behavior","commands","mcp","plugins","providers","usage","skills.installed","skills.catalog","voice","tunnel"],VI={icon:"chat-thread"};function zI(t){const e=un(),n=!t&&aa();return{isVSCode:e,isWeb:n,isDesktop:t}}function Nf(t,e){return t.isAvailable?t.isAvailable(e):!0}function Wd(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function nd(t){if(!Wd(t))return null;const e=t[nx];if(!Wd(e))return null;const n=e.page,r=e.stage;return typeof n!="string"||r!=="page-content"?null:{page:Nu(n),stage:r}}function UI(){return typeof window>"u"||!Wd(window.history.state)?{}:window.history.state}function Pu(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"snippets":return VI.icon;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"plugins":return"code-box";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 rd=t=>{const e=ot.c(95),{onOpen:n}=t,{t:r}=pt();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 l;e[4]!==r?(l=r("settings.view.home.description"),e[4]=r,e[5]=l):l=e[5];let c;e[6]!==l?(c=s.jsx("p",{className:"typography-ui text-muted-foreground",children:l}),e[6]=l,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 f;e[11]!==n?(f=()=>n("providers"),e[11]=n,e[12]=f):f=e[12];let m;e[13]===Symbol.for("react.memo_cache_sentinel")?(m=ge("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 p;e[16]!==u?(p=s.jsx("div",{className:"typography-ui-label text-foreground",children:u}),e[16]=u,e[17]=p):p=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 g;e[20]!==b?(g=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:b}),e[20]=b,e[21]=g):g=e[21];let y;e[22]!==g||e[23]!==f||e[24]!==p?(y=s.jsxs("button",{type:"button",onClick:f,className:m,children:[p,g]}),e[22]=g,e[23]=f,e[24]=p,e[25]=y):y=e[25];let x;e[26]!==n?(x=()=>n("agents"),e[26]=n,e[27]=x):x=e[27];let h;e[28]===Symbol.for("react.memo_cache_sentinel")?(h=ge("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[28]=h):h=e[28];let j;e[29]!==r?(j=r("settings.view.home.cards.agents.title"),e[29]=r,e[30]=j):j=e[30];let v;e[31]!==j?(v=s.jsx("div",{className:"typography-ui-label text-foreground",children:j}),e[31]=j,e[32]=v):v=e[32];let C;e[33]!==r?(C=r("settings.view.home.cards.agents.description"),e[33]=r,e[34]=C):C=e[34];let k;e[35]!==C?(k=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:C}),e[35]=C,e[36]=k):k=e[36];let w;e[37]!==x||e[38]!==v||e[39]!==k?(w=s.jsxs("button",{type:"button",onClick:x,className:h,children:[v,k]}),e[37]=x,e[38]=v,e[39]=k,e[40]=w):w=e[40];let N;e[41]!==n?(N=()=>n("skills.catalog"),e[41]=n,e[42]=N):N=e[42];let I;e[43]===Symbol.for("react.memo_cache_sentinel")?(I=ge("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[43]=I):I=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 T;e[48]!==r?(T=r("settings.view.home.cards.skillsCatalog.description"),e[48]=r,e[49]=T):T=e[49];let S;e[50]!==T?(S=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:T}),e[50]=T,e[51]=S):S=e[51];let M;e[52]!==N||e[53]!==P||e[54]!==S?(M=s.jsxs("button",{type:"button",onClick:N,className:I,children:[P,S]}),e[52]=N,e[53]=P,e[54]=S,e[55]=M):M=e[55];let D;e[56]!==n?(D=()=>n("mcp"),e[56]=n,e[57]=D):D=e[57];let F;e[58]===Symbol.for("react.memo_cache_sentinel")?(F=ge("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[58]=F):F=e[58];let _;e[59]!==r?(_=r("settings.view.home.cards.mcp.title"),e[59]=r,e[60]=_):_=e[60];let V;e[61]!==_?(V=s.jsx("div",{className:"typography-ui-label text-foreground",children:_}),e[61]=_,e[62]=V):V=e[62];let $;e[63]!==r?($=r("settings.view.home.cards.mcp.description"),e[63]=r,e[64]=$):$=e[64];let O;e[65]!==$?(O=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:$}),e[65]=$,e[66]=O):O=e[66];let B;e[67]!==D||e[68]!==V||e[69]!==O?(B=s.jsxs("button",{type:"button",onClick:D,className:F,children:[V,O]}),e[67]=D,e[68]=V,e[69]=O,e[70]=B):B=e[70];let G;e[71]!==n?(G=()=>n("usage"),e[71]=n,e[72]=G):G=e[72];let R;e[73]===Symbol.for("react.memo_cache_sentinel")?(R=ge("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[73]=R):R=e[73];let H;e[74]!==r?(H=r("settings.view.home.cards.usage.title"),e[74]=r,e[75]=H):H=e[75];let J;e[76]!==H?(J=s.jsx("div",{className:"typography-ui-label text-foreground",children:H}),e[76]=H,e[77]=J):J=e[77];let ne;e[78]!==r?(ne=r("settings.view.home.cards.usage.description"),e[78]=r,e[79]=ne):ne=e[79];let ue;e[80]!==ne?(ue=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:ne}),e[80]=ne,e[81]=ue):ue=e[81];let de;e[82]!==G||e[83]!==J||e[84]!==ue?(de=s.jsxs("button",{type:"button",onClick:G,className:R,children:[J,ue]}),e[82]=G,e[83]=J,e[84]=ue,e[85]=de):de=e[85];let pe;e[86]!==y||e[87]!==w||e[88]!==M||e[89]!==B||e[90]!==de?(pe=s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[y,w,M,B,de]}),e[86]=y,e[87]=w,e[88]=M,e[89]=B,e[90]=de,e[91]=pe):pe=e[91];let W;return e[92]!==pe||e[93]!==d?(W=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,pe]})}),e[92]=pe,e[93]=d,e[94]=W):W=e[94],W},WI=t=>{const e=ot.c(97),{onClose:n,forceMobile:r,isWindowed:a}=t,{t:i}=pt(),l=an(),c=r??l.isMobile,d=_e(KI),f=_e(HI),m=_e(GI);let u;e[0]!==d?(u=Nu(d),e[0]=d,e[1]=u):u=e[1];const p=u,[b,g]=o.useState("nav"),y=o.useRef(null),[x,h]=o.useState(216),[j,v]=o.useState(!1),[C,k]=o.useState(!1),w=o.useRef(0),N=o.useRef(x),I=o.useRef(null);let E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=In(),e[2]=E):E=e[2];const P=E;let T;e[3]===Symbol.for("react.memo_cache_sentinel")?(T=zI(P),e[3]=T):T=e[3];const S=T;let M;if(e[4]!==c){let Ze;e[6]===Symbol.for("react.memo_cache_sentinel")?(Ze=rt=>Nf(rt,S),e[6]=Ze):Ze=e[6];let ze;e[7]===Symbol.for("react.memo_cache_sentinel")?(ze=rt=>!(S.isVSCode&&rt.slug==="projects"),e[7]=ze):ze=e[7],M=ju.filter(qI).filter(Ze).filter(ze).filter(rt=>!(c&&rt.slug==="shortcuts")),e[4]=c,e[5]=M}else M=e[5];const D=M;let F;e[8]===Symbol.for("react.memo_cache_sentinel")?(F=new Map(BI.map(JI)),e[8]=F):F=e[8];const _=F;let V;if(e[9]!==D){let Ze;e[11]===Symbol.for("react.memo_cache_sentinel")?(Ze=(ze,rt)=>(_.get(ze.slug)??999)-(_.get(rt.slug)??999),e[11]=Ze):Ze=e[11],V=D.slice().sort(Ze),e[9]=D,e[10]=V}else V=e[10];const $=V,O=Ss(YI);let B,G;e[12]!==j?(B=()=>{if(typeof window>"u")return;const Ze=()=>{if(!j){const ze=sd(Math.floor(window.innerWidth*.12));h(ze)}};return window.addEventListener("resize",Ze),()=>window.removeEventListener("resize",Ze)},G=[j],e[12]=j,e[13]=B,e[14]=G):(B=e[13],G=e[14]),o.useEffect(B,G);let R,H;e[15]!==C?(H=()=>{if(!C)return;const Ze=rt=>{const Ge=rt.clientX-w.current,ct=sd(N.current+Ge);h(ct),v(!0)},ze=()=>k(!1);return window.addEventListener("pointermove",Ze),window.addEventListener("pointerup",ze,{once:!0}),()=>{window.removeEventListener("pointermove",Ze),window.removeEventListener("pointerup",ze)}},R=[C],e[15]=C,e[16]=R,e[17]=H):(R=e[16],H=e[17]),o.useEffect(H,R);let J;e[18]!==x?(J=Ze=>{k(!0),w.current=Ze.clientX,N.current=x,Ze.preventDefault()},e[18]=x,e[19]=J):J=e[19];const ne=J;let ue;e[20]!==x?(ue=Ze=>{const ze=Ze.shiftKey?jf*4:jf;let rt;e:switch(Ze.key){case"ArrowLeft":{rt=x-ze;break e}case"ArrowRight":{rt=x+ze;break e}case"Home":{rt=zd;break e}case"End":{rt=Ud;break e}default:return}Ze.preventDefault(),h(sd(rt)),v(!0)},e[20]=x,e[21]=ue):ue=e[21];const de=ue;let pe;e[22]!==f||e[23]!==a||e[24]!==p?(pe=()=>{if(!(!f&&!S.isVSCode&&!a)){if(p==="agents"){ki.getState().loadAgents();return}if(p==="commands"){lu.getState().loadCommands();return}if(p==="mcp"){wo.getState().loadMcpConfigs();return}if(p==="plugins"){Tn.getState().loadPlugins();return}(p==="skills.installed"||p==="skills.catalog")&&(ya.getState().loadSkills(),Ua.getState().loadCatalog()),p==="snippets"&&lc.getState().loadSnippets()}},e[22]=f,e[23]=a,e[24]=p,e[25]=pe):pe=e[25];let W;e[26]!==O||e[27]!==f||e[28]!==a||e[29]!==p?(W=[O,f,a,S.isVSCode,p],e[26]=O,e[27]=f,e[28]=a,e[29]=p,e[30]=W):W=e[30],o.useEffect(pe,W);let te;e[31]!==c||e[32]!==m?(te=Ze=>{if(m(Ze),y.current=Ze,!c)return;const ze=so(Ze);if(!ze||ze.slug==="home"){g("nav");return}g(ze.kind==="split"?"page-sidebar":"page-content")},e[31]=c,e[32]=m,e[33]=te):te=e[33];const X=te;let ee;e[34]!==p?(ee=so(p),e[34]=p,e[35]=ee):ee=e[35];const fe=ee;let be;e[36]===Symbol.for("react.memo_cache_sentinel")?(be={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[36]=be):be=e[36];const Ne=be;let se;e[37]!==i?(se=Ze=>{switch(Ze){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"plugins":return i("settings.page.plugins.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"snippets":return i("settings.page.snippets.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]=se):se=e[38];const ie=se;let ae;e[39]!==i?(ae=()=>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]=ae):ae=e[40];const xe=ae,Z=QI;let me;e[41]!==X||e[42]!==xe?(me=Ze=>{const ze=so(Ze);if(ze&&!Nf(ze,S))return xe();switch(Ze){case"home":return s.jsx(rd,{onOpen:X});case"projects":return s.jsx(oC,{});case"remote-instances":return s.jsx(MC,{});case"agents":return s.jsx(t3,{});case"behavior":return s.jsx(i3,{});case"commands":return s.jsx(h3,{});case"mcp":return s.jsx(U3,{});case"plugins":return s.jsx(x5,{});case"skills.installed":return s.jsx(Jp,{view:"installed"});case"skills.catalog":return s.jsx(Jp,{view:"catalog"});case"providers":return s.jsx(VC,{});case"usage":return s.jsx(l4,{});case"magic-prompts":return s.jsx(p4,{});case"snippets":return s.jsx(b4,{});case"git":return s.jsx(N4,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const rt=Ne[Ze]??"visual";return s.jsx(DI,{section:rt})}default:return s.jsx(rd,{onOpen:X})}},e[41]=X,e[42]=xe,e[43]=me):me=e[43];const Y=me;let Se,we;e[44]!==c||e[45]!==b||e[46]!==p?(Se=()=>{if(!c||b!=="nav"||p==="home"||y.current===p)return;const Ze=so(p);!Ze||Ze.slug==="home"||(y.current=p,g(Ze.kind==="split"?"page-sidebar":"page-content"))},we=[c,b,p],e[44]=c,e[45]=b,e[46]=p,e[47]=Se,e[48]=we):(Se=e[47],we=e[48]),o.useEffect(Se,we);const ke=c&&b!=="nav",Fe=c&&b==="page-content"&&p==="skills.installed",Ce=b==="page-content"&&fe?.kind==="split"&&!Fe;let Q;e[49]!==Fe||e[50]!==ke||e[51]!==i?(Q=i(Fe?"settings.view.actions.back":ke?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),e[49]=Fe,e[50]=ke,e[51]=i,e[52]=Q):Q=e[52];const ce=Q,ve=ro();let le;e[53]===Symbol.for("react.memo_cache_sentinel")?(le=Ze=>{if(typeof window>"u"||S.isVSCode)return;const ze=nd(window.history.state);ze?.page===Ze&&ze.stage==="page-content"||window.history.pushState({...UI(),[nx]:{page:Ze,stage:"page-content"}},"",window.location.href)},e[53]=le):le=e[53];const Ae=le;let Te;e[54]!==p?(Te=()=>{g("page-content"),p==="skills.installed"&&Ae(p)},e[54]=p,e[55]=Te):Te=e[55];const $e=Te;let ye;e[56]!==Fe||e[57]!==p?(ye=()=>{if(Fe){if((typeof window<"u"?nd(window.history.state):null)?.page===p&&!S.isVSCode){window.history.back();return}g("page-sidebar");return}g("nav")},e[56]=Fe,e[57]=p,e[58]=ye):ye=e[58];const q=ye;let L,U;e[59]!==c||e[60]!==p?(L=()=>{if(!c||S.isVSCode)return;const Ze=ze=>{if(p!=="skills.installed")return;if(nd(ze.state)?.page==="skills.installed"){g("page-content");return}g(XI)};return window.addEventListener("popstate",Ze),()=>{window.removeEventListener("popstate",Ze)}},U=[c,S.isVSCode,p],e[59]=c,e[60]=p,e[61]=L,e[62]=U):(L=e[61],U=e[62]),o.useEffect(L,U);let oe;e[63]===Symbol.for("react.memo_cache_sentinel")?(oe=()=>{g("page-sidebar")},e[63]=oe):oe=e[63];const Ee=oe;let Oe;e[64]!==ie||e[65]!==X||e[66]!==p||e[67]!==$||e[68]!==i?(Oe=()=>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:$.map(Ze=>{const ze=p===Ze.slug,rt=Pu(Ze.slug);return rt?s.jsx(It,{children:s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>X(Ze.slug),"aria-current":ze?"page":void 0,className:ge("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",ze?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[s.jsx(A,{name:rt,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:ie(Ze.slug)}),(Ze.slug==="voice"||Ze.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")})]})]})})},Ze.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:!S.isVSCode&&s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",className:ge("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:ZI,children:[s.jsx(A,{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[64]=ie,e[65]=X,e[66]=p,e[67]=$,e[68]=i,e[69]=Oe):Oe=e[69];const Ie=Oe;let z;e[70]!==fe||e[71]!==$e||e[72]!==b||e[73]!==Y||e[74]!==Ie||e[75]!==p?(z=()=>{if(b==="nav")return s.jsx("div",{className:ge("flex-1 min-h-0 overflow-hidden",S.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(Qs,{children:Ie()})})});if(!fe)return s.jsx("div",{className:"flex-1 bg-background"});if(b==="page-sidebar"){if(fe.kind!=="split"){const ze=Y(p);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Qs,{children:ze})})}return s.jsx("div",{className:ge("flex-1 min-h-0 overflow-hidden",S.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx(Qs,{children:Z(p,{onItemSelect:$e})})})}const Ze=Y(p);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Qs,{children:Ze})})},e[70]=fe,e[71]=$e,e[72]=b,e[73]=Y,e[74]=Ie,e[75]=p,e[76]=z):z=e[76];const De=z;let Qe;e[77]!==fe||e[78]!==X||e[79]!==Y||e[80]!==p?(Qe=()=>!fe||p==="home"?s.jsx(rd,{onOpen:X}):fe.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:ge("w-[264px] min-w-[264px] border-r",S.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:s.jsx(Qs,{children:Z(p,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Qs,{children:Y(p)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:s.jsx(Qs,{children:Y(p)})}),e[77]=fe,e[78]=X,e[79]=Y,e[80]=p,e[81]=Qe):Qe=e[81];const tt=Qe,et="true";let We;e[82]===Symbol.for("react.memo_cache_sentinel")?(We=ge("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[82]=We):We=e[82];const at=c?s.jsxs("div",{className:ge("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:ke?q:n,"aria-label":ce,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(A,{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"):fe?ie(fe.slug):i("settings.view.home.title")}),Ce&&s.jsx("button",{type:"button",onClick:Ee,"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(A,{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:ve}),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(A,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[ke&&s.jsx("div",{className:ge("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:q,"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(A,{name:"arrow-left-s",className:"h-5 w-5"})})}),n&&s.jsx("div",{className:ge("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:ve}),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(A,{name:"close",className:"h-5 w-5"})})})]});let qe;e[83]!==ne||e[84]!==de||e[85]!==c||e[86]!==C||e[87]!==x||e[88]!==tt||e[89]!==De||e[90]!==Ie||e[91]!==i?(qe=s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?De():s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:ge("relative flex h-full min-h-0 flex-col overflow-hidden border-r",P?"bg-sidebar":S.isVSCode?"bg-background":"bg-sidebar",C?"":"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:ge("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)]",C?"bg-primary/30":"bg-transparent hover:bg-primary/20"),tabIndex:0,onPointerDown:ne,onKeyDown:de,role:"separator","aria-orientation":"vertical","aria-valuemin":zd,"aria-valuemax":Ud,"aria-valuenow":x,"aria-label":i("settings.view.actions.resizeNavigation")}),s.jsx(Qs,{children:Ie()})]}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:tt()})]})}),e[83]=ne,e[84]=de,e[85]=c,e[86]=C,e[87]=x,e[88]=tt,e[89]=De,e[90]=Ie,e[91]=i,e[92]=qe):qe=e[92];let nt;return e[93]!==We||e[94]!==at||e[95]!==qe?(nt=s.jsxs("div",{ref:I,"data-settings-view":et,className:We,children:[at,qe]}),e[93]=We,e[94]=at,e[95]=qe,e[96]=nt):nt=e[96],nt};function KI(t){return t.settingsPage}function HI(t){return t.isSettingsDialogOpen}function GI(t){return t.setSettingsPage}function qI(t){return t.slug!=="home"}function JI(t,e){return[t,e]}function YI(t){return t.activeProjectId}function QI(t,e){switch(t){case"projects":return s.jsx(X5,{onItemSelect:e.onItemSelect});case"remote-instances":return s.jsx(vC,{onItemSelect:e.onItemSelect});case"agents":return s.jsx(qk,{onItemSelect:e.onItemSelect});case"commands":return s.jsx(o3,{onItemSelect:e.onItemSelect});case"mcp":return s.jsx(g3,{onItemSelect:e.onItemSelect});case"plugins":return s.jsx(a5,{onItemSelect:e.onItemSelect});case"skills.installed":return s.jsx(y5,{onItemSelect:e.onItemSelect});case"providers":return s.jsx(LC,{onItemSelect:e.onItemSelect});case"usage":return s.jsx(UC,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(d4,{onItemSelect:e.onItemSelect});case"snippets":return s.jsx(f4,{onItemSelect:e.onItemSelect});default:return null}}function XI(t){return t==="page-content"?"page-sidebar":t}function ZI(){vi({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]})}const e6=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:WI,getSettingsNavIcon:Pu},Symbol.toStringTag,{value:"Module"})),Kd=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},t6=()=>{const t=ot.c(162),{t:e}=pt(),n=_e(s6),r=_e(n6),a=_e(r6),i=_e(a6),l=_e(i6),c=_e(o6),d=_e(l6),f=_e(c6),m=_e(d6),u=_e(u6),p=_e(m6),b=_e(p6),g=Lt(f6),y=Lt(h6),x=wa(g6),h=Ms(x6),j=Ss(b6),v=la(),C=au(y6),{files:k,git:w}=Wn(),N=qs(v6),{isMobile:I}=an();let E;t[0]!==v?(E=v?Kd(v):null,t[0]=v,t[1]=E):E=t[1];const P=E,[T,S]=o.useState(""),M=ac(T,200);let D;t[2]!==M?(D=M.trim(),t[2]=M,t[3]=D):D=t[3];const F=D;let _;t[4]!==T?(_=T.trim(),t[4]=T,t[5]=_):_=t[5];const V=_;let $,O;t[6]!==n?($=()=>{n&&S("")},O=[n],t[6]=n,t[7]=$,t[8]=O):($=t[7],O=t[8]),o.useEffect($,O);let B,G;t[9]!==x||t[10]!==N||t[11]!==w||t[12]!==n?(B=()=>{if(!n||!w)return;const Me=setTimeout(()=>{const Ue=new Set;for(const He of x){const lt=ao(He);!lt||Ue.has(lt)||(Ue.add(lt),N(lt,w))}},0);return()=>clearTimeout(Me)},G=[n,x,w,N],t[9]=x,t[10]=N,t[11]=w,t[12]=n,t[13]=B,t[14]=G):(B=t[13],G=t[14]),o.useEffect(B,G);let R;t[15]!==r?(R=()=>r(!1),t[15]=r,t[16]=R):R=t[16];const H=R;let J;t[17]!==H?(J=Me=>()=>{H(),Me()},t[17]=H,t[18]=J):J=t[18];const ne=J;let ue;t[19]!==j?.id||t[20]!==j?.path||t[21]!==h||t[22]!==I||t[23]!==u||t[24]!==g||t[25]!==ne||t[26]!==a||t[27]!==c||t[28]!==i||t[29]!==e||t[30]!==m||t[31]!==f||t[32]!==d?(ue=()=>{const Me=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(A,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:ne(()=>{a("chat"),c(!1),g()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(A,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:ne(w6)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(A,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:ne(j6)},{id:"toggle-sidebar",title:e(I?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(A,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(I?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:ne(()=>{if(I){const{isSessionSwitcherOpen:Ue}=_e.getState();c(!Ue)}else d()})},{id:"toggle-right-sidebar",title:e("commandPalette.item.toggleRightSidebar"),icon:s.jsx(A,{name:"layout-right",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_right_sidebar",searchText:e("commandPalette.item.toggleRightSidebar"),onSelect:ne(()=>f())},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(A,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:ne(()=>m())},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(A,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:ne(()=>{h&&u(h)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(A,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:ne(()=>i(!0))}];return Xd()&&Me.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(A,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:ne(()=>{ra("desktop_open_draft_mini_chat_window",{directory:Kd(h||j?.path||""),projectId:j?.id??null}).catch(N6)})}),Me},t[19]=j?.id,t[20]=j?.path,t[21]=h,t[22]=I,t[23]=u,t[24]=g,t[25]=ne,t[26]=a,t[27]=c,t[28]=i,t[29]=e,t[30]=m,t[31]=f,t[32]=d,t[33]=ue):ue=t[33],j?.id,j?.path;let de;t[34]!==ue?(de=ue(),t[34]=ue,t[35]=de):de=t[35];const pe=de;let W;t[36]===Symbol.for("react.memo_cache_sentinel")?(W=In(),t[36]=W):W=t[36];const te=W;let X;t[37]===Symbol.for("react.memo_cache_sentinel")?(X={isVSCode:un(),isWeb:!te&&aa(),isDesktop:te},t[37]=X):X=t[37];const ee=X;let fe;if(t[38]!==ne||t[39]!==i||t[40]!==l){let Me;t[42]===Symbol.for("react.memo_cache_sentinel")?(Me=Ue=>Ue.isAvailable?Ue.isAvailable(ee):!0,t[42]=Me):Me=t[42],fe=ju.filter(S6).filter(Me).map(Ue=>{const He=Pu(Ue.slug)??"settings-3",lt=(Ue.keywords??[]).join(" ");return{id:`settings:${Ue.slug}`,title:Ue.title,icon:s.jsx(A,{name:He,className:"mr-2 h-4 w-4"}),searchText:`${Ue.title} ${Ue.group} ${lt}`,onSelect:ne(()=>{l(Ue.slug),i(!0)})}}),t[38]=ne,t[39]=i,t[40]=l,t[41]=fe}else fe=t[41];const be=fe,Ne=k6;let se;if(t[43]!==x){let Me;t[45]===Symbol.for("react.memo_cache_sentinel")?(Me=(Ue,He)=>Ne(He)-Ne(Ue),t[45]=Me):Me=t[45],se=[...x].sort(Me),t[43]=x,t[44]=se}else se=t[44];const ie=se,ae=Fh(),xe=Lt(C6);let Z;t[46]!==ae||t[47]!==xe?(Z=(Me,Ue)=>{const He=xe.get(Me);return He?.branch?He.branch.trim()||null:Ue&&ae.get(Ue)?.trim()||null},t[46]=ae,t[47]=xe,t[48]=Z):Z=t[48];const me=Z;let Y;t[49]===Symbol.for("react.memo_cache_sentinel")?(Y=[],t[49]=Y):Y=t[49];const[Se,we]=o.useState(Y),[ke,Fe]=o.useState(!1);let Ce,Q;t[50]!==P||t[51]!==n||t[52]!==C||t[53]!==F?(Ce=()=>{if(!n){we([]),Fe(!1);return}if(!P||F.length===0){we([]),Fe(!1);return}let Me=!1;return Fe(!0),C(P,F,10,{type:"file"}).then(Ue=>{Me||we(Ue.map(I6))}).catch(()=>{Me||we([])}).finally(()=>{Me||Fe(!1)}),()=>{Me=!0}},Q=[n,P,F,C],t[50]=P,t[51]=n,t[52]=C,t[53]=F,t[54]=Ce,t[55]=Q):(Ce=t[54],Q=t[55]),o.useEffect(Ce,Q);const ce=V.length>0;let ve;e:{if(!ce){let Ue;t[56]!==pe?(Ue=pe.map(P6),t[56]=pe,t[57]=Ue):Ue=t[57],ve=Ue;break e}let Me;t[58]!==pe||t[59]!==V?(Me=$o(pe,V,A6,{limit:7,noFuzzy:!0}),t[58]=pe,t[59]=V,t[60]=Me):Me=t[60],ve=Me}const le=ve;let Ae;e:{if(!ce){let Ue;t[61]===Symbol.for("react.memo_cache_sentinel")?(Ue=[],t[61]=Ue):Ue=t[61],Ae=Ue;break e}let Me;t[62]!==V||t[63]!==be?(Me=$o(be,V,D6,{limit:7,noFuzzy:!0}),t[62]=V,t[63]=be,t[64]=Me):Me=t[64],Ae=Me}const Te=Ae;let $e;e:{if(!ce){let Ue;t[65]!==ie?(Ue=ie.slice(0,5).map(T6),t[65]=ie,t[66]=Ue):Ue=t[66],$e=Ue;break e}let Me;t[67]!==V||t[68]!==ie?(Me=$o(ie,V,E6,{limit:7,threshold:.2}),t[67]=V,t[68]=ie,t[69]=Me):Me=t[69],$e=Me}const ye=$e;let q;e:{if(!ce||Se.length===0){let Ue;t[70]===Symbol.for("react.memo_cache_sentinel")?(Ue=[],t[70]=Ue):Ue=t[70],q=Ue;break e}let Me;t[71]!==Se||t[72]!==V?(Me=$o(Se,V,M6,{limit:10,threshold:.4}),t[71]=Se,t[72]=V,t[73]=Me):Me=t[73],q=Me}const L=q;let U,oe,Ee,Oe,Ie,z,De,Qe,tt,et,We,at,qe,nt,Ze;if(t[74]!==me||t[75]!==H||t[76]!==P||t[77]!==k||t[78]!==ce||t[79]!==n||t[80]!==p||t[81]!==T||t[82]!==le||t[83]!==L||t[84]!==ye||t[85]!==Te||t[86]!==r||t[87]!==y||t[88]!==b||t[89]!==e){const Me=le.map(R6),Ue=Te.map(F6),He=ye.map(L6);Ze=ce?L.map(O6):[];let lt;e:{if(!ce){lt=["commands","sessions"];break e}const _t=$6,Ye=[{key:"commands",score:_t(le)},{key:"settings",score:_t(Te)},{key:"sessions",score:_t(ye)},{key:"files",score:_t(L)}];Ye.sort(_6),lt=Ye.map(B6)}const vt=lt;let ft;t[105]!==H||t[106]!==y?(ft=_t=>{H(),y(_t.id,ao(_t))},t[105]=H,t[106]=y,t[107]=ft):ft=t[107];const dt=ft;let Dt;t[108]!==H||t[109]!==P||t[110]!==k||t[111]!==p?(Dt=async _t=>{if(!P)return;const Ye=await vu(k,_t);if(!Ye.ok){K.error(wu(Ye.reason));return}p(P,_t),H()},t[108]=H,t[109]=P,t[110]=k,t[111]=p,t[112]=Dt):Dt=t[112];const Qt=Dt;let Ft;t[113]!==b?(Ft=_t=>ec(sa(_t,b)),t[113]=b,t[114]=Ft):Ft=t[114];const qt=Ft;Oe=ls,at=n,qe=r;let gt;t[115]!==e?(gt=e("commandPalette.title"),t[115]=e,t[116]=gt):gt=t[116];let zt;t[117]!==gt?(zt=s.jsx(ds,{children:gt}),t[117]=gt,t[118]=zt):zt=t[118];let es;t[119]!==e?(es=e("commandPalette.description"),t[119]=e,t[120]=es):es=t[120];let is;t[121]!==es?(is=s.jsx(ys,{children:es}),t[121]=es,t[122]=is):is=t[122],t[123]!==zt||t[124]!==is?(nt=s.jsxs(ps,{className:"sr-only",children:[zt,is]}),t[123]=zt,t[124]=is,t[125]=nt):nt=t[125],Ee=os,et="overflow-hidden p-0",We=!0,oe=Ya,De=!1,Qe="[&_[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 cs;t[126]!==e?(cs=e("commandPalette.input.placeholder"),t[126]=e,t[127]=cs):cs=t[127],t[128]!==T||t[129]!==cs?(tt=s.jsx(Sa,{value:T,onValueChange:S,placeholder:cs}),t[128]=T,t[129]=cs,t[130]=tt):tt=t[130],U=Qa;let hs;t[131]!==e?(hs=e("commandPalette.empty.noResults"),t[131]=e,t[132]=hs):hs=t[132],t[133]!==hs?(Ie=s.jsx(Xa,{children:hs}),t[133]=hs,t[134]=Ie):Ie=t[134],z=vt.map(_t=>_t==="commands"&&Me.length>0?s.jsx(Vn,{children:Me.map(Ye=>s.jsxs(En,{value:Ye.id,onSelect:Ye.onSelect,children:[Ye.icon,s.jsx("span",{children:Ye.title}),Ye.shortcutId?s.jsx(Cj,{children:qt(Ye.shortcutId)}):null]},Ye.id))},"commands"):_t==="settings"&&Ue.length>0?s.jsx(Vn,{children:Ue.map(V6)},"settings"):_t==="sessions"&&He.length>0?s.jsx(Vn,{children:He.map(Ye=>{const Mt=Ye.title||e("commandPalette.session.untitled"),Bt=ao(Ye),wt=me(Ye.id,Bt);return s.jsxs(En,{value:`session:${Ye.id}`,onSelect:()=>dt(Ye),children:[s.jsx(A,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:Mt}),wt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:wt})]}):null]},Ye.id)})},"sessions"):_t==="files"&&Ze.length>0?s.jsx(Vn,{children:Ze.map(Ye=>{const Mt=Xy(Ye.relativePath||Ye.name,{maxLength:80});return s.jsxs(En,{value:`file:${Ye.path}`,onSelect:()=>{Qt(Ye.path)},children:[s.jsx(Er,{filePath:Ye.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":Ye.relativePath,children:Mt})]},`file:${Ye.path}`)})},"files"):null),t[74]=me,t[75]=H,t[76]=P,t[77]=k,t[78]=ce,t[79]=n,t[80]=p,t[81]=T,t[82]=le,t[83]=L,t[84]=ye,t[85]=Te,t[86]=r,t[87]=y,t[88]=b,t[89]=e,t[90]=U,t[91]=oe,t[92]=Ee,t[93]=Oe,t[94]=Ie,t[95]=z,t[96]=De,t[97]=Qe,t[98]=tt,t[99]=et,t[100]=We,t[101]=at,t[102]=qe,t[103]=nt,t[104]=Ze}else U=t[90],oe=t[91],Ee=t[92],Oe=t[93],Ie=t[94],z=t[95],De=t[96],Qe=t[97],tt=t[98],et=t[99],We=t[100],at=t[101],qe=t[102],nt=t[103],Ze=t[104];let ze;t[135]!==ce||t[136]!==ke||t[137]!==e||t[138]!==Ze?(ze=ce&&ke&&Ze.length===0?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[135]=ce,t[136]=ke,t[137]=e,t[138]=Ze,t[139]=ze):ze=t[139];let rt;t[140]!==U||t[141]!==Ie||t[142]!==z||t[143]!==ze?(rt=s.jsxs(U,{children:[Ie,z,ze]}),t[140]=U,t[141]=Ie,t[142]=z,t[143]=ze,t[144]=rt):rt=t[144];let Ge;t[145]!==oe||t[146]!==De||t[147]!==Qe||t[148]!==tt||t[149]!==rt?(Ge=s.jsxs(oe,{shouldFilter:De,className:Qe,children:[tt,rt]}),t[145]=oe,t[146]=De,t[147]=Qe,t[148]=tt,t[149]=rt,t[150]=Ge):Ge=t[150];let ct;t[151]!==Ee||t[152]!==et||t[153]!==We||t[154]!==Ge?(ct=s.jsx(Ee,{className:et,showCloseButton:We,children:Ge}),t[151]=Ee,t[152]=et,t[153]=We,t[154]=Ge,t[155]=ct):ct=t[155];let Pe;return t[156]!==Oe||t[157]!==at||t[158]!==qe||t[159]!==nt||t[160]!==ct?(Pe=s.jsxs(Oe,{open:at,onOpenChange:qe,children:[nt,ct]}),t[156]=Oe,t[157]=at,t[158]=qe,t[159]=nt,t[160]=ct,t[161]=Pe):Pe=t[161],Pe};function s6(t){return t.isCommandPaletteOpen}function n6(t){return t.setCommandPaletteOpen}function r6(t){return t.setActiveMainTab}function a6(t){return t.setSettingsDialogOpen}function i6(t){return t.setSettingsPage}function o6(t){return t.setSessionSwitcherOpen}function l6(t){return t.toggleSidebar}function c6(t){return t.toggleRightSidebar}function d6(t){return t.toggleBottomTerminal}function u6(t){return t.openContextOverview}function m6(t){return t.openContextFile}function p6(t){return t.shortcutOverrides}function f6(t){return t.openNewSessionDraft}function h6(t){return t.setCurrentSession}function g6(t){return t.activeSessions}function x6(t){return t.currentDirectory}function b6(t){return t.getActiveProject()}function y6(t){return t.searchFiles}function v6(t){return t.ensureStatus}function w6(){Lh()}function j6(){Mr.requestDirectoryDialog()}function N6(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function S6(t){return t.slug!=="home"}function k6(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function C6(t){return t.worktreeMetadata}function I6(t){return{path:Kd(t.path),name:t.name,relativePath:t.relativePath}}function P6(t){return{item:t,score:0}}function A6(t){return t.searchText}function D6(t){return t.searchText}function T6(t){return{item:t,score:0}}function E6(t){return t.title||""}function M6(t){return t.name}function R6(t){return t.item}function F6(t){return t.item}function L6(t){return t.item}function O6(t){return t.item}function $6(t){return t.length?t[0].score:1/0}function _6(t,e){return t.score-e.score}function B6(t){return t.key}function V6(t){return s.jsxs(En,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const Sf=(t,e,n)=>ev(t)?ec(sa(t,n)):e,z6=()=>{const t=ot.c(68),{t:e}=pt(),n=_e(U6),r=_e(W6),a=_e(K6);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=Zy(),t[0]=i):i=t[0];const l=i;let c,d,f,m,u,p,b,g,y;if(t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==e){const F=[{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 + ${l} + 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:[`${l} + 1...9`],descriptionKey:"helpDialog.item.switchProject",icon:"layout-left"},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];d=ls,g=n,y=r,c=os,p="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let _;t[14]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(A,{name:"settings-3",className:"h-5 w-5"}),t[14]=_):_=t[14];let V;t[15]!==e?(V=e("helpDialog.title"),t[15]=e,t[16]=V):V=t[16];let $;t[17]!==V?($=s.jsxs(ds,{className:"flex items-center gap-2",children:[_,V]}),t[17]=V,t[18]=$):$=t[18];let O;t[19]!==e?(O=e("helpDialog.description"),t[19]=e,t[20]=O):O=t[20];let B;t[21]!==O?(B=s.jsx(ys,{children:O}),t[21]=O,t[22]=B):B=t[22],t[23]!==$||t[24]!==B?(b=s.jsxs(ps,{children:[$,B]}),t[23]=$,t[24]=B,t[25]=b):b=t[25],u="flex-1 overflow-y-auto mt-3 pr-1",f="space-y-4",m=F.map(G=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(G.categoryKey)}),s.jsx("div",{className:"space-y-1",children:G.items.map(R=>{const H=R.id?Sf(R.id,Array.isArray(R.keys)?R.keys[0]:R.keys,a):Array.isArray(R.keys)?R.keys:R.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:[R.icon&&s.jsx(A,{name:R.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(R.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(H)?H:[H]).map((J,ne)=>s.jsxs(o.Fragment,{children:[ne>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:J})]},`${J}-${ne}`))})]},R.id||R.descriptionKey)})})]},G.categoryKey)),t[1]=n,t[2]=r,t[3]=a,t[4]=e,t[5]=c,t[6]=d,t[7]=f,t[8]=m,t[9]=u,t[10]=p,t[11]=b,t[12]=g,t[13]=y}else c=t[5],d=t[6],f=t[7],m=t[8],u=t[9],p=t[10],b=t[11],g=t[12],y=t[13];let x;t[26]!==f||t[27]!==m?(x=s.jsx("div",{className:f,children:m}),t[26]=f,t[27]=m,t[28]=x):x=t[28];let h;t[29]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(A,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[29]=h):h=t[29];let j;t[30]!==e?(j=e("helpDialog.proTips.title"),t[30]=e,t[31]=j):j=t[31];let v;t[32]!==j?(v=s.jsx("p",{className:"font-medium mb-1",children:j}),t[32]=j,t[33]=v):v=t[33];let C;t[34]!==a||t[35]!==e?(C=e("helpDialog.proTips.commandPalette",{shortcut:Sf("open_command_palette",`${l} P`,a)}),t[34]=a,t[35]=e,t[36]=C):C=t[36];let k;t[37]!==C?(k=s.jsxs("li",{children:["• ",C]}),t[37]=C,t[38]=k):k=t[38];let w;t[39]!==e?(w=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=w):w=t[40];let N;t[41]!==w?(N=s.jsxs("li",{children:["• ",w]}),t[41]=w,t[42]=N):N=t[42];let I;t[43]!==e?(I=e("helpDialog.proTips.themeCycling"),t[43]=e,t[44]=I):I=t[44];let E;t[45]!==I?(E=s.jsxs("li",{children:["• ",I]}),t[45]=I,t[46]=E):E=t[46];let P;t[47]!==k||t[48]!==N||t[49]!==E?(P=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[k,N,E]}),t[47]=k,t[48]=N,t[49]=E,t[50]=P):P=t[50];let T;t[51]!==v||t[52]!==P?(T=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[h,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[v,P]})]})}),t[51]=v,t[52]=P,t[53]=T):T=t[53];let S;t[54]!==T||t[55]!==u||t[56]!==x?(S=s.jsxs("div",{className:u,children:[x,T]}),t[54]=T,t[55]=u,t[56]=x,t[57]=S):S=t[57];let M;t[58]!==c||t[59]!==S||t[60]!==p||t[61]!==b?(M=s.jsxs(c,{className:p,children:[b,S]}),t[58]=c,t[59]=S,t[60]=p,t[61]=b,t[62]=M):M=t[62];let D;return t[63]!==d||t[64]!==M||t[65]!==g||t[66]!==y?(D=s.jsx(d,{open:g,onOpenChange:y,children:M}),t[63]=d,t[64]=M,t[65]=g,t[66]=y,t[67]=D):D=t[67],D};function U6(t){return t.isHelpDialogOpen}function W6(t){return t.setHelpDialogOpen}function K6(t){return t.shortcutOverrides}const H6=()=>{const t=ot.c(32),{t:e}=pt(),n=_e(G6),r=_e(q6),a=_e(J6);let i;t[0]!==a||t[1]!==e?(i=async()=>{if(!a)return;if((await Ln(a)).ok){K.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}K.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=a,t[1]=e,t[2]=i):i=t[2];const l=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(ds,{children:c}),t[5]=c,t[6]=d):d=t[6];let f;t[7]!==e?(f=e("openCodeStatusDialog.description"),t[7]=e,t[8]=f):f=t[8];let m;t[9]!==f?(m=s.jsx(ys,{children:f}),t[9]=f,t[10]=m):m=t[10];let u;t[11]!==d||t[12]!==m?(u=s.jsxs(ps,{children:[d,m]}),t[11]=d,t[12]=m,t[13]=u):u=t[13];let p;t[14]!==e?(p=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=p):p=t[15];let b;t[16]!==l||t[17]!==p?(b=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:l,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:p})}),t[16]=l,t[17]=p,t[18]=b):b=t[18];let g;t[19]!==a||t[20]!==e?(g=a||e("openCodeStatusDialog.empty.noData"),t[19]=a,t[20]=e,t[21]=g):g=t[21];let y;t[22]!==g?(y=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:g}),t[22]=g,t[23]=y):y=t[23];let x;t[24]!==u||t[25]!==b||t[26]!==y?(x=s.jsxs(os,{className:"max-w-2xl",children:[u,b,y]}),t[24]=u,t[25]=b,t[26]=y,t[27]=x):x=t[27];let h;return t[28]!==n||t[29]!==r||t[30]!==x?(h=s.jsx(ls,{open:n,onOpenChange:r,children:x}),t[28]=n,t[29]=r,t[30]=x,t[31]=h):h=t[31],h};function G6(t){return t.isOpenCodeStatusDialogOpen}function q6(t){return t.setOpenCodeStatusDialogOpen}function J6(t){return t.openCodeStatusText}const Y6=180,kf=600,Q6=1,X6=6,Z6=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],ensureSessionRenderable:r})=>{const a=o.useRef(new Map),i=o.useRef([]),l=o.useRef(new Set),c=o.useMemo(()=>un(),[]),d=o.useCallback(()=>{if(!(c||typeof window>"u"))for(;l.current.size<Q6&&i.current.length>0;){const m=i.current.shift();if(!m)break;Lt.getState().currentSessionId!==m&&(im(m).renderable||(l.current.add(m),r(m).catch(()=>{}).finally(()=>{l.current.delete(m),d()})))}},[r,c]),f=o.useCallback(m=>{if(c||!m||m===t||typeof window>"u"||im(m).renderable||l.current.has(m)||i.current.includes(m))return;i.current.length>=X6&&i.current.shift();const u=a.current.get(m);u!==void 0&&window.clearTimeout(u);const p=window.setTimeout(()=>{a.current.delete(m),i.current.push(m),d()},Y6);a.current.set(m,p)},[t,c,d]);o.useEffect(()=>{if(c||!t||e.length===0)return;const m=window.setTimeout(()=>{const u=e.findIndex(p=>p.id===t);u<0||(f(e[u-1]?.id),f(e[u+1]?.id))},kf);return()=>window.clearTimeout(m)},[t,c,f,e]),o.useEffect(()=>{if(c||!t||n.length===0)return;const m=window.setTimeout(()=>{const u=n.indexOf(t);u<0||(f(n[u-1]),f(n[u+1]))},kf);return()=>window.clearTimeout(m)},[t,c,n,f]),o.useEffect(()=>{const m=a.current;return()=>{m.forEach(u=>{clearTimeout(u)}),m.clear(),i.current=[]}},[])};function Cf(t){const{localBranches:e,remoteBranches:n,query:r}=t,a=r.trim();if(!a)return{matching:[],otherLocal:e,otherRemote:n};const i=om(e,a,m=>m),l=om(n,a,m=>m),c=[],d=i.other,f=l.other;for(const m of i.matching)c.push({label:m,value:m,source:"local"});for(const m of l.matching)c.push({label:m,value:`remotes/${m}`,source:"remote"});return c.sort((m,u)=>{const p=m.label.localeCompare(u.label,void 0,{sensitivity:"accent"});return p!==0?p:m.source!==u.source?m.source.localeCompare(u.source):m.value.localeCompare(u.value)}),{matching:c,otherLocal:d,otherRemote:f}}function eP({open:t,onOpenChange:e,onSelect:n}){const{t:r}=pt(),a=_e(ae=>ae.isMobile),{github:i}=Wn(),l=Yn(ae=>ae.status),c=Yn(ae=>ae.hasChecked),d=_e(ae=>ae.setSettingsDialogOpen),f=_e(ae=>ae.setSettingsPage),m=Ss(ae=>ae.getActiveProject()),u=m?.path??null,p=Ve.useMemo(()=>u&&m?{id:m.id,path:u}:null,[m,u]),[b,g]=Ve.useState("issues"),[y,x]=Ve.useState(""),[h,j]=Ve.useState([]),[v,C]=Ve.useState([]),[k,w]=Ve.useState(!1),[N,I]=Ve.useState(!1),[E,P]=Ve.useState(null),[T,S]=Ve.useState(null),[M,D]=Ve.useState(null),[F,_]=Ve.useState(!1),[V,$]=Ve.useState(new Map),[O,B]=Ve.useState(1),[G,R]=Ve.useState(!1),H=Ve.useCallback(async()=>{if(!(!u||!i)&&!(c&&l?.connected===!1)){w(!0),P(null),B(1),R(!1);try{if(b==="issues"&&i.issuesList){const ae=await i.issuesList(u,{page:1});ae.connected===!1?(P(r("session.githubIntegration.error.notConnected")),j([])):(j(ae.issues??[]),B(ae.page??1),R(!!ae.hasMore))}else if(b==="prs"&&i.prsList){const ae=await i.prsList(u,{page:1});ae.connected===!1?(P(r("session.githubIntegration.error.notConnected")),C([])):(C(ae.prs??[]),B(ae.page??1),R(!!ae.hasMore))}}catch(ae){P(ae instanceof Error?ae.message:r("session.githubIntegration.error.loadDataFailed"))}finally{w(!1)}}},[u,i,c,l,b,r]),J=Ve.useCallback(async()=>{if(!(!u||!i)&&!(k||N)&&G){I(!0);try{const ae=O+1;if(b==="issues"&&i.issuesList){const xe=await i.issuesList(u,{page:ae});xe.connected!==!1&&(j(Z=>[...Z,...xe.issues??[]]),B(xe.page??ae),R(!!xe.hasMore))}else if(b==="prs"&&i.prsList){const xe=await i.prsList(u,{page:ae});xe.connected!==!1&&(C(Z=>[...Z,...xe.prs??[]]),B(xe.page??ae),R(!!xe.hasMore))}}catch{}finally{I(!1)}}},[u,i,b,O,G,k,N]);Ve.useEffect(()=>{if(!t){g("issues"),x(""),j([]),C([]),S(null),D(null),_(!1),P(null),$(new Map),B(1),R(!1);return}H()},[t,H]);const ne=Ve.useCallback(async ae=>{if(!(!p||!ae)&&!V.has(ae))try{const Z=(await Oh(p,{mode:"new",branchName:ae,worktreeName:ae})).errors.find(me=>me.code==="branch_in_use");$(me=>new Map(me).set(ae,{isValid:!Z,error:Z?r(Z.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{$(xe=>new Map(xe).set(ae,{isValid:!1,error:r("session.githubIntegration.validation.failed")}))}},[p,V,r]);Ve.useEffect(()=>{!t||b!=="prs"||v.forEach(ae=>{ae.head&&ne(ae.head)})},[t,b,v,ne]);const ue=Ve.useMemo(()=>{const ae=y.trim().toLowerCase();return ae?h.filter(xe=>String(xe.number)===ae.replace(/^#/,"")?!0:xe.title.toLowerCase().includes(ae)):h},[h,y]),de=Ve.useMemo(()=>{const ae=y.trim().toLowerCase();return ae?v.filter(xe=>String(xe.number)===ae.replace(/^#/,"")?!0:xe.title.toLowerCase().includes(ae)):v},[v,y]),pe=c&&l?.connected===!0,W=()=>{f("github"),d(!0)},te=ae=>{S(ae),D(null)},X=ae=>{D(ae),S(null)},ee=()=>{T?n({type:"issue",item:T}):M&&n({type:"pr",item:M,includeDiff:F}),e(!1)},fe=()=>{S(null),D(null),_(!1)},be=T||M&&V.get(M.head??"")?.isValid!==!1,Ne=ae=>ae.head?V.get(ae.head)?.isValid===!1:!0,se=s.jsx(s.Fragment,{children:pe?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"relative mt-2",children:[s.jsx(A,{name:"search",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),s.jsx($t,{value:y,onChange:ae=>x(ae.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:[k&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx(A,{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(A,{name:"error-warning",className:"h-4 w-4"}),s.jsx("span",{className:"typography-small",children:E})]})}),!k&&!E&&b==="issues"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[ue.length>0?ue.map(ae=>s.jsx("button",{onClick:()=>te(ae),className:ge("w-full text-left px-2 py-1.5 rounded transition-colors",T?.number===ae.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:["#",ae.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-2",children:ae.title}),ae.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:[ae.sourceRepo.owner,"/",ae.sourceRepo.repo]}):null]})]})},`${ae.sourceRepo?.owner??""}-${ae.sourceRepo?.repo??""}-${ae.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")}),G&&!N&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>{J()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),N&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),!k&&!E&&b==="prs"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[de.length>0?de.map(ae=>{const xe=Ne(ae),Z=ae.head?V.get(ae.head):void 0;return s.jsx("button",{onClick:()=>!xe&&X(ae),disabled:xe,className:ge("w-full text-left px-2 py-1.5 rounded transition-colors",M?.number===ae.number?"bg-interactive-selection text-interactive-selection-foreground":xe?"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:["#",ae.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-1",children:ae.title}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[ae.head," → ",ae.base]}),ae.sourceRepo?.source==="upstream"?s.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[ae.sourceRepo.owner,"/",ae.sourceRepo.repo]}):null,xe&&Z?.error&&s.jsx("span",{className:"typography-micro text-destructive",children:Z.error})]})]})]})},`${ae.sourceRepo?.owner??""}-${ae.sourceRepo?.repo??""}-${ae.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")}),G&&!N&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(he,{variant:"ghost",size:"sm",onClick:()=>{J()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),N&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(A,{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(A,{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(he,{onClick:W,size:"sm",children:r("session.githubIntegration.connect.action")})]})}),ie=s.jsxs("div",{className:ge("w-full",a?"flex flex-col gap-2":"flex flex-row items-center"),children:[s.jsxs("div",{className:ge("flex items-center gap-4",a?"w-full justify-center order-1":"flex-1"),children:[!a&&(T||M)&&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(A,{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:T?r("session.githubIntegration.selected.issueNumber",{number:T.number}):r("session.githubIntegration.selected.prNumber",{number:M?.number??""})}),s.jsx("button",{onClick:fe,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]}),b==="prs"&&M&&s.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[s.jsx(fs,{checked:F,onChange:ae=>_(ae),ariaLabel:r("session.githubIntegration.includeDiffAria")}),s.jsx("span",{className:"typography-small text-foreground",children:r("session.githubIntegration.includeDiff")})]})]}),s.jsxs("div",{className:ge("flex gap-2",a?"w-full order-2":"justify-end"),children:[s.jsx(he,{variant:"outline",size:"sm",onClick:()=>e(!1),className:ge(a&&"flex-1"),children:r("session.githubIntegration.actions.cancel")}),s.jsx(he,{size:"sm",onClick:ee,disabled:!be,className:ge(a&&"flex-1"),children:r("session.githubIntegration.actions.select")})]})]});return s.jsx(s.Fragment,{children:a?s.jsx(Ur,{open:t,title:r("session.githubIntegration.title"),onClose:()=>e(!1),footer:pe?ie:void 0,renderHeader:ae=>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")}),ae]}),s.jsx("div",{className:"w-full",children:s.jsx(Fr,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(A,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:xe=>{g(xe),x("")},variant:"active-pill",layoutMode:"fit"})}),(T||M)&&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(A,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate flex-1",children:T?r("session.githubIntegration.selected.issueNumber",{number:T.number}):r("session.githubIntegration.selected.prNumber",{number:M?.number??""})}),s.jsx("button",{onClick:fe,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]}),children:se}):s.jsx(ls,{open:t,onOpenChange:e,children:s.jsxs(os,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsx(ps,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(ds,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(A,{name:"github",className:"h-5 w-5"}),r("session.githubIntegration.title")]}),s.jsx("div",{className:"w-[220px]",children:s.jsx(Fr,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(A,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:ae=>{g(ae),x("")},variant:"active-pill",layoutMode:"fit"})})]})}),se,s.jsx(Rs,{className:"mt-1",children:ie})]})})})}const no=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),If="oc:lastWorktreeSourceBranch",tP=t=>String(t).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",Pf=(t,e,n)=>{const r=no(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(f=>{const m=f.indexOf("/");return m<=0||m>=f.length-1?!1:f.slice(m+1)===r});if(a){const f=a.indexOf("/"),m=a.slice(0,f);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(),l=t.headRepo?.owner||i||"pr-head",c=`pr-${tP(l)}`,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}`}},sP=t=>{const e={repo:t.repo??null,issue:t.issue,comments:t.comments};return`GitHub issue context (JSON)
|
|
190
|
+
${JSON.stringify(e,null,2)}`},nP=t=>`GitHub pull request context (JSON)
|
|
191
|
+
${JSON.stringify(t,null,2)}`;function rP({open:t,onOpenChange:e,onWorktreeCreated:n}){const{t:r}=pt(),{github:a,git:i}=Wn(),l=_e(z=>z.isMobile),c=Yn(z=>z.status),d=Yn(z=>z.hasChecked),f=Ss(z=>z.getActiveProject()),m=f?.path??null,u=Ve.useMemo(()=>m&&f?{id:f.id,path:m}:null,[f,m]),[p,b]=Ve.useState("new-branch"),[g,y]=Ve.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[x,h]=Ve.useState({selectedBranch:"",worktreeName:""}),j=su(m),v=$h(m),C=qs(z=>z.fetchBranches),k=Ve.useMemo(()=>j?.all?j.all.filter(z=>!z.startsWith("remotes/")).sort():[],[j]),w=Ve.useMemo(()=>j?.all?j.all.filter(z=>z.startsWith("remotes/")).map(z=>z.replace(/^remotes\//,"")).sort():[],[j]),N=Lt(z=>z.availableWorktreesByProject),I=Ve.useMemo(()=>{if(!m)return new Set;const z=N.get(m)??[];return new Set(z.map(De=>De.name))},[N,m]),E=Ve.useCallback((z=10)=>{for(let De=0;De<z;De++){const Qe=jc();if(!I.has(Qe))return Qe}return`${jc()}-${Date.now().toString(36).slice(-4)}`},[I]),[P,T]=Ve.useState(!1),[S,M]=Ve.useState(!1),[D,F]=Ve.useState(!1),[_,V]=Ve.useState(!1),[$,O]=Ve.useState(!1),[B,G]=Ve.useState(""),[R,H]=Ve.useState(""),J=Ve.useRef(null),ne=Ve.useRef(null),ue=Ve.useRef(null),de=Ve.useRef(null),pe=Ve.useCallback(z=>{z.stopPropagation()},[]),W=Ve.useCallback(z=>{let De=z;for(;De&&De!==document.body;){const{overflowY:Qe}=window.getComputedStyle(De);if((Qe==="auto"||Qe==="scroll")&&De.scrollHeight>De.clientHeight)return De;De=De.parentElement}return null},[]),te=Ve.useCallback(z=>{z&&(z.scrollTop=0)},[]),X=Ve.useCallback(z=>{const De=z.current?.querySelector('[data-slot="command-list"]')??null;te(De)},[te]),ee=Ve.useCallback(z=>{const De=W(z.current);te(De)},[W,te]),fe=Ve.useMemo(()=>Cf({localBranches:k,remoteBranches:w,query:B}),[k,w,B]),be=Ve.useMemo(()=>Cf({localBranches:k,remoteBranches:w,query:R}),[k,w,R]),Ne=B.trim().length>0,se=R.trim().length>0,ie=fe.matching.length>0,ae=be.matching.length>0,xe=!!(m&&i),Z=Ve.useCallback(()=>{!m||!i||C(m,i)},[m,i,C]);Ve.useEffect(()=>{!S&&!_&&G("")},[S,_]),Ve.useEffect(()=>{!D&&!$&&H("")},[D,$]),Ve.useEffect(()=>{S&&X(J),_&&ee(ue)},[S,_,B,X,ee]),Ve.useEffect(()=>{D&&X(ne),$&&ee(de)},[D,$,R,X,ee]);const[me,Y]=Ve.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[Se,we]=Ve.useState(!1),[ke,Fe]=Ve.useState(null),Ce=Ve.useCallback(()=>{const z=jt.getState(),De=z.getVisibleAgents();if(z.settingsDefaultAgent){const Qe=De.find(tt=>tt.name===z.settingsDefaultAgent);if(Qe)return Qe.name}return De.find(Qe=>Qe.name==="build")?.name||De[0]?.name},[]),Q=Ve.useCallback(()=>{const z=jt.getState(),De=z.settingsDefaultModel;if(!De)return null;const Qe=Di(De);if(!Qe)return null;const{providerId:tt,modelId:et}=Qe;return z.getModelMetadata(tt,et)?{providerID:tt,modelID:et}:null},[]),ce=Ve.useCallback((z,De)=>{const Qe=jt.getState(),tt=Qe.settingsDefaultVariant;if(!tt)return;const at=Qe.providers.find(qe=>qe.id===z)?.models.find(qe=>qe.id===De)?.variants;if(at&&Object.prototype.hasOwnProperty.call(at,tt))return tt},[]),ve=Ve.useCallback(z=>{const De=jt.getState();try{_o.getState().saveSessionModelSelection(z.sessionId,z.providerID,z.modelID)}catch{}if(z.agentName){try{De.setAgent(z.agentName)}catch{}try{_o.getState().saveSessionAgentSelection(z.sessionId,z.agentName)}catch{}try{_o.getState().saveAgentModelForSession(z.sessionId,z.agentName,z.providerID,z.modelID)}catch{}if(z.variant!==void 0){try{De.setCurrentVariant(z.variant)}catch{}try{_o.getState().saveAgentModelVariantForSession(z.sessionId,z.agentName,z.providerID,z.modelID,z.variant)}catch{}}}},[]),le=Ve.useCallback(async z=>{if(!m||!a)return;const De=jt.getState(),Qe=tc.getState().lastUsedProvider,tt=Q(),et=tt?.providerID||De.currentProviderId||Qe?.providerID,We=tt?.modelID||De.currentModelId||Qe?.modelID,at=Ce()||De.currentAgentName||void 0;if(!et||!We){K.error(r("session.newWorktree.error.noModelSelected"));return}const qe=ce(et,We);if(ve({sessionId:z.sessionId,providerID:et,modelID:We,agentName:at,variant:qe}),z.issue){if(!a.issueGet||!a.issueComments)return;const nt=await a.issueGet(m,z.issue.number);if(nt.connected===!1||!nt.repo||!nt.issue)throw new Error("Failed to load issue context");const Ze=await a.issueComments(m,z.issue.number);if(Ze.connected===!1)throw new Error("Failed to load issue comments");const ze=await Cn("github.issue.review.visible",{issue_number:String(z.issue.number)}),rt=await Cn("github.issue.review.instructions"),Ge=sP({repo:nt.repo,issue:nt.issue,comments:Ze.comments??[]});await rn.sendMessage({id:z.sessionId,providerID:et,modelID:We,agent:at,variant:qe,text:ze,additionalParts:[{text:rt,synthetic:!0},{text:Ge,synthetic:!0}]}),K.success(r("session.newWorktree.toast.sessionFromIssue"));return}if(z.pr){if(!a.prContext)return;const nt=await a.prContext(m,z.pr.number,{includeDiff:z.includeDiff,includeCheckDetails:!1});if(nt.connected===!1||!nt.repo||!nt.pr)throw new Error("Failed to load PR context");const Ze=await Cn("github.pr.review.visible",{pr_number:String(z.pr.number)}),ze=await Cn("github.pr.review.instructions"),rt=nP(nt);await rn.sendMessage({id:z.sessionId,providerID:et,modelID:We,agent:at,variant:qe,text:Ze,additionalParts:[{text:ze,synthetic:!0},{text:rt,synthetic:!0}]}),K.success(r("session.newWorktree.toast.sessionFromPr"))}},[ve,a,m,Ce,Q,ce,r]),Ae=p==="new-branch"?g:x;Ve.useEffect(()=>{if(!j?.all||!m||g.sourceBranch)return;(async()=>{try{const De=await Po(m).catch(()=>null),Qe=localStorage.getItem(If),tt=Qe&&j.all?.includes(Qe)?Qe:De&&j.all?.includes(De)?De:j.all?.includes("main")?"main":j.all?.includes("master")?"master":j.all?.[0]||"";tt&&y(et=>({...et,sourceBranch:tt}))}catch{}})()},[j,m,g.sourceBranch]),Ve.useEffect(()=>{if(!t)return;b("new-branch"),h({selectedBranch:"",worktreeName:""}),M(!1),F(!1),V(!1),O(!1),G(""),H(""),Y({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const z=E();y({branchName:z,worktreeName:z,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[t,E]),Ve.useEffect(()=>{if(p!=="new-branch"||!g.isSyncingWorktreeName)return;const z=no(g.branchName),De=_n(z);y(Qe=>({...Qe,worktreeName:De}))},[p,g.branchName,g.isSyncingWorktreeName]);const Te=Ve.useCallback(async()=>{if(!u||!me.touched||Se)return;ke&&ke.abort();const z=new AbortController;Fe(z),Y(De=>({...De,isValidating:!0}));try{const De=p==="new-branch"?g.branchName:x.selectedBranch,Qe=Ae.worktreeName,tt=no(De),et=_n(Qe);let We=null,at=null;if(tt||(We=r("session.newWorktree.error.branchNameRequired")),et||(at=r("session.newWorktree.error.worktreeDirectoryRequired")),tt&&et){const qe=p==="new-branch"?g.linkedPr:null,nt=qe?Pf(qe,k,w):null,Ze=await Oh(u,{mode:p==="existing-branch"||nt?"existing":"new",branchName:tt,worktreeName:et,existingBranch:nt?.existingBranch??(p==="existing-branch"?tt:void 0),...nt?.ensureRemoteName?{ensureRemoteName:nt.ensureRemoteName}:{},...nt?.ensureRemoteUrl?{ensureRemoteUrl:nt.ensureRemoteUrl}:{}});if(z.signal.aborted)return;Ze.ok||Ze.errors.forEach(ze=>{if(ze.code==="worktree_exists"){at=at??ze.message;return}ze.code.startsWith("branch_")&&(We=We??ze.message)})}z.signal.aborted||Y(qe=>({...qe,isValidating:!1,branchError:We,worktreeError:at}))}catch{z.signal.aborted||Y(De=>({...De,isValidating:!1}))}},[u,p,g.branchName,g.linkedPr,x.selectedBranch,Ae.worktreeName,k,w,me.touched,ke,Se,r]),$e=p==="new-branch"?g.branchName:x.selectedBranch;Ve.useEffect(()=>{if(!t||!u||!me.touched||Se)return;const z=setTimeout(()=>{Te()},300);return()=>clearTimeout(z)},[Ae.worktreeName,$e,t,u,Te,me.touched,Se]);const ye=async()=>{if(!u||!m){K.error(r("session.newWorktree.error.noActiveProject"));return}Y(et=>({...et,touched:!0}));const z=p==="new-branch"?g.branchName:x.selectedBranch,De=Ae.worktreeName,Qe=no(z),tt=_n(De);if(!Qe){K.error(r("session.newWorktree.error.branchNameRequired"));return}if(!tt){K.error(r("session.newWorktree.error.worktreeDirectoryRequired"));return}ke&&(ke.abort(),Fe(null)),Y(et=>({...et,isValidating:!1,branchError:null,worktreeError:null})),we(!0);try{const et=await cu(u),We=p==="new-branch"?g.linkedPr:null,at=g.sourceBranch;let qe="";const nt=(()=>{if(We){const Me=Pf(We,k,w);return qe=Me.sourceLabel,{preferredName:Qe||tt,mode:"existing",branchName:Qe,worktreeName:tt,existingBranch:Me.existingBranch,setupCommands:et,setUpstream:Me.setUpstream,upstreamRemote:Me.upstreamRemote,upstreamBranch:Me.upstreamBranch,...Me.ensureRemoteName?{ensureRemoteName:Me.ensureRemoteName}:{},...Me.ensureRemoteUrl?{ensureRemoteUrl:Me.ensureRemoteUrl}:{}}}return qe=p==="new-branch"?at:"",{preferredName:Qe||tt,mode:p==="existing-branch"?"existing":"new",branchName:p==="existing-branch"?void 0:Qe,worktreeName:tt,existingBranch:p==="existing-branch"?Qe:void 0,setupCommands:et,...at&&p==="new-branch"?{startRef:at}:{}}})(),Ze=await tv(m,nt),ze=await sv(u,Ze),rt=p==="new-branch"?g.linkedIssue:null,Ge=p==="new-branch"?g.linkedPr:null,ct=p==="new-branch"?g.includePrDiff:!1;let Pe=null;if(rt||Ge){const Me=rt?`#${rt.number} ${rt.title}`.trim():Ge?`#${Ge.number} ${Ge.title}`.trim():r("session.newWorktree.newSessionTitle"),Ue=await nv(Me,ze.path,null);if(!Ue?.id)throw new Error("Failed to create session");Pe=Ue.id,rv(Ue.id,Me).catch(()=>{});try{Lt.getState().initializeNewOpenChamberSession(Ue.id,jt.getState().agents)}catch{}}g.sourceBranch&&p==="new-branch"&&!g.linkedPr&&localStorage.setItem(If,g.sourceBranch),K.success(r("session.newWorktree.toast.worktreeCreated"),{description:r("session.newWorktree.toast.worktreeCreatedDescription",{target:`${ze.branch||ze.name}${qe?` ${r("session.newWorktree.fromSource",{source:qe})}`:""}`})}),e(!1),Pe?(n?.(ze.path,{sessionId:Pe}),le({sessionId:Pe,issue:rt,pr:Ge,includeDiff:ct}).catch(Me=>{const Ue=Me instanceof Error?Me.message:r("session.newWorktree.error.sendGitHubContextFailed");K.error(r("session.newWorktree.error.sendGitHubContextFailed"),{description:Ue})})):n?.(ze.path)}catch(et){const We=et instanceof Error?et.message:r("session.newWorktree.error.createWorktreeFailed");K.error(r("session.newWorktree.error.createWorktreeFailed"),{description:We})}finally{we(!1)}},q=z=>{b(z),Y(De=>({...De,touched:!1,branchError:null,worktreeError:null}))},L=z=>{if(!z){y(De=>({...De,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(z.type==="issue"){const De=z.item,Qe=`issue-${De.number}-${jc()}`;y(tt=>({...tt,linkedIssue:De,linkedPr:null,includePrDiff:!1,branchName:Qe,worktreeName:_n(Qe),isSyncingWorktreeName:!0}))}else if(z.type==="pr"){const De=z.item;y(Qe=>({...Qe,linkedPr:De,linkedIssue:null,includePrDiff:z.includeDiff??!1,branchName:De.head,worktreeName:_n(De.head),isSyncingWorktreeName:!0}))}},U=d&&c?.connected===!0,Ee=(p==="existing-branch"?!!x.selectedBranch&&!!x.worktreeName&&!me.branchError&&!me.worktreeError:!!no(g.branchName)&&!!g.worktreeName&&!me.branchError&&!me.worktreeError)&&!Se,Oe=()=>{y(z=>({...z,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},Ie=s.jsxs("div",{className:ge("flex gap-2",l?"flex-col w-full":"flex-row items-center"),children:[s.jsx("div",{className:ge("flex items-center gap-1.5 text-destructive",l?"w-full justify-center order-first":"mr-auto"),children:me.touched&&(me.branchError||me.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:me.branchError||me.worktreeError})]})}),s.jsxs("div",{className:ge("flex gap-2",l&&"w-full"),children:[s.jsx(he,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Se,className:ge(l&&"flex-1"),children:r("session.newWorktree.actions.cancel")}),s.jsxs(he,{size:"sm",onClick:ye,disabled:!Ee||Se,className:ge("gap-1.5",l&&"flex-1"),children:[Se&&s.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(Se?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return s.jsxs(s.Fragment,{children:[l?s.jsxs(Ur,{open:t,title:r("session.newWorktree.title"),onClose:()=>e(!1),footer:Ie,children:[s.jsx("div",{className:"w-full mb-4",children:s.jsx(Fr,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(A,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:p,onSelect:z=>q(z),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),s.jsxs("div",{className:"space-y-6",children:[p==="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(he,{variant:"outline",size:"sm",onClick:()=>V(!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(A,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(he,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:Z,disabled:!xe||v,title:r("session.newWorktree.fetchBranches"),children:v?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"refresh",className:"size-4"})})]}),s.jsx(Ur,{open:_,title:r("session.newWorktree.selectBranch"),onClose:()=>V(!1),children:s.jsxs("div",{className:"space-y-4",ref:ue,children:[s.jsx($t,{value:B,onChange:z=>G(z.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),v?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):k.length===0&&w.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:[Ne&&ie&&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:fe.matching.map(z=>s.jsx("button",{onClick:()=>{h(De=>({...De,selectedBranch:z.value,worktreeName:_n(z.label)})),Y(De=>({...De,touched:!0})),V(!1)},className:ge("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===z.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z.label})},`${z.source}-${z.value}`))})]}),Ne&&!ie&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),fe.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(Ne?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:fe.otherLocal.map(z=>s.jsx("button",{onClick:()=>{h(De=>({...De,selectedBranch:z,worktreeName:_n(z)})),Y(De=>({...De,touched:!0})),V(!1)},className:ge("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===z?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z})},z))})]}),fe.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(Ne?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:fe.otherRemote.map(z=>s.jsx("button",{onClick:()=>{h(De=>({...De,selectedBranch:`remotes/${z}`,worktreeName:_n(z)})),Y(De=>({...De,touched:!0})),V(!1)},className:ge("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===`remotes/${z}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z})},`remotes/${z}`))})]})]})]})})]}):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")}),p==="new-branch"&&U&&s.jsxs(he,{variant:"outline",size:"sm",onClick:()=>T(!0),className:"gap-1.5 h-7",children:[s.jsx(A,{name:"github",className:"size-4 text-status-success"}),g.linkedIssue||g.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx($t,{value:g.branchName,onChange:z=>{y(De=>({...De,branchName:z.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>Y(z=>({...z,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!g.linkedPr,className:ge("h-8",me.touched&&me.branchError&&"border-destructive",g.linkedPr&&"bg-muted text-muted-foreground")}),g.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:g.linkedPr.head})})]}),g.linkedIssue&&!g.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:g.linkedIssue.number,title:g.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")}),p!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const z=_n(p==="new-branch"?g.branchName:"");y(De=>({...De,worktreeName:z,isSyncingWorktreeName:!0}))},disabled:!g.branchName||g.worktreeName===_n(g.branchName),className:ge("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",g.worktreeName===_n(g.branchName)||!g.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(A,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx($t,{value:Ae.worktreeName,onChange:z=>{p==="new-branch"?y(De=>({...De,worktreeName:z.target.value,isSyncingWorktreeName:!1})):h(De=>({...De,worktreeName:z.target.value}))},onBlur:()=>Y(z=>({...z,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:ge("h-8",me.touched&&me.worktreeError&&"border-destructive")})]}),p==="new-branch"&&!g.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(he,{variant:"outline",size:"sm",onClick:()=>O(!0),className:"w-full justify-between h-9",children:[s.jsx("span",{className:g.sourceBranch?"text-foreground":"text-muted-foreground",children:g.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(A,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),g.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:g.sourceBranch})}),s.jsx(Ur,{open:$,title:r("session.newWorktree.selectSourceBranch"),onClose:()=>O(!1),children:s.jsxs("div",{className:"space-y-4",ref:de,children:[s.jsx($t,{value:R,onChange:z=>H(z.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),v?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):k.length===0&&w.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:[se&&ae&&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:be.matching.map(z=>s.jsx("button",{onClick:()=>{y(De=>({...De,sourceBranch:z.value})),O(!1)},className:ge("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.sourceBranch===z.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z.label})},`${z.source}-${z.value}`))})]}),se&&!ae&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),be.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(se?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:be.otherLocal.map(z=>s.jsx("button",{onClick:()=>{y(De=>({...De,sourceBranch:z})),O(!1)},className:ge("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.sourceBranch===z?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z})},z))})]}),be.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(se?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:be.otherRemote.map(z=>s.jsx("button",{onClick:()=>{y(De=>({...De,sourceBranch:`remotes/${z}`})),O(!1)},className:ge("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.sourceBranch===`remotes/${z}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z})},`remotes/${z}`))})]})]})]})})]}),(g.linkedIssue||g.linkedPr)&&p==="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(A,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),g.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:g.linkedIssue.number})}),g.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:g.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:g.linkedIssue?.title||g.linkedPr?.title}),s.jsx("a",{href:g.linkedIssue?.url||g.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:z=>z.stopPropagation(),children:s.jsx(A,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:Oe,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]}),g.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:[g.linkedPr.head," → ",g.linkedPr.base]}),g.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(ls,{open:t,onOpenChange:e,children:s.jsxs(os,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[s.jsx(ps,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(ds,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(A,{name:"git-branch",className:"h-5 w-5"}),r("session.newWorktree.title")]}),s.jsx("div",{className:"w-[280px] shrink-0",children:s.jsx(Fr,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(A,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:p,onSelect:z=>q(z),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),s.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[p==="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(As,{open:S,onOpenChange:M,children:[s.jsx(Is,{asChild:!0,children:s.jsxs(he,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:ge("truncate",x.selectedBranch?"text-foreground":"text-muted-foreground"),children:x.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(Ps,{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:J,children:s.jsxs(Ya,{shouldFilter:!1,children:[s.jsx(Sa,{placeholder:r("session.newWorktree.searchBranches"),value:B,onValueChange:G,onKeyDown:pe}),s.jsx(Qa,{disableHorizontal:!0,children:v?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):k.length===0&&w.length===0?s.jsx(Xa,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[Ne&&ie&&s.jsx(Vn,{heading:r("session.newWorktree.matchingBranches"),children:fe.matching.map(z=>s.jsx(En,{value:z.value,onSelect:()=>{h(De=>({...De,selectedBranch:z.value,worktreeName:_n(z.label)})),Y(De=>({...De,touched:!0})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z.label})},`${z.source}-${z.value}`))}),Ne&&!ie&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),fe.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[Ne&&s.jsx(Va,{}),s.jsx(Vn,{heading:r(Ne?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:fe.otherLocal.map(z=>s.jsx(En,{value:z,onSelect:()=>{h(De=>({...De,selectedBranch:z,worktreeName:_n(z)})),Y(De=>({...De,touched:!0})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z})},`local-${z}`))})]}),fe.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(fe.otherLocal.length>0||Ne)&&s.jsx(Va,{}),s.jsx(Vn,{heading:r(Ne?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:fe.otherRemote.map(z=>s.jsx(En,{value:`remotes/${z}`,onSelect:()=>{h(De=>({...De,selectedBranch:`remotes/${z}`,worktreeName:_n(z)})),Y(De=>({...De,touched:!0})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z})},`remote-${z}`))})]})]})})]})})]}),s.jsx(he,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:Z,disabled:!xe||v,title:r("session.newWorktree.fetchBranches"),children:v?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{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")}),p==="new-branch"&&U&&s.jsxs(he,{variant:"outline",size:"sm",onClick:()=>T(!0),className:"gap-1.5 h-7",children:[s.jsx(A,{name:"github",className:"size-4 text-status-success"}),g.linkedIssue||g.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx($t,{value:g.branchName,onChange:z=>{y(De=>({...De,branchName:z.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>Y(z=>({...z,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!g.linkedPr,className:ge("h-8",me.touched&&me.branchError&&"border-destructive",g.linkedPr&&"bg-muted text-muted-foreground")}),g.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:g.linkedPr.head})})]}),g.linkedIssue&&!g.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:g.linkedIssue.number,title:g.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")}),p!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const z=_n(p==="new-branch"?g.branchName:"");y(De=>({...De,worktreeName:z,isSyncingWorktreeName:!0}))},disabled:!g.branchName||g.worktreeName===_n(g.branchName),className:ge("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",g.worktreeName===_n(g.branchName)||!g.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(A,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx($t,{value:Ae.worktreeName,onChange:z=>{p==="new-branch"?y(De=>({...De,worktreeName:z.target.value,isSyncingWorktreeName:!1})):h(De=>({...De,worktreeName:z.target.value}))},onBlur:()=>Y(z=>({...z,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:ge("h-8",me.touched&&me.worktreeError&&"border-destructive")})]}),p==="new-branch"&&!g.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(As,{open:D,onOpenChange:F,children:[s.jsx(Is,{asChild:!0,children:s.jsxs(he,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:ge("truncate",g.sourceBranch?"text-foreground":"text-muted-foreground"),children:g.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(Ps,{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:ne,children:s.jsxs(Ya,{shouldFilter:!1,children:[s.jsx(Sa,{placeholder:r("session.newWorktree.searchBranches"),value:R,onValueChange:H,onKeyDown:pe}),s.jsx(Qa,{disableHorizontal:!0,children:v?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):k.length===0&&w.length===0?s.jsx(Xa,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[se&&ae&&s.jsx(Vn,{heading:r("session.newWorktree.matchingBranches"),children:be.matching.map(z=>s.jsx(En,{value:z.value,onSelect:()=>{y(De=>({...De,sourceBranch:z.value})),F(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z.label})},`${z.source}-${z.value}`))}),se&&!ae&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),be.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[se&&s.jsx(Va,{}),s.jsx(Vn,{heading:r(se?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:be.otherLocal.map(z=>s.jsx(En,{value:z,onSelect:()=>{y(De=>({...De,sourceBranch:z})),F(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z})},`local-${z}`))})]}),be.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(be.otherLocal.length>0||se)&&s.jsx(Va,{}),s.jsx(Vn,{heading:r(se?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:be.otherRemote.map(z=>s.jsx(En,{value:`remotes/${z}`,onSelect:()=>{y(De=>({...De,sourceBranch:`remotes/${z}`})),F(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z})},`remote-${z}`))})]})]})})]})})]}),g.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:g.sourceBranch})})]}),(g.linkedIssue||g.linkedPr)&&p==="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(A,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),g.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:g.linkedIssue.number})}),g.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:g.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:g.linkedIssue?.title||g.linkedPr?.title}),s.jsx("a",{href:g.linkedIssue?.url||g.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:z=>z.stopPropagation(),children:s.jsx(A,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:Oe,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]}),g.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:[g.linkedPr.head," → ",g.linkedPr.base]}),g.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(Rs,{className:"mt-1 flex items-center justify-between",children:[s.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:me.touched&&(me.branchError||me.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:me.branchError||me.worktreeError})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(he,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Se,children:r("session.newWorktree.actions.cancel")}),s.jsxs(he,{size:"sm",onClick:ye,disabled:!Ee||Se,className:"gap-1.5",children:[Se&&s.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(Se?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),s.jsx(eP,{open:P,onOpenChange:T,onSelect:L})]})}let ji=null,Ni=null,kl=null,Jl=0;const Ha=new Set,aP=3e4,iP=45e3,rx=()=>{kl&&(clearTimeout(kl),kl=null)},ax=()=>{if(Ni||Ha.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(Jl,5)),aP);Ni=setTimeout(()=>{Ni=null,Jl+=1,ix()},t)},Yl=()=>{rx(),ji&&ji.close(),ji=null},Af=()=>{rx(),Ha.size!==0&&(kl=setTimeout(()=>{Yl(),ax()},iP))},oP=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}},lP=t=>{if(t.type==="openchamber:event-stream-ready"){Jl=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,l=i==="running"||i==="error"?i:"success";if(!n||!r)return;const c={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:a,status:l,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of Ha)d(c)},ix=()=>{if(typeof window>"u"||Ha.size===0||typeof EventSource!="function"||ji&&ji.readyState!==EventSource.CLOSED)return;Yl();const t=new EventSource("/api/openchamber/events");t.onopen=()=>{Af()},t.onmessage=e=>{Af();const n=oP(e.data);n&&lP(n)},t.onerror=()=>{Yl(),ax()},ji=t},ox=t=>(Ha.add(t),ix(),()=>{Ha.delete(t),Ha.size===0&&(Ni&&(clearTimeout(Ni),Ni=null),Jl=0,Yl())}),mc=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},Ri=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},cP=async t=>{const e=Ri(t),n=await fetch(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await mc(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},Df=async(t,e)=>{const n=Ri(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 mc(r,"Failed to save scheduled task"));const a=await r.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},dP=async(t,e)=>{const n=Ri(t),r=Ri(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 mc(a,"Failed to delete scheduled task"));const i=await a.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},uP=async(t,e)=>{const n=Ri(t),r=Ri(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 mc(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}},lx=[0,1,2,3,4,5,6],Tf=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"],Ef=()=>{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}`},Cl=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},Mf=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},mP=(t,e,n)=>{const r=Cl(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},Rf=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),pP=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),l=(new Date(n,r,1).getDay()-e+7)%7,c=new Date(n,r+1,0).getDate(),d=new Date(n,r,0).getDate(),f=[];for(let m=0;m<42;m+=1){const u=m-l+1;if(u<=0){const p=d+u;f.push({date:new Date(n,r-1,p),inCurrentMonth:!1});continue}if(u>c){f.push({date:new Date(n,r+1,u-c),inCurrentMonth:!1});continue}f.push({date:new Date(n,r,u),inCurrentMonth:!0})}return f},fP=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}},Ea=(t,e,n)=>{const r=Number(t),a=Number(e),i=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,l=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(l).padStart(2,"0")}`},Oi=(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"},Ff=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:Oi(t,{min:1,max:12}),sl=t=>/^[0-5][0-9]$/.test(t)?t:Oi(t,{max:59}),hP=(t,e)=>Oi(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),Lf=(t,e)=>Oi(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),gP=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}},xP=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}},bP=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return lx.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},yP=(t,e)=>[...t.slice(e),...t.slice(0,e)],Dr=t=>{const e=ot.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 l;return e[2]!==a||e[3]!==n||e[4]!==i?(l=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]=l):l=e[5],l},Of=t=>{const e=ot.c(84),{value:n,onChange:r,use24Hour:a,hourAriaLabel:i,minuteAriaLabel:l,periodAriaLabel:c,amLabel:d,pmLabel:f}=t;let m;e[0]!==n?(m=fP(n),e[0]=n,e[1]=m):m=e[1];const u=m,p=Ve.useRef(null),b=Ve.useRef(null),[g,y]=Ve.useState(null),[x,h]=Ve.useState(null),j=Ve.useRef(null),v=Ve.useRef(null);let C;e[2]===Symbol.for("react.memo_cache_sentinel")?(C=Y=>{j.current=Y,y(Y)},e[2]=C):C=e[2];const k=C;let w;e[3]===Symbol.for("react.memo_cache_sentinel")?(w=Y=>{v.current=Y,h(Y)},e[3]=w):w=e[3];const N=w,I=kP,E=CP,P=IP;let T;e[4]!==r||e[5]!==u.meridiem||e[6]!==u.minute||e[7]!==a?(T=Y=>{const Se=Y.replace(/\D/g,"").slice(0,2);k(Se),Se.length===2&&(r(a?P(I(Se),u.minute):Ea(Ff(Se),u.minute,u.meridiem)),k(null),b.current?.focus())},e[4]=r,e[5]=u.meridiem,e[6]=u.minute,e[7]=a,e[8]=T):T=e[8];const S=T;let M;e[9]!==r||e[10]!==u.meridiem||e[11]!==u.minute||e[12]!==a?(M=()=>{const Y=j.current;if(Y!==null&&(k(null),Y.length!==0)){if(a){r(P(I(Y.padStart(2,"0")),u.minute));return}r(Ea(Ff(Y.padStart(2,"0")),u.minute,u.meridiem))}},e[9]=r,e[10]=u.meridiem,e[11]=u.minute,e[12]=a,e[13]=M):M=e[13];const D=M;let F;e[14]!==r||e[15]!==u.hour12||e[16]!==u.hour24||e[17]!==u.meridiem||e[18]!==a?(F=Y=>{const Se=Y.replace(/\D/g,"").slice(0,2);N(Se),Se.length===2&&(r(a?P(u.hour24,sl(Se)):Ea(u.hour12,sl(Se),u.meridiem)),N(null))},e[14]=r,e[15]=u.hour12,e[16]=u.hour24,e[17]=u.meridiem,e[18]=a,e[19]=F):F=e[19];const _=F;let V;e[20]!==r||e[21]!==u.hour12||e[22]!==u.hour24||e[23]!==u.meridiem||e[24]!==a?(V=()=>{const Y=v.current;Y!==null&&(N(null),Y.length!==0&&r(a?P(u.hour24,sl(Y.padStart(2,"0"))):Ea(u.hour12,sl(Y.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]=V):V=e[25];const $=V;let O;e[26]!==r||e[27]!==u.hour12||e[28]!==u.hour24||e[29]!==u.meridiem||e[30]!==u.minute||e[31]!==a?(O=Y=>r(a?P(E(u.hour24,Y),u.minute):Ea(hP(u.hour12,Y),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]=O):O=e[32];const B=O;let G;e[33]!==r||e[34]!==u.hour12||e[35]!==u.hour24||e[36]!==u.meridiem||e[37]!==u.minute||e[38]!==a?(G=Y=>r(a?P(u.hour24,Lf(u.minute,Y)):Ea(u.hour12,Lf(u.minute,Y),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]=G):G=e[39];const R=G;let H;e[40]!==r||e[41]!==u.hour12||e[42]!==u.meridiem||e[43]!==u.minute?(H=Y=>{Y!==u.meridiem&&r(Ea(u.hour12,u.minute,Y))},e[40]=r,e[41]=u.hour12,e[42]=u.meridiem,e[43]=u.minute,e[44]=H):H=e[44];const J=H;let ne;e[45]!==D||e[46]!==B?(ne=Y=>{if(Y.key==="ArrowRight"){Y.preventDefault(),D(),b.current?.focus();return}(Y.key==="ArrowUp"||Y.key==="ArrowDown")&&(Y.preventDefault(),k(null),B(Y.key==="ArrowUp"?1:-1))},e[45]=D,e[46]=B,e[47]=ne):ne=e[47];const ue=ne;let de;e[48]!==$||e[49]!==R?(de=Y=>{if(Y.key==="ArrowLeft"&&(Y.currentTarget.selectionStart??0)===0){Y.preventDefault(),$(),p.current?.focus();return}(Y.key==="ArrowUp"||Y.key==="ArrowDown")&&(Y.preventDefault(),N(null),R(Y.key==="ArrowUp"?1:-1))},e[48]=$,e[49]=R,e[50]=de):de=e[50];const pe=de,W=a?"px-2":"pl-2 pr-1";let te;e[51]!==W?(te=ge("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",W),e[51]=W,e[52]=te):te=e[52];const X=g??(a?u.hour24:u.hour12);let ee;e[53]!==S?(ee=Y=>S(Y.target.value),e[53]=S,e[54]=ee):ee=e[54];let fe;e[55]===Symbol.for("react.memo_cache_sentinel")?(fe=()=>k(""),e[55]=fe):fe=e[55];let be;e[56]!==D||e[57]!==i||e[58]!==ue||e[59]!==X||e[60]!==ee?(be=s.jsx("input",{ref:p,inputMode:"numeric",value:X,onChange:ee,onKeyDown:ue,onFocus:fe,onBlur:D,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]=D,e[57]=i,e[58]=ue,e[59]=X,e[60]=ee,e[61]=be):be=e[61];let Ne;e[62]===Symbol.for("react.memo_cache_sentinel")?(Ne=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=Ne):Ne=e[62];const se=x??u.minute;let ie;e[63]!==_?(ie=Y=>_(Y.target.value),e[63]=_,e[64]=ie):ie=e[64];let ae;e[65]===Symbol.for("react.memo_cache_sentinel")?(ae=()=>N(""),e[65]=ae):ae=e[65];let xe;e[66]!==$||e[67]!==l||e[68]!==pe||e[69]!==se||e[70]!==ie?(xe=s.jsx("input",{ref:b,inputMode:"numeric",value:se,onChange:ie,onKeyDown:pe,onFocus:ae,onBlur:$,maxLength:2,"aria-label":l,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]=$,e[67]=l,e[68]=pe,e[69]=se,e[70]=ie,e[71]=xe):xe=e[71];let Z;e[72]!==d||e[73]!==u.meridiem||e[74]!==c||e[75]!==f||e[76]!==J||e[77]!==a?(Z=a?null:s.jsxs(ns,{value:u.meridiem,onValueChange:Y=>J(Y),children:[s.jsx(rs,{"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(ms,{})}),s.jsxs(as,{children:[s.jsx(Rt,{value:"AM",children:d}),s.jsx(Rt,{value:"PM",children:f})]})]}),e[72]=d,e[73]=u.meridiem,e[74]=c,e[75]=f,e[76]=J,e[77]=a,e[78]=Z):Z=e[78];let me;return e[79]!==te||e[80]!==be||e[81]!==xe||e[82]!==Z?(me=s.jsxs("div",{className:te,children:[be,Ne,xe,Z]}),e[79]=te,e[80]=be,e[81]=xe,e[82]=Z,e[83]=me):me=e[83],me},$f=t=>new Date(t.getFullYear(),t.getMonth(),1),vP=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},_f=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),wP=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"]},Bf=(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:wP(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:Ef(),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:Ef(),onceTime:"09:00",weekdays:[1],timezone:n},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent}}},jP=(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")},NP=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 SP(t){const{open:e,task:n,onOpenChange:r,onSave:a}=t,{t:i,locale:l}=pt(),c=jt(U=>U.loadProviders),d=jt(U=>U.loadAgents),f=jt(U=>U.providers),m=jt(U=>U.currentProviderId),u=jt(U=>U.currentModelId),p=jt(U=>U.currentVariant||""),b=jt(U=>U.currentAgentName||""),g=_e(U=>U.timeFormatPreference),y=_e(U=>U.weekStartPreference),x=_e(U=>U.isMobile),[h,j]=Ve.useState(()=>Bf(n,{providerID:m,modelID:u,variant:p,agent:b})),[v,C]=Ve.useState(!1),[k,w]=Ve.useState(!1),[N,I]=Ve.useState(!1),[E,P]=Ve.useState(""),[T,S]=Ve.useState(!1),[M,D]=Ve.useState(""),[F,_]=Ve.useState(!1),[V,$]=Ve.useState(""),[O,B]=Ve.useState(()=>{const U=Cl(n?.schedule?.date||"")||new Date;return new Date(U.getFullYear(),U.getMonth(),1)}),G=Ve.useRef(null),R=Ve.useRef(null),H=Ve.useRef(null),J=Ve.useRef(null),ne=Ve.useRef(null),ue=Ve.useMemo(()=>xP(l),[l]),de=Ve.useMemo(()=>gP(l),[l]),pe=Ve.useMemo(()=>g==="24h"?!0:g==="12h"?!1:ue,[g,ue]),W=Ve.useMemo(()=>y==="sunday"?0:y==="monday"?1:de,[y,de]),te=Ve.useMemo(()=>{const U=bP(l);return yP(lx.map(oe=>({value:oe,label:U[oe]||""})),W)},[l,W]);Ve.useEffect(()=>{e&&(c(),d())},[e,c,d]),Ve.useEffect(()=>{if(!e)return;j(Bf(n,{providerID:m,modelID:u,variant:p,agent:b}));const U=Cl(n?.schedule?.date||"")||new Date;B(new Date(U.getFullYear(),U.getMonth(),1)),w(!1),S(!1),I(!1),D(""),P("")},[e,n,m,u,p,b]),Ve.useEffect(()=>{if(!k)return;const U=oe=>{G.current&&!G.current.contains(oe.target)&&w(!1)};return document.addEventListener("mousedown",U),()=>{document.removeEventListener("mousedown",U)}},[k]);const X=Ve.useMemo(()=>{const oe=f.find(Ee=>Ee.id===h.execution.providerID)?.models?.find(Ee=>Ee.id===h.execution.modelID);return oe?.variants?Object.keys(oe.variants):[]},[f,h.execution.providerID,h.execution.modelID]),ee=X.length>0,fe=Ve.useMemo(()=>!ee||!h.execution.variant?"__default":X.includes(h.execution.variant)?h.execution.variant:"__default",[h.execution.variant,ee,X]);Ve.useEffect(()=>{ee||!h.execution.variant||j(U=>({...U,execution:{...U.execution,variant:""}}))},[ee,h.execution.variant]);const be=Ve.useCallback((U,oe)=>{j(Ee=>{const Oe=new Set(Ee.schedule.weekdays);return oe?Oe.add(U):Oe.delete(U),{...Ee,schedule:{...Ee.schedule,weekdays:Array.from(Oe).sort((Ie,z)=>Ie-z)}}})},[]),Ne=Ve.useCallback((U,oe)=>{j(Ee=>{const Oe=Ee.schedule.times.slice();return Oe[U]=oe,{...Ee,schedule:{...Ee.schedule,times:Oe}}})},[]),se=Ve.useCallback(U=>{j(oe=>{const Ee=oe.schedule.times.filter((Oe,Ie)=>Ie!==U);return{...oe,schedule:{...oe.schedule,times:Ee.length>0?Ee:["09:00"]}}})},[]),ie=Ve.useCallback(()=>{j(U=>({...U,schedule:{...U.schedule,times:[...U.schedule.times,"12:00"]}}))},[]),ae=Ve.useMemo(()=>vP(),[]),xe=Ve.useMemo(()=>$f(ae),[ae]),Z=Ve.useMemo(()=>{const U=Cl(h.schedule.onceDate);return U?_f(U,ae)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(l,{weekday:"short"}).format(U):null},[h.schedule.onceDate,l,i,ae]),me=Ve.useMemo(()=>$f(O).getTime()<=xe.getTime(),[O,xe]),Y=Ve.useMemo(()=>te.map(U=>U.label),[te]),Se=Ve.useCallback(U=>{j(oe=>({...oe,schedule:{...oe.schedule,onceDate:U}}))},[]),we=Ve.useCallback((U,oe)=>{if(U.startsWith("/")){const z=U.indexOf(" "),De=U.indexOf(`
|
|
192
|
+
`),Qe=Math.min(z===-1?U.length:z,De===-1?U.length:De);if(oe<=Qe&&z===-1){D(U.substring(1,Qe)),S(!0),I(!1),_(!1);return}}S(!1);const Ee=U.substring(0,oe),Oe=Ee.lastIndexOf("#");if(Oe!==-1){const z=Oe>0?Ee[Oe-1]:null,De=Ee.substring(Oe+1);if((!z||/\s/.test(z))&&!De.includes(" ")&&!De.includes(`
|
|
193
|
+
`)){$(De),_(!0),I(!1);return}}_(!1);const Ie=Ee.lastIndexOf("@");if(Ie!==-1){const z=Ie>0?Ee[Ie-1]:null,De=Ee.substring(Ie+1);(!z||/\s/.test(z))&&!De.includes(" ")&&!De.includes(`
|
|
194
|
+
`)?(P(De),I(!0)):I(!1);return}I(!1)},[]),ke=Ve.useCallback(U=>{j(oe=>({...oe,execution:{...oe.execution,prompt:U}}))},[]),Fe=Ve.useCallback(U=>{const oe=h.execution.prompt,Oe=R.current?.selectionStart??oe.length,z=oe.substring(0,Oe).lastIndexOf("@"),De=U.relativePath&&U.relativePath.trim().length>0?U.relativePath.trim():U.path||U.name,Qe=z!==-1?z:Oe,tt=`${oe.substring(0,Qe)}@${De} ${oe.substring(Oe)}`,et=Qe+De.length+2;ke(tt),I(!1),P(""),requestAnimationFrame(()=>{const We=R.current;We&&(We.selectionStart=et,We.selectionEnd=et,We.focus()),we(tt,et)})},[h.execution.prompt,ke,we]),Ce=Ve.useCallback(U=>{const oe=h.execution.prompt,Oe=R.current?.selectionStart??oe.length,z=oe.substring(0,Oe).lastIndexOf("@"),De=z!==-1?z:Oe,Qe=`${oe.substring(0,De)}@${U} ${oe.substring(Oe)}`,tt=De+U.length+2;ke(Qe),I(!1),P(""),requestAnimationFrame(()=>{const et=R.current;et&&(et.selectionStart=tt,et.selectionEnd=tt,et.focus()),we(Qe,tt)})},[h.execution.prompt,ke,we]),Q=Ve.useCallback(U=>{const oe=`/${U.name} `;ke(oe),S(!1),D(""),_(!1),requestAnimationFrame(()=>{const Ee=R.current;Ee&&(Ee.focus(),Ee.selectionStart=Ee.value.length,Ee.selectionEnd=Ee.value.length),we(oe,oe.length)})},[ke,we]),ce=Ve.useCallback((U,oe)=>{const Ee=h.execution.prompt,Ie=R.current?.selectionStart??Ee.length,De=Ee.substring(0,Ie).lastIndexOf("#"),Qe=De!==-1?De:Ie,tt=`${Ee.substring(0,Qe)}#${oe} ${Ee.substring(Ie)}`,et=Qe+oe.length+2;ke(tt),_(!1),$(""),requestAnimationFrame(()=>{const We=R.current;We&&(We.selectionStart=et,We.selectionEnd=et,We.focus()),we(tt,et)})},[h.execution.prompt,ke,we]),ve=Ve.useCallback(U=>{if(T&&J.current&&(U.key==="Enter"||U.key==="ArrowUp"||U.key==="ArrowDown"||U.key==="Escape"||U.key==="Tab")){U.preventDefault(),J.current.handleKeyDown(U.key);return}N&&H.current&&(U.key==="Enter"||U.key==="ArrowUp"||U.key==="ArrowDown"||U.key==="Escape"||U.key==="Tab")&&(U.preventDefault(),H.current.handleKeyDown(U.key)),F&&ne.current&&(U.key==="Enter"||U.key==="ArrowUp"||U.key==="ArrowDown"||U.key==="Escape"||U.key==="Tab")&&(U.preventDefault(),ne.current.handleKeyDown(U.key))},[T,N,F]),le=Ve.useCallback(async()=>{const U=jP(h,i);if(U){K.error(U);return}const oe=NP(h.schedule.times),Ee={...h.id?{id:h.id}:{},name:h.name.trim(),enabled:h.enabled,schedule:{kind:h.schedule.kind,timezone:h.schedule.timezone.trim(),...h.schedule.kind==="once"?{date:h.schedule.onceDate,time:h.schedule.onceTime}:{times:oe,...h.schedule.kind==="weekly"?{weekdays:h.schedule.weekdays}:{}}},execution:{prompt:h.execution.prompt,providerID:h.execution.providerID,modelID:h.execution.modelID,...h.execution.variant.trim()?{variant:h.execution.variant.trim()}:{},...h.execution.agent.trim()?{agent:h.execution.agent.trim()}:{}},...h.state?{state:h.state}:{}};C(!0);try{await a(Ee),r(!1)}catch(Oe){K.error(Oe instanceof Error?Oe.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{C(!1)}},[h,r,a,i]),Ae=Ve.useId(),Te=Ve.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),$e=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),ye=i("sessions.scheduledTasks.editor.description"),q=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(Dr,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx($t,{id:"sched-name",value:h.name,onChange:U=>j(oe=>({...oe,name:U.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(Dr,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(ns,{value:h.schedule.kind,onValueChange:U=>{j(oe=>({...oe,schedule:{...oe.schedule,kind:U}}))},children:[s.jsx(rs,{className:"w-fit max-w-full",children:s.jsx(ms,{children:U=>i(U==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":U==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(as,{children:[s.jsx(Rt,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(Rt,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(Rt,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")})]})]})]})]}),h.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:G,children:[s.jsx(Dr,{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:()=>w(U=>!U),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(A,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:mP(h.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),l)})]}),s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),k?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:()=>B(U=>Rf(U,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:me,children:s.jsx(A,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(l,{month:"long",year:"numeric"}).format(O)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>B(U=>Rf(U,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:Y.map((U,oe)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:U},`${U}-${oe}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:pP(O,W).map(({date:U,inCurrentMonth:oe})=>{const Ee=Mf(U),Oe=Ee===h.schedule.onceDate,Ie=_f(U,ae),z=U.getTime()<ae.getTime(),De=Oe?"bg-interactive-selection text-interactive-selection-foreground":z?"text-muted-foreground/40":oe?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{z||(Se(Ee),w(!1))},disabled:z,className:["h-8 rounded-md typography-ui-label",De,Ie&&!Oe?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",z?"cursor-not-allowed opacity-45":""].join(" "),children:U.getDate()},Ee)})}),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:Z||""}),s.jsx(he,{type:"button",size:"xs",variant:"ghost",onClick:()=>{Se(Mf(ae)),B(new Date(ae.getFullYear(),ae.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(Dr,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(Of,{value:h.schedule.onceTime,use24Hour:pe,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:U=>j(oe=>({...oe,schedule:{...oe.schedule,onceTime:U}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(Dr,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(ns,{value:h.schedule.timezone,onValueChange:U=>{j(oe=>({...oe,schedule:{...oe.schedule,timezone:U}}))},children:[s.jsx(rs,{className:"w-fit max-w-full",children:s.jsx(ms,{})}),s.jsx(as,{children:Tf.map(U=>s.jsx(Rt,{value:U,children:U},U))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[h.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(Dr,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:te.map(U=>{const oe=h.schedule.weekdays.includes(U.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",oe?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(fs,{checked:oe,onChange:Ee=>be(U.value,Ee),ariaLabel:U.label}),s.jsx("button",{type:"button",onClick:()=>be(U.value,!oe),className:"group-hover:text-foreground",children:U.label})]},U.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(Dr,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:h.schedule.times.map((U,oe)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Of,{value:U,use24Hour:pe,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:Ee=>Ne(oe,Ee)}),h.schedule.times.length>1?s.jsx(he,{type:"button",size:"icon",variant:"ghost",onClick:()=>se(oe),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(A,{name:"close",className:"h-4 w-4"})}):null]},oe))}),s.jsx("div",{children:s.jsxs(he,{type:"button",size:"sm",variant:"outline",onClick:ie,children:[s.jsx(A,{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(Dr,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(ns,{value:h.schedule.timezone,onValueChange:U=>{j(oe=>({...oe,schedule:{...oe.schedule,timezone:U}}))},children:[s.jsx(rs,{className:"w-fit max-w-full",children:s.jsx(ms,{})}),s.jsx(as,{children:Tf.map(U=>s.jsx(Rt,{value:U,children:U},U))})]})]})]}),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(Dr,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(Eo,{providerId:h.execution.providerID,modelId:h.execution.modelID,onChange:(U,oe)=>{j(Ee=>({...Ee,execution:{...Ee.execution,providerID:U,modelID:oe,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Dr,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(ns,{value:fe,disabled:!ee,onValueChange:U=>{j(oe=>({...oe,execution:{...oe.execution,variant:U==="__default"?"":U}}))},children:[s.jsx(rs,{className:"w-fit max-w-full",children:s.jsx(ms,{children:U=>U==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):U})}),s.jsxs(as,{children:[s.jsx(Rt,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),X.map(U=>s.jsx(Rt,{value:U,children:U},U))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Dr,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(dc,{agentName:h.execution.agent,filter:U=>Sh(U.mode),onChange:U=>j(oe=>({...oe,execution:{...oe.execution,agent:U}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Dr,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(ln,{id:"sched-prompt",ref:R,value:h.execution.prompt,onChange:U=>{const oe=U.target.value;ke(oe);const Ee=U.target.selectionStart??oe.length;we(oe,Ee)},onKeyDown:ve,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),T?s.jsx(_h,{ref:J,searchQuery:M,onCommandSelect:Q,onClose:()=>S(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,N?s.jsx(Bh,{ref:H,searchQuery:E,onFileSelect:Fe,onAgentSelect:Ce,onClose:()=>I(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,F?s.jsx(Vh,{ref:ne,searchQuery:V,onSnippetSelect:ce,onClose:()=>_(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),L=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:h.enabled,onChange:U=>j(oe=>({...oe,enabled:U})),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(he,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:v,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(he,{type:"button",size:"sm",onClick:le,disabled:v,children:i(v?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return x?s.jsx(Ur,{open:e,title:$e,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:U=>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:$e}),U]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:ye})]}),footer:L,children:q}):s.jsx(ls,{open:e,onOpenChange:U=>{!U&&Te()||r(U)},children:s.jsxs(os,{"aria-describedby":Ae,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(ys,{id:Ae,className:"sr-only",children:ye}),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(ds,{className:"typography-ui-label font-medium text-foreground",children:$e}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:ye})]})}),s.jsx(Io,{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:q})}),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:L})})]})})}function kP(t){return Oi(t,{min:0,max:23})}function CP(t,e){return Oi(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function IP(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 PP=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))},AP=(t,e)=>{const n=PP(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||""})},DP=t=>!t||!Number.isFinite(t)?"":new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),Vf=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),a=6e4,i=60*a,l=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<l){const u=Math.floor(r/i),p=Math.round(r%i/a),b=p>0?`${u}h ${p}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/l),f=Math.round(r%l/i),m=f>0?`${d}d ${f}h`:`${d}d`;return c?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:m}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:m})},TP={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"}},EP=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function MP(){const{t}=pt(),e=_e(D=>D.isScheduledTasksDialogOpen),n=_e(D=>D.setScheduledTasksDialogOpen),r=_e(D=>D.isMobile),a=Ss(D=>D.projects),i=Ss(D=>D.getActiveProject()),l=Ms(D=>D.homeDirectory),{currentTheme:c}=Sr(),[d,f]=Ve.useState(""),[m,u]=Ve.useState([]),[p,b]=Ve.useState(!0),[g,y]=Ve.useState(!1),[x,h]=Ve.useState(null),[j,v]=Ve.useState(null),C=Ve.useMemo(()=>a.find(D=>D.id===d)||null,[a,d]),k=Ve.useCallback(D=>{const F=D.label?.trim()||Ja(D.path,l||void 0),_=Do({id:D.id,iconImage:D.iconImage??null},{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),V=D.icon?oc[D.icon]:null,$=D.color?To[D.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[_?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:D.iconBackground?{backgroundColor:D.iconBackground}:void 0,children:s.jsx("img",{src:_,alt:"",className:"h-full w-full object-contain",draggable:!1})}):V?s.jsx(A,{name:V,className:"h-3.5 w-3.5 shrink-0",style:$?{color:$}:void 0}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:$?{color:$}:void 0}),s.jsx("span",{className:"truncate",children:F})]})},[l,c.metadata.variant,c.colors.surface.foreground]),w=Ve.useCallback(async(D,F)=>{if(!D){u([]);return}F?.silent||b(!0);try{const _=await cP(D);_.sort((V,$)=>{if(V.enabled!==$.enabled)return V.enabled?-1:1;const O=V.name.localeCompare($.name);return O!==0?O:(V.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-($.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),u(_)}catch(_){K.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),F?.silent||u([])}finally{F?.silent||b(!1)}},[t]);Ve.useEffect(()=>{if(!e)return;const D=i?.id||a[0]?.id||"";f(D),D?w(D):(u([]),b(!1))},[e,i,a,w]),Ve.useEffect(()=>{if(!e)return;let D=null;const F=ox(_=>{_.type==="scheduled-task-ran"&&_.projectId===d&&(D&&clearTimeout(D),D=setTimeout(()=>{w(d,{silent:!0})},400))});return()=>{D&&clearTimeout(D),F()}},[e,d,w]);const N=Ve.useCallback(async D=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Df(d,D),await w(d),K.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,w,t]),I=Ve.useCallback(async(D,F)=>{if(d){v(D.id),u(_=>_.map(V=>V.id===D.id?{...V,enabled:F}:V));try{await Df(d,{...D,enabled:F}),await w(d,{silent:!0})}catch(_){K.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await w(d,{silent:!0})}finally{v(null)}}},[d,w,t]),E=Ve.useCallback(async D=>{if(!(!d||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:D.name})))){v(D.id);try{await dP(d,D.id),await w(d,{silent:!0}),K.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(_){K.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{v(null)}}},[d,w,t]),P=Ve.useCallback(async D=>{if(d){v(D.id);try{await uP(d,D.id),await Promise.all([w(d,{silent:!0}),xd()]),K.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(F){K.error(F instanceof Error?F.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{v(null)}}},[d,w,t]),T=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs(ns,{value:d||"__none",onValueChange:D=>{const F=D==="__none"?"":D;f(F),F?w(F):u([])},children:[s.jsx(rs,{className:r?"w-full":void 0,children:C?s.jsx(ms,{children:k(C)}):s.jsx(ms,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(as,{children:[a.length===0?s.jsx(Rt,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,a.map(D=>s.jsx(Rt,{value:D.id,children:k(D)},D.id))]})]})]}),S=()=>{h(null),y(!0)},M=s.jsxs("div",{className:"space-y-4",children:[r?T:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[T,s.jsxs(he,{onClick:S,disabled:!d,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})]}),s.jsx("div",{className:"min-h-[280px]",children:p?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(A,{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(D=>{const F=j===D.id,_=D.state?.lastStatus||"idle",V=TP[_],$=t(_==="success"?"sessions.scheduledTasks.dialog.status.success":_==="error"?"sessions.scheduledTasks.dialog.status.error":_==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),O=D.state?.nextRunAt,B=D.state?.lastRunAt;return s.jsxs("div",{className:ge("rounded-lg border border-border p-4 transition-opacity",!D.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:D.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:AP(D,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(A,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),O?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:Vf(O,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:DP(O)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(A,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),_==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):B?s.jsxs(s.Fragment,{children:[V.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${V.tone})`},children:[s.jsx(A,{name:V.Icon,className:"h-3.5 w-3.5"}),$]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:Vf(B,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),D.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:EP("error"),children:[s.jsx(A,{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:D.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:ge("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",D.enabled?"text-foreground":"text-muted-foreground",F&&"cursor-not-allowed opacity-50"),children:[s.jsx(fs,{checked:D.enabled,onChange:G=>{I(D,G)},ariaLabel:D.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:D.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:D.name}),disabled:F}),D.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(he,{variant:"outline",size:"sm",onClick:()=>{P(D)},disabled:F,children:[s.jsx(A,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(he,{variant:"outline",size:"sm",onClick:()=>{h(D),y(!0)},disabled:F,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:D.name}),children:[s.jsx(A,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(he,{variant:"destructive",size:"sm",onClick:()=>{E(D)},disabled:F,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:D.name}),children:s.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},D.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Ur,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:D=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),D]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(he,{className:"w-full",onClick:S,disabled:!d,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:M}):s.jsx(ls,{open:e,onOpenChange:n,children:s.jsxs(os,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(ys,{children:t("sessions.scheduledTasks.dialog.description")})]}),M]})}),s.jsx(SP,{open:g,task:x,onOpenChange:y,onSave:N})]})}const RP=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(c=>xs(c.path)??c.path).filter(c=>!!c)]),i=(c=>c.filter(d=>bo(d,t.normalizedPath,r)))(e.archivedSessions),l=e.sessions.filter(c=>c.time?.archived||xs(c.directory??null)?!1:bo(c,t.normalizedPath,r));return Ti([...i,...l])},FP=t=>{const e=ot.c(12),{normalizedProjects:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:l,isSessionsLoading:c,foldersMap:d,createFolder:f,addSessionToFolder:m,cleanupSessions:u}=t;let p,b;e[0]!==m||e[1]!==a||e[2]!==i||e[3]!==u||e[4]!==f||e[5]!==d||e[6]!==c||e[7]!==l||e[8]!==n||e[9]!==r?(p=()=>{c||n.forEach(g=>{const y=du(g.normalizedPath),x=RP(g,{sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:l}),h=new Set(x.map(LP)),j=d[y]??[],v=new Map(j.map(OP));x.forEach(C=>{const k=av(C,g.normalizedPath),w=k.toLowerCase();let N=v.get(w);N||(N=f(y,k),v.set(w,N)),N.sessionIds.includes(C.id)||m(y,N.id,C.id)}),u(y,h)})},b=[n,r,a,i,l,c,d,f,m,u],e[0]=m,e[1]=a,e[2]=i,e[3]=u,e[4]=f,e[5]=d,e[6]=c,e[7]=l,e[8]=n,e[9]=r,e[10]=p,e[11]=b):(p=e[10],b=e[11]),o.useEffect(p,b)};function LP(t){return t.id}function OP(t){return[t.name.toLowerCase(),t]}const $P=t=>{const e=ot.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:a,availableWorktreesByProject:i,projectRepoStatus:l,projectRootBranches:c,lastRepoStatus:d,buildGroupedSessions:f,hasSessionSearchQuery:m,normalizedSessionSearchQuery:u,filterSessionNodesForSearch:p,buildGroupSearchText:b,foldersMap:g}=t;let y;if(e[0]!==i||e[1]!==f||e[2]!==a||e[3]!==r||e[4]!==d||e[5]!==n||e[6]!==l||e[7]!==c){let P;e[9]!==i||e[10]!==f||e[11]!==a||e[12]!==r||e[13]!==d||e[14]!==l||e[15]!==c?(P=T=>{const S=Ti([...r(T),...a(T)]),M=i.get(T.normalizedPath)??[],D=l.has(T.id)?!!l.get(T.id):d,F=f(S,T.normalizedPath,M,c.get(T.id)??null,D);return{project:T,groups:F}},e[9]=i,e[10]=f,e[11]=a,e[12]=r,e[13]=d,e[14]=l,e[15]=c,e[16]=P):P=e[16],y=n.map(P),e[0]=i,e[1]=f,e[2]=a,e[3]=r,e[4]=d,e[5]=n,e[6]=l,e[7]=c,e[8]=y}else y=e[8];const x=y,h=x;let j;if(e[17]!==b||e[18]!==p||e[19]!==g||e[20]!==m||e[21]!==u||e[22]!==h){e:{const P=new WeakMap;if(!m){j=P;break e}const T=S=>S.reduce((M,D)=>M+1+T(D.children),0);h.forEach(S=>{S.groups.forEach(M=>{const D=p(M.sessions,u),F=T(D),_=b(M).includes(u),V=xs(M.directory??null),O=(V?g[V]??[]:[]).filter(B=>B.name.toLowerCase().includes(u)).length;P.set(M,{filteredNodes:D,matchedSessionCount:F,folderNameMatchCount:O,groupMatches:_,hasMatch:_||F>0||O>0})})}),j=P}e[17]=b,e[18]=p,e[19]=g,e[20]=m,e[21]=u,e[22]=h,e[23]=j}else j=e[23];const v=j;let C;e:{if(!m){C=h;break e}let P;if(e[24]!==v||e[25]!==h){let T;e[27]!==v?(T=S=>({...S,groups:S.groups.filter(M=>v.get(M)?.hasMatch===!0)}),e[27]=v,e[28]=T):T=e[28],P=h.map(T).filter(_P),e[24]=v,e[25]=h,e[26]=P}else P=e[26];C=P}const k=C,w=m?k:h;let N;e:{if(!m){N=0;break e}let P;if(e[29]!==v||e[30]!==w){let T;e[32]!==v?(T=(S,M)=>S+M.groups.reduce((D,F)=>{const _=v.get(F);if(!_)return D;const V=_.folderNameMatchCount+(_.groupMatches?1:0);return D+_.matchedSessionCount+V},0),e[32]=v,e[33]=T):T=e[33],P=w.reduce(T,0),e[29]=v,e[30]=w,e[31]=P}else P=e[31];N=P}const I=N;let E;return e[34]!==v||e[35]!==x||e[36]!==I||e[37]!==k||e[38]!==w||e[39]!==h?(E={projectSections:x,visibleProjectSections:h,groupSearchDataByGroup:v,searchableProjectSections:k,sectionsForRender:w,searchMatchCount:I},e[34]=v,e[35]=x,e[36]=I,e[37]=k,e[38]=w,e[39]=h,e[40]=E):E=e[40],E};function _P(t){return t.groups.length>0}const BP=t=>{const e=ot.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:a,setActiveSessionByProject:i,currentSessionId:l,handleSessionSelect:c,newSessionDraftOpen:d,mobileVariant:f,openNewSessionDraft:m,setActiveMainTab:u,setSessionSwitcherOpen:p,sessions:b,worktreeMetadata:g}=t;let y,x;if(e[0]!==n){x=new Map,y=new Map;const T=(S,M,D,F)=>{x.has(S)||x.set(S,new Map);const _=x.get(S);F.forEach(V=>{const $=xs(V.worktree?.path??V.session.directory??D??M);_.set(V.session.id,{directory:$}),y.has(S)||y.set(S,{id:V.session.id,directory:$}),V.children.length>0&&T(S,M,$,V.children)})};n.forEach(S=>{S.groups.forEach(M=>{T(S.project.id,S.project.normalizedPath,M.directory,M.sessions)})}),e[0]=n,e[1]=y,e[2]=x}else y=e[1],x=e[2];let h;e[3]!==y||e[4]!==x?(h={metaByProject:x,firstSessionByProject:y},e[3]=y,e[4]=x,e[5]=h):h=e[5];const j=h,v=o.useRef(null);let C,k;e[6]!==r||e[7]!==a||e[8]!==l||e[9]!==c||e[10]!==f||e[11]!==d||e[12]!==m||e[13]!==n||e[14]!==j||e[15]!==u||e[16]!==i||e[17]!==p?(C=()=>{if(!r||d||v.current===r)return;const T=n.find($=>$.project.id===r);if(!T)return;v.current=r;const S=j.metaByProject.get(r);if(l&&S&&S.has(l)){i($=>{if($.get(r)===l)return $;const O=new Map($);return O.set(r,l),O});return}if(!S||S.size===0){u("chat"),f&&p(!1),m({directoryOverride:T.project.normalizedPath});return}const M=a.get(r),D=M&&S.has(M)?M:null,F=j.firstSessionByProject.get(r)?.id??null,_=D??F;if(!_||_===l)return;const V=S.get(_)?.directory??null;c(_,V,!1,r)},k=[r,a,l,c,d,f,m,n,j,u,p,i],e[6]=r,e[7]=a,e[8]=l,e[9]=c,e[10]=f,e[11]=d,e[12]=m,e[13]=n,e[14]=j,e[15]=u,e[16]=i,e[17]=p,e[18]=C,e[19]=k):(C=e[18],k=e[19]),o.useLayoutEffect(C,k);let w,N;e[20]!==r||e[21]!==l||e[22]!==j||e[23]!==i?(w=()=>{if(!r||!l)return;const T=j.metaByProject.get(r);!T||!T.has(l)||i(S=>{if(S.get(r)===l)return S;const M=new Map(S);return M.set(r,l),M})},N=[r,l,j,i],e[20]=r,e[21]=l,e[22]=j,e[23]=i,e[24]=w,e[25]=N):(w=e[24],N=e[25]),o.useEffect(w,N);let I;if(e[26]!==l||e[27]!==b||e[28]!==g){e:{if(!l){I=null;break e}const T=g.get(l)?.path;if(T){I=xs(T)??T;break e}let S;e[30]!==l?(S=D=>D.id===l,e[30]=l,e[31]=S):S=e[31];const M=b.find(S);if(!M){I=null;break e}I=xs(M.directory??null)}e[26]=l,e[27]=b,e[28]=g,e[29]=I}else I=e[29];const E=I;let P;return e[32]!==E?(P={currentSessionDirectory:E},e[32]=E,e[33]=P):P=e[33],P},VP=t=>{const e=ot.c(4);let n;e[0]!==t?(n=(i,l)=>{const c=t.get(i);if(!c||c.length===0)return l;const d=new Map(l.map(zP)),f=[];return c.forEach(m=>{const u=d.get(m);u&&(f.push(u),d.delete(m))}),l.forEach(m=>{d.has(m.id)&&f.push(m)}),f},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 zP(t){return[t.id,t]}const nl=t=>!!t.time?.archived,UP=t=>{const{t:e}=pt(),n=o.useCallback(l=>[l.label,l.branch??"",l.description??"",l.directory??""].join(" ").toLowerCase(),[]),r=o.useCallback(l=>{const c=xs(l.directory??null)??"";return`${(l.title||e("sessions.sidebar.session.untitled")).trim()} ${c}`.toLowerCase()},[e]),a=o.useCallback((l,c)=>c?l.flatMap(d=>{if(r(d.session).includes(c))return[d];const m=a(d.children,c);return m.length===0?[]:[{...d,children:m}]}):l,[r]),i=o.useCallback((l,c,d,f,m)=>{const u=xs(c??null),p=Ti(l).sort((T,S)=>wi(T,S,t.pinnedSessionIds)),b=new Map(p.map(T=>[T.id,T])),g=new Map;p.forEach(T=>{const S=T.parentID;if(!S)return;const M=b.get(S);if(!M||nl(M)!==nl(T))return;const D=g.get(S)??[];D.push(T),g.set(S,D)}),g.forEach(T=>T.sort((S,M)=>wi(S,M,t.pinnedSessionIds)));const y=new Map;d.forEach(T=>{if(T.path){const S=xs(T.path)??T.path;y.set(S,T)}});const x=T=>{const S=xs(T.directory??null),M=t.worktreeMetadata.get(T.id)??null;if(M)return M;if(S){const D=y.get(S)??null;if(D&&S!==u)return D}return null},h=T=>{const S=g.get(T.id)??[];return{session:T,children:S.map(M=>h(M)),worktree:x(T)}},j=p.filter(T=>{const S=T.parentID;if(!S)return!0;const M=b.get(S);return M?nl(M)!==nl(T):!0}),v=new Map,C="__archived__",k=T=>{if(T.time?.archived)return C;const S=xs(t.worktreeMetadata.get(T.id)?.path??null),M=xs(T.directory??null);if(!S&&!M)return C;const D=xs(T.project?.worktree??null),F=S??M??D;return F?F!==u&&y.has(F)?F:F===u?u??"__project_root__":C:C};j.forEach(T=>{const S=h(T),M=k(T);v.has(M)||v.set(M,[]),v.get(M)?.push(S)});const w=u??"__project_root__",N=[{id:"root",label:m&&f&&f!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:f}):e("sessions.sidebar.grouping.projectRoot"),branch:f??null,description:u?xo(u,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:u,folderScopeKey:u,sessions:v.get(w)??[]}],I=new Map;d.forEach(T=>{const S=xs(T.path)??T.path,M=v.get(S)??[],D=M.length>0,F=M.reduce((_,V)=>{const $=Number(V.session.time?.updated??V.session.time?.created??0);return Number.isFinite($)?Math.max(_,$):_},0);I.set(S,{hasActiveSession:D,lastUpdatedAt:F})}),[...d].sort((T,S)=>{const M=xs(T.path)??T.path,D=xs(S.path)??S.path,F=I.get(M)??{hasActiveSession:!1,lastUpdatedAt:0},_=I.get(D)??{hasActiveSession:!1,lastUpdatedAt:0};if(F.hasActiveSession!==_.hasActiveSession)return F.hasActiveSession?-1:1;if(F.hasActiveSession&&_.hasActiveSession)return _.lastUpdatedAt-F.lastUpdatedAt;const V=(T.label||T.branch||T.name||T.path||"").toLowerCase(),$=(S.label||S.branch||S.name||S.path||"").toLowerCase();return V.localeCompare($)}).forEach(T=>{const S=xs(T.path)??T.path,M=t.gitBranches.get(S)?.trim()||null,D=T.branch?.trim()||null,_=!!(M&&D&&T.label&&lm(T.label)===lm(D))?M:T.label||T.name||Ja(S,t.homeDirectory)||S;N.push({id:`worktree:${S}`,label:_,branch:M||D,description:xo(S,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:T,directory:S,folderScopeKey:S,sessions:v.get(S)??[]})});const P=v.get(C)??[];return P.length>0&&N.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?du(u):null,sessions:P}),N},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:a,buildGroupedSessions:i}},WP=t=>{const e=ot.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:a,sessionSearchContainerRef:i}=t;let l,c;e[0]!==n||e[1]!==a?(l=()=>{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]=l,e[3]=c):(l=e[2],c=e[3]),o.useEffect(l,c);let d,f;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)},f=[n,r,i],e[4]=n,e[5]=i,e[6]=r,e[7]=d,e[8]=f):(d=e[7],f=e[8]),o.useEffect(d,f)},KP=t=>{const e=ot.c(42),{t:n}=pt(),[r,a]=o.useState(null),i=o.useRef(null);let l,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=()=>()=>{i.current&&clearTimeout(i.current)},c=[],e[0]=l,e[1]=c):(l=e[0],c=e[1]),o.useEffect(l,c);let d;e[2]!==t?(d=(_,V,$,O)=>{if($)return;const B=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(O&&O!==t.activeProjectId&&t.setActiveProjectIdOnly(O),V&&V!==t.currentDirectory&&t.setDirectory(V,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),_===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(_),B();return}t.setCurrentSession(_,V??null),t.onSessionSelected?.(_),B()},e[2]=t,e[3]=d):d=e[3];const f=d;let m;e[4]!==t?(m=(_,V)=>{t.setEditingId(_),t.setEditTitle(V)},e[4]=t,e[5]=m):m=e[5];const u=m;let p;e[6]!==t?(p=async()=>{if(!t.editingId)return;const _=t.editTitle.trim();_&&await t.updateSessionTitle(t.editingId,_),t.setEditingId(null),t.setEditTitle("")},e[6]=t,e[7]=p):p=e[7];const b=p;let g;e[8]!==t?(g=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=g):g=e[9];const y=g;let x;e[10]!==t||e[11]!==n?(x=async _=>{const V=await t.shareSession(_.id);V&&V.share?.url?K.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):K.error(n("sessions.sidebar.session.share.error"))},e[10]=t,e[11]=n,e[12]=x):x=e[12];const h=x;let j;e[13]!==n?(j=(_,V)=>{Ln(_).then($=>{if(!$.ok){K.error(n("sessions.sidebar.session.share.copyUrlError"));return}a(V),i.current&&clearTimeout(i.current),i.current=window.setTimeout(()=>{a(null),i.current=null},2e3)}).catch(()=>{K.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=j):j=e[14];const v=j;let C;e[15]!==t||e[16]!==n?(C=async _=>{await t.unshareSession(_)?K.success(n("sessions.sidebar.session.unshare.success")):K.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=C):C=e[17];const k=C;let w;e[18]!==t.childrenMap?(w=_=>{const V=[],$=O=>{(t.childrenMap.get(O)??[]).forEach(G=>{V.push(G),$(G.id)})};return $(_),V},e[18]=t.childrenMap,e[19]=w):w=e[19];const N=w,I=GP;let E;e[20]!==t||e[21]!==N||e[22]!==n?(E=async(_,V,$)=>{const O=V?.archivedBucket===!0,B=$?.descendantIds??I(N(_.id),O).map(qP);if(B.length===0){(O?await t.deleteSession(_.id):await t.archiveSession(_.id))?K.success(n(O?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):K.error(n(O?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const G=[_.id,...B];if(O){const{deletedIds:J,failedIds:ne}=await t.deleteSessions(G);J.length>0&&K.success(J.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:J.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:J.length})),ne.length>0&&K.error(ne.length===1?n("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ne.length}):n("sessions.sidebar.bulkActions.failedDeletePlural",{count:ne.length}));return}const{archivedIds:R,failedIds:H}=await t.archiveSessions(G);R.length>0&&K.success(R.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:R.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:R.length})),H.length>0&&K.error(H.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:H.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:H.length}))},e[20]=t,e[21]=N,e[22]=n,e[23]=E):E=e[23];const P=E;let T;e[24]!==t||e[25]!==N||e[26]!==P?(T=(_,V)=>{const $=V?.archivedBucket===!0,O=I(N(_.id),$).map(JP);if(!t.showDeletionDialog){P(_,V,{descendantIds:O});return}t.setDeleteSessionConfirm({session:_,descendantCount:O.length,descendantIds:O,archivedBucket:$})},e[24]=t,e[25]=N,e[26]=P,e[27]=T):T=e[27];const S=T;let M;e[28]!==t||e[29]!==P?(M=async()=>{if(!t.deleteSessionConfirm)return;const{session:_,archivedBucket:V,descendantIds:$}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await P(_,{archivedBucket:V},{descendantIds:$})},e[28]=t,e[29]=P,e[30]=M):M=e[30];const D=M;let F;return e[31]!==D||e[32]!==r||e[33]!==y||e[34]!==v||e[35]!==S||e[36]!==b||e[37]!==u||e[38]!==f||e[39]!==h||e[40]!==k?(F={copiedSessionId:r,handleSessionSelect:f,handleSessionDoubleClick:u,handleSaveEdit:b,handleCancelEdit:y,handleShareSession:h,handleCopyShareUrl:v,handleUnshareSession:k,handleDeleteSession:S,confirmDeleteSession:D},e[31]=D,e[32]=r,e[33]=y,e[34]=v,e[35]=S,e[36]=b,e[37]=u,e[38]=f,e[39]=h,e[40]=k,e[41]=F):F=e[41],F};function HP(t){return!t.time?.archived}function GP(t,e){return e?t:t.filter(HP)}function qP(t){return t.id}function JP(t){return t.id}const YP=["project:active:","project:archived:","recent:active:","recent:archived:"],QP=t=>{const{isVSCode:e,hasLoadedGlobalSessions:n,safeStorage:r,keys:a,sessions:i,setPinnedSessionIds:l,groupOrderByProject:c,activeSessionByProject:d,collapsedGroups:f,setExpandedParents:m,setCollapsedProjects:u}=t,p=o.useRef(null),b=o.useRef(null),g=o.useCallback(()=>{if(e)return;const x=b.current;if(b.current=null,p.current=null,!x)return;const{projects:h}=Ss.getState(),j=h.map(v=>({...v,sidebarCollapsed:x.has(v.id)}));Cs({projects:j}).catch(()=>{})},[e]),y=o.useCallback(x=>{typeof window>"u"||e||(b.current=x,p.current!==null&&window.clearTimeout(p.current),p.current=window.setTimeout(()=>{g()},700))},[e,g]);return o.useEffect(()=>()=>{typeof window<"u"&&p.current!==null&&window.clearTimeout(p.current),p.current=null,b.current=null},[]),o.useEffect(()=>{try{const x=r.getItem(a.sessionExpanded);if(x){const j=JSON.parse(x);Array.isArray(j)&&m(new Set(j.filter(v=>typeof v=="string")))}else{const j=r.getItem(a.sessionExpandedLegacy);if(j){try{const v=JSON.parse(j);if(Array.isArray(v)){const C=new Set;if(v.forEach(k=>{typeof k!="string"||k.length===0||YP.forEach(w=>C.add(`${w}${k}`))}),C.size>0){m(C);try{r.setItem(a.sessionExpanded,JSON.stringify(Array.from(C)))}catch{}}}}catch{}try{r.removeItem?.(a.sessionExpandedLegacy)}catch{}}}const h=r.getItem(a.projectCollapse);if(h){const j=JSON.parse(h);Array.isArray(j)&&u(new Set(j.filter(v=>typeof v=="string")))}}catch{}},[a.projectCollapse,a.sessionExpanded,a.sessionExpandedLegacy,r,u,m]),o.useEffect(()=>{if(!n)return;const x=new Set(i.map(h=>h.id));l(h=>{let j=!1;const v=new Set;return h.forEach(C=>{x.has(C)?v.add(C):j=!0}),j?v:h})},[n,i,l]),o.useEffect(()=>{try{const x=Object.fromEntries(c.entries());r.setItem(a.groupOrder,JSON.stringify(x))}catch{}},[c,a.groupOrder,r]),o.useEffect(()=>{try{const x=Object.fromEntries(d.entries());r.setItem(a.projectActiveSession,JSON.stringify(x))}catch{}},[d,a.projectActiveSession,r]),o.useEffect(()=>{try{r.setItem(a.groupCollapse,JSON.stringify(Array.from(f)))}catch{}},[f,a.groupCollapse,r]),{scheduleCollapsedProjectsPersist:y}},XP=t=>{const e=ot.c(26),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:a,setProjectRootBranches:i}=t,{git:l}=Wn(),c=qs(ZP);let d,f;e[0]!==c||e[1]!==l||e[2]!==n||e[3]!==a?(d=()=>{if(!l||n.length===0){a(new Map);return}n.forEach(j=>{c(j.normalizedPath,l)})},f=[n,l,c,a],e[0]=c,e[1]=l,e[2]=n,e[3]=a,e[4]=d,e[5]=f):(d=e[4],f=e[5]),o.useEffect(d,f);let m,u;e[6]!==r||e[7]!==n||e[8]!==a?(m=()=>{const j=new Map;n.forEach(v=>{j.set(v.id,r.get(v.normalizedPath)?.isGitRepo??null)}),a(j)},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]),o.useEffect(m,u);let p;if(e[11]!==r||e[12]!==n){let j;e[14]!==r?(j=v=>{const C=r.get(v.normalizedPath)?.branch??"";return`${v.id}:${C}`},e[14]=r,e[15]=j):j=e[15],p=n.map(j).join("|"),e[11]=r,e[12]=n,e[13]=p}else p=e[13];const b=p;let g;e[16]===Symbol.for("react.memo_cache_sentinel")?(g=new Map,e[16]=g):g=e[16];const y=o.useRef(g);let x;e[17]!==r||e[18]!==n||e[19]!==i?(x=()=>{let j=!1;const v=setTimeout(()=>{(async()=>{const k=new Set(n.map(eA));for(const E of y.current.keys())k.has(E)||y.current.delete(E);const w=n.filter(E=>{const P=r.get(E.normalizedPath);if(P?.isGitRepo===!1)return y.current.delete(E.id),!1;if(P?.isGitRepo!==!0||P.branch===null)return!1;const T=P.branch.trim(),S=`${E.normalizedPath}\0${T}`,M=y.current.get(E.id);return M===void 0||M!==S});if(w.length===0)return;const N=await gg(w,2,async E=>{const P=r.get(E.normalizedPath)?.branch?.trim()??"",T=`${E.normalizedPath}\0${P}`,S=await Po(E.normalizedPath,P?{knownBranch:P}:void 0).catch(tA);return{id:E.id,inputKey:T,branch:S}});if(j)return;const I=N.filter(sA);I.length!==0&&(i(E=>{const P=new Map(E);return I.forEach(T=>{const{id:S,branch:M}=T;M&&P.set(S,M)}),P}),I.forEach(E=>{const{id:P,inputKey:T}=E;y.current.set(P,T)}))})()},150);return()=>{j=!0,clearTimeout(v)}},e[17]=r,e[18]=n,e[19]=i,e[20]=x):x=e[20];let h;e[21]!==r||e[22]!==n||e[23]!==b||e[24]!==i?(h=[n,b,r,i],e[21]=r,e[22]=n,e[23]=b,e[24]=i,e[25]=h):h=e[25],o.useEffect(x,h)};function ZP(t){return t.ensureStatus}function eA(t){return t.id}function tA(){return null}function sA(t){return t.branch}const nA=t=>{const e=ot.c(14),{isVSCode:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i}=t;let l;e[0]!==r?(l=new Map,r.forEach(b=>{const g=xs(b.directory??null)??xs(b.project?.worktree??null);if(!g)return;const y=l.get(g)??[];y.push(b),l.set(g,y)}),e[0]=r,e[1]=l):l=e[1];const c=l;let d;e[2]!==i||e[3]!==n||e[4]!==c?(d=b=>{const g=n?[]:i.get(b.normalizedPath)??[],y=[b.normalizedPath,...g.map(rA).filter(aA)],x=new Set,h=[];return y.forEach(j=>{(c.get(j)??[]).forEach(C=>{x.has(C.id)||(x.add(C.id),h.push(C))})}),h},e[2]=i,e[3]=n,e[4]=c,e[5]=d):d=e[5];const f=d;let m;e[6]!==a||e[7]!==i||e[8]!==n||e[9]!==r?(m=b=>{if(n){const v=a.filter(k=>{const w=xs(k.directory??null),N=xs(k.project?.worktree??null);return w?w===b.normalizedPath:N===b.normalizedPath}),C=r.filter(k=>k.time?.archived||xs(k.directory??null)?!1:xs(k.project?.worktree??null)===b.normalizedPath);return Ti([...v,...C])}const g=n?[]:i.get(b.normalizedPath)??[],y=new Set([b.normalizedPath,...g.map(iA).filter(oA)]),h=(v=>v.filter(C=>bo(C,b.normalizedPath,y)))(a),j=r.filter(v=>{if(v.time?.archived||xs(v.directory??null))return!1;const k=xs(v.project?.worktree??null);return k?k===b.normalizedPath||k.startsWith(`${b.normalizedPath}/`):!1});return Ti([...h,...j])},e[6]=a,e[7]=i,e[8]=n,e[9]=r,e[10]=m):m=e[10];const u=m;let p;return e[11]!==u||e[12]!==f?(p={getSessionsForProject:f,getArchivedSessionsForProject:u},e[11]=u,e[12]=f,e[13]=p):p=e[13],p};function rA(t){return xs(t.path)??t.path}function aA(t){return!!t}function iA(t){return xs(t.path)??t.path}function oA(t){return!!t}const lA=t=>{const e=ot.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:a,normalizedProjects:i,isVSCode:l,availableWorktreesByProject:c,cleanupSessions:d}=t;let f,m;e[0]!==a||e[1]!==c||e[2]!==d||e[3]!==n||e[4]!==l||e[5]!==i||e[6]!==r?(f=()=>{if(n)return;const u=new Map;r.forEach(g=>{const y=xs(g.directory??null);if(!y)return;const x=u.get(y);if(x){x.add(g.id);return}u.set(y,new Set([g.id]))}),i.forEach(g=>{const y=du(g.normalizedPath),x=l?[]:c.get(g.normalizedPath)??[],h=new Set([g.normalizedPath,...x.map(cA).filter(dA)]),j=Ti([...a,...r.filter(v=>v.time?.archived||xs(v.directory??null)?!1:bo(v,g.normalizedPath,h))]).filter(v=>bo(v,g.normalizedPath,h));u.set(y,new Set(j.map(uA)))});const p=er.getState().foldersMap;new Set([...Object.keys(p),...u.keys()]).forEach(g=>{d(g,u.get(g)??new Set)})},m=[a,c,d,n,l,i,r],e[0]=a,e[1]=c,e[2]=d,e[3]=n,e[4]=l,e[5]=i,e[6]=r,e[7]=f,e[8]=m):(f=e[7],m=e[8]),o.useEffect(f,m)};function cA(t){return xs(t.path)??t.path}function dA(t){return!!t}function uA(t){return t.id}const mA=t=>{const e=ot.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[l,c]=o.useState(i);let d;e[1]!==n||e[2]!==a?(d=()=>{if(!n)return;const m=new IntersectionObserver(u=>{u.forEach(p=>{const b=p.target.dataset.projectId;b&&c(g=>{const y=new Set(g);return p.isIntersecting?y.delete(b):y.add(b),y})})},{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 f;return e[4]!==n||e[5]!==a||e[6]!==r?(f=[n,a,r],e[4]=n,e[5]=a,e[6]=r,e[7]=f):f=e[7],o.useEffect(d,f),l},pA=t=>{const e=ot.c(85),{folder:n,sessions:r,subFolderItems:a,isCollapsed:i,onToggle:l,onRename:c,onDelete:d,renderSessionNode:f,groupDirectory:m,projectId:u,mobileVariant:p,alwaysShowActions:b,isRenaming:g,renameDraft:y,onRenameDraftChange:x,onRenameSave:h,onRenameCancel:j,droppableRef:v,isDropTarget:C,onNewSession:k,onNewSubFolder:w,depth:N,hideActions:I,archivedBucket:E}=t,T=b===void 0?p===void 0?!1:p:b,S=g===void 0?!1:g,M=y===void 0?"":y,D=C===void 0?!1:C,F=N===void 0?0:N,_=I===void 0?!1:I,V=E===void 0?!1:E,{t:$}=pt(),[O,B]=o.useState(!1),[G,R]=o.useState(""),H=o.useRef(null),J=S||O,ne=S?M:G;let ue;e[0]!==n.name?(ue=()=>{R(n.name),B(!0)},e[0]=n.name,e[1]=ue):ue=e[1];const de=ue;let pe;e[2]!==ne||e[3]!==n.name||e[4]!==S||e[5]!==c||e[6]!==h?(pe=()=>{const U=ne.trim();U&&U!==n.name&&c(U),S&&h&&h(),B(!1),R("")},e[2]=ne,e[3]=n.name,e[4]=S,e[5]=c,e[6]=h,e[7]=pe):pe=e[7];const W=pe;let te;e[8]!==S||e[9]!==j?(te=()=>{S&&j&&j(),B(!1),R("")},e[8]=S,e[9]=j,e[10]=te):te=e[10];const X=te;let ee;e[11]!==S||e[12]!==x?(ee=U=>{S&&x?x(U):R(U)},e[11]=S,e[12]=x,e[13]=ee):ee=e[13];const fe=ee;let be,Ne;e[14]!==S?(be=()=>{if(!S)return;const U=()=>{const Oe=H.current;Oe&&(Oe.focus(),Oe.select())},oe=requestAnimationFrame(U),Ee=window.setTimeout(U,0);return()=>{cancelAnimationFrame(oe),window.clearTimeout(Ee)}},Ne=[S],e[14]=S,e[15]=be,e[16]=Ne):(be=e[15],Ne=e[16]),o.useEffect(be,Ne);const se=i?"folder":"folder-open",ae=F>0&&"ml-3";let xe;e[17]!==ae?(xe=ge("oc-folder",ae),e[17]=ae,e[18]=xe):xe=e[18];const Z=D&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let me;e[19]!==Z?(me=ge("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",Z),e[19]=Z,e[20]=me):me=e[20];const Y=J?void 0:l,Se=J?void 0:"button",we=J?void 0:0;let ke;e[21]!==l||e[22]!==J?(ke=J?void 0:U=>{(U.key==="Enter"||U.key===" ")&&(U.preventDefault(),l())},e[21]=l,e[22]=J,e[23]=ke):ke=e[23];let Fe;e[24]!==n.name||e[25]!==i||e[26]!==$?(Fe=i?$("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):$("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[24]=n.name,e[25]=i,e[26]=$,e[27]=Fe):Fe=e[27];const Ce=V?T?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let Q;e[28]!==Ce?(Q=ge("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",Ce),e[28]=Ce,e[29]=Q):Q=e[29];const ce=D?"text-primary":"text-muted-foreground";let ve;e[30]!==ce?(ve=ge("h-3.5 w-3.5 flex-shrink-0",ce),e[30]=ce,e[31]=ve):ve=e[31];let le;e[32]!==se||e[33]!==ve?(le=s.jsx(A,{name:se,className:ve}),e[32]=se,e[33]=ve,e[34]=le):le=e[34];let Ae;e[35]!==ne||e[36]!==n.name||e[37]!==X||e[38]!==fe||e[39]!==W||e[40]!==i||e[41]!==D||e[42]!==J||e[43]!==r||e[44]!==$?(Ae=J?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:hA,onMouseDown:gA,onSubmit:U=>{U.preventDefault(),W()},children:[s.jsx("input",{ref:H,value:ne,onChange:U=>fe(U.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:$("sessions.sidebar.folderItem.namePlaceholder"),onClick:xA,onPointerDown:bA,onMouseDown:yA,onKeyDown:U=>{if(U.key==="Escape"){U.stopPropagation(),X();return}(U.key===" "||U.key==="Enter")&&U.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:vA,onPointerDown:wA,onMouseDown:jA,children:s.jsx(A,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:U=>{U.stopPropagation(),X()},onPointerDown:NA,onMouseDown:SA,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(A,{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:ge("typography-ui-label font-semibold truncate",D?"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(A,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=ne,e[36]=n.name,e[37]=X,e[38]=fe,e[39]=W,e[40]=i,e[41]=D,e[42]=J,e[43]=r,e[44]=$,e[45]=Ae):Ae=e[45];let Te;e[46]!==Q||e[47]!==le||e[48]!==Ae?(Te=s.jsxs("div",{className:Q,children:[le,Ae]}),e[46]=Q,e[47]=le,e[48]=Ae,e[49]=Te):Te=e[49];let $e;e[50]!==T||e[51]!==V||e[52]!==F||e[53]!==n.name||e[54]!==de||e[55]!==_||e[56]!==d||e[57]!==k||e[58]!==w||e[59]!==J||e[60]!==$?($e=!J&&(!_||V)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:ge("flex items-center gap-0.5 transition-opacity",T?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",V&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!V&&k?s.jsx("button",{type:"button",onClick:U=>{U.stopPropagation(),k()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":$("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:$("sessions.sidebar.project.actions.newSession"),children:s.jsx(A,{name:"add",className:"h-3.5 w-3.5"})}):null,!V&&w&&F===0?s.jsx("button",{type:"button",onClick:U=>{U.stopPropagation(),w()},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":$("sessions.sidebar.folderItem.newSubfolderAria",{folderName:n.name}),title:$("sessions.sidebar.folderItem.newSubfolder"),children:s.jsx(A,{name:"folder-add",className:"h-3.5 w-3.5"})}):null,V?null:s.jsx("button",{type:"button",onClick:U=>{U.stopPropagation(),de()},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":$("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(A,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:U=>{U.stopPropagation(),d()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V?$("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):$("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[50]=T,e[51]=V,e[52]=F,e[53]=n.name,e[54]=de,e[55]=_,e[56]=d,e[57]=k,e[58]=w,e[59]=J,e[60]=$,e[61]=$e):$e=e[61];let ye;e[62]!==v||e[63]!==me||e[64]!==Y||e[65]!==Se||e[66]!==we||e[67]!==ke||e[68]!==Fe||e[69]!==Te||e[70]!==$e?(ye=s.jsxs("div",{ref:v,className:me,onClick:Y,role:Se,tabIndex:we,onKeyDown:ke,"aria-label":Fe,children:[Te,$e]}),e[62]=v,e[63]=me,e[64]=Y,e[65]=Se,e[66]=we,e[67]=ke,e[68]=Fe,e[69]=Te,e[70]=$e,e[71]=ye):ye=e[71];let q;e[72]!==V||e[73]!==m||e[74]!==i||e[75]!==u||e[76]!==f||e[77]!==r||e[78]!==a||e[79]!==$?(q=i?null:s.jsxs("div",{className:"pb-1 pl-2",children:[a,r.length>0?r.map(U=>f(U,0,m??null,u??null,V)):a?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:$("sessions.sidebar.folderItem.emptyFolder")})]}),e[72]=V,e[73]=m,e[74]=i,e[75]=u,e[76]=f,e[77]=r,e[78]=a,e[79]=$,e[80]=q):q=e[80];let L;return e[81]!==xe||e[82]!==ye||e[83]!==q?(L=s.jsxs("div",{className:xe,children:[ye,q]}),e[81]=xe,e[82]=ye,e[83]=q,e[84]=L):L=e[84],L},fA=o.memo(pA);function hA(t){return t.stopPropagation()}function gA(t){return t.stopPropagation()}function xA(t){return t.stopPropagation()}function bA(t){return t.stopPropagation()}function yA(t){return t.stopPropagation()}function vA(t){return t.stopPropagation()}function wA(t){return t.stopPropagation()}function jA(t){return t.stopPropagation()}function NA(t){return t.stopPropagation()}function SA(t){return t.stopPropagation()}const kA=t=>{const e=ot.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:a,children:i}=t,l=`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]!==l||e[5]!==c?(d={id:l,data:c},e[4]=l,e[5]=c,e[6]=d):d=e[6];const{attributes:f,listeners:m,setNodeRef:u,isDragging:p}=ib(d);let b;e[7]!==m?(b=h=>{h.stopPropagation(),m?.onPointerDown&&m.onPointerDown(h)},e[7]=m,e[8]=b):b=e[8];const g=b,y=p?"opacity-30":void 0;let x;return e[9]!==f||e[10]!==i||e[11]!==g||e[12]!==u||e[13]!==y?(x=s.jsx("div",{ref:u,...f,onPointerDown:g,className:y,children:i}),e[9]=f,e[10]=i,e[11]=g,e[12]=u,e[13]=y,e[14]=x):x=e[14],x},CA=t=>{const e=ot.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 l;e[2]!==a||e[3]!==i?(l={id:a,data:i},e[2]=a,e[3]=i,e[4]=l):l=e[4];const{setNodeRef:c,isOver:d}=ob(l);let f;e[5]!==r||e[6]!==d||e[7]!==c?(f=r(c,d),e[5]=r,e[6]=d,e[7]=c,e[8]=f):f=e[8];let m;return e[9]!==f?(m=s.jsx(s.Fragment,{children:f}),e[9]=f,e[10]=m):m=e[10],m},IA=t=>{const e=ot.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:a,children:i}=t;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[0]=l):l=e[0];const c=mo(bi(po,l)),[d,f]=o.useState(null),[m,u]=o.useState("Session"),[p,b]=o.useState(null),[g,y]=o.useState(null);if(!n){let N;return e[1]!==i?(N=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=N):N=e[2],N}let x;e[3]!==a?(x=N=>{f(null),b(null),y(null);const{active:I,over:E}=N;if(!E)return;const P=I.data.current,T=E.data.current;P?.type==="session"&&P.sessionId&&T?.type==="folder"&&T.folderId&&a(P.sessionId,T.folderId)},e[3]=a,e[4]=x):x=e[4];const h=x;let j,v;e[5]===Symbol.for("react.memo_cache_sentinel")?(j=N=>{const I=N.active.data.current;if(I?.type==="session"&&I.sessionId){f(I.sessionId),u(I.sessionTitle??"Session");const E=N.active.rect.current.initial?.width,P=N.active.rect.current.initial?.height;b(typeof E=="number"?E:null),y(typeof P=="number"?P:null)}},v=()=>{f(null),b(null),y(null)},e[5]=j,e[6]=v):(j=e[5],v=e[6]);let C;e[7]!==g||e[8]!==d||e[9]!==m||e[10]!==p||e[11]!==r?(C=d&&r?s.jsxs("div",{style:{width:p?`${p}px`:"auto",height:g?`${g}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(A,{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]=g,e[8]=d,e[9]=m,e[10]=p,e[11]=r,e[12]=C):C=e[12];let k;e[13]!==C?(k=s.jsx(Dl,{children:C}),e[13]=C,e[14]=k):k=e[14];let w;return e[15]!==i||e[16]!==h||e[17]!==c||e[18]!==k?(w=s.jsxs(fo,{sensors:c,collisionDetection:ho,onDragStart:j,onDragCancel:v,onDragEnd:h,children:[i,k]}),e[15]=i,e[16]=h,e[17]=c,e[18]=k,e[19]=w):w=e[19],w},za=ar()(Fi(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"})),PA=50,AA=28;function DA(t){const{t:e}=pt(),{group:n,groupKey:r,projectId:a,hideGroupLabel:i,hasSessionSearchQuery:l,normalizedSessionSearchQuery:c,groupSearchDataByGroup:d,expandedSessionGroups:f,collapsedGroups:m,hideDirectoryControls:u,collapsedFolderIds:p,toggleFolderCollapse:b,renameFolder:g,deleteFolder:y,showDeletionDialog:x,setDeleteFolderConfirm:h,renderSessionNode:j,projectRepoStatus:v,lastRepoStatus:C,toggleGroupSessionLimit:k,mobileVariant:w,alwaysShowActions:N,activeProjectId:I,setActiveProjectIdOnly:E,setActiveMainTab:P,setSessionSwitcherOpen:T,openNewSessionDraft:S,addSessionToFolder:M,createFolderAndStartRename:D,renamingFolderId:F,renameFolderDraft:_,setRenameFolderDraft:V,setRenamingFolderId:$,pinnedSessionIds:O,sessionOrderIndex:B,prVisualStateByDirectoryBranch:G,onToggleCollapsedGroup:R,dragHandleProps:H,compactBodyPadding:J=!1}=t,ne=o.useCallback((He,lt)=>{const vt=B.get(He.session.id),ft=B.get(lt.session.id);if(vt!==void 0||ft!==void 0){if(vt===void 0)return 1;if(ft===void 0)return-1;if(vt!==ft)return vt-ft}return wi(He.session,lt.session,O)},[O,B]),ue=l?d.get(n):null,de=za(He=>He.displayMode),pe=er(He=>He.foldersMap),W=de==="minimal",te=f.has(r),X=l?!1:m.has(r),ee=u?10:5,fe=l?ue?.groupMatches===!0:!1,be=l,Ne=o.useMemo(()=>[...be?ue?.filteredNodes??[]:n.sessions].sort(ne),[ne,n.sessions,ue?.filteredNodes,be]),se=n.folderScopeKey??xs(n.directory??null),ie=o.useMemo(()=>se?pe[se]??[]:[],[se,pe]),ae=o.useMemo(()=>{const He=new Map,lt=vt=>{vt.forEach(ft=>{He.set(ft.session.id,ft),ft.children.length>0&<(ft.children)})};return lt(Ne),He},[Ne]),xe=o.useMemo(()=>ie.map(He=>{const lt=He.sessionIds.map(vt=>ae.get(vt)).filter(vt=>!!vt).sort(ne);return{folder:He,nodes:lt}}),[ie,ae,ne]),Z=o.useMemo(()=>{const He=new Map(xe.map(dt=>[dt.folder.id,dt])),lt=new Map;for(const{folder:dt}of xe){if(!dt.parentId)continue;const Dt=lt.get(dt.parentId);Dt?Dt.push(dt.id):lt.set(dt.parentId,[dt.id])}const vt=new Map,ft=dt=>{const Dt=vt.get(dt);if(Dt!==void 0)return Dt;const Qt=He.get(dt);if(!Qt)return vt.set(dt,!1),!1;const Ft=lt.get(dt)??[];if(n.isArchivedBucket&&Qt.nodes.length===0){const zt=Ft.some(es=>ft(es));return vt.set(dt,zt),zt}if(!l||Qt.folder.name.toLowerCase().includes(c)||Qt.nodes.length>0)return vt.set(dt,!0),!0;const gt=Ft.some(zt=>ft(zt));return vt.set(dt,gt),gt};return xe.filter(({folder:dt})=>ft(dt.id))},[xe,n.isArchivedBucket,l,c]),me=o.useMemo(()=>new Set(Z.flatMap(He=>He.folder.sessionIds)),[Z]),Y=o.useMemo(()=>Ne.filter(He=>!me.has(He.session.id)),[Ne,me]),Se=o.useMemo(()=>Z.filter(({folder:He})=>!He.parentId),[Z]),we=Y.length,ke=n.isArchivedBucket||l||te?Y:Y.slice(0,ee),Fe=we-ke.length,Ce=n.isArchivedBucket===!0&&!l&&ke.length>=PA,Q=o.useRef(null),[ce,ve]=o.useState(null),[le,Ae]=o.useState(0),Te=mh({count:ke.length,getScrollElement:()=>ce,estimateSize:()=>AA,overscan:8,enabled:Ce&&ce!==null,scrollMargin:le});o.useLayoutEffect(()=>{if(!Ce){ce!==null&&ve(null),le!==0&&Ae(0);return}const He=Q.current;if(!He)return;let lt=ce;if(!lt||!lt.contains(He)){let ft=He.parentElement;for(;ft;){const dt=window.getComputedStyle(ft);if(dt.overflowY==="auto"||dt.overflowY==="scroll"){lt=ft;break}ft=ft.parentElement}if(lt!==ce){ve(lt);return}}if(!lt)return;const vt=He.getBoundingClientRect().top-lt.getBoundingClientRect().top+lt.scrollTop;Ae(ft=>Math.abs(ft-vt)<1?ft:vt)}),o.useEffect(()=>{if(!Ce||!ce)return;const He=new ResizeObserver(()=>{Te.measure()});return He.observe(ce),()=>He.disconnect()},[Ce,ce,Te]);const $e=Te.getTotalSize(),ye=Ce&&ce!==null?Te.getVirtualItems():[];if(l&&!fe&&Se.length===0&&Y.length===0)return null;const q=He=>{const lt=[],vt=ft=>{ft.forEach(dt=>{lt.push(dt.session),dt.children.length>0&&vt(dt.children)})};return vt(He),lt},L=q(Ne),U=a&&v.has(a)?!!v.get(a):C,oe=xs(n.directory??null),Ee=n.branch?.trim()??null,Oe=oe&&Ee?G.get(`${oe}::${Ee}`)??null:null,Ie=!!(Oe&&n.branch),z=!Oe&&!n.isMain&&!!n.branch,De=Oe?.visualState??null,Qe=Oe&&Oe.state==="open"&&Oe.checks?e("sessions.sidebar.group.pr.checksPassed",{success:Oe.checks.success,total:Oe.checks.total}):null,tt=Oe&&Oe.state==="open"&&Oe.checks?[Oe.checks.failure>0?e("sessions.sidebar.group.pr.failingCount",{count:Oe.checks.failure}):null,Oe.checks.pending>0?e("sessions.sidebar.group.pr.pendingCount",{count:Oe.checks.pending}):null].filter(He=>!!He).join(", "):null,et=Oe&&Oe.state==="open"?Oe.mergeableState==="blocked"||Oe.mergeableState==="dirty"?e("sessions.sidebar.group.pr.conflictsOrBlocked"):Oe.mergeableState==="clean"||Oe.canMerge===!0?e("sessions.sidebar.group.pr.mergeable"):null:null,We=Oe&&Oe.state==="open"&&Oe.mergeableState?e("sessions.sidebar.group.pr.mergeState",{state:Oe.mergeableState}):null,at=Oe?.base??null,qe=Oe?.head??null,nt=(()=>{if(!Oe)return n.branch&&iv(n.branch,n.label)?{label:n.branch,color:null}:null;switch(Oe.visualState){case"merged":return{label:e("sessions.sidebar.group.pr.status.merged"),color:"var(--pr-merged)"};case"open":return Oe.canMerge===!0||Oe.mergeableState==="clean"||Oe.checks?.state==="success"?{label:e("sessions.sidebar.group.pr.status.readyToMerge"),color:"var(--pr-open)"}:{label:e("sessions.sidebar.group.pr.status.open"),color:"var(--pr-open)"};case"blocked":return{label:Oe.mergeableState==="dirty"?e("sessions.sidebar.group.pr.status.mergeConflicts"):e("sessions.sidebar.group.pr.status.mergeBlocked"),color:"var(--pr-blocked)"};case"draft":return{label:e("sessions.sidebar.group.pr.status.draft"),color:"var(--pr-draft)"};case"closed":return{label:e("sessions.sidebar.group.pr.status.closed"),color:"var(--pr-closed)"};default:return null}})(),Ze=nt?.color??(De?`var(--pr-${De})`:void 0),ze=He=>{He.preventDefault(),He.stopPropagation();const lt=Oe?.url;lt&&rr(lt)},rt=(He,lt,vt)=>{const ft=Z.filter(({folder:Ft})=>Ft.parentId===He.id),dt=ft.length>0?s.jsx(s.Fragment,{children:ft.map(({folder:Ft,nodes:qt})=>rt(Ft,qt,vt+1))}):void 0,Dt=Ft=>{const qt=Z.find(({folder:zt})=>zt.id===Ft)?.nodes??[],gt=Z.filter(({folder:zt})=>zt.parentId===Ft);return[...q(qt),...gt.flatMap(({folder:zt})=>Dt(zt.id))]},Qt=n.isArchivedBucket?Dt(He.id):[];return s.jsx(CA,{folderId:He.id,children:(Ft,qt)=>s.jsx(fA,{folder:He,sessions:lt,subFolderItems:dt,isCollapsed:l?!1:p.has(He.id),onToggle:()=>b(He.id),onRename:gt=>{se&&g(se,He.id,gt)},onDelete:()=>{if(n.isArchivedBucket){Mr.requestDelete({sessions:Qt,mode:"session"});return}if(!se)return;if(!x){y(se,He.id);return}const gt=Z.filter(({folder:es})=>es.parentId===He.id).length,zt=lt.length;h({scopeKey:se,folderId:He.id,folderName:He.name,subFolderCount:gt,sessionCount:zt})},renderSessionNode:j,groupDirectory:n.directory,projectId:a,mobileVariant:w,alwaysShowActions:N,isRenaming:F===He.id,renameDraft:F===He.id?_:void 0,onRenameDraftChange:gt=>V(gt),onRenameSave:()=>{const gt=_.trim();gt&&se&&g(se,He.id,gt),$(null),V("")},onRenameCancel:()=>{$(null),V("")},droppableRef:Ft,isDropTarget:qt,depth:vt,onNewSession:()=>{a&&a!==I&&E(a),P("chat"),w&&T(!1),S({directoryOverride:n.directory,targetFolderId:He.id})},onNewSubFolder:vt===0?()=>{se&&D(se,He.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},He.id)},Ge=()=>Se.map(({folder:He,nodes:lt})=>rt(He,lt,0)),ct=!!(!n.isMain&&n.worktree),Pe=N?ct?"pr-14":"pr-7":W?ct?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":ct?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",Me=s.jsxs(IA,{scopeKey:se,hasFolders:Z.length>0,onSessionDroppedOnFolder:(He,lt)=>{se&&M(se,lt,He)},children:[Ge(),Ce?s.jsx("div",{ref:Q,style:{position:"relative",height:$e>0?$e:void 0,width:"100%"},children:ye.map(He=>{const lt=ke[He.index];return lt?s.jsx("div",{"data-index":He.index,ref:Te.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${He.start-le}px)`},children:j(lt,0,n.directory,a,!0)},He.key):null})}):ke.map(He=>j(He,0,n.directory,a,n.isArchivedBucket===!0)),we===0&&Z.length===0?s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?e("sessions.sidebar.group.empty.noArchivedSessions"):e("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,Fe>0&&!te?s.jsx("button",{type:"button",onClick:()=>k(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:Fe===1?e("sessions.sidebar.group.showMoreSingle",{count:Fe}):e("sessions.sidebar.group.showMorePlural",{count:Fe})}):null,te&&we>ee?s.jsx("button",{type:"button",onClick:()=>k(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showFewer")}):null]}),Ue=J?"pb-2 pl-1":"pb-3 pl-4";return i?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:ge("oc-group-body",Ue),children:Me})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:ge("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>R(r),role:"button",tabIndex:0,onKeyDown:He=>{(He.key==="Enter"||He.key===" ")&&(He.preventDefault(),R(r))},"aria-label":X?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!X,children:[s.jsx("div",{ref:H?.setActivatorNodeRef,className:ge("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",Pe),...H?.listeners??{},children:s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:Ie&&Oe?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(A,{name:"git-branch",className:ge("h-3.5 w-3.5 shrink-0",N?"hidden":"group-hover/gh:hidden"),style:Ze?{color:Ze}:void 0}),s.jsx("span",{className:ge("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:X?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),Oe.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:He=>He.stopPropagation(),onClick:ze,children:["#",Oe.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",Oe.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:[at||qe?s.jsx("div",{className:"text-muted-foreground truncate",children:at&&qe?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:at}),s.jsx(A,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:qe})]}):s.jsx("span",{children:at??qe??""})}):null,We?s.jsx("div",{className:"text-muted-foreground truncate",children:We}):null,et||Qe?s.jsxs("div",{className:"text-muted-foreground truncate",children:[et??"",et&&Qe?" • ":"",Qe??"",tt?` (${tt})`:""]}):null]})})]}),s.jsx("span",{className:"ml-1 min-w-0 flex-1 truncate leading-none align-middle",children:n.branch})]}):n.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(A,{name:"archive",className:ge("h-3.5 w-3.5 shrink-0 text-muted-foreground",N?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:ge("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:X?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:io(n.label,c)})]}):!n.isMain||n.worktree?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(A,{name:"git-branch",className:ge("h-3.5 w-3.5 shrink-0 text-muted-foreground",N?"hidden":"group-hover/gh:hidden"),style:Ze?{color:Ze}:void 0}),s.jsx("span",{className:ge("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:X?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:io(n.label,c)})]}):io(n.label,c)}),z&&nt?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(A,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!n.isMain||U?Ie&&Oe?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(A,{name:"git-branch",className:"h-3.5 w-3.5 text-muted-foreground",style:Ze?{color:Ze}: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:[at||qe?s.jsx("div",{className:"text-muted-foreground truncate",children:at&&qe?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:at}),s.jsx(A,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:qe})]}):s.jsx("span",{children:at??qe??""})}):null,We?s.jsx("div",{className:"text-muted-foreground truncate",children:We}):null,et||Qe?s.jsxs("div",{className:"text-muted-foreground truncate",children:[et??"",et&&Qe?" • ":"",Qe??"",tt?` (${tt})`:""]}):null]})})]}):s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:Ze?{color:Ze}:void 0}):null,s.jsx("span",{className:ge("min-w-0 truncate text-[11px] font-medium",!nt.color&&"text-muted-foreground/80"),style:nt.color?{color:nt.color}:void 0,children:nt.label})]}):null]})}),n.isArchivedBucket&&L.length>0?s.jsx("div",{className:ge("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"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:He=>{He.stopPropagation(),Mr.requestDelete({sessions:L,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:ge("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"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:He=>{He.stopPropagation(),Mr.requestDelete({sessions:L,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:ge("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"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:He=>{He.stopPropagation(),a&&a!==I&&E(a),P("chat"),w&&T(!1),S({directoryOverride:n.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(A,{name:"add",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),X?null:s.jsx("div",{className:ge("oc-group-body",Ue),children:Me})]})}function TA(t){const e=ot.c(196),{t:n}=pt(),{hideDirectoryControls:r,mobileVariant:a,handleOpenDirectoryDialog:i,openNewSessionDraft:l,canOpenMultiRun:c,openMultiRunLauncher:d,headerActionIconClass:f,headerActionButtonClass:m,isSessionSearchOpen:u,setIsSessionSearchOpen:p,sessionSearchInputRef:b,sessionSearchQuery:g,setSessionSearchQuery:y,hasSessionSearchQuery:x,searchMatchCount:h,collapseAllProjects:j,expandAllProjects:v,openScheduledTasksDialog:C,selectionModeEnabled:k,onToggleSelectionMode:w}=t,N=za(LA),I=za(FA),E=za(RA),P=za(MA);if(r)return null;let T;e[0]!==n?(T=n("sessions.sidebar.header.actions.addProject"),e[0]=n,e[1]=T):T=e[1];let S;e[2]!==f?(S=s.jsx(A,{name:"folder-add",className:f}),e[2]=f,e[3]=S):S=e[3];let M;e[4]!==i||e[5]!==m||e[6]!==T||e[7]!==S?(M=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:m,"aria-label":T,children:S})}),e[4]=i,e[5]=m,e[6]=T,e[7]=S,e[8]=M):M=e[8];let D;e[9]!==n?(D=n("sessions.sidebar.header.actions.addProject"),e[9]=n,e[10]=D):D=e[10];let F;e[11]!==D?(F=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:D})}),e[11]=D,e[12]=F):F=e[12];let _;e[13]!==M||e[14]!==F?(_=s.jsxs(It,{children:[M,F]}),e[13]=M,e[14]=F,e[15]=_):_=e[15];let V;e[16]!==m||e[17]!==f||e[18]!==a||e[19]!==l||e[20]!==n?(V=a?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,className:m,"aria-label":n("sessions.sidebar.header.actions.newSession"),children:s.jsx(A,{name:"chat-new",className:f})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newSession")})})]}):null,e[16]=m,e[17]=f,e[18]=a,e[19]=l,e[20]=n,e[21]=V):V=e[21];let $;e[22]!==n?($=n("sessions.sidebar.header.actions.newMultiRun"),e[22]=n,e[23]=$):$=e[23];const O=!c;let B;e[24]!==f?(B=s.jsx(ov,{className:f}),e[24]=f,e[25]=B):B=e[25];let G;e[26]!==m||e[27]!==d||e[28]!==$||e[29]!==O||e[30]!==B?(G=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:d,className:m,"aria-label":$,disabled:O,children:B})}),e[26]=m,e[27]=d,e[28]=$,e[29]=O,e[30]=B,e[31]=G):G=e[31];let R;e[32]!==n?(R=n("sessions.sidebar.header.actions.newMultiRun"),e[32]=n,e[33]=R):R=e[33];let H;e[34]!==R?(H=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:R})}),e[34]=R,e[35]=H):H=e[35];let J;e[36]!==G||e[37]!==H?(J=s.jsxs(It,{children:[G,H]}),e[36]=G,e[37]=H,e[38]=J):J=e[38];let ne;e[39]!==n?(ne=n("sessions.sidebar.header.actions.scheduledTasks"),e[39]=n,e[40]=ne):ne=e[40];let ue;e[41]!==f?(ue=s.jsx(A,{name:"calendar-schedule",className:f}),e[41]=f,e[42]=ue):ue=e[42];let de;e[43]!==m||e[44]!==C||e[45]!==ne||e[46]!==ue?(de=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:C,className:m,"aria-label":ne,children:ue})}),e[43]=m,e[44]=C,e[45]=ne,e[46]=ue,e[47]=de):de=e[47];let pe;e[48]!==n?(pe=n("sessions.sidebar.header.actions.scheduledTasks"),e[48]=n,e[49]=pe):pe=e[49];let W;e[50]!==pe?(W=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:pe})}),e[50]=pe,e[51]=W):W=e[51];let te;e[52]!==de||e[53]!==W?(te=s.jsxs(It,{children:[de,W]}),e[52]=de,e[53]=W,e[54]=te):te=e[54];let X;e[55]!==J||e[56]!==te||e[57]!==_||e[58]!==V?(X=s.jsxs("div",{className:"flex items-center gap-1.5",children:[_,V,J,te]}),e[55]=J,e[56]=te,e[57]=_,e[58]=V,e[59]=X):X=e[59];let ee;e[60]!==p?(ee=()=>p(EA),e[60]=p,e[61]=ee):ee=e[61];let fe;e[62]!==n?(fe=n("sessions.sidebar.header.actions.searchSessions"),e[62]=n,e[63]=fe):fe=e[63];let be;e[64]!==f?(be=s.jsx(A,{name:"search",className:f}),e[64]=f,e[65]=be):be=e[65];let Ne;e[66]!==m||e[67]!==u||e[68]!==ee||e[69]!==fe||e[70]!==be?(Ne=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ee,className:m,"aria-label":fe,"aria-expanded":u,children:be})}),e[66]=m,e[67]=u,e[68]=ee,e[69]=fe,e[70]=be,e[71]=Ne):Ne=e[71];let se;e[72]!==n?(se=n("sessions.sidebar.header.actions.searchSessions"),e[72]=n,e[73]=se):se=e[73];let ie;e[74]!==se?(ie=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:se})}),e[74]=se,e[75]=ie):ie=e[75];let ae;e[76]!==Ne||e[77]!==ie?(ae=s.jsxs(It,{children:[Ne,ie]}),e[76]=Ne,e[77]=ie,e[78]=ae):ae=e[78];const xe=k&&"bg-interactive-hover text-primary";let Z;e[79]!==m||e[80]!==xe?(Z=ge(m,xe),e[79]=m,e[80]=xe,e[81]=Z):Z=e[81];let me;e[82]!==k||e[83]!==n?(me=n(k?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[82]=k,e[83]=n,e[84]=me):me=e[84];let Y;e[85]!==f?(Y=s.jsx(A,{name:"checkbox-multiple",className:f}),e[85]=f,e[86]=Y):Y=e[86];let Se;e[87]!==w||e[88]!==k||e[89]!==Z||e[90]!==me||e[91]!==Y?(Se=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:w,className:Z,"aria-label":me,"aria-pressed":k,children:Y})}),e[87]=w,e[88]=k,e[89]=Z,e[90]=me,e[91]=Y,e[92]=Se):Se=e[92];let we;e[93]!==k||e[94]!==n?(we=n(k?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[93]=k,e[94]=n,e[95]=we):we=e[95];let ke;e[96]!==we?(ke=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:we})}),e[96]=we,e[97]=ke):ke=e[97];let Fe;e[98]!==Se||e[99]!==ke?(Fe=s.jsxs(It,{children:[Se,ke]}),e[98]=Se,e[99]=ke,e[100]=Fe):Fe=e[100];let Ce;e[101]!==n?(Ce=n("sessions.sidebar.header.actions.sessionDisplayMode"),e[101]=n,e[102]=Ce):Ce=e[102];let Q;e[103]!==f?(Q=s.jsx(A,{name:"equalizer-2",className:f}),e[103]=f,e[104]=Q):Q=e[104];let ce;e[105]!==m||e[106]!==Ce||e[107]!==Q?(ce=s.jsx(Pt,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:m,"aria-label":Ce,children:Q})})}),e[105]=m,e[106]=Ce,e[107]=Q,e[108]=ce):ce=e[108];let ve;e[109]!==n?(ve=n("sessions.sidebar.header.displayMode.label"),e[109]=n,e[110]=ve):ve=e[110];let le;e[111]!==ve?(le=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ve})}),e[111]=ve,e[112]=le):le=e[112];let Ae;e[113]!==ce||e[114]!==le?(Ae=s.jsxs(It,{children:[ce,le]}),e[113]=ce,e[114]=le,e[115]=Ae):Ae=e[115];let Te;e[116]!==E?(Te=()=>E("default"),e[116]=E,e[117]=Te):Te=e[117];let $e;e[118]!==n?($e=n("sessions.sidebar.header.displayMode.default"),e[118]=n,e[119]=$e):$e=e[119];let ye;e[120]!==$e?(ye=s.jsx("span",{children:$e}),e[120]=$e,e[121]=ye):ye=e[121];let q;e[122]!==N?(q=N==="default"?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null,e[122]=N,e[123]=q):q=e[123];let L;e[124]!==Te||e[125]!==ye||e[126]!==q?(L=s.jsxs(Ot,{onClick:Te,className:"flex items-center justify-between",children:[ye,q]}),e[124]=Te,e[125]=ye,e[126]=q,e[127]=L):L=e[127];let U;e[128]!==E?(U=()=>E("minimal"),e[128]=E,e[129]=U):U=e[129];let oe;e[130]!==n?(oe=n("sessions.sidebar.header.displayMode.minimal"),e[130]=n,e[131]=oe):oe=e[131];let Ee;e[132]!==oe?(Ee=s.jsx("span",{children:oe}),e[132]=oe,e[133]=Ee):Ee=e[133];let Oe;e[134]!==N?(Oe=N==="minimal"?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null,e[134]=N,e[135]=Oe):Oe=e[135];let Ie;e[136]!==U||e[137]!==Ee||e[138]!==Oe?(Ie=s.jsxs(Ot,{onClick:U,className:"flex items-center justify-between",children:[Ee,Oe]}),e[136]=U,e[137]=Ee,e[138]=Oe,e[139]=Ie):Ie=e[139];let z;e[140]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(nr,{}),e[140]=z):z=e[140];let De;e[141]!==n?(De=n("sessions.sidebar.header.displayMode.showRecent"),e[141]=n,e[142]=De):De=e[142];let Qe;e[143]!==De?(Qe=s.jsx("span",{children:De}),e[143]=De,e[144]=Qe):Qe=e[144];let tt;e[145]!==I?(tt=I?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null,e[145]=I,e[146]=tt):tt=e[146];let et;e[147]!==Qe||e[148]!==tt||e[149]!==P?(et=s.jsxs(Ot,{onClick:P,className:"flex items-center justify-between",children:[Qe,tt]}),e[147]=Qe,e[148]=tt,e[149]=P,e[150]=et):et=e[150];let We;e[151]===Symbol.for("react.memo_cache_sentinel")?(We=s.jsx(nr,{}),e[151]=We):We=e[151];let at;e[152]===Symbol.for("react.memo_cache_sentinel")?(at=s.jsx(A,{name:"contract-up-down",className:"h-4 w-4"}),e[152]=at):at=e[152];let qe;e[153]!==n?(qe=n("sessions.sidebar.header.displayMode.collapseAll"),e[153]=n,e[154]=qe):qe=e[154];let nt;e[155]!==qe?(nt=s.jsx("span",{children:qe}),e[155]=qe,e[156]=nt):nt=e[156];let Ze;e[157]!==j||e[158]!==nt?(Ze=s.jsxs(Ot,{onClick:j,className:"flex items-center gap-2",children:[at,nt]}),e[157]=j,e[158]=nt,e[159]=Ze):Ze=e[159];let ze;e[160]===Symbol.for("react.memo_cache_sentinel")?(ze=s.jsx(A,{name:"expand-up-down",className:"h-4 w-4"}),e[160]=ze):ze=e[160];let rt;e[161]!==n?(rt=n("sessions.sidebar.header.displayMode.expandAll"),e[161]=n,e[162]=rt):rt=e[162];let Ge;e[163]!==rt?(Ge=s.jsx("span",{children:rt}),e[163]=rt,e[164]=Ge):Ge=e[164];let ct;e[165]!==v||e[166]!==Ge?(ct=s.jsxs(Ot,{onClick:v,className:"flex items-center gap-2",children:[ze,Ge]}),e[165]=v,e[166]=Ge,e[167]=ct):ct=e[167];let Pe;e[168]!==L||e[169]!==Ie||e[170]!==et||e[171]!==Ze||e[172]!==ct?(Pe=s.jsxs(Ps,{align:"end",className:"min-w-[160px]",children:[L,Ie,z,et,We,Ze,ct]}),e[168]=L,e[169]=Ie,e[170]=et,e[171]=Ze,e[172]=ct,e[173]=Pe):Pe=e[173];let Me;e[174]!==Ae||e[175]!==Pe?(Me=s.jsxs(As,{children:[Ae,Pe]}),e[174]=Ae,e[175]=Pe,e[176]=Me):Me=e[176];let Ue;e[177]!==ae||e[178]!==Fe||e[179]!==Me?(Ue=s.jsxs("div",{className:"flex items-center gap-1.5",children:[ae,Fe,Me]}),e[177]=ae,e[178]=Fe,e[179]=Me,e[180]=Ue):Ue=e[180];let He;e[181]!==X||e[182]!==Ue?(He=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[X,Ue]}),e[181]=X,e[182]=Ue,e[183]=He):He=e[183];let lt;e[184]!==x||e[185]!==u||e[186]!==h||e[187]!==b||e[188]!==g||e[189]!==p||e[190]!==y||e[191]!==n?(lt=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:h===1?n("sessions.sidebar.header.search.matchCountSingle",{count:h}):n("sessions.sidebar.header.search.matchCountPlural",{count:h})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(A,{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:g,onChange:ft=>y(ft.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:ft=>{ft.key==="Escape"&&(ft.stopPropagation(),x?y(""):p(!1))}}),g.length>0?s.jsx("button",{type:"button",onClick:()=>y(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null,e[184]=x,e[185]=u,e[186]=h,e[187]=b,e[188]=g,e[189]=p,e[190]=y,e[191]=n,e[192]=lt):lt=e[192];let vt;return e[193]!==He||e[194]!==lt?(vt=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 py-1",children:s.jsxs("div",{className:"flex h-auto min-h-8 flex-col gap-1",children:[He,lt]})}),e[193]=He,e[194]=lt,e[195]=vt):vt=e[195],vt}function EA(t){return!t}function MA(t){return t.toggleRecentSection}function RA(t){return t.setDisplayMode}function FA(t){return t.showRecentSection}function LA(t){return t.displayMode}const zf=7;function OA(t){const e=ot.c(20),{sections:n,renderSessionNode:r}=t,{t:a}=pt();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[l,c]=o.useState(i);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[1]=d):d=e[1];const[f,m]=o.useState(d);let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=v=>{c(C=>{const k=new Set(C);return k.has(v)?k.delete(v):k.add(v),k})},e[2]=u):u=e[2];const p=u;let b;e[3]===Symbol.for("react.memo_cache_sentinel")?(b=v=>{m(C=>{const k=new Set(C);return k.has(v)?k.delete(v):k.add(v),k})},e[3]=b):b=e[3];const g=b;let y,x,h;if(e[4]!==l||e[5]!==f||e[6]!==r||e[7]!==n||e[8]!==a){h=Symbol.for("react.early_return_sentinel");e:{const v=n.filter($A);if(v.length===0){h=null;break e}y="space-y-2 pb-2 pt-1";let C;e[12]!==l||e[13]!==f||e[14]!==r||e[15]!==a?(C=k=>{const w=l.has(k.key),N=f.has(k.key),I=N?k.items:k.items.slice(0,zf),E=k.items.length-I.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>p(k.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":!w,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:w?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:k.title})]}),w?null:s.jsxs("div",{className:ge("space-y-0.5 pl-7"),children:[I.map(P=>r(P.node,0,P.groupDirectory,P.projectId,!1,P.secondaryMeta,"recent")),E>0&&!N?s.jsx("button",{type:"button",onClick:()=>g(k.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,N&&k.items.length>zf?s.jsx("button",{type:"button",onClick:()=>g(k.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]})]},k.key)},e[12]=l,e[13]=f,e[14]=r,e[15]=a,e[16]=C):C=e[16],x=v.map(C)}e[4]=l,e[5]=f,e[6]=r,e[7]=n,e[8]=a,e[9]=y,e[10]=x,e[11]=h}else y=e[9],x=e[10],h=e[11];if(h!==Symbol.for("react.early_return_sentinel"))return h;let j;return e[17]!==y||e[18]!==x?(j=s.jsx("div",{className:y,children:x}),e[17]=y,e[18]=x,e[19]=j):j=e[19],j}function $A(t){return t.items.length>0}const ad="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 _A(t){const e=ot.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:a,onOpenUpdate:i,showRuntimeButtons:l,showUpdateButton:c}=t,d=l===void 0?!0:l,f=c===void 0?!0:c,{t:m}=pt();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:ad,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(A,{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:ad,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(A,{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:ad,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(A,{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 p;e[6]!==i||e[7]!==f||e[8]!==m?(p=f?s.jsx(he,{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]=f,e[8]=m,e[9]=p):p=e[9];let b;return e[10]!==u||e[11]!==p?(b=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[u,p]}),e[10]=u,e[11]=p,e[12]=b):b=e[12],b}const BA=t=>{const e=ot.c(58),{id:n,projectLabel:r,projectDescription:a,projectIcon:i,projectColor:l,projectIconImage:c,projectIconBackground:d,isCollapsed:f,isActiveProject:m,isRepo:u,isDesktopShell:p,isStuck:b,hideDirectoryControls:g,alwaysShowActions:y,onToggle:x,onNewSession:h,onNewWorktreeSession:j,onRenameStart:v,onClose:C,sentinelRef:k,children:w,showCreateButtons:N,hideHeader:I,openSidebarMenuKey:E,setOpenSidebarMenuKey:P}=t,T=N===void 0?!0:N,S=I===void 0?!1:I,{t:M}=pt(),{currentTheme:D}=Sr();let F;e[0]!==n?(F={id:n},e[0]=n,e[1]=F):F=e[1];const{attributes:_,listeners:V,setNodeRef:$,transform:O,transition:B,isDragging:G}=Xl(F),[R,H]=o.useState(!1),J=o.useRef(!1),ne=`project:${n}`,ue=E===ne;let de;e[2]===Symbol.for("react.memo_cache_sentinel")?(de=()=>{H(!1)},e[2]=de):de=e[2];const pe=c?.updatedAt;let W;e[3]!==n||e[4]!==pe?(W=[n,pe],e[3]=n,e[4]=pe,e[5]=W):W=e[5],o.useEffect(de,W);const te=i?oc[i]:null,X=l?To[l]??null:null;let ee;e[6]!==D||e[7]!==n||e[8]!==R||e[9]!==c?(ee=R?null:Do({id:n,iconImage:c},{themeVariant:D.metadata.variant,iconColor:D.colors.surface.foreground}),e[6]=D,e[7]=n,e[8]=R,e[9]=c,e[10]=ee):ee=e[10];const fe=ee;let be;e[11]!==ne||e[12]!==P?(be=ce=>{P(ce?ne:null)},e[11]=ne,e[12]=P,e[13]=be):be=e[13];const Ne=be,se=UA,ie=WA,ae=KA;let xe;e[14]===Symbol.for("react.memo_cache_sentinel")?(xe=ce=>{(ce.button===2||ce.button===0&&ce.ctrlKey)&&(J.current=!0)},e[14]=xe):xe=e[14];const Z=xe;let me;e[15]!==x?(me=()=>{if(J.current){J.current=!1;return}x()},e[15]=x,e[16]=me):me=e[16];const Y=me;let Se;e[17]!==O?(Se=Zl.Transform.toString(O),e[17]=O,e[18]=Se):Se=e[18];let we;e[19]!==Se||e[20]!==B?(we={transform:Se,transition:B},e[19]=Se,e[20]=B,e[21]=we):we=e[21];const ke=G&&"opacity-30";let Fe;e[22]!==ke?(Fe=ge("relative",ke),e[22]=ke,e[23]=Fe):Fe=e[23];let Ce;e[24]!==y||e[25]!==_||e[26]!==Ne||e[27]!==Y||e[28]!==g||e[29]!==S||e[30]!==X||e[31]!==n||e[32]!==fe||e[33]!==m||e[34]!==f||e[35]!==p||e[36]!==ue||e[37]!==u||e[38]!==b||e[39]!==V||e[40]!==C||e[41]!==h||e[42]!==j||e[43]!==v||e[44]!==a||e[45]!==d||e[46]!==te||e[47]!==r||e[48]!==k||e[49]!==T||e[50]!==M?(Ce=S?null:s.jsxs(s.Fragment,{children:[p&&s.jsx("div",{ref:k,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:ge("w-full text-left group/project select-none"),style:{backgroundColor:p&&b?"transparent":void 0},children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",..._,children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:Z,onClick:Y,...V,className:ge("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&&!g?y?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":y?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[s.jsx("span",{className:ge("h-3.5 w-3.5 items-center justify-center text-muted-foreground",y?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:f?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),fe?s.jsx("span",{className:ge("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",y?"hidden":"inline-flex group-hover/project:hidden group-focus-within/project:hidden"),style:d?{backgroundColor:d}:void 0,children:s.jsx("img",{src:fe,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>H(!0)})}):te?s.jsx(A,{name:te,className:ge("h-3.5 w-3.5",y?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:X?{color:X}:void 0}):s.jsx(A,{name:"folder",className:ge("h-3.5 w-3.5 text-muted-foreground/80",y?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:X?{color:X}:void 0})]}),s.jsx("span",{className:ge("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:ge("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",T?"right-7":"right-0.5"),children:[T&&u&&!g&&j?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ce=>{ce.stopPropagation(),j()},className:ge("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground transition-opacity",y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(A,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:M("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(As,{open:ue,onOpenChange:Ne,children:[s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:ge("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",ue?"opacity-100 pointer-events-auto":y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M("sessions.sidebar.project.actions.projectMenu"),onPointerDown:ie,onMouseDown:ae,onClick:se,children:s.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs(Ps,{align:"end",className:"min-w-[180px]",children:[T&&!u&&!g&&h&&s.jsxs(Ot,{onClick:h,children:[s.jsx(A,{name:"add",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.project.actions.newSession")]}),s.jsxs(Ot,{onClick:v,children:[s.jsx(A,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.session.menu.rename")]}),s.jsxs(Ot,{onClick:C,className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"close",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.project.actions.closeProject")]})]})]})]}),T&&h?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:ce=>{ce.stopPropagation(),h()},className:ge("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(A,{name:"add",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:M(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})})]}),e[24]=y,e[25]=_,e[26]=Ne,e[27]=Y,e[28]=g,e[29]=S,e[30]=X,e[31]=n,e[32]=fe,e[33]=m,e[34]=f,e[35]=p,e[36]=ue,e[37]=u,e[38]=b,e[39]=V,e[40]=C,e[41]=h,e[42]=j,e[43]=v,e[44]=a,e[45]=d,e[46]=te,e[47]=r,e[48]=k,e[49]=T,e[50]=M,e[51]=Ce):Ce=e[51];let Q;return e[52]!==w||e[53]!==$||e[54]!==we||e[55]!==Fe||e[56]!==Ce?(Q=s.jsxs("div",{ref:$,style:we,className:Fe,children:[Ce,w]}),e[52]=w,e[53]=$,e[54]=we,e[55]=Fe,e[56]=Ce,e[57]=Q):Q=e[57],Q},VA=t=>{const e=ot.c(21),{id:n,disabled:r,children:a}=t,i=r===void 0?!1:r;let l;e[0]!==i||e[1]!==n?(l={id:n,disabled:i},e[0]=i,e[1]=n,e[2]=l):l=e[2];const{listeners:c,setNodeRef:d,setActivatorNodeRef:f,transform:m,transition:u,isDragging:p}=Xl(l);let b;e[3]!==c||e[4]!==f?(b={listeners:c,setActivatorNodeRef:f},e[3]=c,e[4]=f,e[5]=b):b=e[5];const g=b;let y;e[6]!==m?(y=Zl.Transform.toString(m),e[6]=m,e[7]=y):y=e[7];let x;e[8]!==y||e[9]!==u?(x={transform:y,transition:u},e[8]=y,e[9]=u,e[10]=x):x=e[10];const h=p&&"opacity-50";let j;e[11]!==h?(j=ge("space-y-0.5 rounded-md",h),e[11]=h,e[12]=j):j=e[12];let v;e[13]!==a||e[14]!==g?(v=typeof a=="function"?a(g):a,e[13]=a,e[14]=g,e[15]=v):v=e[15];let C;return e[16]!==d||e[17]!==x||e[18]!==j||e[19]!==v?(C=s.jsx("div",{ref:d,style:x,className:j,children:v}),e[16]=d,e[17]=x,e[18]=j,e[19]=v,e[20]=C):C=e[20],C},zA=o.memo(VA);function UA(t){t.stopPropagation()}function WA(t){t.stopPropagation()}function KA(t){t.stopPropagation()}function HA(t){const e=ot.c(25),{t:n}=pt();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:cb},e[1]=a):a=e[1];const i=mo(bi(po,r),bi(lb,a));let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[2]=l):l=e[2];const c=mo(bi(po,l));if(t.projectSections.length===0){const p=(t.mobileVariant,"");let b;e[3]!==p?(b=ge("space-y-1 pb-1 pl-2.5 pr-2",p),e[3]=p,e[4]=b):b=e[4];let g;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==b?(g=s.jsxs(vs,{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]=g):g=e[8],g}if(t.sectionsForRender.length===0){const p=(t.mobileVariant,"");let b;e[9]!==p?(b=ge("space-y-1 pb-1 pl-2.5 pr-2",p),e[9]=p,e[10]=b):b=e[10];let g;return e[11]!==t.searchEmptyState||e[12]!==b?(g=s.jsx(vs,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:b,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=b,e[13]=g):g=e[13],g}const d=(t.mobileVariant,"");let f;e[14]!==d?(f=ge("space-y-1 pb-1 pl-2.5 pr-2",d),e[14]=d,e[15]=f):f=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 p=t.sectionsForRender.find(x=>x.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!p)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const b=p.groups.find(eD)??p.groups.find(ZA)??p.groups.find(XA)??p.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 g=p.groups.find(QA);return[b,...g&&g.id!==b.id?[g]:[]].map(x=>{const h=`${p.project.id}:${x.id}`,j=x.id===b.id;return s.jsx(o.Fragment,{children:t.renderGroupSessions(x,h,p.project.id,j,null,!0)},h)})})()}):s.jsx(s.Fragment,{children:s.jsxs(fo,{sensors:i,collisionDetection:ho,onDragEnd:p=>{if(t.isInlineEditing)return;const{active:b,over:g}=p;if(!g||b.id===g.id)return;const y=t.sectionsForRender.findIndex(h=>h.project.id===b.id),x=t.sectionsForRender.findIndex(h=>h.project.id===g.id);y===-1||x===-1||y===x||t.reorderProjects(y,x)},children:[s.jsx(Al,{items:t.sectionsForRender.map(YA),strategy:fd,children:t.sectionsForRender.map(p=>{const b=p.project,g=b.id,y=zh(b.label?.trim()||Ja(b.normalizedPath,t.homeDirectory)||b.normalizedPath),x=xo(b.normalizedPath,t.homeDirectory),h=t.collapsedProjects.has(g),j=g===t.activeProjectId,v=t.projectRepoStatus.get(g),C=t.getOrderedGroups(g,p.groups),k=C.find(JA)??null,w=k?C.filter(N=>N.id!==k.id):C;return s.jsx(BA,{id:g,projectLabel:y,projectDescription:x,projectIcon:b.icon,projectColor:b.color,projectIconImage:b.iconImage,projectIconBackground:b.iconBackground,isCollapsed:h,isActiveProject:j,isRepo:!!v,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(g),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onToggle:()=>t.toggleProject(g),onNewSession:()=>{g!==t.activeProjectId&&t.setActiveProjectIdOnly(g),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:b.normalizedPath})},onNewWorktreeSession:()=>{g!==t.activeProjectId&&t.setActiveProjectIdOnly(g),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(g),onClose:()=>t.removeProject(g),sentinelRef:N=>{t.projectHeaderSentinelRefs.current.set(g,N)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:h?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:p.groups.length>0?s.jsxs(fo,{sensors:c,collisionDetection:ho,onDragEnd:N=>{if(t.isInlineEditing)return;const{active:I,over:E}=N;if(!E||I.id===E.id)return;const P=w.findIndex(D=>D.id===I.id),T=w.findIndex(D=>D.id===E.id);if(P===-1||T===-1||P===T)return;const S=uh(w,P,T).map(qA),M=k?[k.id,...S]:S;t.setGroupOrderByProject(D=>{const F=new Map(D);return F.set(g,M),F})},children:[k?t.renderGroupSessions(k,`${g}:${k.id}`,g,!0):null,s.jsx(Al,{items:w.map(GA),strategy:fd,children:w.map(N=>{const I=`${g}:${N.id}`;return s.jsx(zA,{id:N.id,disabled:t.isInlineEditing,children:E=>t.renderGroupSessions(N,I,g,!1,E)},N.id)})}),s.jsx(Dl,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})},g)})}),s.jsx(Dl,{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]!==f||e[23]!==m?(u=s.jsxs(vs,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:f,children:[t.topContent,m]}),e[21]=t.topContent,e[22]=f,e[23]=m,e[24]=u):u=e[24],u}function GA(t){return t.id}function qA(t){return t.id}function JA(t){return t.isMain}function YA(t){return t.project.id}function QA(t){return t.isArchivedBucket}function XA(t){return t.isMain}function ZA(t){return t.sessions.length>0}function eD(t){return t.isMain&&t.sessions.length>0}function tD(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"),l=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${a}, ${i}:${l}`}function sD(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 nD(t){const e=t.info.role==="user"?"User":"Assistant",n=tD(t.info.time?.created),r=sD(t),a=n&&r?`${n} (${r})`:n||r;return a?`**${e}**
|
|
195
|
+
|
|
196
|
+
*${a}*`:`**${e}**`}function rD(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function cx(t){const e=nD(t),n=rD(t.parts).trim();return n?`${e}
|
|
197
|
+
|
|
198
|
+
${n}`:""}function dx(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",a=`${n} Sub-agent: ${t.title}${r}
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
`,i=t.records.map(cx).filter(Boolean).join(`
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
`),l=[a+i];for(const c of t.children)l.push(dx(c,e+1));return l.join(`
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
`)}function aD(t,e,n){const r=e?.trim()||"Session",a=new Date().toISOString().split("T")[0],i=`# ${r}
|
|
211
|
+
|
|
212
|
+
*Exported on ${a}*
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
`,l=t.map(cx).filter(Boolean).join(`
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
`);let c=i+l;if(n&&n.length>0){const d=n.map(f=>dx(f,1)).join(`
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
`);c+=`
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
`+d}return c}function iD(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 oD(t,e){const n=await lv(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 lD(t){const e=dr()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await cv(t)?!0:El(t)}function cD(){return iu()}function dD(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 uD=(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 l of i)r.has(l)||(r.add(l),n.push(l))}return n},br=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(),l=new Set(i.selectedIds);let c=i.scopeKey,d=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(l.clear(),c=r,d=null):c===null&&r!==null&&(c=r);const m=a&&a.length>0?[n,...a]:[n];if(l.has(n)){for(const p of m)l.delete(p);d===n&&(d=null)}else{for(const p of m)l.add(p);d=n}l.size===0?t({selectedIds:l,scopeKey:null,anchorId:null}):t({selectedIds:l,scopeKey:c,anchorId:d})},setRange:(n,r,a,i,l)=>{const c=e();if(a.length===0)return;const d=n&&a.includes(n)?n:a[0],f=a.indexOf(d),m=a.indexOf(r);if(f<0||m<0)return;const[u,p]=f<=m?[f,m]:[m,f],b=a.slice(u,p+1),g=uD(b,l),x=i!==null&&c.scopeKey!==null&&i!==c.scopeKey?new Set:new Set(c.selectedIds);for(const h of g)x.add(h);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}))}})),mD=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,ux=/^g[1-9]\d*$/,Xi=(t,e,n,r,a)=>{if(!mD.test(t)||e!==void 0&&!ux.test(e)||!n?.trim()||!r?.trim()||n!==n.trim()||r!==r.trim())return null;if(a===void 0)return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!1};if(a==="fusion")return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!0};if(!/^\d+$/.test(a))return null;const i=Number.parseInt(a,10);return!Number.isSafeInteger(i)||i<=0?null:{groupSlug:t,runGroup:e,providerID:n,modelID:r,index:i,fusion:!1}},Il=t=>{if(!t)return null;const e=t.split("/");if(e.length<3||e.length>5)return null;const[n]=e;if(e.length===3)return Xi(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,c,d,f]=e;return ux.test(c)?Xi(n,c,d,f,void 0):Xi(n,void 0,c,d,f)}const[,r,a,i,l]=e;return r===""?Xi(n,void 0,a,i,l):Xi(n,r,a,i,l)},pD=t=>{const e=[t.groupSlug];return t.runGroup&&e.push(t.runGroup),e.push(t.providerID,t.modelID),t.index!==void 0&&e.push(String(t.index)),e.join("/")},fD=(t,e,n,r)=>{const a=[t];return r&&a.push(r),a.push(e,n,"fusion"),a.join("/")},mx=t=>{const e=ot.c(35),{value:n,onChange:r,className:a,disabled:i,id:l,portalToBody:c}=t,{t:d}=pt(),f=jt(hD),m=jt(gD),u=jt(xD);let p;e[0]!==f?(p=f(),e[0]=f,e[1]=p):p=e[1];const b=p;let g;e[2]!==b?(g=b.filter(bD),e[2]=b,e[3]=g):g=e[3];const y=g;let x,h;e[4]!==m?(x=()=>{m()},h=[m],e[4]=m,e[5]=x,e[6]=h):(x=e[5],h=e[6]),o.useEffect(x,h);let j,v;e[7]!==u||e[8]!==i||e[9]!==r||e[10]!==y||e[11]!==n?(j=()=>{if(i)return;const S=n.trim();if(S.length>0&&y.some(F=>F.name===S))return;const M=typeof u=="string"&&u.trim().length>0?u.trim():null;if(M&&y.some(F=>F.name===M)){r(M);return}const D=y[0]?.name;D&&r(D)},v=[u,i,r,y,n],e[7]=u,e[8]=i,e[9]=r,e[10]=y,e[11]=n,e[12]=j,e[13]=v):(j=e[12],v=e[13]),o.useEffect(j,v);const C=n.trim().length>0?n:void 0;let k;e[14]!==a?(k=ge("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]=k):k=e[15];let w;e[16]!==d?(w=d("multirun.agentSelector.placeholder"),e[16]=d,e[17]=w):w=e[17];let N;e[18]!==w?(N=s.jsx(ms,{placeholder:w}),e[18]=w,e[19]=N):N=e[19];let I;e[20]!==l||e[21]!==k||e[22]!==N?(I=s.jsx(rs,{id:l,size:"lg",className:k,children:N}),e[20]=l,e[21]=k,e[22]=N,e[23]=I):I=e[23];let E;e[24]!==y?(E=y.length>0&&s.jsx(bd,{children:y.map(yD)}),e[24]=y,e[25]=E):E=e[25];let P;e[26]!==c||e[27]!==E?(P=s.jsx(as,{fitContent:!0,portalToBody:c,children:E}),e[26]=c,e[27]=E,e[28]=P):P=e[28];let T;return e[29]!==i||e[30]!==r||e[31]!==C||e[32]!==I||e[33]!==P?(T=s.jsxs(ns,{value:C,onValueChange:r,disabled:i,children:[I,P]}),e[29]=i,e[30]=r,e[31]=C,e[32]=I,e[33]=P,e[34]=T):T=e[34],T};function hD(t){return t.getVisibleAgents}function gD(t){return t.loadAgents}function xD(t){return t.currentAgentName}function bD(t){return t.mode!=="subagent"}function yD(t){return s.jsx(Rt,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const px="h-7",uo=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,vD=t=>{const e=ot.c(12),{model:n,instanceIndex:r,totalSameModel:a,onRemove:i}=t,l=n.displayName||`${n.providerID}/${n.modelID}`,c=a>1?`${l} (${r})`:l;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=ge("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",px),e[0]=d):d=e[0];let f;e[1]!==n.providerID?(f=s.jsx(wr,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=f):f=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(A,{name:"close",className:"h-3.5 w-3.5"}),e[5]=u):u=e[5];let p;e[6]!==i?(p=s.jsx("button",{type:"button",onClick:i,className:"text-muted-foreground hover:text-foreground ml-0.5",children:u}),e[6]=i,e[7]=p):p=e[7];let b;return e[8]!==f||e[9]!==m||e[10]!==p?(b=s.jsxs("div",{className:d,children:[f,m,p]}),e[8]=f,e[9]=m,e[10]=p,e[11]=b):b=e[11],b},fx=t=>{const e=ot.c(117),{selectedModels:n,onAdd:r,onRemove:a,onUpdate:i,minModels:l,addButtonLabel:c,showChips:d,maxModels:f,addButtonClassName:m,dropdownSide:u,dropdownClassName:p,containerClassName:b,triggerIcon:g}=t,y=d===void 0?!0:d,x=u===void 0?"top":u,{t:h}=pt(),j=jt(wD),v=jt(jD),C=_e(ND),k=_e(SD),{favoriteModelsList:w,recentModelsList:N}=jh(),[I,E]=o.useState(!1),[P,T]=o.useState(""),[S,M]=o.useState(null),D=o.useRef(null),F=o.useRef(null),_=f===1,V=f===void 0||n.length<f||_;let $;if(e[0]!==n){$=new Map;for(const U of n){const oe=`${U.providerID}:${U.modelID}`;$.set(oe,($.get(oe)||0)+1)}e[0]=n,e[1]=$}else $=e[1];const O=$;let B;e[2]!==n?(B=U=>n.filter(Ee=>Ee.providerID===U.providerID&&Ee.modelID===U.modelID).findIndex(Ee=>Ee.instanceId===U.instanceId)+1,e[2]=n,e[3]=B):B=e[3];const G=B;let R,H;e[4]!==x||e[5]!==I?(R=()=>{if(!I||!F.current)return;const U=F.current.getBoundingClientRect();if(x==="bottom"){const De=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-U.bottom-16-112;M(Math.max(160,Math.min(320,De)));return}let oe=F.current.parentElement;for(;oe&&!(oe.getAttribute("role")==="dialog"||oe.hasAttribute("data-scroll-shadow"));){const Ie=getComputedStyle(oe);if(Ie.overflow==="auto"||Ie.overflow==="hidden"||Ie.overflowY==="auto"||Ie.overflowY==="hidden")break;oe=oe.parentElement}const Ee=oe?oe.getBoundingClientRect().top:0,Oe=U.top-Ee-16;M(Math.max(150,Math.min(300,Oe)))},H=[x,I],e[4]=x,e[5]=I,e[6]=R,e[7]=H):(R=e[6],H=e[7]),o.useEffect(R,H);let J,ne;e[8]!==V||e[9]!==I?(J=()=>{!V&&I&&(E(!1),T(""))},ne=[V,I],e[8]=V,e[9]=I,e[10]=J,e[11]=ne):(J=e[10],ne=e[11]),o.useEffect(J,ne);let ue,de;e[12]!==I?(ue=()=>{if(!I)return;const U=oe=>{D.current&&!D.current.contains(oe.target)&&(E(!1),T(""))};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},de=[I],e[12]=I,e[13]=ue,e[14]=de):(ue=e[13],de=e[14]),o.useEffect(ue,de);let pe;e[15]!==_||e[16]!==r||e[17]!==i||e[18]!==n.length?(pe=U=>{const oe={providerID:U.providerID,modelID:U.modelID,displayName:U.model.name||U.modelID,instanceId:uo()};_&&n.length>0&&i?i(0,oe):r(oe),_&&(E(!1),T(""))},e[15]=_,e[16]=r,e[17]=i,e[18]=n.length,e[19]=pe):pe=e[19];const W=pe;let te;e[20]!==h?(te=h("multirun.modelMultiSelect.search.placeholder"),e[20]=h,e[21]=te):te=e[21];let X;e[22]!==h?(X=h("multirun.modelMultiSelect.search.noResults"),e[22]=h,e[23]=X):X=e[23];let ee;e[24]!==h?(ee=h("multirun.modelMultiSelect.sections.favorites"),e[24]=h,e[25]=ee):ee=e[25];let fe;e[26]!==h?(fe=h("multirun.modelMultiSelect.sections.recent"),e[26]=h,e[27]=fe):fe=e[27];let be;e[28]!==h?(be=h("multirun.modelMultiSelect.keyboard.hint"),e[28]=h,e[29]=be):be=e[29];let Ne;e[30]!==h?(Ne=h("settings.agents.modelSelector.actions.favorite"),e[30]=h,e[31]=Ne):Ne=e[31];let se;e[32]!==h?(se=h("settings.agents.modelSelector.actions.unfavorite"),e[32]=h,e[33]=se):se=e[33];let ie;e[34]!==h?(ie=h("chat.modelControls.capabilities"),e[34]=h,e[35]=ie):ie=e[35];let ae;e[36]!==h?(ae=h("chat.modelControls.capability.toolCalling"),e[36]=h,e[37]=ae):ae=e[37];let xe;e[38]!==h?(xe=h("chat.modelControls.capability.reasoning"),e[38]=h,e[39]=xe):xe=e[39];let Z;e[40]!==h?(Z=h("chat.modelControls.input"),e[40]=h,e[41]=Z):Z=e[41];let me;e[42]!==h?(me=h("chat.modelControls.output"),e[42]=h,e[43]=me):me=e[43];let Y;e[44]!==h?(Y=h("chat.modelControls.costPerMillion"),e[44]=h,e[45]=Y):Y=e[45];let Se;e[46]!==te||e[47]!==X||e[48]!==ee||e[49]!==fe||e[50]!==be||e[51]!==Ne||e[52]!==se||e[53]!==ie||e[54]!==ae||e[55]!==xe||e[56]!==Z||e[57]!==me||e[58]!==Y?(Se={searchPlaceholder:te,noResults:X,favorites:ee,recent:fe,keyboardHint:be,favorite:Ne,unfavorite:se,capabilities:ie,capabilityToolCalling:ae,capabilityReasoning:xe,input:Z,output:me,costPerMillion:Y},e[46]=te,e[47]=X,e[48]=ee,e[49]=fe,e[50]=be,e[51]=Ne,e[52]=se,e[53]=ie,e[54]=ae,e[55]=xe,e[56]=Z,e[57]=me,e[58]=Y,e[59]=Se):Se=e[59];const we=Se;let ke;e[60]!==b?(ke=ge("relative",b),e[60]=b,e[61]=ke):ke=e[61];let Fe;e[62]!==m?(Fe=ge(px,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",m),e[62]=m,e[63]=Fe):Fe=e[63];const Ce=!V;let Q;e[64]!==I?(Q=()=>{E(!I)},e[64]=I,e[65]=Q):Q=e[65];let ce;e[66]!==g?(ce=g??s.jsx(A,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=g,e[67]=ce):ce=e[67];let ve;e[68]!==c||e[69]!==h?(ve=c??h("multirun.modelMultiSelect.actions.addModel"),e[68]=c,e[69]=h,e[70]=ve):ve=e[70];let le;e[71]!==Fe||e[72]!==Ce||e[73]!==Q||e[74]!==ce||e[75]!==ve?(le=s.jsxs(he,{ref:F,type:"button",variant:"outline",size:"sm",className:Fe,disabled:Ce,onClick:Q,children:[ce,ve]}),e[71]=Fe,e[72]=Ce,e[73]=Q,e[74]=ce,e[75]=ve,e[76]=le):le=e[76];let Ae;e[77]!==S||e[78]!==V||e[79]!==p||e[80]!==x||e[81]!==w||e[82]!==W||e[83]!==k||e[84]!==I||e[85]!==we||e[86]!==O||e[87]!==v||e[88]!==j||e[89]!==N||e[90]!==P||e[91]!==C?(Ae=I?s.jsx("div",{className:ge("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",x==="top"?"bottom-full mb-1":"top-full mt-1",p),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:s.jsx(Nh,{providers:j,favoriteModels:w,recentModels:N,modelsMetadata:v,searchQuery:P,onSearchQueryChange:T,onSelect:W,labels:we,selectionCount:U=>O.get(`${U.providerID}:${U.modelID}`)||0,disabled:!V,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:S?`${S}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:I,isFavorite:U=>k(U.providerID,U.modelID),onToggleFavorite:U=>C(U.providerID,U.modelID),onEscape:()=>{E(!1),T("")}})}):null,e[77]=S,e[78]=V,e[79]=p,e[80]=x,e[81]=w,e[82]=W,e[83]=k,e[84]=I,e[85]=we,e[86]=O,e[87]=v,e[88]=j,e[89]=N,e[90]=P,e[91]=C,e[92]=Ae):Ae=e[92];let Te;e[93]!==ke||e[94]!==le||e[95]!==Ae?(Te=s.jsxs("div",{className:ke,ref:D,children:[le,Ae]}),e[93]=ke,e[94]=le,e[95]=Ae,e[96]=Te):Te=e[96];let $e;e[97]!==G||e[98]!==O||e[99]!==a||e[100]!==i||e[101]!==j||e[102]!==n||e[103]!==y||e[104]!==h?($e=y&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((U,oe)=>{const Ee=`${U.providerID}:${U.modelID}`,Oe=O.get(Ee)||1,Ie=G(U),De=j.find(We=>We.id===U.providerID)?.models?.find(We=>We.id===U.modelID),Qe=De?.variants?Object.keys(De.variants):[],tt=Qe.length>0,et=U.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(vD,{model:U,instanceIndex:Ie,totalSameModel:Oe,onRemove:()=>a(oe)}),tt&&s.jsxs(ns,{value:et,onValueChange:We=>{if(!i)return;i(oe,{...U,variant:We==="__default__"?void 0:We})},children:[s.jsxs(rs,{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(A,{name:"brain-ai-3",className:ge("h-3.5 w-3.5 flex-shrink-0",et==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(ms,{placeholder:h("multirun.modelMultiSelect.variant.placeholder"),children:We=>We==="__default__"?h("multirun.modelMultiSelect.variant.default"):We})]}),s.jsxs(as,{fitContent:!0,children:[s.jsx(Rt,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:h("multirun.modelMultiSelect.variant.default")}),Qe.map(kD)]})]})]},U.instanceId)})}),e[97]=G,e[98]=O,e[99]=a,e[100]=i,e[101]=j,e[102]=n,e[103]=y,e[104]=h,e[105]=$e):$e=e[105];let ye;e[106]!==Te||e[107]!==$e?(ye=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[Te,$e]}),e[106]=Te,e[107]=$e,e[108]=ye):ye=e[108];let q;e[109]!==f||e[110]!==l||e[111]!==n.length||e[112]!==h?(q=l!==void 0&&n.length<l&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:f!==void 0?h("multirun.modelMultiSelect.validation.minToMax",{min:l,max:f}):h("multirun.modelMultiSelect.validation.minOnly",{min:l})}),e[109]=f,e[110]=l,e[111]=n.length,e[112]=h,e[113]=q):q=e[113];let L;return e[114]!==ye||e[115]!==q?(L=s.jsxs("div",{className:"space-y-2",children:[ye,q]}),e[114]=ye,e[115]=q,e[116]=L):L=e[116],L};function wD(t){return t.providers}function jD(t){return t.modelsMetadata}function ND(t){return t.toggleFavoriteModel}function SD(t){return t.isFavoriteModel}function kD(t){return s.jsx(Rt,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const CD=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
|
|
229
|
+
|
|
230
|
+
--- RESULT ${n+1}: ${r} ---
|
|
231
|
+
${e.trim()}
|
|
232
|
+
--- END RESULT ${n+1} ---`},Uf=(t,e)=>Lt.getState().getWorktreeMetadata(t)?.projectDirectory??e,ID=async t=>{const e=t.directory??void 0,n=dv(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 l=a[i];if(l.info?.role==="assistant")return cm(l.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const a=n[r];if(a.role==="assistant")return cm(uv(a.id,e)).trim()}return""};function PD({session:t,open:e,onOpenChange:n}){const{t:r}=pt(),a=Qd(),i=wa($=>$.activeSessions),l=wa($=>$.archivedSessions),c=jt($=>$.providers),d=jt($=>$.currentProviderId),f=jt($=>$.currentModelId),m=jt($=>$.currentAgentName),[u,p]=o.useState(d??""),[b,g]=o.useState(f??""),[y,x]=o.useState(()=>d&&f?[{providerID:d,modelID:f,instanceId:uo()}]:[]),[h,j]=o.useState(""),[v,C]=o.useState(m??""),[k,w]=o.useState([]),[N,I]=o.useState(!1),E=o.useMemo(()=>Il(t.title),[t.title]),P=o.useMemo(()=>{const $=new Map;for(const O of a)$.set(O.id,O);for(const O of i)$.set(O.id,O);for(const O of l)$.set(O.id,O);return t.id&&$.set(t.id,t),Array.from($.values())},[i,l,a,t]);o.useEffect(()=>{if(!e||!E)return;const $=Lt.getState().getDirectoryForSession(t.id),O=Uf(t.id,$),B=P.map(G=>{const R=Il(G.title);if(!R||R.groupSlug!==E.groupSlug||R.fusion||(R.runGroup??null)!==(E.runGroup??null))return null;const H=Lt.getState().getDirectoryForSession(G.id)??ao(G),J=Uf(G.id,H);return O&&J&&O!==J?null:{session:G,directory:H,projectDirectory:J}}).filter(G=>G!==null).sort((G,R)=>(G.session.time?.created??0)-(R.session.time?.created??0));w(B)},[P,e,E,t.id]);const S=c.find($=>$.id===u)?.models.find($=>$.id===b),M=S?.variants?Object.keys(S.variants):[],D=!!(E&&u&&b&&k.length>0&&!N),F=o.useCallback($=>{x([$]),p($.providerID),g($.modelID),j("")},[]),_=y[0]?.displayName||y[0]?.modelID||r("multirun.fusion.model.placeholder"),V=async()=>{if(!(!E||!u||!b)){I(!0);try{const $=await Promise.all(k.map(ne=>ID(ne))),O=k.map((ne,ue)=>({source:ne,text:$[ue]??""})).filter(ne=>ne.text.trim().length>0);if(O.length===0){K.error(r("multirun.fusion.toast.noOutputs"));return}const B=k[0]?.projectDirectory??k[0]?.directory??null,G=fD(E.groupSlug,u,b,E.runGroup),[R,H]=await Promise.all([Cn("session.fusion.visible"),Cn("session.fusion.instructions")]),J=await Lt.getState().createSession(G,B,null);if(!J)throw new Error("Failed to create fusion session");Lt.getState().setCurrentSession(J.id,B),n(!1),await rn.withDirectory(B??rn.getDirectory(),()=>rn.sendMessage({id:J.id,providerID:u,modelID:b,variant:h||void 0,agent:v||void 0,text:R,additionalParts:[{text:H,synthetic:!0},...O.map((ne,ue)=>({text:CD(ne.source,ne.text,ue),synthetic:!0})),{text:`
|
|
233
|
+
|
|
234
|
+
--- FUSION INPUTS END ---
|
|
235
|
+
Now write the final fused answer.`,synthetic:!0}]}))}catch($){console.error("[MultiRunFusion] Failed to start fusion",$),K.error(r("multirun.fusion.toast.failed"))}finally{I(!1)}}};return s.jsx(ls,{open:e,onOpenChange:n,children:s.jsxs(os,{className:"max-w-xl overflow-visible",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:r("multirun.fusion.title")}),s.jsx(ys,{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(fx,{selectedModels:y,onAdd:F,onUpdate:($,O)=>F(O),onRemove:()=>{x([]),p(""),g(""),j("")},maxModels:1,addButtonLabel:_,showChips:!1,addButtonClassName:"h-8 w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:u?s.jsx(wr,{providerId:u,className:"h-3.5 w-3.5 mr-1"}):void 0})}),M.length>0?s.jsxs(ns,{value:h||"__default__",onValueChange:$=>j($==="__default__"?"":$),children:[s.jsxs(rs,{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(A,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(ms,{children:$=>$==="__default__"?r("multirun.modelMultiSelect.variant.default"):$})]}),s.jsxs(as,{fitContent:!0,portalToBody:!0,children:[s.jsx(Rt,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),M.map($=>s.jsx(Rt,{value:$,children:$},$))]})]}):null,s.jsx(mx,{value:v,onChange:C,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:k.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:k.map($=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(wr,{providerId:Il($.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:$.session.title||$.session.id}),s.jsx("button",{type:"button",onClick:()=>w(O=>O.filter(B=>B.session.id!==$.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"h-4 w-4"})})]},$.session.id))})]}),s.jsxs(Rs,{children:[s.jsx(he,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(he,{onClick:V,disabled:!D,children:r(N?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function AD(t){const e=ot.c(7);let n,r,a,i,l;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"}),l=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]=l):(n=e[0],r=e[1],a=e[2],i=e[3],l=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,l]}),e[5]=t,e[6]=c):c=e[6],c}const Wf=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),La=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(La(n,e))return!0;return!1},Hd=(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(Hd(i,e,n,r))return!0;return!1},DD=(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||Wf(t.node)!==Wf(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=La(t.node,t.currentSessionId),u=La(e.node,e.currentSessionId);if(m||u)return!1}if(t.pinnedSessionIds.has(a)!==e.pinnedSessionIds.has(i))return!1;{const m=t.renderContext??"project",u=e.renderContext??"project",p=t.archivedBucket??!1,b=e.archivedBucket??!1,g=`${m}:${p?"archived":"active"}:${a}`,y=`${u}:${b?"archived":"active"}:${i}`;if(t.expandedParents.has(g)!==e.expandedParents.has(y))return!1}if(t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const m=La(t.node,t.editingId),u=La(e.node,e.editingId);if(m||u)return!1}if(t.editTitle!==e.editTitle){const m=La(t.node,t.editingId),u=La(e.node,e.editingId);if(m||u)return!1}if(t.copiedSessionId===a!=(e.copiedSessionId===i))return!1;const l=Hd(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),c=Hd(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(l!==c)return!1;const d=xs(n.directory??null)??xs(t.groupDirectory??null),f=xs(r.directory??null)??xs(e.groupDirectory??null);return!(d!==f||(d?t.directoryStatus.get(d):null)!==(f?e.directoryStatus.get(f):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 TD(t){const{t:e}=pt(),{node:n,depth:r=0,groupDirectory:a,projectId:i,archivedBucket:l=!1,directoryStatus:c,currentSessionId:d,pinnedSessionIds:f,expandedParents:m,hasSessionSearchQuery:u,normalizedSessionSearchQuery:p,notifyOnSubtasks:b,editingId:g,setEditingId:y,editTitle:x,setEditTitle:h,handleSaveEdit:j,handleCancelEdit:v,toggleParent:C,handleSessionSelect:k,handleSessionDoubleClick:w,togglePinnedSession:N,handleShareSession:I,copiedSessionId:E,handleCopyShareUrl:P,handleUnshareSession:T,openSidebarMenuKey:S,setOpenSidebarMenuKey:M,renamingFolderId:D,getFoldersForScope:F,getSessionFolderId:_,removeSessionFromFolder:V,addSessionToFolder:$,createFolderAndStartRename:O,openContextPanelTab:B,handleDeleteSession:G,mobileVariant:R,alwaysShowActions:H,renderSessionNode:J,secondaryMeta:ne,renderContext:ue="project"}=t,de=!!ne?.projectLabel,pe=!!ne?.branchLabel,te=za(Je=>Je.displayMode)==="minimal",X=o.useMemo(()=>un(),[]),ee=o.useMemo(()=>Xd(),[]),fe=o.useContext(mv),be=X?"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",Ne=X?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",se=X,ie=!l&&!R,ae=te?X?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":X?ie&&se?"group-hover:pr-18":ie||se?"group-hover:pr-12":"group-hover:pr-5":ie?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",xe=ie?"pr-13":"pr-7",Z=o.useRef(!1),[me,Y]=o.useState(!1),Se=o.useRef(g);Se.current=g;const we=o.useRef(null),ke=o.useRef(j);ke.current=j;const Fe=o.useRef(null),Ce=n.session,ce=xh(Ce.id)??Ce,ve=xs(Ce.directory??null)??xs(a??null),le=pv(ve??void 0),Ae=uu(),Te=br(Je=>Je.enabled),$e=br(o.useCallback(Je=>Je.selectedIds.has(Ce.id),[Ce.id])),ye=br(Je=>Je.toggleSelected),q=br(Je=>Je.setRange),L=o.useCallback(Je=>{const Ct=[],kt=Kt=>{Kt.children.forEach(Tt=>{Ct.push(Tt.session.id),kt(Tt)})};return kt(Je),Ct},[]),[U,oe]=o.useState(!1),[Ee,Oe]=o.useState(!0),Ie=`${ue}:${l?"archived":"active"}:${Ce.id}`,z=Uh(o.useCallback(Je=>!!Je.sessionMemoryState.get(Ce.id)?.isZombie,[Ce.id])),De=fv(Ce.id),Qe=hv(Ce.id,ve??void 0),et=(ve?c.get(ve):null)==="missing",We=d===Ce.id,at=ce.title||e("sessions.sidebar.session.untitled"),qe=n.children.length>0,nt=f.has(Ce.id),Ze=Ie,ze=u?!0:m.has(Ze),rt=!!ce.parentID,ct=gv(Ce.id)>0&&(!rt||b),Pe=ce.summary,Me=vh(Pe),Ue=ce.time?.updated||ce.time?.created||Date.now(),He=xv(Ue),lt=wv(Ue),vt=S===Ie,ft=o.useMemo(()=>Il(ce.title)!==null,[ce.title]),[dt,Dt]=o.useState(!1),Qt=o.useMemo(()=>L(n).length,[L,n]),Ft=o.useCallback(async Je=>{const Ct=[];let kt=0;for(const Kt of Je)try{await Ae.ensureSessionRenderable(Kt.session.id);const Tt=dm(le.getState(),Kt.session.id).list,gs=Kt.session.title||e("sessions.sidebar.session.export.untitledSubagent"),js=Kt.session.agent,Ls=await Ft(Kt.children);kt+=Ls.skipped,Ct.push({title:gs,agent:js,records:Tt,children:Ls.children})}catch{kt+=L(Kt).length+1}return{children:Ct,skipped:kt}},[L,le,Ae,e]),qt=o.useCallback(Je=>{Je<=0||K.warning(Je===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:Je}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:Je}))},[e]),gt=o.useCallback(async Je=>{if(!ve){K.error(e("sessions.sidebar.session.export.nothingToExport"));return}await Ae.ensureSessionRenderable(Ce.id);const Ct=dm(le.getState(),Ce.id).list;if(Ct.length===0){K.error(e("sessions.sidebar.session.export.nothingToExport"));return}let kt,Kt=0;if(Je&&n.children.length>0){const Ls=await Ft(n.children);kt=Ls.children,Kt=Ls.skipped}const Tt=aD(Ct,ce.title??null,kt),gs=dD(ce.title??null),js=await oD(Tt,gs);if(js){K.success(e("sessions.sidebar.session.export.success"),{action:{label:e(cD()),onClick:()=>{lD(js).then(Ls=>{Ls||K.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),qt(Kt);return}iD(Tt,gs),K.success(e("sessions.sidebar.session.export.success")),qt(Kt)},[Ft,le,n.children,ce.title,Ce.id,ve,qt,Ae,e]),zt=o.useCallback(async()=>{if(n.children.length>0){Oe(!0),oe(!0);return}await gt(!1)},[gt,n.children.length]),es=o.useCallback(()=>{ve&&ra("desktop_open_session_mini_chat_window",{sessionId:Ce.id,directory:ve}).catch(Je=>{console.warn("[session-sidebar] failed to open mini chat window",Je)})},[Ce.id,ve]);if(o.useEffect(()=>{if(g!==Ce.id)return;const Je=Ct=>{Fe.current&&!Fe.current.contains(Ct.target)&&ke.current()};return document.addEventListener("mousedown",Je),()=>document.removeEventListener("mousedown",Je)},[g,Ce.id]),g===Ce.id)return s.jsx("div",{className:ge("group relative flex items-center rounded-sm px-1.5 py-1",r>0&&"pl-[20px]"),children:s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:[s.jsxs("form",{ref:Fe,className:"flex w-full items-center gap-2",onSubmit:Je=>{Je.preventDefault(),j()},children:[s.jsx("input",{value:x,onChange:Je=>h(Je.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:Je=>{if(Je.key==="Escape"){Je.stopPropagation(),v();return}(Je.key===" "||Je.key==="Enter")&&Je.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(A,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:v,"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(A,{name:"close",className:"size-4"})})]}),te?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:[qe?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:ze?s.jsx(A,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(A,{name:"arrow-right-s",className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:He}),Me?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:["+",Me.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",Me.deletions]})]}):null,de?s.jsx("span",{className:"truncate",children:ne?.projectLabel}):null,pe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ne?.branchLabel})]}):null]})})]})},Ce.id);const is=De?.type??"idle",cs=is==="busy"||is==="retry",hs=Qe.length,Ye=cs||!cs&&ct&&!We,Mt=cs?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")}),Bt=Ye||nt?s.jsxs("span",{className:ge("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",te?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",Ye&&nt?"left-[-18px] w-6":"left-[-10px] w-3.5",qe&&!H?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[Ye?Mt:null,nt?s.jsx(A,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,wt=qe?s.jsx("span",{role:"button",tabIndex:0,onClick:Je=>{Je.stopPropagation(),C(Ze)},onKeyDown:Je=>{(Je.key==="Enter"||Je.key===" ")&&(Je.preventDefault(),Je.stopPropagation(),C(Ze))},className:ge("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",te?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",te&&Ye&&!H?"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(ze?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:ze?s.jsx(A,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(A,{name:"arrow-right-s",className:"h-3 w-3"})}):null,Zt=z?s.jsx(A,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,us=Je=>{M(Je?Ie:null)},Es=Je=>{if(!Je&&we.current){const{id:Ct,title:kt}=we.current;we.current=null,y(Ct),h(kt)}},ws=Je=>{Je.preventDefault(),Je.stopPropagation(),M(vt?null:Ie)},Ds=Je=>{Je.preventDefault(),Je.stopPropagation()},Xt=Je=>{Je.preventDefault(),Je.stopPropagation()},en=Je=>{Je.preventDefault(),Je.stopPropagation()},Ks=Je=>{Je.preventDefault(),Je.stopPropagation()},Us=Je=>{Je.preventDefault(),Je.stopPropagation(),M(null),G(Ce,{archivedBucket:l})},Xs=Je=>{Je.preventDefault(),Je.stopPropagation()},re=Je=>{Je.preventDefault(),Je.stopPropagation()},bt=Je=>{Je.preventDefault(),Je.stopPropagation(),fe?.vscode?.executeCommand("openchamber.openSessionInEditor",Ce.id,at)},Et=Je=>{if(Z.current){Z.current=!1;return}if(Te){if(Je?.preventDefault(),Je?.stopPropagation(),Je?.shiftKey){const kt=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(gs=>gs.getAttribute("data-session-row")).filter(gs=>typeof gs=="string"&&gs.length>0),Kt=br.getState().anchorId,Tt=new Map;Tt.set(Ce.id,L(n)),q(Kt,Ce.id,kt,ve??null,Tt);return}ye(Ce.id,ve??null,L(n));return}k(Ce.id,ve,et,i)},Wt=Je=>{(Je.button===2||Je.button===0&&Je.ctrlKey&&!Te)&&(Z.current=!0)},ts=Je=>{R&&Je.pointerType==="touch"&&Y(!0)},ss=Je=>{R&&Je.pointerType==="touch"&&Y(!1)},Ke=s.jsxs(Ps,{align:"end",className:"min-w-[180px]",finalFocus:()=>!(D||Se.current),children:[s.jsxs(Ot,{onClick:()=>{we.current={id:Ce.id,title:at}},className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(Ot,{onClick:()=>N(Ce.id),className:"[&>svg]:mr-1",children:[nt?s.jsx(A,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(A,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(nt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),ce.share?s.jsxs(s.Fragment,{children:[s.jsx(Ot,{onClick:()=>{ce.share?.url&&P(ce.share.url,Ce.id)},className:"[&>svg]:mr-1",children:E===Ce.id?s.jsxs(s.Fragment,{children:[s.jsx(A,{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(A,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(Ot,{onClick:()=>T(Ce.id),className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Ot,{onClick:()=>I(ce),className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(Ot,{onClick:()=>{zt()},className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),ft?s.jsxs(Ot,{onClick:()=>Dt(!0),className:"[&>svg]:mr-1",children:[s.jsx(AD,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,ve&&!l?(()=>{const Je=F(ve),Ct=_(ve,Ce.id);return s.jsxs(s.Fragment,{children:[s.jsx(nr,{}),s.jsxs(bv,{children:[s.jsxs(yv,{className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(vv,{className:"min-w-[180px]",children:[Je.length===0?s.jsx(Ot,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):Je.map(kt=>s.jsxs(Ot,{onClick:()=>{Ct===kt.id?V(ve,Ce.id):$(ve,kt.id,Ce.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:kt.name}),Ct===kt.id?s.jsx(A,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},kt.id)),s.jsx(nr,{}),s.jsxs(Ot,{onClick:()=>{const kt=O(ve);kt&&$(ve,kt.id,Ce.id)},children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),Ct?s.jsxs(Ot,{onClick:()=>{V(ve,Ce.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,X?null:s.jsxs(Ot,{disabled:!ve,onClick:()=>{ve&&B(ve,{mode:"chat",dedupeKey:`session:${Ce.id}`,label:at})},className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),ee?s.jsxs(Ot,{disabled:!ve,onClick:es,className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(nr,{}),s.jsxs(Ot,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>G(Ce,{archivedBucket:l}),children:[s.jsx(A,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e(l?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(o.Fragment,{children:[s.jsx(kA,{sessionId:Ce.id,sessionDirectory:ve??null,sessionTitle:at,children:s.jsxs("div",{"data-session-row":Ce.id,"data-session-scope":ve??"","data-session-archived":l?"1":"0",className:ge("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",et?"opacity-75":"",r>0&&"pl-[20px]",$e&&"bg-primary/15"),children:[Bt,wt,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:te?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",disabled:et,onPointerDown:ts,onPointerUp:ss,onPointerCancel:ss,onMouseDown:Wt,onClick:Je=>Et(Je),onDoubleClick:Je=>{Je.stopPropagation(),w(Ce.id,at)},className:ge("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]",me&&"bg-interactive-hover/70",H?X?ae:xe:ae),children:s.jsxs("div",{className:ge("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:ge("block min-w-0 flex-1 truncate typography-ui-label font-normal",We?"text-primary":"text-foreground"),children:io(at,p)}),H?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:lt}):null,H?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:ge("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",vt?"opacity-0":Ne),children:lt})}),hs>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(A,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:hs})]}):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:ge("flex items-center gap-3 text-left text-muted-foreground",ne?.projectLabel?"justify-between":"justify-start"),children:[ne?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:ne.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:He})]}),ne?.branchLabel||Me?s.jsxs("div",{className:ge("flex items-center gap-3 text-left text-muted-foreground",ne?.branchLabel?"justify-between":"justify-start"),children:[ne?.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(A,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ne.branchLabel})]})}):null,Me?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",Me.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",Me.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:et,onPointerDown:ts,onPointerUp:ss,onPointerCancel:ss,onMouseDown:Wt,onClick:Je=>Et(Je),onDoubleClick:Je=>{Je.stopPropagation(),w(Ce.id,at)},className:ge("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]",me&&"bg-interactive-hover/70",H?X?ae:xe:ae),children:[s.jsxs("div",{className:ge("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:ge("block min-w-0 flex-1 truncate typography-ui-label font-normal",We?"text-primary":"text-foreground"),children:io(at,p)}),hs>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(A,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:hs})]}):null]}),te?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:He}),Me?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:["+",Me.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Me.deletions]})]}):null,de?s.jsx("span",{className:"truncate",children:ne?.projectLabel}):null,pe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ne?.branchLabel})]}):null]})})]})}),Zt&&!R?s.jsx("div",{className:ge("absolute top-1/2 -translate-y-1/2 z-10",te?"right-0":"right-[30px]"),children:Zt}):null,s.jsxs("div",{className:ge("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",vt||H&&!X?"opacity-100":ge("opacity-0",be)),children:[ie?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",className:ge("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",te&&!H?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:en,onMouseDown:Ks,onClick:Us,onKeyDown:Je=>Je.stopPropagation(),children:s.jsx(A,{name:"archive",className:ge(te&&!H?"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,se?s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",className:ge("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",te&&!H?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:Xs,onMouseDown:re,onClick:bt,onKeyDown:Je=>Je.stopPropagation(),children:s.jsx(A,{name:"external-link",className:ge(te&&!H?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(At,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(As,{open:vt,onOpenChange:us,onOpenChangeComplete:Es,children:[s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:ge("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",te&&!H?vt?"h-4 w-4 opacity-100":ge("h-4 w-4 opacity-0",be):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:Ds,onMouseDown:Xt,onClick:ws,onKeyDown:Je=>Je.stopPropagation(),children:s.jsx(A,{name:"more-2",className:ge(te&&!H?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),Ke]})]})]})}),qe&&ze?n.children.map(Je=>J(Je,r+1,ve??a,i,l,void 0,ue)):null,s.jsx(ls,{open:U,onOpenChange:oe,children:s.jsxs(os,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(ps,{children:[s.jsx(ds,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(ys,{children:Qt===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Qt}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Qt})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:Ee,onChange:Je=>Oe(Je.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(Rs,{children:[s.jsx(he,{type:"button",onClick:()=>oe(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(he,{type:"button",onClick:()=>{oe(!1),gt(Ee)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),ft?s.jsx(PD,{session:ce,open:dt,onOpenChange:Dt}):null]},Ce.id)}const ED=o.memo(TD,DD);function MD(t){const e=ot.c(71),{t:n}=pt(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:l,onConfirm:c}=t;let d,f,m,u,p,b,g,y,x,h;if(e[0]!==a||e[1]!==n||e[2]!==r){const O=n("sessions.sidebar.session.untitled");u=ls,x=!!r,e[13]!==a?(h=G=>{G||a(null)},e[13]=a,e[14]=h):h=e[14],m=os,g=!1,y="max-w-sm gap-5",f=ps;let B;e[15]!==n||e[16]!==r?.archivedBucket?(B=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=B):B=e[17],e[18]!==B?(b=s.jsx(ds,{children:B}),e[18]=B,e[19]=b):b=e[19],d=ys,p=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||O,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||O,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||O,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||O,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||O}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||O}),e[0]=a,e[1]=n,e[2]=r,e[3]=d,e[4]=f,e[5]=m,e[6]=u,e[7]=p,e[8]=b,e[9]=g,e[10]=y,e[11]=x,e[12]=h}else d=e[3],f=e[4],m=e[5],u=e[6],p=e[7],b=e[8],g=e[9],y=e[10],x=e[11],h=e[12];let j;e[20]!==d||e[21]!==p?(j=s.jsx(d,{children:p}),e[20]=d,e[21]=p,e[22]=j):j=e[22];let v;e[23]!==f||e[24]!==b||e[25]!==j?(v=s.jsxs(f,{children:[b,j]}),e[23]=f,e[24]=b,e[25]=j,e[26]=v):v=e[26];let C;e[27]!==l||e[28]!==i?(C=()=>l(!i),e[27]=l,e[28]=i,e[29]=C):C=e[29];const k=!i;let w;e[30]!==i?(w=i?s.jsx(A,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(A,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=i,e[31]=w):w=e[31];let N;e[32]!==n?(N=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=N):N=e[33];let I;e[34]!==w||e[35]!==N||e[36]!==C||e[37]!==k?(I=s.jsxs("button",{type:"button",onClick:C,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:[w,N]}),e[34]=w,e[35]=N,e[36]=C,e[37]=k,e[38]=I):I=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 T;e[43]!==E||e[44]!==P?(T=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]=T):T=e[45];let S;e[46]!==c?(S=()=>{c()},e[46]=c,e[47]=S):S=e[47];let M;e[48]!==n||e[49]!==r?.archivedBucket?(M=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=M):M=e[50];let D;e[51]!==S||e[52]!==M?(D=s.jsx("button",{type:"button",onClick:S,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:M}),e[51]=S,e[52]=M,e[53]=D):D=e[53];let F;e[54]!==T||e[55]!==D?(F=s.jsxs("div",{className:"flex items-center gap-2",children:[T,D]}),e[54]=T,e[55]=D,e[56]=F):F=e[56];let _;e[57]!==I||e[58]!==F?(_=s.jsxs(Rs,{className:"w-full sm:items-center sm:justify-between",children:[I,F]}),e[57]=I,e[58]=F,e[59]=_):_=e[59];let V;e[60]!==m||e[61]!==g||e[62]!==_||e[63]!==y||e[64]!==v?(V=s.jsxs(m,{showCloseButton:g,className:y,children:[v,_]}),e[60]=m,e[61]=g,e[62]=_,e[63]=y,e[64]=v,e[65]=V):V=e[65];let $;return e[66]!==u||e[67]!==V||e[68]!==x||e[69]!==h?($=s.jsx(u,{open:x,onOpenChange:h,children:V}),e[66]=u,e[67]=V,e[68]=x,e[69]=h,e[70]=$):$=e[70],$}function RD(t){const e=ot.c(57),{t:n}=pt(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:l,onConfirm:c}=t,d=r?.archivedBucket===!0,f=r?.sessionCount??0;let m;e[0]!==d||e[1]!==f||e[2]!==n?(m=n(d?f===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":f===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=f,e[2]=n,e[3]=m):m=e[3];const u=m;let p;e[4]!==d||e[5]!==f||e[6]!==n?(p=d?f===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:f}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:f}):f===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:f}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:f}),e[4]=d,e[5]=f,e[6]=n,e[7]=p):p=e[7];const b=p,g=!!r;let y;e[8]!==a?(y=$=>{$||a(null)},e[8]=a,e[9]=y):y=e[9];let x;e[10]!==u?(x=s.jsx(ds,{children:u}),e[10]=u,e[11]=x):x=e[11];let h;e[12]!==b?(h=s.jsx(ys,{children:b}),e[12]=b,e[13]=h):h=e[13];let j;e[14]!==x||e[15]!==h?(j=s.jsxs(ps,{children:[x,h]}),e[14]=x,e[15]=h,e[16]=j):j=e[16];let v;e[17]!==l||e[18]!==i?(v=()=>l(!i),e[17]=l,e[18]=i,e[19]=v):v=e[19];const C=!i;let k;e[20]!==i?(k=i?s.jsx(A,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(A,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=i,e[21]=k):k=e[21];let w;e[22]!==n?(w=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=w):w=e[23];let N;e[24]!==w||e[25]!==v||e[26]!==C||e[27]!==k?(N=s.jsxs("button",{type:"button",onClick:v,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":C,children:[k,w]}),e[24]=w,e[25]=v,e[26]=C,e[27]=k,e[28]=N):N=e[28];let I;e[29]!==a?(I=()=>a(null),e[29]=a,e[30]=I):I=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]!==I||e[34]!==E?(P=s.jsx("button",{type:"button",onClick:I,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]=I,e[34]=E,e[35]=P):P=e[35];let T;e[36]!==c?(T=()=>{c()},e[36]=c,e[37]=T):T=e[37];let S;e[38]!==d||e[39]!==n?(S=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=S):S=e[40];let M;e[41]!==T||e[42]!==S?(M=s.jsx("button",{type:"button",onClick:T,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:S}),e[41]=T,e[42]=S,e[43]=M):M=e[43];let D;e[44]!==P||e[45]!==M?(D=s.jsxs("div",{className:"flex items-center gap-2",children:[P,M]}),e[44]=P,e[45]=M,e[46]=D):D=e[46];let F;e[47]!==N||e[48]!==D?(F=s.jsxs(Rs,{className:"w-full sm:items-center sm:justify-between",children:[N,D]}),e[47]=N,e[48]=D,e[49]=F):F=e[49];let _;e[50]!==F||e[51]!==j?(_=s.jsxs(os,{showCloseButton:!1,className:"max-w-sm gap-5",children:[j,F]}),e[50]=F,e[51]=j,e[52]=_):_=e[52];let V;return e[53]!==g||e[54]!==_||e[55]!==y?(V=s.jsx(ls,{open:g,onOpenChange:y,children:_}),e[53]=g,e[54]=_,e[55]=y,e[56]=V):V=e[56],V}function FD(t){const e=ot.c(36),{t:n}=pt(),{value:r,setValue:a,onConfirm:i}=t,l=!!r;let c;e[0]!==a?(c=k=>{k||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 f;e[4]!==d?(f=s.jsx(ds,{children:d}),e[4]=d,e[5]=f):f=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(ys,{children:m}),e[9]=m,e[10]=u):u=e[10];let p;e[11]!==f||e[12]!==u?(p=s.jsxs(ps,{children:[f,u]}),e[11]=f,e[12]=u,e[13]=p):p=e[13];let b;e[14]!==a?(b=()=>a(null),e[14]=a,e[15]=b):b=e[15];let g;e[16]!==n?(g=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=g):g=e[17];let y;e[18]!==b||e[19]!==g?(y=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:g}),e[18]=b,e[19]=g,e[20]=y):y=e[20];let x;e[21]!==n?(x=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=x):x=e[22];let h;e[23]!==i||e[24]!==x?(h=s.jsx("button",{type:"button",onClick:i,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:x}),e[23]=i,e[24]=x,e[25]=h):h=e[25];let j;e[26]!==h||e[27]!==y?(j=s.jsxs(Rs,{children:[y,h]}),e[26]=h,e[27]=y,e[28]=j):j=e[28];let v;e[29]!==j||e[30]!==p?(v=s.jsxs(os,{showCloseButton:!1,className:"max-w-sm gap-5",children:[p,j]}),e[29]=j,e[30]=p,e[31]=v):v=e[31];let C;return e[32]!==l||e[33]!==c||e[34]!==v?(C=s.jsx(ls,{open:l,onOpenChange:c,children:v}),e[32]=l,e[33]=c,e[34]=v,e[35]=C):C=e[35],C}const LD=t=>{const e=ot.c(46),{selectedCount:n,scopeKey:r,scopeFolders:a,archivedBucket:i,onMoveToFolder:l,onCreateFolderAndMove:c,onRemoveFromFolder:d,canRemoveFromFolder:f,onDelete:m,onDone:u}=t,{t:p}=pt(),b=!!r&&!i;let g;e[0]!==i||e[1]!==p?(g=p(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=p,e[2]=g):g=e[2];const y=g;let x;e[3]!==n||e[4]!==p?(x=p("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=p,e[5]=x):x=e[5];let h;e[6]!==x?(h=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:x}),e[6]=x,e[7]=h):h=e[7];let j;e[8]!==b||e[9]!==f||e[10]!==c||e[11]!==l||e[12]!==d||e[13]!==a||e[14]!==p?(j=b?s.jsxs(As,{children:[s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsx(Is,{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":p("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(A,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:p("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Ps,{align:"end",className:"min-w-[180px]",children:[a.length===0?s.jsx(Ot,{disabled:!0,className:"text-muted-foreground",children:p("sessions.sidebar.folders.none")}):a.map(_=>s.jsx(Ot,{onClick:()=>l(_.id),children:s.jsx("span",{className:"flex-1 truncate",children:_.name})},_.id)),s.jsx(nr,{}),s.jsxs(Ot,{onClick:c,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"}),p("sessions.sidebar.folders.newFolderEllipsis")]}),f?s.jsxs(Ot,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"close",className:"mr-1 h-4 w-4"}),p("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=b,e[9]=f,e[10]=c,e[11]=l,e[12]=d,e[13]=a,e[14]=p,e[15]=j):j=e[15];let v;e[16]===Symbol.for("react.memo_cache_sentinel")?(v=ge("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]=v):v=e[16];let C;e[17]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(A,{name:"delete-bin",className:"h-4 w-4"}),e[17]=C):C=e[17];let k;e[18]!==y||e[19]!==m?(k=s.jsx(Pt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:v,"aria-label":y,children:C})}),e[18]=y,e[19]=m,e[20]=k):k=e[20];let w;e[21]!==y?(w=s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:y})}),e[21]=y,e[22]=w):w=e[22];let N;e[23]!==k||e[24]!==w?(N=s.jsxs(It,{children:[k,w]}),e[23]=k,e[24]=w,e[25]=N):N=e[25];let I;e[26]!==p?(I=p("sessions.sidebar.header.actions.exitSelection"),e[26]=p,e[27]=I):I=e[27];let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(A,{name:"close",className:"h-4 w-4"}),e[28]=E):E=e[28];let P;e[29]!==u||e[30]!==I?(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":I,children:E})}),e[29]=u,e[30]=I,e[31]=P):P=e[31];let T;e[32]!==p?(T=p("sessions.sidebar.header.actions.exitSelection"),e[32]=p,e[33]=T):T=e[33];let S;e[34]!==T?(S=s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:T})}),e[34]=T,e[35]=S):S=e[35];let M;e[36]!==P||e[37]!==S?(M=s.jsxs(It,{children:[P,S]}),e[36]=P,e[37]=S,e[38]=M):M=e[38];let D;e[39]!==M||e[40]!==j||e[41]!==N?(D=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[j,N,M]}),e[39]=M,e[40]=j,e[41]=N,e[42]=D):D=e[42];let F;return e[43]!==D||e[44]!==h?(F=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[h,D]}),e[43]=D,e[44]=h,e[45]=F):F=e[45],F},hx="oc.sessions.activeNow",OD=2160*60*1e3,gx=t=>!!t.parentID,Au=t=>!!t.time?.archived,Gd=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},$D=t=>{try{const e=t.getItem(hx);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,a=[];return n.forEach(i=>{const l=typeof i=="string"?i:i&&typeof i=="object"&&"sessionId"in i&&typeof i.sessionId=="string"?i.sessionId:null;!l||r.has(l)||(r.add(l),a.push({sessionId:l}))}),a}catch{return[]}},id=(t,e)=>{try{t.setItem(hx,JSON.stringify(e))}catch{}},_D=(t,e,n=Date.now())=>{const r=n-OD;return t.filter(a=>{const i=e.get(a.sessionId);return i?Au(i)?!1:Gd(i)>=r:!0})},BD=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],xx=t=>[...t].sort((e,n)=>Gd(n)-Gd(e)),VD=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!Au(r)).filter(r=>!gx(r));return xx(n)},zD=(t,e)=>{const n=t.filter(r=>{if(Au(r)||gx(r))return!1;const a=e[r.id];return a?.type==="busy"||a?.type==="retry"});return xx(n)},rl=vr(),od=ar((t,e)=>({entries:$D(rl),setEntries:n=>{n!==e().entries&&(t({entries:n}),id(rl,n))},addSession:n=>{const r=BD(e().entries,n);r!==e().entries&&(t({entries:r}),id(rl,r))},prune:n=>{const r=e().entries,a=_D(r,n);a.length===r.length&&a.every((i,l)=>i.sessionId===r[l]?.sessionId)||(t({entries:a}),id(rl,a))}})),al="oc.sessions.projectCollapse",Kf="oc.sessions.groupOrder",Hf="oc.sessions.groupCollapse",Gf="oc.sessions.activeSessionByProject",ld="oc.sessions.expandedParents.v2",UD="oc.sessions.expandedParents",WD="oc.sessions.pinned",KD=(t,e)=>{const n=new Set;for(const r of t){const a=xs(r.path)?.toLowerCase();a&&n.add(a)}for(const r of e.values())for(const a of r){const i=xs(a.path)?.toLowerCase();i&&n.add(i)}return n},HD=(t,e)=>{if(t.time?.archived)return!0;const n=xs(ao(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},GD=5*6e4,qf=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:a=!1})=>{const{t:i}=pt(),[l,c]=o.useState(!1),[d,f]=o.useState(""),m=o.useRef(null),u=o.useRef(null),p=o.useRef(new Set),[b,g]=o.useState(null),[y,x]=o.useState(""),[h,j]=o.useState(null),[v,C]=o.useState(new Set),[k]=o.useState(()=>new Map),w=o.useMemo(()=>vr(),[]),N=od(je=>je.entries),I=od(je=>je.addSession),E=od(je=>je.prune),[P,T]=o.useState(new Set),[S,M]=o.useState(new Map),[D,F]=o.useState(new Set),[_,V]=o.useState(!1),[$,O]=o.useState(!1),[B,G]=o.useState(null),[R,H]=o.useState(null),[J,ne]=o.useState(""),[ue,de]=o.useState(null),[pe,W]=o.useState(null),[te,X]=o.useState(null),ee=Nc(je=>je.ids),fe=Nc(je=>je.setIds),be=Nc(je=>je.toggle),[Ne,se]=o.useState(()=>{try{const je=vr().getItem(Hf);if(!je)return new Set;const yt=JSON.parse(je);return new Set(Array.isArray(yt)?yt.filter(mt=>typeof mt=="string"):[])}catch{return new Set}}),[ie,ae]=o.useState(()=>{try{const je=vr().getItem(Kf);if(!je)return new Map;const yt=JSON.parse(je),mt=new Map;return Object.entries(yt).forEach(([Ut,bs])=>{Array.isArray(bs)&&mt.set(Ut,bs.filter(Gs=>typeof Gs=="string"))}),mt}catch{return new Map}}),[xe,Z]=o.useState(()=>{try{const je=vr().getItem(Gf);if(!je)return new Map;const yt=JSON.parse(je),mt=new Map;return Object.entries(yt).forEach(([Ut,bs])=>{typeof bs=="string"&&bs.length>0&&mt.set(Ut,bs)}),mt}catch{return new Map}}),[me,Y]=o.useState(new Map),Se=o.useRef(new Map),we=o.useRef(0),ke=Ms(je=>je.homeDirectory),Fe=Ms(je=>je.currentDirectory),Ce=Ms(je=>je.setDirectory),Q=Ss(je=>je.projects),ce=Ss(je=>je.activeProjectId),ve=Ss(je=>je.removeProject),le=Ss(je=>je.setActiveProjectIdOnly),Ae=Ss(je=>je.updateProjectMeta),Te=Ss(je=>je.reorderProjects),$e=_e(je=>je.setActiveMainTab),ye=_e(je=>je.openContextPanelTab),q=_e(je=>je.setSettingsDialogOpen),L=_e(je=>je.toggleHelpDialog),U=_e(je=>je.setAboutDialogOpen),oe=_e(je=>je.setSessionSwitcherOpen),Ee=_e(je=>je.setScheduledTasksDialogOpen),Oe=_e(je=>je.openMultiRunLauncher),Ie=_e(je=>je.notifyOnSubtasks),z=_e(je=>je.showDeletionDialog),De=_e(je=>je.setShowDeletionDialog),Qe=ac(d,120),tt=o.useMemo(()=>Qe.trim().toLowerCase(),[Qe]),et=tt.length>0,We=er(je=>je.collapsedFolderIds),at=er(je=>je.foldersMap),qe=er(je=>je.getFoldersForScope),nt=er(je=>je.createFolder),Ze=er(je=>je.renameFolder),ze=er(je=>je.deleteFolder),rt=er(je=>je.addSessionToFolder),Ge=er(je=>je.addSessionsToFolder),ct=er(je=>je.removeSessionFromFolder),Pe=er(je=>je.removeSessionsFromFolders),Me=er(je=>je.toggleFolderCollapse),Ue=er(je=>je.cleanupSessions),He=er(je=>je.getSessionFolderId);WP({isSessionSearchOpen:l,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchContainerRef:m});const lt=Fh(),vt=uu(),ft=Qd(),dt=jv(),Dt=wa(je=>je.hasLoaded),Qt=wa(je=>je.activeSessions),Ft=wa(je=>je.archivedSessions),qt=Lt(je=>je.currentSessionId),gt=Lt(je=>!!je.newSessionDraft?.open),zt=Lt(je=>je.setCurrentSession),es=Lt(je=>je.updateSessionTitle),is=Lt(je=>je.shareSession),cs=Lt(je=>je.unshareSession),hs=Lt(je=>je.worktreeMetadata),_t=Lt(je=>je.availableWorktreesByProject),Ye=Lt(je=>je.openNewSessionDraft),Mt=Ka(Qn(je=>({checkForUpdates:je.checkForUpdates,available:je.available,runtimeType:je.runtimeType,info:je.info,downloading:je.downloading,downloaded:je.downloaded,progress:je.progress,error:je.error,downloadUpdate:je.downloadUpdate,restartToUpdate:je.restartToUpdate}))),Bt=o.useMemo(()=>KD(Q,_t),[_t,Q]),wt=o.useMemo(()=>{const je=new Map(ft.map(Ut=>[Ut.id,Ut])),yt=Qt.map(Ut=>je.get(Ut.id)??Ut),mt=new Set(yt.map(Ut=>Ut.id));return ft.forEach(Ut=>{mt.has(Ut.id)||yt.push(Ut)}),yt.filter(Ut=>HD(Ut,Bt))},[Qt,Bt,ft]),Zt=o.useMemo(()=>ft.map(je=>{const yt=xs(je.directory??null)??"";return`${je.id}:${je.title??""}:${je.time?.archived?1:0}:${yt}`}).join("|"),[ft]),us=o.useRef(ft);o.useEffect(()=>{us.current=ft},[Zt,ft]);const Es=o.useMemo(()=>Q.map(je=>`${je.id}:${xs(je.path)??""}`).join("|"),[Q]),ws=o.useRef(!1);o.useEffect(()=>{ws.current||(ws.current=!0,xd(us.current))},[]),o.useEffect(()=>{let je=!1;return(async()=>{const mt=Ss.getState().projects;if(mt.length===0)return;const Ut=new Map,bs=[];await Promise.all(mt.map(async Gs=>{const Rn=xs(Gs.path);if(Rn)try{if(!(qs.getState().directories.get(Rn)?.isGitRepo??await Rr(()=>import("./modelPrefsAutoSave-wwnbqBk7.js").then(Fn=>Fn.f7),__vite__mapDeps([2,0,1,3,4])).then(Fn=>Fn.checkIsGitRepository(Rn))))return;const $n=await gd({id:Gs.id,path:Rn});if(je||$n.length===0)return;Ut.set(Rn,$n),bs.push(...$n)}catch{}})),!je&&Lt.setState({availableWorktrees:bs,availableWorktreesByProject:Ut})})(),()=>{je=!0}},[Es]),o.useEffect(()=>{let je=null;const yt=ox(mt=>{mt.type==="scheduled-task-ran"&&(je&&clearTimeout(je),je=setTimeout(()=>{xd(us.current)},500))});return()=>{je&&clearTimeout(je),yt()}},[]);const Ds=o.useMemo(()=>In(),[]),Xt=o.useMemo(()=>un(),[]),{isTablet:en}=an(),Ks=t||en,{buildGroupSearchText:Us,filterSessionNodesForSearch:Xs,buildGroupedSessions:re}=UP({homeDirectory:ke,worktreeMetadata:hs,pinnedSessionIds:ee,gitBranches:lt,isVSCode:Xt}),{scheduleCollapsedProjectsPersist:bt}=QP({isVSCode:Xt,hasLoadedGlobalSessions:Dt,safeStorage:w,keys:{sessionExpanded:ld,sessionExpandedLegacy:UD,projectCollapse:al,sessionPinned:WD,groupOrder:Kf,projectActiveSession:Gf,groupCollapse:Hf},sessions:wt,setPinnedSessionIds:fe,groupOrderByProject:ie,activeSessionByProject:xe,collapsedGroups:Ne,setExpandedParents:C,setCollapsedProjects:T}),Et=o.useMemo(()=>[...wt].sort((je,yt)=>wi(je,yt,ee)),[wt,ee]),Wt=o.useMemo(()=>new Map(Et.map((je,yt)=>[je.id,yt])),[Et]),ts=o.useMemo(()=>{const je=new Map;return Et.forEach(yt=>{const mt=yt.parentID;if(!mt)return;const Ut=je.get(mt)??[];Ut.push(yt),je.set(mt,Ut)}),je.forEach(yt=>yt.sort((mt,Ut)=>wi(mt,Ut,ee))),je},[Et,ee]),ss=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")})]}),Ke=o.useMemo(()=>Q.find(je=>je.id===h)??null,[Q,h]),Je=o.useCallback(je=>{h&&(Ae(h,je),j(null))},[h,Ae]),Ct=o.useCallback(()=>{V(!0)},[]),kt=o.useCallback(()=>{const je=Ka.getState();if(je.available&&je.info){O(!0);return}Mt.checkForUpdates().then(()=>{const{available:yt,error:mt}=Ka.getState();if(mt){K.error(i("sessions.sidebar.updateCheck.errorTitle"),{description:mt});return}if(!yt){K.success(i("sessions.sidebar.updateCheck.latestVersion"));return}O(!0)})},[i,Mt]),Kt=o.useCallback(()=>{t&&oe(!1),q(!0)},[t,oe,q]),Tt=Mt.available&&(Mt.runtimeType==="desktop"||Mt.runtimeType==="web"),gs=Lt(je=>je.deleteSession),js=Lt(je=>je.deleteSessions),Ls=Lt(je=>je.archiveSession),Os=Lt(je=>je.archiveSessions),{copiedSessionId:tn,handleSessionSelect:cn,handleSessionDoubleClick:Zs,handleSaveEdit:sn,handleCancelEdit:mn,handleShareSession:gn,handleCopyShareUrl:$s,handleUnshareSession:Hs,handleDeleteSession:dn,confirmDeleteSession:Kn}=KP({activeProjectId:ce,currentDirectory:Fe,currentSessionId:qt,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:l,sessionSearchQuery:d,setSessionSearchQuery:f,setIsSessionSearchOpen:c,setActiveProjectIdOnly:le,setDirectory:Ce,setActiveMainTab:$e,setSessionSwitcherOpen:oe,setCurrentSession:zt,updateSessionTitle:es,shareSession:is,unshareSession:cs,deleteSession:gs,deleteSessions:js,archiveSession:Ls,archiveSessions:Os,childrenMap:ts,showDeletionDialog:z,setDeleteSessionConfirm:de,deleteSessionConfirm:ue,setEditingId:g,setEditTitle:x,editingId:b,editTitle:y}),Hn=o.useCallback(()=>{if(!pe)return;const{scopeKey:je,folderId:yt}=pe;W(null),ze(je,yt)},[pe,ze]),kr=o.useCallback(()=>{Mr.requestDirectoryDialog()},[]);o.useEffect(()=>{if(!qt)return;const yt=wt.find(Ut=>Ut.id===qt)?.parentID;if(!yt)return;const mt=[`project:active:${yt}`,`project:archived:${yt}`,`recent:active:${yt}`,`recent:archived:${yt}`];C(Ut=>{if(mt.every(Gs=>Ut.has(Gs)))return Ut;const bs=new Set(Ut);mt.forEach(Gs=>bs.add(Gs));try{w.setItem(ld,JSON.stringify(Array.from(bs)))}catch{}return bs})},[qt,wt,w]);const ir=o.useCallback(je=>{C(yt=>{const mt=new Set(yt);mt.has(je)?mt.delete(je):mt.add(je);try{w.setItem(ld,JSON.stringify(Array.from(mt)))}catch{}return mt})},[w]),bn=o.useCallback((je,yt)=>{if(!je)return null;yt&&We.has(yt)&&Me(yt);const mt=nt(je,i("sessions.sidebar.folder.newFolderName"),yt);return H(mt.id),ne(mt.name),mt},[We,Me,nt,i]),On=o.useCallback(je=>{F(yt=>{const mt=new Set(yt);return mt.has(je)?mt.delete(je):mt.add(je),mt})},[]),ur=o.useCallback(()=>{we.current=Date.now()+150,T(()=>{const je=new Set(Q.map(yt=>yt.id));try{w.setItem(al,JSON.stringify(Array.from(je)))}catch{}return Xt||bt(je),je})},[Q,Xt,w,bt]),Be=o.useCallback(()=>{we.current=Date.now()+150,T(()=>{const je=new Set;try{w.setItem(al,JSON.stringify([]))}catch{}return Xt||bt(je),je})},[Xt,w,bt]),St=o.useCallback(je=>{we.current=Date.now()+150,T(yt=>{const mt=new Set(yt);mt.has(je)?mt.delete(je):mt.add(je);try{w.setItem(al,JSON.stringify(Array.from(mt)))}catch{}return Xt||bt(mt),mt})},[Xt,w,bt]),Gt=o.useMemo(()=>Q.map(je=>({...je,normalizedPath:xs(je.path)})).filter(je=>!!je.normalizedPath),[Q]),Yt=o.useMemo(()=>Gt.map(je=>je.normalizedPath),[Gt]),{github:ks}=Wn(),Bs=Yn(je=>je.status),Fs=Yn(je=>je.hasChecked),Ys=Nv(Yt),nn=yr(je=>je.ensureEntry),Xn=yr(je=>je.setParams),Cr=yr(je=>je.refreshTargets);XP({normalizedProjects:Gt,gitRepoStatus:Ys,setProjectRepoStatus:M,setProjectRootBranches:Y});const mr=Lt(je=>je.isLoading);lA({isSessionsLoading:mr,sessions:wt,archivedSessions:Ft,normalizedProjects:Gt,isVSCode:Xt,availableWorktreesByProject:_t,cleanupSessions:Ue});const{getSessionsForProject:qr,getArchivedSessionsForProject:Jr}=nA({isVSCode:Xt,sessions:wt,archivedSessions:Ft,availableWorktreesByProject:_t});FP({normalizedProjects:Gt,sessions:wt,archivedSessions:Ft,availableWorktreesByProject:_t,isVSCode:Xt,isSessionsLoading:mr,foldersMap:at,createFolder:nt,addSessionToFolder:rt,cleanupSessions:Ue});const Mn=o.useRef(!1);ce&&S.has(ce)&&(Mn.current=!!S.get(ce));const{projectSections:wn,groupSearchDataByGroup:jn,sectionsForRender:Vs,searchMatchCount:yn}=$P({normalizedProjects:Gt,getSessionsForProject:qr,getArchivedSessionsForProject:Jr,availableWorktreesByProject:_t,projectRepoStatus:S,projectRootBranches:me,lastRepoStatus:Mn.current,buildGroupedSessions:re,hasSessionSearchQuery:et,normalizedSessionSearchQuery:tt,filterSessionNodesForSearch:Xs,buildGroupSearchText:Us,foldersMap:at}),pn=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:i("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:i("sessions.sidebar.empty.noMatches.description")})]}),{currentSessionDirectory:Wr}=BP({projectSections:wn,activeProjectId:ce,activeSessionByProject:xe,setActiveSessionByProject:Z,currentSessionId:qt,handleSessionSelect:cn,newSessionDraftOpen:gt,mobileVariant:t,openNewSessionDraft:Ye,setActiveMainTab:$e,setSessionSwitcherOpen:oe,sessions:wt,worktreeMetadata:hs}),{getOrderedGroups:si}=VP(ie),ni=o.useRef(!1);o.useEffect(()=>{if(ni.current||wn.length===0)return;const je=wn.flatMap(yt=>yt.groups.filter(mt=>mt.isArchivedBucket).map(mt=>`${yt.project.id}:${mt.id}`));je.length>0&&se(yt=>new Set([...yt,...je])),ni.current=!0},[wn]);const ka=o.useMemo(()=>{const je=new Map,yt=new Map;return wn.forEach(mt=>{const Ut=zh(mt.project.label?.trim()||Ja(mt.project.normalizedPath,ke)||mt.project.normalizedPath);mt.groups.forEach(bs=>{const Gs=bs.branch&&bs.branch!=="HEAD"&&bs.branch!==Ut?bs.branch:null,Rn={projectLabel:Ut,branchLabel:Gs},Ar=lr=>{lr.forEach($n=>{const Fn=mt.project.normalizedPath.length,oi=yt.get($n.session.id)??-1;Fn<oi||(je.set($n.session.id,{node:$n,projectId:mt.project.id,groupDirectory:bs.directory,secondaryMeta:Rn}),yt.set($n.session.id,Fn),$n.children.length>0&&Ar($n.children))})};Ar(bs.sessions)})}),je},[wn,ke]),Nn=za(je=>je.showRecentSection),Pn=o.useMemo(()=>Nn?VD(N,new Map(wt.map(je=>[je.id,je]))).sort((je,yt)=>wi(je,yt,ee)):[],[N,ee,wt,Nn]),Sn=o.useMemo(()=>Nn?zD(wt,dt):[],[dt,wt,Nn]);o.useEffect(()=>{!Nn||Sn.length===0||Sn.forEach(je=>I(je.id))},[I,Sn,Nn]),o.useEffect(()=>{if(!Nn)return;const je=new Map;[...wt,...Ft].forEach(yt=>{je.set(yt.id,yt)}),E(je)},[Ft,E,wt,Nn]);const Ir=o.useMemo(()=>{if(!Nn)return[];const je=yt=>{const mt=ka.get(yt.id),Ut=xs(yt.directory??null);return{node:mt?.node??{session:yt,children:[],worktree:null},projectId:mt?.projectId??null,groupDirectory:mt?.groupDirectory??Ut,secondaryMeta:mt?.secondaryMeta??null}};return[{key:"active-now",title:i("sessions.sidebar.activity.recentTitle"),items:Pn.map(je)}]},[Pn,ka,Nn,i]),Yr=o.useMemo(()=>new Set(Pn.map(je=>je.id)),[Pn]),Kr=o.useMemo(()=>[...Yr],[Yr]);Z6({currentSessionId:qt,sortedSessions:Et,recentSessionIds:Kr,ensureSessionRenderable:vt.ensureSessionRenderable});const or=o.useMemo(()=>{if(!Xt||et||Yr.size===0)return Vs;const je=yt=>yt.reduce((mt,Ut)=>{if(Yr.has(Ut.session.id))return mt;const bs=je(Ut.children);return bs.length===Ut.children.length?(mt.push(Ut),mt):(mt.push({...Ut,children:bs}),mt)},[]);return Vs.map(yt=>({...yt,groups:yt.groups.map(mt=>({...mt,sessions:je(mt.sessions)}))}))},[Xt,et,Yr,Vs]),Hr=o.useMemo(()=>{const je=new Set;return or.forEach(yt=>{yt.groups.forEach(mt=>{const Ut=xs(mt.directory??null),bs=mt.branch?.trim()||lt.get(Ut||"")?.trim();!Ut||!bs||je.add(lo(Ut,bs))})}),[...je]},[lt,or]),fn=jN(Hr);o.useEffect(()=>{if(!Fs||!Bs?.connected||!ks)return;const je=[],yt=Date.now();if(or.forEach(Ut=>{P.has(Ut.project.id)||Ut.groups.forEach(bs=>{const Gs=xs(bs.directory??null),Rn=bs.branch?.trim()||lt.get(Gs||"")?.trim();if(!Gs||!Rn)return;const Ar=lo(Gs,Rn),lr=yr.getState().entries[Ar],$n=!!lr?.status?.pr,Fn=`${Gs}::${Rn}`,oi=Math.max(lr?.lastRefreshAt??0,lr?.lastDiscoveryPollAt??0),zi=!!(lr?.isInitialStatusResolved&&!$n&&(!p.current.has(Fn)||yt-oi>=GD));(!lr||!lr.isInitialStatusResolved||zi)&&(zi&&p.current.add(Fn),je.push({directory:Gs,branch:Rn}))})}),je.length===0)return;const mt=new Map;je.forEach(Ut=>{const bs=lo(Ut.directory,Ut.branch,Ut.remoteName??null);mt.has(bs)||mt.set(bs,Ut)}),mt.forEach((Ut,bs)=>{nn(bs),Xn(bs,{directory:Ut.directory,branch:Ut.branch,remoteName:Ut.remoteName??null,canShow:!0,github:ks,githubAuthChecked:Fs,githubConnected:Bs.connected})}),Cr([...mt.values()],{silent:!0,markInitialResolved:!0})},[P,nn,ks,Fs,Bs?.connected,lt,Cr,or,Xn]);const _i=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",ai="h-4.5 w-4.5",Bi=mA({isDesktopShellRuntime:Ds,projectSections:wn,projectHeaderSentinelRefs:Se}),da=o.useCallback((je,yt=0,mt,Ut,bs=!1,Gs,Rn="project")=>s.jsx(ED,{node:je,depth:yt,groupDirectory:mt,projectId:Ut,archivedBucket:bs,directoryStatus:k,currentSessionId:qt,pinnedSessionIds:ee,expandedParents:v,hasSessionSearchQuery:et,normalizedSessionSearchQuery:tt,notifyOnSubtasks:Ie,editingId:b,setEditingId:g,editTitle:y,setEditTitle:x,handleSaveEdit:sn,handleCancelEdit:mn,toggleParent:ir,handleSessionSelect:cn,handleSessionDoubleClick:Zs,togglePinnedSession:be,handleShareSession:gn,copiedSessionId:tn,handleCopyShareUrl:$s,handleUnshareSession:Hs,openSidebarMenuKey:B,setOpenSidebarMenuKey:G,renamingFolderId:R,getFoldersForScope:qe,getSessionFolderId:He,removeSessionFromFolder:ct,addSessionToFolder:rt,createFolderAndStartRename:bn,openContextPanelTab:ye,handleDeleteSession:dn,mobileVariant:t,alwaysShowActions:Ks,renderSessionNode:da,secondaryMeta:Gs,renderContext:Rn}),[k,qt,ee,v,et,tt,Ie,b,g,y,x,sn,mn,ir,cn,Zs,be,gn,tn,$s,Hs,B,G,R,qe,He,ct,rt,bn,ye,dn,t,Ks]),Qr=o.useCallback(je=>{se(yt=>{const mt=new Set(yt);return mt.has(je)?mt.delete(je):mt.add(je),mt})},[]),pr=o.useMemo(()=>{const je=new Map;for(const[yt,mt]of fn)je.set(yt,{visualState:mt.visualState,number:mt.number,url:mt.url,state:mt.prState,draft:mt.draft,title:mt.title,base:mt.base,head:mt.head,checks:mt.checks,canMerge:mt.canMerge,mergeableState:mt.mergeableState,repo:mt.repo});return je},[fn]),An=o.useCallback((je,yt,mt,Ut,bs,Gs)=>s.jsx(DA,{group:je,groupKey:yt,projectId:mt,hideGroupLabel:Ut,compactBodyPadding:Gs,hasSessionSearchQuery:et,normalizedSessionSearchQuery:tt,groupSearchDataByGroup:jn,expandedSessionGroups:D,collapsedGroups:Ne,hideDirectoryControls:r,collapsedFolderIds:We,toggleFolderCollapse:Me,renameFolder:Ze,deleteFolder:ze,showDeletionDialog:z,setDeleteFolderConfirm:W,renderSessionNode:da,currentSessionDirectory:Wr,projectRepoStatus:S,lastRepoStatus:Mn.current,toggleGroupSessionLimit:On,mobileVariant:t,alwaysShowActions:Ks,activeProjectId:ce,setActiveProjectIdOnly:le,setActiveMainTab:$e,setSessionSwitcherOpen:oe,openNewSessionDraft:Ye,addSessionToFolder:rt,createFolderAndStartRename:bn,renamingFolderId:R,renameFolderDraft:J,setRenameFolderDraft:ne,setRenamingFolderId:H,pinnedSessionIds:ee,sessionOrderIndex:Wt,prVisualStateByDirectoryBranch:pr,onToggleCollapsedGroup:Qr,dragHandleProps:bs}),[et,tt,jn,D,Ne,r,We,Me,Ze,ze,z,da,Wr,S,On,t,Ks,ce,le,$e,oe,Ye,rt,bn,R,J,ee,Wt,pr,Qr]),vn=Nn&&!et?s.jsx(OA,{sections:Ir,renderSessionNode:da}):null,Or=!!(R||b||h),Pr=br(je=>je.enabled),zs=br(je=>je.selectedIds),$r=br(je=>je.scopeKey),Ca=br,Vi=o.useCallback(()=>{br.getState().toggleMode()},[]),Gn=o.useCallback(()=>{br.getState().disable()},[]),fr=o.useMemo(()=>{if(zs.size===0||typeof document>"u")return!1;let je=!1,yt=!1;for(const mt of zs){const Ut=document.querySelectorAll(`[data-session-row="${CSS.escape(mt)}"]`);for(const bs of Ut)bs.getAttribute("data-session-archived")==="1"?yt=!0:je=!0}return yt&&!je},[zs]),hn=o.useMemo(()=>{if($r)return $r;if(zs.size===0||typeof document>"u")return null;for(const je of zs){const mt=document.querySelector(`[data-session-row="${CSS.escape(je)}"]`)?.getAttribute("data-session-scope");if(mt&&mt.length>0)return mt}return null},[zs,$r]),Ia=o.useMemo(()=>hn?at[hn]??[]:[],[at,hn]),Ro=o.useMemo(()=>{if(!hn||zs.size===0)return!1;const je=at[hn]??[];for(const yt of je)for(const mt of yt.sessionIds)if(zs.has(mt))return!0;return!1},[at,hn,zs]),Pa=o.useCallback(je=>{!hn||zs.size===0||Ge(hn,je,Array.from(zs))},[Ge,zs,hn]),ua=o.useCallback(()=>{if(!hn||zs.size===0)return;const je=bn(hn);je&&Ge(hn,je.id,Array.from(zs))},[Ge,bn,zs,hn]),ii=o.useCallback(()=>{!hn||zs.size===0||Pe(hn,Array.from(zs))},[Pe,zs,hn]),Re=o.useCallback(async()=>{const je=Array.from(zs);if(je.length!==0){if(fr){const{deletedIds:yt,failedIds:mt}=await js(je);yt.length>0&&K.success(yt.length===1?i("sessions.sidebar.bulkActions.deletedSingle",{count:yt.length}):i("sessions.sidebar.bulkActions.deletedPlural",{count:yt.length})),mt.length>0&&K.error(mt.length===1?i("sessions.sidebar.bulkActions.failedDeleteSingle",{count:mt.length}):i("sessions.sidebar.bulkActions.failedDeletePlural",{count:mt.length}))}else{const{archivedIds:yt,failedIds:mt}=await Os(je);yt.length>0&&K.success(yt.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:yt.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:yt.length})),mt.length>0&&K.error(mt.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:mt.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:mt.length}))}br.getState().clear()}},[Os,fr,js,zs,i]),Xe=o.useCallback(()=>{const je=zs.size;if(je!==0){if(!z){Re();return}X({sessionCount:je,archivedBucket:fr})}},[fr,Re,zs,z]),st=o.useCallback(async()=>{X(null),await Re()},[Re]);o.useEffect(()=>{if(!Pr)return;const je=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),yt=mt=>{if(Or)return;const Ut=mt.target;if(Ut&&(Ut.tagName==="INPUT"||Ut.tagName==="TEXTAREA"||Ut.isContentEditable))return;const bs=je?mt.metaKey:mt.ctrlKey;if(mt.key==="Escape"){mt.preventDefault(),br.getState().disable();return}if(bs&&mt.key==="Backspace"){mt.preventDefault(),Xe();return}if(bs&&(mt.key==="a"||mt.key==="A")){const Gs=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Gs.length===0)return;mt.preventDefault();const Ar=Ca.getState().scopeKey??Gs[0]?.getAttribute("data-session-scope")??null,lr=Fn=>Ar?Fn.getAttribute("data-session-scope")===Ar:!0,$n=Gs.filter(lr).map(Fn=>Fn.getAttribute("data-session-row")).filter(Fn=>typeof Fn=="string"&&Fn.length>0);if($n.length===0)return;Ca.getState().replaceAll($n,Ar||null)}};return window.addEventListener("keydown",yt),()=>window.removeEventListener("keydown",yt)},[Xe,Or,Ca,Pr]);const ht=o.useCallback(()=>{$e("chat"),t&&oe(!1),Oe()},[t,Oe,$e,oe]),Vt=o.useCallback(()=>{$e("chat"),t&&oe(!1),Ye()},[t,Ye,$e,oe]);return s.jsxs("div",{ref:m,className:ge("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[s.jsx(TA,{hideDirectoryControls:r,mobileVariant:t,handleOpenDirectoryDialog:kr,openNewSessionDraft:Vt,canOpenMultiRun:Q.length>0,openMultiRunLauncher:ht,headerActionIconClass:ai,headerActionButtonClass:_i,isSessionSearchOpen:l,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchQuery:d,setSessionSearchQuery:f,hasSessionSearchQuery:et,searchMatchCount:yn,collapseAllProjects:ur,expandAllProjects:Be,openScheduledTasksDialog:()=>Ee(!0),selectionModeEnabled:Pr,onToggleSelectionMode:Vi}),s.jsx(HA,{topContent:vn,sectionsForRender:or,projectSections:wn,activeProjectId:ce,showOnlyMainWorkspace:a,hasSessionSearchQuery:et,emptyState:ss,searchEmptyState:pn,renderGroupSessions:An,homeDirectory:ke,collapsedProjects:P,hideDirectoryControls:r,projectRepoStatus:S,isDesktopShellRuntime:Ds,stuckProjectHeaders:Bi,mobileVariant:t,alwaysShowActions:Ks,toggleProject:St,setActiveProjectIdOnly:le,setActiveMainTab:$e,setSessionSwitcherOpen:oe,openNewSessionDraft:Ye,openNewWorktreeDialog:Ct,openProjectEditDialog:j,removeProject:ve,projectHeaderSentinelRefs:Se,reorderProjects:Te,getOrderedGroups:si,setGroupOrderByProject:ae,openSidebarMenuKey:B,setOpenSidebarMenuKey:G,isInlineEditing:Or}),Pr&&zs.size>0?s.jsx(LD,{selectedCount:zs.size,scopeKey:hn,scopeFolders:Ia,archivedBucket:fr,onMoveToFolder:Pa,onCreateFolderAndMove:ua,onRemoveFromFolder:ii,canRemoveFromFolder:Ro,onDelete:Xe,onDone:Gn}):null,s.jsx(_A,{onOpenSettings:Kt,onOpenShortcuts:L,onOpenAbout:()=>U(!0),onOpenUpdate:kt,showRuntimeButtons:!Xt,showUpdateButton:Tt}),s.jsx(_d,{open:$,onOpenChange:O,info:Mt.info,downloading:Mt.downloading,downloaded:Mt.downloaded,progress:Mt.progress,error:Mt.error,onDownload:Mt.downloadUpdate,onRestart:Mt.restartToUpdate,runtimeType:Mt.runtimeType}),Ke?s.jsx(Sv,{open:!!Ke,onOpenChange:je=>{je||j(null)},projectId:Ke.id,projectName:Ke.label||Ja(Ke.path,ke),projectPath:Ke.path,initialIcon:Ke.icon,initialColor:Ke.color,initialIconBackground:Ke.iconBackground,onSave:Je}):null,s.jsx(rP,{open:_,onOpenChange:V,onWorktreeCreated:(je,yt)=>{if($e("chat"),t&&oe(!1),yt?.sessionId){zt(yt.sessionId);return}Ye({directoryOverride:je})}}),s.jsx(MP,{}),s.jsx(MD,{value:ue,setValue:de,showDeletionDialog:z,setShowDeletionDialog:De,onConfirm:Kn}),s.jsx(FD,{value:pe,setValue:W,onConfirm:Hn}),s.jsx(RD,{value:te,setValue:X,showDeletionDialog:z,setShowDeletionDialog:De,onConfirm:st})]})},qD=()=>{const t=ot.c(13),[e,n]=Ve.useState(!1);let r,a;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(In())},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),Ve.useEffect(r,a);let i;t[2]!==e?(i=async p=>e?await kv(p):{success:!0,path:p},t[2]=e,t[3]=i):i=t[3];const l=i;let c;t[4]!==e?(c=async p=>e?await Cv():{success:!0},t[4]=e,t[5]=c):c=t[5];const d=c;let f;t[6]!==e?(f=async p=>e?await Iv():{success:!0},t[6]=e,t[7]=f):f=t[7];const m=f;let u;return t[8]!==e||t[9]!==l||t[10]!==d||t[11]!==m?(u={isDesktop:e,requestAccess:l,startAccessing:d,stopAccessing:m},t[8]=e,t[9]=l,t[10]=d,t[11]=m,t[12]=u):u=t[12],u},JD=t=>t==="/",Ql=t=>t.replace(/\\/g,"/"),Du=t=>{if(!t||JD(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},Si=t=>t.endsWith("/"),YD=t=>{const e=t.trim();return!e||Si(e)?e:`${e}/`},Tu=t=>t.lastIndexOf("/"),bx=t=>{if(Si(t))return t;const e=Tu(t);return e<0?t:t.slice(0,e+1)},QD=t=>{const e=Tu(t);return t.slice(e+1)},yx=t=>{const e=Du(t.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=Tu(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},XD=t=>Si(t)&&yx(t)!==null,ZD=(t,e)=>`${bx(t)}${e}/`,Ma=t=>{if(!t)return null;const e=Du(Ql(t.trim()));return e?e.toLowerCase():null},Jf=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},eT=t=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?t.metaKey&&!t.ctrlKey:t.ctrlKey&&!t.metaKey,cd=t=>{if(!t)return;t.focus({preventScroll:!0});const e=t.value.length;t.setSelectionRange(e,e),t.scrollLeft=t.scrollWidth},tT=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 Ql(e.home.trim())}}catch{}return rn.getFilesystemHome().catch(()=>null)},sT=({open:t,onOpenChange:e})=>{const{t:n}=pt(),r=Ms(Ie=>Ie.homeDirectory),a=Ss(Ie=>Ie.projects),i=Ss(Ie=>Ie.addProject),l=tr(Ie=>Ie.profiles),c=tr(Ie=>Ie.globalIdentity),d=tr(Ie=>Ie.defaultGitIdentityId),f=tr(Ie=>Ie.loadProfiles),m=tr(Ie=>Ie.loadGlobalIdentity),u=tr(Ie=>Ie.loadDefaultGitIdentityId),p=rc(),{isDesktop:b,requestAccess:g,startAccessing:y}=qD(),{isMobile:x}=an(),h=o.useRef(null),j=o.useRef(null),v=o.useRef(new Map),[C,k]=o.useState(""),[w,N]=o.useState("~/"),[I,E]=o.useState([]),[P,T]=o.useState(!1),[S,M]=o.useState(!1),[D,F]=o.useState(0),[_,V]=o.useState(!1),[$,O]=o.useState(!1),[B,G]=o.useState(0),[R,H]=o.useState(!1),[J,ne]=o.useState(""),[ue,de]=o.useState(null),pe=C||r,W=o.useMemo(()=>new Set(a.map(Ie=>Ma(Ie.path)).filter(Ie=>!!Ie)),[a]);o.useEffect(()=>{if(!t)return;N("~/"),E([]),F(0),V(!1),O(!1),H(!1),ne(""),de(null),requestAnimationFrame(()=>cd(h.current));let Ie=!1;return(async()=>{const De=await tT();Ie||(k(De||r||""),requestAnimationFrame(()=>cd(h.current)))})(),()=>{Ie=!0}},[r,t]),o.useEffect(()=>{t&&(f(),m(),u())},[u,f,m,t]);const te=o.useMemo(()=>{const Ie=new Map;c&&Ie.set(c.id,c);for(const z of l)Ie.set(z.id,z);return Array.from(Ie.values())},[l,c]);o.useEffect(()=>{if(!t||!R||ue!==null)return;const Ie=typeof d=="string"?d.trim():"";if(Ie&&te.some(De=>De.id===Ie)){de(Ie);return}const z=te.find(De=>De.authType==="ssh"||De.sshKey);z&&de(z.id)},[te,d,R,t,ue]);const X=o.useMemo(()=>te.find(Ie=>Ie.id===ue)??null,[te,ue]),ee=o.useMemo(()=>bx(w),[w]),fe=o.useMemo(()=>Si(w)?"":QD(w),[w]),be=o.useMemo(()=>pe?Jf(ee,pe):"",[ee,pe]);o.useEffect(()=>{if(!t||!be){E([]);return}let Ie=!1;return T(!0),M(!1),rn.listLocalDirectory(be).then(z=>{if(Ie)return;M(!1);const De=z.filter(Qe=>Qe.isDirectory).map(Qe=>({name:Qe.name,path:Ql(Qe.path)})).sort((Qe,tt)=>Qe.name.localeCompare(tt.name));E(De)}).catch(()=>{Ie||(E([]),M(!0))}).finally(()=>{Ie||T(!1)}),()=>{Ie=!0}},[be,t]);const Ne=o.useMemo(()=>{const Ie=fe.toLowerCase(),z=p||fe.startsWith(".");return I.filter(De=>De.name.toLowerCase().startsWith(Ie)&&(z||!De.name.startsWith(".")))},[fe,I,p]),se=o.useMemo(()=>{const Ie=[];XD(w)&&Ie.push({type:"up",value:"browse:up",name:"..",path:yx(w)});for(const z of Ne){const De=Ma(z.path);Ie.push({type:"directory",value:`browse:${z.path}`,name:z.name,path:z.path,disabled:!!(De&&W.has(De))})}return Ie},[W,Ne,w]);o.useEffect(()=>{F(0)},[w,se.length]);const ie=o.useMemo(()=>pe?Du(Jf(w,pe)):"",[pe,w]),ae=Ma(ie),xe=!!(ae&&W.has(ae)),Z=o.useMemo(()=>fe?Ne.find(Ie=>Ie.name===fe)??null:null,[fe,Ne]),me=!!(ie&&!xe&&(Si(w)&&S||!Si(w)&&fe.trim().length>0&&Z===null)),Y=!_&&!$&&!xe&&!!ie,Se=Y&&J.trim().length>0,we=se[D]??null,ke=!!(we&&(we.type==="up"||we.type==="directory"&&!we.disabled)),Fe=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Ce=n(xe?"directoryExplorerDialog.actions.alreadyAdded":R?_?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":_?"directoryExplorerDialog.actions.adding":me?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");o.useLayoutEffect(()=>{const Ie=j.current;if(!Ie)return;const z=()=>G(Math.ceil(Ie.getBoundingClientRect().width));if(z(),typeof ResizeObserver>"u")return;const De=new ResizeObserver(z);return De.observe(Ie),()=>De.disconnect()},[Ce]),o.useLayoutEffect(()=>{const Ie=h.current;Ie&&(Ie.scrollLeft=Ie.scrollWidth)},[B,w]),o.useLayoutEffect(()=>{t&&cd(h.current)},[t]),o.useLayoutEffect(()=>{const Ie=se[D];Ie&&v.current.get(Ie.value)?.scrollIntoView({block:"nearest"})},[D,se]);const Q=o.useCallback(()=>{e(!1)},[e]),ce=o.useCallback((Ie,z)=>{Ie.stopPropagation();const De=Ma(z);if(De&&W.has(De))return;i(z)||K.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")})},[i,W,n]),ve=o.useCallback(async Ie=>{if(!Ie||_)return;const z=Ma(Ie);if(z&&W.has(z))return;let De=Ie;V(!0);try{const Qe=!R&&me&&Ma(Ie)===Ma(ie);if(R){const et=J.trim();if(!et){K.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}De=(await rn.cloneRepository({remoteUrl:et,destinationPath:Ie,gitIdentityId:X?.id??null})).path}else Qe&&await rn.createDirectory(Ie,{allowOutsideWorkspace:!0});if(!i(De)){K.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}Q()}catch(Qe){K.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Qe instanceof Error?Qe.message:n("directoryExplorerDialog.toast.unknownError")})}finally{V(!1)}},[i,W,J,Q,R,_,X?.id,me,ie,n]),le=o.useCallback(Ie=>{N(YD(Ie))},[]),Ae=o.useCallback(Ie=>{N(ZD(w,Ie.name))},[w]),Te=o.useCallback(Ie=>{if(Ie){if(Ie.type==="up"){Ie.path&&le(Ie.path);return}Ie.disabled||Ae(Ie)}},[le,Ae]),$e=o.useCallback(async()=>{if(!(!b||$)){O(!0);try{const Ie=await g(ie);if(!Ie.success||!Ie.path){Ie.error&&Ie.error!=="Directory selection cancelled"&&K.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Ie.error});return}const z=await y(Ie.path);if(!z.success){K.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:z.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await ve(Ie.path)}catch(Ie){K.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Ie instanceof Error?Ie.message:n("directoryExplorerDialog.toast.unknownError")})}finally{O(!1)}}},[ve,b,$,g,y,n,ie]),ye=o.useCallback(Ie=>{if(Ie.key==="ArrowDown"){Ie.preventDefault(),F(z=>Math.min(se.length-1,z+1));return}if(Ie.key==="ArrowUp"){Ie.preventDefault(),F(z=>Math.max(0,z-1));return}if(Ie.key==="Enter"){if(Ie.preventDefault(),eT(Ie)){ve(ie);return}ke&&Te(we);return}Ie.key==="Backspace"&&w===""&&(Ie.preventDefault(),Q())},[Te,ve,Q,ke,we,w,se.length,ie]),q=s.jsxs("button",{type:"button",onClick:()=>ml(!p),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:[p?s.jsx(A,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(A,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),L=s.jsxs("div",{className:"px-2.5 py-1.5",children:[R?s.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[s.jsx($t,{value:J,onChange:Ie=>ne(Ie.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(ug,{activeProfile:X,identities:te,onSelect:Ie=>de(Ie.id),isApplying:_,iconOnly:!0})]}):null,s.jsxs("div",{className:"relative",children:[s.jsx(A,{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($t,{ref:h,value:w,onChange:Ie=>N(Ql(Ie.target.value)),onKeyDown:ye,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&&B>0?{paddingRight:`${B+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),x?null:s.jsx(he,{ref:j,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:R?!Se:!Y,onMouseDown:Ie=>Ie.preventDefault(),onClick:()=>{ve(ie)},title:Ce,children:Ce})]})]}),U=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")}):se.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:se.map((Ie,z)=>{const De=z===D;return s.jsxs("button",{ref:Qe=>{Qe?v.current.set(Ie.value,Qe):v.current.delete(Ie.value)},type:"button",disabled:Ie.type==="directory"&&Ie.disabled,onMouseEnter:()=>F(z),onMouseDown:Qe=>Qe.preventDefault(),onClick:()=>Te(Ie),className:ge("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",De&&"bg-interactive-selection text-interactive-selection-foreground",!De&&"hover:bg-interactive-hover/50",Ie.type==="directory"&&Ie.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[Ie.type==="up"?s.jsx(A,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(A,{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:Ie.name})}),Ie.type==="directory"&&Ie.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")}):Ie.type==="directory"?s.jsx("button",{type:"button",onMouseDown:Qe=>Qe.stopPropagation(),onClick:Qe=>ce(Qe,Ie.path),className:"flex-shrink-0 rounded-full p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",title:n("directoryExplorerDialog.browse.quickAdd"),children:s.jsx(A,{name:"add",className:"h-3.5 w-3.5"})}):null]},Ie.value)})})]})}),oe=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[L,U]}),Ee=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(A,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),s.jsx(A,{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(A,{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:Fe}),s.jsx(A,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),Oe=()=>s.jsxs(s.Fragment,{children:[x?null:Ee,s.jsxs("div",{className:ge("flex w-full flex-row justify-end gap-2 sm:w-auto",x&&"justify-stretch"),children:[b?s.jsx(he,{variant:"ghost",size:"xs",onClick:$e,disabled:_||$||R,children:n($?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(he,{variant:"ghost",size:"xs",onClick:()=>H(Ie=>!Ie),disabled:_||$,className:ge(x&&"flex-1"),children:n(R?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),x?s.jsx(he,{size:"xs",onClick:()=>{ve(ie)},disabled:R?!Se:!Y,className:"flex-1",children:Ce}):null]})]});return x?s.jsx(Ur,{open:t,onClose:Q,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:Oe()}),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[s.jsx("div",{className:"flex justify-end",children:q}),oe]})}):s.jsx(ls,{open:t,onOpenChange:e,children:s.jsxs(os,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[s.jsx(ps,{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(ds,{children:n("directoryExplorerDialog.title")}),s.jsx(ys,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),q]})}),s.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:oe}),s.jsx(Rs,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:Oe()})]})})},Ra=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,Br=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},nT=()=>{const{t}=pt(),[e,n]=o.useState(!1),[r,a]=o.useState(!1),[i,l]=o.useState(null),[c,d]=o.useState([]),[f,m]=o.useState(!1),[u,p]=o.useState(!1),[b,g]=o.useState(!1),[y,x]=o.useState(!1),[h,j]=o.useState(new Set),v=Lt(Y=>Y.getWorktreeMetadata),C=Lt(Y=>Y.newSessionDraft),k=Lt(Y=>Y.setNewSessionDraftTarget),w=Lt(Y=>Y.setDraftBootstrapPendingDirectory),N=Pv,I=Tv,E=Lt(Y=>Y.deleteSessions),P=Lt(Y=>Y.archiveSessions),T=_e(Y=>Y.showDeletionDialog),S=_e(Y=>Y.setShowDeletionDialog),M=Ms(Y=>Y.currentDirectory),D=Ms(Y=>Y.homeDirectory),F=Ms(Y=>Y.isHomeReady),_=Ss(Y=>Y.projects),V=Ss(Y=>Y.activeProjectId),{isMobile:$,isTablet:O,hasTouchInput:B}=an(),G=$||O||B,R=o.useMemo(()=>{const Se=(V?_.find(we=>we.id===V)??null:null)?.path??M;return Br(Se)},[V,M,_]),H=o.useCallback(Y=>{const we=Br(Y.projectDirectory)||R;return{id:(_.find(Fe=>Br(Fe.path)===we)??null)?.id??`path:${we}`,path:we}},[R,_]),J=y&&h.size>0,ne=o.useMemo(()=>{const Y=i?.worktree;return Y&&typeof Y.branch=="string"&&Y.branch.trim().length>0?!0:c.length>0&&c.every(({metadata:Se})=>typeof Se.branch=="string"&&Se.branch.trim().length>0)},[i?.worktree,c]),ue=i?.mode==="worktree",de=ue,pe=b||!ue||!ne,W=b||!ue;o.useEffect(()=>{r||!F||_.length>0||(a(!0),n(!0))},[r,F,_.length]);const te=o.useCallback(Y=>{l({sessions:Y.sessions,dateLabel:Y.dateLabel,mode:Y.mode??"session",worktree:Y.worktree??null})},[]),X=o.useCallback(()=>{l(null),d([]),m(!1),p(!1),g(!1),x(!1),j(new Set)},[]),ee=o.useCallback(async Y=>{if(Y.sessions.length===0)return;if(Y.sessions.length===1){const Fe=Y.sessions[0];await N(Fe.id)?K.success(t("sessions.sidebar.session.delete.success")):K.error(t("sessions.sidebar.session.delete.error"));return}const Se=Y.sessions.map(Fe=>Fe.id),{deletedIds:we,failedIds:ke}=await E(Se);if(we.length>0){const Fe=ke.length>0?ke.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:ke.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:ke.length}):Y.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:Y.dateLabel}):void 0;K.success(we.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:we.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:we.length}),{description:Ra(Fe)})}ke.length>0&&K.error(ke.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ke.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:ke.length}),{description:Ra(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[N,E,t]);o.useEffect(()=>Mr.onDeleteRequest(Y=>{if(!T&&(Y.mode??"session")==="session"){ee(Y);return}te(Y)}),[te,T,ee]),o.useEffect(()=>Mr.onDirectoryRequest(()=>{n(!0)}),[]),o.useEffect(()=>{if(!i){d([]),m(!1),p(!1),x(!1),j(new Set);return}const Y=i.sessions.map(ke=>{const Fe=v(ke.id);return Fe?{session:ke,metadata:Fe}:null}).filter(ke=>!!ke);d(Y),m(!1),x(!1),j(new Set);const Se=new Map;if(i.worktree?.path&&Se.set(Br(i.worktree.path),i.worktree),Y.forEach(({metadata:ke})=>{ke.path&&Se.set(Br(ke.path),ke)}),Se.size===0){x(!0);return}let we=!1;return(async()=>{const ke=new Map,Fe=new Set;await Promise.all(Array.from(Se.entries()).map(async([Ce,Q])=>{try{const ce=await Av(Q.path);ke.set(Ce,ce),ce?.isDirty&&Fe.add(Ce)}catch{Q.status&&(ke.set(Ce,Q.status),Q.status.isDirty&&Fe.add(Ce))}})).catch(Ce=>{console.warn("Failed to inspect worktree status before deletion:",Ce)}),!we&&(j(Fe),x(!0),l(Ce=>{if(!Ce?.worktree?.path)return Ce;const Q=Br(Ce.worktree.path),ce=ke.get(Q);if(!ce)return Ce;const ve=Ce.worktree.status;return ve?.isDirty===ce.isDirty&&ve?.ahead===ce.ahead&&ve?.behind===ce.behind&&ve?.upstream===ce.upstream?Ce:{...Ce,worktree:{...Ce.worktree,status:ce}}}),d(Ce=>Ce.map(Q=>{const ce=Br(Q.metadata.path),ve=ke.get(ce);return ve?{session:Q.session,metadata:{...Q.metadata,status:ve}}:Q})))})(),()=>{we=!0}},[i,v]),o.useEffect(()=>{ne||m(!1)},[ne]);const fe=o.useCallback(async(Y,Se)=>{const we=f&&ne,ke=H(Y),Fe=Br(Y.path),Ce=Br(ke.path);try{await Dv(ke,Y,{deleteRemoteBranch:we,deleteLocalBranch:Se});const Q=Br(C?.directoryOverride);return C?.open&&Fe&&Q===Fe&&Ce&&(w(null),k({projectId:ke.id,directoryOverride:Ce},{force:!0})),Br(M)===Fe&&Ce&&Ms.getState().setDirectory(Ce,{showOverlay:!1}),!0}catch(Q){return K.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Ra(Q instanceof Error?Q.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[ne,M,f,H,C?.directoryOverride,C?.open,w,k,t]),be=o.useCallback(async()=>{if(i){g(!0);try{const Y=de,Se=Y&&f,we=Y&&u;if(i.sessions.length===0&&ue&&i.worktree){if(!await fe(i.worktree,we)){X();return}const Ce=t(f&&ne?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");K.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Ra(Ce)}),X();return}if(i.sessions.length===1){const ke=i.sessions[0];if(!(ue?await I(ke.id):await N(ke.id,{archiveWorktree:!1,deleteRemoteBranch:Se,deleteLocalBranch:we}))){K.error(t(ue?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),g(!1);return}const Ce=!ue&&Y?t(Se?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;K.success(t(ue?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Ra(Ce),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const ke=i.sessions.map(Q=>Q.id);let Fe=[],Ce=[];if(ue){const Q=await P(ke);Fe=Q.archivedIds,Ce=Q.failedIds}else{const Q=await E(ke);Fe=Q.deletedIds,Ce=Q.failedIds}if(ue&&i.worktree&&Ce.length===0&&await fe(i.worktree,we),Fe.length>0){const Q=!ue&&Y?t(Se?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,ve=[Ce.length>0?ue?Ce.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:Ce.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:Ce.length}):Ce.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:Ce.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:Ce.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,Q].filter(Boolean).join(" ");K.success(ue?Fe.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:Fe.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:Fe.length}):Fe.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Fe.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Fe.length}),{description:Ra(ve||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(Ce.length>0&&(K.error(ue?Ce.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Ce.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:Ce.length}):Ce.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:Ce.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:Ce.length}),{description:Ra(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),Fe.length===0)){g(!1);return}}ue&&i.sessions.length===1&&i.worktree&&await fe(i.worktree,we),X()}finally{g(!1)}}},[i,f,u,N,E,I,P,X,de,ue,ne,fe,t]),Ne=i?.worktree??c[0]?.metadata??null,se=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}):"",ie=i?s.jsxs("div",{className:ge(ue?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:ge(ue?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[ue&&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:ge(ue?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(Y=>s.jsxs("li",{className:ge(ue?"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:ge(!ue&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:Y.title||t("sessions.sidebar.session.untitled")})]},Y.id)),i.sessions.length>5&&s.jsx("li",{className:ge(ue?"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})})]})]}),ue?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(A,{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")}),Ne?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:Ne.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:Ne?xo(Ne.path,D):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),J&&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,ae=ue?ne?s.jsxs("button",{type:"button",onClick:()=>{pe||m(Y=>!Y)},disabled:pe,className:ge("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",pe?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[f?s.jsx(A,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(A,{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,xe=ue?s.jsxs("button",{type:"button",onClick:()=>{W||p(Y=>!Y)},disabled:W,className:ge("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",W?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(A,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(A,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,Z=ue?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:[xe,ae]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(he,{variant:"ghost",onClick:X,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(he,{variant:"destructive",onClick:be,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:()=>S(!T),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":!T,children:[T?s.jsx(A,{name:"checkbox-blank",className:"size-4"}):s.jsx(A,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(he,{variant:"ghost",onClick:X,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(he,{variant:"destructive",onClick:be,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")})]})]}),me=ue?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:[G?s.jsx(Ur,{open:!!i,onClose:()=>{b||X()},title:me,footer:s.jsx("div",{className:"flex justify-end gap-2",children:Z}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[se&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:se}),ie]})}):s.jsx(ls,{open:!!i,onOpenChange:Y=>{if(!Y){if(b)return;X()}},children:s.jsxs(os,{className:ge(ue?"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(ps,{children:[s.jsxs(ds,{className:ge(ue&&"flex items-center gap-2"),children:[ue&&s.jsx(A,{name:"delete-bin",className:"h-5 w-5"}),me]}),se&&s.jsx(ys,{children:se})]}),s.jsx("div",{className:ge(ue&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:ie}),s.jsx(Rs,{className:"mt-2 gap-2 pt-1 pb-1",children:Z})]})}),s.jsx(sT,{open:e,onOpenChange:n})]})},qd=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),rT=(t,e)=>{const n=qd(t),r=qd(e);return`${n}-${r}`.substring(0,60)},Yf=(t,e)=>`${t}/${e}`,aT=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},Qf=(t,e)=>{const n=aT(e),r=t.directory,a=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};Fv(t.id,n),Lt.getState().markSessionAsOpenChamberCreated(t.id),wa.getState().upsertSession(a);try{Lv().ensureChild(n,{bootstrap:!1}).setState(l=>{const c=l.session.findIndex(f=>f.id===t.id);if(c>=0&&l.session[c]===a)return l;const d=c>=0?l.session.map((f,m)=>m===c?a:f):[...l.session,a].sort((f,m)=>f.id.localeCompare(m.id));return{session:d,sessionTotal:Math.max(l.sessionTotal,d.length),limit:Math.max(l.limit,d.length)}})}catch{}return a},iT=()=>{const t=Ss.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=Ms.getState().currentDirectory??null;if(r&&r.trim().length>0){const a=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${a}`,path:a}}return null},dd=ar()(ei(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),{groups:r,agent:a,files:i,setupCommands:l}=e;if(!n)return t({error:"Group name is required"}),null;if(!r||r.length===0)return t({error:"At least one run group is required"}),null;for(let c=0;c<r.length;c++){if(!r[c].prompt.trim())return t({error:`Group ${c+1}: prompt is required`}),null;if(r[c].models.length<1)return t({error:`Group ${c+1}: select at least 1 model`}),null;if(r[c].models.length>5)return t({error:`Group ${c+1}: maximum 5 models allowed`}),null}t({isLoading:!0,error:null});try{const c=iT();if(!c)return t({error:"Select a project",isLoading:!1}),null;const d=c.path,m=await Eh(d)&&e.isolateRuns!==!1,u=qd(n),p=m?await Po(d):void 0,b=m?await Ev(d):null,g=[],y=l?.filter(C=>C.trim().length>0)??[];for(let C=0;C<r.length;C++){const k=r[C],w=k.prompt,N=new Map;for(const E of k.models){const P=`${E.providerID}:${E.modelID}`;N.set(P,(N.get(P)||0)+1)}const I=new Map;for(const E of k.models){const P=`${E.providerID}:${E.modelID}`,T=N.get(P)||1,S=(I.get(P)||0)+1;I.set(P,S);const M=rT(E.providerID,E.modelID),D=r.length>1?`g${C+1}`:void 0,F=T>1?Yf(u,`${M}/${S}`):Yf(u,M),_=D?`${D}/${F}`:F,V=pD({groupSlug:u,runGroup:D,providerID:E.providerID,modelID:E.modelID,index:T>1?S:void 0});try{if(!m){const G=await rn.withDirectory(d,()=>rn.createSession({title:V}));Qf(G,d),g.push({sessionId:G.id,worktreePath:d,providerID:E.providerID,modelID:E.modelID,variant:E.variant,prompt:w});continue}const $=await Mv(c,{preferredName:_,mode:"new",branchName:_,worktreeName:_,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:y},{resolvedRootTrackingRemote:b}),O={...$,createdFromBranch:p,kind:"standard"},B=await rn.withDirectory($.path,()=>rn.createSession({title:V}));Qf(B,$.path),Lt.getState().setWorktreeMetadata(B.id,O),g.push({sessionId:B.id,worktreePath:$.path,providerID:E.providerID,modelID:E.modelID,variant:E.variant,prompt:w})}catch($){console.warn("[MultiRun] Failed to create session:",$)}}}const x=l?.filter(C=>C.trim().length>0)??[];x.length>0&&Mh(c,x).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const h=g.map(C=>C.sessionId),j=g[0]?.sessionId??null;if(h.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const v=i?.map(C=>({type:"file",mime:C.mime,filename:C.filename,url:C.url}));return(async()=>{try{const C=lc.getState().expandText;await Promise.allSettled(g.map(async k=>{try{const w=await C(k.prompt).catch(()=>k.prompt);await Rv({sessionId:k.sessionId,directory:k.worktreePath,content:w,providerID:k.providerID,modelID:k.modelID,variant:k.variant,agent:a,files:v})}catch(w){console.warn("[MultiRun] Failed to start run:",w)}}))}catch(C){console.warn("[MultiRun] Failed to start runs:",C)}})(),t({isLoading:!1}),{groupSlug:u,sessionIds:h,firstSessionId:j}}catch(c){return t({error:c instanceof Error?c.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"})),oT="oc:lastWorktreeSourceBranch";function vx(t){const e=ot.c(30),{git:n}=Wn(),r=su(t),a=tu(t),i=nu(t),l=$h(t),c=qs(mT),d=qs(uT);let f,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==a||e[4]!==i?(f=()=>{!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]=f,e[6]=m):(f=e[5],m=e[6]),o.useEffect(f,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 p=r?.all;let b;e[13]!==t||e[14]!==c||e[15]!==n||e[16]!==a||e[17]!==p?(b=[t,n,a,p,c],e[13]=t,e[14]=c,e[15]=n,e[16]=a,e[17]=p,e[18]=b):b=e[18],o.useEffect(u,b);const g=i||a===!0&&l;let y;e:{if(!r?.all){let N;e[19]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[19]=N):N=e[19],y=N;break e}let w;e[20]!==r.all?(w=r.all.filter(dT).sort(),e[20]=r.all,e[21]=w):w=e[21],y=w}const x=y;let h;e:{if(!r?.all){let N;e[22]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[22]=N):N=e[22],h=N;break e}let w;e[23]!==r.all?(w=r.all.filter(cT).map(lT).sort(),e[23]=r.all,e[24]=w):w=e[24],h=w}const j=h;let v;e:{if(!t){v=null;break e}if(a!==null){v=a;break e}if(g){v=null;break e}v=r?.all?!0:null}const C=v;let k;return e[25]!==C||e[26]!==g||e[27]!==x||e[28]!==j?(k={localBranches:x,remoteBranches:j,isLoading:g,isGitRepository:C},e[25]=C,e[26]=g,e[27]=x,e[28]=j,e[29]=k):k=e[29],k}function lT(t){return t.replace(/^remotes\//,"")}function cT(t){return t.startsWith("remotes/")}function dT(t){return!t.startsWith("remotes/")}function uT(t){return t.fetchStatus}function mT(t){return t.fetchBranches}const pT=({directory:t,value:e,onChange:n,className:r,disabled:a,id:i})=>{const{t:l}=pt(),{localBranches:c,remoteBranches:d,isLoading:f,isGitRepository:m}=vx(t),u=o.useMemo(()=>[...c,...d.map(b=>`remotes/${b}`)],[c,d]);o.useEffect(()=>{if(a||f||u.length===0||e&&u.includes(e))return;(async()=>{try{const g=t?await Po(t).catch(()=>null):null,y=localStorage.getItem(oT);y&&u.includes(y)?n(y):g&&u.includes(g)?n(g):u.includes("main")?n("main"):u.includes("master")?n("master"):u[0]&&n(u[0])}catch{}})()},[u,t,a,f,n,e]);const p=a||!m||f;return s.jsxs("div",{children:[s.jsxs(ns,{value:e,onValueChange:n,disabled:p,children:[s.jsx(rs,{id:i,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(ms,{placeholder:l(f?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(as,{className:"max-h-[280px] max-w-[320px]",children:f?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("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:l("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[c.length>0&&s.jsxs(bd,{children:[s.jsx(um,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.localBranches")}),c.map(b=>s.jsx(Rt,{value:b,className:"whitespace-normal break-all",children:b},b))]}),c.length>0&&d.length>0&&s.jsx(Ov,{}),d.length>0&&s.jsxs(bd,{children:[s.jsx(um,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.remoteBranches")}),d.map(b=>s.jsx(Rt,{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:l("multiRun.branchSelector.status.notInGitRepository")})]})},fT=10*1024*1024,ud=5,Pl=t=>{const e=ot.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(A,{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},Ba=t=>{const e=ot.c(9),{htmlFor:n,required:r,children:a,info:i}=t;let l;e[0]!==r?(l=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=l):l=e[1];let c;e[2]!==a||e[3]!==n||e[4]!==l?(c=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,l]}),e[2]=a,e[3]=n,e[4]=l,e[5]=c):c=e[5];const d=i&&i;let f;return e[6]!==c||e[7]!==d?(f=s.jsxs("div",{className:"flex items-center gap-1.5",children:[c,d]}),e[6]=c,e[7]=d,e[8]=f):f=e[8],f},hT=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:a}=pt(),[i,l]=o.useState(""),[c,d]=o.useState(()=>[{id:uo(),prompt:"",models:[]}]),[f,m]=o.useState(""),[u,p]=o.useState([]),[b,g]=o.useState(!1),[y,x]=o.useState([]),[h,j]=o.useState(!1),[v,C]=o.useState(!1),[k,w]=o.useState(!0),N=o.useRef(null),I=Ms(Q=>Q.currentDirectory??null),E=Ms(Q=>Q.homeDirectory??null),P=o.useMemo(()=>{if(typeof window>"u")return null;const Q=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof Q=="string"&&Q.trim().length>0?Q.trim():null},[]),T=Ss(Q=>Q.activeProjectId),S=Ss(Q=>Q.setActiveProjectIdOnly),M=Ss(Q=>Q.projects),[D,F]=o.useState(()=>T??null);o.useEffect(()=>{if(T){F(T);return}!D&&M.length>0&&F(M[0].id)},[T,M,D]);const _=o.useMemo(()=>D?M.find(Q=>Q.id===D)??null:null,[M,D]),V=_?.path??I,$=o.useCallback(Q=>{F(Q),Q!==T&&S(Q)},[T,S]),{currentTheme:O}=Sr(),B=o.useCallback(Q=>{const ce=Q.label?.trim()||Ja(Q.path,E),ve=Do({id:Q.id,iconImage:Q.iconImage??null},{themeVariant:O.metadata.variant,iconColor:O.colors.surface.foreground}),le=Q.icon?oc[Q.icon]:null,Ae=Q.color?To[Q.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[ve?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:Q.iconBackground?{backgroundColor:Q.iconBackground}:void 0,children:s.jsx("img",{src:ve,alt:"",className:"h-full w-full object-contain",draggable:!1})}):le?s.jsx(A,{name:le,className:"h-3.5 w-3.5 shrink-0",style:Ae?{color:Ae}:void 0}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:Ae?{color:Ae}:void 0}),s.jsx("span",{className:"truncate",children:ce})]})},[E,O.metadata.variant,O.colors.surface.foreground]),G=o.useMemo(()=>{if(_?.path)return{id:_.id,path:_.path};const Q=I??P;return Q?{id:`path:${Q}`,path:Q}:null},[_,I,P]),[R]=o.useState(()=>typeof window<"u"?In():!1),H=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),J=bh(),ne=o.useMemo(()=>{if(typeof window>"u")return null;const Q=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Q=="number"&&Number.isFinite(Q)&&Q>0)return Q;if(typeof navigator>"u")return null;const ce=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!ce)return null;const ve=Number.parseInt(ce[1],10),le=Number.parseInt(ce[2],10);return Number.isNaN(ve)?null:ve===10?le:ve},[]),ue=o.useMemo(()=>R&&H||J?"pl-[5.5rem]":"pl-3",[R,H,J]),de=o.useMemo(()=>!R||!H||ne===null?"":ne>=26?"h-12":ne<=15?"h-14":"",[R,H,ne]),pe=o.useCallback(async Q=>{Q.target.closest("button, a, input, select, textarea")||Q.button===0&&R&&await $v()},[R]);o.useEffect(()=>{if(!n)return;const Q=ce=>{ce.key==="Escape"&&(ce.preventDefault(),ce.stopPropagation(),n())};return window.addEventListener("keydown",Q,!0),()=>window.removeEventListener("keydown",Q,!0)},[n]);const[W,te]=o.useState(""),{isLoading:X,isGitRepository:ee}=vx(V),fe=o.useRef(!1),be=ee===!0,Ne=be&&k;o.useEffect(()=>{if(ee===!1){fe.current=!0,w(!1);return}ee===!0&&fe.current&&(fe.current=!1,w(!0))},[ee]);const se=dd(Q=>Q.createMultiRun),ie=dd(Q=>Q.error),ae=dd(Q=>Q.clearError);o.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(Q=>{const ce=[...Q];return ce.length>0&&!ce[0].prompt.trim()&&(ce[0]={...ce[0],prompt:t}),ce})},[t]),o.useEffect(()=>{if(!G)return;let Q=!1;return C(!0),(async()=>{try{const ce=await cu(G);Q||x(ce)}catch{}finally{Q||C(!1)}})(),()=>{Q=!0}},[G]);const xe=o.useCallback((Q,ce)=>{d(ve=>ve.map(le=>le.id===Q?{...le,...ce}:le))},[]),Z=o.useCallback(Q=>{d(ce=>ce.filter(ve=>ve.id!==Q))},[]),me=o.useCallback(()=>{d(Q=>[...Q,{id:uo(),prompt:"",models:[]}])},[]),Y=async Q=>{const ce=Q.target.files;if(!ce)return;let ve=0;for(let le=0;le<ce.length;le++){const Ae=ce[le];if(Ae.size>fT){K.error(a("multirun.launcher.toast.fileTooLarge",{fileName:Ae.name}));continue}try{const Te=await new Promise(($e,ye)=>{const q=new FileReader;q.onload=()=>$e(q.result),q.onerror=ye,q.readAsDataURL(Ae)});p($e=>[...$e,{id:uo(),filename:Ae.name,mimeType:Ae.type||"application/octet-stream",size:Ae.size,dataUrl:Te}]),ve++}catch(Te){console.error("File attach failed",Te),K.error(a("multirun.launcher.toast.attachFailed",{fileName:Ae.name}))}}ve>0&&K.success(ve===1?a("multirun.launcher.toast.attachedSingle",{count:ve}):a("multirun.launcher.toast.attachedPlural",{count:ve})),N.current&&(N.current.value="")},Se=Q=>{p(ce=>ce.filter(ve=>ve.id!==Q))},we=o.useMemo(()=>c.reduce((Q,ce)=>Q+ce.models.length,0),[c]),ke=async Q=>{Q.preventDefault();const ce=c.filter(ve=>ve.prompt.trim()&&ve.models.length>=1);if(ce.length!==0&&!(we<1)){g(!0),ae();try{D&&D!==T&&S(D);const ve=u.map(ye=>({mime:ye.mimeType,filename:ye.filename,url:ye.dataUrl})),le=y.filter(ye=>ye.trim().length>0),Ae=ce.map(ye=>({prompt:ye.prompt.trim(),models:ye.models.map(q=>({providerID:q.providerID,modelID:q.modelID,displayName:q.displayName,variant:q.variant}))})),Te={name:i.trim(),groups:Ae,agent:f||void 0,worktreeBaseBranch:Ne?W:void 0,isolateRuns:Ne,files:ve.length>0?ve:void 0,setupCommands:le.length>0?le:void 0},$e=await se(Te);$e&&($e.firstSessionId&&Lt.getState().setCurrentSession($e.firstSessionId),e?.())}finally{g(!1)}}},Fe=!!(i.trim()&&c.some(Q=>Q.prompt.trim()&&Q.models.length>=1)&&we>=1&&V&&!X&&(ee===!1||!Ne||W)),Ce=y.filter(Q=>Q.trim()).length;return s.jsxs("form",{onSubmit:ke,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:pe,className:ge("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",ue,de),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(A,{name:"close",className:"h-5 w-5"})})}),s.jsx(At,{children:s.jsx("p",{children:a("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(Io,{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(Ba,{htmlFor:"multirun-project",required:!0,children:a("multirun.launcher.project.label")}),M.length>0?s.jsxs(ns,{value:D??void 0,onValueChange:$,children:[s.jsx(rs,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:_?s.jsx(ms,{children:B(_)}):s.jsx(ms,{placeholder:a("multirun.launcher.project.placeholder")})}),s.jsx(as,{fitContent:!0,children:M.map(Q=>s.jsx(Rt,{value:Q.id,className:"max-w-[24rem]",children:B(Q)},Q.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(Ba,{htmlFor:"group-name",required:!0,info:s.jsx(Pl,{children:a("multirun.launcher.groupName.info")}),children:a("multirun.launcher.groupName.label")}),s.jsx($t,{id:"group-name",value:i,onChange:Q=>l(Q.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(Ba,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Pl,{children:a("multirun.launcher.baseBranch.info")}),children:a("multirun.launcher.baseBranch.label")}),s.jsx(pT,{directory:V,value:W,onChange:te,disabled:!Ne,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:k,onChange:w,disabled:!be,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(Ba,{htmlFor:"multirun-agent",info:s.jsx(Pl,{children:a("multirun.launcher.agent.info")}),children:a("multirun.launcher.agent.label")}),s.jsx(mx,{value:f,onChange:m,id:"multirun-agent"})]})]}),s.jsxs(jr,{open:h,onOpenChange:j,children:[s.jsxs(Lr,{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(A,{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")}),Ce>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:Ce}),s.jsx(A,{name:"arrow-down-s",className:ge("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",h&&"rotate-180")})]}),s.jsx(Nr,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:v?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:a("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[y.map((Q,ce)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx($t,{value:Q,onChange:ve=>{const le=[...y];le[ce]=ve.target.value,x(le)},placeholder:a("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>x(y.filter((ve,le)=>le!==ce)),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(A,{name:"close",className:"h-3.5 w-3.5"})})]},`${Q}-${ce}`)),s.jsxs("button",{type:"button",onClick:()=>x([...y,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(A,{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(Ba,{htmlFor:"prompt",required:!0,children:a("multirun.launcher.attachments.label")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:N,type:"file",multiple:!0,className:"hidden",onChange:Y,accept:"*/*"}),s.jsxs(It,{children:[s.jsx(Pt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>N.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(A,{name:"attachment-2",className:"h-3 w-3"}),a("multirun.launcher.attachments.attach")]})}),s.jsx(At,{children:a("multirun.launcher.attachments.tooltip")})]}),u.map(Q=>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:[Q.mimeType.startsWith("image/")?s.jsx(A,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(A,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:Q.filename,children:Q.filename}),s.jsx("button",{type:"button",onClick:()=>Se(Q.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(A,{name:"close",className:"h-3 w-3"})})]},Q.id))]})]}),c.map((Q,ce)=>s.jsx(gT,{group:Q,groupIndex:ce,canRemove:c.length>1,onUpdate:xe,onRemove:Z},Q.id)),s.jsxs("button",{type:"button",onClick:me,className:"flex items-center gap-1.5 py-2 px-3 -mx-3 rounded-lg typography-meta font-medium text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),a("multirun.launcher.groups.addGroup")]}),ie&&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:ie})]})})}),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:[!Ne&&ee!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(A,{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(he,{type:"button",variant:"ghost",size:"sm",onClick:n,children:a("multirun.launcher.actions.cancel")}),s.jsx(he,{type:"submit",size:"sm",disabled:!Fe||b,children:b?a("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:a("multirun.launcher.actions.startWithRunCount",{count:we})})})]})})]})},gT=t=>{const e=ot.c(99),{group:n,groupIndex:r,canRemove:a,onUpdate:i,onRemove:l}=t,{t:c}=pt(),[d,f]=o.useState(!1),[m,u]=o.useState(""),[p,b]=o.useState(!1),[g,y]=o.useState(""),[x,h]=o.useState(!1),[j,v]=o.useState(""),C=o.useRef(null),k=o.useRef(null),w=o.useRef(null),N=o.useRef(null);let I;e[0]!==n.id||e[1]!==n.models||e[2]!==i?(I=le=>{n.models.length>=ud||i(n.id,{models:[...n.models,le]})},e[0]=n.id,e[1]=n.models,e[2]=i,e[3]=I):I=e[3];const E=I;let P;e[4]!==n.id||e[5]!==n.models||e[6]!==i?(P=le=>{i(n.id,{models:n.models.filter((Ae,Te)=>Te!==le)})},e[4]=n.id,e[5]=n.models,e[6]=i,e[7]=P):P=e[7];const T=P;let S;e[8]!==n.id||e[9]!==n.models||e[10]!==i?(S=(le,Ae)=>{i(n.id,{models:n.models.map((Te,$e)=>$e===le?Ae:Te)})},e[8]=n.id,e[9]=n.models,e[10]=i,e[11]=S):S=e[11];const M=S;let D;e[12]===Symbol.for("react.memo_cache_sentinel")?(D=(le,Ae)=>{if(le.startsWith("/")){const q=le.indexOf(" "),L=le.indexOf(`
|
|
236
|
+
`),U=Math.min(q===-1?le.length:q,L===-1?le.length:L);if(Ae<=U&&q===-1){y(le.substring(1,U)),b(!0),f(!1),h(!1);return}}b(!1);const Te=le.substring(0,Ae),$e=Te.lastIndexOf("#");if($e!==-1){const q=$e>0?Te[$e-1]:null,L=Te.substring($e+1);if((!q||/\s/.test(q))&&!L.includes(" ")&&!L.includes(`
|
|
237
|
+
`)){v(L),h(!0),f(!1);return}}h(!1);const ye=Te.lastIndexOf("@");if(ye!==-1){const q=ye>0?Te[ye-1]:null,L=Te.substring(ye+1);(!q||/\s/.test(q))&&!L.includes(" ")&&!L.includes(`
|
|
238
|
+
`)?(u(L),f(!0)):f(!1);return}f(!1)},e[12]=D):D=e[12];const F=D;let _;e[13]!==n.id||e[14]!==i?(_=le=>{i(n.id,{prompt:le})},e[13]=n.id,e[14]=i,e[15]=_):_=e[15];const V=_;let $;e[16]!==n.prompt||e[17]!==V?($=le=>{const Ae=n.prompt,$e=C.current?.selectionStart??Ae.length,q=Ae.substring(0,$e).lastIndexOf("@"),L=le.relativePath&&le.relativePath.trim().length>0?le.relativePath.trim():le.path||le.name,U=q!==-1?q:$e,oe=`${Ae.substring(0,U)}@${L} ${Ae.substring($e)}`,Ee=U+L.length+2;V(oe),f(!1),u(""),requestAnimationFrame(()=>{const Oe=C.current;Oe&&(Oe.selectionStart=Ee,Oe.selectionEnd=Ee,Oe.focus()),F(oe,Ee)})},e[16]=n.prompt,e[17]=V,e[18]=$):$=e[18];const O=$;let B;e[19]!==n.prompt||e[20]!==V?(B=le=>{const Ae=n.prompt,$e=C.current?.selectionStart??Ae.length,q=Ae.substring(0,$e).lastIndexOf("@"),L=q!==-1?q:$e,U=`${Ae.substring(0,L)}@${le} ${Ae.substring($e)}`,oe=L+le.length+2;V(U),f(!1),u(""),requestAnimationFrame(()=>{const Ee=C.current;Ee&&(Ee.selectionStart=oe,Ee.selectionEnd=oe,Ee.focus()),F(U,oe)})},e[19]=n.prompt,e[20]=V,e[21]=B):B=e[21];const G=B;let R;e[22]!==V?(R=le=>{const Ae=`/${le.name} `;V(Ae),b(!1),y(""),h(!1),requestAnimationFrame(()=>{const Te=C.current;Te&&(Te.focus(),Te.selectionStart=Te.value.length,Te.selectionEnd=Te.value.length),F(Ae,Ae.length)})},e[22]=V,e[23]=R):R=e[23];const H=R;let J;e[24]!==n.prompt||e[25]!==V?(J=(le,Ae)=>{const Te=n.prompt,ye=C.current?.selectionStart??Te.length,L=Te.substring(0,ye).lastIndexOf("#"),U=L!==-1?L:ye,oe=`${Te.substring(0,U)}#${Ae} ${Te.substring(ye)}`,Ee=U+Ae.length+2;V(oe),h(!1),v(""),requestAnimationFrame(()=>{const Oe=C.current;Oe&&(Oe.selectionStart=Ee,Oe.selectionEnd=Ee,Oe.focus()),F(oe,Ee)})},e[24]=n.prompt,e[25]=V,e[26]=J):J=e[26];const ne=J;let ue;e[27]!==p||e[28]!==d||e[29]!==x?(ue=le=>{if(p&&w.current&&(le.key==="Enter"||le.key==="ArrowUp"||le.key==="ArrowDown"||le.key==="Escape"||le.key==="Tab")){le.preventDefault(),w.current.handleKeyDown(le.key);return}d&&k.current&&(le.key==="Enter"||le.key==="ArrowUp"||le.key==="ArrowDown"||le.key==="Escape"||le.key==="Tab")&&(le.preventDefault(),k.current.handleKeyDown(le.key)),x&&N.current&&(le.key==="Enter"||le.key==="ArrowUp"||le.key==="ArrowDown"||le.key==="Escape"||le.key==="Tab")&&(le.preventDefault(),N.current.handleKeyDown(le.key))},e[27]=p,e[28]=d,e[29]=x,e[30]=ue):ue=e[30];const de=ue,pe=r+1;let W;e[31]!==c||e[32]!==pe?(W=c("multirun.launcher.groups.groupLabel",{index:pe}),e[31]=c,e[32]=pe,e[33]=W):W=e[33];let te;e[34]!==W?(te=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:W}),e[34]=W,e[35]=te):te=e[35];let X;e[36]!==a||e[37]!==n.id||e[38]!==l||e[39]!==c?(X=a&&s.jsx("button",{type:"button",onClick:()=>l(n.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10","aria-label":c("multirun.launcher.groups.removeGroup"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=a,e[37]=n.id,e[38]=l,e[39]=c,e[40]=X):X=e[40];let ee;e[41]!==te||e[42]!==X?(ee=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[te,X]}),e[41]=te,e[42]=X,e[43]=ee):ee=e[43];let fe;e[44]!==c?(fe=c("multirun.launcher.groups.prompt.label"),e[44]=c,e[45]=fe):fe=e[45];let be;e[46]!==fe?(be=s.jsx(Ba,{required:!0,children:fe}),e[46]=fe,e[47]=be):be=e[47];const Ne=n.prompt;let se;e[48]!==V?(se=le=>{const Ae=le.target.value;V(Ae);const Te=le.target.selectionStart??Ae.length;F(Ae,Te)},e[48]=V,e[49]=se):se=e[49];let ie;e[50]!==c?(ie=c("multirun.launcher.groups.prompt.placeholder"),e[50]=c,e[51]=ie):ie=e[51];let ae;e[52]!==n.prompt||e[53]!==de||e[54]!==se||e[55]!==ie?(ae=s.jsx(ln,{ref:C,value:Ne,onChange:se,onKeyDown:de,placeholder:ie,className:"typography-meta min-h-[80px] max-h-[200px] resize-none overflow-y-auto field-sizing-content",required:!0}),e[52]=n.prompt,e[53]=de,e[54]=se,e[55]=ie,e[56]=ae):ae=e[56];let xe;e[57]!==g||e[58]!==H||e[59]!==p?(xe=p?s.jsx(_h,{ref:w,searchQuery:g,onCommandSelect:H,onClose:()=>b(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=g,e[58]=H,e[59]=p,e[60]=xe):xe=e[60];let Z;e[61]!==G||e[62]!==O||e[63]!==m||e[64]!==d?(Z=d?s.jsx(Bh,{ref:k,searchQuery:m,onFileSelect:O,onAgentSelect:G,onClose:()=>f(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=G,e[62]=O,e[63]=m,e[64]=d,e[65]=Z):Z=e[65];let me;e[66]!==ne||e[67]!==x||e[68]!==j?(me=x?s.jsx(Vh,{ref:N,searchQuery:j,onSnippetSelect:ne,onClose:()=>h(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=ne,e[67]=x,e[68]=j,e[69]=me):me=e[69];let Y;e[70]!==ae||e[71]!==xe||e[72]!==Z||e[73]!==me?(Y=s.jsxs("div",{className:"relative",children:[ae,xe,Z,me]}),e[70]=ae,e[71]=xe,e[72]=Z,e[73]=me,e[74]=Y):Y=e[74];let Se;e[75]!==be||e[76]!==Y?(Se=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[be,Y]}),e[75]=be,e[76]=Y,e[77]=Se):Se=e[77];let we;e[78]!==c?(we=c("multirun.launcher.models.info",{max:ud}),e[78]=c,e[79]=we):we=e[79];let ke;e[80]!==we?(ke=s.jsx(Pl,{children:we}),e[80]=we,e[81]=ke):ke=e[81];let Fe;e[82]!==c?(Fe=c("multirun.launcher.models.label"),e[82]=c,e[83]=Fe):Fe=e[83];let Ce;e[84]!==ke||e[85]!==Fe?(Ce=s.jsx(Ba,{required:!0,info:ke,children:Fe}),e[84]=ke,e[85]=Fe,e[86]=Ce):Ce=e[86];let Q;e[87]!==n.models||e[88]!==E||e[89]!==T||e[90]!==M?(Q=s.jsx(fx,{selectedModels:n.models,onAdd:E,onRemove:T,onUpdate:M,minModels:1,maxModels:ud}),e[87]=n.models,e[88]=E,e[89]=T,e[90]=M,e[91]=Q):Q=e[91];let ce;e[92]!==Ce||e[93]!==Q?(ce=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[Ce,Q]}),e[92]=Ce,e[93]=Q,e[94]=ce):ce=e[94];let ve;return e[95]!==ee||e[96]!==Se||e[97]!==ce?(ve=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[ee,Se,ce]}),e[95]=ee,e[96]=Se,e[97]=ce,e[98]=ve):ve=e[98],ve};class xT extends o.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(Wh,{className:"w-full max-w-md",children:[s.jsx(_v,{className:"text-center",children:s.jsxs(Bv,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(A,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(Vv,{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(he,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(A,{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 bT(t){const e=ot.c(22),{t:n}=pt();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 l;e[6]!==n?(l=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=l):l=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 f;e[12]!==r||e[13]!==a||e[14]!==i||e[15]!==l||e[16]!==c||e[17]!==d?(f={title:r,description:a,sessionLabel:i,detailsSummary:l,resetAction:c,persistentHint:d},e[12]=r,e[13]=a,e[14]=i,e[15]=l,e[16]=c,e[17]=d,e[18]=f):f=e[18];let m;return e[19]!==t||e[20]!==f?(m=s.jsx(xT,{...t,texts:f}),e[19]=t,e[20]=f,e[21]=m):m=e[21],m}const Jd=t=>{const e=ot.c(5),{readOnly:n}=t,r=n===void 0?!1:n,i=Lt(yT)||void 0;let l;e[0]!==r?(l=s.jsx(zv,{readOnly:r}),e[0]=r,e[1]=l):l=e[1];let c;return e[2]!==i||e[3]!==l?(c=s.jsx(bT,{sessionId:i,children:l}),e[2]=i,e[3]=l,e[4]=c):c=e[4],c};function yT(t){return t.currentSessionId}const vT=ca(()=>Rr(()=>Promise.resolve().then(()=>QS),void 0).then(t=>({default:t.PlanView}))),Xf=ca(()=>Rr(()=>Promise.resolve().then(()=>a2),void 0).then(t=>({default:t.GitView}))),wT=ca(()=>Rr(()=>Promise.resolve().then(()=>bS),void 0).then(t=>({default:t.DiffView}))),Zf=ca(()=>Rr(()=>import("./TerminalView-CuXkDROt.js"),__vite__mapDeps([5,0,1,2,3,4])).then(t=>({default:t.TerminalView}))),jT=ca(()=>Rr(()=>Promise.resolve().then(()=>KS),void 0).then(t=>({default:t.FilesView}))),NT=ca(()=>Rr(()=>Promise.resolve().then(()=>e6),void 0).then(t=>({default:t.SettingsView}))),ST=ca(()=>Rr(()=>import("./SettingsWindow-_c3TTL2z.js"),__vite__mapDeps([6,0,1,2,3,4])).then(t=>({default:t.SettingsWindow}))),kT=ca(()=>Rr(()=>import("./MultiRunWindow-Cl7wS_CB.js"),__vite__mapDeps([7,0,1,2,3,4])).then(t=>({default:t.MultiRunWindow}))),CT=280,IT=500,PT=360,AT=860,DT=()=>{const a=_e(W=>W.isSidebarOpen),i=_e(W=>W.isRightSidebarOpen),l=_e(W=>W.isBottomTerminalOpen),c=_e(W=>W.setRightSidebarOpen),d=_e(W=>W.setBottomTerminalOpen),f=_e(W=>W.activeMainTab),m=_e(W=>W.setIsMobile),u=_e(W=>W.isSessionSwitcherOpen),p=_e(W=>W.isSettingsDialogOpen),b=_e(W=>W.setSettingsDialogOpen),g=_e(W=>W.isMultiRunLauncherOpen),y=_e(W=>W.setMultiRunLauncherOpen),x=_e(W=>W.multiRunLauncherPrefillPrompt),{isMobile:h,isTablet:j}=an(),v=_e(W=>W.sidebarWidth),C=_e(W=>W.rightSidebarWidth),k=o.useRef(!1),w=o.useRef(!1),N=o.useRef(!1),[I,E]=o.useState(!1),[P,T]=o.useState(!1),[S,M]=o.useState(!1),[D,F]=o.useState(!1),_=o.useCallback(W=>{E(W),_e.getState().setSessionSwitcherOpen(W)},[]),V=o.useRef(!1),$=o.useRef(typeof window>"u"?0:window.innerWidth),O=_u(-$.current),B=Ve.useRef(0),G=_u($.current),R=Ve.useRef(0);Ve.useEffect(()=>{h&&(B.current=window.innerWidth,R.current=window.innerWidth)},[h]),Ve.useEffect(()=>{if(!h){M(!1);return}I&&M(!0),Bu(O,I?0:-B.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[I,h,O]),Ve.useEffect(()=>{if(!h){F(!1);return}V.current=P,P&&F(!0),Bu(G,P?0:R.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[h,P,G]),Ve.useEffect(()=>{if(h)return O.on("change",W=>{const te=B.current||$.current,X=I||W>-te+.5;M(ee=>ee===X?ee:X)})},[h,O,I]),Ve.useEffect(()=>{if(h)return G.on("change",W=>{const te=R.current||$.current,X=P||W<te-.5;F(ee=>ee===X?ee:X)})},[h,P,G]),Ve.useEffect(()=>{h&&!u&&I&&_(!1)},[u,h,I,_]),Ve.useEffect(()=>{if(!h){N.current=!1;return}N.current||(N.current=!0,_(!1),T(!1),_e.getState().isRightSidebarOpen&&c(!1))},[h,_,c]),Ve.useEffect(()=>{if(!h||f!=="chat"||I||P||p)return;let W=!1,te;const X=ee=>{te=window.setTimeout(()=>{if(W)return;const fe=Lt.getState(),be=_e.getState();if(!(be.activeMainTab!=="chat"||be.isSettingsDialogOpen||fe.currentSessionId||fe.newSessionDraft?.open)){if(fe.isLoading){X(250);return}fe.openNewSessionDraft()}},ee)};return X(500),()=>{W=!0,te!==void 0&&window.clearTimeout(te)}},[f,h,p,I,P]),Ve.useEffect(()=>{!h||!p||(_(!1),T(!1),i&&c(!1))},[h,p,i,_,c]);const H=Ka(W=>W.checkForUpdates);o.useEffect(()=>{let fe=!1,be=null;const Ne=ie=>{const ae=Math.round(ie*1e3);return Math.max(3e5,Math.min(864e5,ae))},se=ie=>{fe||(be=window.setTimeout(async()=>{const ae=await H(),xe=typeof ae=="number"&&Number.isFinite(ae)?Ne(ae):36e5;se(xe)},ie))};return se(3e3),()=>{fe=!0,be!==null&&window.clearTimeout(be)}},[H]),o.useEffect(()=>{_e.getState().isMobile!==h&&m(h)},[h,m]),o.useEffect(()=>{if(typeof window>"u")return;let W;const te=()=>{W!==void 0&&window.clearTimeout(W),W=window.setTimeout(()=>{_e.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",te),()=>{window.removeEventListener("resize",te),W!==void 0&&window.clearTimeout(W)}},[]),o.useEffect(()=>{if(typeof window>"u")return;let W;const te=()=>{const ee=_e.getState(),fe=window.innerWidth,be=window.innerHeight;if(!h&&!j){const Ne=fe<1140,se=fe>=1220;Ne?ee.isRightSidebarOpen&&(c(!1),k.current=!0):se&&k.current&&(c(!0),k.current=!1);const ie=be<640,ae=be>=700;ie?ee.isBottomTerminalOpen&&(d(!1),w.current=!0):ae&&w.current&&(d(!0),w.current=!1)}},X=()=>{W!==void 0&&window.clearTimeout(W),W=window.setTimeout(()=>{te()},100)};return te(),window.addEventListener("resize",X),()=>{window.removeEventListener("resize",X),W!==void 0&&window.clearTimeout(W)}},[h,j,d,c]),o.useEffect(()=>{if(typeof window>"u")return;const W=_e.subscribe((te,X)=>{const ee=window.innerWidth,fe=window.innerHeight,be=ee>=1220,Ne=fe>=700;te.isRightSidebarOpen!==X.isRightSidebarOpen&&be&&(k.current=!1),te.isBottomTerminalOpen!==X.isBottomTerminalOpen&&Ne&&(w.current=!1)});return()=>{W()}},[h,j,d,c]);const J=o.useCallback(()=>{I&&_(!1),T(!P)},[I,P,_]),ne=o.useMemo(()=>{switch(f){case"plan":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(vT,{})});case"git":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(Xf,{})});case"diff":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(wT,{})});case"terminal":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(Zf,{})});case"files":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(jT,{})});case"context":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(Sg,{})});default:return null}},[f]),ue=f==="chat",de=o.useMemo(()=>Math.min(IT,Math.max(CT,v||Sd)),[v]),pe=o.useMemo(()=>Math.min(AT,Math.max(PT,C||kd)),[C]);return s.jsx(F0,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:ge("main-content-safe-area",h?"flex h-[100dvh] flex-col":"flex h-[100dvh]","bg-background"),children:[s.jsx(t6,{}),s.jsx(z6,{}),s.jsx(H6,{}),s.jsx(nT,{}),h?s.jsxs(Uv,{value:{leftDrawerOpen:I,rightDrawerOpen:P,toggleLeftDrawer:()=>{const W=!I;P&&T(!1),_(W)},toggleRightDrawer:J,leftDrawerX:O,rightDrawerX:G,leftDrawerWidth:B,rightDrawerWidth:R,setMobileLeftDrawerOpen:_,setRightSidebarOpen:T},children:[!p&&s.jsx(Dm,{onToggleLeftDrawer:()=>{const W=!I;P&&T(!1),_(W)},onToggleRightDrawer:()=>{J()},leftDrawerOpen:I,rightDrawerOpen:P}),s.jsx("div",{"data-page-scroll-lock":"true",className:ge("flex flex-1 overflow-hidden relative",p&&"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:ge("absolute inset-0",!ue&&"invisible"),children:s.jsx(Qs,{children:s.jsx(Jd,{})})}),ne&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Qs,{children:ne})}),g&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Qs,{children:s.jsx(hT,{initialPrompt:x,onCreated:()=>y(!1),onCancel:()=>y(!1)})})}),S&&s.jsx(Vu.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:O},"aria-hidden":!I,children:s.jsx(Qs,{children:s.jsx(qf,{mobileVariant:!0})})}),D&&s.jsx(Vu.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:G},"aria-hidden":!P,children:s.jsx(Qs,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(Xf,{})})})})]})}),p&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(Qs,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(NT,{onClose:()=>b(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[s.jsx(Dm,{}),s.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-sidebar","data-page-scroll-lock":"true",children:[s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute top-0 z-0 bg-sidebar transition-[left,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{left:`${a?de:0}px`,opacity:a?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute bottom-0 z-0 bg-sidebar transition-[left,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{left:`${a?de:0}px`,opacity:a?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute top-0 z-0 bg-sidebar transition-[right,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{right:`${i?pe:0}px`,opacity:i?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute bottom-0 z-0 bg-sidebar transition-[right,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{right:`${i?pe:0}px`,opacity:i?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)"}}),s.jsx(Vw,{isOpen:a,isMobile:h,className:"border-0",children:s.jsx(qf,{})}),s.jsxs("div",{className:ge("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-background","border border-border/50 rounded-[10px]",!a&&"border-l-transparent",!i&&"border-r-transparent"),"data-page-scroll-lock":"true",children:[s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden","data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:ge("absolute inset-0",!ue&&"invisible"),children:s.jsx(Qs,{children:s.jsx(Jd,{})})}),ne&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Qs,{children:ne})})]}),s.jsx(Ok,{})]})}),s.jsx(Lw,{isOpen:l,isMobile:h,children:l?s.jsx(Qs,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(Zf,{})})}):null})]}),s.jsx(zw,{isOpen:i,className:"border-0",children:s.jsx(Qs,{children:s.jsx($2,{})})})]})]}),s.jsx(o.Suspense,{fallback:null,children:s.jsx(ST,{open:p,onOpenChange:b})}),s.jsx(o.Suspense,{fallback:null,children:s.jsx(kT,{open:g,onOpenChange:y,initialPrompt:x})})]})]})})},TT=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`},xr=t=>{const e=ot.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 l;e[3]!==r?(l=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=l):l=e[4];let c;return e[5]!==i||e[6]!==l?(c=s.jsxs("div",{className:"rounded-md p-2",style:a,children:[i,l]}),e[5]=i,e[6]=l,e[7]=c):c=e[7],c},eh=t=>{const e=ot.c(43),{title:n,snapshot:r,emptyLabel:a}=t,{t:i}=pt();let l;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(RT,0),e[8]=r.entries,e[9]=d):d=e[9];const f=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?TT(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=u):u=e[15];let p;e[16]!==u?(p=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:u}),e[16]=u,e[17]=p):p=e[17];let b;e[18]!==m||e[19]!==p?(b=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,p]}),e[18]=m,e[19]=p,e[20]=b):b=e[20];let g;e[21]!==i?(g=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=g):g=e[22];let y;e[23]!==r.entries.length||e[24]!==g?(y=s.jsx(xr,{label:g,value:r.entries.length}),e[23]=r.entries.length,e[24]=g,e[25]=y):y=e[25];let x;e[26]!==i?(x=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=x):x=e[27];let h;e[28]!==x||e[29]!==f?(h=s.jsx(xr,{label:x,value:f}),e[28]=x,e[29]=f,e[30]=h):h=e[30];let j;e[31]!==i?(j=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=j):j=e[32];let v;e[33]!==r.lastUpdatedAt||e[34]!==i?(v=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=v):v=e[35];let C;e[36]!==j||e[37]!==v?(C=s.jsx(xr,{label:j,value:v}),e[36]=j,e[37]=v,e[38]=C):C=e[38];let k;e[39]!==h||e[40]!==C||e[41]!==y?(k=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[y,h,C]}),e[39]=h,e[40]=C,e[41]=y,e[42]=k):k=e[42],l=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[b,k,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(vs,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:c.map(w=>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:w.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:w.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:w.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:w.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:w.total})})]})]},w.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]=l}else l=e[7];return l},ET=t=>{const e=ot.c(101),{onClose:n}=t,{t:r}=pt(),[a,i]=o.useState("memory"),[l,c]=o.useState("idle"),d=Lt(FT),f=Uh(LT),m=ic(),u=Dh(OT),p=yr($T),[b,g]=o.useState(_T),[y,x]=o.useState(BT);let h;e[0]!==b.entries?(h=new Map,b.entries.forEach(we=>{h.set(we.metric,we.count)}),e[0]=b.entries,e[1]=h):h=e[1];let j;e[2]!==h?(j=h.get("ui.message_list.render")??0,e[2]=h,e[3]=j):j=e[3];let v;e[4]!==h?(v=h.get("ui.message_list.render.streaming")??0,e[4]=h,e[5]=v):v=e[5];let C;e[6]!==h?(C=h.get("ui.chat_message.render")??0,e[6]=h,e[7]=C):C=e[7];let k;e[8]!==h?(k=h.get("ui.chat_message.render.streaming")??0,e[8]=h,e[9]=k):k=e[9];let w;e[10]!==h?(w=h.get("ui.chat_message.render.static_during_stream")??0,e[10]=h,e[11]=w):w=e[11];let N;e[12]!==h?(N=h.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=h,e[13]=N):N=e[13];let I;e[14]!==j||e[15]!==v||e[16]!==C||e[17]!==k||e[18]!==w||e[19]!==N?(I={messageListRender:j,messageListRenderStreaming:v,chatMessageRender:C,chatMessageRenderStreaming:k,chatMessageRenderStaticDuringStream:w,chatMessageRenderStaticOutsideActiveTurnDuringStream:N},e[14]=j,e[15]=v,e[16]=C,e[17]=k,e[18]=w,e[19]=N,e[20]=I):I=e[20];const E=I;let P,T;e[21]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{const we=()=>{g(pl()),x(fl())};we();const ke=window.setInterval(we,500);return()=>window.clearInterval(ke)},T=[],e[21]=P,e[22]=T):(P=e[21],T=e[22]),o.useEffect(P,T);let S,M;e[23]!==l?(S=()=>{if(l==="idle")return;const we=window.setTimeout(()=>{c("idle")},1500);return()=>window.clearTimeout(we)},M=[l],e[23]=l,e[24]=S,e[25]=M):(S=e[24],M=e[25]),o.useEffect(S,M);let D=0,F;if(e[26]!==u?(F=Object.keys(u),e[26]=u,e[27]=F):F=e[27],e[28]!==u||e[29]!==F||e[30]!==D){for(const we of F)D=D+(u[we]?.length??0);e[28]=u,e[29]=F,e[30]=D,e[31]=D}else D=e[31];const _=D;let V;if(e[32]!==d||e[33]!==u||e[34]!==f||e[35]!==m||e[36]!==r){let we;e[38]!==d||e[39]!==u||e[40]!==f||e[41]!==r?(we=ke=>{const Fe=u[ke.id]?.length||0,Ce=f.get(ke.id);return{id:ke.id,title:ke.title||r("memoryDebugPanel.common.untitled"),messageCount:Fe,isStreaming:Ce?.isStreaming||!1,isZombie:Ce?.isZombie||!1,backgroundCount:Ce?.backgroundMessageCount||0,lastAccessed:Ce?.lastAccessedAt||0,isCurrent:ke.id===d}},e[38]=d,e[39]=u,e[40]=f,e[41]=r,e[42]=we):we=e[42],V=m.map(we).sort(VT),e[32]=d,e[33]=u,e[34]=f,e[35]=m,e[36]=r,e[37]=V}else V=e[37];const $=V;let O;e[43]!==u?(O=Object.keys(u),e[43]=u,e[44]=O):O=e[44];const B=O.length;let G;e[45]===Symbol.for("react.memo_cache_sentinel")?(G=async()=>{try{const we={generatedAt:new Date().toISOString(),ui:pl(),vscode:fl()};await navigator.clipboard.writeText(JSON.stringify(we,null,2)),c("copied")}catch{c("error")}},e[45]=G):G=e[45];const R=G;let H;e[46]===Symbol.for("react.memo_cache_sentinel")?(H={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=H):H=e[46];let J;e[47]!==a?(J=a==="memory"?s.jsx(A,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(A,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=a,e[48]=J):J=e[48];let ne;e[49]!==r?(ne=r("memoryDebugPanel.title"),e[49]=r,e[50]=ne):ne=e[50];let ue;e[51]!==ne?(ue=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:ne}),e[51]=ne,e[52]=ue):ue=e[52];let de;e[53]!==J||e[54]!==ue?(de=s.jsxs("div",{className:"flex items-center gap-2",children:[J,ue]}),e[53]=J,e[54]=ue,e[55]=de):de=e[55];let pe;e[56]!==a?(pe=a==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(he,{size:"xs",variant:"ghost",onClick:R,children:s.jsx(A,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(he,{size:"xs",variant:"ghost",onClick:()=>{Kv(),g(pl()),x(fl())},children:s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=a,e[57]=pe):pe=e[57];let W;e[58]!==n?(W=n?s.jsx(he,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(A,{name:"close",className:"h-4 w-4"})}):null,e[58]=n,e[59]=W):W=e[59];let te;e[60]!==pe||e[61]!==W?(te=s.jsxs("div",{className:"flex items-center gap-1",children:[pe,W]}),e[60]=pe,e[61]=W,e[62]=te):te=e[62];let X;e[63]!==de||e[64]!==te?(X=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[de,te]}),e[63]=de,e[64]=te,e[65]=X):X=e[65];let ee;e[66]===Symbol.for("react.memo_cache_sentinel")?(ee={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=ee):ee=e[66];const fe=a==="memory"?"secondary":"ghost";let be;e[67]===Symbol.for("react.memo_cache_sentinel")?(be=()=>i("memory"),e[67]=be):be=e[67];let Ne;e[68]!==r?(Ne=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=Ne):Ne=e[69];let se;e[70]!==fe||e[71]!==Ne?(se=s.jsx(he,{size:"sm",variant:fe,className:"flex-1",onClick:be,children:Ne}),e[70]=fe,e[71]=Ne,e[72]=se):se=e[72];const ie=a==="streaming"?"secondary":"ghost";let ae;e[73]===Symbol.for("react.memo_cache_sentinel")?(ae=()=>i("streaming"),e[73]=ae):ae=e[73];let xe;e[74]!==r?(xe=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=xe):xe=e[75];let Z;e[76]!==ie||e[77]!==xe?(Z=s.jsx(he,{size:"sm",variant:ie,className:"flex-1",onClick:ae,children:xe}),e[76]=ie,e[77]=xe,e[78]=Z):Z=e[78];let me;e[79]!==se||e[80]!==Z?(me=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:ee,children:[se,Z]}),e[79]=se,e[80]=Z,e[81]=me):me=e[81];let Y;e[82]!==a||e[83]!==B||e[84]!==l||e[85]!==d||e[86]!==u||e[87]!==f||e[88]!==$||e[89]!==m||e[90]!==E||e[91]!==b||e[92]!==r||e[93]!==p||e[94]!==_||e[95]!==y?(Y=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(xr,{label:r("memoryDebugPanel.metric.totalMessages"),value:_}),s.jsx(xr,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${B} / ${mm.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:Wv()})})]}),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:mm.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:p})]})]}),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(vs,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:$.map(we=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:we.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:we.title}),we.isStreaming?s.jsx(A,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,we.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:we.messageCount})}),we.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",we.backgroundCount]}):null]})]},we.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(he,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(zT),currentSessionId:d,cachedSessions:Object.keys(u),memoryStates:Object.fromEntries(f)})},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(l==="copied"?"memoryDebugPanel.streaming.copy.copied":l==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(he,{size:"xs",variant:"outline",onClick:R,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(xr,{label:r("memoryDebugPanel.metric.uiMetrics"),value:b.entries.length}),s.jsx(xr,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:y.entries.length}),s.jsx(xr,{label:r("memoryDebugPanel.metric.messageListRenders"),value:E.messageListRender}),s.jsx(xr,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:E.messageListRenderStreaming}),s.jsx(xr,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:E.chatMessageRender}),s.jsx(xr,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:E.chatMessageRenderStreaming}),s.jsx(xr,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:E.chatMessageRenderStaticDuringStream}),s.jsx(xr,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:E.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(eh,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:b,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),y.entries.length>0?s.jsx(eh,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:y,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=a,e[83]=B,e[84]=l,e[85]=d,e[86]=u,e[87]=f,e[88]=$,e[89]=m,e[90]=E,e[91]=b,e[92]=r,e[93]=p,e[94]=_,e[95]=y,e[96]=Y):Y=e[96];let Se;return e[97]!==X||e[98]!==me||e[99]!==Y?(Se=s.jsxs(Wh,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:H,children:[X,me,Y]}),e[97]=X,e[98]=me,e[99]=Y,e[100]=Se):Se=e[100],Se},MT=ET;function RT(t,e){return t+e.count}function FT(t){return t.currentSessionId}function LT(t){return t.sessionMemoryState}function OT(t){return t.message}function $T(t){return t.totalRequestCount}function _T(){return pl()}function BT(){return fl()}function VT(t,e){return e.lastAccessed-t.lastAccessed}function zT(t){return{id:t.id,title:t.title}}const UT=()=>{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()??"":""},WT=async()=>{const t=UT()||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")},th="openchamber:menu-action",md="openchamber:check-for-updates",KT=t=>{const e=Lt(N=>N.openNewSessionDraft),n=_e(N=>N.toggleCommandPalette),r=_e(N=>N.setCommandPaletteOpen),a=_e(N=>N.toggleHelpDialog),i=_e(N=>N.toggleSidebar),l=_e(N=>N.setSessionSwitcherOpen),c=_e(N=>N.setActiveMainTab),d=_e(N=>N.setSettingsDialogOpen),f=_e(N=>N.setAboutDialogOpen),m=_e(N=>N.toggleRightSidebar),u=_e(N=>N.setRightSidebarOpen),p=_e(N=>N.setRightSidebarTab),b=_e(N=>N.toggleBottomTerminal),g=_e(N=>N.setBottomTerminalExpanded),y=Ka(N=>N.checkForUpdates),{setThemeMode:x}=Sr(),h=o.useRef(!1),j=o.useCallback(()=>{h.current||(h.current=!0,y().then(()=>{const{available:N,error:I}=Ka.getState();if(I){K.error("Failed to check for updates",{description:I});return}N||K.success("You are on the latest version")}).finally(()=>{h.current=!1}))},[y]),v=o.useCallback(()=>{Mr.requestDirectoryDialog()},[]),C=o.useCallback(N=>{const I=Hv();if(I.length===0)return;const E=Lt.getState().currentSessionId,P=I.findIndex(M=>M.id===E);let T=N>0?0:I.length-1;P>=0&&(T=(P+N+I.length)%I.length);const S=I[T];S&&(c("chat"),l(!1),Lt.getState().setCurrentSession(S.id))},[c,l]),k=o.useCallback(N=>{const{activeProjectId:I,projects:E,setActiveProject:P}=Ss.getState();if(E.length===0)return;const T=E.findIndex(D=>D.id===I);let S=N>0?0:E.length-1;T>=0&&(S=(T+N+E.length)%E.length);const M=E[S];M&&P(M.id)},[]),w=o.useCallback(N=>{switch(N){case"about":f(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":c("chat"),l(!1),e();break;case"new-worktree-session":c("chat"),l(!1),Lh();break;case"change-workspace":v();break;case"toggle-right-sidebar":m();break;case"open-right-sidebar-git":u(!0),p("git");break;case"open-right-sidebar-files":u(!0),p("files");break;case"toggle-terminal":b();break;case"toggle-terminal-expanded":g(!_e.getState().isBottomTerminalExpanded);break;case"copy":{const I=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(I)||WT();break}case"theme-light":x("light");break;case"theme-dark":x("dark");break;case"theme-system":x("system");break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"go-back":Ms.getState().goBack();break;case"go-forward":Ms.getState().goForward();break;case"previous-session":C(-1);break;case"next-session":C(1);break;case"previous-project":k(-1);break;case"next-project":k(1);break;case"help-dialog":a();break;case"download-logs":{Gv().catch(()=>{K.error("Failed to collect OpenCode status")});break}}},[v,k,C,t,e,f,c,l,r,d,g,u,p,x,b,n,a,m,i]);o.useEffect(()=>{const N=E=>{const P=E.detail;P&&w(P)},I=()=>{j()};return window.addEventListener(th,N),window.addEventListener(md,I),()=>{window.removeEventListener(th,N),window.removeEventListener(md,I)}},[w,j]),o.useEffect(()=>{if(typeof window>"u")return;const I=window.__TAURI__?.event?.listen;if(typeof I!="function")return;let E=null,P=null;return I("openchamber:menu-action",T=>{const S=T?.payload;typeof S=="string"&&w(S)}).then(T=>{E=T}).catch(()=>{}),I("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(md))}).then(T=>{P=T}).catch(()=>{}),()=>{(async()=>{try{const S=E?.();S instanceof Promise&&await S}catch{}try{const S=P?.();S instanceof Promise&&await S}catch{}})()}},[w])},HT=["chat","git","diff","terminal","files"],GT=["settings","agents","commands","skills","providers","usage","git-identities"],Tr={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function sh(t){const e=qT();return{sessionId:JT(e),tab:YT(e),settingsPath:QT(e),diffFile:XT(e)}}function qT(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function JT(t){const e=t.get(Tr.SESSION);return!e||e.trim().length===0?null:e.trim()}function YT(t){const e=t.get(Tr.TAB);if(!e)return null;const n=e.toLowerCase().trim();return HT.includes(n)?n:null}function QT(t){const e=t.get(Tr.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(GT.includes(n),n)}function XT(t){const e=t.get(Tr.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function nh(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(Tr.SESSION)||t.has(Tr.TAB)||t.has(Tr.SETTINGS)||t.has(Tr.FILE)}catch{return!1}}const ZT="chat";function wx(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(Tr.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(Tr.SETTINGS,n),e}return t.tab!==ZT&&e.set(Tr.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(Tr.FILE,t.diffFile),e}function e7(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function t7(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=wx(t),r=[...e.entries()].sort((i,l)=>i[0].localeCompare(l[0])),a=[...n.entries()].sort((i,l)=>i[0].localeCompare(l[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 s7(t,e={}){if(!(typeof window>"u")&&!n7()&&!(!e.force&&t7(t)))try{const n=wx(t),r=e7(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function n7(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function r7(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function a7(){const t=o.useMemo(()=>r7(),[]),e=o.useRef(!1),n=o.useRef(!1),r=Lt(u=>u.setCurrentSession),a=_e(u=>u.setActiveMainTab),i=_e(u=>u.setSettingsDialogOpen),l=_e(u=>u.setSettingsPage),c=_e(u=>u.navigateToDiff),d=o.useCallback(async u=>{if(!n.current){n.current=!0;try{if(u.sessionId){const p=Lt.getState().currentSessionId;u.sessionId!==p&&await r(u.sessionId)}if(u.settingsPath){l(Nu(u.settingsPath)),i(!0);return}_e.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,l,c]),f=o.useCallback(()=>{const u=Lt.getState(),p=_e.getState();return{sessionId:u.currentSessionId,tab:p.activeMainTab,isSettingsOpen:p.isSettingsDialogOpen,settingsPath:p.settingsPage,diffFile:p.pendingDiffFile}},[]),m=o.useCallback((u={})=>{if(t||n.current)return;const p=f();s7(p,u)},[t,f]);o.useEffect(()=>{if(e.current||(e.current=!0,!nh()))return;const u=sh();(async()=>(await d(u),t||m({replace:!0})))()},[d,t,m]),o.useEffect(()=>{if(t)return;let u=Lt.getState().currentSessionId;return Lt.subscribe(b=>{const g=b.currentSessionId;g===u||n.current||(u=g,m())})},[t,m]),o.useEffect(()=>{if(t)return;let u=_e.getState().activeMainTab,p=_e.getState().isSettingsDialogOpen,b=_e.getState().settingsPage,g=_e.getState().pendingDiffFile;return _e.subscribe(x=>{if(n.current)return;const h=x.activeMainTab!==u,j=x.isSettingsDialogOpen!==p,v=x.settingsPage!==b,C=x.pendingDiffFile!==g&&x.activeMainTab==="diff";u=x.activeMainTab,p=x.isSettingsDialogOpen,b=x.settingsPage,g=x.pendingDiffFile,(h||j||v||C)&&m()})},[t,m]),o.useEffect(()=>{if(typeof window>"u"||t)return;const u=()=>{const p=sh();if(nh())d(p);else{const b=_e.getState();b.isSettingsDialogOpen&&i(!1),b.activeMainTab!=="chat"&&a("chat")}};return window.addEventListener("popstate",u),()=>{window.removeEventListener("popstate",u)}},[d,t,a,i])}const i7="/api/notifications/stream",o7=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),l7=t=>{if(!t||typeof t!="object")return null;const e=t,n=e.properties&&typeof e.properties=="object"?e.properties:null;return e.type!=="openchamber:notification"||!n?null:{title:typeof n.title=="string"?n.title:void 0,body:typeof n.body=="string"?n.body:void 0,tag:typeof n.tag=="string"?n.tag:void 0}},c7=t=>{const e=ot.c(3),n=t?.enabled??!0;let r,a;e[0]!==n?(r=()=>{if(!n||In()||!aa()||typeof window>"u"||typeof EventSource>"u")return;const i=new EventSource(i7);return i.onmessage=d7,()=>{i.close()}},a=[n],e[0]=n,e[1]=r,e[2]=a):(r=e[1],a=e[2]),o.useEffect(r,a)};function d7(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=_e.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&o7())return;const r=l7(e);if(!r)return;dr()?.notifications?.notifyAgentCompletion(r)}const u7=t=>!(t.dismissed==="true"||t.sessionShown==="true"||t.hasActiveToast),m7=t=>!(!t.version||t.seenVersions.has(t.version)||t.dismissedVersion!==null&&t.dismissedVersion===t.version),p7=t=>{if(t===null||typeof t!="object")return"";const e=t.version;return typeof e!="string"?"":e.trim()},f7=t=>!t||t.available!==!0||typeof t.latestVersion!="string"?"":t.latestVersion.trim(),rh="pwa-install-toast-shown",ah="pwa-install-toast-dismissed",h7=()=>{const t=ot.c(6),{browserTab:e}=Qg(),{t:n}=pt(),r=o.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]),o.useEffect(a,i);let l,c;t[3]!==e?(l=()=>{if(typeof window>"u"||!aa()||!e)return;let d=null,f=null;const m=()=>{f!==null&&(K.dismiss(f),f=null)},u=async()=>{if(!d)return;const g=d;d=null,m(),await g.prompt();const{outcome:y}=await g.userChoice;y==="accepted"&&K.success(r.current("pwa.installPrompt.started"))},p=g=>{const y=g;if(typeof y.prompt!="function")return;y.preventDefault(),d=y;const x=vr(),h=hh();u7({dismissed:x.getItem(ah),sessionShown:h.getItem(rh),hasActiveToast:f!==null})&&(h.setItem(rh,"true"),f=K.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{u()}},cancel:{label:r.current("pwa.installPrompt.dismiss"),onClick:()=>{vr().setItem(ah,"true"),m()}}}))},b=()=>{d=null,m(),K.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",p),window.addEventListener("appinstalled",b),()=>{m(),window.removeEventListener("beforeinstallprompt",p),window.removeEventListener("appinstalled",b)}},c=[e],t[3]=e,t[4]=l,t[5]=c):(l=t[4],c=t[5]),o.useEffect(l,c)},g7=["local","remote",null],x7=["ok","not-configured","unreachable","wrong-service","missing"];function jx(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!g7.includes(n)))return{valid:!1};if(typeof r!="string"||!x7.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 ih(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 b7(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function y7(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function oh(){if(Yd()!=="valid")return null;const e=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__,n=jx(e);return n.valid?n.outcome:null}function Yd(){if(typeof window>"u")return"not-injected";const t=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":jx(t).valid?"valid":"malformed"}const v7=()=>{const t=ot.c(5),[e,n]=o.useState(w7),{isUpdating:r,message:a}=e;let i,l;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>Jv(n),l=[],t[0]=i,t[1]=l):(i=t[0],l=t[1]),o.useEffect(i,l),!r)return null;let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(ou,{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 w7(){return qv()}const j7=({open:t,onOpenChange:e})=>{const{t:n}=pt(),r=!1,[a,i]=o.useState(null),[l,c]=o.useState(null),[d,f]=o.useState(!1),[m,u]=o.useState(!1),[p,b]=o.useState(null),[g,y]=o.useState(!1);o.useCallback(async()=>{},[p,d,r,n]),o.useEffect(()=>{if(!t)return;(async()=>{try{const j=await fetch("/api/system/info");if(j.ok){const v=await j.json();if(typeof v.openchamberVersion=="string"&&v.openchamberVersion.trim()){i(v.openchamberVersion);return}}}catch{}i(await Yv())})()},[t]),o.useEffect(()=>{if(!t)return;let h=!1;return(async()=>{try{const v=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!v.ok)return;const C=await v.json().catch(()=>null),k=typeof C?.currentVersion=="string"?C.currentVersion.trim():"";!h&&k&&c(k)}catch{}})(),()=>{h=!0}},[t]),o.useEffect(()=>{{b(null),y(!1);return}},[t,r]);const x=a;return s.jsx(ls,{open:t,onOpenChange:e,children:s.jsx(os,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(ou,{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})}),l&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:l})})]})]}),r,s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsxs("div",{className:"flex items-center justify-center gap-4",children:[s.jsxs("a",{href:"https://github.com/btriapitsyn/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(A,{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(A,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:"https://x.com/openchamber_dev",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(A,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},pd=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},N7=(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},S7=()=>{const t=kn(i=>i.completeAuth),[e,n]=o.useState("working"),[r,a]=o.useState("Completing MCP authorization...");return o.useEffect(()=>{if(typeof window>"u"){n("error"),a("Browser context unavailable.");return}const i=new URLSearchParams(window.location.search),l=pd(i,"code"),c=zg(i),d=Su(i),f=pd(i,"error"),m=pd(i,"error_description");if(f){d&&fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(m??f);return}(async()=>{try{if(!l)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 p=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(p.ok){const b=await p.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,l,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(N7(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(he,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},Zi="opencode-update-available",il="opencode-upgrade-progress",k7=5e3,C7=[1e4,6e4],lh="opencode-update-toast-dismissed-version",Nx=()=>{const{t}=pt(),e=_e(l=>l.showOpenCodeUpdateNotifications),n=Ve.useRef(new Set),r=Ve.useRef(!1);Ve.useEffect(()=>{e||K.dismiss(Zi)},[e]);const a=Ve.useCallback(()=>{K.dismiss(il),vi({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),i=Ve.useCallback(async()=>{if(!r.current){r.current=!0,K.dismiss(Zi),K.message(t("opencodeUpdate.toast.upgrading.title"),{id:il,description:t("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:s.jsx(A,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const l=await fetch("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),c=await l.json().catch(()=>null);if(!l.ok||c?.success===!1)throw new Error(c?.error||l.statusText||t("opencodeUpdate.toast.failed.description"));K.success(t("opencodeUpdate.toast.updated.title"),{id:il,description:c?.version?t("opencodeUpdate.toast.updated.descriptionWithVersion",{version:c.version}):t("opencodeUpdate.toast.updated.description"),duration:1/0,icon:s.jsx(A,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:t("opencodeUpdate.toast.actions.reload"),onClick:a}})}catch(l){K.error(t("opencodeUpdate.toast.failed.title"),{id:il,description:l instanceof Error?l.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[a,t]);return Ve.useEffect(()=>{const l=u=>{if(!_e.getState().showOpenCodeUpdateNotifications){K.dismiss(Zi);return}m7({version:u,dismissedVersion:vr().getItem(lh),seenVersions:n.current})&&(n.current.add(u),K.info(t("opencodeUpdate.toast.available.title"),{id:Zi,description:t("opencodeUpdate.toast.available.description",{version:u}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:i},cancel:{label:t("opencodeUpdate.toast.actions.dismiss"),onClick:()=>{vr().setItem(lh,u),K.dismiss(Zi)}}}))},c=u=>{const p=p7(u.detail);l(p)};let d=!1;const f=[],m=async u=>{try{const p=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!p.ok)throw new Error(p.statusText||"OpenCode upgrade status check failed");const b=await p.json().catch(()=>null),g=f7(b);!d&&g&&l(g)}catch{const p=C7[u];!d&&p!==void 0&&f.push(setTimeout(()=>{m(u+1)},p))}};return e&&f.push(setTimeout(()=>{m(0)},k7)),window.addEventListener("openchamber:opencode-update-available",c),()=>{d=!0;for(const u of f)clearTimeout(u);window.removeEventListener("openchamber:opencode-update-available",c)}},[i,e,t]),null},ch=ca(()=>Rr(()=>import("./OnboardingScreen-DTv6YJI1.js"),__vite__mapDeps([8,0,1,2,3,4])).then(t=>({default:t.OnboardingScreen}))),I7=()=>{const t=ot.c(3),e=_e(M7),n=_e(R7);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(j7,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},P7=t=>{const e=ot.c(21),{onRetry:n,isRetrying:r}=t,{t:a}=pt();let i;e[0]!==a?(i=a("startup.initRecovery.title"),e[0]=a,e[1]=i):i=e[1];let l;e[2]!==i?(l=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=l):l=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 f;e[8]!==l||e[9]!==d?(f=s.jsxs("div",{className:"flex flex-col gap-2",children:[l,d]}),e[8]=l,e[9]=d,e[10]=f):f=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(he,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=u):u=e[17];let p;return e[18]!==f||e[19]!==u?(p=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:[f,u]})}),e[18]=f,e[19]=u,e[20]=p):p=e[20],p},dh=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",A7=()=>{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"}},D7=()=>typeof window>"u"?!1:window.location.pathname===Vg,T7=t=>{const e=ot.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:a}=t,i=Ms(F7),l=Lt(L7),c=Lt(O7),d=uu(),f=o.useRef(null);let m;e[0]!==n.directory?(m=dh(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const u=m;let p;e[2]!==i?(p=dh(i),e[2]=i,e[3]=p):p=e[3];const b=p;let g,y;if(e[4]!==b||e[5]!==l||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==u||e[9]!==r||e[10]!==c||e[11]!==d?(g=()=>{if(r||u&&b!==u)return;const k=`${u}
|
|
239
|
+
${n.sessionId}`;f.current===k&&l===n.sessionId||(f.current=k,c(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},y=[b,l,n.directory,n.sessionId,u,r,c,d],e[4]=b,e[5]=l,e[6]=n.directory,e[7]=n.sessionId,e[8]=u,e[9]=r,e[10]=c,e[11]=d,e[12]=g,e[13]=y):(g=e[12],y=e[13]),o.useEffect(g,y),u&&b!==u)return null;let x;e[14]!==a?(x=s.jsx(Kh,{embeddedBackgroundWorkEnabled:a}),e[14]=a,e[15]=x):x=e[15];let h;e[16]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(Nx,{}),e[16]=h):h=e[16];let j;e[17]!==n.readOnly?(j=s.jsx(Jd,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=j):j=e[18];let v;e[19]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(Hh,{}),e[19]=v):v=e[19];let C;return e[20]!==x||e[21]!==j?(C=s.jsxs(s.Fragment,{children:[x,h,j,v]}),e[20]=x,e[21]=j,e[22]=C):C=e[22],C};function E7({apis:t}){const e=jt(W=>W.initializeApp),n=jt(W=>W.isInitialized),r=jt(W=>W.isConnected),a=jt(W=>W.providers.length),i=jt(W=>W.agents.length),l=jt(W=>W.loadProviders),c=jt(W=>W.loadAgents),d=Lt(W=>W.error),f=Lt(W=>W.clearError),m=Ms(W=>W.currentDirectory),u=Ms(W=>W.setDirectory),p=Ms(W=>W.isSwitchingDirectory),[b,g]=o.useState(!1),y=Yn(W=>W.refreshStatus),[x,h]=o.useState(()=>t.runtime.isVSCode),[j,v]=o.useState(!0),[C,k]=o.useState(!1),[w,N]=o.useState(0),[I,E]=o.useState(!1),P=_e(W=>W.wideChatLayoutEnabled),T=_e(W=>W.mobileKeyboardMode),S=o.useMemo(()=>In(),[]),M=Zd(W=>W.setPlanModeEnabled),[D,F]=o.useState(()=>Yd()),[_,V]=o.useState(()=>{const W=oh();return W!==null?ih({isDesktopShell:!0,bootOutcome:W}):null}),$=o.useRef(!1),O=o.useMemo(()=>A7(),[]),B=!O||j,G=o.useMemo(()=>D7(),[]);o.useEffect(()=>(pm(b),()=>{pm(!1)}),[b]),o.useEffect(()=>{Qv(T)},[T]),o.useEffect(()=>{h(t.runtime.isVSCode)},[t.runtime.isVSCode]),o.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",P),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[P]),o.useEffect(()=>(fm(t),()=>fm(null)),[t]),o.useEffect(()=>{O||y(t.github,{force:!0})},[t.github,O,y]),Xv();const R=D==="valid",H=_?.screen==="main";o.useEffect(()=>{if(!b7({isDesktopShell:S,isInitialized:n,bootOutcomeKnown:R,bootViewIsMain:H}))return;const W=setTimeout(()=>{const te=document.getElementById("initial-loading");te&&(te.classList.add("fade-out"),setTimeout(()=>{te.remove()},300))},150);return()=>clearTimeout(W)},[S,n,R,H]),o.useEffect(()=>{if(!S||D!=="malformed")return;const W=document.getElementById("initial-loading");W&&(W.textContent="Desktop startup failed — please restart the app.")},[S,D]),o.useEffect(()=>{if(S)return;const W=setTimeout(()=>{const te=document.getElementById("initial-loading");te&&!n&&(te.classList.add("fade-out"),setTimeout(()=>{te.remove()},300))},5e3);return()=>clearTimeout(W)},[S,n]),o.useEffect(()=>{let W=!1;return(async()=>{const X=await fetch("/health",{method:"GET"}).catch(()=>null);if(!X||!X.ok||W)return;const ee=await X.json().catch(()=>null);if(!ee||W)return;const fe=ee.planModeExperimentalEnabled;M(fe===!0||fe===1||fe==="1"||fe==="true")})(),()=>{W=!0}},[M]),o.useEffect(()=>{x||e()},[e,x]),o.useEffect(()=>{if(x||n)return;let W=!0,te,X=0;const ee=10,fe=1e3,be=async()=>{if(!W)return;if(X>=ee){k(!0);return}const Ne=jt.getState();if(Ne.isInitialized){k(!1);return}X+=1,await Ne.initializeApp();const se=jt.getState();if(!W)return;if(se.isInitialized){k(!1);return}if(X>=ee){k(!0);return}const ie=Math.min(fe*Math.pow(2,X-1),16e3);te=setTimeout(be,ie)};return te=setTimeout(be,fe),()=>{W=!1,te&&clearTimeout(te)}},[w,n,x]),o.useEffect(()=>{n&&k(!1)},[n]),o.useEffect(()=>{if(!C)return;const W=document.getElementById("initial-loading");W&&(W.classList.add("fade-out"),setTimeout(()=>{W.remove()},300))},[C]),o.useEffect(()=>{if(x||!r||a>0&&i>0)return;let W=!0,te=0;const X=15,ee=async()=>{const be=jt.getState();if(!(be.providers.length>0&&be.agents.length>0))try{be.providers.length===0&&await l(),jt.getState().agents.length===0&&await c()}catch{}};ee();const fe=setInterval(()=>{if(W){if(++te>=X){clearInterval(fe);return}ee()}},2e3);return()=>{W=!1,clearInterval(fe)}},[r,x,c,l,a,i]),o.useEffect(()=>{p||x||r&&rn.setDirectory(m)},[m,p,r,x]),o.useEffect(()=>{if(!O||typeof window>"u")return;const W=ee=>{const fe=ee?.visible===!0;v(fe)},te=ee=>{if(ee.origin!==window.location.origin)return;const fe=ee.data;fe?.type==="openchamber:embedded-visibility"&&W(fe.payload)},X=window;return X.__openchamberSetEmbeddedVisibility=W,window.addEventListener("message",te),()=>{window.removeEventListener("message",te),X.__openchamberSetEmbeddedVisibility===W&&delete X.__openchamberSetEmbeddedVisibility}},[O]),o.useEffect(()=>{!O?.directory||x||m!==O.directory&&u(O.directory,{showOverlay:!1})},[m,O,x,u]),o.useEffect(()=>{if(!O||typeof window>"u")return;const W=te=>{te.storageArea===window.localStorage&&te.key==="ui-store"&&_e.persist.rehydrate()};return window.addEventListener("storage",W),()=>{window.removeEventListener("storage",W)}},[O]),o.useEffect(()=>{if(typeof window>"u")return;const W=te=>{const X=te.detail,ee=typeof X?.sessionId=="string"?X.sessionId.trim():"";if(!ee)return;const fe=typeof X?.directory=="string"&&X.directory.trim().length>0?X.directory.trim():null;_e.getState().setActiveMainTab("chat"),Lt.getState().setCurrentSession(ee,fe)};return window.addEventListener("openchamber:open-session",W),()=>window.removeEventListener("openchamber:open-session",W)},[]),o.useEffect(()=>{if(typeof window>"u")return;const W=te=>{const X=te.detail,ee=typeof X?.directory=="string"&&X.directory.trim().length>0?X.directory.trim():null,fe=typeof X?.projectId=="string"&&X.projectId.trim().length>0?X.projectId.trim():null;_e.getState().setActiveMainTab("chat"),_e.getState().setSessionSwitcherOpen(!1),Lt.getState().openNewSessionDraft({selectedProjectId:fe,directoryOverride:ee,preserveDirectoryOverride:!!ee})};return window.addEventListener("openchamber:open-draft-session",W),()=>window.removeEventListener("openchamber:open-draft-session",W)},[]),o.useEffect(()=>{if(typeof window>"u")return;const W=te=>{const X=te.detail,ee=typeof X?.projectPath=="string"?X.projectPath.trim():"";if(!ee)return;const fe=Ss.getState(),be=fe.projects.find(Ne=>Ne.path===ee);be?fe.setActiveProject(be.id):fe.addProject(ee)};return window.addEventListener("openchamber:open-project",W),()=>window.removeEventListener("openchamber:open-project",W)},[]),o.useEffect(()=>{typeof window>"u"||!n||p||$.current||($.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,p]),Zv({enabled:B}),c7({enabled:B}),h7(),e1(),a7();const J=o.useCallback(()=>{g(W=>!W)},[]);KT(J),o.useEffect(()=>{if(O)return;const W=te=>{eu(te)&&te.shiftKey&&!te.altKey&&(te.code==="KeyD"||te.key.toLowerCase()==="d")&&(te.preventDefault(),g(ee=>!ee))};return window.addEventListener("keydown",W,!0),()=>window.removeEventListener("keydown",W,!0)},[O]),o.useEffect(()=>{O||d&&setTimeout(()=>f(),5e3)},[f,O,d]),o.useEffect(()=>{if(!S||D!=="not-injected")return;let W=!1,te=0;const X=200,ee=2e3,fe=50,be=()=>{if(W)return;te++;const Ne=Yd();if(Ne!=="not-injected"){if(W=!0,F(Ne),Ne==="valid"){const ie=oh();ie&&V(ih({isDesktopShell:!0,bootOutcome:ie}))}return}const se=Math.min(X*Math.pow(1.1,te),ee);if(te>=fe){const ie=document.getElementById("initial-loading");ie&&!ie.textContent?.includes("taking longer")&&(ie.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(be,se)};return window.setTimeout(be,X),()=>{W=!0}},[S,D]);const ne=o.useCallback(async()=>{if(y7({isTauriShell:Ga(),isDesktopLocalOriginActive:ia()})){await Rh();return}window.location.reload()},[]),ue=o.useCallback(async()=>{if(!I){k(!1),E(!0);try{await jt.getState().initializeApp()}finally{E(!1)}jt.getState().isInitialized||N(W=>W+1)}},[I]),de=W=>{if(W.screen==="recovery")return W.variant};if(S&&_&&_.screen!=="main"){if(_.screen==="chooser")return s.jsx(Qs,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(o.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(ch,{mode:"first-launch",onCliAvailable:ne,onChooseRemote:()=>{}})})})});const W=de(_),te=_.screen==="recovery"&&"url"in _?_.url:void 0;return s.jsx(Qs,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(o.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(ch,{mode:"recovery",recoveryVariant:W,recoveryHostUrl:te,recoveryHostLabel:void 0,onCliAvailable:ne})})})})}if(O)return s.jsx(Qs,{children:s.jsx(hm,{sdk:rn.getSdkClient(),directory:m||"",children:s.jsx(gm,{apis:t,children:s.jsx(xm,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(T7,{embeddedSessionChat:O,isVSCodeRuntime:x,embeddedBackgroundWorkEnabled:B})})})})})});if(G)return s.jsx(Qs,{children:s.jsx(S7,{})});if(C&&!n&&!x&&!O)return s.jsx(Qs,{children:s.jsx(P7,{onRetry:()=>{ue()},isRetrying:I})});const pe=!n&&!S;return s.jsx(Qs,{children:s.jsx(hm,{sdk:rn.getSdkClient(),directory:m||"",children:s.jsx(gm,{apis:t,children:s.jsx(Sj,{children:s.jsx(t1,{children:s.jsx(xm,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:S?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(Kh,{embeddedBackgroundWorkEnabled:B}),s.jsx(Nx,{}),s.jsx(DT,{}),s.jsx(Hh,{}),!pe&&s.jsxs(s.Fragment,{children:[s.jsx(v7,{}),s.jsx(I7,{}),b&&s.jsx(MT,{onClose:()=>g(!1)})]})]})})})})})})})}function M7(t){return t.isAboutDialogOpen}function R7(t){return t.setAboutDialogOpen}function F7(t){return t.currentDirectory}function L7(t){return t.currentSessionId}function O7(t){return t.setCurrentSession}const $7=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();s1();n1().then(()=>{Promise.all([r1(),a1()]).catch(t=>{console.error("[main] settings init failed:",t)}),i1(),o1(),l1()}).catch(t=>{console.error("[main] appearance init failed:",t)});const Sx=document.getElementById("root");if(!Sx)throw new Error("Root element not found");db.createRoot(Sx).render(s.jsx(Ve.StrictMode,{children:s.jsx(c1,{children:s.jsx(d1,{children:s.jsx(u1,{children:s.jsx(m1,{children:s.jsx(E7,{apis:$7})})})})})}));const H7=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{hT as M,hl as P,Fr as S,WI as a,H7 as m,on as u};
|