@openchamber/web 1.10.3 → 1.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{JsonTreeView-BhnwxlMV.js → JsonTreeView-DjN_Y61c.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-BL9AWfBg.js → MarkdownRendererImpl-D8Pj3Iy7.js} +3 -3
- package/dist/assets/{MultiRunWindow-C2H5hpiq.js → MultiRunWindow-BQtAxwtT.js} +1 -1
- package/dist/assets/{OnboardingScreen-B0qAcM9E.js → OnboardingScreen-Bm0_2bRQ.js} +2 -2
- package/dist/assets/{SettingsWindow-BPWLJy6K.js → SettingsWindow-DfL6vlAG.js} +1 -1
- package/dist/assets/{TerminalView-CSEtmbyD.js → TerminalView-DiV5PHoV.js} +1 -1
- package/dist/assets/{ToolOutputDialog-U8mr6h7H.js → ToolOutputDialog-D32OrEUX.js} +6 -6
- package/dist/assets/{es-RQYrOImo.js → es-B8ic5apd.js} +1 -1
- package/dist/assets/{index-pJeohTL6.css → index-4bBArO_M.css} +1 -1
- package/dist/assets/index-DqXJOAVZ.js +1 -0
- package/dist/assets/{ko-BqABW41E.js → ko-pXQ0SsBr.js} +1 -1
- package/dist/assets/main-BRTUWU3R.js +126 -0
- package/dist/assets/{main-DkIlaUcs.js → main-DXB_3esA.js} +2 -2
- package/dist/assets/miniChat-CZqOFY1k.js +2 -0
- package/dist/assets/{modelPrefsAutoSave-BHV5Gay8.js → modelPrefsAutoSave-DlTpduDU.js} +84 -84
- package/dist/assets/{pl-BFhTdei9.js → pl-DP_0oFey.js} +1 -1
- package/dist/assets/{pt-BR-Cw30xZ9f.js → pt-BR-BmQJZ1NW.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-DuNBYm_K.js +2 -0
- package/dist/assets/{uk-C6rZuAGS.js → uk-CrHgOUe5.js} +1 -1
- package/dist/assets/{vendor-.bun-kY4nnc4l.js → vendor-.bun-0geEbyBQ.js} +1 -1
- package/dist/assets/{zh-CN-bjbBXFpu.js → zh-CN-DyZ0csLN.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/package.json +1 -1
- package/dist/assets/index-CX9TA5UH.js +0 -1
- package/dist/assets/main-Qzl_qZz0.js +0 -126
- package/dist/assets/miniChat-DO_5ziuU.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-B6udecQK.js +0 -2
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-0geEbyBQ.js","assets/vendor--V65Sl9C2.css","assets/modelPrefsAutoSave-DlTpduDU.js","assets/index-DqXJOAVZ.js","assets/index-4bBArO_M.css","assets/TerminalView-DiV5PHoV.js","assets/JsonTreeView-DjN_Y61c.js","assets/SettingsWindow-DfL6vlAG.js","assets/MultiRunWindow-BQtAxwtT.js","assets/OnboardingScreen-Bm0_2bRQ.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as nt,R as l,u as $l,a as vo,j as s,b as yu,C as vu,P as Bl,d as Is,S as Pd,e as mb,D as _l,f as Vl,g as zl,i as Nr,k as to,r as Oe,l as pb,m as hb,p as _o,n as dc,o as In,q as fb,s as gb,t as xb,v as ks,B as vr,w as Zs,G as Gr,T as bb,x as wu,K as Za,y as Ef,Y as yb,N as vb,M as wb,z as uc,A as ei,W as Qs,E as Jn,O as Ui,F as Do,H as Ca,I as Jr,J as Vo,L as Ul,U as ts,Q as qr,V as ti,X as zs,Z as Na,$ as $n,a0 as mc,a1 as Ff,a2 as Dd,a3 as Ei,_ as Mr,a4 as si,a5 as Wi,a6 as jb,a7 as Of,a8 as ju,a9 as Nb,aa as wo,ab as Fi,ac as ho,ad as Nu,ae as Nl,af as an,ag as Sb,ah as ui,ai as Wl,aj as kb,ak as Td,al as Cb,am as ea,an as Yr,ao as Lf,ap as Su,aq as ku,ar as Cu,as as $f,at as Iu,au as Ib,av as Ab,aw as Pb,ax as Db,ay as Tb,az as Au,aA as Pu,aB as Mb,aC as Rb,aD as pc,aE as Ga,aF as Du,aG as Pr,aH as Eb,aI as qa,aJ as Fb,aK as Wa,aL as Us,aM as Qr,aN as Ob,aO as Sr,aP as hc,aQ as Aa,aR as Tu,aS as Xr,aT as Bf,aU as Lb,aV as $b,aW as Bb,aX as _b,aY as Vb,aZ as zb,a_ as Ub,a$ as Wb,b0 as _f,b1 as Kb,b2 as or,b3 as Hb,b4 as so,b5 as cm,b6 as Gb,b7 as qb,b8 as Rc,b9 as Qb,ba as Jb,bb as Yb,bc as dm,bd as um,be as Xb,bf as Vf,bg as zf,bh as Zb,bi as mm,bj as ey,bk as ty,bl as sy,bm as ny,bn as ry,bo as Mu,bp as Ru,bq as ay,br as iy,bs as Uf,bt as oy,bu as Md,bv as Wf,bw as Kf,bx as Ti,by as fo,bz as Rd,bA as rt,bB as Hf,bC as Gf,bD as ly,bE as cy,bF as dy,bG as uy,bH as my,bI as py,bJ as hy,bK as fy,bL as gy,bM as xy,bN as qf,bO as ni,bP as Qf,bQ as Ed,bR as Jf,bS as by,bT as yy,bU as vy,bV as wy,bW as jy,bX as Ny,bY as Un,bZ as Fn,b_ as Sy,b$ as ky,c0 as Eu,c1 as la,c2 as Kl,c3 as Yf,c4 as Cy,c5 as Fu,c6 as Fd,c7 as Xf,c8 as Zf,c9 as Iy,ca as Ay,cb as Ec,cc as pm,cd as eg,ce as Py,cf as Dy,cg as Ty,ch as My,ci as Sl,cj as tg,ck as sg,cl as Od,cm as Ry,cn as Ey,co as Fy,cp as ng,cq as Oy,cr as Ly,cs as $y,ct as By,cu as _y,cv as Vy,cw as zy,cx as rg,cy as ag,cz as Uy,cA as Wy,cB as Ky,cC as jo,cD as Ld,cE as Hy,cF as Gy,cG as Mi,cH as qy,cI as ig,cJ as Qy,cK as Jy,cL as Yy,cM as Xy,cN as Zy,cO as hm,cP as $d,cQ as ev,cR as tv,cS as sv,cT as nv,cU as rv,cV as av,cW as fm,cX as iv,cY as ov,cZ as gm,c_ as lv,c$ as cv,d0 as dv,d1 as xm,d2 as Oi,d3 as Li,d4 as bm,d5 as uv,d6 as mv,d7 as ym,d8 as vm,d9 as Fc,da as pv,db as hv,dc as fv}from"./vendor-.bun-0geEbyBQ.js";import{a as gv,b as xv,f as bv}from"./index-DqXJOAVZ.js";import{u as ut,a as De,b as dn,c as me,d as As,i as jn,g as yr,e as va,s as Oc,r as Lc,f as $c,h as Es,o as Mn,j as qs,T as St,k as kt,l as It,m as ri,n as ca,p as wm,D as Lt,q as yv,t as Hl,v as Wn,w as q,x as $s,y as Ln,z as Bs,A as _s,B as og,C as jm,E as vv,F as wv,G as Nm,H as jv,I as Nv,J as Sv,K as kv,L as Yn,M as Pn,N as mr,O as Bd,P as Vn,Q as No,R as Cv,S as yt,U as Ht,V as Iv,W as lg,X as So,Y as cg,Z as sr,_ as Ou,$ as fc,a0 as Av,a1 as Sm,a2 as Pv,a3 as Dv,a4 as dg,a5 as Tv,a6 as Mv,a7 as ug,a8 as Lu,a9 as Gl,aa as mg,ab as gc,ac as ia,ad as $u,ae as kl,af as Rv,ag as on,ah as pg,ai as hg,aj as Bt,ak as Ps,al as Vr,am as Ki,an as Ev,ao as fg,ap as Cs,aq as js,ar as ve,as as vs,at as ws,au as Hi,av as Fv,aw as Ov,ax as sl,ay as zn,az as gg,aA as xg,aB as xc,aC as Lv,aD as $v,aE as km,aF as An,aG as bs,aH as Bv,aI as _v,aJ as Vv,aK as zv,aL as Uv,aM as Wv,aN as Kv,aO as Js,aP as Hv,aQ as Gv,aR as Fs,aS as qv,aT as Qv,aU as Jv,aV as Yv,aW as Dr,aX as zo,aY as Xv,aZ as Xs,a_ as ps,a$ as hs,b0 as ys,b1 as fs,b2 as Rt,b3 as Zv,b4 as ai,b5 as e1,b6 as ta,b7 as bg,b8 as bc,b9 as t1,ba as Bu,bb as s1,bc as n1,bd as yg,be as r1,bf as pn,bg as Uo,bh as Tr,bi as a1,bj as i1,bk as Bc,bl as yc,bm as _u,bn as Vu,bo as vc,bp as qn,bq as zu,br as ii,bs as wc,bt as go,bu as Gi,bv as qi,bw as Cm,bx as ql,by as Ql,bz as To,bA as Qi,bB as vg,bC as o1,bD as Er,bE as l1,bF as Im,bG as Jl,bH as Wo,bI as wg,bJ as c1,bK as d1,bL as Ko,bM as u1,bN as Ri,bO as Mo,bP as jg,bQ as Ji,bR as Ng,bS as m1,bT as p1,bU as Uu,bV as wa,bW as $i,bX as Qa,bY as jc,bZ as Ho,b_ as Go,b$ as _d,c0 as Sg,c1 as Wu,c2 as kg,c3 as Ro,c4 as h1,c5 as f1,c6 as g1,c7 as x1,c8 as b1,c9 as ko,ca as _c,cb as Am,cc as y1,cd as v1,ce as w1,cf as j1,cg as Ai,ch as Vc,ci as N1,cj as Pm,ck as Sa,cl as S1,cm as Dm,cn as Tm,co as Mm,cp as Rm,cq as Cl,cr as Em,cs as k1,ct as zc,cu as C1,cv as I1,cw as A1,cx as P1,cy as D1,cz as T1,cA as M1,cB as Uc,cC as Fm,cD as R1,cE as E1,cF as F1,cG as O1,cH as L1,cI as Wc,cJ as $1,cK as B1,cL as _1,cM as Cg,cN as V1,cO as Pi,cP as z1,cQ as Om,cR as U1,cS as Ig,cT as nl,cU as Il,cV as W1,cW as Ag,cX as K1,cY as H1,cZ as Lm,c_ as $m,c$ as Pg,d0 as Dg,d1 as Kc,d2 as rl,d3 as G1,d4 as q1,d5 as Q1,d6 as J1,d7 as Tg,d8 as Mg,d9 as Vd,da as Ku,db as Y1,dc as Ns,dd as Eo,de as Yi,df as Bi,dg as Bm,dh as rr,di as X1,dj as Co,dk as Z1,dl as Rg,dm as ew,dn as tw,dp as sw,dq as Eg,dr as Fg,ds as nw,dt as rw,du as aw,dv as iw,dw as _m,dx as ow,dy as lw,dz as cw,dA as dw,dB as uw,dC as Og,dD as mw,dE as pw,dF as hw,dG as fw,dH as gw,dI as xw,dJ as bw,dK as yw,dL as vw,dM as ww,dN as jw,dO as Nw,dP as Sw,dQ as kw,dR as zd,dS as Vm,dT as Cw,dU as Lg,dV as Iw,dW as Aw,dX as Pw,dY as Dw,dZ as ua,d_ as Tw,d$ as zm,e0 as Mw,e1 as Al,e2 as Pl,e3 as Rw,e4 as Ew,e5 as Fw,e6 as Ow,e7 as $g,e8 as Um,e9 as Lw,ea as Wm,eb as $w,ec as Km,ed as Bw,ee as _w,ef as Vw,eg as Hm,eh as Gm,ei as qm,ej as Qm,ek as Jm,el as zw,em as Uw,en as Ww,eo as Kw,ep as Hw,eq as Gw,er as qw,es as Qw,et as Jw,eu as Yw,ev as Xw,ew as Zw}from"./modelPrefsAutoSave-DlTpduDU.js";import{J as ej}from"./JsonTreeView-DjN_Y61c.js";const tj=({transform:t})=>({...t,y:0}),sj=t=>{const e=nt.c(18),{id:n,children:r,className:a}=t;let i;e[0]!==n?(i={id:n},e[0]=n,e[1]=i):i=e[1];const{attributes:o,listeners:c,setNodeRef:d,transform:p,transition:m,isDragging:u}=yu(i);let f;e[2]!==p?(f=vu.Transform.toString(p),e[2]=p,e[3]=f):f=e[3];let y;e[4]!==f||e[5]!==m?(y={transform:f,transition:m},e[4]=f,e[5]=m,e[6]=y):y=e[6];const h=u&&"opacity-50";let b;e[7]!==a||e[8]!==h?(b=me("h-full rounded-md",a,h),e[7]=a,e[8]=h,e[9]=b):b=e[9];let x;return e[10]!==o||e[11]!==r||e[12]!==n||e[13]!==c||e[14]!==d||e[15]!==y||e[16]!==b?(x=s.jsx("div",{ref:d,"data-sortable-tab-id":n,style:y,className:b,...o,...c,children:r}),e[10]=o,e[11]=r,e[12]=n,e[13]=c,e[14]=d,e[15]=y,e[16]=b,e[17]=x):x=e[17],x},nj=t=>{const e=nt.c(6),{id:n,children:r,className:a}=t;let i;e[0]!==a?(i=me("h-full",a),e[0]=a,e[1]=i):i=e[1];let o;return e[2]!==r||e[3]!==n||e[4]!==i?(o=s.jsx("div",{className:i,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=i,e[5]=o):o=e[5],o},zr=t=>{const e=nt.c(121),{items:n,activeId:r,onSelect:a,onClose:i,onReorder:o,layoutMode:c,variant:d,activePillInsetClassName:p,activePillButtonClassName:m,inactiveTabsIconOnly:u,iconOnlyActiveTab:f,animateActivePill:y,activePillLowercase:h,className:b}=t,x=c===void 0?"scrollable":c,g=d===void 0?"default":d,w=u===void 0?!1:u,v=f===void 0?!1:f,S=h===void 0?!0:h,{t:P}=ut(),j=De(rj),{isTablet:C}=dn(),I=j||C,R=l.useRef(null);let k;e[0]===Symbol.for("react.memo_cache_sentinel")?(k={left:!1,right:!1},e[0]=k):k=e[0];const[A,N]=l.useState(k);let D;e[1]!==n?(D=n.map(aj),e[1]=n,e[2]=D):D=e[2];const T=D,M=x==="scrollable",$=g==="default",F=g==="active-pill",_=g==="animated",O=F||_,L=$,K=O||L,B=F&&M,re=O,oe=y??_,ee=typeof o=="function",ae=ee?sj:nj;let ge;e[3]===Symbol.for("react.memo_cache_sentinel")?(ge=new Map,e[3]=ge):ge=e[3];const ne=l.useRef(ge),[E,z]=l.useState(null);let J;e[4]===Symbol.for("react.memo_cache_sentinel")?(J={activationConstraint:{distance:8}},e[4]=J):J=e[4];const H=$l(vo(Bl,J)),te=ij;let ce;e[5]===Symbol.for("react.memo_cache_sentinel")?(ce=(at,ye)=>{if(ye){ne.current.set(at,ye);return}ne.current.delete(at)},e[5]=ce):ce=e[5];const Se=ce;let pe;e[6]!==r||e[7]!==K?(pe=()=>{if(!K||!r){z(oj);return}const at=R.current,ye=ne.current.get(r);if(!at||!ye){z(lj);return}let Ge=0,$e=0,_e=ye;for(;_e&&_e!==at;)Ge=Ge+_e.offsetLeft,$e=$e+_e.offsetTop,_e=_e.offsetParent;const tt={left:Ge,top:$e,width:ye.offsetWidth,height:ye.offsetHeight};z(Qe=>te(Qe,tt)?Qe:tt)},e[6]=r,e[7]=K,e[8]=pe):pe=e[8];const we=pe;let W;e[9]!==M?(W=()=>{if(!M){N({left:!1,right:!1});return}const at=R.current;if(!at){N({left:!1,right:!1});return}N({left:at.scrollLeft>2,right:at.scrollLeft+at.clientWidth<at.scrollWidth-2})},e[9]=M,e[10]=W):W=e[10];const ue=W;let Y;e[11]!==M||e[12]!==ue?(Y=()=>{if(!M){N({left:!1,right:!1});return}const at=R.current;if(!at)return;ue(),at.addEventListener("scroll",ue,{passive:!0});const ye=new ResizeObserver(ue);return ye.observe(at),()=>{at.removeEventListener("scroll",ue),ye.disconnect()}},e[11]=M,e[12]=ue,e[13]=Y):Y=e[13];let le;e[14]!==M||e[15]!==n.length||e[16]!==ue?(le=[M,n.length,ue],e[14]=M,e[15]=n.length,e[16]=ue,e[17]=le):le=e[17],l.useEffect(Y,le);let Z;e[18]!==r||e[19]!==we||e[20]!==K?(Z=()=>{if(!K){z(null);return}we();const at=R.current;if(!at)return;const ye=new ResizeObserver(we);if(ye.observe(at),r){const Ge=ne.current.get(r);Ge&&ye.observe(Ge)}return()=>{ye.disconnect()}},e[18]=r,e[19]=we,e[20]=K,e[21]=Z):Z=e[21];let Ie;e[22]!==r||e[23]!==n.length||e[24]!==we||e[25]!==K?(Ie=[r,n.length,we,K],e[22]=r,e[23]=n.length,e[24]=we,e[25]=K,e[26]=Ie):Ie=e[26],l.useEffect(Z,Ie);let Ne;e[27]!==we?(Ne=()=>{we()},e[27]=we,e[28]=Ne):Ne=e[28],l.useLayoutEffect(Ne);let X;e[29]!==r||e[30]!==M||e[31]!==ue?(X=()=>{if(!M||!r)return;const at=R.current;if(!at)return;const ye=window.requestAnimationFrame(()=>{const Ge=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),$e=at.querySelector(`[data-sortable-tab-id="${Ge}"]`);$e&&($e.scrollIntoView({block:"nearest",inline:"nearest"}),ue())});return()=>{window.cancelAnimationFrame(ye)}},e[29]=r,e[30]=M,e[31]=ue,e[32]=X):X=e[32];let he;e[33]!==r||e[34]!==M||e[35]!==n.length||e[36]!==ue?(he=[r,M,n.length,ue],e[33]=r,e[34]=M,e[35]=n.length,e[36]=ue,e[37]=he):he=e[37],l.useEffect(X,he);let je;e[38]!==o?(je=at=>{if(!o)return;const{active:ye,over:Ge}=at;!Ge||ye.id===Ge.id||o(String(ye.id),String(Ge.id))},e[38]=o,e[39]=je):je=e[39];const be=je;let fe;e[40]!==b?(fe=me("relative flex h-full min-w-0 flex-1",b),e[40]=b,e[41]=fe):fe=e[41];let Pe;e[42]!==M||e[43]!==A||e[44]!==O?(Pe=M&&A.left?s.jsx("div",{className:me("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]=M,e[43]=A,e[44]=O,e[45]=Pe):Pe=e[45];let Be;e[46]!==M||e[47]!==A||e[48]!==O?(Be=M&&A.right?s.jsx("div",{className:me("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]=M,e[47]=A,e[48]=O,e[49]=Be):Be=e[49];const G=O?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",ke=O&&"@container/pill-tabs",Ee=O&&"pill-tabs__track",Ae=O&&(p??"gap-0.5 py-0.5"),xe=L&&"items-center overflow-y-hidden",V=re&&"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",de=M?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let Me;e[50]!==G||e[51]!==ke||e[52]!==Ee||e[53]!==Ae||e[54]!==xe||e[55]!==V||e[56]!==de?(Me=me("relative flex h-full min-w-0 flex-1",G,ke,Ee,Ae,xe,V,de),e[50]=G,e[51]=ke,e[52]=Ee,e[53]=Ae,e[54]=xe,e[55]=V,e[56]=de,e[57]=Me):Me=e[57];let Le;e[58]!==M?(Le=M?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=M,e[59]=Le):Le=e[59];let se;e[60]!==P?(se=P("sortableTabsStrip.aria.tabs"),e[60]=P,e[61]=se):se=e[61];let ie;e[62]!==E||e[63]!==oe||e[64]!==O?(ie=O&&E?s.jsx("div",{className:me("pointer-events-none absolute left-0 top-0 z-0 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[var(--surface-elevated)]","border border-border/60"),style:{transform:`translate3d(${E.left}px, ${E.top}px, 0)`,width:`${E.width}px`,height:`${E.height}px`,transition:oe?"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]=E,e[63]=oe,e[64]=O,e[65]=ie):ie=e[65];let U;e[66]!==E||e[67]!==L?(U=L&&E?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(${E.left}px, 0, 0)`,width:`${E.width}px`},"aria-hidden":!0}):null,e[66]=E,e[67]=L,e[68]=U):U=e[68];let Ve;if(e[69]!==ae||e[70]!==r||e[71]!==m||e[72]!==S||e[73]!==I||e[74]!==v||e[75]!==w||e[76]!==F||e[77]!==j||e[78]!==M||e[79]!==n||e[80]!==i||e[81]!==a||e[82]!==B||e[83]!==O){let at;e[85]!==ae||e[86]!==r||e[87]!==m||e[88]!==S||e[89]!==I||e[90]!==v||e[91]!==w||e[92]!==F||e[93]!==j||e[94]!==M||e[95]!==i||e[96]!==a||e[97]!==B||e[98]!==O?(at=ye=>{const Ge=ye.id===r,$e=w&&O&&!Ge&&!!ye.icon,_e=!$e,tt=!!ye.icon&&(!v||Ge),Qe=w&&O&&Ge&&!M&&!B,ze=ye.closable!==!1&&!!i,gt=ze&&!!ye.icon,Vt=M||B?void 0:O?Qe?"flex-none basis-auto":j?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0";return s.jsx(ae,{id:ye.id,className:Vt,children:s.jsxs("div",{ref:Kt=>Se(ye.id,Kt),className:me("group flex h-full min-w-0 flex-nowrap items-center",M||B?"shrink-0":O?"w-full":"w-full min-w-0",O?"relative z-10 bg-transparent":Ge?"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":Ge,"aria-label":$e?ye.title??ye.label:void 0,onClick:()=>a(ye.id),className:me(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&&S?"lowercase":null,O&&($e?"gap-0":"gap-1.5"),O?B?"shrink-0 whitespace-nowrap px-3 text-center":M?"max-w-56 shrink-0 px-3 text-center":$e?"px-2 !min-w-0 text-center":Qe?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":M?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",O?m??(F?j?"h-[38px]":"h-[31px]":"h-7"):null,O?Ge?"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:ye.title??ye.label,children:O?s.jsxs(s.Fragment,{children:[tt?s.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[s.jsx("span",{className:me("flex items-center justify-center transition-opacity",gt&&(I?"opacity-0":"group-hover:opacity-0")),children:ye.icon}),gt?s.jsx("span",{role:"button",tabIndex:-1,className:me("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",I?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:cj,onClick:Kt=>{Kt.stopPropagation(),i?.(ye.id)},"aria-label":ye.closeLabel??`Close ${ye.label} tab`,title:ye.closeLabel??`Close ${ye.label} tab`,children:s.jsx(Is,{className:"h-3.5 w-3.5"})}):null]}):null,_e?s.jsx("span",{className:"animated-tabs__label truncate",children:ye.label}):null]}):s.jsxs("span",{className:me("flex min-w-0 flex-nowrap items-center gap-1.5",!M&&"justify-center"),children:[tt?s.jsxs("span",{className:me("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",Ge?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:me("flex items-center justify-center transition-opacity",gt&&(I?"opacity-0":"group-hover:opacity-0")),children:ye.icon}),gt?s.jsx("span",{role:"button",tabIndex:-1,className:me("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",I?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:dj,onClick:Kt=>{Kt.stopPropagation(),i?.(ye.id)},"aria-label":ye.closeLabel??`Close ${ye.label} tab`,title:ye.closeLabel??`Close ${ye.label} tab`,children:s.jsx(Is,{className:"h-3.5 w-3.5"})}):null]}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:ye.label})]})}),ze&&!gt?s.jsx("button",{type:"button",onPointerDown:uj,onClick:Kt=>{Kt.stopPropagation(),i?.(ye.id)},className:me("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?Ge?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":Ge?"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":ye.closeLabel??`Close ${ye.label} tab`,title:ye.closeLabel??`Close ${ye.label} tab`,children:s.jsx(Is,{className:"h-3 w-3"})}):null]})},ye.id)},e[85]=ae,e[86]=r,e[87]=m,e[88]=S,e[89]=I,e[90]=v,e[91]=w,e[92]=F,e[93]=j,e[94]=M,e[95]=i,e[96]=a,e[97]=B,e[98]=O,e[99]=at):at=e[99],Ve=n.map(at),e[69]=ae,e[70]=r,e[71]=m,e[72]=S,e[73]=I,e[74]=v,e[75]=w,e[76]=F,e[77]=j,e[78]=M,e[79]=n,e[80]=i,e[81]=a,e[82]=B,e[83]=O,e[84]=Ve}else Ve=e[84];let He;e[100]!==Me||e[101]!==Le||e[102]!==se||e[103]!==ie||e[104]!==U||e[105]!==Ve?(He=s.jsxs("div",{ref:R,className:Me,style:Le,role:"tablist","aria-label":se,children:[ie,U,Ve]}),e[100]=Me,e[101]=Le,e[102]=se,e[103]=ie,e[104]=U,e[105]=Ve,e[106]=He):He=e[106];let Ke;e[107]!==fe||e[108]!==Pe||e[109]!==Be||e[110]!==He?(Ke=s.jsxs("div",{className:fe,children:[Pe,Be,He]}),e[107]=fe,e[108]=Pe,e[109]=Be,e[110]=He,e[111]=Ke):Ke=e[111];const Ze=Ke;if(!ee)return Ze;let Xe;e[112]===Symbol.for("react.memo_cache_sentinel")?(Xe=[tj],e[112]=Xe):Xe=e[112];let dt;e[113]!==T||e[114]!==Ze?(dt=s.jsx(Pd,{items:T,strategy:mb,children:Ze}),e[113]=T,e[114]=Ze,e[115]=dt):dt=e[115];let et;e[116]===Symbol.for("react.memo_cache_sentinel")?(et=s.jsx(_l,{dropAnimation:null}),e[116]=et):et=e[116];let ct;return e[117]!==be||e[118]!==H||e[119]!==dt?(ct=s.jsxs(Vl,{sensors:H,collisionDetection:zl,onDragEnd:be,modifiers:Xe,children:[dt,et]}),e[117]=be,e[118]=H,e[119]=dt,e[120]=ct):ct=e[120],ct};function rj(t){return t.isMobile}function aj(t){return t.id}function ij(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 oj(t){return t===null?t:null}function lj(t){return t===null?t:null}function cj(t){t.stopPropagation()}function dj(t){t.stopPropagation()}function uj(t){t.stopPropagation()}function Ym(t){const e=nt.c(14);let n,r,a,i;e[0]!==t?({size:a,className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);const o=typeof a=="number"?`${a}px`:a,c=typeof a=="number"?`${a}px`:a;let d;e[5]!==i||e[6]!==o||e[7]!==c?(d={width:o,height:c,...i},e[5]=i,e[6]=o,e[7]=c,e[8]=d):d=e[8];let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx("path",{d:"M112,148a12,12,0,0,0-12,12v19L69.17,148.2A4,4,0,0,1,68,145.37V97.94a36,36,0,1,0-24,0v47.43a27.81,27.81,0,0,0,8.2,19.8L83,196H64a12,12,0,0,0,0,24h48a12,12,0,0,0,12-12V160A12,12,0,0,0,112,148ZM56,52A12,12,0,1,1,44,64,12,12,0,0,1,56,52ZM212,158.06V110.63a27.81,27.81,0,0,0-8.2-19.8L173,60h19a12,12,0,0,0,0-24H144a12,12,0,0,0-12,12V96a12,12,0,0,0,24,0V77l30.83,30.83a4,4,0,0,1,1.17,2.83v47.43a36,36,0,1,0,24,0ZM200,204a12,12,0,1,1,12-12A12,12,0,0,1,200,204Z"}),e[9]=p):p=e[9];let m;return e[10]!==n||e[11]!==r||e[12]!==d?(m=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:d,...r,children:p}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const Zr=[{id:"claude",name:"Claude"},{id:"codex",name:"Codex"},{id:"github-copilot",name:"GitHub Copilot"},{id:"google",name:"Google"},{id:"kimi-for-coding",name:"Kimi for Coding"},{id:"nano-gpt",name:"NanoGPT"},{id:"openrouter",name:"OpenRouter"},{id:"zai-coding-plan",name:"z.ai"},{id:"zhipuai-coding-plan",name:"Zhipu AI Coding Plan"},{id:"minimax-cn-coding-plan",name:"MiniMax Coding Plan (minimaxi.com)"},{id:"minimax-coding-plan",name:"MiniMax Coding Plan (minimax.io)"},{id:"ollama-cloud",name:"Ollama Cloud"},{id:"zhipuai-coding-plan",name:"ZhipuAI"}];Zr.reduce((t,e)=>(t[e.id]=e,t),{});const mj=t=>typeof t!="number"||Number.isNaN(t)?null:Math.max(0,Math.min(100,Math.round(t))),pj=t=>typeof t!="number"||Number.isNaN(t)?"-":`${Math.round(t)}%`,Fo=(t,e)=>t??pj(e),Bg=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",Hu=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,hj=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},Oo=(t,e,n,r)=>{let a=n;if(a===null&&r&&(a=hj(r)),t===null||e===null||a===null||a<=0)return null;const i=Date.now(),o=Math.max(0,(e-i)/1e3),c=Math.max(0,Math.min(a,a-o)),d=Math.max(0,Math.min(1,c/a)),p=t/100,m=t>=100&&o>0;let u;d>.01?u=Math.min(999,p/d*100):u=t;let f;m?f="exhausted":p<=d?f="on-track":u<=130?f="slightly-fast":f="too-fast";const y=a>=120*3600,h=y?86400:3600,b=y?"d":"h",x=a/h,g=Math.max(c/h,x*.01),w=t/g,v=Number.isFinite(w)?`${Math.min(999.9,Math.max(0,w)).toFixed(1)}%/${b}`:"-",S=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`;let P=null;const j=a/86400;return j>=7&&(P=100/j),{elapsedRatio:d,usageRatio:p,predictedFinalPercent:u,remainingSeconds:o,isExhausted:m,elapsedSeconds:c,totalSeconds:a,status:f,paceRateText:v,predictText:S,dailyAllocationPercent:P}},fj=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)"}},Xm=t=>{const e=Math.max(0,Math.floor(t)),n=Math.floor(e/60),r=Math.floor(n/60),a=Math.floor(r/24),i=r%24,o=n%60;return a>0?`${a}d ${i}h`:r>0?`${r}h`:n===0?"<1m":`${o}m`},oa=t=>Math.min(100,Math.max(0,t*100));function Yl(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 gj=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],_g={google:gj};function Vg(t,e){const n=_g[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function zg(t){return _g[t]??[]}function Ug(t){return[...t].sort((e,n)=>e.order-n.order)}function xj(t,e){const n=new Map;for(const r of Object.keys(t)){const i=Vg(r,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(r)}return n}function bj(t,e,n){const r=new Map;for(const a of t){const i=e(a),c=Vg(i,n)?.id??null;r.has(c)||r.set(c,[]),r.get(c).push(a)}return r}function yj(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 Gu=6e4,Zm=t=>{const e=Zr.map(u=>u.id),n=typeof t?.usageAutoRefresh=="boolean"?t.usageAutoRefresh:!1,r=typeof t?.usageRefreshIntervalMs=="number"&&Number.isFinite(t.usageRefreshIntervalMs)?Math.max(3e4,Math.min(3e5,Math.round(t.usageRefreshIntervalMs))):Gu,a=t?.usageDisplayMode==="remaining"?"remaining":"usage",i=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,o=i?i.filter(u=>typeof u=="string"&&e.includes(u)):e,c={},d=t?.usageSelectedModels;if(d&&typeof d=="object")for(const[u,f]of Object.entries(d))Array.isArray(f)&&(c[u]=f.filter(y=>typeof y=="string"));const p={},m=t?.usageExpandedFamilies;if(m&&typeof m=="object")for(const[u,f]of Object.entries(m))Array.isArray(f)&&(p[u]=f.filter(y=>typeof y=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:a,dropdownProviderIds:o,selectedModels:c,expandedFamilies:p}},vj=async()=>{const t=yr()?.settings;if(t)try{const n=(await t.load())?.settings;return Zm(n??null)}catch{}if(!jn()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return Zm(n)}}return{autoRefresh:!1,refreshIntervalMs:Gu,displayMode:"usage",dropdownProviderIds:Zr.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Ls=Nr()(to((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Gu,displayMode:"usage",dropdownProviderIds:Zr.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await vj();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Zr.map(r=>r.id);try{await Promise.all(n.map(r=>e().fetchProviderQuota(r))),t({isLoading:!1,lastUpdated:Date.now()})}catch(r){const a=r instanceof Error?r.message:"Failed to fetch quotas";t({isLoading:!1,error:a})}},fetchProviderQuota:async n=>{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!0}}));try{const r=await fetch(`/api/quota/${encodeURIComponent(n)}`),a=await r.json().catch(()=>null);if(!r.ok)throw new Error(a?.error||"Failed to fetch quota");const i=a;t(o=>{const c=o.results.filter(d=>d.providerId!==n);return c.push(i),{results:c,error:null}})}catch(r){const a=r instanceof Error?r.message:"Failed to fetch quota",i={providerId:n,providerName:n,ok:!1,configured:!1,error:a,usage:null,fetchedAt:Date.now()};t(o=>{const c=o.results.filter(d=>d.providerId!==n);return c.push(i),{results:c,error:a}})}finally{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>t({selectedProviderId:n}),setAutoRefresh:n=>t({autoRefresh:n}),setRefreshInterval:n=>{const r=Math.max(3e4,Math.min(3e5,Math.round(n)));t({refreshIntervalMs:r})},setDisplayMode:n=>t({displayMode:n}),setDropdownProviderIds:n=>t({dropdownProviderIds:n}),setSelectedModels:(n,r)=>{t(a=>({selectedModels:{...a.selectedModels,[n]:r}}))},toggleModelSelected:(n,r)=>{t(a=>{const i=a.selectedModels[n]??[],c=i.includes(r)?i.filter(d=>d!==r):[...i,r];return{selectedModels:{...a.selectedModels,[n]:c}}})},setExpandedFamilies:(n,r)=>{t(a=>({expandedFamilies:{...a.expandedFamilies,[n]:r}})),As({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}}}),As({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=yj(n,r);i.length!==0&&(t(o=>({selectedModels:{...o.selectedModels,[n]:i}})),As({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Wg=()=>{const t=nt.c(5),e=Ls(wj),n=Ls(jj),r=Ls(Nj);let a,i;t[0]!==e||t[1]!==r||t[2]!==n?(a=()=>{if(!e)return;const o=window.setInterval(()=>{r()},n);return()=>window.clearInterval(o)},i=[e,n,r],t[0]=e,t[1]=r,t[2]=n,t[3]=a,t[4]=i):(a=t[3],i=t[4]),l.useEffect(a,i)};function wj(t){return t.autoRefresh}function jj(t){return t.refreshIntervalMs}function Nj(t){return t.fetchAllQuotas}const Xl=Oe.forwardRef((t,e)=>{const n=nt.c(11);let r,a;n[0]!==t?({className:r,...a}=t,n[0]=t,n[1]=r,n[2]=a):(r=n[1],a=n[2]);let i;n[3]!==r?(i=me("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]",r),n[3]=r,n[4]=i):i=n[4];let o;n[5]===Symbol.for("react.memo_cache_sentinel")?(o={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=o):o=n[5];let c;n[6]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(pb,{className:me("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[checked]:translate-x-4 data-[unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=c):c=n[6];let d;return n[7]!==a||n[8]!==e||n[9]!==i?(d=s.jsx(hb,{className:i,style:o,...a,ref:e,children:c}),n[7]=a,n[8]=e,n[9]=i,n[10]=d):d=n[10],d});Xl.displayName="Switch";const al=()=>{try{const e=Es.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=Mn.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[McpConfigStore] Error resolving config directory:",t)}return null},ep=t=>t?Object.entries(t).map(([e,n])=>({key:e,value:n})):[],tp=t=>{const e=t.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},il=t=>typeof t!="string"?void 0:t.trim()||void 0,Hc=800,Sj=5e3,kj="__default__",Ud=new Map,Gc=new Map,Kg=t=>t?.trim()||kj,qc=t=>{Ud.delete(Kg(t))},Lo=Nr()(to(_o((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=al(),a=Kg(r),i=Date.now(),o=Ud.get(a)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&i-o<Sj)return!0;const d=Gc.get(a);if(!n?.force&&d)return d;const p=(async()=>{t({isLoading:!0});try{const m=r?`?directory=${encodeURIComponent(r)}`:"",u=await fetch(`/api/config/mcp${m}`,{headers:r?{"x-opencode-directory":r}:void 0});if(!u.ok)throw new Error("Failed to load MCP configs");const f=await u.json();return t({mcpServers:f,isLoading:!1}),Ud.set(a,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();Gc.set(a,p);try{return await p}finally{Gc.delete(a)}},createMcp:async n=>{Oc("Creating MCP server configuration…");let r=!1;try{const a=sp(n),i=al(),o=i?`?directory=${encodeURIComponent(i)}`:"",c=await fetch(`/api/config/mcp/${encodeURIComponent(n.name)}${o}`,{method:"POST",headers:{"Content-Type":"application/json",...i?{"x-opencode-directory":i}:{}},body:JSON.stringify(a)}),d=await c.json().catch(()=>null);if(!c.ok)throw new Error(d?.error||"Failed to create MCP server");return qc(i),d?.requiresReload?(r=!0,await Lc({message:d.message,delayMs:d.reloadDelayMs??Hc,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||$c()}},updateMcp:async(n,r)=>{Oc("Updating MCP server configuration…");let a=!1;try{const i=sp(r),o=al(),c=o?`?directory=${encodeURIComponent(o)}`:"",d=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${c}`,{method:"PATCH",headers:{"Content-Type":"application/json",...o?{"x-opencode-directory":o}:{}},body:JSON.stringify(i)}),p=await d.json().catch(()=>null);if(!d.ok)throw new Error(p?.error||"Failed to update MCP server");return qc(o),p?.requiresReload?(a=!0,await Lc({message:p.message,delayMs:p.reloadDelayMs??Hc,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:p?.reloadFailed===!0,message:p?.message,warning:p?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:p?.reloadFailed===!0,message:p?.message,warning:p?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{a||$c()}},deleteMcp:async n=>{Oc("Deleting MCP server configuration…");let r=!1;try{const a=al(),i=a?`?directory=${encodeURIComponent(a)}`:"",o=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:a?{"x-opencode-directory":a}:void 0}),c=await o.json().catch(()=>null);if(!o.ok)throw new Error(c?.error||"Failed to delete MCP server");return qc(a),c?.requiresReload&&(r=!0,await Lc({message:c.message,delayMs:c.reloadDelayMs??Hc,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||$c()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:dc(()=>va()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function sp(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=tp(t.environment)??{}),t.headers!==void 0&&(e.headers=tp(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:il(t.oauthClientId),clientSecret:il(t.oauthClientSecret),scope:il(t.oauthScope),redirectUri:il(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 Cj={},Ij={},aa=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},Si=t=>aa(t)??"__global__",Ea=t=>{const e=aa(t);return e?Mn.getScopedApiClient(e):Mn.getApiClient()},Tn=Nr()(to((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=Si(n??qs.getState().currentDirectory);return e().byDirectory[r]??Cj},getDiagnosticForDirectory:n=>{const r=Si(n??qs.getState().currentDirectory);return e().diagnosticsByDirectory[r]??Ij},getErrorForDirectory:n=>{const r=Si(n??qs.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=aa(n?.directory??qs.getState().currentDirectory),a=Si(r);n?.silent||t(i=>({loadingKeys:{...i.loadingKeys,[a]:!0},lastErrorKeys:{...i.lastErrorKeys,[a]:null}}));try{const c=(await Ea(r).mcp.status()).data??{};t(d=>({byDirectory:{...d.byDirectory,[a]:c},diagnosticsByDirectory:{...d.diagnosticsByDirectory,[a]:Object.fromEntries(Object.entries(d.diagnosticsByDirectory[a]??{}).filter(([p])=>!c[p]))},loadingKeys:{...d.loadingKeys,[a]:!1},lastErrorKeys:{...d.lastErrorKeys,[a]:null}}))}catch(i){const o=i instanceof Error?i.message:"Failed to load MCP status";t(c=>({loadingKeys:{...c.loadingKeys,[a]:!1},lastErrorKeys:{...c.lastErrorKeys,[a]:o}}))}},connect:async(n,r)=>{const a=aa(r??qs.getState().currentDirectory),i=Si(a),o=Ea(a);try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(c){const d=c instanceof Error?c.message:"Connection failed";throw t(p=>({diagnosticsByDirectory:{...p.diagnosticsByDirectory,[i]:{...p.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:d}}}})),c}await e().refresh({directory:a,silent:!0})},disconnect:async(n,r)=>{const a=aa(r??qs.getState().currentDirectory);await Ea(a).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},startAuth:async(n,r)=>{const a=aa(r??qs.getState().currentDirectory),c=(await Ea(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=aa(a??qs.getState().currentDirectory);await Ea(i).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,r)=>{const a=aa(r??qs.getState().currentDirectory);await Ea(a).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},testConnection:async(n,r)=>{const a=aa(r??qs.getState().currentDirectory),i=Si(a),o=Ea(a),d=e().getStatusForDirectory(a)[n]?.status==="connected";let p,m;try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(y){p=y instanceof Error?y.message:"Connection failed",t(h=>({diagnosticsByDirectory:{...h.diagnosticsByDirectory,[i]:{...h.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:p??"Connection failed"}}}}))}await e().refresh({directory:a,silent:!0});const u=e().getStatusForDirectory(a)[n],f=u;if(!d&&u?.status==="connected"){try{await o.mcp.disconnect({name:n},{throwOnError:!0})}catch(y){m=`Connection test succeeded, but cleanup disconnect failed: ${y instanceof Error?y.message:"Disconnect failed"}`}await e().refresh({directory:a,silent:!0})}return{status:f??e().getStatusForDirectory(a)[n],error:p,warning:m}}})));function Hg(t){const e=nt.c(4);let n,r;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z"}),r=s.jsx("path",{d:"M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z"}),e[0]=n,e[1]=r):(n=e[0],r=e[1]);let a;return e[2]!==t?(a=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",fillRule:"evenodd",viewBox:"-0.5 -0.5 25 25",...t,children:[n,r]}),e[2]=t,e[3]=a):a=e[3],a}const Aj=(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}},Pj=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Gg=({active:t,className:e})=>{const{t:n}=ut(),a=qs(g=>g.currentDirectory)??null,i=Tn(g=>g.getStatusForDirectory(a)),o=Tn(g=>g.refresh),c=Tn(g=>g.connect),d=Tn(g=>g.disconnect),p=Lo(g=>g.mcpServers),m=Lo(g=>g.loadMcpConfigs),[u,f]=l.useState(!1),[y,h]=l.useState(null);l.useEffect(()=>{o({directory:a,silent:!0})},[o,a]),l.useEffect(()=>{m({force:!0})},[m]),l.useEffect(()=>{t&&Promise.all([o({directory:a,silent:!0}),m({force:!0})])},[t,o,a,m]);const b=l.useMemo(()=>{const g=new Set(Object.keys(i));for(const w of p)w?.name&&g.add(w.name);return Array.from(g).sort((w,v)=>w.localeCompare(v))},[p,i]),x=l.useCallback(g=>{if(g?.preventDefault(),u)return;f(!0);const w=new Promise(v=>setTimeout(v,500));Promise.all([o({directory:a}),w]).finally(()=>{f(!1)})},[u,o,a]);return s.jsxs("div",{className:me("w-full",e),children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:n("mcpDropdown.title")}),a&&s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:a.split("/").pop()||a})]}),s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:u,onClick:x,"aria-label":n("mcpDropdown.actions.refreshAria"),children:s.jsx(In,{className:me("h-4 w-4",u&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[b.map(g=>{const w=i[g],v=Pj(w),S=w?.status==="connected",P=y===g,j=Aj(w,n);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("span",{className:me("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":j})}),s.jsx(It,{side:"left",children:s.jsx("p",{children:j})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:g})]})}),s.jsx(Xl,{checked:S,disabled:P,className:"data-[checked]:bg-status-info",onCheckedChange:async C=>{h(g);try{C?await c(g,a):await d(g,a)}finally{h(null)}}})]},g)}),b.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},$o=t=>{const e=nt.c(20),{percent:n,tonePercent:r,className:a,expectedMarkerPercent:i}=t;let o;e[0]!==n?(o=mj(n)??0,e[0]=n,e[1]=o):o=e[1];const c=o,d=r??n;let p;e[2]!==d?(p=Bg(d),e[2]=d,e[3]=p):p=e[3];const m=p,u=i!=null?Math.max(0,Math.min(100,i)):null;let f;e[4]!==m?(f=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=f):f=e[5];const y=f;let h;e[6]!==a?(h=me("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",a),e[6]=a,e[7]=h):h=e[7];const b=`${c}%`;let x;e[8]!==y||e[9]!==b?(x={...y,width:b},e[8]=y,e[9]=b,e[10]=x):x=e[10];let g;e[11]!==c||e[12]!==x?(g=s.jsx("div",{className:"h-full transition-all duration-300",style:x,role:"progressbar","aria-valuenow":c,"aria-valuemin":0,"aria-valuemax":100}),e[11]=c,e[12]=x,e[13]=g):g=e[13];let w;e[14]!==u?(w=u!=null&&u>0&&u<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${u}%`},title:`Expected usage if spread evenly: ${Math.round(u)}% of quota`,"aria-hidden":"true"}),e[14]=u,e[15]=w):w=e[15];let v;return e[16]!==h||e[17]!==g||e[18]!==w?(v=s.jsxs("div",{className:h,children:[g,w]}),e[16]=h,e[17]=g,e[18]=w,e[19]=v):v=e[19],v},Bo=t=>{const e=nt.c(67),{paceInfo:n,className:r,compact:a}=t,i=a===void 0?!1:a,{t:o}=ut();let c;e[0]!==n.status?(c=fj(n.status),e[0]=n.status,e[1]=c):c=e[1];const d=c;let p;e:{switch(n.status){case"on-track":{let C;e[2]!==o?(C=o("settings.usage.pace.status.onTrack"),e[2]=o,e[3]=C):C=e[3],p=C;break e}case"slightly-fast":{let C;e[4]!==o?(C=o("settings.usage.pace.status.slightlyFast"),e[4]=o,e[5]=C):C=e[5],p=C;break e}case"too-fast":{let C;e[6]!==o?(C=o("settings.usage.pace.status.tooFast"),e[6]=o,e[7]=C):C=e[7],p=C;break e}case"exhausted":{let C;e[8]!==o?(C=o("settings.usage.pace.status.usedUp"),e[8]=o,e[9]=C):C=e[9],p=C;break e}}p=void 0}const m=p;let u;e[10]!==n.predictText||e[11]!==o?(u=o("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=o,e[12]=u):u=e[12];const f=u;if(i){let C;e[13]!==r?(C=me("flex items-center gap-1.5",r),e[13]=r,e[14]=C):C=e[14];let I;e[15]!==d?(I={backgroundColor:d},e[15]=d,e[16]=I):I=e[16];let R;e[17]!==m||e[18]!==I?(R=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]=R):R=e[19];let k;e[20]!==d?(k={color:d},e[20]=d,e[21]=k):k=e[21];const A=n.isExhausted?void 0:f;let N;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==o?(N=n.isExhausted?s.jsx(s.Fragment,{children:o("settings.usage.pace.wait",{duration:Xm(n.remainingSeconds)})}):s.jsx(s.Fragment,{children:o("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=o,e[26]=N):N=e[26];let D;e[27]!==N||e[28]!==k||e[29]!==A?(D=s.jsx("span",{className:"typography-micro tabular-nums",style:k,title:A,children:N}),e[27]=N,e[28]=k,e[29]=A,e[30]=D):D=e[30];let T;return e[31]!==D||e[32]!==C||e[33]!==R?(T=s.jsxs("div",{className:C,children:[R,D]}),e[31]=D,e[32]=C,e[33]=R,e[34]=T):T=e[34],T}let y;e[35]!==r?(y=me("flex items-center justify-between gap-2",r),e[35]=r,e[36]=y):y=e[36];let h;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==o?(h=!n.isExhausted&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:o("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=o,e[40]=h):h=e[40];let b;e[41]!==h?(b=s.jsx("div",{className:"flex items-center gap-1.5",children:h}),e[41]=h,e[42]=b):b=e[42];let x;e[43]!==d?(x={color:d},e[43]=d,e[44]=x):x=e[44];let g;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==f||e[49]!==m||e[50]!==o?(g=n.isExhausted?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"font-medium",children:m}),s.jsx("span",{className:"text-muted-foreground",children:o("settings.usage.pace.waitSeparator")}),s.jsx("span",{className:"font-medium",children:Xm(n.remainingSeconds)})]}):s.jsxs("span",{title:f,children:[s.jsx("span",{className:"text-muted-foreground",children:o("settings.usage.pace.predictionLabel")}),s.jsx("span",{className:"font-medium",children:n.predictText})]}),e[45]=n.isExhausted,e[46]=n.predictText,e[47]=n.remainingSeconds,e[48]=f,e[49]=m,e[50]=o,e[51]=g):g=e[51];let w;e[52]!==x||e[53]!==g?(w=s.jsx("span",{className:"typography-micro tabular-nums",style:x,children:g}),e[52]=x,e[53]=g,e[54]=w):w=e[54];let v;e[55]!==d?(v={backgroundColor:d},e[55]=d,e[56]=v):v=e[56];let S;e[57]!==m||e[58]!==v?(S=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]=S):S=e[59];let P;e[60]!==w||e[61]!==S?(P=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,S]}),e[60]=w,e[61]=S,e[62]=P):P=e[62];let j;return e[63]!==P||e[64]!==y||e[65]!==b?(j=s.jsxs("div",{className:y,children:[b,P]}),e[63]=P,e[64]=y,e[65]=b,e[66]=j):j=e[66],j},wr=fb,Rr=t=>{const e=nt.c(14);let n,r,a,i;e[0]!==t?({className:a,asChild:n,children:r,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);let o;e[5]!==n||e[6]!==r?(o=n&&Oe.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=o):o=e[7];const c=o;let d;e[8]!==a?(d=me("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",a),e[8]=a,e[9]=d):d=e[9];let p;return e[10]!==i||e[11]!==c||e[12]!==d?(p=s.jsx(gb,{className:d,...i,...c}),e[10]=i,e[11]=c,e[12]=d,e[13]=p):p=e[13],p},jr=t=>{const e=nt.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=me("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(xb,{className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i},ja=[{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"}],Wd="finder",Kd=new Set(["finder","terminal"]),Hd=t=>t?ja.find(e=>e.id===t)??null:null,Qc=()=>ja.filter(t=>Kd.has(t.id)).map(t=>({...t})),Dj=()=>{if(typeof window>"u")return Wd;const t=window.localStorage.getItem("openInAppId");return t&&Hd(t)?t:Wd};let Jc=!1,ki=!1,ga=!1,xa=0,Io=null;const np=()=>{Io&&(clearTimeout(Io),Io=null)},Br=Nr()((t,e)=>({selectedAppId:Dj(),availableApps:Qc(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(Jc||typeof window>"u")return;Jc=!0;const n=d=>{if(!Array.isArray(d)||d.length===0){t({availableApps:Qc(),hasLoadedApps:!1});return}const p=new Set(d.map(y=>y.name)),m=new Map(d.map(y=>[y.name,y.iconDataUrl??void 0])),f=ja.filter(y=>p.has(y.appName)||Kd.has(y.id)).map(y=>({...y,iconDataUrl:m.get(y.appName)}));t({availableApps:f,hasLoadedApps:!0})},r=async d=>{if(!ri()||!ca()||ki||e().hasLoadedApps&&!d)return;const m=ja.map(u=>u.appName);np(),ki=!0,ga=!1,t({isScanning:!0});try{const{apps:u,success:f,hasCache:y,isCacheStale:h}=await wm(m,d);if(t({isCacheStale:y?h:!1}),n(u),f){if(!y&&u.length===0&&xa<3){const x=[800,1600,3200][xa]??3200;xa+=1,ga=!0,Io=setTimeout(()=>{r()},x);return}xa=0,ga=!1;return}if(xa<3){const x=[1e3,3e3,7e3][xa]??7e3;xa+=1,ga=!0,Io=setTimeout(()=>{r()},x)}}finally{ki=!1,ga||t({isScanning:!1})}};r();const a=d=>{const p=d.detail,m=p&&typeof p.openInAppId=="string"&&p.openInAppId.length>0&&Hd(p.openInAppId)?p.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},i=()=>{r()},o=d=>{const p=d.detail;Array.isArray(p)&&(xa=3,ga=!1,t({isScanning:!1,isCacheStale:!1}),n(p))};window.addEventListener("openchamber:settings-synced",a),window.addEventListener("openchamber:app-ready",i),window.addEventListener("openchamber:installed-apps-updated",o),window.__openchamberAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(Jc||e().initialize(),!ri()||!ca()||ki||e().hasLoadedApps&&!n)return;const a=ja.map(i=>i.appName);np(),n&&t({hasLoadedApps:!1}),ki=!0,ga=!1,t({isScanning:!0});try{const{apps:i,hasCache:o,isCacheStale:c}=await wm(a,n),d=new Set(i.map(f=>f.name)),p=new Map(i.map(f=>[f.name,f.iconDataUrl??void 0])),u=ja.filter(f=>d.has(f.appName)||Kd.has(f.id)).map(f=>({...f,iconDataUrl:p.get(f.appName)}));t({availableApps:u.length>0?u:Qc(),hasLoadedApps:u.length>0,isCacheStale:o?c:!1})}finally{ki=!1,ga||t({isScanning:!1})}},selectApp:async n=>{Hd(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await As({openInAppId:n}))}})),Tj="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",Mj="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",Yc=t=>({...t,fallbackIconDataUrl:t.id==="finder"?Tj:t.id==="terminal"?Mj:void 0}),rp=t=>{const e=nt.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:a}=t,[i,o]=l.useState(!1);let c;e[0]!==n?(c=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=c):c=e[1];const d=c,p=r||a;if(p&&!i){let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f=()=>o(!0),e[2]=f):f=e[2];let y;return e[3]!==p?(y=s.jsx("img",{src:p,alt:"",className:"h-4 w-4 rounded-sm",onError:f}),e[3]=p,e[4]=y):y=e[4],y}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=me("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=m):m=e[5];let u;return e[6]!==d?(u=s.jsx("span",{className:m,children:d}),e[6]=d,e[7]=u):u=e[7],u},Rj=t=>{const e=nt.c(82),{directory:n,className:r}=t,{t:a}=ut(),i=Br(Ej),o=Br(Fj),c=Br(Oj),d=Br(Lj),p=Br($j),m=Br(Bj),u=Br(_j);let f,y;e[0]!==p?(f=()=>{p()},y=[p],e[0]=p,e[1]=f,e[2]=y):(f=e[1],y=e[2]),l.useEffect(f,y);const h=ri()&&ca();let b;e:{let te;e[3]!==o||e[4]!==i?(te=o.find(pe=>pe.id===i)??o.find(Vj)??o[0]??ja[0],e[3]=o,e[4]=i,e[5]=te):te=e[5];const ce=te;if(ce){let pe;e[6]!==ce?(pe=Yc(ce),e[6]=ce,e[7]=pe):pe=e[7],b=pe;break e}let Se;e[8]===Symbol.for("react.memo_cache_sentinel")?(Se=Yc(ja[0]),e[8]=Se):Se=e[8],b=Se}const x=b;if(!h||!n||o.length===0)return null;let g;e[9]!==n?(g=async te=>{await yv(n,te.id,te.appName)||await Hl(n,te.appName)},e[9]=n,e[10]=g):g=e[10];const w=g;let v;e[11]!==w||e[12]!==u?(v=async te=>{await u(te.id),await w(te)},e[11]=w,e[12]=u,e[13]=v):v=e[13];const S=v;let P;e[14]!==n||e[15]!==a?(P=async()=>{(await Wn(n)).ok&&q.success(a("openInApp.toast.pathCopied"))},e[14]=n,e[15]=a,e[16]=P):P=e[16];const j=P;let C;e[17]!==r?(C=me("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=C):C=e[18];let I;e[19]!==w||e[20]!==x?(I=()=>{w(x)},e[19]=w,e[20]=x,e[21]=I):I=e[21];let R;e[22]===Symbol.for("react.memo_cache_sentinel")?(R=me("inline-flex h-full items-center gap-2 px-3 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors"),e[22]=R):R=e[22];let k;e[23]!==x.label||e[24]!==a?(k=a("openInApp.actions.openInAria",{app:x.label}),e[23]=x.label,e[24]=a,e[25]=k):k=e[25];let A;e[26]!==x.fallbackIconDataUrl||e[27]!==x.iconDataUrl||e[28]!==x.label?(A=s.jsx(rp,{label:x.label,iconDataUrl:x.iconDataUrl,fallbackIconDataUrl:x.fallbackIconDataUrl}),e[26]=x.fallbackIconDataUrl,e[27]=x.iconDataUrl,e[28]=x.label,e[29]=A):A=e[29];const N=d?"animate-pulse text-muted-foreground":void 0;let D;e[30]!==N?(D=me("header-open-label",N),e[30]=N,e[31]=D):D=e[31];let T;e[32]!==a?(T=a("openInApp.actions.open"),e[32]=a,e[33]=T):T=e[33];let M;e[34]!==D||e[35]!==T?(M=s.jsx("span",{className:D,children:T}),e[34]=D,e[35]=T,e[36]=M):M=e[36];let $;e[37]!==k||e[38]!==A||e[39]!==M||e[40]!==I?($=s.jsxs("button",{type:"button",onClick:I,className:R,"aria-label":k,children:[A,M]}),e[37]=k,e[38]=A,e[39]=M,e[40]=I,e[41]=$):$=e[41];let F;e[42]===Symbol.for("react.memo_cache_sentinel")?(F=me("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[42]=F):F=e[42];let _;e[43]!==a?(_=a("openInApp.actions.chooseAppAria"),e[43]=a,e[44]=_):_=e[44];let O;e[45]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(ks,{className:"h-4 w-4"}),e[45]=O):O=e[45];let L;e[46]!==_?(L=s.jsx($s,{asChild:!0,children:s.jsx("button",{type:"button",className:F,"aria-label":_,children:O})}),e[46]=_,e[47]=L):L=e[47];let K;e[48]===Symbol.for("react.memo_cache_sentinel")?(K={translate:"-30px 0"},e[48]=K):K=e[48];let B;e[49]!==j?(B=()=>{j()},e[49]=j,e[50]=B):B=e[50];let re;e[51]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx(vr,{className:"h-4 w-4"}),e[51]=re):re=e[51];let oe;e[52]!==a?(oe=a("openInApp.actions.copyPath"),e[52]=a,e[53]=oe):oe=e[53];let ee;e[54]!==oe?(ee=s.jsx("span",{className:"typography-ui-label text-foreground",children:oe}),e[54]=oe,e[55]=ee):ee=e[55];let ae;e[56]!==B||e[57]!==ee?(ae=s.jsxs(Lt,{className:"flex items-center gap-2",onClick:B,children:[re,ee]}),e[56]=B,e[57]=ee,e[58]=ae):ae=e[58];let ge;e[59]===Symbol.for("react.memo_cache_sentinel")?(ge=s.jsx(Ln,{}),e[59]=ge):ge=e[59];let ne;if(e[60]!==o||e[61]!==S||e[62]!==x.id){let te;e[64]!==S||e[65]!==x.id?(te=ce=>{const Se=Yc(ce);return s.jsxs(Lt,{className:"flex items-center gap-2",onClick:()=>{S(ce)},children:[s.jsx(rp,{label:ce.label,iconDataUrl:ce.iconDataUrl,fallbackIconDataUrl:Se.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:ce.label}),x.id===ce.id?s.jsx(Zs,{className:"ml-auto h-4 w-4 text-primary"}):null]},ce.id)},e[64]=S,e[65]=x.id,e[66]=te):te=e[66],ne=o.map(te),e[60]=o,e[61]=S,e[62]=x.id,e[63]=ne}else ne=e[63];let E;e[67]!==c||e[68]!==m||e[69]!==a?(E=c?s.jsxs(Lt,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(In,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("openInApp.actions.refreshApps")})]}):null,e[67]=c,e[68]=m,e[69]=a,e[70]=E):E=e[70];let z;e[71]!==ae||e[72]!==ne||e[73]!==E?(z=s.jsxs(Bs,{align:"center",className:"w-56 max-h-[70vh] overflow-y-auto",style:K,children:[ae,ge,ne,E]}),e[71]=ae,e[72]=ne,e[73]=E,e[74]=z):z=e[74];let J;e[75]!==L||e[76]!==z?(J=s.jsxs(_s,{children:[L,z]}),e[75]=L,e[76]=z,e[77]=J):J=e[77];let H;return e[78]!==$||e[79]!==J||e[80]!==C?(H=s.jsxs("div",{className:C,children:[$,J]}),e[78]=$,e[79]=J,e[80]=C,e[81]=H):H=e[81],H};function Ej(t){return t.selectedAppId}function Fj(t){return t.availableApps}function Oj(t){return t.isCacheStale}function Lj(t){return t.isScanning}function $j(t){return t.initialize}function Bj(t){return t.loadInstalledApps}function _j(t){return t.selectApp}function Vj(t){return t.id===Wd}const zj=1e6,Uj="terminal-store";let ap=!1;const Xc=t=>typeof t=="object"&&t!==null,Wj=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function er(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const Zc=(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}),qg=/\x1b\[[0-9;]*m/g,Kj=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[\w\-./~%!$&'()*+,;=:@?#[\]]*)?)/i,Hj=new Set([".",",",";",":","!","?"]),Gj=t=>{let e=t;for(;e.length>0;){const n=e[e.length-1];if(n===")"||n==="]"||n==="}"||n===">"){const r=n===")"?"(":n==="]"?"[":n==="}"?"{":"<",a=e.slice(0,-1),i=(a.match(new RegExp(`\\${r}`,"g"))||[]).length,o=(a.match(new RegExp(`\\${n}`,"g"))||[]).length;if(i>o)break;e=a;continue}if(Hj.has(n)){e=e.slice(0,-1);continue}break}return e},qj=t=>{if(!t)return null;const n=t.replace(qg,"").match(Kj);if(!n?.[1])return null;let r=Gj(n[1]);return r=r.replace("0.0.0.0","127.0.0.1"),r=r.replace("[::1]","127.0.0.1"),r=r.replace("[::]","127.0.0.1"),r},Qj=t=>{if(!t)return null;const n=t.replace(qg,"").match(/Serving HTTP on .*? port (\d{2,5})/i);if(!n?.[1])return null;const r=Number.parseInt(n[1],10);return!Number.isFinite(r)||r<=0||r>65535?null:`http://127.0.0.1:${r}/`},ed=t=>({tabs:[t],activeTabId:t.id}),Lr=(t,e)=>t.tabs.findIndex(n=>n.id===e),xn=Nr()(to(_o((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=er(n);r&&t(a=>{if(a.sessions.has(r))return a;const i=new Map(a.sessions),o=`tab-${a.nextTabId}`,c=Zc(o,"Terminal");return i.set(r,ed(c)),{sessions:i,nextTabId:a.nextTabId+1}})},getDirectoryState:n=>{const r=er(n);return e().sessions.get(r)},getActiveTab:n=>{const r=er(n),a=e().sessions.get(r);if(!a)return;const i=a.activeTabId;return i?a.tabs.find(o=>o.id===i)??a.tabs[0]:a.tabs[0]},createTab:n=>{const r=er(n);if(!r)return"tab-invalid";const a=`tab-${e().nextTabId}`;return t(i=>{const o=new Map(i.sessions),c=o.get(r),d=i.nextTabId+1,m=`Terminal ${(c?.tabs.length??0)+1}`,u=Zc(a,m);return c?o.set(r,{...c,tabs:[...c.tabs,u]}):o.set(r,ed(u)),{sessions:o,nextTabId:d}}),a},setActiveTab:(n,r)=>{const a=er(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);return!c||c.activeTabId===r||Lr(c,r)<0?i:(o.set(a,{...c,activeTabId:r}),{sessions:o})})},setTabLabel:(n,r,a)=>{const i=er(n),o=a.trim();o&&t(c=>{const d=new Map(c.sessions),p=d.get(i);if(!p)return c;const m=Lr(p,r);if(m<0||p.tabs[m]?.label===o)return c;const u=[...p.tabs];return u[m]={...u[m],label:o},d.set(i,{...p,tabs:u}),{sessions:d}})},setTabIconKey:(n,r,a)=>{const i=er(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Lr(d,r);if(p<0)return o;const m=a?.trim()||null;if(d.tabs[p]?.iconKey===m)return o;const u=[...d.tabs];return u[p]={...u[p],iconKey:m},c.set(i,{...d,tabs:u}),{sessions:c}})},closeTab:async(n,r)=>{const a=er(n),c=e().sessions.get(a)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(c)try{await gv(c)}catch{}t(d=>{const p=new Map(d.sessions),m=p.get(a);if(!m)return d;const u=Lr(m,r);if(u<0)return d;const f=m.tabs.filter(x=>x.id!==r),y=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,x])=>!(x.directory===a&&x.tabId===r))),h=Object.keys(y).length!==Object.keys(d.projectActionRuns).length;if(f.length===0){const x=`tab-${d.nextTabId}`,g=Zc(x,"Terminal");return p.set(a,ed(g)),{sessions:p,nextTabId:d.nextTabId+1,...h?{projectActionRuns:y}:{}}}let b=m.activeTabId;return m.activeTabId===r&&(b=f[Math.min(u,f.length-1)]?.id??f[0]?.id??null),p.set(a,{...m,tabs:f,activeTabId:b}),{sessions:p,...h?{projectActionRuns:y}:{}}})},setTabSessionId:(n,r,a)=>{const i=er(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Lr(d,r);if(p<0)return o;const m=d.tabs[p],u=a!==null&&m.terminalSessionId!==a,f=a?"running":m.terminalSessionId?"exited":m.lifecycle,y={...m,terminalSessionId:a,lifecycle:f,isConnecting:!1,...u?{bufferChunks:[],bufferLength:0}:{}},h=[...d.tabs];return h[p]=y,c.set(i,{...d,tabs:h}),{sessions:c}})},setTabLifecycle:(n,r,a)=>{const i=er(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Lr(d,r);if(p<0)return o;const m=[...d.tabs];return m[p]={...m[p],lifecycle:a,isConnecting:!1},c.set(i,{...d,tabs:m}),{sessions:c}})},setConnecting:(n,r,a)=>{const i=er(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Lr(d,r);if(p<0)return o;const m=[...d.tabs];return m[p]={...m[p],isConnecting:a},c.set(i,{...d,tabs:m}),{sessions:c}})},appendToBuffer:(n,r,a)=>{if(!a)return;const i=er(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Lr(d,r);if(p<0)return o;const m=d.tabs[p],u=o.nextChunkId,f={id:u,data:a},y=[...m.bufferChunks,f];let h=m.bufferLength+a.length;for(;h>zj&&y.length>1;){const w=y.shift();if(!w)break;h-=w.data.length}const b=m.previewUrlLocked?null:qj(a)??Qj(a),x=!!(b&&b!==m.previewUrl),g=[...d.tabs];return g[p]={...m,bufferChunks:y,bufferLength:h,...x?{previewUrl:b,previewAutoOpened:!1}:null},c.set(i,{...d,tabs:g}),{sessions:c,nextChunkId:u+1}})},setTabPreviewUrl:(n,r,a,i={})=>{const o=er(n);t(c=>{const d=new Map(c.sessions),p=d.get(o);if(!p)return c;const m=Lr(p,r);if(m<0)return c;const u=p.tabs[m],f=i.autoOpened??u.previewAutoOpened,y=i.locked??u.previewUrlLocked;if(u.previewUrl===a&&u.previewAutoOpened===f&&u.previewUrlLocked===y)return c;const h=[...p.tabs];return h[m]={...u,previewUrl:a,previewAutoOpened:f,previewUrlLocked:y},d.set(o,{...p,tabs:h}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const a=er(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);if(!c)return i;const d=Lr(c,r);if(d<0)return i;const p=c.tabs[d];if(!p.previewUrl||p.previewAutoOpened)return i;const m=[...c.tabs];return m[d]={...p,previewAutoOpened:!0},o.set(a,{...c,tabs:m}),{sessions:o}})},setProjectActionRun:n=>{t(r=>{const a=r.projectActionRuns[n.key];return a&&a.directory===n.directory&&a.actionId===n.actionId&&a.tabId===n.tabId&&a.sessionId===n.sessionId&&a.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(a=>{const i=a.projectActionRuns[n];return!i||i.status===r?a:{projectActionRuns:{...a.projectActionRuns,[n]:{...i,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const a={...r.projectActionRuns};return delete a[n],{projectActionRuns:a}})},clearBuffer:(n,r)=>{const a=er(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);if(!c)return i;const d=Lr(c,r);if(d<0)return i;const p=[...c.tabs];return p[d]={...p[d],bufferChunks:[],bufferLength:0},o.set(a,{...c,tabs:p}),{sessions:o}})},removeDirectory:n=>{const r=er(n);t(a=>{const i=new Map(a.sessions);i.delete(r);const o=Object.fromEntries(Object.entries(a.projectActionRuns).filter(([,c])=>c.directory!==r));return{sessions:i,projectActionRuns:o}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:Uj,storage:dc(()=>og()),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(!Xc(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let a=0;for(const c of n){if(!Array.isArray(c)||c.length!==2)continue;const[d,p]=c;if(typeof d!="string"||!Xc(p))continue;const m=Array.isArray(p.tabs)?p.tabs:[],u=[];for(const h of m){if(!Xc(h))continue;const b=typeof h.id=="string"?h.id:null;if(!b)continue;const x=Wj(b);x!==null&&(a=Math.max(a,x));const g=typeof h.terminalSessionId=="string"||h.terminalSessionId===null?h.terminalSessionId:null,w=h.lifecycle,v=w==="idle"||w==="running"||w==="exited"?w:g?"running":"idle";u.push({id:b,label:typeof h.label=="string"?h.label:"Terminal",iconKey:typeof h.iconKey=="string"?h.iconKey:null,terminalSessionId:g,lifecycle:v,createdAt:typeof h.createdAt=="number"?h.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(u.length===0)continue;const f=typeof p.activeTabId=="string"?p.activeTabId:null,y=f?u.some(h=>h.id===f):!1;r.set(d,{tabs:u,activeTabId:y?f:u[0].id})}const i=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,o=Math.max(e.nextTabId,i,a+1);return{...e,sessions:r,nextChunkId:1,nextTabId:o,hasHydrated:!0}}})));if(typeof window<"u"&&!ap){ap=!0;const t=xn.persist,e=()=>{xn.getState().hasHydrated||xn.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const ip=(t,e)=>e.updatedAtMs-t.updatedAtMs,rn=Nr((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([Nv(),Nm()]),a={};for(const i of r.sort(ip))a[i.id]=i;e().listenerReady||await Sv(i=>{t(o=>({statusesById:{...o.statusesById,[i.id]:i}}))}),t({instances:n.instances,statusesById:a,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){t({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){t({isImportsLoading:!0,error:null});try{const n=await jv();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await Nm(),r={};for(const a of n.sort(ip))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 wv({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=kv(n,r);a&&a.trim()&&(i.nickname=a.trim()),await e().upsertInstance(i)},removeInstance:async n=>{await jm(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 vv(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 jm(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})})),Qg=[{key:"play",label:"Play",Icon:Gr},{key:"build",label:"Build",Icon:bb},{key:"lint",label:"Lint",Icon:wu},{key:"terminal",label:"Terminal",Icon:Za},{key:"tools",label:"Tools",Icon:Ef},{key:"bug",label:"Bug",Icon:yb},{key:"flask",label:"Flask",Icon:vb},{key:"rocket",label:"Rocket",Icon:wb},{key:"code",label:"Code",Icon:uc},{key:"server",label:"Server",Icon:ei},{key:"branch",label:"Branch",Icon:Qs},{key:"search",label:"Search",Icon:Jn},{key:"settings",label:"Settings",Icon:Ui},{key:"brain",label:"Brain",Icon:Do},{key:"stack",label:"Stack",Icon:Ca},{key:"robot",label:"Robot",Icon:Jr},{key:"command",label:"Command",Icon:Vo},{key:"file",label:"File",Icon:Ul}],Dl=Object.fromEntries(Qg.map(t=>[t.key,t.Icon])),Gd="openchamber:project-actions-updated",Jg=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},ba=(t,e)=>`${Jg(t)}::${e}`,Jj=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},op=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},Yj=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=op(e.localPort),r=op(e.remotePort);if(!n||!r)return null;const a=Jj(e.localHost||t.localForward.bindHost||"127.0.0.1"),i=(e.remoteHost||"127.0.0.1").trim(),o=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${o} - ${a}:${n} -> ${i}:${r}`,url:`http://${a}:${n}`}},Yg=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const a=Yj(n,r);a&&e.push(a)}return e},Xj=(t,e)=>{const n=(t||"").trim();return n&&Yg(e).find(i=>i.id===n)?.url||null},Zj=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],e0=["dev","start","preview","serve"];async function t0(t,e,n){if(!t)return null;const r=r0(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const a=a0(n);if(a){const i=await i0(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 s0(t)){const a=await n0(),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 s0(t){const e=`${t}/index.html`,n=await Zl(e);return typeof n=="string"&&n.trim().length>0}async function n0(){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 r0(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(e0.some(a=>n.includes(a)))return e}return t.length===1?t[0]:null}function a0(t){for(const{pattern:e}of Zj)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function i0(t){const e=await Zl(`${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 Zl(`${t}/${r}`);if(typeof i=="string"&&i.trim().length>0)return a}return"npm"}async function Zl(t){const e=yr()?.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 o0(t){try{const e=await Zl(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const l0=t=>new Promise(e=>{window.setTimeout(e,t)}),c0="\x1B",d0=new RegExp(`${c0}\\[[0-9;?]*[ -/]*[@-~]`,"g"),u0=/https?:\/\/[^\s<>'"`]+/gi,hr="__openchamber_auto_discover_preview__",m0=15e3,p0=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},h0=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}},f0=t=>{const n=t.replace(d0,"").match(u0);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const a=[];for(const i of r)try{const o=new URL(i);o.port&&o.port.length>0&&a.push({raw:i,parsed:o})}catch{}if(a.length>0){const i=o=>{const{parsed:c}=o,d=c.hostname.toLowerCase(),p=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=c.pathname||"/",u=m.split("/").filter(Boolean).length,f=m==="/"||m==="",y=!!(c.search||c.hash);let h=0;return p&&(h+=50),f&&(h+=30),h-=Math.min(u*5,20),y&&(h-=10),h};return a.sort((o,c)=>i(c)-i(o)),a[0]?.parsed.origin??a[0]?.raw??null}return r[0]??null},g0=(t,e)=>{const n=t.trim();if(!n)return e;const r=n.split(/\s+/).filter(Boolean);if(r.length>=2){const a=r[0],i=r[1].slice(0,3),o=`${a} ${i}`.trim();return r.length>2||o.length<n.length?`${o}...`:o}return n.length>12?`${n.slice(0,9).trimEnd()}...`:n},lp=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:a=!1})=>{const{t:i}=ut(),{terminal:o,runtime:c}=Yn(),{isMobile:d}=dn(),p=l.useMemo(()=>Pn(),[]),m=rn(G=>G.instances),u=rn(G=>G.load),f=De(G=>G.setBottomTerminalOpen),y=De(G=>G.setActiveMainTab),h=De(G=>G.setSettingsPage),b=De(G=>G.setSettingsDialogOpen),x=De(G=>G.setSettingsProjectsSelectedId),g=De(G=>G.openContextPreview),w=xn(G=>G.sessions),v=xn(G=>G.ensureDirectory),S=xn(G=>G.setTabLabel),P=xn(G=>G.setTabIconKey),j=xn(G=>G.setActiveTab),C=xn(G=>G.setConnecting),I=xn(G=>G.setTabSessionId),R=xn(G=>G.setTabPreviewUrl),k=xn(G=>G.projectActionRuns),A=xn(G=>G.setProjectActionRun),N=xn(G=>G.updateProjectActionRunStatus),D=xn(G=>G.removeProjectActionRun),[T,M]=l.useState([]),[$,F]=l.useState(null),[_,O]=l.useState(!1),L=l.useRef({}),K=l.useRef({}),B=l.useRef({}),re=l.useRef({}),oe=l.useRef(0),ee=t?.id??null,ae=t?.path??"",ge=l.useMemo(()=>ee?{id:ee,path:ae}:null,[ee,ae]);l.useEffect(()=>{p&&u().catch(()=>{})},[p,u]);const ne=l.useCallback(async G=>{await mr(G)},[]),E=l.useCallback(async()=>{if(!ge)return;const G=oe.current+1;oe.current=G,O(!0);try{const ke=await Bd(ge);if(oe.current!==G)return;const Ee=ke.actions;M(Ee),F(Ae=>Ae===hr||Ae&&Ee.some(xe=>xe.id===Ae)?Ae:null)}catch{if(oe.current!==G)return}finally{oe.current===G&&O(!1)}},[ge]),z=l.useMemo(()=>Jg(e||ge?.path||""),[e,ge?.path]),J=l.useMemo(()=>$?T.find(G=>G.id===$)??null:null,[T,$]),H=l.useMemo(()=>({id:hr,name:i("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[i]),te=!d,ce=l.useMemo(()=>te?[H,...T]:T,[T,H,te]);l.useEffect(()=>{E()},[E]),l.useEffect(()=>{if(typeof window>"u")return;const G=ke=>{const Ee=ke.detail;ee&&(Ee?.projectId&&Ee.projectId!==ee||E())};return window.addEventListener(Gd,G),()=>{window.removeEventListener(Gd,G)}},[E,ee]),l.useEffect(()=>{$&&($===hr&&te||T.some(G=>G.id===$)||F(null))},[T,te,$]),l.useEffect(()=>{for(const[G,ke]of Object.entries(k)){const Ae=w.get(ke.directory)?.tabs.find(xe=>xe.id===ke.tabId);(!Ae||Ae.terminalSessionId!==ke.sessionId)&&D(G)}},[k,D,w]),l.useEffect(()=>{for(const[G,ke]of Object.entries(k)){const Ee=K.current[G]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};K.current[G]=Ee;const Ae=ce.find(U=>U.id===ke.actionId);if(!Ae)continue;const V=w.get(ke.directory)?.tabs.find(U=>U.id===ke.tabId);if(!V||!Array.isArray(V.bufferChunks)||V.bufferChunks.length===0)continue;const de=V.bufferChunks.filter(U=>Ee.lastSeenChunkId===null?!0:U.id>Ee.lastSeenChunkId);if(de.length===0)continue;const Me=de.map(U=>U.data).join(""),Le=`${Ee.tail}${Me}`,se=!Ee.openedUrl&&Ae.autoOpenUrl===!0?f0(Le):null,ie=de[de.length-1]?.id??Ee.lastSeenChunkId;if(Ee.lastSeenChunkId=ie,Ee.tail=Le.slice(-512),se)if(Ee.openedUrl=!0,Ee.openInPreview){const U=k[G];U&&(R(U.directory,U.tabId,se,{locked:!1,autoOpened:!1}),U.status==="waiting-for-preview"&&N(G,"running"),window.clearTimeout(re.current[G]),delete re.current[G],g(U.directory,se))}else ne(se),q.success(i("projectActions.toast.openedUrlFromOutput"));K.current[G]=Ee}for(const G of Object.keys(K.current))k[G]||(delete K.current[G],window.clearTimeout(re.current[G]),delete re.current[G])},[ce,g,ne,k,R,i,w,N]);const Se=l.useCallback(async(G,ke={})=>{if(!z)throw new Error(i("projectActions.error.noActiveDirectory"));const Ee=ba(z,G.id);v(z);const Ae=xn.getState(),xe=Ae.getDirectoryState(z);let V=L.current[Ee]||null;const de=V?!!xe?.tabs.some(se=>se.id===V):!1;(!V||!de)&&(V=Ae.createTab(z),L.current[Ee]=V),S(z,V,`Action: ${G.name}`),P(z,V,G.icon||"play"),ke.revealTerminal!==!1&&(j(z,V),f(!0),y("terminal"));const Le=xn.getState().getDirectoryState(z)?.tabs.find(se=>se.id===V);return{key:Ee,tabId:V,sessionId:Le?.terminalSessionId??null}},[v,z,y,j,f,P,S,i]),pe=l.useCallback(async G=>{if(c.isVSCode||!a&&d)return;if(!z){q.error(i("projectActions.error.noActiveDirectoryForAction"));return}const ke=ba(z,G.id),Ee=k[ke];if(!(Ee&&Ee.status==="running"))try{const Ae=G.id===hr?await(async()=>{const[Ke,Ze]=await Promise.all([Bd({id:ge?.id??"",path:z}),o0(z)]),Xe=await t0(z,Ke.actions,Ze);if(!Xe)throw new Error(i("contextPanel.preview.noDevServer"));return{id:hr,name:i("projectActions.actions.autoDiscover"),command:Xe.command,icon:"search",autoOpenUrl:!0,openUrl:Xe.previewUrlHint||""}})():G,xe=Ae.autoOpenUrl===!0&&(Ae.openUrl||"").trim().length>0,{key:V,tabId:de,sessionId:Me}=await Se(Ae,{revealTerminal:!xe&&G.id!==hr});let Le=Me,se=!1;if(!Le){C(z,de,!0);try{Le=(await o.createSession({cwd:z})).sessionId,se=!0,I(z,de,Le)}finally{C(z,de,!1)}}if(!Le)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));se&&await l0(350),Ae.id===hr&&(B.current[V]?.(),C(z,de,!0),B.current[V]=xv(Le,Ke=>{Ke.type==="data"&&typeof Ke.data=="string"&&Ke.data.length>0&&xn.getState().appendToBuffer(z,de,Ke.data),Ke.type==="exit"&&(xn.getState().setTabLifecycle(z,de,"exited"),xn.getState().setConnecting(z,de,!1),xn.getState().removeProjectActionRun(V),delete K.current[V],B.current[V]?.(),delete B.current[V],window.clearTimeout(re.current[V]),delete re.current[V])},()=>{xn.getState().setConnecting(z,de,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const ie=Ae.autoOpenUrl===!0&&p&&(Ae.desktopOpenSshForward||"").trim().length>0,U=Ae.autoOpenUrl?h0(Ae.openUrl):null,Ve=Ae.autoOpenUrl&&p?Xj(Ae.desktopOpenSshForward,m):null;A({key:V,directory:z,actionId:Ae.id,tabId:de,sessionId:Le,status:Ae.id===hr&&!U?"waiting-for-preview":"running"}),window.clearTimeout(re.current[V]),delete re.current[V],Ae.id===hr&&!U&&(re.current[V]=window.setTimeout(()=>{xn.getState().updateProjectActionRunStatus(V,"running"),delete re.current[V]},m0)),Ve?(R(z,de,null,{locked:!0}),ne(Ve),q.success(i("projectActions.toast.openedForwardedUrl"))):U?(R(z,de,U,{locked:!0,autoOpened:!0}),g(z,U),q.success(i("projectActions.toast.openedActionUrl"))):xe?(R(z,de,null,{locked:!0}),q.error(i("projectActions.error.invalidCustomUrlFormat"))):ie?(R(z,de,null,{locked:!0}),q.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):R(z,de,null,{locked:!1,autoOpened:!1}),K.current[V]={lastSeenChunkId:null,openedUrl:!!Ve||!!U||xe,tail:"",openInPreview:Ae.id===hr};const He=p0(Ae.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
+
`));await o.sendInput(Le,`${He}\r`)}catch(Ae){D(ke),delete K.current[ke],B.current[ke]?.(),delete B.current[ke],window.clearTimeout(re.current[ke]),delete re.current[ke],q.error(Ae instanceof Error?Ae.message:i("projectActions.error.failedToRunAction"))}},[m,Se,a,d,p,z,ne,g,k,c.isVSCode,D,C,A,R,I,ge?.id,i,o]),we=l.useCallback(async G=>{const ke=ba(z,G.id),Ee=k[ke];if(!Ee)return;N(ke,"stopping");try{await o.sendInput(Ee.sessionId,"")}catch{}if(await new Promise(V=>{window.setTimeout(V,1e3)}),xn.getState().getDirectoryState(Ee.directory)?.tabs.find(V=>V.id===Ee.tabId)?.terminalSessionId===Ee.sessionId){if(typeof o.forceKill=="function")try{await o.forceKill({sessionId:Ee.sessionId})}catch{}else try{await o.close(Ee.sessionId)}catch{}I(Ee.directory,Ee.tabId,null)}D(ke),delete K.current[ke],B.current[ke]?.(),delete B.current[ke],window.clearTimeout(re.current[ke]),delete re.current[ke]},[z,k,D,I,o,N]),W=l.useCallback(()=>{const G=J??ce[0];if(!G)return;const ke=ba(z,G.id),Ee=k[ke];if(Ee?.status!=="stopping"){if(Ee){we(G);return}pe(G)}},[ce,z,pe,k,J,we]),ue=l.useCallback((G,ke=!1)=>{if(F(G.id),!ke){pe(G);return}const Ee=ba(z,G.id),Ae=k[Ee];if(Ae?.status!=="stopping"){if(Ae){we(G);return}pe(G)}},[z,pe,k,we]),Y=l.useCallback(()=>{ge?.id&&(x(ge.id),h("projects"),b(!0))},[b,h,x,ge?.id]);if(c.isVSCode||!a&&d||!ge||!z)return null;const le=J??ce[0]??null;if(!le)return null;const Z=le.icon||"play",Ie=le.id===hr?Jn:Dl[Z]||Gr,Ne=g0(le.name,i("projectActions.label.fallbackAction")),X=ba(z,le.id),he=k[X],je=he?.status==="stopping",be=he?.status==="waiting-for-preview",fe=he?w.get(he.directory)?.tabs.find(G=>G.id===he.tabId)?.previewUrl??null:null,Pe=!!(he&&fe),Be=()=>{!he||!fe||g(he.directory,fe)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:_||je,className:me("app-region-no-drag inline-flex h-9 w-9 items-center justify-center rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] p-2","typography-ui-label font-medium text-muted-foreground hover:bg-interactive-hover hover:text-foreground transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","disabled:cursor-not-allowed",n),onClick:W,"aria-label":he?i("projectActions.actions.stopNamedAria",{name:le.name}):i("projectActions.actions.runNamedAria",{name:le.name}),children:je||be?s.jsx(ts,{className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):he?s.jsx(qr,{className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(Ie,{className:"h-5 w-5"})}),Pe?s.jsxs(St,{children:[s.jsx(kt,{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:Be,children:s.jsx(ti,{className:"h-4 w-4"})})}),s.jsx(It,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(_s,{children:[s.jsx($s,{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(ks,{className:"h-3.5 w-3.5"})})}),s.jsxs(Bs,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Lt,{className:"flex items-center gap-2",onClick:Y,children:[s.jsx(zs,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Ln,{}),ce.map(G=>{const ke=G.icon||"play",Ee=G.id===hr?Jn:Dl[ke]||Gr,Ae=ba(z,G.id),xe=k[Ae],V=!!xe,de=xe?.status==="stopping";return s.jsxs(Lt,{className:"flex items-center gap-2",onClick:()=>{ue(G,!0)},children:[s.jsx(Ee,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:G.name}),de||xe?.status==="waiting-for-preview"?s.jsx(ts,{className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):V?s.jsx(qr,{className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},G.id)})]})]})]}):s.jsxs("div",{className:me("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[s.jsxs("button",{type:"button",onClick:W,disabled:_||je,className:me("inline-flex h-full items-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 justify-center px-0":"gap-2 px-3","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":he?i("projectActions.actions.stopNamedAria",{name:le.name}):i("projectActions.actions.runNamedAria",{name:le.name}),children:[s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:je||be?s.jsx(ts,{className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):he?s.jsx(qr,{className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(Ie,{className:"h-4 w-4"})}),r?null:s.jsx("span",{className:"header-open-label whitespace-nowrap",children:Ne})]}),Pe?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Be,className:me(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.openPreview"),children:s.jsx(ti,{className:"h-4 w-4"})})}),s.jsx(It,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(_s,{children:[s.jsx($s,{asChild:!0,children:s.jsx("button",{type:"button",className:me(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(ks,{className:"h-4 w-4"})})}),s.jsxs(Bs,{align:"center",className:"w-52 max-h-[70vh] overflow-y-auto",style:{translate:"-30px 0"},children:[s.jsxs(Lt,{className:"flex items-center gap-2",onClick:Y,children:[s.jsx(zs,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Ln,{}),ce.map(G=>{const ke=G.icon||"play",Ee=G.id===hr?Jn:Dl[ke]||Gr,Ae=ba(z,G.id),xe=k[Ae],V=!!xe,de=xe?.status==="stopping";return s.jsxs(Lt,{className:"flex items-center gap-2",onClick:()=>{ue(G)},children:[s.jsx(Ee,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:G.name}),de||xe?.status==="waiting-for-preview"?s.jsx(ts,{className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):V?s.jsx(qr,{className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},G.id)})]})]})]})},Nc="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",x0="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",ol=l.memo(function(e){const n=nt.c(13),{visible:r,title:a,ariaLabel:i,onClick:o,className:c,Icon:d,iconClassName:p}=e;if(!(r===void 0?!0:r))return null;const u=c??Nc,f=p??"h-[18px] w-[18px]";let y;n[0]!==d||n[1]!==f?(y=s.jsx(d,{className:f}),n[0]=d,n[1]=f,n[2]=y):y=n[2];let h;n[3]!==i||n[4]!==o||n[5]!==u||n[6]!==y?(h=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,"aria-label":i,className:u,children:y})}),n[3]=i,n[4]=o,n[5]=u,n[6]=y,n[7]=h):h=n[7];let b;n[8]!==a?(b=s.jsx(It,{children:s.jsx("p",{children:a})}),n[8]=a,n[9]=b):b=n[9];let x;return n[10]!==h||n[11]!==b?(x=s.jsxs(St,{children:[h,b]}),n[10]=h,n[11]=b,n[12]=x):x=n[12],x}),b0=l.memo(function(e){const n=nt.c(42),{isMobile:r,githubAuthStatus:a,githubAccounts:i,githubAvatarUrl:o,githubLogin:c,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:p}=e,{t:m}=ut();if(!a?.connected||r)return null;if(i.length>1){let h;n[0]===Symbol.for("react.memo_cache_sentinel")?(h=me(Nc,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=h):h=n[0];let b;n[1]!==c||n[2]!==m?(b=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[1]=c,n[2]=m,n[3]=b):b=n[3];let x;n[4]!==o||n[5]!==c||n[6]!==m?(x=o?s.jsx("img",{src:o,alt:c?m("header.github.avatarWithLogin",{login:c}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(Na,{className:"h-3.5 w-3.5 text-foreground"}),n[4]=o,n[5]=c,n[6]=m,n[7]=x):x=n[7];let g;n[8]!==d||n[9]!==b||n[10]!==x?(g=s.jsx($s,{asChild:!0,children:s.jsx("button",{type:"button",className:h,title:b,disabled:d,children:x})}),n[8]=d,n[9]=b,n[10]=x,n[11]=g):g=n[11];let w;n[12]!==m?(w=m("header.github.accountsTitle"),n[12]=m,n[13]=w):w=n[13];let v;n[14]!==w?(v=s.jsx(No,{className:"typography-ui-header font-semibold text-foreground",children:w}),n[14]=w,n[15]=v):v=n[15];let S;n[16]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(Ln,{}),n[16]=S):S=n[16];let P;if(n[17]!==i||n[18]!==p||n[19]!==d||n[20]!==m){let I;n[22]!==p||n[23]!==d||n[24]!==m?(I=R=>{const k=R.user,A=!!R.current;return s.jsxs(Lt,{className:"gap-2",disabled:A||d,onSelect:()=>{A||p(R.id)},children:[k?.avatarUrl?s.jsx("img",{src:k.avatarUrl,alt:k.login?m("header.github.avatarWithLogin",{login:k.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(Na,{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:k?.name?.trim()||k?.login||"GitHub"}),k?.login?s.jsx("span",{className:"truncate typography-micro font-mono text-muted-foreground",children:k.login}):null]}),A?s.jsx(Zs,{className:"h-4 w-4 text-primary"}):null]},R.id)},n[22]=p,n[23]=d,n[24]=m,n[25]=I):I=n[25],P=i.map(I),n[17]=i,n[18]=p,n[19]=d,n[20]=m,n[21]=P}else P=n[21];let j;n[26]!==v||n[27]!==P?(j=s.jsxs(Bs,{align:"end",className:"w-64",children:[v,S,P]}),n[26]=v,n[27]=P,n[28]=j):j=n[28];let C;return n[29]!==g||n[30]!==j?(C=s.jsxs(_s,{children:[g,j]}),n[29]=g,n[30]=j,n[31]=C):C=n[31],C}let u;n[32]!==c||n[33]!==m?(u=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[32]=c,n[33]=m,n[34]=u):u=n[34];let f;n[35]!==o||n[36]!==c||n[37]!==m?(f=o?s.jsx("img",{src:o,alt:c?m("header.github.avatarWithLogin",{login:c}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(Na,{className:"h-3.5 w-3.5 text-foreground"}),n[35]=o,n[36]=c,n[37]=m,n[38]=f):f=n[38];let y;return n[39]!==u||n[40]!==f?(y=s.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:u,children:f}),n[39]=u,n[40]=f,n[41]=y):y=n[41],y}),y0=l.memo(function(e){const n=nt.c(76),{isDesktopApp:r,currentInstanceLabel:a,compactCurrentInstanceLabel:i,isDesktopServicesOpen:o,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,desktopServicesTab:p,setDesktopServicesTab:m,quotaResultsLength:u,fetchAllQuotas:f,servicesTabItems:y,quotaLastUpdated:h,quotaDisplayMode:b,quotaDisplayTabItems:x,handleDisplayModeChange:g,handleUsageRefresh:w,isQuotaLoading:v,isUsageRefreshSpinning:S,hasRateLimits:P,rateLimitGroups:j,expandedFamilies:C,toggleFamilyExpanded:I,shortcutLabel:R,showDevShutdown:k,isDevShutdownInFlight:A,onDevShutdown:N}=e,{t:D}=ut();let T;n[0]!==p||n[1]!==f||n[2]!==u||n[3]!==d||n[4]!==c?(T=H=>{c(H),H&&(d(),p==="usage"&&u===0&&f())},n[0]=p,n[1]=f,n[2]=u,n[3]=d,n[4]=c,n[5]=T):T=n[5];let M;n[6]!==a||n[7]!==r||n[8]!==D?(M=r?D("header.services.openWithCurrent",{current:a}):D("header.services.open"),n[6]=a,n[7]=r,n[8]=D,n[9]=M):M=n[9];const $=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let F;n[10]!==$?(F=me(Nc,$),n[10]=$,n[11]=F):F=n[11];let _;n[12]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(Ca,{className:"h-[18px] w-[18px]"}),n[12]=_):_=n[12];let O;n[13]!==i||n[14]!==r?(O=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[13]=i,n[14]=r,n[15]=O):O=n[15];let L;n[16]!==M||n[17]!==F||n[18]!==O?(L=s.jsx(kt,{asChild:!0,children:s.jsx($s,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":M,className:F,children:[_,O]})})}),n[16]=M,n[17]=F,n[18]=O,n[19]=L):L=n[19];let K;n[20]!==a||n[21]!==r||n[22]!==R||n[23]!==D?(K=r?D("header.services.tooltip.currentInstanceWithShortcuts",{current:a,toggle:R("toggle_services_menu"),nextTab:R("cycle_services_tab")}):D("header.services.tooltip.servicesWithShortcuts",{toggle:R("toggle_services_menu"),nextTab:R("cycle_services_tab")}),n[20]=a,n[21]=r,n[22]=R,n[23]=D,n[24]=K):K=n[24];let B;n[25]!==K?(B=s.jsx(It,{children:s.jsx("p",{children:K})}),n[25]=K,n[26]=B):B=n[26];let re;n[27]!==L||n[28]!==B?(re=s.jsxs(St,{children:[L,B]}),n[27]=L,n[28]=B,n[29]=re):re=n[29];let oe;n[30]!==f||n[31]!==u||n[32]!==m?(oe=H=>{const te=H;m(te),te==="usage"&&u===0&&f()},n[30]=f,n[31]=u,n[32]=m,n[33]=oe):oe=n[33];let ee;n[34]!==p||n[35]!==y||n[36]!==oe?(ee=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(zr,{items:y,activeId:p,onSelect:oe,layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),n[34]=p,n[35]=y,n[36]=oe,n[37]=ee):ee=n[37];let ae;n[38]!==p||n[39]!==r||n[40]!==o||n[41]!==c?(ae=r&&p==="instance"?s.jsx(Cv,{embedded:!0,open:o&&p==="instance",onOpenChange:j0,onHostSwitched:()=>c(!1)}):null,n[38]=p,n[39]=r,n[40]=o,n[41]=c,n[42]=ae):ae=n[42];let ge;n[43]!==p||n[44]!==o?(ge=p==="mcp"?s.jsx(Gg,{active:o&&p==="mcp"}):null,n[43]=p,n[44]=o,n[45]=ge):ge=n[45];let ne;n[46]!==p||n[47]!==C||n[48]!==g||n[49]!==w||n[50]!==P||n[51]!==v||n[52]!==S||n[53]!==b||n[54]!==x||n[55]!==h||n[56]!==j||n[57]!==D||n[58]!==I?(ne=p==="usage"?s.jsxs("div",{className:"overflow-x-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--interactive-border)] px-4 py-2.5",children:[s.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:D("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Xg(h)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(zr,{items:x,activeId:b,onSelect:H=>{g(H)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:me("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:w,disabled:v||S,"aria-label":D("header.services.refreshRateLimitsAria"),children:s.jsx(In,{className:me("h-4 w-4",S&&"animate-spin")})})]})]}),P?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:j.map((H,te)=>{const ce=C[H.providerId]??[];return s.jsxs(l.Fragment,{children:[te>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(Vn,{providerId:H.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:H.providerName})]}),H.entries.length===0&&(!H.modelFamilies||H.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:H.error??D("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[H.entries.map(Se=>{const[pe,we]=Se,W=b==="remaining"?we.remainingPercent:we.usedPercent,ue=Oo(we.usedPercent,we.resetAt,we.windowSeconds,pe),Y=ue?.dailyAllocationPercent!=null?b==="remaining"?100-oa(ue.elapsedRatio):oa(ue.elapsedRatio):null,le=Fo(we.valueLabel,W);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Hu(pe)}),we.resetAfterFormatted??we.resetAtFormatted?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:we.resetAfterFormatted??we.resetAtFormatted}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:le==="-"?"":le})]}),s.jsx($o,{percent:W,tonePercent:we.usedPercent,className:"h-1.5",expectedMarkerPercent:Y}),ue?s.jsx(Bo,{paceInfo:ue,compact:!0}):null]},`${H.providerId}-${pe}`)}),H.modelFamilies&&H.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:H.modelFamilies.map(Se=>{const pe=Se.familyId??"other",we=ce.includes(pe);return s.jsxs(wr,{open:we,onOpenChange:()=>I(H.providerId,pe),children:[s.jsxs(Rr,{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}),we?s.jsx(ks,{className:"h-4 w-4 text-muted-foreground"}):s.jsx($n,{className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(jr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Se.models.map(W=>{const[ue,Y]=W,le=b==="remaining"?Y.remainingPercent:Y.usedPercent,Z=Oo(Y.usedPercent,Y.resetAt,Y.windowSeconds),Ie=Z?.dailyAllocationPercent!=null?b==="remaining"?100-oa(Z.elapsedRatio):oa(Z.elapsedRatio):null,Ne=Fo(Y.valueLabel,le);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:Yl(ue)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:Ne==="-"?"":Ne})]}),s.jsx($o,{percent:le,tonePercent:Y.usedPercent,className:"h-1.5",expectedMarkerPercent:Ie}),Z?s.jsx(Bo,{paceInfo:Z,compact:!0}):null]},`${H.providerId}-${ue}`)})})})]},pe)})}):null]})]},H.providerId)})})]}):null,n[46]=p,n[47]=C,n[48]=g,n[49]=w,n[50]=P,n[51]=v,n[52]=S,n[53]=b,n[54]=x,n[55]=h,n[56]=j,n[57]=D,n[58]=I,n[59]=ne):ne=n[59];let E;n[60]!==A||n[61]!==N||n[62]!==k||n[63]!==D?(E=k?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(Lt,{disabled:A,onSelect:()=>{N()},children:D("header.services.shutdownDev")})})]}):null,n[60]=A,n[61]=N,n[62]=k,n[63]=D,n[64]=E):E=n[64];let z;n[65]!==ee||n[66]!==ae||n[67]!==ge||n[68]!==ne||n[69]!==E?(z=s.jsxs(Bs,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[ee,ae,ge,ne,E]}),n[65]=ee,n[66]=ae,n[67]=ge,n[68]=ne,n[69]=E,n[70]=z):z=n[70];let J;return n[71]!==o||n[72]!==T||n[73]!==re||n[74]!==z?(J=s.jsxs(_s,{open:o,onOpenChange:T,children:[re,z]}),n[71]=o,n[72]=T,n[73]=re,n[74]=z,n[75]=J):J=n[75],J}),v0=(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??""),w0=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},Xg=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(/\/+$/,"")},ll=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,cp=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r,desktopRightSidebarActionsHost:a=null})=>{const{t:i}=ut(),o=De(Fe=>Fe.setSessionSwitcherOpen),c=De(Fe=>Fe.toggleSidebar),d=De(Fe=>Fe.isSidebarOpen),p=De(Fe=>Fe.isRightSidebarOpen),m=De(Fe=>Fe.toggleBottomTerminal),u=De(Fe=>Fe.toggleRightSidebar),f=De(Fe=>Fe.openContextOverview),y=De(Fe=>Fe.openContextPlan),h=De(Fe=>Fe.closeContextPanel),b=De(Fe=>Fe.contextPanelByDirectory),x=De(Fe=>Fe.activeMainTab),g=De(Fe=>Fe.setActiveMainTab),w=De(Fe=>Fe.shortcutOverrides),v=yt(Fe=>Fe.getCurrentModel),S=Yn(),[P,j]=l.useState(!1),C=Ht(Fe=>Fe.getContextUsage),I=Ht(Fe=>Fe.openNewSessionDraft),R=Ht(Fe=>!!Fe.newSessionDraft?.open),k=Ht(Fe=>Fe.currentSessionId),A=Iv(k??""),N=lg(k??null),D=So(Fe=>Fe.activeSessions),T=cg(),M=Es(Fe=>Fe.activeProjectId?Fe.projects.find(Nt=>Nt.id===Fe.activeProjectId)??null:null),$=l.useMemo(()=>{if(!M)return null;const Fe=M.label?.trim();if(Fe)return Fe;const Nt=M.path.split(/[\\/]/).filter(Boolean);return Nt[Nt.length-1]??null},[M]),F=Ls(Fe=>Fe.results),_=Ls(Fe=>Fe.fetchAllQuotas),O=Ls(Fe=>Fe.isLoading),L=Ls(Fe=>Fe.lastUpdated),K=Ls(Fe=>Fe.displayMode),B=Ls(Fe=>Fe.dropdownProviderIds),re=Ls(Fe=>Fe.loadSettings),oe=Ls(Fe=>Fe.setDisplayMode),{isMobile:ee}=dn(),ae=sr(Fe=>Fe.status),ge=sr(Fe=>Fe.setStatus),ne=l.useRef(null),[E,z]=l.useState(()=>typeof window>"u"?!1:Pn()),J=l.useMemo(()=>Ou(),[]),H=fc(),[te,ce]=l.useState(!1),Se=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),pe=l.useMemo(()=>{if(typeof window>"u")return null;const Fe=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Fe=="number"&&Number.isFinite(Fe)&&Fe>0)return Fe;if(typeof navigator>"u")return null;const Nt=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Nt)return null;const Xt=Number.parseInt(Nt[1],10),ms=Number.parseInt(Nt[2],10);return Number.isNaN(Xt)?null:Xt===10?ms:Xt},[]);Oe.useEffect(()=>{typeof window>"u"||z(Pn())},[]);const we=v(),W=we&&typeof we.limit=="object"&&we.limit!==null?we.limit:null,ue=W&&typeof W.context=="number"?W.context:0,Y=W&&typeof W.output=="number"?W.output:0,le=C(ue,Y),[Z,Ie]=l.useState(null),Ne=!k||A;Oe.useEffect(()=>{if(!k){Ie(Fe=>Fe===null?Fe:null);return}if(le&&le.totalTokens>0){Ie(Fe=>v0(Fe,le)?Fe:le);return}Ne&&Ie(Fe=>Fe===null?Fe:null)},[le,k,Ne]);const X=De(Fe=>Fe.isSessionSwitcherOpen),he=ae?.connected?ae.user?.avatarUrl??null:null,je=ae?.connected?ae.user?.login??null:null,be=ae?.accounts??[],[fe,Pe]=l.useState(!1),[Be,G]=l.useState(!1),[ke,Ee]=l.useState(!1),[Ae,xe]=l.useState(!1),[V,de]=l.useState("Local"),Me=l.useMemo(()=>w0(V),[V]),[Le,se]=l.useState(E?"instance":"usage"),[ie,U]=l.useState("usage");Oe.useEffect(()=>{!E&&Le==="instance"&&se("usage")},[Le,E]);const Ve=l.useMemo(()=>jn(),[]),He=l.useMemo(()=>ee?typeof t=="function"?!!n:X:d,[ee,X,d,n,t]),Ke=!Ve&&x==="chat"&&!!Z&&Z.totalTokens>0,Ze=Z&&Z.contextLimit>0?Math.min(999,Z.totalTokens/Z.contextLimit*100):0,Xe=l.useCallback(async()=>{if(!(typeof window>"u"||!E))try{const Fe=await Av(),Nt=window.location.href,Xt=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin;if(Sm(Nt,Xt)){de("Local");return}const ms=Fe.hosts.find(tn=>Sm(Nt,tn.url));if(ms?.label?.trim()){de(Pv(ms.label.trim()));return}de("Instance")}catch{de("Local")}},[E]);Oe.useEffect(()=>{Xe()},[Xe]),Wg();const dt=Ls(Fe=>Fe.selectedModels),et=Ls(Fe=>Fe.expandedFamilies),ct=Ls(Fe=>Fe.toggleFamilyExpanded),at=l.useMemo(()=>{const Fe=[];for(const Nt of Zr){if(!B.includes(Nt.id))continue;const Xt=F.find(Gs=>Gs.providerId===Nt.id),ms=Xt?.usage?.windows??{},tn=Xt?.usage?.models,sn=Object.entries(ms),Hs={providerId:Nt.id,providerName:Nt.name,entries:sn,error:Xt&&!Xt.ok&&Xt.configured?Xt.error:void 0};if(tn&&Object.keys(tn).length>0){const Gs=dt[Nt.id]??[],nn=Gs.length>0,pr=xj(tn,Nt.id),lr=zg(Nt.id),ma=Ug(lr);Hs.modelFamilies=[];for(const _n of ma){const nr=pr.get(_n.id)??[];if(nr.length===0)continue;const vn=nn?nr.filter(En=>Gs.includes(En)):nr;if(vn.length===0)continue;const cr=[];for(const En of vn){const Ur=tn[En];if(Ur?.windows){const Wr=Object.entries(Ur.windows);Wr.length>0&&cr.push([En,Wr[0][1]])}}cr.length>0&&Hs.modelFamilies.push({familyId:_n.id,familyLabel:_n.label,models:cr})}const Bn=pr.get(null)??[],Or=nn?Bn.filter(_n=>Gs.includes(_n)):Bn;if(Or.length>0){const _n=[];for(const nr of Or){const vn=tn[nr];if(vn?.windows){const cr=Object.entries(vn.windows);cr.length>0&&_n.push([nr,cr[0][1]])}}_n.length>0&&Hs.modelFamilies.push({familyId:null,familyLabel:i("header.services.modelFamily.other"),models:_n})}}(sn.length>0||Hs.modelFamilies&&Hs.modelFamilies.length>0||Hs.error)&&Fe.push(Hs)}return Fe},[B,F,dt,i]),ye=at.length>0;l.useEffect(()=>{re()},[re]);const Ge=l.useCallback(async Fe=>{oe(Fe);try{await As({usageDisplayMode:Fe})}catch(Nt){console.warn("Failed to update usage display mode:",Nt)}},[oe]),$e=l.useCallback(()=>{if(Ae)return;xe(!0);const Fe=new Promise(Nt=>setTimeout(Nt,500));Promise.all([_(),Fe]).finally(()=>{xe(!1)})},[_,Ae]),_e=l.useMemo(()=>k?T.find(Fe=>Fe.id===k)??D.find(Fe=>Fe.id===k)??N??Dv().find(Fe=>Fe.id===k)??null:null,[k,N,D,T]),tt=l.useRef(null),[Qe,ze]=l.useState(0);l.useEffect(()=>{if(!k){tt.current&&(tt.current=null,ze(ms=>ms+1));return}if(_e){tt.current={sessionId:k,session:_e,expiresAt:Date.now()+2e3};return}const Fe=tt.current;if(!Fe||Fe.sessionId!==k)return;const Nt=Fe.expiresAt-Date.now();if(Nt<=0){tt.current=null,ze(ms=>ms+1);return}const Xt=window.setTimeout(()=>{tt.current?.sessionId===k&&(tt.current=null),ze(ms=>ms+1)},Nt);return()=>{window.clearTimeout(Xt)}},[k,_e]);const gt=(()=>{if(_e)return _e;if(!k)return null;const Fe=tt.current;return Fe&&Fe.sessionId===k&&Fe.expiresAt>Date.now()?Fe.session:null})(),Vt=Ht(Fe=>k?Fe.worktreeMetadata.get(k)?.path??"":""),Kt=Ht(Fe=>k?Fe.worktreeMetadata.get(k)?.branch?.trim()??null:null),Jt=dg(Fe=>k?Fe.getAttachment(k):void 0),At=l.useMemo(()=>Jt?Tv(Jt):null,[Jt]),jt=l.useMemo(()=>Jt?Jt.legacy?"legacy":Jt.degraded?"degraded":Jt.worktreeStatus==="missing"?"missing":Jt.worktreeStatus==="invalid"?"invalid":Jt.attentionReason?"attention":null:null,[Jt]),ns=l.useMemo(()=>Cr(Vt||""),[Vt]),ot=l.useMemo(()=>{const Fe=typeof gt?.directory=="string"?gt.directory:"";return Cr(Fe||"")},[gt?.directory]),Zt=Ht(Fe=>Fe.newSessionDraft?.open?Cr(Fe.newSessionDraft.bootstrapPendingDirectory??Fe.newSessionDraft.directoryOverride??""):""),Yt=l.useMemo(()=>ns||ot||Zt,[Zt,ot,ns]),es=Ht(Fe=>{const Nt=Cr(ns||ot||"");if(!Nt)return null;for(const Xt of Fe.availableWorktreesByProject.values()){const tn=Xt.find(sn=>Cr(sn.path)===Nt)?.branch?.trim();if(tn)return tn}return null}),ds=Mv(Yt||null)||Kt||es,gs=l.useMemo(()=>{if(!k)return $??"OpenChamber";const Fe=gt?.title?.trim();return Fe&&Fe.length>0?Fe:"Untitled Session"},[$,gt?.title,k]),us=l.useMemo(()=>ug(gt?.summary),[gt?.summary]),Ct=l.useMemo(()=>us||{additions:0,deletions:0},[us]),Ue=Ct.additions>0||Ct.deletions>0,Dt=l.useMemo(()=>Cr(Yt||M?.path||""),[M?.path,Yt]),Tt=l.useMemo(()=>M?{id:M.id,path:M.path}:null,[M]),wt=l.useRef(null);l.useEffect(()=>{!Tt||!Dt||(wt.current={projectRef:Tt,directory:Dt})},[Dt,Tt]);const Wt=l.useMemo(()=>Tt&&Dt?{projectRef:Tt,directory:Dt}:wt.current,[Dt,Tt]),_t=Lu(Fe=>Fe.planModeEnabled),Vs=Ht(Fe=>Fe.isSessionPlanAvailable),mt=_t&&k?Vs(k):!1,cs=mt,qt=l.useRef("");l.useEffect(()=>{if(!_t){De.getState().activeMainTab==="plan"&&De.getState().setActiveMainTab("chat");return}if(!k)return;const Fe=`${k||"none"}:${ot||"none"}:${gt?.time?.created||0}:${gt?.slug||"none"}`;qt.current!==Fe&&(qt.current=Fe),!mt&&De.getState().activeMainTab==="plan"&&De.getState().setActiveMainTab("chat")},[_t,mt,gt?.slug,gt?.time?.created,k,ot]);const Ds=l.useCallback(async Fe=>{if(!(!Fe||fe)){Pe(!0);try{const Nt=S.github?await S.github.authActivate(Fe):await(async()=>{const Xt=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:Fe})}),ms=await Xt.json().catch(()=>null);if(!Xt.ok||!ms)throw new Error(ms?.error||Xt.statusText);return ms})();ge(Nt)}catch(Nt){console.error("Failed to switch GitHub account:",Nt)}finally{Pe(!1)}}},[fe,S.github,ge]),Os=l.useCallback(()=>{if(typeof document>"u")return;const Fe=document.activeElement;if(!Fe)return;const Nt=Fe.tagName;(Nt==="INPUT"||Nt==="TEXTAREA"||Nt==="SELECT"||Fe.isContentEditable)&&Fe.blur()},[]),Q=l.useCallback(()=>{if(ee){Os(),o(!X);return}c()},[Os,ee,X,o,c]),ht=l.useCallback(()=>{g("chat"),o(!1),I()},[I,g,o]),vt=l.useCallback(()=>{Gl("desktop_open_draft_mini_chat_window",{directory:Cr(Yt||M?.path||""),projectId:M?.id??null}).catch(Fe=>{console.warn("[header] failed to open draft mini chat window",Fe)})},[M?.id,M?.path,Yt]),zt=l.useCallback(()=>{if(R){vt();return}k&&Gl("desktop_open_session_mini_chat_window",{sessionId:k,directory:Cr(Yt||M?.path||"")}).catch(Fe=>{console.warn("[header] failed to open session mini chat window",Fe)})},[M?.path,k,vt,R,Yt]),ss=l.useCallback(()=>{const Fe=Cr(Yt||"");if(!Fe)return;const Nt=b[Fe];if(ll(Nt)==="context"){h(Fe);return}f(Fe)},[h,b,f,Yt]),is=l.useMemo(()=>{const Fe=Cr(Yt||"");if(!Fe)return!1;const Nt=b[Fe];return ll(Nt)==="context"},[b,Yt]),Ss=l.useCallback(()=>{const Fe=Cr(Yt||"");if(!Fe)return;const Nt=b[Fe];if(ll(Nt)==="plan"){h(Fe);return}y(Fe)},[h,b,y,Yt]),Ms=l.useMemo(()=>{const Fe=Cr(Yt||"");if(!Fe)return!1;const Nt=b[Fe];return ll(Nt)==="plan"},[b,Yt]),We=Nc,xt=x0,Pt=l.useMemo(()=>!d&&(E&&Se&&!te||H)?"pl-[5.5rem]":"pl-3",[E,te,Se,d,H]);Oe.useEffect(()=>{if(!E||!Se){ce(!1);return}let Fe=!1,Nt=null;const Xt=async()=>{try{const{getCurrentWindow:tn}=await Mr(async()=>{const{getCurrentWindow:Gs}=await import("./vendor-.bun-0geEbyBQ.js").then(nn=>nn.fc);return{getCurrentWindow:Gs}},__vite__mapDeps([0,1])),Hs=await tn().isFullscreen();Fe||ce(Hs)}catch{Fe||ce(!1)}},ms=async()=>{try{const{getCurrentWindow:tn}=await Mr(async()=>{const{getCurrentWindow:Hs}=await import("./vendor-.bun-0geEbyBQ.js").then(Gs=>Gs.fc);return{getCurrentWindow:Hs}},__vite__mapDeps([0,1]));Nt=await tn().onResized(()=>{Xt()})}catch{}};return Xt(),ms(),()=>{Fe=!0,Nt&&Nt()}},[E,Se]);const Mt=l.useMemo(()=>!E||!Se||pe===null?"":pe>=26?"h-12":pe<=15?"h-14":"",[E,Se,pe]),as=l.useMemo(()=>{if(!(E||Ve))return{paddingLeft:H&&!d?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",minHeight:"max(3rem, var(--oc-wco-titlebar-height, 0px))",height:"max(3rem, var(--oc-wco-titlebar-height, 0px))"}},[E,d,H,Ve]),st=l.useCallback(()=>{if(typeof document>"u")return;const Fe=ne.current?.getBoundingClientRect().height;Fe&&document.documentElement.style.setProperty("--oc-header-height",`${Fe}px`)},[]);Oe.useEffect(()=>{if(typeof window>"u")return;st();const Fe=ne.current;if(!Fe||typeof ResizeObserver>"u")return()=>{};let Nt=0;const Xt=()=>{Nt||(Nt=requestAnimationFrame(()=>{Nt=0,st()}))},ms=new ResizeObserver(Xt);return ms.observe(Fe),window.addEventListener("resize",Xt),window.addEventListener("orientationchange",Xt),()=>{Nt&&cancelAnimationFrame(Nt),ms.disconnect(),window.removeEventListener("resize",Xt),window.removeEventListener("orientationchange",Xt)}},[st]),Oe.useEffect(()=>{st()},[st,ee,Mt]);const Et=l.useCallback(async Fe=>{const Nt=Fe.target;Nt.closest(".app-region-no-drag")||Nt.closest("button, a, input, select, textarea")||Fe.button===0&&E&&await mg()},[E]),os=l.useMemo(()=>{if(ee){const Fe=[{id:"chat",label:i("layout.mainTab.chat"),icon:mc}];return cs&&Fe.push({id:"plan",label:i("layout.mainTab.plan"),icon:Ul}),Fe.push({id:"diff",label:i("layout.mainTab.diff"),icon:"diff"},{id:"files",label:i("layout.mainTab.files"),icon:Ff},{id:"terminal",label:i("layout.mainTab.terminal"),icon:Za}),Fe}return[]},[ee,cs,i]),rs=l.useCallback(Fe=>gc(ia(Fe,w)),[w]);Oe.useEffect(()=>{!ee&&(x==="git"||x==="terminal"||x==="diff"||x==="files")&&g("chat")},[x,ee,g]);const $t=l.useMemo(()=>{const Fe=[];return E&&Fe.push({value:"instance",label:i("layout.services.instance"),icon:ei}),Fe.push({value:"usage",label:i("layout.services.usage"),icon:Dd},{value:"mcp",label:"MCP",icon:Hg}),Fe},[E,i]),xs=l.useMemo(()=>$t.map(Fe=>({id:Fe.value,label:Fe.label,icon:s.jsx(Fe.icon,{className:"h-3.5 w-3.5"})})),[$t]),bn=l.useMemo(()=>{if(typeof window>"u"||E||Ve)return!1;const Fe=window.location.hostname;return Fe==="localhost"||Fe==="127.0.0.1"||Fe==="::1"},[E,Ve]),en=l.useCallback(async()=>{if(P)return;j(!0),Ee(!1);const Fe=[];let Nt=!1;try{try{for(const[,Xt]of xn.getState().sessions.entries())for(const ms of Xt.tabs)ms.previewUrl&&Fe.push(ms.previewUrl)}catch{}try{await bv({})}catch{}try{(await fetch("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:Fe})})).ok?Nt=!0:Nt=(await fetch("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{Nt||j(!1)}},[P,Ee]),Ws=l.useMemo(()=>[{value:"usage",label:i("header.services.used")},{value:"remaining",label:i("header.services.remaining")}],[i]),hn=l.useMemo(()=>Ws.map(Fe=>({id:Fe.value,label:Fe.label})),[Ws]),un=l.useMemo(()=>[{id:"usage",label:i("layout.services.usage"),icon:s.jsx(Dd,{className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(Vo,{className:"h-3.5 w-3.5"})}],[i]);Oe.useEffect(()=>{const Fe=Nt=>{if($u(Nt)&&!Nt.shiftKey&&!Nt.altKey){const Xt=parseInt(Nt.key,10);Xt>=1&&Xt<=os.length&&(Nt.preventDefault(),g(os[Xt-1].id))}};return window.addEventListener("keydown",Fe),()=>window.removeEventListener("keydown",Fe)},[os,g]),Oe.useEffect(()=>{const Fe=Nt=>{const Xt=ia("toggle_services_menu",w);if(kl(Nt,Xt)){Nt.preventDefault(),ke?Ee(!1):(Ee(!0),Xe(),Le==="usage"&&F.length===0&&_());return}const ms=ia("cycle_services_tab",w);if(kl(Nt,ms)){Nt.preventDefault();const sn=$t.map(pr=>pr.value);if(sn.length===0)return;const Hs=sn.indexOf(Le),Gs=Hs===-1?0:(Hs+1)%sn.length,nn=sn[Gs];se(nn),Ee(!0),Xe(),nn==="usage"&&F.length===0&&_();return}const tn=ia("toggle_context_plan",w);kl(Nt,tn)&&(Nt.preventDefault(),Ss())};return window.addEventListener("keydown",Fe),()=>window.removeEventListener("keydown",Fe)},[w,ke,Le,$t,F.length,_,Xe,Ss]);const fn=Fe=>{const Nt=x===Fe.id,Xt=Fe.icon==="diff",ms=Xt?null:Fe.icon,tn=Fe.id==="chat",sn=Gs=>Xt?s.jsx(Ym,{size:Gs}):ms?s.jsx(ms,{size:Gs}):null,Hs=s.jsxs("button",{type:"button",onClick:()=>g(Fe.id),className:me("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",Nt?"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",tn&&!ee&&"min-w-[100px] justify-center"),"aria-label":Fe.label,"aria-selected":Nt,role:"tab",children:[ee?sn(20):s.jsxs(s.Fragment,{children:[sn(16),s.jsx("span",{className:"header-tab-label",children:Fe.label})]}),Fe.badge!==void 0&&Fe.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:Fe.badge})]});return s.jsx(l.Fragment,{children:Hs},Fe.id)},gn=s.jsxs(s.Fragment,{children:[cs&&s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.actions.openPlanAria"),onClick:Ss,className:me(We,Ms&&"bg-[var(--interactive-hover)]"),children:s.jsx(Ul,{className:"h-[18px] w-[18px]"})})}),s.jsx(It,{children:s.jsx("p",{children:i("header.actions.planWithShortcut",{shortcut:rs("toggle_context_plan")})})})]}),s.jsx(Rj,{directory:Dt,className:"mr-1"}),s.jsx(y0,{isDesktopApp:E,currentInstanceLabel:V,compactCurrentInstanceLabel:Me,isDesktopServicesOpen:ke,setIsDesktopServicesOpen:Ee,refreshCurrentInstanceLabel:Xe,desktopServicesTab:Le,setDesktopServicesTab:se,quotaResultsLength:F.length,fetchAllQuotas:_,servicesTabItems:xs,quotaLastUpdated:L,quotaDisplayMode:K,quotaDisplayTabItems:hn,handleDisplayModeChange:Ge,handleUsageRefresh:$e,isQuotaLoading:O,isUsageRefreshSpinning:Ae,hasRateLimits:ye,rateLimitGroups:at,expandedFamilies:et,toggleFamilyExpanded:ct,shortcutLabel:rs,showDevShutdown:bn,isDevShutdownInFlight:P,onDevShutdown:en}),s.jsx(ol,{title:i("header.actions.terminalPanelWithShortcut",{shortcut:rs("toggle_terminal")}),ariaLabel:i("header.actions.toggleTerminalPanelAria"),onClick:m,Icon:Za}),s.jsx(ol,{title:i("header.actions.rightSidebarWithShortcut",{shortcut:rs("toggle_right_sidebar")}),ariaLabel:i("header.actions.toggleRightSidebarAria"),onClick:u,Icon:Ei}),s.jsx(b0,{isMobile:ee,githubAuthStatus:ae,githubAccounts:be,githubAvatarUrl:he,githubLogin:je,isSwitchingGitHubAccount:fe,handleGitHubAccountSwitch:Ds})]}),yn=!p||!a,mn=J&&(R||!!k),Rn=()=>s.jsxs("div",{onMouseDown:Et,className:me("app-region-drag relative flex h-12 select-none items-center pr-3",Pt,Mt),style:as,role:"tablist","aria-label":i("header.navigation.mainAria"),children:[s.jsx(ol,{visible:!d,title:i("header.actions.openSessionsWithShortcut",{shortcut:rs("toggle_sidebar")}),ariaLabel:i("header.actions.openSessionsAria"),onClick:Q,className:`${We} shrink-0`,Icon:si}),s.jsxs("div",{className:me("flex min-w-0 flex-1 items-center",!d&&"pl-3"),children:[He?null:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.actions.newSessionAria"),onClick:ht,className:me(We,"mr-6 shrink-0"),children:s.jsx(Of,{className:"h-[18px] w-[18px]"})})}),s.jsx(It,{children:s.jsx("p",{children:i("header.actions.newSessionWithShortcut",{shortcut:rs("new_chat")})})})]}),Wt&&s.jsx(lp,{projectRef:Wt.projectRef,directory:Wt.directory,className:"mr-2"}),R?null:s.jsxs("div",{className:"mr-3 min-w-0",children:[s.jsx("div",{className:"truncate pl-1 typography-ui-label text-[14px] font-normal leading-tight text-foreground",children:gs}),$||ds||Ue?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 truncate pl-1 typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[$?s.jsx("span",{className:"truncate",children:$}):null,ds?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(Qs,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ds})]}):null,Ue?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:["+",Ct.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Ct.deletions]})]}):null,jt?s.jsxs("span",{className:me("inline-flex min-w-0 items-center gap-0.5",jt==="attention"||jt==="invalid"||jt==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(ju,{className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:At})]}):null]}):null]}),os.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:os.map(Fe=>fn(Fe))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ke&&Z?s.jsx(Rv,{totalTokens:Z.totalTokens,percentage:Ze,colorPercentage:Z.percentage,contextLimit:Z.contextLimit,outputLimit:Z.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:ss,pressed:is,className:yn&&!mn?"mr-3.5":"",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,s.jsx(ol,{visible:mn,title:i(R?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:i(R?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:zt,className:me(We,yn&&Ke?"mr-3.5":"mr-1"),Icon:Nb}),yn?gn:null,!yn&&a?wo.createPortal(gn,a):null]})]})]}),Fr=()=>s.jsxs("div",{className:"app-region-drag relative flex items-center gap-2 px-3 py-2 select-none",children:[s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t?s.jsx("button",{type:"button",onClick:t,className:me(xt,n&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":i(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(si,{className:"h-5 w-5"})}):X?s.jsx("button",{type:"button",onClick:()=>o(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":i("header.actions.backAria"),children:s.jsx(Wi,{className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:Q,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":i("header.actions.openSessionsAria"),children:s.jsx(jb,{className:"h-5 w-5"})}),X&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:i("header.sessions.title")})]}),!X&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":i("header.navigation.mainAria"),children:os.map(Fe=>{const Nt=x===Fe.id,Xt=Fe.icon==="diff",ms=Xt?null:Fe.icon;return s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{ee&&Os(),g(Fe.id)},"aria-label":Fe.label,"aria-selected":Nt,role:"tab",className:me(xt,"relative rounded-lg",Nt&&"bg-interactive-selection text-interactive-selection-foreground"),children:[Xt?s.jsx(Ym,{className:"h-5 w-5"}):ms?s.jsx(ms,{className:"h-5 w-5"}):null,Fe.badge!==void 0&&Fe.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:Fe.badge}),Fe.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":i("header.changes.availableAria")})]})}),s.jsx(It,{children:s.jsx("p",{children:Fe.label})})]},Fe.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[Wt&&s.jsx(lp,{projectRef:Wt.projectRef,directory:Wt.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(_s,{open:Be,onOpenChange:Fe=>{G(Fe),Fe&&F.length===0&&_()},children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx($s,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.services.viewAria"),className:xt,children:s.jsx(Ca,{className:"h-5 w-5"})})})}),s.jsx(It,{children:s.jsx("p",{children:i("header.services.title")})})]}),s.jsx(Bs,{align:"end",sideOffset:0,className:"h-dvh w-[100vw] max-h-none rounded-none border-0 p-0 overflow-hidden",children:s.jsxs("div",{className:"flex h-full flex-col bg-[var(--surface-elevated)]",children:[s.jsx("div",{className:"sticky top-0 z-20 bg-[var(--surface-elevated)] px-2 py-px",children:s.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-0",children:[s.jsx("div",{className:"h-10 min-w-0 flex-1",children:s.jsx(zr,{items:un,activeId:ie,onSelect:Fe=>{const Nt=Fe;U(Nt),Nt==="usage"&&F.length===0&&_()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})}),s.jsx("button",{type:"button",onClick:()=>G(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":i("header.services.closeAria"),children:s.jsx(Is,{className:"h-5 w-5"})})]})}),ie==="mcp"&&s.jsx(Gg,{active:Be&&ie==="mcp"}),ie==="usage"&&s.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]",children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[s.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:i("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Xg(L)})]}),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:()=>Ge("usage"),className:me("typography-ui-label px-1 pb-0.5 transition-colors",K==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:i("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>Ge("remaining"),className:me("typography-ui-label px-1 pb-0.5 transition-colors",K==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:i("header.services.remaining")})]}),s.jsx("button",{type:"button",className:me("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:$e,disabled:O||Ae,"aria-label":i("header.services.refreshRateLimitsAria"),children:s.jsx(In,{className:me("h-4 w-4",Ae&&"animate-spin")})})]})]})}),!ye&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:i("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:at.map((Fe,Nt)=>s.jsxs(l.Fragment,{children:[Nt>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(Vn,{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??i("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Fe.entries.map(([Xt,ms])=>{const tn=K==="remaining"?ms.remainingPercent:ms.usedPercent,sn=Oo(ms.usedPercent,ms.resetAt,ms.windowSeconds,Xt),Hs=sn?.dailyAllocationPercent!=null?K==="remaining"?100-oa(sn.elapsedRatio):oa(sn.elapsedRatio):null,Gs=Fo(ms.valueLabel,tn);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:Hu(Xt)}),ms.resetAfterFormatted??ms.resetAtFormatted?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:ms.resetAfterFormatted??ms.resetAtFormatted}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Gs==="-"?"":Gs})]}),s.jsx($o,{percent:tn,tonePercent:ms.usedPercent,className:"h-1.5",expectedMarkerPercent:Hs}),sn?s.jsx(Bo,{paceInfo:sn,compact:!0}):null]},`${Fe.providerId}-${Xt}`)}),Fe.modelFamilies&&Fe.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:Fe.modelFamilies.map(Xt=>{const tn=(et[Fe.providerId]??[]).includes(Xt.familyId??"other");return s.jsxs(wr,{open:tn,onOpenChange:()=>ct(Fe.providerId,Xt.familyId??"other"),children:[s.jsxs(Rr,{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:Xt.familyLabel}),tn?s.jsx(ks,{className:"h-4 w-4 text-muted-foreground"}):s.jsx($n,{className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(jr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Xt.models.map(([sn,Hs])=>{const Gs=K==="remaining"?Hs.remainingPercent:Hs.usedPercent,nn=Oo(Hs.usedPercent,Hs.resetAt,Hs.windowSeconds),pr=nn?.dailyAllocationPercent!=null?K==="remaining"?100-oa(nn.elapsedRatio):oa(nn.elapsedRatio):null,lr=Fo(Hs.valueLabel,Gs);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:Yl(sn)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:lr==="-"?"":lr})]}),s.jsx($o,{percent:Gs,tonePercent:Hs.usedPercent,className:"h-1.5",expectedMarkerPercent:pr}),nn?s.jsx(Bo,{paceInfo:nn,compact:!0}):null]},`${Fe.providerId}-${sn}`)})})})]},Xt.familyId??"other")})})]})]},Fe.providerId))})]})]})})]}),e?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:e,className:me(xt,"relative",r&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(Ei,{className:"h-5 w-5"})})}),s.jsx(It,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Kn=me("header-safe-area relative z-10",ee&&"border-b border-border/50","bg-background");return s.jsx("header",{ref:ne,className:Kn,style:{"--padding-scale":"1"},children:ee?Fr():Rn()})};function j0(){}const dp=180,up=640,N0=110,S0=t=>{const e=nt.c(44),{isOpen:n,isMobile:r,children:a}=t,{t:i}=ut(),o=De(k0),c=De(C0),d=De(I0),p=De(A0),[m,u]=l.useState(null),[f,y]=l.useState(!1),h=l.useRef(null),b=l.useRef(0),x=l.useRef(o||300),g=Math.min(up,Math.max(dp,o||300));let w,v;e[0]!==n?(w=()=>{n||(u(null),y(!1))},v=[n],e[0]=n,e[1]=w,e[2]=v):(w=e[1],v=e[2]),l.useEffect(w,v);let S,P;e[3]!==c||e[4]!==r||e[5]!==n?(S=()=>{if(r||!n||!c)return;const oe=()=>{const ge=h.current?.parentElement?.getBoundingClientRect().height;if(!ge||ge<=0)return;const ne=Math.max(0,Math.round(ge));u(E=>E===ne?E:ne)};oe();const ee=h.current?.parentElement;if(!ee)return;const ae=new ResizeObserver(oe);return ae.observe(ee),()=>{ae.disconnect()}},P=[c,r,n],e[3]=c,e[4]=r,e[5]=n,e[6]=S,e[7]=P):(S=e[6],P=e[7]),l.useEffect(S,P);let j,C;if(e[8]!==c||e[9]!==r||e[10]!==f||e[11]!==d||e[12]!==p?(j=()=>{if(r||!f||c)return;const oe=ae=>{const ge=b.current-ae.clientY,ne=Math.min(up,Math.max(dp,x.current+ge));d(ne)},ee=()=>{y(!1),De.getState().bottomTerminalHeight<=N0&&p(!1)};return window.addEventListener("pointermove",oe),window.addEventListener("pointerup",ee,{once:!0}),()=>{window.removeEventListener("pointermove",oe),window.removeEventListener("pointerup",ee)}},C=[c,r,f,d,p],e[8]=c,e[9]=r,e[10]=f,e[11]=d,e[12]=p,e[13]=j,e[14]=C):(j=e[13],C=e[14]),l.useEffect(j,C),r)return null;const I=n?c?Math.max(0,m??g):g:0,R=n&&c;let k;e[15]!==I||e[16]!==c||e[17]!==n?(k=oe=>{!n||c||(y(!0),b.current=oe.clientY,x.current=I,oe.preventDefault())},e[15]=I,e[16]=c,e[17]=n,e[18]=k):k=e[18];const A=k,N=R?"absolute inset-x-0 bottom-0 z-40":"relative",D=f?"transition-none":"transition-[height] duration-300 ease-in-out",T=!n&&"border-t-0";let M;e[19]!==T||e[20]!==N||e[21]!==D?(M=me("flex overflow-hidden border-t border-border bg-sidebar",N,D,T),e[19]=T,e[20]=N,e[21]=D,e[22]=M):M=e[22];let $;e[23]!==I||e[24]!==R?($=R?{top:"var(--oc-header-height, 48px)"}:{height:`${I}px`,minHeight:`${I}px`,maxHeight:`${I}px`},e[23]=I,e[24]=R,e[25]=$):$=e[25];const F=!n||!c&&I===0;let _;e[26]!==A||e[27]!==c||e[28]!==n||e[29]!==f||e[30]!==i?(_=n&&!c&&s.jsx("div",{className:me("absolute left-0 top-0 z-20 h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",f&&"bg-[var(--interactive-border)]"),onPointerDown:A,role:"separator","aria-orientation":"horizontal","aria-label":i("terminalView.bottomDock.resizeAria")}),e[26]=A,e[27]=c,e[28]=n,e[29]=f,e[30]=i,e[31]=_):_=e[31];const O=!n&&"pointer-events-none select-none opacity-0";let L;e[32]!==O?(L=me("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]=L):L=e[33];const K=!n;let B;e[34]!==a||e[35]!==L||e[36]!==K?(B=s.jsx("div",{className:L,"aria-hidden":K,children:a}),e[34]=a,e[35]=L,e[36]=K,e[37]=B):B=e[37];let re;return e[38]!==M||e[39]!==$||e[40]!==F||e[41]!==_||e[42]!==B?(re=s.jsxs("section",{ref:h,className:M,style:$,"aria-hidden":F,children:[_,B]}),e[38]=M,e[39]=$,e[40]=F,e[41]=_,e[42]=B,e[43]=re):re=e[43],re};function k0(t){return t.bottomTerminalHeight}function C0(t){return t.isBottomTerminalExpanded}function I0(t){return t.setBottomTerminalHeight}function A0(t){return t.setBottomTerminalOpen}const qd=280,mp=280,pp=500,P0=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:a}=ut(),i=De(S=>S.sidebarWidth),o=De(S=>S.setSidebarWidth),[c,d]=l.useState(!1),p=l.useRef(0),m=l.useRef(i||qd),u=l.useRef(null),f=l.useRef(null),y=l.useRef(null),h=l.useCallback(S=>Math.min(pp,Math.max(mp,S)),[]),b=l.useCallback(S=>{const P=y.current;P&&P.style.setProperty("--oc-left-sidebar-width",`${S}px`)},[]);if(l.useEffect(()=>{e&&c&&d(!1)},[e,c]),l.useEffect(()=>{c||(u.current=null,f.current=null)},[c]),e)return null;const x=t?Math.min(pp,Math.max(mp,i||qd)):0,g=S=>{if(t){try{S.currentTarget.setPointerCapture(S.pointerId)}catch{}f.current=S.pointerId,d(!0),p.current=S.clientX,m.current=x,u.current=x,b(x),S.preventDefault()}},w=S=>{if(e||!c||f.current!==S.pointerId)return;const P=S.clientX-p.current,j=h(m.current+P);u.current!==j&&(u.current=j,b(j))},v=S=>{if(f.current!==S.pointerId||e)return;try{S.currentTarget.releasePointerCapture(S.pointerId)}catch{}const P=h(u.current??x);f.current=null,u.current=null,d(!1),o(P)};return s.jsxs("aside",{ref:y,className:me("relative flex h-full overflow-hidden border-r border-border/40","bg-sidebar",c?"transition-none":"transition-[width] duration-300 ease-in-out",!t&&"border-r-0",r),style:{width:"var(--oc-left-sidebar-width)",minWidth:"var(--oc-left-sidebar-width)",maxWidth:"var(--oc-left-sidebar-width)","--oc-left-sidebar-width":`${c?u.current??x:x}px`,overflowX:"clip"},"aria-hidden":!t||x===0,children:[t&&s.jsx("div",{className:me("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",c&&"bg-[var(--interactive-border)]"),onPointerDown:g,onPointerMove:w,onPointerUp:v,onPointerCancel:v,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.leftPanelAria")}),s.jsx("div",{className:me("relative z-10 flex h-full flex-col transition-opacity duration-300 ease-in-out",c&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(on,{children:n})})})]})},Zg=420,hp=400,fp=860,D0=({isOpen:t,children:e,className:n,onTopActionsHostChange:r})=>{const{t:a}=ut(),i=De(R=>R.rightSidebarWidth),o=De(R=>R.setRightSidebarWidth),c=l.useMemo(()=>Pn(),[]),d=l.useMemo(()=>jn(),[]),p=fc(),[m,u]=l.useState(!1),f=l.useRef(0),y=l.useRef(i||420),h=l.useRef(null),b=l.useRef(null),x=l.useRef(null),g=l.useCallback(R=>Math.min(fp,Math.max(hp,R)),[]),w=l.useCallback(R=>{const k=x.current;k&&k.style.setProperty("--oc-right-sidebar-width",`${R}px`)},[]),v=t?Math.min(fp,Math.max(hp,i||Zg)):0,S=R=>{if(t){try{R.currentTarget.setPointerCapture(R.pointerId)}catch{}b.current=R.pointerId,u(!0),f.current=R.clientX,y.current=v,h.current=v,w(v),R.preventDefault()}},P=R=>{if(!m||b.current!==R.pointerId)return;const k=f.current-R.clientX,A=g(y.current+k);h.current!==A&&(h.current=A,w(A))},j=R=>{if(b.current!==R.pointerId)return;try{R.currentTarget.releasePointerCapture(R.pointerId)}catch{}const k=g(h.current??v);b.current=null,h.current=null,u(!1),o(k)};l.useEffect(()=>{m||(h.current=null,b.current=null)},[m]),l.useEffect(()=>{t||r?.(null)},[t,r]);const C=l.useCallback(async R=>{const k=R.target;k.closest(".app-region-no-drag")||k.closest("button, a, input, select, textarea")||R.button===0&&c&&await mg()},[c]),I=l.useMemo(()=>{if(!(c||d))return{paddingLeft:"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",...p?{paddingTop:"var(--oc-safe-area-top, 0px)"}:null}},[c,p,d]);return s.jsxs("aside",{ref:x,className:me("relative flex h-full overflow-hidden border-l border-border/40","bg-sidebar",m?"transition-none":"transition-[width] duration-300 ease-in-out",!t&&"border-l-0",n),style:{width:"var(--oc-right-sidebar-width)",minWidth:"var(--oc-right-sidebar-width)",maxWidth:"var(--oc-right-sidebar-width)","--oc-right-sidebar-width":`${m?h.current??v:v}px`,overflowX:"clip"},"aria-hidden":!t||v===0,children:[t?s.jsx("div",{onMouseDown:C,className:me("app-region-drag absolute inset-x-0 top-0 z-20 flex items-center justify-end px-3","h-[var(--oc-header-height,56px)]"),style:I,"aria-hidden":!0,children:s.jsx("div",{ref:r,className:"app-region-no-drag flex items-center gap-1"})}):null,t&&s.jsx("div",{className:me("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",m&&"bg-[var(--interactive-border)]"),onPointerDown:S,onPointerMove:P,onPointerUp:j,onPointerCancel:j,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.rightPanelAria")}),s.jsx("div",{className:me("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",m&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:t?{paddingTop:"var(--oc-header-height, 56px)"}:void 0,"aria-hidden":!t,children:t?e:null})]})},T0=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),M0=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=T0.format(t);return e.endsWith(".0")?e.slice(0,-2):e},qo=({providerId:t,modelId:e,onChange:n,className:r,allowedProviderIds:a,placeholder:i})=>{const{t:o}=ut(),{isReady:c,isUnavailable:d}=pg(),p=yt(E=>E.providers),m=yt(E=>E.modelsMetadata),u=De(E=>E.isMobile),f=De(E=>E.hiddenModels),y=De(E=>E.toggleFavoriteModel),h=De(E=>E.isFavoriteModel),b=De(E=>E.addRecentModel),{favoriteModelsList:x,recentModelsList:g}=hg(),{isMobile:w}=dn(),v=u||w,[S,P]=l.useState(!1),[j,C]=l.useState(new Set),[I,R]=l.useState(!1),[k,A]=l.useState(""),[N,D]=l.useState(0),T=l.useRef([]),M=l.useMemo(()=>!Array.isArray(a)||a.length===0?null:new Set(a),[a]),$=l.useMemo(()=>(M?p.filter(z=>M.has(String(z.id))):p).map(z=>{const H=(Array.isArray(z.models)?z.models:[]).filter(te=>{const ce=typeof te?.id=="string"?te.id:"";return!f.some(Se=>Se.providerID===String(z.id)&&Se.modelID===ce)});return{...z,models:H}}).filter(z=>z.models.length>0),[p,M,f]),F=()=>P(!1),_=E=>{C(z=>{const J=new Set(z);return J.has(E)?J.delete(E):J.add(E),J})};l.useEffect(()=>{I||(A(""),D(0))},[I]),l.useEffect(()=>{D(0)},[k]);const O=E=>{const z=E?.name||E?.id||"",J=String(z);return J.length>40?J.substring(0,37)+"...":J},L=(E,z)=>{const J=`${E}/${z}`;return m.get(J)},K=(E,z)=>{n(E,z),E&&z&&b(E,z),R(!1)},B=(E,z)=>{if(!k.trim())return!0;const J=k.toLowerCase();return E.toLowerCase().includes(J)||z.toLowerCase().includes(J)},re=(E,z,J,H,te,ce)=>{const Se=L(z,J),pe=M0(Se?.limit?.context),we=t===z&&e===J,W=h(z,J),ue=H==="fav"||H==="recent";return s.jsxs(Lt,{ref:Y=>{T.current[te]=Y},className:me("group flex items-center gap-2",ce&&"bg-interactive-selection"),onSelect:()=>K(z,J),onMouseEnter:()=>D(te),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[ue&&s.jsx(Vn,{providerId:z,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:O(E)}),pe?s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:pe}):null]}),s.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[we&&s.jsx(Zs,{className:"h-4 w-4 text-primary"}),s.jsx("button",{onClick:Y=>{Y.preventDefault(),Y.stopPropagation(),y(z,J)},className:me("model-favorite-button flex h-4 w-4 items-center justify-center hover:text-primary/80",W?"text-primary":"text-muted-foreground"),"aria-label":o(W?"settings.agents.modelSelector.actions.unfavorite":"settings.agents.modelSelector.actions.favorite"),title:o(W?"settings.agents.modelSelector.actions.removeFromFavorites":"settings.agents.modelSelector.actions.addToFavorites"),children:W?s.jsx(ho,{className:"h-3.5 w-3.5"}):s.jsx(Nl,{className:"h-3.5 w-3.5"})})]})]},`${H}-${z}-${J}`)},oe=x.filter(({model:E,providerID:z})=>{if(M&&!M.has(z))return!1;const H=p.find(ce=>ce.id===z)?.name||z,te=O(E);return B(te,H)}),ee=g.filter(({model:E,providerID:z})=>{if(M&&!M.has(z))return!1;const H=p.find(ce=>ce.id===z)?.name||z,te=O(E);return B(te,H)}),ae=$.map(E=>{const J=(Array.isArray(E.models)?E.models:[]).filter(H=>{const te=O(H);return B(te,E.name||E.id||"")});return{...E,models:J}}).filter(E=>E.models.length>0),ge=oe.length>0||ee.length>0||ae.length>0,ne=()=>v?s.jsx(Vr,{open:S,onClose:F,title:o("settings.agents.modelSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[x.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:o("settings.agents.modelSelector.section.favorites")}),s.jsx("div",{className:"border-t border-border/20",children:x.map(({model:E,providerID:z,modelID:J})=>{const H=z===t&&J===e;return s.jsxs("div",{className:me("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",H?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{K(z,J),F()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Vn,{providerId:z,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:O(E)})]})}),s.jsx("button",{onClick:te=>{te.preventDefault(),te.stopPropagation(),y(z,J)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-primary hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":o("settings.agents.modelSelector.actions.unfavorite"),children:s.jsx(ho,{className:"h-4 w-4"})})]},`fav-mobile-${z}-${J}`)})})]}),g.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:o("settings.agents.modelSelector.section.recents")}),s.jsx("div",{className:"border-t border-border/20",children:g.map(({model:E,providerID:z,modelID:J})=>{const H=z===t&&J===e;return s.jsxs("div",{className:me("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",H?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{K(z,J),F()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Vn,{providerId:z,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:O(E)})]})}),s.jsx("button",{onClick:te=>{te.preventDefault(),te.stopPropagation(),y(z,J)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-muted-foreground/50 hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":o("settings.agents.modelSelector.actions.favorite"),children:s.jsx(Nl,{className:"h-4 w-4"})})]},`recent-mobile-${z}-${J}`)})})]}),$.map(E=>{const z=Array.isArray(E.models)?E.models:[];if(z.length===0)return null;const J=E.id===t,H=j.has(E.id);return s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)]",children:[s.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-1.5 px-2 py-1.5 text-left",onClick:()=>_(E.id),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Vn,{providerId:E.id,className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:E.name}),J&&s.jsx("span",{className:"typography-micro text-primary/80",children:o("settings.agents.modelSelector.badge.current")})]}),H?s.jsx(ks,{className:"h-3 w-3 text-muted-foreground"}):s.jsx($n,{className:"h-3 w-3 text-muted-foreground"})]}),H&&s.jsx("div",{className:"border-t border-border/20",children:z.map(te=>{const ce=E.id===t&&te.id===e;return s.jsxs("div",{className:me("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",ce?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{K(E.id,te.id),F()},children:s.jsx("span",{className:"font-medium truncate",children:O(te)})}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[s.jsx("button",{onClick:Se=>{Se.preventDefault(),Se.stopPropagation(),y(E.id,te.id)},className:me("flex h-8 w-8 items-center justify-center active:scale-95 touch-manipulation hover:text-primary/80",h(E.id,te.id)?"text-primary":"text-muted-foreground/50"),"aria-label":h(E.id,te.id)?o("settings.agents.modelSelector.actions.unfavorite"):o("settings.agents.modelSelector.actions.favorite"),children:h(E.id,te.id)?s.jsx(ho,{className:"h-4 w-4"}):s.jsx(Nl,{className:"h-4 w-4"})}),ce&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]})]},te.id)})})]},E.id)}),s.jsx("button",{type:"button",className:"flex w-full items-center justify-between rounded-lg border border-border/40 bg-[var(--surface-elevated)] px-2 py-1.5 text-left",onClick:()=>{K("",""),F()},children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:i||o("settings.agents.modelSelector.noModelOptional")})})]})}):null;return s.jsxs(s.Fragment,{children:[v?s.jsxs("button",{type:"button",onClick:c?()=>P(!0):void 0,disabled:!c,className:me("flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-[var(--surface-elevated)] px-2 py-1.5 text-left",!c&&"opacity-60 cursor-not-allowed",r),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[c?t?s.jsx(Vn,{providerId:t,className:"h-3.5 w-3.5"}):s.jsx(Fi,{className:"h-3 w-3 text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(ts,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]}),c&&s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t&&e?`${t}/${e}`:i||o("settings.agents.modelSelector.selectPlaceholder")})]}),s.jsx(ks,{className:"h-3 w-3 text-muted-foreground"})]}):s.jsxs(_s,{open:c&&I,onOpenChange:c?R:void 0,children:[s.jsx($s,{asChild:!0,children:s.jsxs("div",{className:me("border-input data-[placeholder]:text-muted-foreground flex items-center justify-between gap-2 rounded-lg border bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover data-[popup-open]:bg-interactive-active h-6 w-fit",r),children:[c?s.jsxs(s.Fragment,{children:[t?s.jsxs(s.Fragment,{children:[s.jsx(Vn,{providerId:t,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx(Fi,{className:"h-3 w-3 text-primary/60 hidden"})]}):s.jsx(Fi,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-foreground",children:t&&e?`${t}/${e}`:i||o("settings.agents.modelSelector.notSelected")})]}):s.jsxs(s.Fragment,{children:[s.jsx(ts,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]}),s.jsx(ks,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsx(Bs,{className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",align:"start",children:(()=>{const E=[];oe.forEach(({model:te,providerID:ce,modelID:Se})=>{E.push({model:te,providerID:ce,modelID:Se,section:"fav"})}),ee.forEach(({model:te,providerID:ce,modelID:Se})=>{E.push({model:te,providerID:ce,modelID:Se,section:"recent"})}),ae.forEach(te=>{te.models.forEach(ce=>{E.push({model:ce,providerID:te.id,modelID:ce.id,section:"provider"})})});const z=E.length,J=te=>{if(te.stopPropagation(),te.key==="ArrowDown"){te.preventDefault();const ce=(N+1)%Math.max(1,z);D(ce),setTimeout(()=>{T.current[ce]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(te.key==="ArrowUp"){te.preventDefault();const ce=(N-1+Math.max(1,z))%Math.max(1,z);D(ce),setTimeout(()=>{T.current[ce]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(te.key==="Enter"){te.preventDefault();const ce=E[N];ce&&K(ce.providerID,ce.modelID)}else te.key==="Escape"&&(te.preventDefault(),R(!1))};let H=0;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"p-2 border-b border-border/40",children:s.jsxs("div",{className:"relative",children:[s.jsx(Jn,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Bt,{type:"text",placeholder:o("settings.agents.modelSelector.searchPlaceholder"),value:k,onChange:te=>A(te.target.value),onKeyDown:J,className:"pl-8 h-8 typography-meta",autoFocus:!0})]})}),s.jsx(Ps,{outerClassName:"max-h-[min(400px,calc(100dvh-12rem))] flex-1",children:s.jsxs("div",{className:"p-1",children:[s.jsxs(Lt,{className:me("flex items-center gap-2"),onSelect:()=>K("",""),children:[s.jsx(Is,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-muted-foreground",children:i||o("settings.agents.modelSelector.notSelected")}),!t&&!e&&s.jsx(Zs,{className:"h-4 w-4 text-primary ml-auto"})]}),s.jsx(Ln,{}),!ge&&k&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:o("settings.agents.modelSelector.state.noModelsFound")}),oe.length>0&&s.jsxs("div",{children:[s.jsxs(No,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(ho,{className:"h-4 w-4 text-primary"}),o("settings.agents.modelSelector.section.favorites")]}),oe.map(({model:te,providerID:ce,modelID:Se})=>{const pe=H++;return re(te,ce,Se,"fav",pe,N===pe)})]}),ee.length>0&&s.jsxs("div",{children:[oe.length>0&&s.jsx(Ln,{}),s.jsxs(No,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(Nu,{className:"h-4 w-4"}),o("settings.agents.modelSelector.section.recent")]}),ee.map(({model:te,providerID:ce,modelID:Se})=>{const pe=H++;return re(te,ce,Se,"recent",pe,N===pe)})]}),(oe.length>0||ee.length>0)&&ae.length>0&&s.jsx(Ln,{}),ae.map((te,ce)=>s.jsxs("div",{children:[ce>0&&s.jsx(Ln,{}),s.jsxs(No,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(Vn,{providerId:te.id,className:"h-4 w-4 flex-shrink-0"}),te.name]}),te.models.map(Se=>{const pe=H++;return re(Se,te.id,Se.id,"provider",pe,N===pe)})]},te.id))]})}),s.jsx("div",{className:"px-3 pt-1 pb-1.5 border-t border-border/40 typography-micro text-muted-foreground",children:o("settings.agents.modelSelector.keyboardHints")})]})})()})]}),ne()]})},Sc=t=>{const e=nt.c(34),{agentName:n,onChange:r,className:a,filter:i}=t,{t:o}=ut(),{isReady:c,isUnavailable:d}=pg(),p=yt(R0),m=Ki(E0),u=Ki(F0),f=yt(O0);let y;e:{if(Array.isArray(p)&&p.length>0){y=p;break e}let F;e[0]!==m?(F=Array.isArray(m)?m:[],e[0]=m,e[1]=F):F=e[1],y=F}const h=y;let b;if(e[2]!==i||e[3]!==h){const F=Ev(h);b=i?F.filter(i):F,e[2]=i,e[3]=h,e[4]=b}else b=e[4];const x=b,g=De(L0),{isMobile:w}=dn(),v=g||w,[S,P]=l.useState(!1);let j,C;e[5]!==u||e[6]!==f||e[7]!==h.length?(j=()=>{h.length>0||(f(),u())},C=[h.length,f,u],e[5]=u,e[6]=f,e[7]=h.length,e[8]=j,e[9]=C):(j=e[8],C=e[9]),l.useEffect(j,C);let I;e[10]===Symbol.for("react.memo_cache_sentinel")?(I=()=>P(!1),e[10]=I):I=e[10];const R=I;let k;e[11]!==r?(k=F=>{r(F)},e[11]=r,e[12]=k):k=e[12];const A=k;let N;e[13]!==n||e[14]!==x||e[15]!==A||e[16]!==v||e[17]!==S||e[18]!==o?(N=()=>v?s.jsx(Vr,{open:S,onClose:R,title:o("settings.commands.agentSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",className:me("flex w-full items-center justify-between rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",n?"text-foreground":"bg-primary/10 text-primary"),onClick:()=>{A(""),R()},children:[s.jsx("span",{className:me("typography-meta",n?"text-muted-foreground":"font-medium"),children:o("settings.commands.agentSelector.notSelected")}),!n&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]}),x.map(F=>{const _=F.name===n;return s.jsxs("button",{type:"button",className:me("flex w-full items-center justify-between rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",_?"bg-primary/10 text-primary":"text-foreground"),onClick:()=>{A(F.name),R()},children:[s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-meta font-medium",children:F.name}),F.description&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:F.description})]}),_&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]},F.name)})]})}):null,e[13]=n,e[14]=x,e[15]=A,e[16]=v,e[17]=S,e[18]=o,e[19]=N):N=e[19];const D=N;let T;e[20]!==n||e[21]!==x||e[22]!==a||e[23]!==A||e[24]!==v||e[25]!==c||e[26]!==d||e[27]!==o?(T=v?s.jsxs("button",{type:"button",onClick:c?()=>P(!0):void 0,disabled:!c,className:me("flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",!c&&"opacity-60 cursor-not-allowed",a),children:[s.jsx("div",{className:"flex items-center gap-2",children:c?s.jsxs(s.Fragment,{children:[s.jsx(Jr,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:n||o("settings.commands.agentSelector.selectAgentPlaceholder")})]}):s.jsxs(s.Fragment,{children:[s.jsx(ts,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]})}),s.jsx(ks,{className:"h-3 w-3 text-muted-foreground"})]}):c?s.jsxs(_s,{children:[s.jsx($s,{asChild:!0,children:s.jsxs("div",{className:me("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 cursor-pointer hover:bg-interactive-hover/30 h-6 w-fit",a),children:[s.jsx(Jr,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap",children:n||o("settings.commands.agentSelector.notSelected")}),s.jsx(ks,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsxs(Bs,{className:"max-w-[300px]",children:[s.jsx(Lt,{className:"typography-meta",onSelect:()=>A(""),children:s.jsx("span",{className:"text-muted-foreground",children:o("settings.commands.agentSelector.notSelected")})}),x.map(F=>s.jsx(Lt,{className:"typography-meta",onSelect:()=>A(F.name),children:s.jsx("span",{className:"font-medium",children:F.name})},F.name))]})]}):s.jsxs("div",{className:me("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 h-6 w-fit opacity-60",a),children:[s.jsx(ts,{className:"h-3 w-3 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]}),e[20]=n,e[21]=x,e[22]=a,e[23]=A,e[24]=v,e[25]=c,e[26]=d,e[27]=o,e[28]=T):T=e[28];let M;e[29]!==D?(M=D(),e[29]=D,e[30]=M):M=e[30];let $;return e[31]!==T||e[32]!==M?($=s.jsxs(s.Fragment,{children:[T,M]}),e[31]=T,e[32]=M,e[33]=$):$=e[33],$};function R0(t){return t.agents}function E0(t){return t.agents}function F0(t){return t.loadAgents}function O0(t){return t.loadAgents}function L0(t){return t.isMobile}const gp=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent}),$0=t=>{const e=nt.c(38),{value:n,options:r,disabled:a,onChange:i}=t,{t:o}=ut();let c;e[0]!==o||e[1]!==n?(c=n||o("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[0]=o,e[1]=n,e[2]=c):c=e[2];const d=c,p=a?"cursor-not-allowed opacity-60":"cursor-pointer hover:bg-interactive-hover/30";let m;e[3]!==p?(m=me("flex h-6 w-fit items-center gap-1.5 rounded-lg border border-border/20 bg-interactive-selection/20 px-2",p),e[3]=p,e[4]=m):m=e[4];let u;e[5]!==d?(u=s.jsx("span",{className:"typography-micro whitespace-nowrap font-medium capitalize",children:d}),e[5]=d,e[6]=u):u=e[6];let f;e[7]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(ks,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),e[7]=f):f=e[7];let y;e[8]!==m||e[9]!==u?(y=s.jsxs("div",{className:m,children:[u,f]}),e[8]=m,e[9]=u,e[10]=y):y=e[10];const h=y;if(a)return h;let b;e[11]!==h?(b=s.jsx($s,{asChild:!0,children:h}),e[11]=h,e[12]=b):b=e[12];let x;e[13]!==i?(x=()=>i(""),e[13]=i,e[14]=x):x=e[14];const g=!n&&"text-primary";let w;e[15]!==g?(w=me("font-medium",g),e[15]=g,e[16]=w):w=e[16];let v;e[17]!==o?(v=o("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[17]=o,e[18]=v):v=e[18];let S;e[19]!==w||e[20]!==v?(S=s.jsx("span",{className:w,children:v}),e[19]=w,e[20]=v,e[21]=S):S=e[21];let P;e[22]!==S||e[23]!==x?(P=s.jsx(Lt,{className:"typography-meta",onSelect:x,children:S}),e[22]=S,e[23]=x,e[24]=P):P=e[24];let j;if(e[25]!==i||e[26]!==r||e[27]!==n){let R;e[29]!==i||e[30]!==n?(R=k=>s.jsx(Lt,{className:"typography-meta",onSelect:()=>i(k),children:s.jsx("span",{className:me("font-medium capitalize",n===k&&"text-primary"),children:k})},k),e[29]=i,e[30]=n,e[31]=R):R=e[31],j=r.map(R),e[25]=i,e[26]=r,e[27]=n,e[28]=j}else j=e[28];let C;e[32]!==P||e[33]!==j?(C=s.jsxs(Bs,{align:"start",className:"max-w-[220px]",children:[P,j]}),e[32]=P,e[33]=j,e[34]=C):C=e[34];let I;return e[35]!==C||e[36]!==b?(I=s.jsxs(_s,{children:[b,C]}),e[35]=C,e[36]=b,e[37]=I):I=e[37],I};function ex(t){const e=nt.c(99),{t:n}=ut(),{open:r,onOpenChange:a,target:i,projectDirectory:o,submitting:c,onConfirm:d}=t,p=c===void 0?!1:c,m=yt(q0),u=yt(G0),f=Ki(H0),y=yt(K0),h=yt(W0),b=yt(U0),x=yt(z0),g=yt(V0);let w;e[0]!==g||e[1]!==b||e[2]!==h||e[3]!==x?(w=()=>gp({providerID:h,modelID:b,variant:x,agent:g}),e[0]=g,e[1]=b,e[2]=h,e[3]=x,e[4]=w):w=e[4];const[v,S]=l.useState(w);let P,j;e[5]!==f||e[6]!==u||e[7]!==m||e[8]!==r||e[9]!==o?(P=()=>{r&&(m({directory:o}),u({directory:o}),f())},j=[r,m,u,f,o],e[5]=f,e[6]=u,e[7]=m,e[8]=r,e[9]=o,e[10]=P,e[11]=j):(P=e[10],j=e[11]),l.useEffect(P,j);let C,I;e[12]!==g||e[13]!==b||e[14]!==h||e[15]!==x||e[16]!==r?(C=()=>{r&&S(gp({providerID:h,modelID:b,variant:x,agent:g}))},I=[r,h,b,x,g],e[12]=g,e[13]=b,e[14]=h,e[15]=x,e[16]=r,e[17]=C,e[18]=I):(C=e[17],I=e[18]),l.useEffect(C,I);let R,k;e[19]!==v.modelID||e[20]!==v.providerID||e[21]!==r||e[22]!==y?(R=()=>{if(!r||y.length===0)return;const he=y.find(Pe=>Pe.id===v.providerID)??y[0],je=Array.isArray(he?.models)?he.models:[],be=je.some(Pe=>Pe.id===v.modelID),fe=je[0]?.id??"";he?.id===v.providerID&&be||S(Pe=>({...Pe,providerID:he?.id??"",modelID:be?Pe.modelID:fe,variant:""}))},k=[r,y,v.providerID,v.modelID],e[19]=v.modelID,e[20]=v.providerID,e[21]=r,e[22]=y,e[23]=R,e[24]=k):(R=e[23],k=e[24]),l.useEffect(R,k);const A=_0;let N;if(e[25]!==v.modelID||e[26]!==v.providerID||e[27]!==y){let he;e[29]!==v.providerID?(he=be=>be.id===v.providerID,e[29]=v.providerID,e[30]=he):he=e[30],N=y.find(he)?.models?.find(be=>be.id===v.modelID),e[25]=v.modelID,e[26]=v.providerID,e[27]=y,e[28]=N}else N=e[28];const D=N;let T;e[31]!==D?(T=D?.variants?Object.keys(D.variants):[],e[31]=D,e[32]=T):T=e[32];const M=T,$=M.length>0;let F,_;e[33]!==v.variant||e[34]!==$?(F=()=>{$||!v.variant||S(B0)},_=[$,v.variant],e[33]=v.variant,e[34]=$,e[35]=F,e[36]=_):(F=e[35],_=e[36]),l.useEffect(F,_);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 L=O;let K;e[40]!==L||e[41]!==v||e[42]!==d||e[43]!==p?(K=()=>{!L||p||d(v)},e[40]=L,e[41]=v,e[42]=d,e[43]=p,e[44]=K):K=e[44];const B=K;let re,oe;e[45]!==B||e[46]!==r?(re=()=>{if(!r)return;const he=je=>{(je.metaKey||je.ctrlKey)&&je.key==="Enter"&&(je.preventDefault(),B())};return window.addEventListener("keydown",he),()=>window.removeEventListener("keydown",he)},oe=[r,B],e[45]=B,e[46]=r,e[47]=re,e[48]=oe):(re=e[47],oe=e[48]),l.useEffect(re,oe);let ee;e[49]!==n||e[50]!==i?(ee=n(i==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=i,e[51]=ee):ee=e[51];const ae=ee;let ge;e[52]!==a||e[53]!==p?(ge=he=>{p||a(he)},e[52]=a,e[53]=p,e[54]=ge):ge=e[54];let ne;e[55]!==ae?(ne=s.jsx(Cs,{children:s.jsx(js,{children:ae})}),e[55]=ae,e[56]=ne):ne=e[56];let E;e[57]===Symbol.for("react.memo_cache_sentinel")?(E=(he,je)=>{S(be=>({...be,providerID:he,modelID:je,variant:""}))},e[57]=E):E=e[57];let z;e[58]!==v.modelID||e[59]!==v.providerID?(z=s.jsx(qo,{providerId:v.providerID,modelId:v.modelID,onChange:E}),e[58]=v.modelID,e[59]=v.providerID,e[60]=z):z=e[60];const J=!$;let H;e[61]===Symbol.for("react.memo_cache_sentinel")?(H=he=>S(je=>({...je,variant:he})),e[61]=H):H=e[61];let te;e[62]!==v.variant||e[63]!==J||e[64]!==M?(te=s.jsx($0,{value:v.variant,options:M,disabled:J,onChange:H}),e[62]=v.variant,e[63]=J,e[64]=M,e[65]=te):te=e[65];let ce;e[66]===Symbol.for("react.memo_cache_sentinel")?(ce=he=>S(je=>({...je,agent:he})),e[66]=ce):ce=e[66];let Se;e[67]!==v.agent?(Se=s.jsx(Sc,{agentName:v.agent,filter:A,onChange:ce}),e[67]=v.agent,e[68]=Se):Se=e[68];let pe;e[69]!==z||e[70]!==te||e[71]!==Se?(pe=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[z,te,Se]}),e[69]=z,e[70]=te,e[71]=Se,e[72]=pe):pe=e[72];let we;e[73]!==a?(we=()=>a(!1),e[73]=a,e[74]=we):we=e[74];let W;e[75]!==n?(W=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[75]=n,e[76]=W):W=e[76];let ue;e[77]!==p||e[78]!==we||e[79]!==W?(ue=s.jsx(ve,{variant:"ghost",size:"sm",onClick:we,disabled:p,children:W}),e[77]=p,e[78]=we,e[79]=W,e[80]=ue):ue=e[80];const Y=!L||p;let le;e[81]!==p||e[82]!==n?(le=n(p?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[81]=p,e[82]=n,e[83]=le):le=e[83];let Z;e[84]!==B||e[85]!==Y||e[86]!==le?(Z=s.jsx(ve,{size:"sm",onClick:B,disabled:Y,children:le}),e[84]=B,e[85]=Y,e[86]=le,e[87]=Z):Z=e[87];let Ie;e[88]!==ue||e[89]!==Z?(Ie=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[ue,Z]}),e[88]=ue,e[89]=Z,e[90]=Ie):Ie=e[90];let Ne;e[91]!==ne||e[92]!==pe||e[93]!==Ie?(Ne=s.jsxs(vs,{className:"max-w-lg",children:[ne,pe,Ie]}),e[91]=ne,e[92]=pe,e[93]=Ie,e[94]=Ne):Ne=e[94];let X;return e[95]!==r||e[96]!==ge||e[97]!==Ne?(X=s.jsx(ws,{open:r,onOpenChange:ge,children:Ne}),e[95]=r,e[96]=ge,e[97]=Ne,e[98]=X):X=e[98],X}function B0(t){return{...t,variant:""}}function _0(t){return fg(t.mode)}function V0(t){return t.currentAgentName||""}function z0(t){return t.currentVariant||""}function U0(t){return t.currentModelId}function W0(t){return t.currentProviderId}function K0(t){return t.providers}function H0(t){return t.loadAgents}function G0(t){return t.loadAgents}function q0(t){return t.loadProviders}const Q0=async(t,e)=>{const n=await Bv(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},J0=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,Y0=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:a})=>{const{t:i}=ut(),[o,c]=l.useState(!1),[d,p]=l.useState(""),[m,u]=l.useState([]),[f,y]=l.useState(""),[h,b]=l.useState(null),[x,g]=l.useState(()=>new Set),[w,v]=l.useState([]),[S,P]=l.useState(null),[j,C]=l.useState(!1),[I,R]=l.useState(0),k=l.useRef(!1),A=l.useRef(""),N=Ht(X=>X.currentSessionId),D=Ht(X=>X.createSession),T=Ht(X=>X.initializeNewOpenChamberSession),M=Ht(X=>X.sendMessage),$=Ht(X=>X.setCurrentSession),F=Hi(X=>X.setPendingInputText),_=qs(X=>X.currentDirectory),O=De(X=>X.openContextPanelTab),L=De(X=>X.setActiveMainTab),K=De(X=>X.setSessionSwitcherOpen),B=l.useCallback(async(X,he)=>{if(!t)return!1;const je=await Fv(t,{notes:X,todos:he});return je||q.error(i("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),je},[t,i]);l.useEffect(()=>{if(!t){p(""),u([]),v([]),y(""),g(new Set);return}let X=!1;return c(!0),(async()=>{try{const he=await Ov(t),je=await Promise.all(he.plans.map(be=>Q0(be,i("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(X)return;p(he.notes),u(he.todos),v(je),A.current=he.notes,k.current=!0,y(""),g(new Set)}catch{X||(q.error(i("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),p(""),u([]),v([]),A.current="",k.current=!0)}finally{X||c(!1)}})(),()=>{X=!0}},[I,t,i]),l.useEffect(()=>{if(!t)return;const X=he=>{const je=he.detail;je?.projectId&&je.projectId!==t.id||R(be=>be+1)};return window.addEventListener("openchamber:project-plan-saved",X),window.addEventListener("openchamber:project-notes-updated",X),()=>{window.removeEventListener("openchamber:project-plan-saved",X),window.removeEventListener("openchamber:project-notes-updated",X)}},[t]);const re=l.useCallback(()=>{A.current=d,B(d,m)},[d,B,m]);l.useEffect(()=>{if(!t||!k.current||d===A.current)return;const X=window.setTimeout(()=>{A.current=d,B(d,m)},400);return()=>{window.clearTimeout(X)}},[d,B,t,m]);const oe=l.useCallback(()=>{const X=f.trim();if(!X)return;const he=[...m,{id:J0(),text:X.slice(0,sl),completed:!1,createdAt:Date.now()}];u(he),y(""),B(d,he)},[f,d,B,m]),ee=l.useCallback(X=>{g(he=>{const je=new Set(he);return je.has(X)?je.delete(X):je.add(X),je})},[]),ae=l.useCallback((X,he)=>{const je=m.map(be=>be.id===X?{...be,completed:he}:be);u(je),B(d,je)},[d,B,m]),ge=l.useCallback(X=>{const he=m.filter(je=>je.id!==X);u(he),B(d,he)},[d,B,m]),ne=l.useCallback(()=>{const X=m.filter(he=>!he.completed);X.length!==m.length&&(u(X),B(d,X))},[d,B,m]),E=f.slice(0,sl),z=m.reduce((X,he)=>X+(he.completed?1:0),0),J=l.useCallback(()=>{L("chat"),K(!1)},[L,K]),H=l.useCallback((X,he)=>{!t||h||P({kind:"session",todoId:X,todoText:he})},[t,h]),te=l.useCallback(X=>{if(!N){q.error(i("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}J();const he=`\`\`\`md
|
|
4
|
+
${X}
|
|
5
|
+
\`\`\``;F(he,"append"),q.success(i("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[N,r,J,F,i]),ce=l.useCallback((X,he)=>{if(!(!t||h)){if(!n){q.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}P({kind:"worktree",todoId:X,todoText:he})}},[n,t,h,i]),Se=l.useCallback(async X=>{if(!t||!S)return;const he=await zn("plan.todo.visible",{todo_text:S.todoText}),be=[{synthetic:!0,text:await zn("plan.todo.instructions",{todo_text:S.todoText})}];C(!0),b(S.todoId);try{J();let fe=null,Pe=t.path;if(S.kind==="worktree"){if(!n){q.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const G=await gg(t.path,xg());if(!G?.id)return;fe=G.id,Pe=null}else{const G=await D(void 0,t.path,null);if(!G?.id){q.error(i("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}fe=G.id,Pe=G.directory??t.path,T(G.id,yt.getState().agents??[])}if(!fe)return;const Be=xc.getState();Be.saveSessionModelSelection(fe,X.providerID,X.modelID),X.agent.trim()&&(Be.saveSessionAgentSelection(fe,X.agent),Be.saveAgentModelForSession(fe,X.agent,X.providerID,X.modelID),Be.saveAgentModelVariantForSession(fe,X.agent,X.providerID,X.modelID,X.variant||void 0)),$(fe,Pe),await M(he,X.providerID,X.modelID,X.agent.trim()||void 0,void 0,void 0,be,X.variant||void 0),q.success(S.kind==="worktree"?i("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):i("rightSidebar.contextNotesTodo.toast.sentToNewSession")),P(null),r?.()}catch(fe){const Pe=fe instanceof Error?fe.message:void 0;q.error(i("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),Pe?{description:Pe}:void 0)}finally{C(!1),b(null)}},[n,D,T,r,S,t,J,M,$,i]),pe=l.useRef(null),[we,W]=l.useState(!1),[ue,Y]=l.useState(null),le=l.useCallback(async X=>{if(!(!t||ue)){Y(X);try{if(!await Lv(t,X)){q.error(i("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}v(je=>je.filter(be=>be.id!==X)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}}))}finally{Y(null)}}},[ue,t,i]),Z=l.useCallback(()=>{!t||we||pe.current?.click()},[we,t]),Ie=l.useCallback(async X=>{if(!(!t||!X)){W(!0);try{const he=await X.text();if(!he.trim()){q.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const je=X.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await $v(t,he,je)){q.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),q.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(he){const je=he instanceof Error?he.message:void 0;q.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),je?{description:je}:void 0)}finally{W(!1)}}},[t,i]),Ne=l.useCallback(X=>{const he=t?.path?.trim(),je=_?.trim()||he;je&&O(je,{mode:"plan",targetPath:X.path,dedupeKey:X.path,label:X.title})},[_,O,t]);return t?s.jsxs("div",{className:me("w-full min-w-0 space-y-3 p-3",a),children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"min-w-0 truncate typography-ui-label font-semibold text-foreground",title:t.path,children:i("rightSidebar.contextNotesTodo.notes.title",{project:e?.trim()||t.path.split("/").filter(Boolean).pop()||t.path})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d.length,"/",km]})]}),s.jsx(An,{value:d,onChange:X=>p(X.target.value.slice(0,km)),onBlur:re,placeholder:i("rightSidebar.contextNotesTodo.notes.placeholder"),className:"min-h-28 max-h-80 resize-none",useScrollShadow:!0,scrollShadowSize:56,disabled:o})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:m.length===1?i("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:m.length}):i("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:m.length})}),s.jsx("button",{type:"button",onClick:ne,disabled:o||z===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:[E.length,"/",sl]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Bt,{value:E,onChange:X=>y(X.target.value.slice(0,sl)),onKeyDown:X=>{X.key==="Enter"&&(X.preventDefault(),oe())},placeholder:i("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:o,className:"h-8"}),s.jsx("button",{type:"button",onClick:oe,disabled:o||E.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(zs,{className:"h-4 w-4"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",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("ul",{className:"divide-y divide-border/50",children:m.map(X=>{const he=x.has(X.id);return s.jsxs("li",{className:"flex items-start gap-1.5 px-2.5 py-1.5",children:[s.jsx("div",{className:"flex h-6 items-center",children:s.jsx(bs,{checked:X.completed,onChange:je=>ae(X.id,je),ariaLabel:i("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:X.text})})}),s.jsx("button",{type:"button",onClick:()=>ee(X.id),className:me("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-6 text-foreground",he?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",X.completed&&"text-muted-foreground line-through"),title:he?void 0:X.text,"aria-label":he?i("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:X.text}):i("rightSidebar.contextNotesTodo.todo.actions.expand",{text:X.text}),children:X.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>ge(X.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:X.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:X.text}),children:s.jsx(an,{className:"h-3.5 w-3.5"})}),s.jsxs(_s,{children:[s.jsx($s,{asChild:!0,children:s.jsx("button",{type:"button",disabled:h===X.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:X.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.send",{text:X.text}),children:s.jsx(Sb,{className:"h-3.5 w-3.5"})})}),s.jsxs(Bs,{align:"end",className:"w-56",children:[s.jsx(Lt,{onClick:()=>te(X.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx(Lt,{onClick:()=>H(X.id,X.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx(Lt,{onClick:()=>{ce(X.id,X.text)},disabled:!n,children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]},X.id)})})})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.plans.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:w.length===1?i("rightSidebar.contextNotesTodo.plans.filesSingle",{count:w.length}):i("rightSidebar.contextNotesTodo.plans.filesPlural",{count:w.length})})]}),s.jsx("input",{ref:pe,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:X=>{const he=X.target.files?.[0]??null;Ie(he),X.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:Z,disabled:!t||we,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(zs,{className:"h-3.5 w-3.5"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:w.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.plans.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:w.map(X=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>Ne(X),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:X.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(X.createdAt).toLocaleDateString()})]}),s.jsx("button",{type:"button",onClick:()=>{le(X.id)},disabled:ue===X.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:X.title}),children:s.jsx(an,{className:"h-3.5 w-3.5"})})]},X.id))})})]}),s.jsx(ex,{open:S!==null,onOpenChange:X=>{!X&&!j&&P(null)},target:S?.kind??"session",projectDirectory:t?.path??null,submitting:j,onConfirm:Se})]}):s.jsx("div",{className:me("w-full min-w-0 p-3",a),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.empty.selectProject")})})},tx=12,X0=[{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"}],Z0=t=>{const e=nt.c(18),{isActive:n,burstKey:r,className:a,durationMs:i,bursts:o,onComplete:c}=t,d=r===void 0?0:r,p=i===void 0?900:i,m=o===void 0?X0:o,u=Oe.useRef(!1);let f,y;e[0]!==n||e[1]!==c?(f=()=>{!n&&u.current&&c?.(),n&&(u.current=!0)},y=[n,c],e[0]=n,e[1]=c,e[2]=f,e[3]=y):(f=e[2],y=e[3]),Oe.useEffect(f,y);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=Array.from({length:tx},eN),e[4]=h):h=e[4];const b=h;if(!n)return null;let x;e[5]!==a?(x=me("fireworks-overlay pointer-events-none",a),e[5]=a,e[6]=x):x=e[6];let g;if(e[7]!==d||e[8]!==m||e[9]!==p){let v;e[11]!==d||e[12]!==p?(v=S=>{const P={"--burst-delay":`${S.delay}ms`,"--burst-x":`${S.x}%`,"--burst-y":`${S.y}%`,"--firework-color":`var(${S.colorVar})`,"--firework-duration":`${p}ms`};return s.jsx("div",{className:"firework-burst",style:P,children:b.map((j,C)=>{const I=j.x*S.radius,R=j.y*S.radius,k={"--translate-x":`${I}px`,"--translate-y":`${R}px`,"--particle-delay":`${j.delay}ms`,color:`var(${S.colorVar})`};return s.jsx("span",{className:"firework-particle",style:k},`${S.id}-${C}-${d}`)})},`${S.id}-${d}`)},e[11]=d,e[12]=p,e[13]=v):v=e[13],g=m.map(v),e[7]=d,e[8]=m,e[9]=p,e[10]=g}else g=e[10];let w;return e[14]!==d||e[15]!==x||e[16]!==g?(w=s.jsx("div",{className:x,"aria-hidden":"true","data-burst-key":d,children:g}),e[14]=d,e[15]=x,e[16]=g,e[17]=w):w=e[17],w};function eN(t,e){const n=Math.PI*2*e/tx;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const tN=t=>{const e=nt.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,a=r===void 0?3400:r;let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={isActive:!1,cycle:0},e[2]=i):i=e[2];const[o,c]=Oe.useState(i),d=Oe.useRef(null);let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=p):p=e[3];const m=p;let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{m(),c(sN)},e[4]=u):u=e[4];const f=u;let y;e[5]!==a?(y=()=>{m(),c(nN),d.current=window.setTimeout(()=>{c(rN),d.current=null},a)},e[5]=a,e[6]=y):y=e[6];const h=y;let b,x;e[7]===Symbol.for("react.memo_cache_sentinel")?(b=()=>()=>m(),x=[m],e[7]=b,e[8]=x):(b=e[7],x=e[8]),Oe.useEffect(b,x);let g;return e[9]!==o.cycle||e[10]!==o.isActive||e[11]!==h?(g={isActive:o.isActive,burstKey:o.cycle,triggerFireworks:h,dismissFireworks:f},e[9]=o.cycle,e[10]=o.isActive,e[11]=h,e[12]=g):g=e[12],g};function sN(t){return t.isActive?{...t,isActive:!1}:t}function nN(t){return{isActive:!0,cycle:t.cycle+1}}function rN(t){return t.isActive?{...t,isActive:!1}:t}const sx=l.createContext(void 0),aN=t=>{const e=nt.c(10),{children:n}=t,{isActive:r,burstKey:a,triggerFireworks:i,dismissFireworks:o}=tN();let c;e[0]!==o||e[1]!==i?(c={triggerFireworks:i,dismissFireworks:o},e[0]=o,e[1]=i,e[2]=c):c=e[2];const d=c;let p;e[3]!==a||e[4]!==r?(p=s.jsx(Z0,{isActive:r,burstKey:a}),e[3]=a,e[4]=r,e[5]=p):p=e[5];let m;return e[6]!==n||e[7]!==p||e[8]!==d?(m=s.jsxs(sx.Provider,{value:d,children:[n,p]}),e[6]=n,e[7]=p,e[8]=d,e[9]=m):m=e[9],m},iN=()=>{const t=l.useContext(sx);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},ar=Nr()(to(_o((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 Kv();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 Wv();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 Uv();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=yr()?.settings;if(a)try{const o=(await a.load())?.settings||{};r=n(o.defaultGitIdentityId)}catch{}}if(r===null)try{const a=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(a.ok){const i=await a.json().catch(()=>null);r=n(i?.defaultGitIdentityId)}}catch{}return t({defaultGitIdentityId:r}),!0}catch(r){return console.error("Failed to load default git identity setting:",r),!1}},setDefaultGitIdentityId:async n=>{try{const r=typeof n=="string"?n.trim():"",a=r.length>0?r:"";return await As({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 zv(r),await e().loadProfiles(),!0}catch(r){return console.error("Failed to create git identity profile:",r),!1}},updateProfile:async(n,r)=>{try{const a=e().profiles.find(o=>o.id===n);if(!a)throw new Error("Profile not found");const i={...a,...r};return await Vv(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 _v(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:dc(()=>va()),partialize:t=>({selectedProfileId:t.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=ar);function oi(t){const e=nt.c(12);let n,r,a;e[0]!==t?({className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a):(n=e[1],r=e[2],a=e[3]);let i;e[4]!==a?(i={color:"var(--surface-elevated-foreground)",...a},e[4]=a,e[5]=i):i=e[5];let o;e[6]!==n?(o=me("flex h-full w-full flex-col overflow-hidden rounded-xl",n),e[6]=n,e[7]=o):o=e[7];let c;return e[8]!==r||e[9]!==i||e[10]!==o?(c=s.jsx(ui,{"data-slot":"command",style:i,className:o,...r}),e[8]=r,e[9]=i,e[10]=o,e[11]=c):c=e[11],c}const Ia=Oe.forwardRef((t,e)=>{const n=nt.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(Jn,{className:"size-4 shrink-0 opacity-50"}),n[3]=i):i=n[3];let o;n[4]!==r?(o=me("placeholder:text-muted-foreground flex h-8 w-full rounded-lg bg-transparent py-2 typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",r),n[4]=r,n[5]=o):o=n[5];let c;return n[6]!==a||n[7]!==e||n[8]!==o?(c=s.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-8 items-center gap-2 border-b px-3",children:[i,s.jsx(ui.Input,{ref:e,"data-slot":"command-input",className:o,...a})]}),n[6]=a,n[7]=e,n[8]=o,n[9]=c):c=n[9],c});Ia.displayName="CommandInput";function li(t){const e=nt.c(14);let n,r,a,i,o;e[0]!==t?({className:r,children:n,scrollbarClassName:o,disableHorizontal:a,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i,e[5]=o):(n=e[1],r=e[2],a=e[3],i=e[4],o=e[5]);let c;e[6]!==r?(c=me("scroll-py-1 overflow-x-hidden h-full min-h-0",r),e[6]=r,e[7]=c):c=e[7];const d=o??"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",p=a??!0;let m;return e[8]!==n||e[9]!==i||e[10]!==c||e[11]!==d||e[12]!==p?(m=s.jsx(Ps,{as:ui.List,"data-slot":"command-list",outerClassName:"max-h-[min(600px,calc(100vh-10rem))] overflow-x-hidden p-0 w-full h-full min-h-0",className:c,scrollbarClassName:d,disableHorizontal:p,...i,children:n}),e[8]=n,e[9]=i,e[10]=c,e[11]=d,e[12]=p,e[13]=m):m=e[13],m}function ci(t){const e=nt.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(ui.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 Qn(t){const e=nt.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=me("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(ui.Group,{"data-slot":"command-group",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function Ka(t){const e=nt.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=me("bg-border -mx-1 h-px",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(ui.Separator,{"data-slot":"command-separator",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function On(t){const e=nt.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=me("data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(ui.Item,{"data-slot":"command-item",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function oN(t){const e=nt.c(12);let n,r,a,i;if(e[0]!==t){const{className:c,...d}=t,p=cN,m=typeof d.children=="string"?d.children:"",u=m?m.split("+").map(lN).filter(Boolean):[];n="command-shortcut",e[5]!==c?(r=me("text-muted-foreground ml-auto flex items-center gap-1 typography-meta",c),e[5]=c,e[6]=r):r=e[6],a=d,i=u.length>0?u.map((f,y)=>s.jsxs(Oe.Fragment,{children:[y>0&&s.jsx("span",{className:"opacity-60 text-xs",children:"+"}),p(f)]},`${f}-${y}`)):d.children,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i}else n=e[1],r=e[2],a=e[3],i=e[4];let o;return e[7]!==n||e[8]!==r||e[9]!==a||e[10]!==i?(o=s.jsx("span",{"data-slot":n,className:r,...a,children:i}),e[7]=n,e[8]=r,e[9]=a,e[10]=i,e[11]=o):o=e[11],o}function lN(t){return t.trim()}function cN(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(Vo,{className:"size-3.5"}):e==="shift"||e==="⇧"?s.jsx(Wl,{className:"size-3.5"}):s.jsx("span",{className:"text-xs font-medium",children:t})}const Qd=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},dN=t=>{const e=Qd(t);if(!e)return null;const r=e.indexOf("/.git/worktrees/");return r>0&&e.slice(0,r)||null};function uN(t,e,n){const r=nt.c(5),[a,i]=l.useState();let o,c;return r[0]!==n||r[1]!==t||r[2]!==e?(o=()=>{if(e){i(void 0);return}if(!t){i(void 0);return}i(void 0);let d=!1;return(async()=>{const[p,m]=await Promise.all([Js("git rev-parse --absolute-git-dir",t),Js("git rev-parse --show-toplevel",t)]);if(d||!p.success||!m.success)return;const u=Qd((p.stdout||"").trim()),f=dN(u);if(!f)return;const y=Qd((m.stdout||"").trim());if(!y||y===f)return;const h=n||"",b=y.split("/").filter(Boolean).pop()||y;i({source:"sdk",path:y,projectDirectory:f,branch:h,label:h||b,name:b,worktreeRoot:y,worktreeStatus:"ready",headState:h?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},c=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=o,r[4]=c):(o=r[3],c=r[4]),l.useEffect(o,c),e??a}const ir=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},Xi=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),da=t=>!!t.success,kc=t=>(t.stdout||"").trim(),Ja=t=>(t.stderr||"").trim();async function mN(t){const n=((await Js("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 pN(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),a=(await mN(t.repoRoot)).filter(o=>o.branchRef===e).map(o=>o.path).filter(o=>o&&!n.has(o)),i=[];for(const o of a){const c=await Js("git status --porcelain",o);kc(c)||i.push(o)}return i}async function nx(t,e){for(const n of e)await Js("git reset --hard",n).catch(()=>{})}async function hN(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await Js(`git show-ref --verify --quiet ${ir(`refs/heads/${n}`)}`,t);if(da(r))return n;if(n.startsWith("remotes/")){const o=n.slice(8).split("/"),c=o[0]||"origin",d=o.slice(1).join("/");if(d)return await Js(`git branch --track ${ir(d)} ${ir(`${c}/${d}`)}`,t),d}const a=await Js(`git show-ref --verify --quiet ${ir(`refs/remotes/origin/${n}`)}`,t);return da(a)&&await Js(`git branch --track ${ir(n)} ${ir(`origin/${n}`)}`,t),n}async function io(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 hN(e,r),i=await Js(`git cherry ${ir(a)} ${ir(n)}`,e),o=Xi(i.stdout),c=new Set;for(const u of o){const f=u.match(/^\+\s+([0-9a-f]{7,40})\b/i);f&&c.add(f[1])}const d=await Js(`git rev-list --reverse ${ir(`${a}..${n}`)}`,e),m=Xi(d.stdout).filter(u=>c.has(u));return{repoRoot:e,sourceBranch:n,targetBranch:a,commits:m}}async function fN(t,e){const n=await Js('mkdir -p "$HOME/.config/openchamber/tmp"',t);if(!da(n))throw new Error(Ja(n)||"Failed to create temp directory parent");const r=await Js('mktemp -d "$HOME/.config/openchamber/tmp/oc-integrate-XXXXXX"',t),a=kc(r);if(!a)throw new Error(Ja(r)||"Failed to create temp directory");const i=await Js(`git worktree add --force ${ir(a)} ${ir(e)}`,t);if(!da(i))throw new Error(Ja(i)||"Failed to create temp worktree");return a}async function ec(t,e){await Js(`git worktree remove --force ${ir(e)}`,t).catch(()=>{}),await Js("git worktree prune",t).catch(()=>{})}async function gN(t){const e=await Js("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=kc(e);if(!n)return;await Js("git fetch",t);const r=await Js(`git merge --ff-only ${ir(n)}`,t);if(!da(r))throw new Error(Ja(r)||"Fast-forward failed")}async function tc(t){const e=await Js("git status --porcelain",t),n=await Js("git diff --name-only --diff-filter=U",t),r=await Js("git diff",t),a=await Js("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),i=await Js("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:Xi(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:a.stdout||a.stderr||"",currentPatch:i.stdout||i.stderr||""}}async function xN(t){return tc(t)}async function bN(t){const e=await Js("git rev-parse --verify --quiet CHERRY_PICK_HEAD",t);return da(e)}async function yN(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await fN(t.repoRoot,t.targetBranch);let n=[];try{await gN(e);const r=await Js("git status --porcelain",e);if(kc(r))throw new Error("Target branch has local changes; abort integration and retry");const a=await pN({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const i=n[0],o=await Js(`git cherry-pick ${ir(i)}`,e);if(da(o)){n.shift();continue}const c=await Js("git diff --name-only --diff-filter=U",e);if(Xi(c.stdout).length>0){const p=await tc(e);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:e,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:a,remainingCommits:n,currentCommit:i},details:p}}throw new Error(Ja(o)||"Cherry-pick failed")}return await ec(t.repoRoot,e),await nx(t.repoRoot,a).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await ec(t.repoRoot,e).catch(()=>{}),r}}async function vN(t){await Js("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await ec(t.repoRoot,t.tempWorktreePath)}async function wN(t){const e=await Js("git cherry-pick --continue",t.tempWorktreePath);if(!da(e)){const i=await Js("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(Xi(i.stdout).length>0){const c=await tc(t.tempWorktreePath);return{kind:"conflict",state:t,details:c}}throw new Error(Ja(e)||"Cherry-pick continue failed")}const n=t.tempWorktreePath,r=[...t.remainingCommits];r.length>0&&r[0]===t.currentCommit&&r.shift();const a=[...r];for(;a.length>0;){const i=a[0],o=await Js(`git cherry-pick ${ir(i)}`,n);if(da(o)){a.shift();continue}const c=await Js("git diff --name-only --diff-filter=U",n);if(Xi(c.stdout).length>0){const p=await tc(n);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:n,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:t.cleanTargetWorktrees,remainingCommits:a,currentCommit:i},details:p}}throw new Error(Ja(o)||"Cherry-pick failed")}return await ec(t.repoRoot,t.tempWorktreePath),await nx(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:t.remainingCommits.length}}const jN=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:a,refreshKey:i,onRefresh:o})=>{const{t:c}=ut(),d=Ht(O=>O.currentSessionId),p=De(O=>O.setActiveMainTab),[m,u]=Oe.useState(!1),f=Oe.useRef(null),[y,h]=Oe.useState(a);Oe.useEffect(()=>{h(a)},[a]),Oe.useEffect(()=>{if(m){const O=setTimeout(()=>{f.current?.focus()},0);return()=>clearTimeout(O)}},[m]);const b=!!(t&&e&&y&&y!=="HEAD"&&e!==y),[x,g]=Oe.useState({kind:"idle"}),[w,v]=Oe.useState(!1),[S,P]=Oe.useState([]),j=Oe.useMemo(()=>d?`openchamber.integrate.conflict:${d}`:null,[d]);Oe.useEffect(()=>{if(!j||typeof window>"u")return;const O=window.localStorage.getItem(j);if(!O)return;let L=!1;try{const K=JSON.parse(O);if(!K?.tempWorktreePath||K.repoRoot!==t){window.localStorage.removeItem(j);return}(async()=>{const B=await bN(K.tempWorktreePath).catch(()=>!1);if(L)return;if(!B){window.localStorage.removeItem(j);return}const re=await xN(K.tempWorktreePath).catch(()=>null);L||re&&g({kind:"conflict",state:K,details:re})})()}catch{window.localStorage.removeItem(j)}return()=>{L=!0}},[j,t]),Oe.useEffect(()=>{if(!b){g({kind:"idle"});return}let O=!1;return g({kind:"loading"}),(async()=>{try{const L=await io({repoRoot:t,sourceBranch:e,targetBranch:y});if(O)return;if(g({kind:"ready",plan:L}),L.commits.length>0){const re=L.commits.slice(-50).reverse().map(ge=>JSON.stringify(ge)).join(" "),ee=((await Js(`git show -s --format=%H%x09%h%x09%s ${re}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),ae=[];for(const ge of ee){const[ne,E,z]=ge.split(" ");!ne||!E||ae.push({sha:ne,short:E,subject:z||""})}O||(P(ae),v(!1))}else O||(P([]),v(!1))}catch{O||g({kind:"idle"})}})(),()=>{O=!0}},[b,t,e,y,i]);const C=Oe.useCallback(O=>{d&&Ht.getState().setWorktreeMetadata(d,{...n,createdFromBranch:O})},[d,n]),I=Ht(O=>O.openNewSessionDraft),R=Oe.useCallback(async O=>{const L=await zn("git.integrate.cherrypick.resolve.visible",{current_commit:O.state.currentCommit,target_branch:O.state.targetBranch}),K=await zn("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}),B=`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:L,instructionsText:K,payloadText:B}},[]),k=Hi(O=>O.setPendingInputText),A=Hi(O=>O.setPendingSyntheticParts),N=Oe.useCallback(async(O,L)=>{const K=await R(O);if(L){I({directoryOverride:O.state.tempWorktreePath,initialPrompt:K.visibleText,syntheticParts:[{text:K.instructionsText,synthetic:!0},{text:K.payloadText,synthetic:!0}]}),p("chat");return}if(!d){q.error(c("gitView.integrate.noActiveSession"),{description:c("gitView.integrate.noActiveSessionDescription")});return}k(K.visibleText,"replace"),A([{text:K.instructionsText,synthetic:!0},{text:K.payloadText,synthetic:!0}]),p("chat")},[d,p,R,I,k,A,c]),D=Oe.useCallback(async()=>{if(x.kind==="ready"){if(x.plan.commits.length===0){q.message(c("gitView.integrate.noCommitsToMoveToast"));return}g({kind:"running",plan:x.plan});try{const O=await yN(x.plan);if(O.kind==="success"){q.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 L=await io(x.plan);g({kind:"ready",plan:L}),o?.();return}O.kind==="conflict"&&(q.error(c("gitView.integrate.cherryPickConflictToast"),{description:c("gitView.integrate.cherryPickConflictDescription")}),g({kind:"conflict",state:O.state,details:O.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify(O.state)))}catch(O){const L=O instanceof Error?O.message:String(O);q.error(c("gitView.integrate.failedToMoveToast"),{description:L});const K=await io({repoRoot:t,sourceBranch:e,targetBranch:y}).catch(()=>null);g(K?{kind:"ready",plan:K}:{kind:"idle"})}}},[x,o,t,e,y,j,c]),T=Oe.useCallback(async()=>{if(x.kind==="conflict")try{await vN(x.state),q.message(c("gitView.integrate.cherryPickAbortedToast")),j&&typeof window<"u"&&window.localStorage.removeItem(j)}finally{const O=await io({repoRoot:t,sourceBranch:e,targetBranch:y}).catch(()=>null);g(O?{kind:"ready",plan:O}:{kind:"idle"})}},[x,t,e,y,j,c]),M=Oe.useCallback(async()=>{if(x.kind==="conflict")try{const O=await wN(x.state);if(O.kind==="success"){q.success(c("gitView.integrate.cherryPickFinishedToast"));const L=await io({repoRoot:t,sourceBranch:e,targetBranch:y}).catch(()=>null);g(L?{kind:"ready",plan:L}:{kind:"idle"}),j&&typeof window<"u"&&window.localStorage.removeItem(j),o?.();return}O.kind==="conflict"&&(g({kind:"conflict",state:O.state,details:O.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify(O.state)))}catch(O){const L=O instanceof Error?O.message:String(O);q.error(c("gitView.integrate.cherryPickContinueFailedToast"),{description:L})}},[x,t,e,y,o,j,c]);return!t||!e?null:s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(kb,{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(ts,{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," → ",y]})]}),s.jsx("div",{className:"flex-1"}),s.jsxs(_s,{open:m,onOpenChange:u,children:[s.jsx($s,{asChild:!0,children:s.jsxs(ve,{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:y}),s.jsx(ks,{className:"size-4 opacity-60"})]})}),s.jsx(Bs,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(oi,{className:"h-full min-h-0",children:[s.jsx(Ia,{ref:f,placeholder:c("gitView.branch.searchPlaceholder")}),s.jsxs(li,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(ci,{children:c("gitView.branch.empty")}),s.jsx(Qn,{heading:c("gitView.branch.localBranches"),children:r.map(O=>s.jsx(On,{value:O,onSelect:()=>{h(O),C(O),u(!1)},children:O},O))})]})]})})]}),x.kind==="ready"?s.jsx(ve,{size:"sm",onClick:()=>{D()},disabled:!b||x.plan.commits.length===0,children:c("gitView.integrate.move")}):x.kind==="loading"?s.jsx(ve,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.checking")}):x.kind==="running"?s.jsx(ve,{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,")"]})]}),S.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(w?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),s.jsxs("div",{className:"space-y-1",children:[(w?S:S.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)),S.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.previewUnavailable")}),x.plan.commits.length>S.length&&s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c("gitView.integrate.showingFirstCommits",{count:S.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(ve,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{T()},children:c("gitView.operation.abort")}),s.jsxs(ve,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!d,onClick:()=>{N({state:x.state,details:x.details},!1)},children:[s.jsx(Td,{className:"size-3.5"}),c("gitView.integrate.currentSession")]}),s.jsxs(ve,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{N({state:x.state,details:x.details},!0)},children:[s.jsx(Td,{className:"size-3.5"}),c("gitView.integrate.newSession")]}),s.jsx(ve,{size:"sm",className:"typography-meta",onClick:()=>{M()},children:c("gitView.operation.continue")})]})]})]})]})},NN=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),SN=({currentBranch:t,localBranches:e,remoteBranches:n,branchInfo:r,onCheckout:a,onCreate:i,remotes:o=[],disabled:c=!1})=>{const{t:d}=ut(),[p,m]=l.useState(!1),[u,f]=l.useState(""),[y,h]=l.useState(!1),[b,x]=l.useState(!1),[g,w]=l.useState(""),[v,S]=l.useState(!1),P=l.useRef(null),j=l.useCallback(F=>{F.stopPropagation()},[]),C=o.length>1,I=l.useMemo(()=>NN(g),[g]),R=l.useMemo(()=>{const F=u.toLowerCase();return F?e.filter(_=>_.toLowerCase().includes(F)):e},[u,e]),k=l.useMemo(()=>{const F=u.toLowerCase();return F?n.filter(_=>_.toLowerCase().includes(F)):n},[u,n]),A=F=>{if(F===t){m(!1);return}a(F),m(!1),f("")},N=()=>{h(!0),setTimeout(()=>P.current?.focus(),50)},D=async()=>{if(!(!I||v)){if(C){x(!0);return}S(!0);try{await i(I,o[0]),w(""),h(!1),m(!1)}finally{S(!1)}}},T=async F=>{if(!(!I||v)){S(!0);try{await i(I,F),w(""),h(!1),x(!1),m(!1)}finally{S(!1)}}},M=()=>{x(!1)},$=()=>{w(""),h(!1),x(!1)};return l.useEffect(()=>{p||(f(""),h(!1),x(!1),w(""))},[p]),s.jsxs(_s,{open:p,onOpenChange:m,children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx($s,{asChild:!0,children:s.jsxs(ve,{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(Qs,{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(ks,{className:"size-4 opacity-60"})]})})}),s.jsx(It,{sideOffset:8,children:d("gitView.branch.currentBranchTooltip")})]}),s.jsx(Bs,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:s.jsxs(oi,{className:"h-full min-h-0",children:[s.jsx(Ia,{placeholder:d("gitView.branch.searchPlaceholder"),value:u,onValueChange:f}),s.jsxs(li,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(ci,{children:d("gitView.branch.empty")}),s.jsx(Qn,{children:b?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:M,disabled:v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(Cb,{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:o.map(F=>s.jsxs("button",{type:"button",onClick:()=>T(F),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(ts,{className:"inline size-3 mr-1.5 animate-spin"}):null,F.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:F.pushUrl})]},F.name))})]}):y?s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[s.jsx("input",{ref:P,placeholder:d("gitView.branch.newBranchPlaceholder"),value:g,onChange:F=>w(F.target.value),onClick:F=>F.stopPropagation(),onKeyDown:F=>{j(F),F.key==="Enter"?(F.preventDefault(),D()):F.key==="Escape"&&(F.preventDefault(),$())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"button",onClick:D,disabled:!I||v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:v?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(zs,{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(Is,{className:"size-4"})})]}):s.jsxs(On,{onSelect:N,children:[s.jsx(zs,{className:"size-4"}),s.jsx("span",{children:d("gitView.branch.create")})]})}),s.jsx(Ka,{}),s.jsxs(Qn,{heading:d("gitView.branch.localBranches"),children:[R.map(F=>s.jsxs(On,{onSelect:()=>A(F),children:[s.jsxs("span",{className:"flex flex-1 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:F}),(r?.[F]?.ahead||r?.[F]?.behind)&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[r[F].ahead||0," ahead ·"," ",r[F].behind||0," behind"]})]}),t===F&&s.jsx("span",{className:"typography-micro text-primary",children:d("gitView.branch.currentBadge")})]},`local-${F}`)),R.length===0&&s.jsx(On,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noLocalBranches")})})]}),s.jsx(Ka,{}),s.jsxs(Qn,{heading:d("gitView.branch.remoteBranches"),children:[k.map(F=>s.jsx(On,{onSelect:()=>A(F),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:F})},`remote-${F}`)),k.length===0&&s.jsx(On,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noRemoteBranches")})})]})]})]})})]})},kN=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),CN=({currentBranch:t,onRename:e,showEditButton:n=!0})=>{const{t:r}=ut(),[a,i]=l.useState(!1),[o,c]=l.useState(t||""),[d,p]=l.useState(!1),m=l.useRef(null),u=()=>{!t||!e||(c(t),i(!0),setTimeout(()=>m.current?.focus(),0))},f=async()=>{if(!t||!e||!o.trim())return;const b=kN(o);if(b===t){i(!1);return}p(!0);try{await e(t,b),i(!1),c("")}finally{p(!1)}},y=()=>{i(!1),c("")},h=b=>{b.key==="Enter"?(b.preventDefault(),f()):b.key==="Escape"&&(b.preventDefault(),y())};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:b=>{b.preventDefault(),f()},children:[s.jsx(Qs,{className:"size-4 text-primary"}),s.jsx("input",{ref:m,value:o,onChange:b=>c(b.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:r("gitView.branch.namePlaceholder"),onKeyDown:h,autoFocus:!0}),s.jsx("button",{type:"submit",disabled:d,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:d?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(Zs,{className:"size-4"})}),s.jsx("button",{type:"button",onClick:y,disabled:d,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(Is,{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(Qs,{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(ve,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:u,title:r("gitView.branch.renameTitle"),children:s.jsx(ea,{className:"size-4"})})]})]})},IN=t=>{const e=nt.c(41),{syncAction:n,remotes:r,onFetch:a,onSync:i,onRemoveRemote:o,disabled:c,removingRemoteName:d,aheadCount:p,behindCount:m,trackingRemoteName:u,hasUncommittedChanges:f}=t,y=r===void 0?[]:r,h=d===void 0?null:d,b=p===void 0?0:p,x=m===void 0?0:m,g=f===void 0?!1:f,{t:w}=ut(),v=l.useRef(!1),S=!!h,P=y.find(W=>W.name===u)??y[0],j=x>0&&g,C=c||n!==null||S||!P||j,I=c||n!==null||S||y.length===0,R=b>0||x>0;let k;e[0]!==w?(k=w("gitView.sync.sync"),e[0]=w,e[1]=k):k=e[1];const A=x>0?`↓${x}`:null,N=b>0?`↑${b}`:null;let D;e[2]!==k||e[3]!==A||e[4]!==N?(D=[k,A,N].filter(Boolean),e[2]=k,e[3]=A,e[4]=N,e[5]=D):D=e[5];const T=D.join(" "),M=j?w("gitView.sync.commitOrStashTooltip"):P?R?w("gitView.sync.syncChangesTooltip",{ahead:b,behind:x}):w("gitView.sync.syncChanges"):w("gitView.sync.noRemoteTooltip"),$=()=>{P&&i(P)},F="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")?(_=me("inline-flex h-7 items-center gap-1.5 px-2 typography-ui-label font-medium text-foreground","transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[6]=_):_=e[6];let O;e[7]!==w?(O=w("gitView.sync.syncChanges"),e[7]=w,e[8]=O):O=e[8];let L;e[9]!==n?(L=n==="sync"?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(In,{className:"size-4"}),e[9]=n,e[10]=L):L=e[10];let K;e[11]!==T?(K=s.jsx("span",{className:"whitespace-nowrap tabular-nums",children:T}),e[11]=T,e[12]=K):K=e[12];let B;e[13]!==$||e[14]!==C||e[15]!==O||e[16]!==L||e[17]!==K?(B=s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:$,disabled:C,className:_,"aria-label":O,children:[L,K]})}),e[13]=$,e[14]=C,e[15]=O,e[16]=L,e[17]=K,e[18]=B):B=e[18];let re;e[19]!==M?(re=s.jsx(It,{sideOffset:8,children:M}),e[19]=M,e[20]=re):re=e[20];let oe;e[21]!==B||e[22]!==re?(oe=s.jsxs(St,{children:[B,re]}),e[21]=B,e[22]=re,e[23]=oe):oe=e[23];const ee=_s;let ae;e[24]===Symbol.for("react.memo_cache_sentinel")?(ae=me("inline-flex h-7 w-6 items-center justify-center border-l border-[var(--interactive-border)] text-muted-foreground","transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[24]=ae):ae=e[24];let ge;e[25]!==w?(ge=w("gitView.sync.moreActionsAria"),e[25]=w,e[26]=ge):ge=e[26];let ne;e[27]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsx(ks,{className:"size-4"}),e[27]=ne):ne=e[27];let E;e[28]!==I||e[29]!==ge?(E=s.jsx($s,{asChild:!0,children:s.jsx("button",{type:"button",className:ae,disabled:I,"aria-label":ge,children:ne})}),e[28]=I,e[29]=ge,e[30]=E):E=e[30];const z=Bs,J="start",H=-40,te="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",ce=y.map(W=>s.jsx(Lt,{onSelect:ue=>{if(v.current){ue.preventDefault(),v.current=!1;return}a(W)},children:s.jsxs("div",{className:"flex w-full items-center gap-2",children:[s.jsx(In,{className:"size-4 text-muted-foreground"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:w("gitView.sync.fetchFromRemote",{name:W.name})}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:W.fetchUrl})]})}),o&&W.name!==u?s.jsx(ve,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||S,onPointerDown:ue=>{v.current=!0,ue.preventDefault(),ue.stopPropagation()},onClick:ue=>{v.current=!0,ue.preventDefault(),ue.stopPropagation(),o(W)},"aria-label":w("gitView.header.removeRemoteAria",{name:W.name}),title:w("gitView.header.removeRemoteTitle",{name:W.name}),children:h===W.name?s.jsx(ts,{className:"size-3.5 animate-spin"}):s.jsx(Is,{className:"size-3.5"})}):null]})},W.name));let Se;e[31]!==z||e[32]!==ce?(Se=s.jsx(z,{align:J,alignOffset:H,className:te,children:ce}),e[31]=z,e[32]=ce,e[33]=Se):Se=e[33];let pe;e[34]!==ee||e[35]!==E||e[36]!==Se?(pe=s.jsxs(ee,{children:[E,Se]}),e[34]=ee,e[35]=E,e[36]=Se,e[37]=pe):pe=e[37];let we;return e[38]!==oe||e[39]!==pe?(we=s.jsxs("div",{className:F,children:[oe,pe]}),e[38]=oe,e[39]=pe,e[40]=we):we=e[40],we},AN={branch:Qs,briefcase:Cu,house:ku,graduation:Su,code:uc,heart:Lf,user:Yr},PN={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 rx(t){return t&&PN[t]||"var(--primary)"}const xp=t=>{const e=nt.c(8),{icon:n,className:r,colorToken:a}=t,i=AN[n??"branch"]??Yr;let o;e[0]!==a?(o=rx(a),e[0]=a,e[1]=o):o=e[1];let c;e[2]!==o?(c={color:o},e[2]=o,e[3]=c):c=e[3];let d;return e[4]!==i||e[5]!==r||e[6]!==c?(d=s.jsx(i,{className:r,style:c}),e[4]=i,e[5]=r,e[6]=c,e[7]=d):d=e[7],d},ax=t=>{const e=nt.c(35),{activeProfile:n,identities:r,onSelect:a,isApplying:i,iconOnly:o}=t,c=o===void 0?!1:o,{t:d}=ut(),p=i||r.length===0,m=n?.color;let u;e[0]!==m?(u=rx(m),e[0]=m,e[1]=u):u=e[1];let f;e[2]!==u?(f={color:u},e[2]=u,e[3]=f):f=e[3];let y;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==i?(y=i?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(xp,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=i,e[7]=y):y=e[7];let h;e[8]!==n?.name||e[9]!==c||e[10]!==d?(h=!c&&s.jsx("span",{className:"git-identity-label min-w-0 flex-1 truncate text-left",children:n?.name||d("gitView.header.noIdentity")}),e[8]=n?.name,e[9]=c,e[10]=d,e[11]=h):h=e[11];let b;e[12]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(ks,{className:"size-4 opacity-60"}),e[12]=b):b=e[12];let x;e[13]!==p||e[14]!==f||e[15]!==y||e[16]!==h?(x=s.jsx(kt,{asChild:!0,children:s.jsx($s,{asChild:!0,children:s.jsxs(ve,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-[15rem] justify-start gap-1.5 px-2 py-1 typography-ui-label",style:f,disabled:p,children:[y,h,b]})})}),e[13]=p,e[14]=f,e[15]=y,e[16]=h,e[17]=x):x=e[17];let g;e[18]!==d?(g=d("gitView.header.identityTooltip"),e[18]=d,e[19]=g):g=e[19];let w;e[20]!==g?(w=s.jsx(It,{sideOffset:8,children:g}),e[20]=g,e[21]=w):w=e[21];let v;e[22]!==w||e[23]!==x?(v=s.jsxs(St,{children:[x,w]}),e[22]=w,e[23]=x,e[24]=v):v=e[24];let S;e[25]!==n?.id||e[26]!==r||e[27]!==a||e[28]!==d?(S=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(C=>{const I=n?.id===C.id;return s.jsx(Lt,{onSelect:()=>a(C),children:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(xp,{icon:C.icon,colorToken:C.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:C.name}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:C.userEmail})]}),I?s.jsx(Zs,{className:"ml-auto size-4 text-foreground"}):null]})},C.id)}),e[25]=n?.id,e[26]=r,e[27]=a,e[28]=d,e[29]=S):S=e[29];let P;e[30]!==S?(P=s.jsx(Bs,{align:"end",className:"w-64",children:S}),e[30]=S,e[31]=P):P=e[31];let j;return e[32]!==v||e[33]!==P?(j=s.jsxs(_s,{children:[v,P]}),e[32]=v,e[33]=P,e[34]=j):j=e[34],j},DN=t=>{const e=nt.c(48),{status:n,localBranches:r,remoteBranches:a,branchInfo:i,syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,onCheckoutBranch:f,onCreateBranch:y,onRenameBranch:h,activeIdentityProfile:b,availableIdentities:x,onSelectIdentity:g,isApplyingIdentity:w,isWorktreeMode:v,onOpenHistory:S,actionTabItems:P,activeActionTab:j,onSelectActionTab:C}=t,{t:I}=ut();if(!n)return null;let R;e[0]!==S||e[1]!==I?(R=S?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0",onClick:S,children:s.jsx($f,{className:"size-4"})})}),s.jsx(It,{sideOffset:8,children:I("gitView.history.title")})]}):null,e[0]=S,e[1]=I,e[2]=R):R=e[2];let k;e[3]!==R?(k=s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:R}),e[3]=R,e[4]=k):k=e[4];const A=k,N=!n;let D;e[5]!==n.tracking?(D=n.tracking?.split("/")[0],e[5]=n.tracking,e[6]=D):D=e[6];const T=(n.files?.length??0)>0;let M;e[7]!==d||e[8]!==m||e[9]!==p||e[10]!==c||e[11]!==u||e[12]!==n.ahead||e[13]!==n.behind||e[14]!==o||e[15]!==N||e[16]!==D||e[17]!==T?(M=s.jsx(IN,{syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,disabled:N,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:D,hasUncommittedChanges:T}),e[7]=d,e[8]=m,e[9]=p,e[10]=c,e[11]=u,e[12]=n.ahead,e[13]=n.behind,e[14]=o,e[15]=N,e[16]=D,e[17]=T,e[18]=M):M=e[18];const $=M;let F;e[19]!==b||e[20]!==x||e[21]!==w||e[22]!==g?(F=s.jsx(ax,{activeProfile:b,identities:x,onSelect:g,isApplying:w,iconOnly:!0}),e[19]=b,e[20]=x,e[21]=w,e[22]=g,e[23]=F):F=e[23];const _=F;let O;e[24]!==i||e[25]!==v||e[26]!==r||e[27]!==f||e[28]!==y||e[29]!==h||e[30]!==a||e[31]!==c||e[32]!==n.current?(O=s.jsx("div",{className:"min-w-0 flex-1",children:v?s.jsx(CN,{currentBranch:n.current,onRename:h}):s.jsx(SN,{currentBranch:n.current,localBranches:r,remoteBranches:a,branchInfo:i,onCheckout:f,onCreate:y,remotes:c})}),e[24]=i,e[25]=v,e[26]=r,e[27]=f,e[28]=y,e[29]=h,e[30]=a,e[31]=c,e[32]=n.current,e[33]=O):O=e[33];let L;e[34]!==_||e[35]!==A?(L=s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[A,_]}),e[34]=_,e[35]=A,e[36]=L):L=e[36];let K;e[37]!==O||e[38]!==L?(K=s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[O,L]}),e[37]=O,e[38]=L,e[39]=K):K=e[39];let B;e[40]!==P||e[41]!==j||e[42]!==C||e[43]!==$?(B=P&&j&&C?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(zr,{items:P,activeId:j,onSelect:C,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),s.jsx("div",{className:"shrink-0",children:$})]}):null,e[40]=P,e[41]=j,e[42]=C,e[43]=$,e[44]=B):B=e[44];let re;return e[45]!==K||e[46]!==B?(re=s.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[K,B]}),e[45]=K,e[46]=B,e[47]=re):re=e[47],re},TN=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,uncommittedFileCount:a,onChanged:i})=>{const{t:o}=ut(),[c,d]=l.useState([]),[p,m]=l.useState(!1),[u,f]=l.useState(""),[y,h]=l.useState(""),[b,x]=l.useState(null),[g,w]=l.useState({}),v=l.useCallback(async()=>{if(n){m(!0);try{const R=await Hv(n);d(R.stashes),w({})}catch(R){q.error(R instanceof Error?R.message:o("gitView.stashes.toast.loadFailed"))}finally{m(!1)}}},[n,o]);l.useEffect(()=>{t&&v()},[v,t]),l.useEffect(()=>{if(!t||!n||c.length===0)return;let R=!1;const k=c.map(A=>A.ref);return Gv(n,k).then(A=>{R||w(A.counts)}).catch(()=>{}),()=>{R=!0}},[n,t,c]);const S=l.useMemo(()=>{const R=u.trim().toLowerCase();return R?c.filter(k=>`${k.ref} ${k.message} ${k.relativeTime}`.toLowerCase().includes(R)):c},[u,c]),P=l.useCallback(async()=>{await v(),await i?.()},[v,i]),j=async()=>{if(!(!n||b)){x("create");try{(await qv(n,{message:y.trim()||void 0})).created?(q.success(o("gitView.stashes.toast.created")),h("")):q.info(o("gitView.stashes.toast.noChanges")),await P()}catch(R){q.error(R instanceof Error?R.message:o("gitView.stashes.toast.createFailed"))}finally{x(null)}}},C=async(R,k)=>{if(!(!n||b)&&!(k==="drop"&&!window.confirm(o("gitView.stashes.confirm.drop",{ref:R.ref})))){x(`${k}:${R.ref}`);try{k==="apply"&&await Qv(n,{ref:R.ref}),k==="pop"&&await Jv(n,{ref:R.ref}),k==="drop"&&await Yv(n,{ref:R.ref});const A=k==="apply"?"gitView.stashes.toast.applySuccess":k==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";q.success(o(A)),await P()}catch(A){const N=k==="apply"?"gitView.stashes.toast.applyFailed":k==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";q.error(A instanceof Error?A.message:o(N)),await P()}finally{x(null)}}},I=b!==null;return s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(Cs,{children:[s.jsxs(js,{className:"flex items-center gap-2",children:[s.jsx(Iu,{className:"h-5 w-5"}),o("gitView.stashes.title")]}),s.jsx(Fs,{children:o("gitView.stashes.description")})]}),s.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[s.jsx(Bt,{value:y,onChange:R=>h(R.target.value),placeholder:o("gitView.stashes.messagePlaceholder"),disabled:I||!r,className:"flex-1"}),s.jsxs(ve,{onClick:j,disabled:!r||I||!n,children:[b==="create"?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(Ib,{className:"size-4"}),o("gitView.stashes.actions.stashCurrentWithCount",{count:a})]})]}),s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:o("gitView.stashes.includeUntrackedHint")})]}),s.jsxs("div",{className:"relative mt-2",children:[s.jsx(Jn,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(Bt,{value:u,onChange:R=>f(R.target.value),placeholder:o("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:p?s.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:s.jsx(ts,{className:"size-5 animate-spin"})}):S.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:o(u?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):S.map((R,k)=>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:R.message||o("gitView.stashes.untitled")}),s.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("span",{children:k===0&&!u.trim()?o("gitView.stashes.latestLabel"):o("gitView.stashes.itemNumber",{number:k+1})})}),s.jsx(It,{sideOffset:6,children:R.ref})]})," · ",R.relativeTime," · ",typeof g[R.ref]=="number"?o("gitView.stashes.fileCount",{count:g[R.ref]}):o("gitView.stashes.fileCountLoading")]})]}),s.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[s.jsx(td,{label:o("gitView.stashes.actions.apply"),loading:b===`apply:${R.ref}`,onClick:()=>C(R,"apply"),disabled:I,children:s.jsx(Ab,{className:"size-4"})}),s.jsx(td,{label:o("gitView.stashes.actions.pop"),loading:b===`pop:${R.ref}`,onClick:()=>C(R,"pop"),disabled:I,children:s.jsx(Pb,{className:"size-4"})}),s.jsx(td,{label:o("gitView.stashes.actions.drop"),loading:b===`drop:${R.ref}`,onClick:()=>C(R,"drop"),disabled:I,destructive:!0,children:s.jsx(an,{className:"size-4"})})]})]},R.ref))})]})})},td=t=>{const e=nt.c(15),{label:n,loading:r,disabled:a,destructive:i,onClick:o,children:c}=t,d=i?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let p;e[0]!==d?(p=me("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",d),e[0]=d,e[1]=p):p=e[1];let m;e[2]!==c||e[3]!==r?(m=r?s.jsx(ts,{className:"size-4 animate-spin"}):c,e[2]=c,e[3]=r,e[4]=m):m=e[4];let u;e[5]!==a||e[6]!==o||e[7]!==p||e[8]!==m?(u=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",className:p,onClick:o,disabled:a,children:m})}),e[5]=a,e[6]=o,e[7]=p,e[8]=m,e[9]=u):u=e[9];let f;e[10]!==n?(f=s.jsx(It,{sideOffset:6,children:n}),e[10]=n,e[11]=f):f=e[11];let y;return e[12]!==u||e[13]!==f?(y=s.jsxs(St,{children:[u,f]}),e[12]=u,e[13]=f,e[14]=y):y=e[14],y},ix={"?":{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"}},MN=ix.M;function RN(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 EN(t){const e=RN(t);return ix[e]??MN}const bp=l.memo(function(e){const n=nt.c(71),{file:r,checked:a,onToggle:i,onViewDiff:o,onRevert:c,isReverting:d,stats:p,rowPaddingClassName:m,indentPx:u}=e,f=u===void 0?0:u;let y;n[0]!==r?(y=EN(r),n[0]=r,n[1]=y):y=n[1];const h=y,{t:b}=ut(),x=h.description,g=p?.insertions??0,w=p?.deletions??0;let v;n[2]!==i||n[3]!==o?(v=E=>{E.key===" "?(E.preventDefault(),i()):E.key==="Enter"&&(E.preventDefault(),o())},n[2]=i,n[3]=o,n[4]=v):v=n[4];const S=v;let P;n[5]!==c?(P=E=>{E.preventDefault(),E.stopPropagation(),c()},n[5]=c,n[6]=P):P=n[6];const j=P,C=`group flex items-center gap-2 py-1.5 hover:bg-sidebar/40 cursor-pointer ${m??"px-3"}`;let I;n[7]!==f?(I=f>0?{paddingLeft:`${f}px`}:void 0,n[7]=f,n[8]=I):I=n[8];let R;n[9]!==i?(R=()=>i(),n[9]=i,n[10]=R):R=n[10];let k;n[11]!==r.path||n[12]!==b?(k=b("gitView.changes.selectFileAria",{path:r.path}),n[11]=r.path,n[12]=b,n[13]=k):k=n[13];let A;n[14]!==a||n[15]!==R||n[16]!==k?(A=s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",onClick:FN,children:s.jsx(bs,{size:"sm",checked:a,onChange:R,ariaLabel:k})}),n[14]=a,n[15]=R,n[16]=k,n[17]=A):A=n[17];let N;n[18]!==h.color?(N={color:h.color},n[18]=h.color,n[19]=N):N=n[19];let D;n[20]!==h.code||n[21]!==x||n[22]!==N?(D=s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:N,title:x,"aria-label":x,children:h.code}),n[20]=h.code,n[21]=x,n[22]=N,n[23]=D):D=n[23];let T;n[24]!==r.path?(T=s.jsx(Dr,{filePath:r.path,className:"h-3.5 w-3.5 shrink-0"}),n[24]=r.path,n[25]=T):T=n[25];let M;if(n[26]!==r.path){e:{const E=r.path.lastIndexOf("/");if(E===-1){let pe;n[28]===Symbol.for("react.memo_cache_sentinel")?(pe={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[28]=pe):pe=n[28],M=s.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:pe,title:r.path,children:r.path});break e}const z=r.path.slice(0,E),J=r.path.slice(E);let H;n[29]===Symbol.for("react.memo_cache_sentinel")?(H={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[29]=H):H=n[29];let te;n[30]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx("span",{className:"text-muted-foreground",children:"/"}),n[30]=te):te=n[30];const ce=s.jsx("span",{className:"text-foreground",children:J.slice(1)});let Se;n[31]!==ce?(Se=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[te,ce]}),n[31]=ce,n[32]=Se):Se=n[32],M=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:H,children:z}),Se]})}n[26]=r.path,n[27]=M}else M=n[27];let $;n[33]===Symbol.for("react.memo_cache_sentinel")?($={color:"var(--status-success)"},n[33]=$):$=n[33];let F;n[34]!==g?(F=s.jsxs("span",{style:$,children:["+",g]}),n[34]=g,n[35]=F):F=n[35];let _,O;n[36]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),O={color:"var(--status-error)"},n[36]=_,n[37]=O):(_=n[36],O=n[37]);let L;n[38]!==w?(L=s.jsxs("span",{style:O,children:["-",w]}),n[38]=w,n[39]=L):L=n[39];let K;n[40]!==F||n[41]!==L?(K=s.jsxs("span",{className:"shrink-0 typography-micro",children:[F,_,L]}),n[40]=F,n[41]=L,n[42]=K):K=n[42];let B;n[43]!==r.path||n[44]!==b?(B=b("gitView.changes.revertFileAria",{path:r.path}),n[43]=r.path,n[44]=b,n[45]=B):B=n[45];let re;n[46]!==d?(re=d?s.jsx(ts,{className:"size-3.5 animate-spin"}):s.jsx(Db,{className:"size-3.5"}),n[46]=d,n[47]=re):re=n[47];let oe;n[48]!==j||n[49]!==d||n[50]!==B||n[51]!==re?(oe=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,disabled:d,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":B,children:re})}),n[48]=j,n[49]=d,n[50]=B,n[51]=re,n[52]=oe):oe=n[52];let ee;n[53]!==b?(ee=b("gitView.changes.revertFileTooltip"),n[53]=b,n[54]=ee):ee=n[54];let ae;n[55]!==ee?(ae=s.jsx(It,{sideOffset:8,children:ee}),n[55]=ee,n[56]=ae):ae=n[56];let ge;n[57]!==oe||n[58]!==ae?(ge=s.jsxs(St,{children:[oe,ae]}),n[57]=oe,n[58]=ae,n[59]=ge):ge=n[59];let ne;return n[60]!==S||n[61]!==o||n[62]!==D||n[63]!==T||n[64]!==M||n[65]!==K||n[66]!==ge||n[67]!==C||n[68]!==I||n[69]!==A?(ne=s.jsxs("div",{className:C,role:"button",tabIndex:0,onClick:o,onKeyDown:S,style:I,children:[A,D,T,M,K,ge]}),n[60]=S,n[61]=o,n[62]=D,n[63]=T,n[64]=M,n[65]=K,n[66]=ge,n[67]=C,n[68]=I,n[69]=A,n[70]=ne):ne=n[70],ne});function FN(t){t.stopPropagation()}const ON=120,LN=34,yp=14,ox=t=>t.replace(/\\/g,"/").replace(/^\/+/,"").trim(),vp=(t,e)=>({id:`dir:${t}`,path:t,name:e,children:new Map,directFiles:[],files:[]}),$N=t=>{const e=vp("","");for(const n of t){const r=ox(n.path);if(!r)continue;const i=r.split("/").filter(Boolean).slice(0,-1);let o=e;if(o.files.push(n),i.length>0){let c="";for(const d of i){c=c?`${c}/${d}`:d;const p=o.children.get(d);if(p){p.files.push(n),o=p;continue}const m=vp(c,d);m.files.push(n),o.children.set(d,m),o=m}}o.directFiles.push(n)}return e},BN=(t,e)=>{const n=[],r=(a,i)=>{const o=Array.from(a.children.values()).sort((d,p)=>d.path.localeCompare(p.path));for(const d of o)n.push({key:d.id,kind:"directory",depth:i,directory:d}),e.has(d.path)&&r(d,i+1);const c=[...a.directFiles].sort((d,p)=>d.path.localeCompare(p.path));for(const d of c)n.push({key:`file:${ox(d.path)}`,kind:"file",depth:i,file:d})};return r(t,0),n},wp=(t,e)=>{if(t.files.length===0)return"none";let n=0;for(const r of t.files)e.has(r.path)&&(n+=1);return n===0?"none":n===t.files.length?"all":"partial"},_N=({changeEntries:t,selectedPaths:e,diffStats:n,revertingPaths:r,onToggleFile:a,onSelectAll:i,onClearSelection:o,onRevertAll:c,onViewDiff:d,onRevertFile:p,isRevertingAll:m=!1,maxListHeightClassName:u,onVisiblePathsChange:f,onOpenStashes:y})=>{const{t:h}=ut(),b=l.useRef(null),g=De(ne=>ne.gitChangesViewMode)==="tree",w=e.size,v=t.length,[S,P]=l.useState(!1),j=l.useMemo(()=>$N(t),[t]),[C,I]=l.useState(new Set),R=l.useMemo(()=>Array.from(j.children.values()).map(ne=>ne.path),[j]);l.useEffect(()=>{g&&I(ne=>{const E=new Set,z=new Set(R);return ne.forEach(J=>{if(J.includes("/")){E.add(J);return}z.has(J)&&E.add(J)}),R.forEach(J=>E.add(J)),E})},[g,R]);const k=l.useMemo(()=>BN(j,C),[C,j]),A=l.useMemo(()=>g?k:t,[t,g,k]),N=A.length,D=N>=ON,T=w>0,M=v>0&&w===v,$=T&&!M,F=Tb({count:N,getScrollElement:()=>b.current,estimateSize:()=>LN,overscan:10,enabled:D});l.useEffect(()=>{if(!D)return;const ne=b.current;if(!ne)return;const E=new ResizeObserver(()=>{F.measure()});return E.observe(ne),()=>E.disconnect()},[D,F]);const _=F.getTotalSize(),O=l.useMemo(()=>D&&_>=0?F.getVirtualItems():[],[D,F,_]);l.useEffect(()=>{if(!f)return;if(N===0){f([]);return}const ne=E=>{if(!g)return E.path;const z=E;return z.kind==="file"?z.file.path:null};if(!D){f(A.slice(0,Math.min(30,N)).map(E=>ne(E)).filter(E=>!!E));return}f(O.map(E=>A[E.index]).map(E=>E?ne(E):null).filter(E=>!!E))},[g,f,N,A,D,O]);const L="flex flex-col flex-1 min-h-0",K="flex items-center justify-between gap-2 px-0 py-3 border-b border-border/40",B=`flex-1 min-h-0 pr-0 ${u??""}`.trim(),re="pl-0 pr-2",oe=l.useCallback(ne=>{I(E=>{const z=new Set(E);return z.has(ne)?z.delete(ne):z.add(ne),z})},[]),ee=l.useCallback(ne=>{const z=wp(ne,e)!=="all";for(const J of ne.files){const H=e.has(J.path);(z&&!H||!z&&H)&&a(J.path)}},[a,e]),ae=l.useCallback(ne=>{if(!g){const te=ne;return s.jsx(bp,{file:te,checked:e.has(te.path),stats:n?.[te.path],onToggle:()=>a(te.path),onViewDiff:()=>d(te.path),onRevert:()=>p(te.path),isReverting:r.has(te.path)||m,rowPaddingClassName:re})}const E=ne;if(E.kind==="file"){const te=E.file;return s.jsx(bp,{file:te,checked:e.has(te.path),stats:n?.[te.path],onToggle:()=>a(te.path),onViewDiff:()=>d(te.path),onRevert:()=>p(te.path),isReverting:r.has(te.path)||m,rowPaddingClassName:re,indentPx:E.depth*yp})}const z=E.directory,J=C.has(z.path),H=wp(z,e);return s.jsxs("div",{className:me("group flex items-center gap-2 py-1.5 hover:bg-sidebar/40",re),style:{paddingLeft:`${E.depth*yp}px`},children:[s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",children:s.jsx(bs,{size:"sm",checked:H==="all",indeterminate:H==="partial",onChange:()=>ee(z),ariaLabel:h("gitView.changes.toggleDirectorySelectionAria",{path:z.path})})}),s.jsxs("button",{type:"button",onClick:()=>oe(z.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":J?h("gitView.changes.collapseDirectoryAria",{path:z.path}):h("gitView.changes.expandDirectoryAria",{path:z.path}),children:[J?s.jsx(Au,{className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(Pu,{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:z.path,children:z.name}),s.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:z.files.length})]})]})},[n,C,m,g,p,a,d,r,re,e,h,oe,ee]),ge=l.useCallback(async()=>{!c||m||t.length===0||(await c(t.map(ne=>ne.path)),P(!1))},[t,m,c]);return s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:L,children:[s.jsxs("header",{className:K,children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:h("gitView.changes.title")}),v>0?s.jsxs("div",{className:me("inline-flex h-6 items-center gap-1 rounded px-1.5",m&&"cursor-not-allowed opacity-50"),children:[s.jsx(bs,{size:"sm",checked:T,indeterminate:$,disabled:m,onChange:()=>M?o():i(),ariaLabel:h(M?"gitView.changes.clearSelectionAria":"gitView.changes.selectAllAria")}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[w,"/",v]})]}):null,y?s.jsx(ve,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-1.5",onClick:y,"aria-label":h("gitView.stashes.title"),title:h("gitView.stashes.title"),children:s.jsx(Iu,{className:"size-4"})}):null]}),s.jsx("div",{className:"flex items-center gap-2 pr-1",children:v>0&&c?s.jsx(ve,{variant:"destructive",size:"xs",onClick:()=>P(!0),disabled:m,children:h("gitView.changes.revertAll")}):null})]}),s.jsxs("div",{className:me("relative flex flex-col min-h-0 w-full overflow-hidden",B),children:[s.jsx(zo,{ref:b,className:"overlay-scrollbar-target overlay-scrollbar-container flex-1 min-h-0 w-full overflow-y-auto overflow-x-hidden",children:D?s.jsx("div",{className:"relative w-full",style:{height:`${F.getTotalSize()}px`},children:O.map(ne=>{const E=A[ne.index];if(!E)return null;const z=g?E.key:`file:${E.path}`;return s.jsx("div",{ref:F.measureElement,"data-index":ne.index,className:me("absolute left-0 top-0 w-full",ne.index>0&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),style:{transform:`translateY(${ne.start}px)`},children:ae(E)},z)})}):s.jsx("div",{role:"list","aria-label":h("gitView.changes.changedFilesAria"),children:A.map((ne,E)=>s.jsx("div",{className:me("relative",E>0&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:ae(ne)},g?ne.key:`file:${ne.path}`))})}),s.jsx(Xv,{containerRef:b,disableHorizontal:!0})]})]}),s.jsx(ws,{open:S,onOpenChange:ne=>{m||P(ne)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:h("gitView.changes.revertAllDialogTitle")}),s.jsx(Fs,{children:v===1?h("gitView.changes.revertAllDescriptionSingle",{count:v}):h("gitView.changes.revertAllDescriptionPlural",{count:v})})]}),s.jsxs(Xs,{children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>P(!1),disabled:m,children:h("gitView.common.cancel")}),s.jsx(ve,{variant:"destructive",size:"sm",onClick:()=>{ge()},disabled:m,children:h(m?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})})]})},sd=38,cl=200,VN=t=>{const e=nt.c(20),{value:n,onChange:r,placeholder:a,disabled:i,hasTouchInput:o,isMobile:c}=t,d=i===void 0?!1:i,p=o===void 0?!1:o,m=c===void 0?!1:c,{t:u}=ut(),f=l.useRef(null),y=De(zN);let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{const R=f.current;if(!R)return;const k=document.activeElement===R,A=()=>{R.style.height=`${sd}px`;const D=R.scrollHeight,T=Math.min(Math.max(D,sd),cl);R.style.height=`${T}px`,R.style.overflowY=D>cl?"auto":"hidden",D>cl&&!k&&(R.scrollTop=R.scrollHeight)};A();const N=window.requestAnimationFrame(A);return()=>{window.cancelAnimationFrame(N)}},e[0]=h):h=e[0];let b;e[1]!==n?(b=[n],e[1]=n,e[2]=b):b=e[2],l.useLayoutEffect(h,b);let x;e[3]!==r?(x=R=>r(R.target.value),e[3]=r,e[4]=x):x=e[4];let g;e[5]!==a||e[6]!==u?(g=a??u("gitView.commit.messagePlaceholder"),e[5]=a,e[6]=u,e[7]=g):g=e[7];const w=p?"on":"off",v=p?"sentences":"off",S=m||y,P=d&&"opacity-50";let j;e[8]!==P?(j=me("w-full rounded-lg border border-border/60 bg-surface-elevated px-3 py-2 typography-ui-label text-foreground placeholder:text-muted-foreground","resize-none outline-none transition-[border-color,box-shadow] duration-150","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",P),e[8]=P,e[9]=j):j=e[9];let C;e[10]===Symbol.for("react.memo_cache_sentinel")?(C={minHeight:sd,maxHeight:cl},e[10]=C):C=e[10];let I;return e[11]!==d||e[12]!==S||e[13]!==j||e[14]!==x||e[15]!==g||e[16]!==w||e[17]!==v||e[18]!==n?(I=s.jsx("textarea",{ref:f,value:n,onChange:x,placeholder:g,rows:1,disabled:d,autoCorrect:w,autoCapitalize:v,spellCheck:S,className:j,style:C}),e[11]=d,e[12]=S,e[13]=j,e[14]=x,e[15]=g,e[16]=w,e[17]=v,e[18]=n,e[19]=I):I=e[19],I};function zN(t){return t.inputSpellcheckEnabled}const UN=t=>{const e=nt.c(30),{highlights:n,onInsert:r}=t,{t:a}=ut();if(n.length===0)return null;let i;e[0]!==n||e[1]!==r?(i=()=>{r(n)},e[0]=n,e[1]=r,e[2]=i):i=e[2];const o=i;let c;e[3]!==a?(c=a("gitView.commit.aiHighlights.title"),e[3]=a,e[4]=c):c=e[4];let d;e[5]!==c?(d=s.jsx("p",{className:"typography-micro text-muted-foreground",children:c}),e[5]=c,e[6]=d):d=e[6];let p;e[7]!==a?(p=a("gitView.commit.aiHighlights.insertAria"),e[7]=a,e[8]=p):p=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Mb,{className:"size-4"}),e[9]=m):m=e[9];let u;e[10]!==o||e[11]!==p?(u=s.jsx(kt,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"icon",className:"size-6",onClick:o,"aria-label":p,children:m})}),e[10]=o,e[11]=p,e[12]=u):u=e[12];let f;e[13]!==a?(f=a("gitView.commit.aiHighlights.insertTooltip"),e[13]=a,e[14]=f):f=e[14];let y;e[15]!==f?(y=s.jsx(It,{sideOffset:8,children:f}),e[15]=f,e[16]=y):y=e[16];let h;e[17]!==u||e[18]!==y?(h=s.jsxs(St,{children:[u,y]}),e[17]=u,e[18]=y,e[19]=h):h=e[19];let b;e[20]!==d||e[21]!==h?(b=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d,h]}),e[20]=d,e[21]=h,e[22]=b):b=e[22];let x;e[23]!==n?(x=n.map(WN),e[23]=n,e[24]=x):x=e[24];let g;e[25]!==x?(g=s.jsx("ul",{className:"space-y-1",children:x}),e[25]=x,e[26]=g):g=e[26];let w;return e[27]!==b||e[28]!==g?(w=s.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[b,g]}),e[27]=b,e[28]=g,e[29]=w):w=e[29],w};function WN(t,e){return s.jsx("li",{className:"typography-meta text-foreground",children:t},`${t}-${e}`)}const KN=t=>{const e=nt.c(72),{selectedCount:n,commitMessage:r,onCommitMessageChange:a,generatedHighlights:i,onInsertHighlights:o,onGenerateMessage:c,isGeneratingMessage:d,onCommit:p,onCommitAndPush:m,commitAction:u,gitmojiEnabled:f,onOpenGitmojiPicker:y}=t,{t:h}=ut(),b=n>0;let x;e[0]!==u||e[1]!==r||e[2]!==b?(x=r.trim()&&b&&u===null,e[0]=u,e[1]=r,e[2]=b,e[3]=x):x=e[3];const g=x,{isMobile:w,hasTouchInput:v}=dn();let S;e[4]!==h?(S=h("gitView.commit.title"),e[4]=h,e[5]=S):S=e[5];let P;e[6]!==S?(P=s.jsx("div",{className:"flex w-full items-center justify-between px-0 pt-2 pb-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:S})}),e[6]=S,e[7]=P):P=e[7];let j;e[8]!==b||e[9]!==h?(j=b?null:s.jsx("p",{className:"typography-meta text-muted-foreground",children:h("gitView.commit.selectFilesHint")}),e[8]=b,e[9]=h,e[10]=j):j=e[10];let C;e[11]!==i||e[12]!==o?(C=s.jsx(UN,{highlights:i,onInsert:o}),e[11]=i,e[12]=o,e[13]=C):C=e[13];let I;e[14]!==h?(I=h("gitView.commit.messagePlaceholder"),e[14]=h,e[15]=I):I=e[15];const R=u!==null;let k;e[16]!==r||e[17]!==v||e[18]!==w||e[19]!==a||e[20]!==I||e[21]!==R?(k=s.jsx(VN,{value:r,onChange:a,placeholder:I,disabled:R,hasTouchInput:v,isMobile:w}),e[16]=r,e[17]=v,e[18]=w,e[19]=a,e[20]=I,e[21]=R,e[22]=k):k=e[22];let A;e[23]!==f||e[24]!==y||e[25]!==h?(A=f&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:y,className:"w-fit",type:"button",children:[s.jsx(Rb,{className:"size-4"}),h("gitView.commit.addGitmoji")]}),e[23]=f,e[24]=y,e[25]=h,e[26]=A):A=e[26];const N=d||u!==null||n===0;let D;e[27]!==h?(D=h("gitView.commit.generateAria"),e[27]=h,e[28]=D):D=e[28];let T;e[29]!==d?(T=d?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(Ga,{className:"size-4 text-primary"}),e[29]=d,e[30]=T):T=e[30];let M;e[31]!==h?(M=h("gitView.commit.generate"),e[31]=h,e[32]=M):M=e[32];let $;e[33]!==M?($=s.jsx("span",{className:"commit-actions__label",children:M}),e[33]=M,e[34]=$):$=e[34];let F;e[35]!==c||e[36]!==N||e[37]!==D||e[38]!==T||e[39]!==$?(F=s.jsxs(ve,{variant:"outline",size:"sm",onClick:c,disabled:N,type:"button","aria-label":D,className:"commit-actions__btn",children:[T,$]}),e[35]=c,e[36]=N,e[37]=D,e[38]=T,e[39]=$,e[40]=F):F=e[40];let _;e[41]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx("div",{className:"flex-1"}),e[41]=_):_=e[41];const O=!g||d;let L;e[42]!==h?(L=h("gitView.commit.commitAria"),e[42]=h,e[43]=L):L=e[43];let K;e[44]!==u||e[45]!==h?(K=u==="commit"?s.jsxs(s.Fragment,{children:[s.jsx(ts,{className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.committing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(pc,{className:"size-4"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.commit")})]}),e[44]=u,e[45]=h,e[46]=K):K=e[46];let B;e[47]!==p||e[48]!==O||e[49]!==L||e[50]!==K?(B=s.jsx(ve,{size:"sm",variant:"outline",onClick:p,disabled:O,className:"commit-actions__btn whitespace-nowrap","aria-label":L,children:K}),e[47]=p,e[48]=O,e[49]=L,e[50]=K,e[51]=B):B=e[51];let re;e[52]!==g||e[53]!==u||e[54]!==d||e[55]!==w||e[56]!==m||e[57]!==h?(re=w?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(ve,{variant:"default",size:"sm",onClick:()=>m(),disabled:!g||d,className:"h-7 w-7 p-0","aria-label":h("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(Wl,{className:"size-3.5"})})}),s.jsx(It,{side:"top",children:s.jsx("p",{children:h("gitView.commit.push")})})]}):s.jsx(ve,{size:"sm",variant:"default",onClick:()=>m(),disabled:!g||d,className:"commit-actions__btn","aria-label":h("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsxs(s.Fragment,{children:[s.jsx(ts,{className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.pushing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(Wl,{className:"size-3.5"}),s.jsx("span",{className:"commit-actions__label",children:h("gitView.commit.push")})]})}),e[52]=g,e[53]=u,e[54]=d,e[55]=w,e[56]=m,e[57]=h,e[58]=re):re=e[58];let oe;e[59]!==F||e[60]!==B||e[61]!==re?(oe=s.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[F,_,B,re]}),e[59]=F,e[60]=B,e[61]=re,e[62]=oe):oe=e[62];let ee;e[63]!==oe||e[64]!==j||e[65]!==C||e[66]!==k||e[67]!==A?(ee=s.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[j,C,k,A,oe]}),e[63]=oe,e[64]=j,e[65]=C,e[66]=k,e[67]=A,e[68]=ee):ee=e[68];let ae;return e[69]!==ee||e[70]!==P?(ae=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[P,ee]}),e[69]=ee,e[70]=P,e[71]=ae):ae=e[71],ae},HN=t=>{const e=nt.c(16),{onOpenStashes:n}=t,{t:r}=ut();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(pc,{className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=a):a=e[0];let i;e[1]!==r?(i=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=i):i=e[2];let o;e[3]!==i?(o=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:i}),e[3]=i,e[4]=o):o=e[4];let c;e[5]!==r?(c=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=c):c=e[6];let d;e[7]!==c?(d=s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:c}),e[7]=c,e[8]=d):d=e[8];let p;e[9]!==n||e[10]!==r?(p=n?s.jsxs(ve,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(Iu,{className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=p):p=e[11];let m;return e[12]!==o||e[13]!==d||e[14]!==p?(m=s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[a,o,d,p]}),e[12]=o,e[13]=d,e[14]=p,e[15]=m):m=e[15],m};function jp(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 GN(t){switch(t){case"A":return"text-[var(--status-success)]";case"D":return"text-[var(--status-error)]";case"M":return"text-[var(--status-warning)]";case"R":return"text-[var(--status-info)]";default:return"text-muted-foreground"}}const qN=l.memo(t=>{const e=nt.c(55),{entry:n,isExpanded:r,onToggle:a,files:i,isLoadingFiles:o,onCopyHash:c}=t,{t:d}=ut(),p=r?"bg-sidebar/90":"hover:bg-sidebar/40";let m;e[0]!==p?(m=me("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",p),e[0]=p,e[1]=m):m=e[1];let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),e[2]=u):u=e[2];let f;e[3]!==n.message?(f=s.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:n.message}),e[3]=n.message,e[4]=f):f=e[4];let y;e[5]!==n.author_name?(y=s.jsx("span",{className:"truncate min-w-[3ch]",title:n.author_name,children:n.author_name}),e[5]=n.author_name,e[6]=y):y=e[6];let h;e[7]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx("span",{className:"shrink-0",children:"·"}),e[7]=h):h=e[7];let b;e[8]!==n.date?(b=jp(n.date),e[8]=n.date,e[9]=b):b=e[9];let x;e[10]!==n.date?(x=jp(n.date),e[10]=n.date,e[11]=x):x=e[11];let g;e[12]!==b||e[13]!==x?(g=s.jsx("span",{className:"truncate min-w-0",title:b,children:x}),e[12]=b,e[13]=x,e[14]=g):g=e[14];let w;e[15]!==y||e[16]!==g?(w=s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[y,h,g]}),e[15]=y,e[16]=g,e[17]=w):w=e[17];let v;e[18]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("span",{className:"shrink-0",children:"·"}),e[18]=v):v=e[18];let S;e[19]!==n.hash?(S=n.hash.slice(0,8),e[19]=n.hash,e[20]=S):S=e[20];let P;e[21]!==S?(P=s.jsx("code",{className:"shrink-0 font-mono",children:S}),e[21]=S,e[22]=P):P=e[22];let j;e[23]!==n.hash||e[24]!==c?(j=F=>{F.stopPropagation(),c(n.hash)},e[23]=n.hash,e[24]=c,e[25]=j):j=e[25];let C;e[26]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(vr,{className:"size-3"}),e[26]=C):C=e[26];let I;e[27]!==j?(I=s.jsx(kt,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:j,children:C})}),e[27]=j,e[28]=I):I=e[28];let R;e[29]!==d?(R=d("gitView.history.copySha"),e[29]=d,e[30]=R):R=e[30];let k;e[31]!==R?(k=s.jsx(It,{sideOffset:8,children:R}),e[31]=R,e[32]=k):k=e[32];let A;e[33]!==I||e[34]!==k?(A=s.jsxs(St,{children:[I,k]}),e[33]=I,e[34]=k,e[35]=A):A=e[35];let N;e[36]!==w||e[37]!==P||e[38]!==A?(N=s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[w,v,P,A]}),e[36]=w,e[37]=P,e[38]=A,e[39]=N):N=e[39];let D;e[40]!==N||e[41]!==f?(D=s.jsxs("div",{className:"min-w-0 flex-1",children:[f,N]}),e[40]=N,e[41]=f,e[42]=D):D=e[42];let T;e[43]!==a||e[44]!==m||e[45]!==D?(T=s.jsxs("button",{type:"button",onClick:a,className:m,children:[u,D]}),e[43]=a,e[44]=m,e[45]=D,e[46]=T):T=e[46];let M;e[47]!==i||e[48]!==r||e[49]!==o||e[50]!==d?(M=r&&s.jsx("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:o?s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(ts,{className:"size-4 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:d("gitView.history.loadingFiles")})]}):i.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:d("gitView.history.noFiles")}):s.jsx("ul",{className:"space-y-0.5 py-2",children:i.map(F=>s.jsxs("li",{className:"flex items-center gap-2 typography-micro",children:[s.jsx("span",{className:me("font-semibold w-3 text-center",GN(F.changeType)),children:F.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:F.path,children:F.path}),!F.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",F.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",F.deletions]})]}),F.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:d("gitView.history.binary")})]},F.path))})}),e[47]=i,e[48]=r,e[49]=o,e[50]=d,e[51]=M):M=e[51];let $;return e[52]!==T||e[53]!==M?($=s.jsxs("li",{children:[T,M]}),e[52]=T,e[53]=M,e[54]=$):$=e[54],$}),QN=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],JN=t=>{const e=nt.c(54),{log:n,isLogLoading:r,logMaxCount:a,onLogMaxCountChange:i,expandedCommitHashes:o,onToggleCommit:c,commitFilesMap:d,loadingCommitHashes:p,onCopyHash:m,showHeader:u,contentMaxHeightClassName:f,branchDivider:y}=t,h=u===void 0?!0:u,b=f===void 0?"max-h-[50vh]":f,x=y===void 0?null:y,{t:g}=ut(),[w,v]=l.useState(!0);if(!n)return null;const S=x!==null&&x.insertBeforeIndex>0&&x.insertBeforeIndex<n.all.length,P=x!==null&&x.insertBeforeIndex===n.all.length,j=S||P;let C;e[0]!==x||e[1]!==S||e[2]!==P||e[3]!==n.all?(C=S?n.all.slice(0,x.insertBeforeIndex):P?n.all:[],e[0]=x,e[1]=S,e[2]=P,e[3]=n.all,e[4]=C):C=e[4];const I=C;let R;if(e[5]!==x||e[6]!==d||e[7]!==b||e[8]!==o||e[9]!==S||e[10]!==j||e[11]!==p||e[12]!==n.all||e[13]!==m||e[14]!==c||e[15]!==g||e[16]!==I){const O=S?n.all.slice(x.insertBeforeIndex):[];let L;e[18]!==x?.direction?(L=x?.direction==="down"?s.jsx(ks,{className:"size-3.5"}):s.jsx(Wl,{className:"size-3.5"}),e[18]=x?.direction,e[19]=L):L=e[19];const K=L;let B;e[20]!==d||e[21]!==o||e[22]!==p||e[23]!==m||e[24]!==c?(B=oe=>s.jsx("ul",{className:"divide-y divide-border/60",children:oe.map(ee=>s.jsx(qN,{entry:ee,isExpanded:o.has(ee.hash),onToggle:()=>c(ee.hash),files:d.get(ee.hash)??[],isLoadingFiles:p.has(ee.hash),onCopyHash:m},ee.hash))}),e[20]=d,e[21]=o,e[22]=p,e[23]=m,e[24]=c,e[25]=B):B=e[25];const re=B;R=s.jsx(Ps,{outerClassName:`min-h-0 ${b}`,className:"h-full w-full",children:n.all.length===0?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:g("gitView.history.noCommits")})}):j&&x?s.jsxs("div",{className:"flex flex-col gap-0",children:[I.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:re(I)}):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:x.branchName,children:x.branchName}),K]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),O.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:re(O)}):null]}):re(n.all)}),e[5]=x,e[6]=d,e[7]=b,e[8]=o,e[9]=S,e[10]=j,e[11]=p,e[12]=n.all,e[13]=m,e[14]=c,e[15]=g,e[16]=I,e[17]=R}else R=e[17];const k=R;if(!h){if(j){let L;return e[26]!==k?(L=s.jsx("section",{className:"h-full min-h-0",children:k}),e[26]=k,e[27]=L):L=e[27],L}let O;return e[28]!==k?(O=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:k}),e[28]=k,e[29]=O):O=e[29],O}let A;e[30]!==g?(A=g("gitView.history.title"),e[30]=g,e[31]=A):A=e[31];let N;e[32]!==A?(N=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:A}),e[32]=A,e[33]=N):N=e[33];let D;e[34]!==r||e[35]!==w||e[36]!==a||e[37]!==i||e[38]!==g?(D=w&&s.jsx("div",{onClick:YN,onPointerDown:XN,children:s.jsxs(ps,{value:String(a),onValueChange:O=>i(Number(O)),disabled:r,children:[s.jsx(hs,{size:"sm",className:"data-[size=sm]:h-auto h-7 min-h-7 w-auto justify-between px-2 py-0",disabled:r,children:s.jsx(ys,{placeholder:g("gitView.history.commitsPlaceholder")})}),s.jsx(fs,{children:QN.map(O=>s.jsx(Rt,{value:String(O.value),children:g(O.labelKey)},O.value))})]})}),e[34]=r,e[35]=w,e[36]=a,e[37]=i,e[38]=g,e[39]=D):D=e[39];let T;e[40]!==w?(T=w?s.jsx(Du,{className:"size-4 text-muted-foreground"}):s.jsx(ks,{className:"size-4 text-muted-foreground"}),e[40]=w,e[41]=T):T=e[41];let M;e[42]!==D||e[43]!==T?(M=s.jsxs("div",{className:"flex items-center gap-2",children:[D,T]}),e[42]=D,e[43]=T,e[44]=M):M=e[44];let $;e[45]!==M||e[46]!==N?($=s.jsxs(Rr,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[N,M]}),e[45]=M,e[46]=N,e[47]=$):$=e[47];let F;e[48]!==k?(F=s.jsx(jr,{children:k}),e[48]=k,e[49]=F):F=e[49];let _;return e[50]!==w||e[51]!==$||e[52]!==F?(_=s.jsxs(wr,{open:w,onOpenChange:v,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[$,F]}),e[50]=w,e[51]=$,e[52]=F,e[53]=_):_=e[53],_};function YN(t){return t.stopPropagation()}function XN(t){return t.stopPropagation()}const ZN=9e4,e2=15e3,t2=5*6e4,s2=[2e3,5e3],n2=6e4,r2=2*6e4,a2=5*6e4,i2=720*6e4,o2="openchamber.github-pr-status",l2=t=>t==="closed"||t==="merged",c2=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},Ao=(t,e,n)=>`${t}::${e}`,dl=new Map,ul=new Map,oo=new Set,Np=new Map,xo=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),sc=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,qu=t=>{const e=sc(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},lx=(t,e)=>Object.entries(t).filter(([,n])=>qu(n)===e).map(([n])=>n),d2=(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}}},ml=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},u2=(t,e,n)=>{const r=lx(t,e),a=r.map(d=>ml(t[d])).filter(d=>!!d);if(a.length===0)return null;const i=ml(t[n]);if(i&&qu(t[n])===e)return i;const o=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&ml(d)));if(o)return ml(o);const c=a.find(d=>!!d.remoteName);return c||(a[0]??null)},m2=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:sc(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),p2=t=>({...xo(),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}),br=Nr()(_o((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:xo()}})},setParams:(n,r)=>{t(a=>{const i=a.entries[n]??xo();return{entries:{...a.entries,[n]:d2(i,r)}}})},startWatching:n=>{if(t(i=>{const o=i.entries[n]??xo();return{entries:{...i.entries,[n]:{...o,watchers:o.watchers+1}}}}),dl.has(n))return;const r=i=>{const o=window.setTimeout(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const d=e().entries[n];!d||d.watchers<=0||d.status?.pr||e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},i),c=ul.get(n)??[];c.push(o),ul.set(n,c)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),s2.forEach(i=>r(i));const a=window.setInterval(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const i=e().entries[n];if(!i||i.watchers<=0)return;if(!!!i.status?.pr){const p=Date.now();if(p-i.lastDiscoveryPollAt<t2)return;t(m=>{const u=m.entries[n];return u?{entries:{...m.entries,[n]:{...u,lastDiscoveryPollAt:p}}}:m}),e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}if(l2(i.status?.pr?.state))return;const c=Date.now()-i.lastRefreshAt,d=c2(i.status)?n2:i.status?.checks&&i.status.checks.state!=="pending"?a2:r2;c<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},e2);dl.set(n,a)},stopWatching:n=>{t(o=>{const c=o.entries[n];if(!c)return o;const d=Math.max(0,c.watchers-1);return{entries:{...o.entries,[n]:{...c,watchers:d}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const a=dl.get(n);typeof a=="number"&&window.clearInterval(a),dl.delete(n);const i=ul.get(n);i&&i.length>0&&i.forEach(o=>{window.clearTimeout(o)}),ul.delete(n)},refresh:async(n,r)=>{const a=e(),i=a.entries[n],o=qu(i);if(!i||!o)return;const c=lx(a.entries,o),d=c.some(u=>!!a.entries[u]?.status?.pr);if(r?.onlyExistingPr&&!d)return;const p=Np.get(o)??0;if(!r?.force&&Date.now()-p<ZN||oo.has(o))return;const m=u2(a.entries,o,n);if(m){if(oo.add(o),Np.set(o,Date.now()),t(u=>{const f={...u.entries};return c.forEach(y=>{const h=f[y];h&&(f[y]={...h,lastRefreshAt:Date.now(),isLoading:r?.silent?h.isLoading:!0,error:null})}),{entries:f}}),m.githubAuthChecked&&m.githubConnected===!1){t(u=>{const f={...u.entries};return c.forEach(y=>{const h=f[y];h&&(f[y]={...h,status:{connected:!1},error:null,isLoading:r?.silent?h.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?h.isInitialStatusResolved:!0})}),{entries:f}}),oo.delete(o);return}if(!m.github?.prStatus){t(u=>{const f={...u.entries};return c.forEach(y=>{const h=f[y];h&&(f[y]={...h,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?h.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?h.isInitialStatusResolved:!0})}),{entries:f}}),oo.delete(o);return}try{t(f=>({...f,activeRequestCount:f.activeRequestCount+1,totalRequestCount:f.totalRequestCount+1}));const u=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0,{force:r?.force});t(f=>{const y={...f.entries};return c.forEach(h=>{const b=y[h];if(!b)return;const x=b.status?.pr,g=u.pr,v=!!(g&&x&&g.number===x.number&&(!g.body||!g.body.trim())&&typeof x.body=="string"&&x.body.trim().length>0)&&g&&x?.body?{...u,pr:{...g,body:x.body}}:u,S=v.resolvedRemoteName??b.resolvedRemoteName??m.remoteName??null,P=sc(b)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};y[h]={...b,status:v,error:null,isLoading:r?.silent?b.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?b.isInitialStatusResolved:!0,resolvedRemoteName:S,identity:{...P,remoteName:S??P.remoteName??null}}}),{entries:y}})}catch(u){const f=u instanceof Error?u.message:String(u);t(y=>{const h={...y.entries};return c.forEach(b=>{const x=h[b];x&&(h[b]={...x,error:f||"Failed to load PR status",isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0})}),{entries:h}})}finally{oo.delete(o),t(u=>({...u,activeRequestCount:Math.max(0,u.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const a=Array.from(new Set(n.map(i=>{const o=i.directory.trim(),c=i.branch.trim();return!o||!c?null:Ao(o,c,i.remoteName??null)}).filter(i=>!!i)));await Promise.all(a.map(i=>e().refresh(i,r)))},updateStatus:(n,r)=>{t(a=>{const i=a.entries[n]??xo();return{entries:{...a.entries,[n]:{...i,status:r(i.status)}}}})}}),{name:o2,storage:dc(()=>va()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=sc(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<i2}).map(([e,n])=>[e,m2(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([a,i])=>[a,p2(i)]))}}})),h2=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"},f2=t=>{const e=h2(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}},g2=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 nd=new Map,Sp=new Map;const x2=t=>{const e=nt.c(2);let n;return e[0]!==t?(n=r=>{const a=new Map,i=new Map;for(const o of t){const c=r.entries[o];if(!c)continue;const d=f2(c);if(!d)continue;const p=g2(d);a.set(o,p),i.set(o,d)}if(a.size===nd.size){let o=!0;for(const[c,d]of a)if(nd.get(c)!==d){o=!1;break}if(o)return Sp}return nd=a,Sp=i,i},e[0]=t,e[1]=n):n=e[1],br(n)},b2=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"}},y2=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"},v2=[2e3,5e3],kp=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),ya=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):""},w2=(t,e)=>{const n=ya(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},j2=(t,e)=>`${t}::${e}`,Qu=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},rd=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const i=t.find(o=>o.name===n);if(i)return i}const r=Qu(e.trackingBranch);if(r){const i=r==="origin"?t.find(c=>c.name==="upstream"):null;if(i)return i;const o=t.find(c=>c.name===r);if(o)return o}const a=t.find(i=>i.name==="origin");return a||(t[0]??null)},N2=t=>t.startsWith("pr-"),S2=(t,e)=>{const n=Qu(e),r=new Map(t.map(o=>[o.name,o])),a=[],i=o=>{o&&(a.some(c=>c.name===o.name)||a.push(o))};return n&&i(r.get(n)),i(r.get("upstream")),i(r.get("origin")),t.filter(o=>!N2(o.name)).forEach(o=>i(o)),t.forEach(o=>i(o)),a},ad=new Map,id=mr;function k2(t,e){const[n,r]=l.useState(null),[a,i]=l.useState([]),o=l.useRef(null);return l.useEffect(()=>{r(null),i([])},[t]),l.useEffect(()=>{if(!t||!e?.repoUpstream||o.current===t)return;o.current=t;let c=!1;return(async()=>{try{const d=await e.repoUpstream(t);if(c||!d?.isFork||!d.upstream||(r(d.upstream),!e.repoBranches))return;try{const p=await e.repoBranches(d.upstream.owner,d.upstream.repo);c||i(p)}catch{}}catch{}})(),()=>{c=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:a}}const C2=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:a=[],remoteBranches:i=[],onGeneratedDescription:o})=>{const{t:c}=ut(),{github:d}=Yn(),p=sr(We=>We.status),m=sr(We=>We.hasChecked),u=De(We=>We.setSettingsDialogOpen),f=De(We=>We.setSettingsPage),y=De(We=>We.setActiveMainTab),h=Ht(We=>We.currentSessionId),{isMobile:b,hasTouchInput:x}=dn(),g=l.useCallback(()=>{f("github"),u(!0)},[u,f]),w=l.useMemo(()=>j2(t,e),[t,e]),v=l.useMemo(()=>ad.get(w)??null,[w]),S=br(We=>We.ensureEntry),P=br(We=>We.setParams),j=br(We=>We.startWatching),C=br(We=>We.stopWatching),I=br(We=>We.refresh),R=br(We=>We.updateStatus),[k,A]=l.useState(()=>v?.title??kp(e)),[N,D]=l.useState(()=>v?.body??""),[T,M]=l.useState(()=>v?.draft??!1),[$,F]=l.useState(()=>v?.additionalContext??""),[_,O]=l.useState(()=>{const We=typeof v?.targetBaseBranch=="string"?ya(v.targetBaseBranch):"";return We||ya(n)}),[L,K]=l.useState("squash"),[B,re]=l.useState(!1),[oe,ee]=l.useState(!1),[ae,ge]=l.useState(!1),[ne,E]=l.useState(!1),[z,J]=l.useState(!1),[H,te]=l.useState(!1),[ce,Se]=l.useState(null),[pe,we]=l.useState(""),[W,ue]=l.useState(""),[Y,le]=l.useState(!1),[Z,Ie]=l.useState(!1),[Ne,X]=l.useState(()=>rd(a,{selectedRemoteName:v?.selectedRemoteName,trackingBranch:r})),[he,je]=l.useState(!1),{detectedUpstream:be,upstreamBranches:fe}=k2(t,d);l.useEffect(()=>{je(!1)},[t]);const Pe=a.some(We=>We.name==="upstream"),G=!!(t&&e&&n&&(e!==n||(Pe||be!==null))),ke=l.useMemo(()=>Ao(t,e),[t,e]),Ee=br(We=>We.entries[ke]),Ae=Ee?.isLoading??!1,xe=Ee?.status??null,V=Ee?.error??null,de=Ee?.isInitialStatusResolved??!1,Me=l.useMemo(()=>{const We=he?null:Ne?.name?.trim()||null,xt=new Set;for(const as of i){const st=w2(as,We);!st||st==="HEAD"||xt.add(st)}if(he)for(const as of fe)as&&as!=="HEAD"&&xt.add(as);const Pt=ya(n);Pt&&Pt!=="HEAD"&&xt.add(Pt);const Mt=ya(_);return Mt&&Mt!=="HEAD"&&xt.add(Mt),Array.from(xt).sort((as,st)=>as.localeCompare(st))},[n,i,Ne?.name,_,fe,he]);l.useEffect(()=>{if(a.length===0){Ne&&X(null);return}(!Ne||!a.some(We=>We.name===Ne.name))&&X(rd(a,{selectedRemoteName:v?.selectedRemoteName,trackingBranch:r}))},[v?.selectedRemoteName,a,Ne,r]),l.useEffect(()=>{const We=ya(n);if(!_&&We){O(We);return}if(Me.length!==0&&!Me.includes(_)){const xt=Me.includes(We)?We:Me[0];xt&&O(xt)}},[Me,n,_]);const[Le,se]=l.useState(!1),[ie,U]=l.useState(null),[Ve,He]=l.useState(!1),[Ke,Ze]=l.useState(new Set),[Xe,dt]=l.useState(!1),[et,ct]=l.useState(null),[at,ye]=l.useState(!1),Ge=l.useRef(new Set),$e=l.useRef(null),_e=l.useRef(!1),tt=l.useRef(new Set),Qe=l.useRef([]);l.useEffect(()=>{be&&!Pe&&je(!0)},[be,Pe]),l.useEffect(()=>{he&&be?.defaultBranch&&O(be.defaultBranch)},[he,be?.defaultBranch]);const ze=xe?.pr??null,gt=ze?`${t}#${ze.number}`:null,Vt=!!(gt&&ce===gt);l.useEffect(()=>{if(!d?.prContext||!ze||typeof ze.body=="string"&&ze.body.length>0)return;const We=`${t}#${ze.number}`;if(Ge.current.has(We))return;Ge.current.add(We),Se(We);let xt=!1;return d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1}).then(Pt=>{if(xt)return;const Mt=Pt?.pr;Mt&&R(ke,as=>!as?.pr||as.pr.number!==ze.number?as:{...as,pr:{...as.pr,body:Mt.body||""}})}).catch(()=>{}).finally(()=>{xt||Se(Pt=>Pt===We?null:Pt)}),()=>{xt=!0}},[t,d,ze,ke,R]),l.useEffect(()=>{if(!ze){te(!1),we(""),ue(""),$e.current=null;return}const We=$e.current!==null&&$e.current!==ze.number;We&&te(!1),(!H||We)&&(we(ze.title||""),ue(ze.body||"")),$e.current=ze.number},[H,ze]);const Kt=l.useCallback(async()=>{if(!d?.prContext){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(ze){se(!0),Ze(new Set),He(!0);try{const We=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!0});U(We)}catch(We){const xt=We instanceof Error?We.message:String(We);q.error(c("gitView.pr.toast.loadCheckDetailsFailed"),{description:xt})}finally{He(!1)}}},[t,d,ze,c]),Jt=l.useCallback(async()=>{if(!d?.prContext){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(ze){dt(!0),ye(!0);try{const We=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1});ct(We)}catch(We){const xt=We instanceof Error?We.message:String(We);q.error(c("gitView.pr.toast.loadCommentsFailed"),{description:xt})}finally{ye(!1)}}},[t,d,ze,c]),At=l.useCallback(We=>{if(!We)return"";const xt=Date.parse(We);return Number.isFinite(xt)?new Date(xt).toLocaleString():We},[]),jt=l.useMemo(()=>{const We=p?.user?.login;return typeof We=="string"?We.trim():""},[p]),ns=l.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),ot=l.useCallback(We=>{const xt=jt.toLowerCase(),Pt=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return We.replace(Pt,(Mt,as,st)=>{const Et=`@${st}`,os=st.toLowerCase();return`${as}[${Et}](https://github.com/${os}${xt&&os===xt?"?oc-self-mention=1":""})`})},[jt]),Zt=l.useMemo(()=>{const We=(et?.issueComments??[]).map(Mt=>({id:`issue-${Mt.id}`,body:Mt.body||"",authorName:Mt.author?.name||Mt.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Mt.author?.login||null,avatarUrl:Mt.author?.avatarUrl||null,createdAt:Mt.createdAt,context:c("gitView.pr.comments.generalContext"),path:null,line:null})),xt=(et?.reviewComments??[]).map(Mt=>({id:`review-${Mt.id}`,body:Mt.body||"",authorName:Mt.author?.name||Mt.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Mt.author?.login||null,avatarUrl:Mt.author?.avatarUrl||null,createdAt:Mt.createdAt,context:c("gitView.pr.comments.reviewContext"),path:Mt.path||null,line:Mt.line??null})),Pt=[...We,...xt];return Pt.sort((Mt,as)=>{const st=Mt.createdAt?Date.parse(Mt.createdAt):0,Et=as.createdAt?Date.parse(as.createdAt):0,os=Number.isFinite(st)?st:0,rs=Number.isFinite(Et)?Et:0;return os-rs}),Pt},[et,c]),Yt=l.useCallback(()=>{if(!h)return q.error(c("gitView.pr.toast.noActiveSession"),{description:c("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:We,currentModelId:xt,currentAgentName:Pt,currentVariant:Mt}=yt.getState(),as=xc.getState().lastUsedProvider,st=We||as?.providerID,Et=xt||as?.modelID;return!st||!Et?(q.error(c("gitView.pr.toast.noModelSelected")),null):{sessionId:h,providerID:st,modelID:Et,currentAgentName:Pt??null,currentVariant:Mt??null}},[h,c]),es=l.useCallback((We,xt,Pt,Mt)=>{Ht.getState().sendMessage(xt,We.providerID,We.modelID,We.currentAgentName??void 0,void 0,void 0,[{text:Pt,synthetic:!0},{text:Mt,synthetic:!0}],We.currentVariant??void 0).catch(as=>{const st=as instanceof Error?as.message:String(as);q.error(c("gitView.pr.toast.sendMessageFailed"),{description:st})})},[c]),ls=l.useCallback(We=>{const xt=We.status||"unknown",Pt=We.conclusion??void 0,Mt=Pt?`${xt} / ${Pt}`:xt,as=We.app?.name||We.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:We.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:as?`${as} · ${Mt}`:Mt})]}),We.detailsUrl?s.jsx(ve,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:We.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(Pr,{className:"size-4"}),"Open"]})}):null]}),We.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:We.output.title}):null,We.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap",children:We.output.summary}):null,We.output?.text?s.jsx("div",{className:"rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:We.output.text}):null,Array.isArray(We.annotations)&&We.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",We.annotations.length>20?` (showing 20/${We.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:We.annotations.slice(0,20).map((st,Et)=>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:[st.title||st.level||"Issue",st.path?` · ${st.path}`:"",typeof st.startLine=="number"?`:${st.startLine}`:"",typeof st.endLine=="number"&&st.endLine!==st.startLine?`-${st.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:st.message}),st.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:st.rawDetails}):null]},`${st.path||"file"}:${st.startLine||Et}:${Et}`))})]}):null,We.job?.steps&&We.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:We.job.steps.map((st,Et)=>{const os=(st.conclusion||"").toLowerCase(),rs=os&&!["success","neutral","skipped"].includes(os),$t=`${We.id??"run"}:${We.job?.jobId??"job"}:${st.number??Et}:${st.name}`,xs=Ke.has($t);return rs?s.jsxs(wr,{open:xs,children:[s.jsxs("button",{type:"button",onClick:()=>{Ze(bn=>{const en=new Set(bn);return en.has($t)?en.delete($t):en.add($t),en})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(rs?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[xs?s.jsx(ks,{className:"size-4"}):s.jsx($n,{className:"size-4"}),s.jsx("span",{className:"truncate",children:st.name}),st.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:st.conclusion}):null]}),s.jsx(jr,{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 st.number=="number"?s.jsxs("div",{children:[c("gitView.pr.checks.stepLabel"),": ",st.number]}):null,st.status?s.jsxs("div",{children:[c("gitView.pr.checks.statusLabel"),": ",st.status]}):null,st.conclusion?s.jsxs("div",{children:[c("gitView.pr.checks.conclusionLabel"),": ",st.conclusion]}):null,st.startedAt?s.jsxs("div",{children:[c("gitView.pr.checks.startedLabel"),": ",At(st.startedAt)]}):null,st.completedAt?s.jsxs("div",{children:[c("gitView.pr.checks.completedLabel"),": ",At(st.completedAt)]}):null]})})]},$t):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:st.name}),st.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:st.conclusion}):null]},$t)})})]}):null]})},[Ke,At,c]),ds=l.useCallback(async()=>{if(y("chat"),!d?.prContext){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!ze)return;const We=Yt();if(We)try{const xt=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!0}),Mt=(xt.checkRuns??[]).filter(rs=>{const $t=typeof rs.conclusion=="string"?rs.conclusion.toLowerCase():"";return $t?!["success","neutral","skipped"].includes($t):!1});if(Mt.length===0){q.message(c("gitView.pr.toast.noFailedChecks"));return}const as=await zn("github.pr.checks.review.visible"),st=await zn("github.pr.checks.review.instructions"),Et=Mt.flatMap(rs=>(Array.isArray(rs.annotations)?rs.annotations:[]).map(xs=>({run:rs.name,level:xs.level,title:xs.title,path:xs.path,startLine:xs.startLine,endLine:xs.endLine,message:xs.message,rawDetails:xs.rawDetails}))),os=`GitHub PR failed checks (JSON)
|
|
7
|
+
${JSON.stringify({repo:xt.repo??null,pr:xt.pr??null,failedChecks:Mt,failedAnnotations:Et},null,2)}`;es(We,as,st,os)}catch(xt){const Pt=xt instanceof Error?xt.message:String(xt);q.error(c("gitView.pr.toast.loadChecksFailed"),{description:Pt})}},[t,es,d,ze,Yt,y,c]),gs=l.useCallback(async()=>{if(y("chat"),!d?.prContext){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!ze)return;const We=Yt();if(We)try{const xt=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1}),Pt=xt.issueComments??[],Mt=xt.reviewComments??[];if(Pt.length+Mt.length===0){q.message(c("gitView.pr.toast.noPrComments"));return}const st=await zn("github.pr.comments.review.visible"),Et=await zn("github.pr.comments.review.instructions"),os=`GitHub PR comments (JSON)
|
|
8
|
+
${JSON.stringify({repo:xt.repo??null,pr:xt.pr??null,issueComments:Pt,reviewComments:Mt},null,2)}`;es(We,st,Et,os)}catch(xt){const Pt=xt instanceof Error?xt.message:String(xt);q.error(c("gitView.pr.toast.loadPrCommentsFailed"),{description:Pt})}},[t,es,d,ze,Yt,y,c]),us=l.useCallback(async We=>{dt(!1),y("chat");const xt=Yt();if(!xt)return;const Pt=await zn("github.pr.comment.single.visible"),Mt=await zn("github.pr.comment.single.instructions"),as=`GitHub PR comment (JSON)
|
|
9
|
+
${JSON.stringify({repo:et?.repo??null,pr:et?.pr??ze??null,comment:We},null,2)}`;es(xt,Pt,Mt,as)},[et,es,ze,Yt,y]),Ct=l.useCallback(async We=>{await I(ke,We)},[ke,I]),Ue=l.useCallback(()=>{Qe.current.forEach(We=>{window.clearTimeout(We)}),Qe.current=v2.map(We=>window.setTimeout(()=>{Ct({force:!0,silent:!0,markInitialResolved:!0})},We))},[Ct]);l.useEffect(()=>{if(!d?.prStatus||!G||a.length<=1||_e.current||xe?.pr)return;const We=`${w}::${Ne?.name??""}`;if(tt.current.has(We))return;tt.current.add(We);const xt=S2(a,r).filter(as=>as.name!==Ne?.name);if(xt.length===0)return;let Pt=!1;return(async()=>{for(const as of xt){if(Pt)return;try{if(!(await d.prStatus(t,e,as.name))?.pr)continue;if(Pt)return;X(Et=>Et?.name===as.name?Et:as);return}catch{}}})(),()=>{Pt=!0}},[e,G,t,d,a,Ne?.name,w,xe?.pr,r]),l.useEffect(()=>{S(ke),P(ke,{directory:t,branch:e,remoteName:Ne?.name??null,canShow:G,github:d,githubAuthChecked:m,githubConnected:p?.connected??null})},[e,G,t,S,d,m,p?.connected,ke,Ne?.name,P]),l.useEffect(()=>(j(ke),()=>{C(ke)}),[ke,j,C]),l.useEffect(()=>{const We=ad.get(w)??null;A(We?.title??kp(e)),D(We?.body??""),M(We?.draft??!1),O(We?.targetBaseBranch?ya(We.targetBaseBranch):ya(n));const xt=rd(a,{selectedRemoteName:We?.selectedRemoteName,trackingBranch:r});X(Pt=>Pt?.name===xt?.name?Pt:xt)},[n,e,a,w,r]),l.useEffect(()=>{Ct({markInitialResolved:!0})},[ke,Ct]),l.useEffect(()=>{!G||!Ne?.name||Ct({force:!0,silent:!0,markInitialResolved:!0})},[G,Ct,Ne?.name]),l.useEffect(()=>{const We=xe?.resolvedRemoteName?.trim();if(!We||_e.current)return;const xt=a.find(Pt=>Pt.name===We);xt&&X(Pt=>Pt?.name===xt.name?Pt:xt)},[a,xe?.resolvedRemoteName]),l.useEffect(()=>{const We=xe?.pr?.state==="closed"||xe?.pr?.state==="merged",xt=Ee?.lastRefreshAt??0,Pt=Date.now()-xt>6e4,Mt=!We&&Pt,as=()=>{Mt&&Ct({force:!0,silent:!0})},st=()=>{document.visibilityState==="visible"&&Mt&&Ct({force:!0,silent:!0})};return window.addEventListener("focus",as),document.addEventListener("visibilitychange",st),()=>{window.removeEventListener("focus",as),document.removeEventListener("visibilitychange",st)}},[Ct,xe?.pr?.state,Ee?.lastRefreshAt]),l.useEffect(()=>{m&&p?.connected===!1&&Ct({force:!0,silent:!0,markInitialResolved:!0})},[m,p,Ct]),l.useEffect(()=>{!t||!e||ad.set(w,{title:k,body:N,draft:T,additionalContext:$,targetBaseBranch:_,selectedRemoteName:Ne?.name})},[w,k,N,T,$,_,Ne?.name,t,e]),l.useEffect(()=>{const We=Qe.current;return()=>{We.forEach(xt=>{window.clearTimeout(xt)}),Qe.current=[]}},[]);const Dt=l.useCallback(async()=>{if(!B&&t){re(!0);try{const xt={base:he&&be?.defaultBranchSha?be.defaultBranchSha:_,head:e};$&&(xt.context=$);const Pt=await Zv(t,xt);Pt.title?.trim()&&A(Pt.title.trim()),Pt.body?.trim()&&D(Pt.body.trim()),o?.()}catch(We){const xt=We instanceof Error?We.message:String(We);q.error(c("gitView.pr.toast.generateDescriptionFailed"),{description:xt})}finally{re(!1)}}},[$,e,be?.defaultBranchSha,t,B,o,_,c,he]),Tt=l.useCallback(async()=>{if(!d?.prCreate){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}const We=k.trim();if(!We){q.error(c("gitView.pr.toast.titleRequired"));return}const xt=_.trim();if(!xt){q.error(c("gitView.pr.toast.baseBranchRequired"));return}if(!he&&xt===e){q.error(c("gitView.pr.toast.baseMustDifferFromHead"));return}ee(!0);try{const Pt=Qu(r),Mt=he&&be,as=await d.prCreate({directory:t,title:We,head:e,base:xt,...N.trim()?{body:N}:{},draft:T,...Mt?{targetRepo:{owner:be.owner,repo:be.repo},headRemote:"origin"}:{...Ne?{remote:Ne.name}:{},...Pt&&Pt!==Ne?.name?{headRemote:Pt}:{}}});q.success(c("gitView.pr.toast.prCreated")),R(ke,st=>st&&{...st,pr:as}),await Ct({force:!0}),Ue()}catch(Pt){const Mt=Pt instanceof Error?Pt.message:String(Pt);q.error(c("gitView.pr.toast.createPrFailed"),{description:Mt})}finally{ee(!1)}},[N,e,be,t,T,d,ke,Ct,Ue,Ne,_,k,r,R,he,c]),wt=l.useCallback(async We=>{if(!d?.prMerge){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}E(!0);try{const xt=await d.prMerge({directory:t,number:We.number,method:L});xt.merged?q.success(c("gitView.pr.toast.prMerged")):q.message(c("gitView.pr.toast.prNotMerged"),{description:xt.message||c("gitView.pr.notMergeable")}),await Ct({force:!0}),Ue()}catch(xt){const Pt=xt instanceof Error?xt.message:String(xt);q.error(c("gitView.pr.toast.mergeFailed"),{description:Pt}),We.url&&id(We.url)}finally{E(!1)}},[t,d,L,Ct,Ue,c]),Wt=l.useCallback(async We=>{if(!d?.prReady){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}J(!0);try{await d.prReady({directory:t,number:We.number}),q.success(c("gitView.pr.toast.markedReady")),await Ct({force:!0}),Ue()}catch(xt){const Pt=xt instanceof Error?xt.message:String(xt);q.error(c("gitView.pr.toast.markReadyFailed"),{description:Pt}),We.url&&id(We.url)}finally{J(!1)}},[t,d,Ct,Ue,c]),_t=l.useCallback(async We=>{if(!d?.prUpdate){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}const xt=pe.trim();if(!xt){q.error(c("gitView.pr.toast.titleRequired"));return}ge(!0);try{const Pt=await d.prUpdate({directory:t,number:We.number,title:xt,body:W});R(ke,Mt=>Mt&&{...Mt,pr:{...Mt.pr??We,...Pt}}),te(!1),q.success(c("gitView.pr.toast.prUpdated")),await Ct({force:!0}),Ue()}catch(Pt){const Mt=Pt instanceof Error?Pt.message:String(Pt);q.error(c("gitView.pr.toast.updatePrFailed"),{description:Mt})}finally{ge(!1)}},[t,W,pe,d,ke,Ct,Ue,R,c]);if(!G)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 Vs=xe?.repo?.url||null,mt=he&&be?.url?be.url:Vs,cs=xe?.checks??null,qt=!!xe?.canMerge,Ds=!!xe?.connected,Os=m&&xe?.connected===!1,Q=y2(xe),ht=Q?`var(--pr-${Q})`:"var(--status-info)",vt=Q==="draft"?Eb:Q==="merged"?qa:Q==="closed"?Fb:Wa,zt=ze?[`${ze.state}${ze.draft?" (draft)":""}`,ze.mergeable===!1?c("gitView.pr.notMergeable"):null,ze.state==="open"&&typeof ze.mergeableState=="string"&&ze.mergeableState&&ze.mergeableState!=="unknown"?ze.mergeableState:null].filter(Boolean).join(" · "):"",ss=cs?cs.total>0?`${cs.success}/${cs.total} ${c("gitView.pr.checks.label")}`:`${cs.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:[ze?s.jsxs(St,{children:[s.jsx(kt,{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:()=>{id(ze.url)},"aria-label":c("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(vt,{className:"size-4 shrink-0",style:{color:ht}})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(vt,{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")}),ze?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",ze.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ae?s.jsx(ts,{className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(St,{children:[s.jsx(kt,{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:Ae,onClick:()=>{Ct({force:!0})},"aria-label":c("gitView.pr.actions.refreshAria"),children:s.jsx(In,{className:"size-3.5 text-muted-foreground"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.refresh")})})]})]})]}),ze?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:ht},children:zt}),cs?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${b2(cs.state)}`}),ss]}):null,r&&Ne&&r.split("/")[0]!==Ne.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",Ne.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[Os?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.githubNotConnected")}),s.jsx(ve,{variant:"outline",size:"sm",onClick:g,className:"w-fit",children:c("gitView.pr.actions.openSettings")})]}):null,V?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:V}),mt?s.jsx(ve,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:mt,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(Pr,{className:"size-4"}),"Open Repo"]})}):null]}):null,!ze&&!de&&!V&&!Os?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(ts,{className:"size-4 animate-spin"}),c("gitView.pr.checkingStatus")]}):ze?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:[H?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Bt,{value:pe,onChange:We=>we(We.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x}),s.jsx(An,{value:W,onChange:We=>ue(We.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:ze.title}),ze.body?.trim()?s.jsx(ai,{content:ze.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(Vt?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),qt&&ze.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.draftMustBeReady")}):null,qt?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:[ze.state==="open"?H?s.jsxs(s.Fragment,{children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{te(!1),we(ze.title||""),ue(ze.body||"")},disabled:ae,"aria-label":c("gitView.pr.actions.cancelEditingAria"),children:s.jsx(Is,{className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(ve,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>_t(ze),disabled:ae||!pe.trim(),"aria-label":c("gitView.pr.actions.savePrAria"),children:ae?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(Zs,{className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.savePr")})})]})]}):s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>te(!0),"aria-label":c("gitView.pr.actions.editPrAria"),children:s.jsx(ea,{className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.editPr")})})]}):null,cs?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Kt,disabled:Ve,"aria-label":c("gitView.pr.actions.openChecksAria"),children:Ve?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(Us,{className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.openChecks")})})]}):null,cs?.failure?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(ve,{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:ds,"aria-label":c("gitView.pr.actions.resolveFailedChecksAria"),children:s.jsx(Qr,{className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.resolveFailedChecks")})})]}):null,s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Jt,"aria-label":c("gitView.pr.actions.openCommentsAria"),children:s.jsx(mc,{className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.openComments")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(ve,{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:gs,"aria-label":c("gitView.pr.actions.shareCommentsAria"),children:s.jsx(Ga,{className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.shareComments")})})]}),qt&&ze.draft&&ze.state==="open"?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Wt(ze),disabled:z||ne||ae||H,"aria-label":c("gitView.pr.actions.markReadyAria"),children:z?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(wu,{className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.markReady")})})]}):null]}),s.jsx("div",{className:"ml-auto flex items-center gap-2",children:qt?s.jsxs(s.Fragment,{children:[s.jsxs(ps,{value:L,onValueChange:We=>K(We),disabled:ne||ze.state!=="open",children:[s.jsx(hs,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(ys,{})}),s.jsxs(fs,{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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(ve,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>wt(ze),disabled:ne||z||ze.state!=="open"||ze.draft||ae||H,"aria-label":c("gitView.pr.actions.mergePrAria"),children:ne?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(qa,{className:"size-4"})})}),s.jsx(It,{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:["(",he&&be?"upstream":"remote",")"]})]})]}),mt?s.jsx(ve,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:mt,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(Pr,{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(Bt,{value:k,onChange:We=>A(We.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")}),Me.length>0?s.jsxs(ps,{value:_,onValueChange:O,children:[s.jsx(hs,{className:"h-9",children:s.jsx(ys,{placeholder:c("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(fs,{children:Me.map(We=>s.jsx(Rt,{value:We,children:We},We))})]}):s.jsx(Bt,{value:_,onChange:We=>O(We.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(An,{value:N,onChange:We=>D(We.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":T,onClick:()=>M(We=>!We),onKeyDown:We=>{(We.key===" "||We.key==="Enter")&&(We.preventDefault(),M(xt=>!xt))},children:[s.jsx(bs,{size:"sm",checked:T,onChange:We=>M(We),ariaLabel:c("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:c("gitView.pr.field.draft")})]}),b?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.optional")}),s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>Ie(!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(wr,{open:Y,onOpenChange:le,children:[s.jsxs(Rr,{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:Y?c("gitView.pr.actions.hide"):$.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),s.jsx(jr,{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(An,{value:$,onChange:We=>F(We.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(Vr,{open:Z,onClose:()=>Ie(!1),title:c("gitView.pr.additionalContext.title"),footer:s.jsx(ve,{size:"sm",onClick:()=>Ie(!1),className:"w-full",children:c("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(An,{value:$,onChange:We=>F(We.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(ve,{variant:"outline",size:"sm",onClick:Dt,disabled:B||oe,children:[B?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(Ga,{className:"size-4 text-primary"}),c("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(ve,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Tt,disabled:oe||!Ds||!_.trim()||!he&&_.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:oe?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(Wa,{className:"size-4"})}),s.jsx("span",{children:c("gitView.pr.actions.createPr")})]})]})]})]}),s.jsx(ws,{open:Le,onOpenChange:se,children:s.jsxs(vs,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(Cs,{children:[s.jsxs(js,{className:"flex items-center gap-2",children:[s.jsx(Wa,{className:"h-5 w-5"}),c("gitView.pr.checkDetails.title")]}),s.jsx(Fs,{children:ze?c("gitView.pr.numberLabel",{number:ze.number}):c("gitView.pullRequest.title")})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto mt-2",children:[Ve?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(ts,{className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,Ve?null:s.jsx("div",{className:"space-y-3",children:Array.isArray(ie?.checkRuns)&&ie?.checkRuns.length>0?ie.checkRuns.map((We,xt)=>{const Pt=`${We.id??"run"}:${We.job?.jobId??"job"}:${We.name}:${xt}`;return s.jsx("div",{className:"p-1",children:ls(We)},Pt)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(ws,{open:Xe,onOpenChange:dt,children:s.jsxs(vs,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(Cs,{children:s.jsxs(js,{className:"flex items-center gap-2",children:[s.jsx(Wa,{className:"h-5 w-5"}),c("gitView.pr.comments.title"),ze?s.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.numberLabel",{number:ze.number})}):null]})}),s.jsxs(zo,{className:"mt-2 max-h-[66vh] overflow-y-auto overlay-scrollbar-target overlay-scrollbar-container",children:[at?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(ts,{className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,at?null:s.jsx("div",{className:"space-y-4",children:Zt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Zt.map((We,xt)=>{const Pt=(We.authorName||"?").charAt(0).toUpperCase(),Mt=xt===Zt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[Mt?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:We.avatarUrl?s.jsx("img",{src:We.avatarUrl,alt:We.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:Pt})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[We.authorName,We.authorLogin&&We.authorLogin!==We.authorName?` · @${We.authorLogin}`:""]}),We.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:At(We.createdAt)}):null,s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs(ve,{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:()=>{us(We)},"aria-label":c("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(Ga,{className:"size-3.5"}),c("gitView.pr.actions.sendToAgent")]})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[We.context,We.path?` · ${We.path}`:"",We.line?`:${We.line}`:""]}),s.jsx(ai,{content:ot(We.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",ns].filter(Boolean).join(" ")})]})]},We.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.comments.empty")})})]})]})})]})},I2=t=>{const e=nt.c(150),{open:n,onOpenChange:r,conflictFiles:a,directory:i,operation:o,onAbort:c,onClearState:d}=t;let p;e[0]!==a?(p=a===void 0?[]:a,e[0]=a,e[1]=p):p=e[1];const m=p,{t:u}=ut(),f=Ht(A2),y=Ht(P2),h=Hi(D2),b=Hi(T2),x=De(M2),[g,w]=l.useState(!1),[v,S]=l.useState(null),[P,j]=l.useState(null);let C,I;e[2]!==i||e[3]!==n||e[4]!==u?(C=()=>{!n||!i||(w(!0),j(null),S(null),e1(i).then(je=>{S(je)}).catch(je=>{const be=je instanceof Error?je.message:u("gitView.conflict.loadFailed");j(be)}).finally(()=>{w(!1)}))},I=[n,i,u],e[2]=i,e[3]=n,e[4]=u,e[5]=C,e[6]=I):(C=e[5],I=e[6]),l.useEffect(C,I);let R;e[7]!==v||e[8]!==i||e[9]!==o?(R=async()=>{if(!v)return null;const je=o==="merge"?"merge":"rebase",be=v.headInfo||(o==="merge"?"MERGE_HEAD":"REBASE_HEAD"),fe=o==="merge"?"git commit --no-edit":"git rebase --continue",Pe=await zn("git.conflict.resolve.visible",{operation_label:je,head_ref:be}),Be=await zn("git.conflict.resolve.instructions",{operation_label:je,directory:i,operation:o,head_info:v.headInfo||"N/A",continue_cmd:fe}),G=`${je} conflict context (JSON)
|
|
10
|
+
${JSON.stringify({directory:i,operation:v.operation,headInfo:v.headInfo,statusPorcelain:v.statusPorcelain,unmergedFiles:v.unmergedFiles,diff:v.diff},null,2)}`;return{visibleText:Pe,instructionsText:Be,payloadText:G}},e[7]=v,e[8]=i,e[9]=o,e[10]=R):R=e[10];const k=R;let A;e[11]!==c||e[12]!==r?(A=()=>{c(),r(!1)},e[11]=c,e[12]=r,e[13]=A):A=e[13];const N=A;let D;e[14]!==d||e[15]!==r?(D=()=>{d?.(),r(!1)},e[14]=d,e[15]=r,e[16]=D):D=e[16];const T=D;let M;e[17]!==k||e[18]!==y||e[19]!==d||e[20]!==r||e[21]!==x||e[22]!==h||e[23]!==b||e[24]!==u?(M=async()=>{const je=await k();if(!je){q.error(u("gitView.conflict.noDetailsAvailable"));return}if(!y){q.error(u("gitView.conflict.noActiveSession"),{description:u("gitView.conflict.noActiveSessionDescription")});return}h(je.visibleText,"replace"),b([{text:je.instructionsText,synthetic:!0},{text:je.payloadText,synthetic:!0}]),x("chat"),d?.(),r(!1)},e[17]=k,e[18]=y,e[19]=d,e[20]=r,e[21]=x,e[22]=h,e[23]=b,e[24]=u,e[25]=M):M=e[25];const $=M;let F;e[26]!==k||e[27]!==i||e[28]!==d||e[29]!==r||e[30]!==f||e[31]!==x||e[32]!==u?(F=async()=>{const je=await k();if(!je){q.error(u("gitView.conflict.noDetailsAvailable"));return}f({directoryOverride:i,initialPrompt:je.visibleText,syntheticParts:[{text:je.instructionsText,synthetic:!0},{text:je.payloadText,synthetic:!0}]}),x("chat"),d?.(),r(!1)},e[26]=k,e[27]=i,e[28]=d,e[29]=r,e[30]=f,e[31]=x,e[32]=u,e[33]=F):F=e[33];const _=F;let O,L,K,B,re,oe,ee,ae,ge,ne,E,z,J,H,te,ce,Se,pe,we,W,ue,Y;if(e[34]!==v||e[35]!==m||e[36]!==y||e[37]!==N||e[38]!==T||e[39]!==$||e[40]!==_||e[41]!==g||e[42]!==P||e[43]!==r||e[44]!==n||e[45]!==o||e[46]!==u){const je=u(o==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),be=v?.unmergedFiles||m;K=ws,ue=n,Y=r,L=vs,W="max-w-md w-[calc(100vw-2rem)]",H="flex flex-col gap-4 overflow-hidden";let fe;e[69]===Symbol.for("react.memo_cache_sentinel")?(fe=s.jsx(ju,{className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=fe):fe=e[69];const Pe=s.jsxs("div",{className:"flex items-center gap-2",children:[fe,s.jsx(js,{children:u("gitView.conflict.detectedTitle",{operation:je})})]});let Be;e[70]!==o||e[71]!==u?(Be=u("gitView.conflict.detectedDescription",{operation:o}),e[70]=o,e[71]=u,e[72]=Be):Be=e[72];let G;e[73]!==Be?(G=s.jsx(Fs,{children:Be}),e[73]=Be,e[74]=G):G=e[74],e[75]!==Pe||e[76]!==G?(te=s.jsxs(Cs,{children:[Pe,G]}),e[75]=Pe,e[76]=G,e[77]=te):te=e[77],e[78]!==g||e[79]!==u?(ce=g&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s.jsx(ts,{className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:u("gitView.conflict.loading")})]}),e[78]=g,e[79]=u,e[80]=ce):ce=e[80],e[81]!==P||e[82]!==u?(Se=P&&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:P})}),e[81]=P,e[82]=u,e[83]=Se):Se=e[83],e[84]!==be||e[85]!==u?(pe=be.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:be.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:be.map(R2)})})]}),e[84]=be,e[85]=u,e[86]=pe):pe=e[86],e[87]!==v||e[88]!==u?(we=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]=we):we=e[89],E="flex flex-col gap-2 pt-2";let ke;e[90]!==_?(ke=()=>{_()},e[90]=_,e[91]=ke):ke=e[91];const Ee=g||!v;let Ae;e[92]!==g?(Ae=g?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(zs,{className:"size-4"}),e[92]=g,e[93]=Ae):Ae=e[93];let xe;e[94]!==u?(xe=u("gitView.conflict.resolveNewSession"),e[94]=u,e[95]=xe):xe=e[95],e[96]!==ke||e[97]!==Ee||e[98]!==Ae||e[99]!==xe?(z=s.jsxs(ve,{variant:"default",onClick:ke,disabled:Ee,className:"w-full gap-2",children:[Ae,xe]}),e[96]=ke,e[97]=Ee,e[98]=Ae,e[99]=xe,e[100]=z):z=e[100];let V;e[101]!==$?(V=()=>{$()},e[101]=$,e[102]=V):V=e[102];const de=g||!v||!y;let Me;e[103]!==g?(Me=g?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(Ob,{className:"size-4"}),e[103]=g,e[104]=Me):Me=e[104];let Le;e[105]!==u?(Le=u("gitView.conflict.resolveCurrentSession"),e[105]=u,e[106]=Le):Le=e[106],e[107]!==V||e[108]!==de||e[109]!==Me||e[110]!==Le?(J=s.jsxs(ve,{variant:"outline",onClick:V,disabled:de,className:"w-full gap-2",children:[Me,Le]}),e[107]=V,e[108]=de,e[109]=Me,e[110]=Le,e[111]=J):J=e[111],ge="flex gap-2 pt-1";let se;e[112]!==u?(se=u("gitView.conflict.continueLater"),e[112]=u,e[113]=se):se=e[113],e[114]!==T||e[115]!==se?(ne=s.jsx(ve,{variant:"ghost",size:"sm",onClick:T,className:"flex-1",children:se}),e[114]=T,e[115]=se,e[116]=ne):ne=e[116],O=ve,B="destructive",re="sm",oe=N,ee="flex-1",ae=u("gitView.conflict.abortOperation",{operation:je}),e[34]=v,e[35]=m,e[36]=y,e[37]=N,e[38]=T,e[39]=$,e[40]=_,e[41]=g,e[42]=P,e[43]=r,e[44]=n,e[45]=o,e[46]=u,e[47]=O,e[48]=L,e[49]=K,e[50]=B,e[51]=re,e[52]=oe,e[53]=ee,e[54]=ae,e[55]=ge,e[56]=ne,e[57]=E,e[58]=z,e[59]=J,e[60]=H,e[61]=te,e[62]=ce,e[63]=Se,e[64]=pe,e[65]=we,e[66]=W,e[67]=ue,e[68]=Y}else O=e[47],L=e[48],K=e[49],B=e[50],re=e[51],oe=e[52],ee=e[53],ae=e[54],ge=e[55],ne=e[56],E=e[57],z=e[58],J=e[59],H=e[60],te=e[61],ce=e[62],Se=e[63],pe=e[64],we=e[65],W=e[66],ue=e[67],Y=e[68];let le;e[117]!==O||e[118]!==B||e[119]!==re||e[120]!==oe||e[121]!==ee||e[122]!==ae?(le=s.jsx(O,{variant:B,size:re,onClick:oe,className:ee,children:ae}),e[117]=O,e[118]=B,e[119]=re,e[120]=oe,e[121]=ee,e[122]=ae,e[123]=le):le=e[123];let Z;e[124]!==ge||e[125]!==ne||e[126]!==le?(Z=s.jsxs("div",{className:ge,children:[ne,le]}),e[124]=ge,e[125]=ne,e[126]=le,e[127]=Z):Z=e[127];let Ie;e[128]!==E||e[129]!==z||e[130]!==J||e[131]!==Z?(Ie=s.jsxs("div",{className:E,children:[z,J,Z]}),e[128]=E,e[129]=z,e[130]=J,e[131]=Z,e[132]=Ie):Ie=e[132];let Ne;e[133]!==H||e[134]!==te||e[135]!==ce||e[136]!==Se||e[137]!==pe||e[138]!==we||e[139]!==Ie?(Ne=s.jsxs("div",{className:H,children:[te,ce,Se,pe,we,Ie]}),e[133]=H,e[134]=te,e[135]=ce,e[136]=Se,e[137]=pe,e[138]=we,e[139]=Ie,e[140]=Ne):Ne=e[140];let X;e[141]!==L||e[142]!==W||e[143]!==Ne?(X=s.jsx(L,{className:W,children:Ne}),e[141]=L,e[142]=W,e[143]=Ne,e[144]=X):X=e[144];let he;return e[145]!==K||e[146]!==ue||e[147]!==Y||e[148]!==X?(he=s.jsx(K,{open:ue,onOpenChange:Y,children:X}),e[145]=K,e[146]=ue,e[147]=Y,e[148]=X,e[149]=he):he=e[149],he};function A2(t){return t.openNewSessionDraft}function P2(t){return t.currentSessionId}function D2(t){return t.setPendingInputText}function T2(t){return t.setPendingSyntheticParts}function M2(t){return t.setActiveMainTab}function R2(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const E2=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:a})=>{const{t:i}=ut(),[o,c]=l.useState(!0),[d,p]=l.useState(!1),m=i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),u=async()=>{p(!0);try{await a(o),e(!1)}catch(y){const h=y instanceof Error?y.message:`Failed to ${n}`;q.error(h)}finally{p(!1)}},f=()=>{d||e(!1)};return s.jsx(ws,{open:t,onOpenChange:d?void 0:e,children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ju,{className:"size-5 text-[var(--status-warning)]"}),s.jsx(js,{children:i("gitView.stash.title")})]}),s.jsx(Fs,{children:i("gitView.stash.description",{operation:n})})]}),s.jsxs("div",{className:"py-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:i("gitView.stash.thisWill")}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[s.jsx("li",{children:i("gitView.stash.stepStash")}),s.jsxs("li",{children:[i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",i(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",s.jsx("span",{className:"font-mono text-primary",children:r})]}),o&&s.jsx("li",{children:i("gitView.stash.stepRestore")})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(bs,{checked:o,onChange:c,disabled:d,ariaLabel:i("gitView.stash.restoreAria")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!d&&c(!o),children:i("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(Xs,{className:"gap-2",children:[s.jsx(ve,{variant:"ghost",size:"sm",onClick:f,disabled:d,children:i("gitView.common.cancel")}),s.jsx(ve,{variant:"default",size:"sm",onClick:u,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(ts,{className:"size-4 animate-spin"}),i("gitView.common.processing")]}):i("gitView.stash.confirmButton",{operation:m})})]})]})})},F2=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:a,hasUnresolvedConflicts:i=!1,isLoading:o=!1})=>{const{t:c}=ut(),[d,p]=l.useState(null),m=t&&t.head,u=e&&(e.headName||e.onto),f=m?"merge":u?"rebase":null;if(!f)return null;const y=async()=>{p("continue");try{await n()}finally{p(null)}},h=async()=>{p("abort");try{await r()}finally{p(null)}},b=d!==null,x=c(f==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),g=f==="merge"?qa:Qs;let w="";return t?w=t.message?c("gitView.operation.mergingMessage",{message:t.message}):c("gitView.operation.mergeInProgressWithHead",{head:t.head}):e&&(w=e.headName?c("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):c("gitView.operation.rebaseInProgress")),s.jsx("div",{className:"bg-[var(--status-warning-bg)] border border-[var(--status-warning)] rounded-lg p-3 mx-3 mt-3",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[s.jsx(g,{className:"size-4 text-[var(--status-warning)] shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:c("gitView.operation.inProgressTitle",{operation:x})}),w&&s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:w})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i&&a&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:a,disabled:b||o,className:"gap-1.5",children:[s.jsx(Td,{className:"size-4"}),c("gitView.operation.resolveWithAi")]}),d!=="continue"&&s.jsxs(ve,{variant:"ghost",size:"sm",onClick:h,disabled:b||o,className:"gap-1.5",children:[d==="abort"?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(Is,{className:"size-4"}),c("gitView.operation.abort")]}),!i&&s.jsxs(ve,{variant:"default",size:"sm",onClick:y,disabled:b||o,className:"gap-1.5",children:[d==="continue"?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(Zs,{className:"size-4"}),c("gitView.operation.continue")]})]}),i&&s.jsx("p",{className:"typography-micro text-[var(--status-warning)]",children:c("gitView.operation.resolveConflictsHint")})]})})},O2=t=>{const e=nt.c(104),{currentBranch:n,localBranches:r,remoteBranches:a,onMerge:i,onRebase:o,disabled:c,isOperating:d,operationLogs:p,onOperationComplete:m,mode:u,defaultTargetBranch:f}=t,y=c===void 0?!1:c,h=d===void 0?!1:d,b=p===void 0?[]:p,x=u===void 0?"dialog":u,{t:g}=ut(),[w,v]=l.useState(!1),[S,P]=l.useState("merge"),[j,C]=l.useState(null),[I,R]=l.useState(!1),[k,A]=l.useState(""),N=l.useRef(null),D=l.useRef(null),T=y||h,M=n||g("gitView.branch.currentBranchFallback"),$=b.length>0&&b.every(L2),F=b.some($2);let _;e[0]===Symbol.for("react.memo_cache_sentinel")?(_=()=>{D.current&&(D.current.scrollTop=D.current.scrollHeight)},e[0]=_):_=e[0],l.useEffect(_,[b]);let O;if(e[1]!==k||e[2]!==n||e[3]!==r||e[4]!==a){e:{const V=k.toLowerCase();let de;e[6]!==a?(de=new Set(a.map(B2).filter(Boolean)),e[6]=a,e[7]=de):de=e[7];const Me=de;let Le;e[8]!==n||e[9]!==Me?(Le=ie=>ie!==n&&!Me.has(ie),e[8]=n,e[9]=Me,e[10]=Le):Le=e[10];const se=r.filter(Le);if(!V){O=se;break e}O=se.filter(ie=>ie.toLowerCase().includes(V))}e[1]=k,e[2]=n,e[3]=r,e[4]=a,e[5]=O}else O=e[5];const L=O;let K;if(e[11]!==k||e[12]!==a){e:{const V=k.toLowerCase();if(!V){K=a;break e}K=a.filter(de=>de.toLowerCase().includes(V))}e[11]=k,e[12]=a,e[13]=K}else K=e[13];const B=K;let re;e[14]!==f||e[15]!==r||e[16]!==a?(re=()=>f&&(a.includes(f)||r.includes(f))?f:null,e[14]=f,e[15]=r,e[16]=a,e[17]=re):re=e[17];const oe=re;let ee;e[18]!==oe||e[19]!==v?(ee=()=>{v(!0),C(oe()),P("merge"),A("")},e[18]=oe,e[19]=v,e[20]=ee):ee=e[20];const ae=ee;let ge;e[21]===Symbol.for("react.memo_cache_sentinel")?(ge=V=>{C(V),R(!1),A("")},e[21]=ge):ge=e[21];const ne=ge;let E;e[22]!==i||e[23]!==o||e[24]!==S||e[25]!==j?(E=()=>{j&&(S==="merge"?i(j):o(j))},e[22]=i,e[23]=o,e[24]=S,e[25]=j,e[26]=E):E=e[26];const z=E;let J;e[27]!==h||e[28]!==v?(J=()=>{h||(C(null),P("merge"),A(""),v(!1))},e[27]=h,e[28]=v,e[29]=J):J=e[29];const H=J,te=()=>{h&&!$||($&&m?.(),C(null),P("merge"),A(""),v(!1))};let ce,Se;e[30]!==I?(ce=()=>{I||A("")},Se=[I],e[30]=I,e[31]=ce,e[32]=Se):(ce=e[31],Se=e[32]),l.useEffect(ce,Se);let pe,we;e[33]!==x||e[34]!==oe||e[35]!==j?(pe=()=>{x!=="inline"||j||C(oe())},we=[x,oe,j],e[33]=x,e[34]=oe,e[35]=j,e[36]=pe,e[37]=we):(pe=e[36],we=e[37]),l.useEffect(pe,we);const Y=h?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:D,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:b.map(_2)})}),$?x==="dialog"?s.jsx(Xs,{children:s.jsx(ve,{variant:"default",size:"sm",onClick:te,children:g(F?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(ve,{variant:"default",size:"sm",onClick:te,children:g(F?"gitView.common.close":"gitView.common.done")})}):null]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:g("gitView.branch.operation")}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>P("merge"),className:me("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",S==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(qa,{className:me("size-4",S==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:me("typography-ui-label",S==="merge"?"text-foreground":"text-muted-foreground"),children:g("gitView.operation.merge")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:g("gitView.branch.mergeDescription")})]}),s.jsxs("button",{type:"button",onClick:()=>P("rebase"),className:me("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",S==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Qs,{className:me("size-4",S==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:me("typography-ui-label",S==="rebase"?"text-foreground":"text-muted-foreground"),children:g("gitView.operation.rebase")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:g("gitView.branch.rebaseDescription")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:S==="merge"?g("gitView.branch.branchToMergeInto",{branch:M}):g("gitView.branch.branchToRebaseOnto")}),s.jsxs(_s,{open:I,onOpenChange:R,modal:!1,children:[s.jsx($s,{asChild:!0,children:s.jsxs(ve,{variant:"outline",size:"lg",className:"w-full justify-between",children:[s.jsx("span",{className:me("truncate",!j&&"text-muted-foreground"),children:j||g("gitView.branch.selectBranch")}),s.jsx(ks,{className:"size-4 opacity-60 shrink-0"})]})}),s.jsx(Bs,{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(oi,{className:"h-full min-h-0",children:[s.jsx(Ia,{ref:N,placeholder:g("gitView.branch.searchPlaceholder"),value:k,onValueChange:A,onKeyDown:V2}),s.jsxs(li,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(ci,{children:g("gitView.branch.empty")}),L.length>0&&s.jsx(Qn,{heading:g("gitView.branch.localBranches"),children:L.map(V=>s.jsx(On,{onSelect:()=>ne(V),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:V})},`local-${V}`))}),L.length>0&&B.length>0?s.jsx(Ka,{}):null,B.length>0&&s.jsx(Qn,{heading:g("gitView.branch.remoteBranches"),children:B.map(V=>s.jsx(On,{onSelect:()=>ne(V),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:V})},`remote-${V}`))})]})]})})]})]}),j?s.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:S==="merge"?s.jsxs(s.Fragment,{children:[g("gitView.branch.summaryMergePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})," ",g("gitView.branch.summaryMergeInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:M})]}):s.jsxs(s.Fragment,{children:[g("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:M})," ",g("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})]})})}):null,x==="dialog"?s.jsxs(Xs,{className:"gap-2 pt-1",children:[s.jsx(ve,{variant:"ghost",size:"sm",onClick:H,children:g("gitView.common.cancel")}),s.jsx(ve,{variant:"default",size:"sm",onClick:z,disabled:!j,className:"gap-1.5",children:S==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(qa,{className:"size-4"}),g("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(Qs,{className:"size-4"}),g("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(ve,{variant:"destructive",size:"sm",onClick:H,disabled:T,children:g("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(ve,{variant:"default",size:"sm",onClick:z,disabled:T||!j,children:g(S==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(x==="inline"){let V;e[38]!==g?(V=g("gitView.branch.updateTitle"),e[38]=g,e[39]=V):V=e[39];let de;e[40]!==V?(de=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:V}),e[40]=V,e[41]=de):de=e[41];let Me;e[42]!==g?(Me=g("gitView.branch.updateDescriptionPrefix"),e[42]=g,e[43]=Me):Me=e[43];let Le;e[44]!==M?(Le=s.jsx("span",{className:"font-mono text-foreground",children:M}),e[44]=M,e[45]=Le):Le=e[45];let se;e[46]!==Me||e[47]!==Le?(se=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Me," ",Le,"."]}),e[46]=Me,e[47]=Le,e[48]=se):se=e[48];let ie;e[49]!==de||e[50]!==se?(ie=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[de,se]})}),e[49]=de,e[50]=se,e[51]=ie):ie=e[51];let U;e[52]!==Y?(U=s.jsx("div",{className:"pt-3",children:Y}),e[52]=Y,e[53]=U):U=e[53];let Ve;return e[54]!==ie||e[55]!==U?(Ve=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[ie,U]}),e[54]=ie,e[55]=U,e[56]=Ve):Ve=e[56],Ve}let le;e[57]!==h?(le=h?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(qa,{className:"size-4"}),e[57]=h,e[58]=le):le=e[58];let Z;e[59]!==g?(Z=g("gitView.branch.mergeRebase"),e[59]=g,e[60]=Z):Z=e[60];let Ie;e[61]!==Z?(Ie=s.jsx("span",{children:Z}),e[61]=Z,e[62]=Ie):Ie=e[62];let Ne;e[63]!==ae||e[64]!==T||e[65]!==le||e[66]!==Ie?(Ne=s.jsx(kt,{asChild:!0,children:s.jsxs(ve,{variant:"outline",size:"sm",className:"gap-1.5",onClick:ae,disabled:T,children:[le,Ie]})}),e[63]=ae,e[64]=T,e[65]=le,e[66]=Ie,e[67]=Ne):Ne=e[67];let X;e[68]!==g?(X=g("gitView.branch.mergeRebaseTooltip"),e[68]=g,e[69]=X):X=e[69];let he;e[70]!==X?(he=s.jsx(It,{sideOffset:8,children:X}),e[70]=X,e[71]=he):he=e[71];let je;e[72]!==Ne||e[73]!==he?(je=s.jsxs(St,{children:[Ne,he]}),e[72]=Ne,e[73]=he,e[74]=je):je=e[74];let be;e[75]!==te||e[76]!==v?(be=V=>{V?v(!0):te()},e[75]=te,e[76]=v,e[77]=be):be=e[77];let fe;e[78]!==g?(fe=g("gitView.branch.updateTitle"),e[78]=g,e[79]=fe):fe=e[79];let Pe;e[80]!==fe?(Pe=s.jsx(js,{children:fe}),e[80]=fe,e[81]=Pe):Pe=e[81];let Be;e[82]!==F||e[83]!==h||e[84]!==S||e[85]!==$||e[86]!==g||e[87]!==M?(Be=h?g($?F?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":S==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):s.jsxs(s.Fragment,{children:[g("gitView.branch.dialogDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:M}),"."]}),e[82]=F,e[83]=h,e[84]=S,e[85]=$,e[86]=g,e[87]=M,e[88]=Be):Be=e[88];let G;e[89]!==Be?(G=s.jsx(Fs,{children:Be}),e[89]=Be,e[90]=G):G=e[90];let ke;e[91]!==Pe||e[92]!==G?(ke=s.jsxs(Cs,{children:[Pe,G]}),e[91]=Pe,e[92]=G,e[93]=ke):ke=e[93];let Ee;e[94]!==Y||e[95]!==ke?(Ee=s.jsxs(vs,{className:"max-w-md",children:[ke,Y]}),e[94]=Y,e[95]=ke,e[96]=Ee):Ee=e[96];let Ae;e[97]!==w||e[98]!==be||e[99]!==Ee?(Ae=s.jsx(ws,{open:w,onOpenChange:be,children:Ee}),e[97]=w,e[98]=be,e[99]=Ee,e[100]=Ae):Ae=e[100];let xe;return e[101]!==je||e[102]!==Ae?(xe=s.jsxs(s.Fragment,{children:[je,Ae]}),e[101]=je,e[102]=Ae,e[103]=xe):xe=e[103],xe};function L2(t){return t.status==="done"||t.status==="error"}function $2(t){return t.status==="error"}function B2(t){return t.slice(t.indexOf("/")+1)}function _2(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(ts,{className:"size-3.5 animate-spin text-primary"}),t.status==="done"&&s.jsx(Zs,{className:"size-3.5 text-success"}),t.status==="error"&&s.jsx(Is,{className:"size-3.5 text-destructive"}),t.status==="pending"&&s.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),s.jsx("span",{className:me("typography-micro",t.status==="error"&&"text-destructive",t.status==="done"&&"text-muted-foreground",t.status==="running"&&"text-foreground",t.status==="pending"&&"text-muted-foreground/60"),children:t.message})]},e)}function V2(t){return t.stopPropagation()}const Cp="oc.git.actionTab",z2=t=>t==="commit"||t==="branch"||t==="pr",cx="gitmojiCache",U2=1e3*60*60*24*7,dx="1",W2=40,K2=20,H2="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:"},ux=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},G2=()=>{if(typeof window>"u")return null;try{const t=localStorage.getItem(cx);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==dx||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(ux),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},q2=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:dx};localStorage.setItem(cx,JSON.stringify(e))}catch{return}},Q2=t=>Date.now()-t.fetchedAt<U2,J2=(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(p=>p.code===d)||null}const i=n.split(" ")[0],o=Ip[i];return o&&e.find(c=>c.code===o)||null},Ap=new Map,Fa=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),mx=()=>{const{t}=ut(),{git:e}=Yn(),n=ta(),[r,a]=l.useState(null),[i,o]=l.useState(!1),c=Ht(Re=>Re.currentSessionId),d=Ht(Re=>Re.newSessionDraft),p=Ht(Re=>Re.setDraftBootstrapPendingDirectory),m=Ht(Re=>Re.worktreeMetadata),u=Ht(Re=>Re.availableWorktrees),f=Fa(n),y=l.useMemo(()=>{if(!f)return;const Re=u.find(Je=>Fa(Je.path)===f);if(Re)return Re;for(const Je of m.values())if(Fa(Je.path)===f)return Je},[u,f,m]),h=l.useMemo(()=>{if(c)return m.get(c)??y;if(d?.open)return y},[c,y,d?.open,m]),{profiles:b,globalIdentity:x,defaultGitIdentityId:g,loadProfiles:w,loadGlobalIdentity:v,loadDefaultGitIdentityId:S}=ar(Sr(Re=>({profiles:Re.profiles,globalIdentity:Re.globalIdentity,defaultGitIdentityId:Re.defaultGitIdentityId,loadProfiles:Re.loadProfiles,loadGlobalIdentity:Re.loadGlobalIdentity,loadDefaultGitIdentityId:Re.loadDefaultGitIdentityId}))),P=bg(n??null),j=bc(n??null),C=dg(Re=>c?Re.getAttachment(c):void 0),I=C?t1(C):[],R=C&&!C.degraded&&!C.legacy?C.worktreeRoot??void 0:void 0,k=uN(n,h,j?.current??void 0),A=Bu(n??null),N=s1(n??null),D=n1(n??null),T=yg(n??null),M=r1(n??null),$=pn(Re=>Re.setActiveDirectory),F=pn(Re=>Re.fetchAll),_=pn(Re=>Re.ensureAll),O=pn(Re=>Re.fetchStatus),L=pn(Re=>Re.fetchBranches),K=pn(Re=>Re.fetchLog),B=pn(Re=>Re.fetchIdentity),re=pn(Re=>Re.prefetchDiffs),oe=pn(Re=>Re.setLogMaxCount),ee=De(Re=>Re.isMobile),ae=De(Re=>Re.openContextDiff),ge=De(Re=>Re.navigateToDiff),ne=De(Re=>Re.setRightSidebarOpen),E=l.useRef(null);l.useEffect(()=>{if(!n){a(null),o(!1);return}let Re=!1,Je=null;const Ye=async()=>{try{const it=await i1(n);if(Re)return;a(it.status),it.status==="pending"&&(Je=window.setTimeout(()=>{Ye()},500))}catch{Re||a(null)}};return Ye(),()=>{Re=!0,Je!==null&&window.clearTimeout(Je)}},[n]),l.useEffect(()=>{const Re=E.current;E.current=r,!(!n||!e)&&(Re==="pending"&&r==="ready"&&(o(!0),F(n,e).finally(()=>{window.setTimeout(()=>{o(!1)},1200)})),r==="failed"&&(p(null),o(!1)))},[n,F,e,p,r]);const z=Fa(d?.bootstrapPendingDirectory??null),J=!!(n&&z&&z===Fa(n)),te=!!(n&&(r==="pending"||J))||i,ce=l.useMemo(()=>n?Ap.get(n)??null:null,[n]),Se=yt(Re=>Re.settingsGitmojiEnabled),[pe,we]=l.useState(null);l.useEffect(()=>{const Re=R||k?.projectDirectory;if(!Re){we(null);return}let Je=!1;return Uo(Re).then(Ye=>{if(Je)return;const it=Ye.trim();we(it&&it!=="HEAD"?it:null)}).catch(()=>{Je||we(null)}),()=>{Je=!0}},[R,k?.projectDirectory]);const[W,ue]=l.useState(ce?.commitMessage??""),[Y,le]=l.useState([]),[Z,Ie]=l.useState(!1),Ne=l.useRef(null),[X,he]=l.useState(null),[je,be]=l.useState(!1),[fe,Pe]=l.useState(null),[Be,G]=l.useState(25),[ke,Ee]=l.useState(!1),{triggerFireworks:Ae}=iN(),xe=l.useRef(new Map),V=l.useRef(0),de=l.useCallback(()=>{V.current+=1,Ee(!0)},[]),Me=l.useCallback(()=>{V.current=Math.max(0,V.current-1),V.current===0&&Ee(!1)},[]),[Le,se]=l.useState(()=>new Set(ce?.selectedPaths??[])),[ie,U]=l.useState(!1),[Ve,He]=l.useState(new Set),[Ke,Ze]=l.useState(!1),[Xe,dt]=l.useState(0),[et,ct]=l.useState(!1),[at,ye]=l.useState(ce?.generatedHighlights??[]),Ge=l.useCallback(()=>{const Re=Ne.current;Re&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{Re.scrollTo({top:Re.scrollHeight,behavior:"smooth"})})})},[]),$e=R||k?.projectDirectory||null,_e=j?.current||null,tt=l.useMemo(()=>{const Re=j?.tracking;return Re?Re.startsWith("origin/"):!0},[j?.tracking]),Qe=l.useMemo(()=>{const Re=k?.createdFromBranch,Je=typeof Re=="string"?Re.trim():"",Ye=typeof j?.current=="string"?j.current.trim():"",it=typeof pe=="string"?pe.trim():"";return Je?Je===Ye&&Je.startsWith("opencode/")&&it.length>0&&it!==Je?it:Je:it||Ye||"HEAD"},[k?.createdFromBranch,j,pe]),ze=l.useCallback(()=>{ye([])},[]),[gt,Vt]=l.useState(new Set),[Kt,Jt]=l.useState(new Map),[At,jt]=l.useState(new Set),[ns,ot]=l.useState(null),[Zt,Yt]=l.useState(null),[es,ls]=l.useState([]),[ds,gs]=l.useState(""),[us,Ct]=l.useState(!1),Ue=l.useMemo(()=>[{id:"commit",label:t("gitView.tabs.commit"),icon:s.jsx(pc,{className:"h-3.5 w-3.5"})},{id:"branch",label:t("gitView.tabs.update"),icon:s.jsx(qa,{className:"h-3.5 w-3.5"})},{id:"pr",label:t("gitView.tabs.pr"),icon:s.jsx(Wa,{className:"h-3.5 w-3.5"})}],[t]),[Dt,Tt]=l.useState(()=>{if(typeof window>"u")return"commit";const Re=window.localStorage.getItem(Cp);return Re==="worktree"?"branch":z2(Re)?Re:"commit"}),[wt,Wt]=l.useState([]),[_t,Vs]=l.useState(null),[mt,cs]=l.useState(null),[qt,Ds]=l.useState([]),[Os,Q]=l.useState(!1),[ht,vt]=l.useState([]),[zt,ss]=l.useState("merge"),is=l.useMemo(()=>c?`openchamber.conflict:${c}`:null,[c]),Ss=l.useCallback((Re,Je,Ye)=>{if(!is||typeof window>"u")return;const it={directory:Re,conflictFiles:Je,operation:Ye};window.localStorage.setItem(is,JSON.stringify(it))},[is]),Ms=l.useCallback(()=>{!is||typeof window>"u"||window.localStorage.removeItem(is)},[is]);l.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(Cp,Dt)},[Dt]),l.useEffect(()=>{if(!is||typeof window>"u"||!n)return;const Re=window.localStorage.getItem(is);if(Re)try{const Je=JSON.parse(Re);if(Je.directory!==n){window.localStorage.removeItem(is);return}vt(Je.conflictFiles??[]),ss(Je.operation??"merge"),Q(!0)}catch{window.localStorage.removeItem(is)}},[is,n]);const[We,xt]=l.useState(!1),[Pt,Mt]=l.useState("merge"),[as,st]=l.useState(""),Et=l.useCallback(Re=>{Wn(Re).then(Je=>{if(Je.ok){q.success(t("gitView.toast.commitHashCopied"));return}q.error(t("gitView.toast.copyFailed"))})},[t]),os=l.useCallback(Re=>{Vt(Je=>{const Ye=new Set(Je);return Ye.has(Re)?Ye.delete(Re):Ye.add(Re),Ye})},[]);l.useEffect(()=>{if(!n||!e)return;const Re=Array.from(gt).filter(Je=>!Kt.has(Je)&&!At.has(Je));if(Re.length!==0){jt(Je=>{const Ye=new Set(Je);for(const it of Re)Ye.add(it);return Ye});for(const Je of Re)e.getCommitFiles(n,Je).then(Ye=>{Jt(it=>new Map(it).set(Je,Ye.files))}).catch(Ye=>{console.error("Failed to fetch commit files:",Ye),Jt(it=>new Map(it).set(Je,[]))}).finally(()=>{jt(Ye=>{const it=new Set(Ye);return it.delete(Je),it})})}},[gt,n,e,Kt,At]),l.useEffect(()=>{n&&Ap.set(n,{directory:n,selectedPaths:Array.from(Le),commitMessage:W,generatedHighlights:at})},[W,n,Le,at]),l.useEffect(()=>{w(),v(),S()},[w,v,S]),l.useEffect(()=>{if(!n||!e?.getRemoteUrl){Yt(null);return}e.getRemoteUrl(n).then(Yt).catch(()=>Yt(null))},[n,e]);const rs=l.useCallback(async()=>{if(!n||!e?.getRemotes){Wt([]);return}try{const Re=await e.getRemotes(n);Wt(Re)}catch{Wt([])}},[n,e]);l.useEffect(()=>{rs()},[rs]),l.useEffect(()=>{if(!Se){ls([]);return}let Re=!1;const Je=G2();return Je&&(ls(Je.gitmojis),Q2(Je))?()=>{Re=!0}:((async()=>{try{const it=await fetch(H2);if(!it.ok)throw new Error(`Failed to load gitmojis: ${it.statusText}`);const Ft=await it.json(),Ut=Array.isArray(Ft.gitmojis)?Ft.gitmojis.filter(ux):[];Re||(ls(Ut),q2(Ut))}catch(it){Re||console.warn("Failed to load gitmoji list:",it)}})(),()=>{Re=!0})},[Se]),l.useEffect(()=>{n&&($(n),_(n,e))},[n,$,_,e]),l.useEffect(()=>{if(n)return Tr.onGitRefreshHint(Re=>{Fa(Re.directory)===Fa(n)&&O(n,e)})},[n,O,e]);const $t=l.useCallback(async(Re=!0)=>{if(n)try{await Promise.all([O(n,e),L(n,e)])}catch(Je){if(Re){const Ye=Je instanceof Error?Je.message:t("gitView.toast.refreshRepositoryFailed");q.error(Ye)}}},[n,e,O,L,t]),xs=l.useCallback(async()=>{n&&await K(n,e,Be)},[n,e,K,Be]),bn=l.useCallback(async()=>{n&&await B(n,e)},[n,e,B]);l.useEffect(()=>{if(!n||!e?.hasLocalIdentity||P!==!0)return;const Re=typeof g=="string"?g.trim():"";if(!Re||Re==="global"||xe.current.get(n)===Re)return;let Ye=!1;return(async()=>{try{const Ft=await e.hasLocalIdentity?.(n);if(Ye||Ft===!0)return;de(),await e.setGitIdentity(n,Re),xe.current.set(n,Re),await bn()}catch(Ft){console.warn("Failed to auto-apply default git identity:",Ft)}finally{Ye||Me()}})(),()=>{Ye=!0}},[de,n,g,Me,e,P,bn]);const en=l.useMemo(()=>{if(!j)return[];const Re=j.files??[],Je=new Map;for(const Ye of Re)Je.set(Ye.path,Ye);return Array.from(Je.values()).sort((Ye,it)=>Ye.path.localeCompare(it.path))},[j]);l.useEffect(()=>{if(!n||en.length===0)return;const Re=[],Je=new Set,Ye=Ft=>{!Ft||Je.has(Ft)||(Je.add(Ft),Re.push(Ft))};if(Array.from(Le).forEach(Ye),Y.forEach(Ye),en.slice(0,K2).forEach(Ft=>Ye(Ft.path)),Re.length===0)return;const it=window.setTimeout(()=>{re(n,e,Re,{maxFiles:W2})},120);return()=>{window.clearTimeout(it)}},[en,n,e,re,Le,Y]),l.useEffect(()=>{if(!j||en.length===0){se(new Set),U(!1);return}se(Re=>{const Je=new Set,Ye=Re??new Set;for(const it of en)Ye.has(it.path)?Je.add(it.path):ie||Je.add(it.path);return Je})},[j,en,ie]);const Ws=async(Re,Je)=>{if(n){he(Re);try{const Ye=it=>{const Ft=`${it.name}/`,Ut=j?.tracking?.startsWith(Ft)?j.tracking.slice(Ft.length):void 0;return{remote:it.name,branch:Ut,rebase:!0}};if(Re==="fetch"){if(!Je)throw new Error("No remote available for fetch");await e.gitFetch(n,{remote:Je.name}),q.success(t("gitView.toast.fetchedFromRemote",{name:Je.name}))}else if(Re==="pull"){if(!Je)throw new Error("No remote available for pull");const it=await e.gitPull(n,Ye(Je));q.success(it.files.length===1?t("gitView.toast.pulledFilesSingle",{count:it.files.length,name:Je.name}):t("gitView.toast.pulledFilesPlural",{count:it.files.length,name:Je.name}))}else if(Re==="push")await e.gitPush(n),q.success(t("gitView.toast.pushedToUpstream"));else if(Re==="sync"){if(!Je)throw new Error("No remote available for sync");let it=0,Ft=!1;await e.gitFetch(n,{remote:Je.name});const Ut=await e.getGitStatus(n);if((Ut.behind??0)>0){if((Ut.files?.length??0)>0){q.error(t("gitView.toast.commitOrStashBeforeSync"));return}it=(await e.gitPull(n,Ye(Je))).files.length}((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),Ft=!0),it>0&&Ft?q.success(it===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:it,name:Je.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:it,name:Je.name})):it>0?q.success(it===1?t("gitView.toast.pulledFilesSingle",{count:it,name:Je.name}):t("gitView.toast.pulledFilesPlural",{count:it,name:Je.name})):Ft?q.success(t("gitView.toast.pushedToUpstream")):q.success(t("gitView.toast.alreadyUpToDate"))}await $t(!1),await xs()}catch(Ye){const it=Ye instanceof Error?Ye.message:t("gitView.toast.syncActionFailed",{action:Re==="sync"?t("gitView.sync.syncChanges"):Re==="pull"?t("gitView.sync.pull"):Re});q.error(it)}finally{he(null)}}},hn=l.useCallback(async Re=>{if(!n)return;const Je=Re.name.trim();if(!Je){q.error(t("gitView.toast.remoteNameRequired"));return}if(Je==="origin"){q.error(t("gitView.toast.cannotRemoveOriginRemote"));return}Vs(Je);try{await e.removeRemote(n,{remote:Je}),q.success(t("gitView.toast.removedRemote",{name:Je})),await Promise.all([$t(!1),rs()])}catch(Ye){const it=Ye instanceof Error?Ye.message:`Failed to remove ${Je}`;q.error(it)}finally{Vs(null)}},[n,e,rs,$t,t]),un=async(Re={})=>{if(!n)return;if(!W.trim()){q.error(t("gitView.toast.enterCommitMessage"));return}const Je=Array.from(Le).sort();if(Je.length===0){q.error(t("gitView.toast.selectFileToCommit"));return}const Ye=Re.pushAfter?"commitAndPush":"commit";Pe(Ye);try{if(await e.createGitCommit(n,W.trim(),{files:Je}),q.success(t("gitView.toast.commitCreated")),ue(""),se(new Set),U(!1),ze(),await $t(),Re.pushAfter){he("sync");const it=j?.tracking?.split("/")[0],Ft=Nt.find(bi=>bi.name===it)??Nt[0];if(!Ft)throw new Error("No remote available for sync");const Ut=`${Ft.name}/`,Ks=j?.tracking?.startsWith(Ut)?j.tracking.slice(Ut.length):void 0;let wn=0,dr=!1;await e.gitFetch(n,{remote:Ft.name}),((await e.getGitStatus(n)).behind??0)>0&&(wn=(await e.gitPull(n,{remote:Ft.name,branch:Ks,rebase:!0})).files.length),((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),dr=!0),wn>0&&dr?q.success(wn===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:wn,name:Ft.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:wn,name:Ft.name})):wn>0?q.success(wn===1?t("gitView.toast.pulledFilesSingle",{count:wn,name:Ft.name}):t("gitView.toast.pulledFilesPlural",{count:wn,name:Ft.name})):dr?q.success(t("gitView.toast.pushedToUpstream")):q.success(t("gitView.toast.alreadyUpToDate")),Ae(),await $t(!1)}else await $t(!1);await xs(),dt(it=>it+1)}catch(it){const Ft=it instanceof Error?it.message:t("gitView.toast.createCommitFailed");q.error(Ft)}finally{Pe(null),Re.pushAfter&&he(null)}},fn=l.useCallback(async()=>{if(n){if(Le.size===0){q.error(t("gitView.toast.selectFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:n,selectedFiles:Le.size}),ct(!0);try{const{message:Re}=await a1(n,Array.from(Le)),Je=Re.subject?.trim()??"",Ye=Array.isArray(Re.highlights)?Re.highlights:[];if(Je){let it=Je;if(Se&&es.length>0){const Ft=J2(Je,es);if(Ft){const{code:Ut,emoji:Ks}=Ft;!Je.startsWith(Ut)&&!Je.startsWith(Ks)&&(it=`${Ut} ${Je}`)}}ue(it)}ye(Ye),Ge()}catch(Re){console.error("[git-generation][browser] GitView generate handler failed",{message:Re instanceof Error?Re.message:String(Re),error:Re});const Je=Re instanceof Error?Re.message:t("gitView.toast.generateCommitMessageFailed");q.error(Je)}finally{ct(!1)}}},[n,Le,Se,es,Ge,t]),gn=Re=>Re.reason==="attention"?`${Re.attentionReason} in progress`:Re.reason==="missing"?"worktree is missing":"worktree is invalid",yn=async(Re,Je)=>{if(!n||!j)return;const Ye=Bc(C);if(Ye.length>0){q.error(t("gitView.toast.cannotCreateBranch",{reason:gn(Ye[0])}));return}const it=j.current??null,Ft=Je?.name??"origin";try{await e.createBranch(n,Re,it??"HEAD"),q.success(t("gitView.toast.createdBranch",{name:Re})),await e.checkoutBranch(n,Re);let Ut=!1;try{await e.gitPush(n,{remote:Ft,branch:Re,options:["--set-upstream"]}),Ut=!0}catch(Ks){const wn=Ks instanceof Error?Ks.message:`Unable to push new branch to ${Ft}.`;q.warning(t("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",wn]})})}await $t(),await xs(),Ut&&q.success(t("gitView.toast.upstreamSet",{branch:Re,remote:Ft}))}catch(Ut){const Ks=Ut instanceof Error?Ut.message:t("gitView.toast.createBranchFailed");throw q.error(Ks),Ut}},mn=async(Re,Je)=>{if(!n)return;const Ye=Bc(C);if(Ye.length>0){q.error(t("gitView.toast.cannotRenameBranch",{reason:gn(Ye[0])}));return}try{await e.renameBranch(n,Re,Je),q.success(t("gitView.toast.renamedBranch",{oldName:Re,newName:Je})),await $t(),await xs()}catch(it){const Ft=it instanceof Error?it.message:t("gitView.toast.renameBranchFailed",{oldName:Re,newName:Je});q.error(Ft)}},Rn=async Re=>{if(!n)return;const Je=Bc(C);if(Je.length>0){q.error(t("gitView.toast.cannotCheckout",{reason:gn(Je[0])}));return}const Ye=Re.replace(/^remotes\//,"");if(j?.current!==Ye)try{await e.checkoutBranch(n,Ye),q.success(t("gitView.toast.checkedOut",{name:Ye})),await $t(),await xs()}catch(it){const Ft=it instanceof Error?it.message:t("gitView.toast.checkoutFailed",{name:Ye});q.error(Ft)}},Fr=async Re=>{if(n){de();try{await e.setGitIdentity(n,Re.id),q.success(t("gitView.toast.appliedIdentity",{name:Re.name})),await bn()}catch(Je){const Ye=Je instanceof Error?Je.message:t("gitView.toast.applyIdentityFailed");q.error(Ye)}finally{Me()}}},Kn=l.useMemo(()=>A?.all?A.all.filter(Re=>!Re.startsWith("remotes/")).sort():[],[A]),Fe=l.useMemo(()=>A?.all?A.all.filter(Re=>Re.startsWith("remotes/")).map(Re=>Re.replace(/^remotes\//,"")).sort():[],[A]),Nt=l.useMemo(()=>{if(wt.length>0)return wt;const Re=new Set,Je=j?.tracking?.trim();Je&&Je.includes("/")&&Re.add(Je.split("/")[0]);for(const Ye of Fe){const it=Ye.indexOf("/");it>0&&Re.add(Ye.slice(0,it))}return Re.size===0&&Zt&&Re.add("origin"),Array.from(Re).map(Ye=>({name:Ye,fetchUrl:Zt??"",pushUrl:Zt??""}))},[wt,Fe,Zt,j?.tracking]),Xt=l.useMemo(()=>{const Re=new Set(Nt.map(Ft=>Ft.name)),Je=Ft=>{if(!Ft)return"";let Ut=Ft.trim();if(!Ut||Ut==="HEAD")return"";if(Kn.includes(Ut))return Ut;Ut.startsWith("refs/heads/")&&(Ut=Ut.slice(11)),Ut.startsWith("heads/")&&(Ut=Ut.slice(6)),Ut.startsWith("remotes/")&&(Ut=Ut.slice(8));const Ks=Ut.indexOf("/");if(Ks>0){const wn=Ut.slice(0,Ks);if(Re.has(wn)){const dr=Ut.slice(Ks+1).trim();dr&&(Ut=dr)}}return Ut},Ye=Je(typeof k?.createdFromBranch=="string"?k.createdFromBranch:"");if(Ye)return Ye;const it=Je(typeof pe=="string"?pe:"");return it||(Kn.includes("main")?"main":Kn.includes("master")?"master":Kn.includes("develop")?"develop":"main")},[Nt,Kn,pe,k?.createdFromBranch]),ms=l.useMemo(()=>Nt.map(Ye=>Ye.name).map(Ye=>`${Ye}/${Xt}`).find(Ye=>Fe.includes(Ye))??Xt,[Xt,Nt,Fe]),tn=l.useMemo(()=>{const Re=new Map;x&&Re.set(x.id,x);let Je=null;if(Zt)try{let Ye=Zt.trim();Ye.startsWith("git@")&&(Ye=`https://${Ye.slice(4).replace(":","/")}`),Ye.endsWith(".git")&&(Ye=Ye.slice(0,-4));const it=new URL(Ye);Je=it.hostname+it.pathname}catch{}for(const Ye of b){if(Ye.authType!=="token"){Re.set(Ye.id,Ye);continue}const it=Ye.host;if(!it){Re.set(Ye.id,Ye);continue}if(!it.includes("/")){Re.set(Ye.id,Ye);continue}Je&&Je===it&&Re.set(Ye.id,Ye)}return Array.from(Re.values())},[b,x,Zt]),sn=l.useMemo(()=>{if(D?.userName&&D?.userEmail){const Re=b.find(Je=>Je.userName===D.userName&&Je.userEmail===D.userEmail);return Re||(x&&x.userName===D.userName&&x.userEmail===D.userEmail?x:{id:"local-config",name:D.userName,userName:D.userName,userEmail:D.userEmail,sshKey:D.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return x??null},[D,b,x]),Hs=Le.size,Gs=T||X!==null||fe!==null,nn=j?.current??null,pr=!!(k&&$e&&_e&&tt),lr=!!(n&&nn),ma=!!nn,Bn=pr&&$e&&_e&&k?{repoRoot:$e,sourceBranch:_e,worktreeMetadata:k}:null,Or=l.useMemo(()=>!lr||!n||!nn?null:{directory:n,branch:nn},[lr,nn,n]);l.useEffect(()=>{if(!n||!e||!N?.all?.length||!nn||!Xt||nn===Xt){ot(null);return}let Re=!1;return(async()=>{try{const Ye=await e.getGitLog(n,{from:Xt,to:"HEAD",maxCount:Be});if(Re)return;const it=new Set((Ye?.all??[]).map(Ut=>Ut.hash).filter(Ut=>typeof Ut=="string"&&Ut.length>0));if(it.size===0){ot(null);return}const Ft=N.all.findIndex(Ut=>!it.has(Ut.hash));if(Ft===0){ot(null);return}if(Ft===-1){ot({insertBeforeIndex:N.all.length,branchName:nn,direction:"up"});return}ot({insertBeforeIndex:Ft,branchName:nn,direction:"up"})}catch{Re||ot(null)}})(),()=>{Re=!0}},[Xt,nn,n,e,N,Be]);const _n=Re=>{se(Je=>{const Ye=new Set(Je);return Ye.has(Re)?Ye.delete(Re):Ye.add(Re),Ye}),U(!0)},nr=()=>{const Re=new Set(en.map(Je=>Je.path));se(Re),U(!0)},vn=()=>{se(new Set),U(!0)},cr=l.useCallback(async Re=>{if(n){He(Je=>{const Ye=new Set(Je);return Ye.add(Re),Ye});try{await e.revertGitFile(n,Re),q.success(t("gitView.toast.revertedFile",{path:Re})),await $t(!1)}catch(Je){const Ye=Je instanceof Error?Je.message:t("gitView.toast.revertFailed");q.error(Ye)}finally{He(Je=>{const Ye=new Set(Je);return Ye.delete(Re),Ye})}}},[n,$t,e,t]),En=l.useCallback(async Re=>{if(!n||Re.length===0||Ke)return;const Je=Array.from(new Set(Re));Ze(!0),He(it=>{const Ft=new Set(it);return Je.forEach(Ut=>Ft.add(Ut)),Ft});const Ye=[];try{if(await Promise.all(Je.map(async it=>{try{await e.revertGitFile(n,it)}catch(Ft){Ye.push({path:it,message:Ft instanceof Error?Ft.message:t("gitView.toast.revertFailed")})}})),await $t(!1),Ye.length===0)q.success(Je.length===1?t("gitView.toast.revertedFilesSingle",{count:Je.length}):t("gitView.toast.revertedFilesPlural",{count:Je.length}));else if(Ye.length===Je.length)q.error(Ye[0]?.message||t("gitView.toast.revertFailed"));else{const it=Je.length-Ye.length;q.warning(it===1?t("gitView.toast.revertedSomeSingle",{success:it,failed:Ye.length}):t("gitView.toast.revertedSomePlural",{success:it,failed:Ye.length}))}}finally{He(it=>{const Ft=new Set(it);return Je.forEach(Ut=>Ft.delete(Ut)),Ft}),Ze(!1)}},[n,e,Ke,$t,t]),Ur=l.useCallback(Re=>{if(Re.length===0)return;const Je=Re.map(Ye=>Ye.trim()).filter(Boolean);if(Je.length===0){ze();return}ue(Ye=>{const it=Ye.trim(),Ft=it.length>0?`
|
|
11
|
+
|
|
12
|
+
`:"";return`${it}${Ft}${Je.join(`
|
|
13
|
+
`)}`.trim()}),ze()},[ze]),Wr=l.useCallback((Re,Je)=>{const Ye=Je||Re;ue(it=>{const Ft=it.trimStart();return Ft.startsWith(Re)||Je&&Ft.startsWith(Je)?it:`${Ye.endsWith(" ")?Ye:`${Ye} `}${it}`.trimStart()}),gs(""),Ie(!1)},[]),Pa=l.useCallback(Re=>{G(Re),n&&(oe(n,Re),K(n,e,Re))},[n,oe,K,e]),sa=l.useCallback(Re=>{const Je=Re instanceof Error?Re.message.toLowerCase():"";return Je.includes("uncommitted changes")||Je.includes("local changes")||Je.includes("your local changes would be overwritten")||Je.includes("please commit your changes or stash them")||Je.includes("cannot rebase: you have unstaged changes")||Je.includes("error: cannot pull with rebase")},[]),Hn=l.useCallback((Re,Je)=>{Ds(Ye=>[...Ye,{message:Re,status:Je,timestamp:Date.now()}])},[]),Nn=l.useCallback((Re,Je)=>{Ds(Ye=>{if(Ye.length===0)return Ye;const it=[...Ye];return it[it.length-1]={...it[it.length-1],status:Re,...Je?{message:Je}:{}},it})},[]),ln=l.useCallback(()=>{Ds([])},[]),kr=l.useCallback(()=>{Ds([]),cs(null)},[]),Kr=l.useCallback(Re=>{const Je=Re.trim(),Ye=new Set(Nt.map(Ft=>Ft.name)),it=Je.indexOf("/");if(it>0){const Ft=Je.slice(0,it),Ut=Je.slice(it+1);if(Ye.has(Ft)&&Ut)return{branch:Je,remote:Ft,remoteBranch:Ut}}for(const Ft of Nt){const Ut=`${Ft.name}/${Je}`;if(Fe.includes(Ut))return{branch:Ut,remote:Ft.name,remoteBranch:Je}}return{branch:Je,remote:null,remoteBranch:null}},[Nt,Fe]),mi=l.useCallback(async Re=>{if(!n)return;cs("merge"),ln();const Je=j?.current,Ye=Kr(Re);try{Ye.remote&&Ye.remoteBranch&&(Hn(`Fetching ${Ye.remote}/${Ye.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:Ye.remote,branch:Ye.remoteBranch}),Nn("done",`Fetched ${Ye.remote}/${Ye.remoteBranch}`)),Hn(`Merging ${Ye.branch} into ${Je}...`,"running");const it=await e.merge(n,{branch:Ye.branch});it.conflict?(Nn("error","Merge conflicts detected"),vt(it.conflictFiles??[]),ss("merge"),Q(!0),Ss(n,it.conflictFiles??[],"merge")):(Nn("done",`Merged ${Ye.branch} into ${Je}`),Ms(),Hn("Refreshing repository status...","running"),await $t(),await xs(),Nn("done","Repository status updated"))}catch(it){if(sa(it))Nn("error","Uncommitted changes detected"),Mt("merge"),st(Ye.branch),xt(!0);else{const Ft=it instanceof Error?it.message:`Failed to merge ${Ye.branch}`;Nn("error",Ft)}}},[n,e,j,Kr,$t,xs,sa,Ss,Ms,Hn,Nn,ln]),pa=l.useCallback(async Re=>{if(!n)return;cs("rebase"),ln();const Je=j?.current,Ye=Kr(Re);try{Ye.remote&&Ye.remoteBranch&&(Hn(`Fetching ${Ye.remote}/${Ye.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:Ye.remote,branch:Ye.remoteBranch}),Nn("done",`Fetched ${Ye.remote}/${Ye.remoteBranch}`)),Hn(`Rebasing ${Je} onto ${Ye.branch}...`,"running");const it=await e.rebase(n,{onto:Ye.branch});it.conflict?(Nn("error","Rebase conflicts detected"),vt(it.conflictFiles??[]),ss("rebase"),Q(!0),Ss(n,it.conflictFiles??[],"rebase")):(Nn("done",`Rebased ${Je} onto ${Ye.branch}`),Ms(),Hn("Refreshing repository status...","running"),await $t(),await xs(),Nn("done","Repository status updated"))}catch(it){if(sa(it))Nn("error","Uncommitted changes detected"),Mt("rebase"),st(Ye.branch),xt(!0);else{const Ft=it instanceof Error?it.message:`Failed to rebase onto ${Ye.branch}`;Nn("error",Ft)}}},[n,e,j,Kr,$t,xs,sa,Ss,Ms,Hn,Nn,ln]),pi=l.useCallback(async()=>{if(n)try{zt==="merge"?(await e.abortMerge(n),q.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),q.success(t("gitView.toast.rebaseAborted"))),Ms(),await $t(),await xs()}catch(Re){const Je=Re instanceof Error?Re.message:`Failed to abort ${zt}`;q.error(Je)}},[n,e,zt,$t,xs,Ms,t]),Dn=l.useMemo(()=>j?.files?j.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,[j?.files]),hi=l.useCallback(async()=>{if(n)try{const Re=!!j?.mergeInProgress?.head,Je=!!(j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto);if(Re){const Ye=await e.continueMerge(n);Ye.conflict?(vt(Ye.conflictFiles??[]),ss("merge"),Q(!0),Ss(n,Ye.conflictFiles??[],"merge"),q.error(t("gitView.toast.mergeConflictsDetected"))):(Ms(),q.success(t("gitView.toast.mergeCompleted")),await $t(),await xs())}else if(Je){const Ye=await e.continueRebase(n);Ye.conflict?(vt(Ye.conflictFiles??[]),ss("rebase"),Q(!0),Ss(n,Ye.conflictFiles??[],"rebase"),q.error(t("gitView.toast.rebaseConflictsDetected"))):(Ms(),q.success(t("gitView.toast.rebaseStepCompleted")),await $t(),await xs())}}catch(Re){const Je=Re instanceof Error?Re.message:t("gitView.toast.continueOperationFailed");q.error(Je)}},[n,e,j,$t,xs,Ss,Ms,t]),fi=l.useCallback(async()=>{if(n)try{!!j?.mergeInProgress?.head?(await e.abortMerge(n),q.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),q.success(t("gitView.toast.rebaseAborted"))),Ms(),await $t(),await xs()}catch(Re){const Je=Re instanceof Error?Re.message:t("gitView.toast.abortOperationFailed");q.error(Je)}},[n,e,j,$t,xs,Ms,t]),gi=l.useCallback(()=>{if(!n)return;const Je=!!j?.mergeInProgress?.head?"merge":"rebase",Ye=j?.files?.filter(it=>it.index==="U"||it.working_dir==="U").map(it=>it.path)??[];Ye.length>0&&vt(Ye),ss(Je),Q(!0)},[n,j]),Xn=l.useCallback(async Re=>{if(!n)return;const Je=j?.current,Ye=Pt,it=as;try{await e.stash(n,{message:`Auto-stash before ${Ye} with ${it}`,includeUntracked:!0})}catch(Ks){const wn=Ks instanceof Error?Ks.message:"Failed to stash changes";q.error(wn);return}let Ft=!1,Ut=!1;try{if(Ye==="merge"){const Ks=await e.merge(n,{branch:it});Ks.conflict?(Ut=!0,vt(Ks.conflictFiles??[]),ss("merge"),Q(!0)):(Ft=!0,q.success(t("gitView.toast.mergedIntoBranch",{branch:it,currentBranch:Je||""})))}else{const Ks=await e.rebase(n,{onto:it});Ks.conflict?(Ut=!0,vt(Ks.conflictFiles??[]),ss("rebase"),Q(!0)):(Ft=!0,q.success(t("gitView.toast.rebasedOntoBranch",{currentBranch:Je||"",branch:it})))}if(Re&&Ft)try{await e.stashPop(n),q.success(t("gitView.toast.stashedRestored"))}catch(Ks){const wn=Ks instanceof Error?Ks.message:t("gitView.toast.restoreStashFailed");q.error(wn)}else Re&&Ut&&q.info(t("gitView.toast.restoreStashManually"));await $t(),await xs()}catch(Ks){if(Re)try{await e.stashPop(n)}catch{}throw Ks}},[n,e,j,Pt,as,$t,xs,t]);return n?T&&P===null?s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(ts,{className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:t("gitView.loading.checkingRepository")})]})}):P===!1?te?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(ts,{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(Qs,{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:me("flex h-full flex-col overflow-hidden","bg-sidebar"),children:[s.jsx(DN,{status:j,localBranches:Kn,remoteBranches:Fe,branchInfo:A?.branches,syncAction:X,remotes:Nt,onFetch:Re=>Ws("fetch",Re),onSync:Re=>Ws("sync",Re),onRemoveRemote:hn,removingRemoteName:_t,onCheckoutBranch:Rn,onCreateBranch:yn,onRenameBranch:mn,activeIdentityProfile:sn,availableIdentities:tn,onSelectIdentity:Fr,isApplyingIdentity:ke,isWorktreeMode:!!k,onOpenHistory:()=>Ct(!0),actionTabItems:Ue,activeActionTab:Dt,onSelectActionTab:Re=>Tt(Re)}),n&&(j?.mergeInProgress?.head||j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto)&&s.jsx(F2,{mergeInProgress:j?.mergeInProgress,rebaseInProgress:j?.rebaseInProgress,onContinue:hi,onAbort:fi,onResolveWithAI:gi,hasUnresolvedConflicts:Dn,isLoading:T}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.jsx("div",{className:"h-full min-h-0 flex flex-col",children:s.jsx("div",{className:me("min-w-0 min-h-0 h-full flex flex-col","bg-sidebar"),children:s.jsxs(Ps,{as:zo,ref:Ne,outerClassName:"flex-1 min-h-0",className:me("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:[Dt==="commit"?s.jsx("div",{className:"space-y-4",children:(en?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx(_N,{maxListHeightClassName:"max-h-[40vh]",changeEntries:en,onVisiblePathsChange:le,selectedPaths:Le,diffStats:j?.diffStats,revertingPaths:Ve,onToggleFile:_n,onSelectAll:nr,onClearSelection:vn,onRevertAll:En,onViewDiff:Re=>{if(n&&!ee){ae(n,Re);return}ge(Re),ee&&ne(!1)},onRevertFile:cr,isRevertingAll:Ke,onOpenStashes:()=>be(!0)}),s.jsx(KN,{selectedCount:Hs,commitMessage:W,onCommitMessageChange:ue,generatedHighlights:at,onInsertHighlights:Ur,onGenerateMessage:fn,isGeneratingMessage:et,onCommit:()=>un({pushAfter:!1}),onCommitAndPush:()=>un({pushAfter:!0}),commitAction:fe,gitmojiEnabled:Se,onOpenGitmojiPicker:()=>Ie(!0)})]}):s.jsx(HN,{onOpenStashes:()=>be(!0)})}):null,Dt==="branch"?s.jsx("div",{className:"space-y-4",children:ma?s.jsxs(s.Fragment,{children:[s.jsx(O2,{mode:"inline",currentBranch:j?.current,localBranches:Kn,remoteBranches:Fe,defaultTargetBranch:ms,onMerge:mi,onRebase:pa,disabled:Gs,isOperating:mt!==null,operationLogs:qt,onOperationComplete:kr}),Bn?s.jsx(jN,{repoRoot:Bn.repoRoot,sourceBranch:Bn.sourceBranch,worktreeMetadata:Bn.worktreeMetadata,localBranches:Kn,defaultTargetBranch:Qe,refreshKey:Xe,onRefresh:()=>{n&&(O(n,e),L(n,e),K(n,e,Be))}},Bn.worktreeMetadata.path):null]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("gitView.branch.actionsUnavailable")})}):null,Dt==="pr"?s.jsx("div",{className:"space-y-4",children:Or?s.jsx(C2,{directory:Or.directory,branch:Or.branch,baseBranch:Xt,trackingBranch:j?.tracking??void 0,remotes:wt,remoteBranches:Fe,onGeneratedDescription:Ge}):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(ws,{open:us,onOpenChange:Ct,children:s.jsxs(vs,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("gitView.history.title")}),s.jsx(Fs,{children:t("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(JN,{log:N,isLogLoading:M,logMaxCount:Be,onLogMaxCountChange:Pa,expandedCommitHashes:gt,onToggleCommit:os,commitFilesMap:Kt,loadingCommitHashes:At,onCopyHash:Et,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:ns})})]})}),s.jsx(TN,{open:je,onOpenChange:be,directory:n,hasUncommittedChanges:(j?.files?.length??0)>0,uncommittedFileCount:j?.files?.length??0,onChanged:async()=>{await $t(!1),await xs()}}),s.jsx(ws,{open:Z,onOpenChange:Ie,children:s.jsxs(vs,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(Cs,{className:"px-4 pt-4",children:s.jsx(js,{children:t("gitView.gitmoji.title")})}),s.jsxs(oi,{className:"h-[420px]",children:[s.jsx(Ia,{placeholder:t("gitView.gitmoji.searchPlaceholder"),value:ds,onValueChange:gs}),s.jsxs(li,{children:[s.jsx(ci,{children:t("gitView.gitmoji.empty")}),s.jsx(Qn,{children:(es.length===0?[]:es.filter(Re=>{const Je=ds.trim().toLowerCase();return Je?Re.emoji.includes(Je)||Re.code.toLowerCase().includes(Je)||Re.description.toLowerCase().includes(Je):!0})).map(Re=>s.jsxs(On,{onSelect:()=>Wr(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(I2,{open:Os,onOpenChange:Q,conflictFiles:ht,directory:n,operation:zt,onAbort:pi,onClearState:Ms}),s.jsx(E2,{open:We,onOpenChange:xt,operation:Pt,targetBranch:as,onConfirm:Xn})]}):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")})})},Y2=Object.freeze(Object.defineProperty({__proto__:null,GitView:mx},Symbol.toStringTag,{value:"Module"})),Jd=5e3,X2=(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},Z2=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"},eS=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()},Ju=async(t,e)=>{try{const n=await eS(t,e);return X2(n,Jd)>Jd?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:Z2(n)}}},Yu=t=>t==="too-large"?`File is too large to open (>${Jd.toLocaleString()} lines)`:t==="missing"?"File not found":"Failed to open file",tS=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),tr=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},px=(t,e)=>{const n=tr(e),r=tr(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},sS=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),nS=new Set(["node_modules"]),rS=t=>nS.has(t),aS=t=>{const e=tr(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},hx=(t,e)=>s.jsx(Dr,{filePath:t,extension:e}),iS=t=>{const e=nt.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},oS=t=>{const e=nt.c(63),{node:n,root:r,isExpanded:a,isActive:i,status:o,badge:c,permissions:d,downloadFile:p,contextMenuPath:m,setContextMenuPath:u,onSelect:f,onToggle:y,onRevealPath:h,onOpenDialog:b}=t,{t:x}=ut(),g=n.type==="directory",{canRename:w,canCreateFile:v,canCreateFolder:S,canDelete:P,canReveal:j}=d;let C;e[0]!==v||e[1]!==S||e[2]!==P||e[3]!==w||e[4]!==j||e[5]!==n.path||e[6]!==u?(C=oe=>{!w&&!v&&!S&&!P&&!j||(oe?.preventDefault(),u(n.path))},e[0]=v,e[1]=S,e[2]=P,e[3]=w,e[4]=j,e[5]=n.path,e[6]=u,e[7]=C):C=e[7];const I=C;let R;e[8]!==g||e[9]!==n||e[10]!==f||e[11]!==y?(R=()=>{g?y(n.path):f(n)},e[8]=g,e[9]=n,e[10]=f,e[11]=y,e[12]=R):R=e[12];const k=R;let A;e[13]!==n.path||e[14]!==u?(A=oe=>{oe.stopPropagation(),u(n.path)},e[13]=n.path,e[14]=u,e[15]=A):A=e[15];const N=A;let D;e[16]!==n.path||e[17]!==r?(D=oe=>{const ee=px(r,n.path);!ee||ee==="."||(oe.dataTransfer.setData("application/x-openchamber-file-path",ee),oe.dataTransfer.effectAllowed="copy")},e[16]=n.path,e[17]=r,e[18]=D):D=e[18];const T=D,M=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let $;e[19]!==M?($=me("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",M,"cursor-grab active:cursor-grabbing"),e[19]=M,e[20]=$):$=e[20];let F;e[21]!==g||e[22]!==a||e[23]!==n.extension||e[24]!==n.path?(F=g?a?s.jsx(Au,{className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(Pu,{className:"h-4 w-4 flex-shrink-0 text-primary/60"}):hx(n.path,n.extension),e[21]=g,e[22]=a,e[23]=n.extension,e[24]=n.path,e[25]=F):F=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]!==g||e[30]!==o?(O=!g&&o&&s.jsx(iS,{status:o}),e[29]=g,e[30]=o,e[31]=O):O=e[31];let L;e[32]!==c||e[33]!==g?(L=g&&c&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[c.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",c.modified]}),c.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",c.added]})]}),e[32]=c,e[33]=g,e[34]=L):L=e[34];let K;e[35]!==I||e[36]!==T||e[37]!==k||e[38]!==L||e[39]!==$||e[40]!==F||e[41]!==_||e[42]!==O?(K=s.jsxs("button",{type:"button",onClick:k,onContextMenu:I,draggable:!0,onDragStart:T,className:$,children:[F,_,O,L]}),e[35]=I,e[36]=T,e[37]=k,e[38]=L,e[39]=$,e[40]=F,e[41]=_,e[42]=O,e[43]=K):K=e[43];let B;e[44]!==v||e[45]!==S||e[46]!==P||e[47]!==w||e[48]!==j||e[49]!==m||e[50]!==p||e[51]!==N||e[52]!==g||e[53]!==n||e[54]!==b||e[55]!==h||e[56]!==u||e[57]!==x?(B=(w||v||S||P||j)&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(_s,{open:m===n.path,onOpenChange:oe=>u(oe?n.path:null),children:[s.jsx($s,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:N,children:s.jsx(Tu,{className:"h-4 w-4"})})}),s.jsxs(Bs,{align:"end",side:"bottom",onCloseAutoFocus:()=>u(null),children:[w&&s.jsxs(Lt,{onClick:oe=>{oe.stopPropagation(),b("rename",n)},children:[s.jsx(ea,{className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.rename")]}),s.jsxs(Lt,{onClick:oe=>{oe.stopPropagation(),Wn(n.path).then(ee=>{if(ee.ok){q.success(x("sidebarFilesTree.toast.pathCopied"));return}q.error(x("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(vr,{className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.copyPath")]}),!g&&p&&s.jsxs(Lt,{onClick:oe=>{oe.stopPropagation(),p(n.path)},children:[s.jsx(Xr,{className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.save")]}),j&&s.jsxs(Lt,{onClick:oe=>{oe.stopPropagation(),h(n.path)},children:[s.jsx(Bf,{className:"mr-2 h-4 w-4"})," ",x(zu())]}),g&&(v||S)&&s.jsxs(s.Fragment,{children:[s.jsx(Ln,{}),v&&s.jsxs(Lt,{onClick:oe=>{oe.stopPropagation(),b("createFile",n)},children:[s.jsx(hc,{className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFile")]}),S&&s.jsxs(Lt,{onClick:oe=>{oe.stopPropagation(),b("createFolder",n)},children:[s.jsx(Aa,{className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFolder")]})]}),P&&s.jsxs(s.Fragment,{children:[s.jsx(Ln,{}),s.jsxs(Lt,{onClick:oe=>{oe.stopPropagation(),b("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(an,{className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.delete")]})]})]})]})}),e[44]=v,e[45]=S,e[46]=P,e[47]=w,e[48]=j,e[49]=m,e[50]=p,e[51]=N,e[52]=g,e[53]=n,e[54]=b,e[55]=h,e[56]=u,e[57]=x,e[58]=B):B=e[58];let re;return e[59]!==I||e[60]!==K||e[61]!==B?(re=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:I,children:[K,B]}),e[59]=I,e[60]=K,e[61]=B,e[62]=re):re=e[62],re},lS=()=>{const t=nt.c(240),{t:e}=ut(),{files:n,runtime:r}=Yn(),a=ta()??"";let i;t[0]!==a?(i=tr(a.trim()),t[0]=a,t[1]=i):i=t[1];const o=i,c=yc(),d=_u(),p=Vu(cS),m=De(dS),u=bc(a),[f,y]=l.useState(""),h=vc(f,200),b=l.useRef(null);let x;t[2]===Symbol.for("react.memo_cache_sentinel")?(x=[],t[2]=x):x=t[2];const[g,w]=l.useState(x),[v,S]=l.useState(!1);let P;t[3]===Symbol.for("react.memo_cache_sentinel")?(P={},t[3]=P):P=t[3];const[j,C]=l.useState(P);let I;t[4]===Symbol.for("react.memo_cache_sentinel")?(I=new Set,t[4]=I):I=t[4];const R=l.useRef(I);let k;t[5]===Symbol.for("react.memo_cache_sentinel")?(k=new Set,t[5]=k):k=t[5];const A=l.useRef(k);let N;t[6]===Symbol.for("react.memo_cache_sentinel")?(N=[],t[6]=N):N=t[6];const D=N;let T;t[7]===Symbol.for("react.memo_cache_sentinel")?(T=[],t[7]=T):T=t[7];const M=T;let $;t[8]!==o?($=Q=>o?Q.byRoot[o]?.expandedPaths??D:D,t[8]=o,t[9]=$):$=t[9];const F=qn($);let _;t[10]!==o?(_=Q=>o?Q.byRoot[o]?.selectedPath??null:null,t[10]=o,t[11]=_):_=t[11];const O=qn(_),L=qn(uS),K=qn(mS),B=qn(pS),re=qn(hS);let oe;t[12]!==o?(oe=Q=>o?Q.contextPanelByDirectory[o]?.tabs??M:M,t[12]=o,t[13]=oe):oe=t[13];const ee=De(oe);let ae;t[14]!==ee?(ae=new Set(ee.map(fS).filter(gS).map(xS)),t[14]=ee,t[15]=ae):ae=t[15];const ge=ae,[ne,E]=l.useState(null),[z,J]=l.useState(null),[H,te]=l.useState(null),[ce,Se]=l.useState(""),[pe,we]=l.useState(!1),W=!!n.writeFile,ue=!!n.createDirectory,Y=!!n.rename,le=!!n.delete,Z=!!n.revealPath;let Ie;t[16]!==W||t[17]!==ue||t[18]!==le||t[19]!==Y||t[20]!==Z?(Ie={canRename:Y,canCreateFile:W,canCreateFolder:ue,canDelete:le,canReveal:Z},t[16]=W,t[17]=ue,t[18]=le,t[19]=Y,t[20]=Z,t[21]=Ie):Ie=t[21];const Ne=Ie;let X;t[22]!==n||t[23]!==e?(X=Q=>{n.revealPath&&n.revealPath(Q).catch(()=>{q.error(e("sidebarFilesTree.toast.revealFailed"))})},t[22]=n,t[23]=e,t[24]=X):X=t[24];const he=X;let je;t[25]===Symbol.for("react.memo_cache_sentinel")?(je=(Q,ht)=>{J(Q),te(ht),Se(Q==="rename"&&ht.name||""),we(!1)},t[25]=je):je=t[25];const be=je;let fe;t[26]!==d||t[27]!==c?(fe=(Q,ht)=>{const vt=ht.filter(bS).filter(zt=>c||!zt.name.startsWith(".")).filter(zt=>d||!rS(zt.name)).map(zt=>{const ss=zt.name,is=tr(zt.path||""),Ss=is?sS(is)?is:tr(`${Q}/${is}`):tr(`${Q}/${ss}`),Ms=zt.isDirectory?"directory":"file",We=Ms==="file"&&ss.includes(".")?ss.split(".").pop()?.toLowerCase():void 0;return{name:ss,path:Ss,type:Ms,extension:We}});return tS(vt)},t[26]=d,t[27]=c,t[28]=fe):fe=t[28];const Pe=fe;let Be;t[29]!==n||t[30]!==Pe||t[31]!==r.isDesktop||t[32]!==d?(Be=async Q=>{const ht=tr(Q.trim());if(!ht||R.current.has(ht)||A.current.has(ht))return;A.current=new Set(A.current),A.current.add(ht);const vt=!d;await(r.isDesktop?n.listDirectory(ht,{respectGitignore:vt}).then(vS):Mn.listLocalDirectory(ht,{respectGitignore:vt}).then(jS)).then(ss=>{const is=Pe(ht,ss);R.current=new Set(R.current),R.current.add(ht),C(Ss=>({...Ss,[ht]:is}))}).catch(()=>{C(ss=>({...ss,[ht]:ss[ht]??[]}))}).finally(()=>{A.current=new Set(A.current),A.current.delete(ht)})},t[29]=n,t[30]=Pe,t[31]=r.isDesktop,t[32]=d,t[33]=Be):Be=t[33];const G=Be;let ke;t[34]!==G||t[35]!==o?(ke=async()=>{o&&(R.current=new Set,A.current=new Set,C(NS),await G(o))},t[34]=G,t[35]=o,t[36]=ke):ke=t[36];const Ee=ke;let Ae;t[37]!==G||t[38]!==Ee?(Ae=async Q=>{if(!Q){await Ee();return}const ht=tr(Q);R.current=new Set(R.current),R.current.delete(ht),A.current=new Set(A.current),A.current.delete(ht),await G(ht)},t[37]=G,t[38]=Ee,t[39]=Ae):Ae=t[39];const xe=Ae;let V;t[40]!==G||t[41]!==o?(V=()=>{o&&(R.current=new Set,A.current=new Set,C(SS),G(o))},t[40]=G,t[41]=o,t[42]=V):V=t[42];let de;t[43]!==G||t[44]!==o||t[45]!==d||t[46]!==c?(de=[G,o,c,d],t[43]=G,t[44]=o,t[45]=d,t[46]=c,t[47]=de):de=t[47],l.useEffect(V,de);let Me,Le;t[48]!==F||t[49]!==G||t[50]!==o?(Me=()=>{if(!o||F.length===0)return;const Q=F.map(kS).filter(vt=>!!vt&&vt!==o&&vt.startsWith(`${o}/`)&&!R.current.has(vt)&&!A.current.has(vt)).sort(CS);if(Q.length===0)return;let ht=!1;return(async()=>{for(let vt=0;vt<Q.length&&!ht;vt=vt+3,vt){const zt=Q.slice(vt,vt+3);await Promise.all(zt.map(ss=>G(ss)))}})(),()=>{ht=!0}},Le=[F,G,o],t[48]=F,t[49]=G,t[50]=o,t[51]=Me,t[52]=Le):(Me=t[51],Le=t[52]),l.useEffect(Me,Le);let se,ie;t[53]!==a||t[54]!==h||t[55]!==p||t[56]!==d||t[57]!==c?(se=()=>{if(!a){w([]),S(!1);return}const Q=h.trim();if(!Q){w([]),S(!1);return}let ht=!1;return S(!0),p(a,Q,150,{includeHidden:c,respectGitignore:!d,type:"file"}).then(vt=>{if(ht)return;const ss=vt.filter(is=>d||!aS(is.path)).map(IS);w(ss)}).catch(()=>{ht||w([])}).finally(()=>{ht||S(!1)}),()=>{ht=!0}},ie=[a,h,p,c,d],t[53]=a,t[54]=h,t[55]=p,t[56]=d,t[57]=c,t[58]=se,t[59]=ie):(se=t[58],ie=t[59]),l.useEffect(se,ie);let U;t[60]!==u||t[61]!==ge||t[62]!==o?(U=Q=>{if(ge.has(Q))return"open";if(u?.files){const ht=Q.startsWith(o+"/")?Q.slice(o.length+1):Q,vt=u.files.find(zt=>zt.path===ht);if(vt){if(vt.index==="A"||vt.working_dir==="?")return"git-added";if(vt.index==="D")return"git-deleted";if(vt.index==="M"||vt.working_dir==="M")return"git-modified"}}return null},t[60]=u,t[61]=ge,t[62]=o,t[63]=U):U=t[63];const Ve=U;let He;t[64]!==u||t[65]!==o?(He=Q=>{if(!u?.files)return null;const ht=Q.startsWith(o+"/")?Q.slice(o.length+1):Q,vt=ht?`${ht}/`:"";let zt=0,ss=0;for(const is of u.files)is.path.startsWith(vt)&&((is.index==="M"||is.working_dir==="M")&&zt++,(is.index==="A"||is.working_dir==="?")&&ss++);return zt+ss>0?{modified:zt,added:ss}:null},t[64]=u,t[65]=o,t[66]=He):He=t[66];const Ke=He;let Ze;t[67]!==K||t[68]!==n||t[69]!==m||t[70]!==o||t[71]!==L?(Ze=async Q=>{if(!o)return;const ht=await Ju(n,Q.path);if(!ht.ok){q.error(Yu(ht.reason));return}L(o,Q.path),K(o,Q.path),m(o,Q.path)},t[67]=K,t[68]=n,t[69]=m,t[70]=o,t[71]=L,t[72]=Ze):Ze=t[72];const Xe=Ze;let dt;t[73]!==G||t[74]!==o||t[75]!==re?(dt=async Q=>{const ht=tr(Q);o&&(re(o,ht),R.current.has(ht)||await G(ht))},t[73]=G,t[74]=o,t[75]=re,t[76]=dt):dt=t[76];const et=dt;let ct;t[77]!==z||t[78]!==H||t[79]!==ce||t[80]!==n||t[81]!==xe||t[82]!==B||t[83]!==o||t[84]!==O||t[85]!==L||t[86]!==e?(ct=async Q=>{if(Q?.preventDefault(),!H||!z)return;we(!0);const ht=()=>we(!1),vt=()=>J(null);if(z==="createFile"){if(!ce.trim()){q.error(e("sidebarFilesTree.toast.filenameRequired")),ht();return}if(!n.writeFile){q.error(e("sidebarFilesTree.toast.writeNotSupported")),ht();return}const zt=H.path,ss=zt?`${zt}/`:"",is=tr(`${ss}${ce.trim()}`);await n.writeFile(is,"").then(async Ss=>{Ss.success&&(q.success(e("sidebarFilesTree.toast.fileCreated")),await xe(zt)),vt()}).catch(()=>q.error(e("sidebarFilesTree.toast.operationFailed"))).finally(ht);return}if(z==="createFolder"){if(!ce.trim()){q.error(e("sidebarFilesTree.toast.folderNameRequired")),ht();return}const zt=H.path,ss=zt?`${zt}/`:"",is=tr(`${ss}${ce.trim()}`);await n.createDirectory(is).then(async Ss=>{Ss.success&&(q.success(e("sidebarFilesTree.toast.folderCreated")),await xe(zt)),vt()}).catch(()=>q.error(e("sidebarFilesTree.toast.operationFailed"))).finally(ht);return}if(z==="rename"){if(!ce.trim()){q.error(e("sidebarFilesTree.toast.nameRequired")),ht();return}if(!n.rename){q.error(e("sidebarFilesTree.toast.renameNotSupported")),ht();return}const zt=H.path,ss=zt.split("/").slice(0,-1).join("/"),is=ss?`${ss}/`:"",Ss=tr(`${is}${ce.trim()}`);await n.rename(zt,Ss).then(async Ms=>{Ms.success&&(q.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await xe(ss),o&&B(o,zt),(O===zt||O&&O.startsWith(`${zt}/`))&&L(o,null)),vt()}).catch(()=>q.error(e("sidebarFilesTree.toast.operationFailed"))).finally(ht);return}if(z==="delete"){if(!n.delete){q.error(e("sidebarFilesTree.toast.deleteNotSupported")),ht();return}const zt=H.path,ss=zt.split("/").slice(0,-1).join("/");await n.delete(zt).then(async is=>{is.success&&(q.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await xe(ss),o&&B(o,zt),(O===zt||O&&O.startsWith(zt+"/"))&&L(o,null)),vt()}).catch(()=>q.error(e("sidebarFilesTree.toast.operationFailed"))).finally(ht);return}ht()},t[77]=z,t[78]=H,t[79]=ce,t[80]=n,t[81]=xe,t[82]=B,t[83]=o,t[84]=O,t[85]=L,t[86]=e,t[87]=ct):ct=t[87];const at=ct;let ye,Ge,$e,_e,tt,Qe,ze;if(t[88]!==W||t[89]!==ue||t[90]!==j||t[91]!==ne||t[92]!==a||t[93]!==F||t[94]!==Ne||t[95]!==n.downloadFile||t[96]!==Ve||t[97]!==Ke||t[98]!==Xe||t[99]!==he||t[100]!==Ee||t[101]!==o||t[102]!==f||t[103]!==g||t[104]!==v||t[105]!==O||t[106]!==e||t[107]!==et){let Q=function(Et,os){const rs=j[Et]??[];return rs.map(($t,xs)=>{const bn=$t.type==="directory",en=bn&&F.includes($t.path),Ws=O===$t.path,hn=xs===rs.length-1;return s.jsxs("li",{className:"relative",children:[os>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),hn&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(oS,{node:$t,root:o,isExpanded:en,isActive:Ws,status:bn?void 0:Ve($t.path),badge:bn?Ke($t.path):void 0,permissions:Ne,downloadFile:n.downloadFile,contextMenuPath:ne,setContextMenuPath:E,onSelect:Xe,onToggle:et,onRevealPath:he,onOpenDialog:be}),bn&&en&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Q($t.path,os+1)})]},$t.path)})};const ht=!!(o&&j[o]);Qe="flex h-full min-h-0 flex-col overflow-hidden bg-sidebar";let vt;t[115]===Symbol.for("react.memo_cache_sentinel")?(vt=s.jsx(Jn,{className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),t[115]=vt):vt=t[115];let zt;t[116]===Symbol.for("react.memo_cache_sentinel")?(zt=Et=>y(Et.target.value),t[116]=zt):zt=t[116];let ss;t[117]!==e?(ss=e("sidebarFilesTree.search.placeholder"),t[117]=e,t[118]=ss):ss=t[118];let is;t[119]!==f||t[120]!==ss?(is=s.jsx(Bt,{ref:b,value:f,onChange:zt,placeholder:ss,className:"h-8 pl-8 pr-8 typography-meta"}),t[119]=f,t[120]=ss,t[121]=is):is=t[121];let Ss;t[122]!==f||t[123]!==e?(Ss=f.trim().length>0?s.jsx("button",{type:"button","aria-label":e("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{y(""),b.current?.focus()},children:s.jsx(Is,{className:"h-4 w-4"})}):null,t[122]=f,t[123]=e,t[124]=Ss):Ss=t[124];let Ms;t[125]!==is||t[126]!==Ss?(Ms=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[vt,is,Ss]}),t[125]=is,t[126]=Ss,t[127]=Ms):Ms=t[127];let We;t[128]!==W||t[129]!==a||t[130]!==e?(We=W&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>be("createFile",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(hc,{className:"h-4 w-4"})}),t[128]=W,t[129]=a,t[130]=e,t[131]=We):We=t[131];let xt;t[132]!==ue||t[133]!==a||t[134]!==e?(xt=ue&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>be("createFolder",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(Aa,{className:"h-4 w-4"})}),t[132]=ue,t[133]=a,t[134]=e,t[135]=xt):xt=t[135];let Pt;t[136]!==Ee?(Pt=()=>{Ee()},t[136]=Ee,t[137]=Pt):Pt=t[137];let Mt;t[138]!==e?(Mt=e("sidebarFilesTree.actions.refreshTitle"),t[138]=e,t[139]=Mt):Mt=t[139];let as;t[140]===Symbol.for("react.memo_cache_sentinel")?(as=s.jsx(In,{className:"h-4 w-4"}),t[140]=as):as=t[140];let st;t[141]!==Pt||t[142]!==Mt?(st=s.jsx(ve,{variant:"ghost",size:"sm",onClick:Pt,className:"h-8 w-8 p-0 flex-shrink-0",title:Mt,children:as}),t[141]=Pt,t[142]=Mt,t[143]=st):st=t[143],t[144]!==Ms||t[145]!==We||t[146]!==xt||t[147]!==st?(ze=s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[Ms,We,xt,st]}),t[144]=Ms,t[145]=We,t[146]=xt,t[147]=st,t[148]=ze):ze=t[148],ye=Ps,_e="flex-1 min-h-0",tt="p-2",Ge="flex flex-col",$e=v?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(ts,{className:"h-4 w-4 animate-spin"}),e("sidebarFilesTree.state.searching")]}):g.length>0?g.map(Et=>{const os=O===Et.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>Xe(Et),draggable:!0,onDragStart:rs=>{const $t=Et.relativePath||px(o??"",Et.path);!$t||$t==="."||(rs.dataTransfer.setData("application/x-openchamber-file-path",$t),rs.dataTransfer.effectAllowed="copy")},className:me("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors cursor-grab active:cursor-grabbing",os?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:Et.path,children:[hx(Et.path,Et.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:Et.relativePath??Et.path})]})},Et.path)}):ht&&o?Q(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("sidebarFilesTree.state.loading")}),t[88]=W,t[89]=ue,t[90]=j,t[91]=ne,t[92]=a,t[93]=F,t[94]=Ne,t[95]=n.downloadFile,t[96]=Ve,t[97]=Ke,t[98]=Xe,t[99]=he,t[100]=Ee,t[101]=o,t[102]=f,t[103]=g,t[104]=v,t[105]=O,t[106]=e,t[107]=et,t[108]=ye,t[109]=Ge,t[110]=$e,t[111]=_e,t[112]=tt,t[113]=Qe,t[114]=ze}else ye=t[108],Ge=t[109],$e=t[110],_e=t[111],tt=t[112],Qe=t[113],ze=t[114];let gt;t[149]!==Ge||t[150]!==$e?(gt=s.jsx("ul",{className:Ge,children:$e}),t[149]=Ge,t[150]=$e,t[151]=gt):gt=t[151];let Vt;t[152]!==ye||t[153]!==_e||t[154]!==tt||t[155]!==gt?(Vt=s.jsx(ye,{outerClassName:_e,className:tt,children:gt}),t[152]=ye,t[153]=_e,t[154]=tt,t[155]=gt,t[156]=Vt):Vt=t[156];const Kt=!!z;let Jt;t[157]===Symbol.for("react.memo_cache_sentinel")?(Jt=Q=>!Q&&J(null),t[157]=Jt):Jt=t[157];let At;t[158]!==z||t[159]!==e?(At=z==="createFile"&&e("sidebarFilesTree.dialog.createFile.title"),t[158]=z,t[159]=e,t[160]=At):At=t[160];let jt;t[161]!==z||t[162]!==e?(jt=z==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.title"),t[161]=z,t[162]=e,t[163]=jt):jt=t[163];let ns;t[164]!==z||t[165]!==e?(ns=z==="rename"&&e("sidebarFilesTree.dialog.rename.title"),t[164]=z,t[165]=e,t[166]=ns):ns=t[166];let ot;t[167]!==z||t[168]!==e?(ot=z==="delete"&&e("sidebarFilesTree.dialog.delete.title"),t[167]=z,t[168]=e,t[169]=ot):ot=t[169];let Zt;t[170]!==At||t[171]!==jt||t[172]!==ns||t[173]!==ot?(Zt=s.jsxs(js,{children:[At,jt,ns,ot]}),t[170]=At,t[171]=jt,t[172]=ns,t[173]=ot,t[174]=Zt):Zt=t[174];let Yt;t[175]!==z||t[176]!==H?.path||t[177]!==e?(Yt=z==="createFile"&&e("sidebarFilesTree.dialog.createFile.description",{path:H?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[175]=z,t[176]=H?.path,t[177]=e,t[178]=Yt):Yt=t[178];let es;t[179]!==z||t[180]!==H?.path||t[181]!==e?(es=z==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.description",{path:H?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[179]=z,t[180]=H?.path,t[181]=e,t[182]=es):es=t[182];let ls;t[183]!==z||t[184]!==H?.name||t[185]!==e?(ls=z==="rename"&&e("sidebarFilesTree.dialog.rename.description",{name:H?.name??""}),t[183]=z,t[184]=H?.name,t[185]=e,t[186]=ls):ls=t[186];let ds;t[187]!==z||t[188]!==H?.name||t[189]!==e?(ds=z==="delete"&&e("sidebarFilesTree.dialog.delete.description",{name:H?.name??""}),t[187]=z,t[188]=H?.name,t[189]=e,t[190]=ds):ds=t[190];let gs;t[191]!==Yt||t[192]!==es||t[193]!==ls||t[194]!==ds?(gs=s.jsxs(Fs,{children:[Yt,es,ls,ds]}),t[191]=Yt,t[192]=es,t[193]=ls,t[194]=ds,t[195]=gs):gs=t[195];let us;t[196]!==Zt||t[197]!==gs?(us=s.jsxs(Cs,{children:[Zt,gs]}),t[196]=Zt,t[197]=gs,t[198]=us):us=t[198];let Ct;t[199]!==z||t[200]!==ce||t[201]!==at||t[202]!==e?(Ct=z!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Bt,{value:ce,onChange:Q=>Se(Q.target.value),placeholder:e(z==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:Q=>{Q.key==="Enter"&&at()},autoFocus:!0})}),t[199]=z,t[200]=ce,t[201]=at,t[202]=e,t[203]=Ct):Ct=t[203];let Ue;t[204]===Symbol.for("react.memo_cache_sentinel")?(Ue=()=>J(null),t[204]=Ue):Ue=t[204];let Dt;t[205]!==e?(Dt=e("sidebarFilesTree.dialog.cancel"),t[205]=e,t[206]=Dt):Dt=t[206];let Tt;t[207]!==pe||t[208]!==Dt?(Tt=s.jsx(ve,{variant:"outline",onClick:Ue,disabled:pe,children:Dt}),t[207]=pe,t[208]=Dt,t[209]=Tt):Tt=t[209];const wt=z==="delete"?"destructive":"default";let Wt;t[210]!==at?(Wt=()=>{at()},t[210]=at,t[211]=Wt):Wt=t[211];let _t;t[212]!==z||t[213]!==ce||t[214]!==pe?(_t=pe||z!=="delete"&&!ce.trim(),t[212]=z,t[213]=ce,t[214]=pe,t[215]=_t):_t=t[215];let Vs;t[216]!==z||t[217]!==pe||t[218]!==e?(Vs=pe?s.jsx(ts,{className:"animate-spin"}):e(z==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm"),t[216]=z,t[217]=pe,t[218]=e,t[219]=Vs):Vs=t[219];let mt;t[220]!==wt||t[221]!==Wt||t[222]!==_t||t[223]!==Vs?(mt=s.jsx(ve,{variant:wt,onClick:Wt,disabled:_t,children:Vs}),t[220]=wt,t[221]=Wt,t[222]=_t,t[223]=Vs,t[224]=mt):mt=t[224];let cs;t[225]!==Tt||t[226]!==mt?(cs=s.jsxs(Xs,{children:[Tt,mt]}),t[225]=Tt,t[226]=mt,t[227]=cs):cs=t[227];let qt;t[228]!==us||t[229]!==Ct||t[230]!==cs?(qt=s.jsxs(vs,{children:[us,Ct,cs]}),t[228]=us,t[229]=Ct,t[230]=cs,t[231]=qt):qt=t[231];let Ds;t[232]!==Kt||t[233]!==qt?(Ds=s.jsx(ws,{open:Kt,onOpenChange:Jt,children:qt}),t[232]=Kt,t[233]=qt,t[234]=Ds):Ds=t[234];let Os;return t[235]!==Qe||t[236]!==ze||t[237]!==Vt||t[238]!==Ds?(Os=s.jsxs("section",{className:Qe,children:[ze,Vt,Ds]}),t[235]=Qe,t[236]=ze,t[237]=Vt,t[238]=Ds,t[239]=Os):Os=t[239],Os};function cS(t){return t.searchFiles}function dS(t){return t.openContextFile}function uS(t){return t.setSelectedPath}function mS(t){return t.addOpenPath}function pS(t){return t.removeOpenPathsByPrefix}function hS(t){return t.toggleExpandedPath}function fS(t){return t.mode==="file"?t.targetPath:null}function gS(t){return typeof t=="string"&&t.length>0}function xS(t){return tr(t)}function bS(t){return t&&typeof t.name=="string"&&t.name.length>0}function yS(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function vS(t){return t.entries.map(yS)}function wS(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function jS(t){return t.map(wS)}function NS(t){return Object.keys(t).length===0?t:{}}function SS(t){return Object.keys(t).length===0?t:{}}function kS(t){return tr(t)}function CS(t,e){return t.split("/").length-e.split("/").length}function IS(t){return{name:t.name,path:tr(t.path),type:"file",extension:t.extension,relativePath:t.relativePath}}function AS(t,e){const n=nt.c(6),{git:r}=Yn(),a=pn(PS);let i,o;n[0]!==t||n[1]!==a||n[2]!==r||n[3]!==e?(i=()=>{if(!t||!r||!e)return;a(t,r);const c=setInterval(()=>{typeof document<"u"&&document.hidden||a(t,r)},1e4);return()=>clearInterval(c)},o=[t,r,e,a],n[0]=t,n[1]=a,n[2]=r,n[3]=e,n[4]=i,n[5]=o):(i=n[4],o=n[5]),l.useEffect(i,o)}function PS(t){return t.ensureStatus}const DS=()=>{const t=nt.c(17),e=Es(MS),n=Es(RS),r=qs(ES),a=pn(FS);let i;e:{if(e){let h;t[0]!==e||t[1]!==n?(h=n.find(b=>b.id===e)??n[0]??null,t[0]=e,t[1]=n,t[2]=h):h=t[2],i=h;break e}i=n[0]??null}const o=i;let c;e:{if(!o){c=null;break e}let h;t[3]!==o.id||t[4]!==o.path?(h={id:o.id,path:o.path},t[3]=o.id,t[4]=o.path,t[5]=h):h=t[5],c=h}const d=c;let p;e:{if(!o){p=null;break e}let h;t[6]!==o.label||t[7]!==o.path||t[8]!==r?(h=o.label?.trim()||ii(o.path,r)||o.path,t[6]=o.label,t[7]=o.path,t[8]=r,t[9]=h):h=t[9],p=h}const m=p;let u;e:{if(!o){u=!1;break e}let h;t[10]!==o.path||t[11]!==a?(h=a.get(o.path)?.isGitRepo,t[10]=o.path,t[11]=a,t[12]=h):h=t[12],u=h===!0}const f=u;let y;return t[13]!==f||t[14]!==m||t[15]!==d?(y=s.jsx("div",{className:"h-full min-h-0 overflow-auto bg-sidebar",children:s.jsx(Y0,{projectRef:d,projectLabel:m,canCreateWorktree:f})}),t[13]=f,t[14]=m,t[15]=d,t[16]=y):y=t[16],y},TS=()=>{const t=nt.c(38),{t:e}=ut(),n=De(OS),r=De(LS),a=De($S),i=ta();AS(i,a);let o;t[0]!==e?(o=e("layout.rightSidebar.git"),t[0]=e,t[1]=o):o=t[1];let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Qs,{className:"h-3.5 w-3.5"}),t[2]=c):c=t[2];let d;t[3]!==o?(d={id:"git",label:o,icon:c},t[3]=o,t[4]=d):d=t[4];let p;t[5]!==e?(p=e("layout.rightSidebar.files"),t[5]=e,t[6]=p):p=t[6];let m;t[7]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Lb,{className:"h-3.5 w-3.5"}),t[7]=m):m=t[7];let u;t[8]!==p?(u={id:"files",label:p,icon:m},t[8]=p,t[9]=u):u=t[9];let f;t[10]!==e?(f=e("layout.rightSidebar.context"),t[10]=e,t[11]=f):f=t[11];let y;t[12]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx($b,{className:"h-3.5 w-3.5"}),t[12]=y):y=t[12];let h;t[13]!==f?(h={id:"context",label:f,icon:y},t[13]=f,t[14]=h):h=t[14];let b;t[15]!==d||t[16]!==u||t[17]!==h?(b=[d,u,h],t[15]=d,t[16]=u,t[17]=h,t[18]=b):b=t[18];const x=b;let g;t[19]!==r?(g=I=>r(I),t[19]=r,t[20]=g):g=t[20];let w;t[21]!==n||t[22]!==g||t[23]!==x?(w=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx(zr,{items:x,activeId:n,onSelect:g,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[21]=n,t[22]=g,t[23]=x,t[24]=w):w=t[24];let v;t[25]!==n?(v=n==="git"&&s.jsx(mx,{}),t[25]=n,t[26]=v):v=t[26];let S;t[27]!==n?(S=n==="files"&&s.jsx(lS,{}),t[27]=n,t[28]=S):S=t[28];let P;t[29]!==n?(P=n==="context"&&s.jsx(DS,{}),t[29]=n,t[30]=P):P=t[30];let j;t[31]!==v||t[32]!==S||t[33]!==P?(j=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[v,S,P]}),t[31]=v,t[32]=S,t[33]=P,t[34]=j):j=t[34];let C;return t[35]!==w||t[36]!==j?(C=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[w,j]}),t[35]=w,t[36]=j,t[37]=C):C=t[37],C};function MS(t){return t.activeProjectId}function RS(t){return t.projects}function ES(t){return t.homeDirectory}function FS(t){return t.directories}function OS(t){return t.rightSidebarTab}function LS(t){return t.setRightSidebarTab}function $S(t){return t.isRightSidebarOpen}function fx(t){const e=nt.c(63),{draft:n,onEdit:r,onDelete:a,className:i,maxWidth:o}=t,{t:c}=ut(),p=wc()?.currentTheme,[m,u]=Oe.useState(!1),f=typeof n.text=="string"?n.text:"";let y;e[0]!==f?(y=f.length>150||f.split(`
|
|
14
|
+
`).length>3,e[0]=f,e[1]=y):y=e[1];const h=y;let b;e[2]!==i?(b=me("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden transition-all duration-200",i),e[2]=i,e[3]=b):b=e[3];const x=p?.colors?.surface?.elevated,g=p?.colors?.interactive?.border,w=o?`${Math.max(200,Math.floor(o))}px`:void 0;let v;e[4]!==x||e[5]!==g||e[6]!==w?(v={backgroundColor:x,borderColor:g,maxWidth:w},e[4]=x,e[5]=g,e[6]=w,e[7]=v):v=e[7];let S;e[8]!==n.fileLabel?(S=s.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),e[8]=n.fileLabel,e[9]=S):S=e[9];let P;e[10]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx("span",{children:"•"}),e[10]=P):P=e[10];let j;e[11]!==n.endLine||e[12]!==n.startLine||e[13]!==c?(j=c("inlineComment.range.lines",{start:n.startLine,end:n.endLine}),e[11]=n.endLine,e[12]=n.startLine,e[13]=c,e[14]=j):j=e[14];let C;e[15]!==j?(C=s.jsx("span",{children:j}),e[15]=j,e[16]=C):C=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 R;e[19]!==C||e[20]!==I||e[21]!==S?(R=s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[S,P,C,I]}),e[19]=C,e[20]=I,e[21]=S,e[22]=R):R=e[22];const k=m||!h,A=!m&&h&&"line-clamp-3";let N;e[23]!==A?(N=me("text-sm whitespace-pre-wrap break-words leading-relaxed",A),e[23]=A,e[24]=N):N=e[24];let D;e[25]!==f||e[26]!==N?(D=s.jsx("div",{className:N,children:f}),e[25]=f,e[26]=N,e[27]=D):D=e[27];let T;e[28]!==h||e[29]!==m||e[30]!==c?(T=h&&s.jsx(Rr,{asChild:!0,children:s.jsx(ve,{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(Du,{className:"size-3 mr-1"}),c("inlineComment.actions.showLess")]}):s.jsxs(s.Fragment,{children:[s.jsx(ks,{className:"size-3 mr-1"}),c("inlineComment.actions.showMore")]})})}),e[28]=h,e[29]=m,e[30]=c,e[31]=T):T=e[31];let M;e[32]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(jr,{}),e[32]=M):M=e[32];let $;e[33]!==k||e[34]!==D||e[35]!==T?($=s.jsxs(wr,{open:k,onOpenChange:u,children:[D,T,M]}),e[33]=k,e[34]=D,e[35]=T,e[36]=$):$=e[36];let F;e[37]!==R||e[38]!==$?(F=s.jsxs("div",{className:"flex-1 min-w-0",children:[R,$]}),e[37]=R,e[38]=$,e[39]=F):F=e[39];let _;e[40]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx($s,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:s.jsx(Bb,{className:"size-4"})})}),e[40]=_):_=e[40];let O;e[41]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(ea,{className:"size-4 mr-2"}),e[41]=O):O=e[41];let L;e[42]!==c?(L=c("inlineComment.actions.editComment"),e[42]=c,e[43]=L):L=e[43];let K;e[44]!==r||e[45]!==L?(K=s.jsxs(Lt,{onClick:r,children:[O,L]}),e[44]=r,e[45]=L,e[46]=K):K=e[46];let B;e[47]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(an,{className:"size-4 mr-2"}),e[47]=B):B=e[47];let re;e[48]!==c?(re=c("inlineComment.actions.deleteComment"),e[48]=c,e[49]=re):re=e[49];let oe;e[50]!==a||e[51]!==re?(oe=s.jsxs(Lt,{onClick:a,className:"text-destructive",children:[B,re]}),e[50]=a,e[51]=re,e[52]=oe):oe=e[52];let ee;e[53]!==K||e[54]!==oe?(ee=s.jsxs(_s,{children:[_,s.jsxs(Bs,{align:"end",children:[K,oe]})]}),e[53]=K,e[54]=oe,e[55]=ee):ee=e[55];let ae;e[56]!==F||e[57]!==ee?(ae=s.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[F,ee]}),e[56]=F,e[57]=ee,e[58]=ae):ae=e[58];let ge;return e[59]!==b||e[60]!==ae||e[61]!==v?(ge=s.jsx("div",{className:b,style:v,"data-comment-card":"true",children:ae}),e[59]=b,e[60]=ae,e[61]=v,e[62]=ge):ge=e[62],ge}function nc(t){const e=nt.c(57),{initialText:n,onSave:r,onCancel:a,fileLabel:i,lineRange:o,isEditing:c,className:d,maxWidth:p}=t,m=n===void 0?"":n,u=c===void 0?!1:c,{t:f}=ut(),h=wc()?.currentTheme,{isMobile:b}=dn(),[x,g]=l.useState(m),w=Oe.useRef(null),v=Oe.useRef(o);let S,P;e[0]!==o?(S=()=>{o&&(v.current=o)},P=[o],e[0]=o,e[1]=S,e[2]=P):(S=e[1],P=e[2]),Oe.useEffect(S,P);const j=KS,C=j(o);let I,R;e[3]!==b?(I=()=>{const ue=w.current;if(!ue)return;const Y=ue.closest(".overlay-scrollbar-container"),le=Y?.scrollTop??window.scrollY,Z=Y?.scrollLeft??window.scrollX;if(b){ue.scrollIntoView({behavior:"auto",block:"nearest"});try{ue.focus({preventScroll:!0})}catch{ue.focus()}return}try{ue.focus({preventScroll:!0})}catch{ue.focus()}const Ie=ue.value.length;try{ue.setSelectionRange(Ie,Ie)}catch{}requestAnimationFrame(()=>{Y?(Y.scrollTop=le,Y.scrollLeft=Z):window.scrollTo({top:le,left:Z})})},R=[b],e[3]=b,e[4]=I,e[5]=R):(I=e[4],R=e[5]),Oe.useEffect(I,R);let k;e[6]!==a||e[7]!==r||e[8]!==x?(k=ue=>{(ue.metaKey||ue.ctrlKey)&&ue.key==="Enter"?(ue.preventDefault(),x.trim()&&r(x,j(v.current))):ue.key==="Escape"&&(ue.preventDefault(),a())},e[6]=a,e[7]=r,e[8]=x,e[9]=k):k=e[9];const A=k;let N;e[10]!==r||e[11]!==x?(N=ue=>{ue.stopPropagation(),x.trim()&&r(x,j(v.current))},e[10]=r,e[11]=x,e[12]=N):N=e[12];const D=N;let T;e[13]!==d?(T=me("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden animate-in fade-in zoom-in-95 duration-200",d),e[13]=d,e[14]=T):T=e[14];const M=h?.colors?.surface?.elevated,$=h?.colors?.interactive?.border,F=p?`${Math.max(200,Math.floor(p))}px`:void 0;let _;e[15]!==M||e[16]!==$||e[17]!==F?(_={backgroundColor:M,borderColor:$,maxWidth:F},e[15]=M,e[16]=$,e[17]=F,e[18]=_):_=e[18];const O="true",L=WS,K=US,B="p-3",re=(i||o)&&s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2",children:[i&&s.jsx("span",{className:"truncate max-w-[200px]",children:i}),i&&o&&s.jsx("span",{children:"•"}),C&&s.jsx("span",{children:f("inlineComment.range.lines",{start:C.start,end:C.end})})]});let oe;e[19]===Symbol.for("react.memo_cache_sentinel")?(oe=ue=>g(ue.target.value),e[19]=oe):oe=e[19];let ee;e[20]!==f?(ee=f("inlineComment.input.placeholder"),e[20]=f,e[21]=ee):ee=e[21];let ae;e[22]!==A||e[23]!==ee||e[24]!==x?(ae=s.jsx(An,{simple:!0,ref:w,value:x,onChange:oe,onKeyDown:A,placeholder:ee,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]=A,e[23]=ee,e[24]=x,e[25]=ae):ae=e[25];let ge;e[26]!==f?(ge=f("inlineComment.actions.cancel"),e[26]=f,e[27]=ge):ge=e[27];let ne;e[28]!==a||e[29]!==ge?(ne=s.jsx(ve,{variant:"ghost",size:"sm",onClick:a,onPointerDown:zS,onTouchStart:VS,className:"h-8 text-muted-foreground hover:text-foreground",children:ge}),e[28]=a,e[29]=ge,e[30]=ne):ne=e[30];let E;e[31]!==x?(E=x.trim(),e[31]=x,e[32]=E):E=e[32];const z=!E,J=h?.colors?.status?.success,H=h?.colors?.status?.successForeground;let te;e[33]!==J||e[34]!==H?(te={backgroundColor:J,color:H},e[33]=J,e[34]=H,e[35]=te):te=e[35];let ce;e[36]!==u||e[37]!==f?(ce=f(u?"inlineComment.actions.save":"inlineComment.actions.comment"),e[36]=u,e[37]=f,e[38]=ce):ce=e[38];let Se;e[39]!==D||e[40]!==z||e[41]!==te||e[42]!==ce?(Se=s.jsx(ve,{size:"sm",onClick:D,onPointerDown:_S,onTouchStart:BS,disabled:z,className:"h-8 min-w-[80px]",style:te,children:ce}),e[39]=D,e[40]=z,e[41]=te,e[42]=ce,e[43]=Se):Se=e[43];let pe;e[44]!==ne||e[45]!==Se?(pe=s.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[ne,Se]}),e[44]=ne,e[45]=Se,e[46]=pe):pe=e[46];let we;e[47]!==re||e[48]!==ae||e[49]!==pe?(we=s.jsxs("div",{className:B,children:[re,ae,pe]}),e[47]=re,e[48]=ae,e[49]=pe,e[50]=we):we=e[50];let W;return e[51]!==_||e[52]!==L||e[53]!==K||e[54]!==we||e[55]!==T?(W=s.jsx("div",{className:T,style:_,"data-comment-input":O,onPointerDown:L,onTouchStart:K,children:we}),e[51]=_,e[52]=L,e[53]=K,e[54]=we,e[55]=T,e[56]=W):W=e[56],W}function BS(t){return t.stopPropagation()}function _S(t){return t.stopPropagation()}function VS(t){return t.stopPropagation()}function zS(t){return t.stopPropagation()}function US(t){return t.stopPropagation()}function WS(t){return t.stopPropagation()}function KS(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 HS=t=>{const e=Math.min(t.startLine,t.endLine),n=Math.max(t.startLine,t.endLine);return{...t,startLine:e,endLine:n}},rc=t=>{const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}};function Xu(t){const e=nt.c(40),{t:n}=ut(),{source:r,fileLabel:a,language:i,getCodeForRange:o,toStoreRange:c,fromDraftRange:d}=t,p=Ht(XS),m=Ht(YS),u=go(JS),f=go(QS),y=go(qS),h=go(GS),[b,x]=l.useState(null),[g,w]=l.useState(""),[v,S]=l.useState(null),P=p??(m?"draft":null);let j;e:{if(!P||!a){let B;e[0]===Symbol.for("react.memo_cache_sentinel")?(B=[],e[0]=B):B=e[0],j=B;break e}let O;e[1]!==h||e[2]!==P?(O=h[P]??[],e[1]=h,e[2]=P,e[3]=O):O=e[3];const L=O;let K;if(e[4]!==a||e[5]!==L||e[6]!==r){let B;e[8]!==a||e[9]!==r?(B=re=>re.source===r&&re.fileLabel===a,e[8]=a,e[9]=r,e[10]=B):B=e[10],K=L.filter(B),e[4]=a,e[5]=L,e[6]=r,e[7]=K}else K=e[7];j=K}const C=j;let I;e[11]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{x(null),w(""),S(null)},e[11]=I):I=e[11];const R=I;let k;e[12]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{R()},e[12]=k):k=e[12];const A=k;let N;e[13]!==d?(N=O=>{const L=rc(d(O));x(L),w(O.text),S(O.id)},e[13]=d,e[14]=N):N=e[14];const D=N;let T;e[15]!==v||e[16]!==y?(T=O=>{y(O.sessionKey,O.id),v===O.id&&R()},e[15]=v,e[16]=y,e[17]=T):T=e[17];const M=T;let $;e[18]!==u||e[19]!==v||e[20]!==a||e[21]!==o||e[22]!==i||e[23]!==b||e[24]!==P||e[25]!==r||e[26]!==n||e[27]!==c||e[28]!==f?($=(O,L)=>{const K=L??b,B=O.trim();if(!K||!B||!a)return;if(!P){q.error(n("inlineComment.toast.selectSessionToSave"));return}const re=rc(K),oe=HS(c(re)),ee=o(re);v?f(P,v,{fileLabel:a,startLine:oe.startLine,endLine:oe.endLine,side:oe.side,code:ee,language:i,text:B}):u({sessionKey:P,source:r,fileLabel:a,startLine:oe.startLine,endLine:oe.endLine,side:oe.side,code:ee,language:i,text:B}),R()},e[18]=u,e[19]=v,e[20]=a,e[21]=o,e[22]=i,e[23]=b,e[24]=P,e[25]=r,e[26]=n,e[27]=c,e[28]=f,e[29]=$):$=e[29];const F=$;let _;return e[30]!==g||e[31]!==M||e[32]!==C||e[33]!==v||e[34]!==d||e[35]!==F||e[36]!==b||e[37]!==P||e[38]!==D?(_={sessionKey:P,drafts:C,selection:b,setSelection:x,commentText:g,setCommentText:w,editingDraftId:v,setEditingDraftId:S,reset:R,cancel:A,startEdit:D,deleteDraft:M,saveComment:F,fromDraftRange:d},e[30]=g,e[31]=M,e[32]=C,e[33]=v,e[34]=d,e[35]=F,e[36]=b,e[37]=P,e[38]=D,e[39]=_):_=e[39],_}function GS(t){return t.drafts}function qS(t){return t.removeDraft}function QS(t){return t.updateDraft}function JS(t){return t.addDraft}function YS(t){return t.newSessionDraft?.open}function XS(t){return t.currentSessionId}function gx(t){const{drafts:e,editingDraftId:n,commentText:r,selection:a,isDragging:i,fileLabel:o,newWidgetId:c,mapDraftToRange:d,onSave:p,onCancel:m,onEdit:u,onDelete:f}=t,y=[];for(const h of e){const b=d(h);if(h.id===n){y.push({afterLine:b.end,id:`edit-${h.id}`,content:s.jsx(nc,{initialText:r,fileLabel:o,lineRange:b,isEditing:!0,onSave:p,onCancel:m},`edit-${h.id}`)});continue}y.push({afterLine:b.end,id:`card-${h.id}`,content:s.jsx(fx,{draft:h,onEdit:()=>u(h),onDelete:()=>f(h)},`card-${h.id}`)})}if(a&&!n&&!i){const h={...a,start:Math.min(a.start,a.end),end:Math.max(a.start,a.end)};y.push({afterLine:h.end,id:c,content:s.jsx(nc,{initialText:r,fileLabel:o,lineRange:h,isEditing:!1,onSave:p,onCancel:m},c)})}return y}const Tl=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}`},ZS=t=>{const{drafts:e,editingDraftId:n,selection:r}=t,a=[];for(const i of e){if(!Number.isFinite(i.endLine))continue;const o=Math.max(1,Math.floor(i.endLine)),c=i.side==="original"?"deletions":"additions";a.push({lineNumber:o,side:c,metadata:{type:i.id===n?"edit":"saved",draft:i}})}return r&&!n&&a.push({lineNumber:Math.max(r.start,r.end),side:r.side??"additions",metadata:{type:"new",selection:r}}),a};function ek(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 Pp(t){if(!(!t||t<=0))return Math.max(200,Math.floor(t))}function tk(t){const{diffRootRef:e,drafts:n,selection:r,editingDraftId:a,commentText:i,fileLabel:o,onSave:c,onCancel:d,onEdit:p,onDelete:m}=t,[u,f]=l.useState(0),[y,h]=l.useState(null),b=l.useMemo(()=>!r||a?null:Tl({type:"new",selection:r}),[a,r]),x=l.useMemo(()=>{const v=n.map(S=>Tl({type:S.id===a?"edit":"saved",draft:S}));return b&&v.push(b),v},[n,a,b]),g=l.useCallback(v=>{const S=e.current;if(!S)return null;const P=S.querySelector("diffs-container");if(!(P instanceof HTMLElement))return null;const j=P.querySelector(`[data-annotation-id="${v}"]`);if(j instanceof HTMLElement)return j;const C=P.shadowRoot;return C?C.querySelector(`[data-annotation-id="${v}"]`):null},[e]);l.useEffect(()=>{if(x.length===0)return;let v=!1,S=0;const P=12,j=()=>{v||x.every(I=>!!g(I))||S>=P||(S+=1,requestAnimationFrame(()=>{v||(f(I=>I+1),j())}))};return j(),()=>{v=!0}},[x,g]),l.useEffect(()=>{const v=e.current;if(!v)return;const S=()=>{const j=getComputedStyle(v),C=ek(j.getPropertyValue("--oc-context-panel-width")),I=v.getBoundingClientRect(),R=C??I.width;h(R>0?R:null)};S();const P=new ResizeObserver(()=>{S()});return P.observe(v),window.addEventListener("resize",S),()=>{P.disconnect(),window.removeEventListener("resize",S)}},[e]);const w=l.useCallback(v=>{const P=e.current?.getBoundingClientRect(),j=v.closest("[data-annotation-content]"),C=j instanceof HTMLElement?j.getBoundingClientRect():v.getBoundingClientRect(),I=[C.width];P&&I.push(P.right-C.left);const R=I.filter(k=>Number.isFinite(k)&&k>0);return R.length>0?Pp(Math.min(...R)):Pp(y)},[e,y]);return s.jsxs(s.Fragment,{children:[n.map(v=>{const S=Tl({type:v.id===a?"edit":"saved",draft:v}),P=g(S);if(!P)return null;const j=w(P);return v.id===a?wo.createPortal(s.jsx(nc,{initialText:i,fileLabel:o,lineRange:{start:v.startLine,end:v.endLine,side:v.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:d,maxWidth:j}),P,`draft-edit-${v.id}`):wo.createPortal(s.jsx(fx,{draft:v,onEdit:()=>p(v),onDelete:()=>m(v),maxWidth:j}),P,`draft-card-${v.id}`)}),r&&!a&&b&&(()=>{const v=g(b);if(!v)return null;const S=w(v);return wo.createPortal(s.jsx(nc,{initialText:i,fileLabel:o,lineRange:r,isEditing:!1,onSave:c,onCancel:d,maxWidth:S}),v,b)})()]})}function sk(){return new Worker(_b,{type:"module"})}const nk=["typescript","javascript","tsx","jsx","json","markdown"],Yd={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let Dp,Tp;const Mp=t=>{const e=Yd[t],n=new Vb({workerFactory:sk,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:nk,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},rk=t=>{if(!(typeof window>"u"))return t==="split"?(Tp??=Mp("split"),Tp):(Dp??=Mp("unified"),Dp)},ak=t=>{const e=nt.c(7),{children:n,renderTheme:r}=t,a=Xd("unified"),i=Xd("split");let o,c;e[0]!==r||e[1]!==i||e[2]!==a?(o=()=>{a&&a.setRenderOptions({theme:r,lineDiffType:Yd.unified.lineDiffType}),i&&i.setRenderOptions({theme:r,lineDiffType:Yd.split.lineDiffType})},c=[r,i,a],e[0]=r,e[1]=i,e[2]=a,e[3]=o,e[4]=c):(o=e[3],c=e[4]),Oe.useEffect(o,c);let d;return e[5]!==n?(d=s.jsx(s.Fragment,{children:n}),e[5]=n,e[6]=d):d=e[6],d},ik=t=>{const e=nt.c(11),{children:n}=t,r=wc();let a,i;if(e[0]!==r?.availableThemes||e[1]!==r?.darkThemeId||e[2]!==r?.lightThemeId){const p=Gi(!1),m=Gi(!0),u=r?.lightThemeId??p.metadata.id,f=r?.darkThemeId??m.metadata.id;i=r?.availableThemes.find(y=>y.metadata.id===u)??p,a=r?.availableThemes.find(y=>y.metadata.id===f)??m,qi(i),qi(a),e[0]=r?.availableThemes,e[1]=r?.darkThemeId,e[2]=r?.lightThemeId,e[3]=a,e[4]=i}else a=e[3],i=e[4];let o;e[5]!==a.metadata.id||e[6]!==i.metadata.id?(o={light:i.metadata.id,dark:a.metadata.id},e[5]=a.metadata.id,e[6]=i.metadata.id,e[7]=o):o=e[7];const c=o;let d;return e[8]!==n||e[9]!==c?(d=s.jsx(ak,{renderTheme:c,children:n}),e[8]=n,e[9]=c,e[10]=d):d=e[10],d},Xd=t=>{const e=nt.c(2),n=t===void 0?"unified":t;let r;return e[0]!==n?(r=rk(n),e[0]=n,e[1]=r):r=e[1],r},ok=5e5,lk=`
|
|
15
|
+
:host {
|
|
16
|
+
font-family: var(--font-mono);
|
|
17
|
+
font-size: var(--text-code);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
pre, [data-code] {
|
|
21
|
+
font-family: var(--font-mono);
|
|
22
|
+
font-size: var(--text-code);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* Mobile touch selection support */
|
|
26
|
+
[data-line-number] {
|
|
27
|
+
touch-action: manipulation;
|
|
28
|
+
-webkit-tap-highlight-color: transparent;
|
|
29
|
+
cursor: pointer;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Ensure interactive line numbers work on touch */
|
|
33
|
+
pre[data-interactive-line-numbers] [data-line-number] {
|
|
34
|
+
touch-action: manipulation;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
[data-diff-header],
|
|
38
|
+
[data-diff] {
|
|
39
|
+
[data-separator] {
|
|
40
|
+
height: 24px !important;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`;function ck(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 Rp(t){const e=t.length>400?`${t.slice(0,200)}${t.slice(-200)}`:t;return`${t.length}:${ck(e)}`}const dk=(t,e,n)=>{const i=(n.side==="deletions"?t:e).split(`
|
|
44
|
+
`),o=Math.min(n.start,n.end),c=Math.max(n.start,n.end),d=Math.max(1,o),p=Math.min(i.length,c);return d>p?"":i.slice(d-1,p).join(`
|
|
45
|
+
`)},uk=(t,e)=>t===e?!0:!t||!e?!1:t.start===e.start&&t.end===e.end&&t.side===e.side,pl=new WeakMap,mk={lineHeight:24,hunkSeparatorHeight:24,fileGap:0};function pk(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 hk(t){if(typeof document>"u")return null;const e=pk(t);let n=pl.get(e.key);if(!n){const a=new Wb;a.setup(e.root,e.content),n={virtualizer:a,refs:0},pl.set(e.key,n)}n.refs+=1;let r=!1;return{virtualizer:n.virtualizer,release:()=>{if(r)return;r=!0;const a=pl.get(e.key);a&&(a.refs-=1,!(a.refs>0)&&(a.virtualizer.cleanUp(),pl.delete(e.key)))}}}const xx=({original:t,modified:e,language:n,fileName:r,renderSideBySide:a,wrapLines:i,layout:o="fill"})=>{const c=wc(),d=c?.currentTheme.metadata.variant==="dark",p=c?.availableThemes.find(J=>J.metadata.id===c.lightThemeId)??Gi(!1),m=c?.availableThemes.find(J=>J.metadata.id===c.darkThemeId)??Gi(!0),{isMobile:u}=dn(),f=Xu({source:"diff",fileLabel:r||"unknown",language:n,getCodeForRange:J=>dk(t,e,J),toStoreRange:J=>({startLine:J.start,endLine:J.end,side:J.side==="deletions"?"original":"modified"}),fromDraftRange:J=>({start:J.startLine,end:J.endLine,side:J.side==="original"?"deletions":"additions"})}),{drafts:y,selection:h,setSelection:b,commentText:x,setCommentText:g,editingDraftId:w,saveComment:v,cancel:S,startEdit:P,deleteDraft:j}=f,C=Oe.useRef(null),I=Oe.useRef(null),R=Oe.useRef(!1),k=Oe.useRef(null);Oe.useEffect(()=>{C.current=h},[h]),Oe.useEffect(()=>{I.current=w},[w]);const A=Oe.useCallback(J=>{if(R.current)return;const H=C.current;if(u&&H&&J&&J.side===H.side){const te=Math.min(H.start,J.start),ce=Math.max(H.end,J.end);b({...J,start:te,end:ce})}else b(J);J&&(I.current||g(""))},[u,g,b]),N=Oe.useCallback(()=>{S()},[S]),D=Oe.useCallback(J=>{const H=document.createElement("div");H.style.position="relative";const te=Tl(J.metadata);return H.dataset.annotationId=te,H.dataset.annotationSide=J.side,H.dataset.annotationLine=String(J.lineNumber),H},[]),T=Oe.useCallback((J,H)=>{v(J,H??h??void 0)},[v,h]),M=Oe.useCallback(J=>{b(J);const H=L.current;if(H)try{R.current=!0,H.setSelectedLines(J),k.current=J}catch{}finally{R.current=!1}},[b]),$=Oe.useCallback(J=>{const H=J.closest("[data-line-type]")?.getAttribute("data-line-type")??J.getAttribute("data-line-type");if(H==="change-deletion")return"deletions";if(H==="change-addition")return"additions";const te=J.getAttribute("data-column-side")??J.getAttribute("data-side")??J.closest("[data-column-side]")?.getAttribute("data-column-side");if(te==="deletions"||te==="left"||te==="original")return"deletions";if(te==="additions"||te==="right"||te==="modified")return"additions";const ce=J.closest("[data-line-type]");if(ce instanceof HTMLElement){const Se=ce.getBoundingClientRect(),pe=J.getBoundingClientRect(),we=Se.left+Se.width/2;return pe.left+pe.width/2<we?"deletions":"additions"}return"additions"},[]);qi(p),qi(m);const F=`${p.metadata.id}:${m.metadata.id}:${d?"dark":"light"}`,_=Oe.useRef(null),O=Oe.useRef(null),L=Oe.useRef(null),K=Oe.useRef(null),[,B]=l.useReducer(J=>J+1,0),re=Xd(a?"split":"unified"),oe=Oe.useMemo(()=>Cm(p),[p]),ee=Oe.useMemo(()=>Cm(m),[m]);l.useLayoutEffect(()=>{const J=_.current;if(!J)return;const H=J.querySelector("diffs-container");if(!H)return;const te=d?ee:oe,ce=(X,he)=>X.colors?.[he],Se=ce(oe,"terminal.ansiGreen"),pe=ce(oe,"terminal.ansiRed"),we=ce(oe,"terminal.ansiBlue"),W=ce(ee,"terminal.ansiGreen"),ue=ce(ee,"terminal.ansiRed"),Y=ce(ee,"terminal.ansiBlue");H.style.setProperty("--shiki-light",oe.fg),H.style.setProperty("--shiki-light-bg",oe.bg),Se&&H.style.setProperty("--shiki-light-addition-color",Se),pe&&H.style.setProperty("--shiki-light-deletion-color",pe),we&&H.style.setProperty("--shiki-light-modified-color",we),H.style.setProperty("--shiki-dark",ee.fg),H.style.setProperty("--shiki-dark-bg",ee.bg),W&&H.style.setProperty("--shiki-dark-addition-color",W),ue&&H.style.setProperty("--shiki-dark-deletion-color",ue),Y&&H.style.setProperty("--shiki-dark-modified-color",Y),H.style.setProperty("--diffs-bg",te.bg),H.style.setProperty("--diffs-fg",te.fg);const le=d?W:Se,Z=d?ue:pe,Ie=d?Y:we;le&&H.style.setProperty("--diffs-addition-color-override",le),Z&&H.style.setProperty("--diffs-deletion-color-override",Z),Ie&&H.style.setProperty("--diffs-modified-color-override",Ie);const Ne=H.shadowRoot?.querySelector("pre");Ne&&(Ne.style.setProperty("--shiki-light",oe.fg),Ne.style.setProperty("--shiki-light-bg",oe.bg),Se&&Ne.style.setProperty("--shiki-light-addition-color",Se),pe&&Ne.style.setProperty("--shiki-light-deletion-color",pe),we&&Ne.style.setProperty("--shiki-light-modified-color",we),Ne.style.setProperty("--shiki-dark",ee.fg),Ne.style.setProperty("--shiki-dark-bg",ee.bg),W&&Ne.style.setProperty("--shiki-dark-addition-color",W),ue&&Ne.style.setProperty("--shiki-dark-deletion-color",ue),Y&&Ne.style.setProperty("--shiki-dark-modified-color",Y),Ne.style.setProperty("--diffs-bg",te.bg),Ne.style.setProperty("--diffs-fg",te.fg),le&&Ne.style.setProperty("--diffs-addition-color-override",le),Z&&Ne.style.setProperty("--diffs-deletion-color-override",Z),Ie&&Ne.style.setProperty("--diffs-modified-color-override",Ie))},[ee,F,d,oe]);const ae=Oe.useMemo(()=>Math.max(t.length,e.length)>ok,[t.length,e.length]),ge=Oe.useMemo(()=>({theme:{dark:m.metadata.id,light:p.metadata.id},themeType:d?"dark":"light",diffStyle:a?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:ae?0:1e3,maxLineLengthForHighlighting:ae?1:1e3,expansionLineCount:20,overflow:i?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:!0,enableHoverUtility:!1,onLineSelected:A,unsafeCSS:lk,renderAnnotation:D}),[m.metadata.id,d,ae,p.metadata.id,a,i,A,D]),ne=Oe.useMemo(()=>ZS({drafts:y,editingDraftId:w,selection:h}),[w,y,h]),E=Oe.useRef(ne);if(Oe.useEffect(()=>{E.current=ne},[ne]),Oe.useEffect(()=>{if(typeof window>"u")return;const J=O.current;if(!J||!re)return;L.current?.cleanUp(),L.current=null,K.current?.release(),K.current=null,J.innerHTML="";const H=hk(J);K.current=H;const te=H?new zb(ge,H.virtualizer,mk,re):new Ub(ge,re);L.current=te,k.current=null;const ce={name:r||"",contents:t,lang:n,cacheKey:`old:${F}:${r}:${Rp(t)}`},Se={name:r||"",contents:e,lang:n,cacheKey:`new:${F}:${r}:${Rp(e)}`};return te.render({oldFile:ce,newFile:Se,lineAnnotations:E.current,containerWrapper:J}),requestAnimationFrame(()=>{B()}),()=>{te.cleanUp(),L.current===te&&(L.current=null),H?.release(),H&&K.current===H&&(K.current=null),J.innerHTML=""}},[F,r,n,e,ge,t,re]),Oe.useEffect(()=>{const J=L.current;if(J){try{J.setLineAnnotations(ne)}catch(H){console.error("Failed to apply diff line annotations",H);try{J.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(L.current===J){try{J.rerender()}catch{}B()}})}},[ne]),Oe.useEffect(()=>{const J=L.current;if(!J||h!==null)return;const H=k.current;if(!uk(h,H))try{R.current=!0,J.setSelectedLines(h),k.current=h}catch{}finally{R.current=!1}},[h]),Oe.useEffect(()=>{const J=O.current;if(!J)return;let H=null,te=()=>{};const ce=()=>{const pe=J.querySelector("diffs-container")?.shadowRoot;if(!pe){H=requestAnimationFrame(ce);return}const we=W=>{if(!(W instanceof MouseEvent)||W.button!==0||!(W.target instanceof Element))return;const ue=W.target.closest("[data-column-number]");if(!(ue instanceof HTMLElement))return;const Y=ue.getAttribute("data-column-number"),le=Y?parseInt(Y,10):NaN;if(Number.isNaN(le))return;const Z=$(ue);A({start:le,end:le,side:Z}),W.preventDefault(),W.stopPropagation()};pe.addEventListener("click",we,!0),te=()=>{pe.removeEventListener("click",we,!0)}};return ce(),()=>{H!==null&&cancelAnimationFrame(H),te()}},[F,r,A,$]),Oe.useEffect(()=>{const J=O.current;if(!J)return;let H=null,te=null;const Se=setTimeout(()=>{const pe=J.querySelector("diffs-container");if(!(pe instanceof HTMLElement))return;const we=pe.shadowRoot;H=new MutationObserver(()=>{te&&cancelAnimationFrame(te),te=requestAnimationFrame(()=>{B(),te=null})}),H.observe(pe,{childList:!0,subtree:!0}),we&&H.observe(we,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(Se),te&&cancelAnimationFrame(te),H?.disconnect()}},[F,r]),typeof window>"u")return null;const z=s.jsx(tk,{diffRootRef:_,drafts:y,selection:h,editingDraftId:w,commentText:x,fileLabel:r?.split("/").pop()??"",onSave:T,onCancel:N,onEdit:J=>{M({start:J.startLine,end:J.endLine,side:J.side==="original"?"deletions":"additions"}),P(J)},onDelete:j});return o==="fill"?s.jsx("div",{className:me("flex flex-col relative","size-full"),"data-diff-virtual-root":!0,children:s.jsxs("div",{className:"flex-1 relative min-h-0",children:[s.jsx(Ps,{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"})})}),z]})}):s.jsxs("div",{className:me("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"})}),z]})},fk=1100,Zd=15e3,Ep=500,gk=t=>t<=6?t:t<=12?6:t<=25?4:2,bx=l.memo(()=>{const t=nt.c(4),{t:e}=ut();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}),yx={"?":{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"}},xk=yx.M,Ml=[{value:"single",labelKey:"diffView.mode.single.label",descriptionKey:"diffView.mode.single.description"},{value:"stacked",labelKey:"diffView.mode.stacked.label",descriptionKey:"diffView.mode.stacked.description"}],bk=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"},vx=t=>{const e=bk(t);return yx[e]??xk},yk=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},vk=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),wk=(t,e)=>{const n=t.replace(/\\/g,"/").replace(/\/+$/g,""),r=e.replace(/\\/g,"/");if(vk(r))return r;const a=r.replace(/^\/+/,"");return n?`${n}/${a}`:a},Fp=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Op=(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},jk=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},ac=(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]})},Nk=l.memo(t=>{const e=nt.c(29),{changedFiles:n,selectedFile:r,selectedFileEntry:a,onSelectFile:i,isMobile:o,showModeSelector:c,mode:d,onModeChange:p}=t,m=c===void 0?!1:c,{t:u}=ut();let f;e[0]!==o?(f=C=>{if(!o)return C;const I=C.lastIndexOf("/");return I>=0?C.slice(I+1):C},e[0]=o,e[1]=f):f=e[1];const y=f;if(n.length===0)return null;let h;e[2]!==y||e[3]!==a||e[4]!==u?(h=a?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx(Dr,{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:y(a.path)}),ac(a.insertions,a.deletions)]}):s.jsx("span",{className:"text-muted-foreground",children:u("diffView.selector.selectFile")}),e[2]=y,e[3]=a,e[4]=u,e[5]=h):h=e[5];let b;e[6]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(ks,{className:"size-4 opacity-50"}),e[6]=b):b=e[6];let x;e[7]!==h?(x=s.jsx($s,{asChild:!0,children:s.jsxs("button",{className:"flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",children:[h,b]})}),e[7]=h,e[8]=x):x=e[8];let g;e[9]!==d||e[10]!==p||e[11]!==m||e[12]!==u?(g=m&&d&&p?s.jsxs(s.Fragment,{children:[s.jsx(No,{className:"typography-meta text-muted-foreground",children:u("diffView.selector.viewMode")}),s.jsx(ql,{value:d,onValueChange:C=>p(C),children:Ml.map(C=>s.jsx(Ql,{value:C.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:u(C.labelKey)})},C.value))}),s.jsx(Ln,{})]}):null,e[9]=d,e[10]=p,e[11]=m,e[12]=u,e[13]=g):g=e[13];const w=r??"";let v;if(e[14]!==n||e[15]!==y){let C;e[17]!==y?(C=I=>s.jsx(Ql,{value:I.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(Dr,{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:y(I.path)}),s.jsx("span",{className:"ml-auto",children:ac(I.insertions,I.deletions)})]})},I.path),e[17]=y,e[18]=C):C=e[18],v=n.map(C),e[14]=n,e[15]=y,e[16]=v}else v=e[16];let S;e[19]!==i||e[20]!==w||e[21]!==v?(S=s.jsx(ql,{value:w,onValueChange:i,children:v}),e[19]=i,e[20]=w,e[21]=v,e[22]=S):S=e[22];let P;e[23]!==g||e[24]!==S?(P=s.jsxs(Bs,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[g,S]}),e[23]=g,e[24]=S,e[25]=P):P=e[25];let j;return e[26]!==P||e[27]!==x?(j=s.jsxs(_s,{children:[x,P]}),e[26]=P,e[27]=x,e[28]=j):j=e[28],j}),Sk=l.memo(t=>{const e=nt.c(31),{mode:n,onModeChange:r}=t,{t:a}=ut();let i,o,c,d,p,m;if(e[0]!==n||e[1]!==a){const v=Ml.find(S=>S.value===n)??Ml[0];o=_s,i=$s,m=!0,p="flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",c="min-w-0 truncate typography-meta",d=a(v.labelKey),e[0]=n,e[1]=a,e[2]=i,e[3]=o,e[4]=c,e[5]=d,e[6]=p,e[7]=m}else i=e[2],o=e[3],c=e[4],d=e[5],p=e[6],m=e[7];let u;e[8]!==c||e[9]!==d?(u=s.jsx("span",{className:c,children:d}),e[8]=c,e[9]=d,e[10]=u):u=e[10];let f;e[11]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(ks,{className:"size-4 opacity-50"}),e[11]=f):f=e[11];let y;e[12]!==p||e[13]!==u?(y=s.jsxs("button",{className:p,children:[u,f]}),e[12]=p,e[13]=u,e[14]=y):y=e[14];let h;e[15]!==i||e[16]!==m||e[17]!==y?(h=s.jsx(i,{asChild:m,children:y}),e[15]=i,e[16]=m,e[17]=y,e[18]=h):h=e[18];let b;e[19]!==r?(b=v=>r(v),e[19]=r,e[20]=b):b=e[20];let x;e[21]!==a?(x=Ml.map(v=>s.jsx(Ql,{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 g;e[23]!==n||e[24]!==x||e[25]!==b?(g=s.jsx(Bs,{className:"min-w-[140px]",children:s.jsx(ql,{value:n,onValueChange:b,children:x})}),e[23]=n,e[24]=x,e[25]=b,e[26]=g):g=e[26];let w;return e[27]!==o||e[28]!==g||e[29]!==h?(w=s.jsxs(o,{children:[h,g]}),e[27]=o,e[28]=g,e[29]=h,e[30]=w):w=e[30],w}),kk=l.memo(t=>{const e=nt.c(11),{changedFiles:n,selectedFile:r,onSelectFile:a}=t,{t:i}=ut();if(n.length===0)return null;let o;if(e[0]!==n||e[1]!==a||e[2]!==r||e[3]!==i){let d;e[5]!==a||e[6]!==r||e[7]!==i?(d=p=>{const m=vx(p),u=r===p.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>a(p.path),className:me("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",u?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[s.jsx(Dr,{filePath:p.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:m.color},title:i(m.descriptionKey),"aria-label":i(m.descriptionKey),children:m.code}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:p.path,children:p.path}),ac(p.insertions,p.deletions)]})},p.path)},e[5]=a,e[6]=r,e[7]=i,e[8]=d):d=e[8],o=n.map(d),e[0]=n,e[1]=a,e[2]=r,e[3]=i,e[4]=o}else o=e[4];let c;return e[9]!==o?(c=s.jsx(Ps,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:o})}),e[9]=o,e[10]=c):c=e[10],c}),Ck=l.memo(t=>{const e=nt.c(21),{filePath:n,diff:r,isVisible:a,renderSideBySide:i}=t,{t:o}=ut(),c=r.original.length>0,d=r.modified.length>0;if(!a){let b;return e[0]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx("div",{className:"absolute inset-0 hidden"}),e[0]=b):b=e[0],b}const p=i?"flex flex-row gap-6 items-start justify-center h-full":"flex flex-col gap-4 items-center",m=i?"flex flex-col items-center gap-2 flex-1 min-w-0 h-full":"flex flex-col items-center gap-2";let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={contain:"size layout"},e[1]=u):u=e[1];let f;e[2]!==r.original||e[3]!==n||e[4]!==c||e[5]!==m||e[6]!==i||e[7]!==o?(f=c&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:o("diffView.image.original")}),s.jsx("img",{src:r.original,alt:o("diffView.image.originalAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[2]=r.original,e[3]=n,e[4]=c,e[5]=m,e[6]=i,e[7]=o,e[8]=f):f=e[8];let y;e[9]!==r.modified||e[10]!==n||e[11]!==d||e[12]!==c||e[13]!==m||e[14]!==i||e[15]!==o?(y=d&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:o(c?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:o("diffView.image.modifiedAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[9]=r.modified,e[10]=n,e[11]=d,e[12]=c,e[13]=m,e[14]=i,e[15]=o,e[16]=y):y=e[16];let h;return e[17]!==p||e[18]!==f||e[19]!==y?(h=s.jsx("div",{className:"absolute inset-0 overflow-auto p-4",style:u,children:s.jsxs("div",{className:p,children:[f,y]})}),e[17]=p,e[18]=f,e[19]=y,e[20]=h):h=e[20],h}),Ik=l.memo(t=>{const e=nt.c(20),{filePath:n,diff:r,renderSideBySide:a}=t,{t:i}=ut(),o=r.original.length>0,c=r.modified.length>0,d=a?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",p=a?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={contain:"layout"},e[0]=m):m=e[0];let u;e[1]!==r.original||e[2]!==n||e[3]!==o||e[4]!==p||e[5]!==a||e[6]!==i?(u=o&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i("diffView.image.original")}),s.jsx("img",{src:r.original,alt:i("diffView.image.originalAlt",{path:n}),className:a?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=r.original,e[2]=n,e[3]=o,e[4]=p,e[5]=a,e[6]=i,e[7]=u):u=e[7];let f;e[8]!==r.modified||e[9]!==n||e[10]!==c||e[11]!==o||e[12]!==p||e[13]!==a||e[14]!==i?(f=c&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i(o?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:i("diffView.image.modifiedAlt",{path:n}),className:a?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=r.modified,e[9]=n,e[10]=c,e[11]=o,e[12]=p,e[13]=a,e[14]=i,e[15]=f):f=e[15];let y;return e[16]!==d||e[17]!==u||e[18]!==f?(y=s.jsx("div",{className:"w-full overflow-auto p-4",style:m,children:s.jsxs("div",{className:d,children:[u,f]})}),e[16]=d,e[17]=u,e[18]=f,e[19]=y):y=e[19],y}),Ak=l.memo(t=>{const e=nt.c(15),{filePath:n,diff:r,renderSideBySide:a,wrapLines:i}=t;let o;e[0]!==n?(o=To(n)||"text",e[0]=n,e[1]=o):o=e[1];const c=o;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(bx,{}),e[2]=m):m=e[2],m}if(Qi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a?(m=s.jsx(Ik,{filePath:n,diff:r,renderSideBySide:a}),e[3]=r,e[4]=n,e[5]=a,e[6]=m):m=e[6],m}let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d={contain:"layout"},e[7]=d):d=e[7];let p;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==c||e[12]!==a||e[13]!==i?(p=s.jsx("div",{className:"w-full",style:d,children:s.jsx(xx,{original:r.original,modified:r.modified,language:c,fileName:n,renderSideBySide:a,wrapLines:i,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=c,e[12]=a,e[13]=i,e[14]=p):p=e[14],p}),Pk=l.memo(t=>{const e=nt.c(15),{filePath:n,diff:r,isVisible:a,renderSideBySide:i,wrapLines:o}=t;let c;e[0]!==n?(c=To(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(bx,{}),e[2]=m):m=e[2],m}if(!a)return null;if(Qi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a||e[6]!==i?(m=s.jsx(Ck,{filePath:n,diff:r,isVisible:a,renderSideBySide:i}),e[3]=r,e[4]=n,e[5]=a,e[6]=i,e[7]=m):m=e[7],m}let p;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==d||e[12]!==i||e[13]!==o?(p=s.jsx(Ps,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(xx,{original:r.original,modified:r.modified,language:d,fileName:n,renderSideBySide:i,wrapLines:o,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=d,e[12]=i,e[13]=o,e[14]=p):p=e[14],p}),Dk=l.memo(t=>{const e=nt.c(122),{directory:n,file:r,layout:a,wrapLines:i,scrollRootRef:o,isSelected:c,onSelect:d,registerSectionRef:p,defaultCollapsed:m,expandRequestPath:u,expandRequestNonce:f,showOpenInEditorAction:y,isOpeningInEditor:h,onOpenInEditor:b}=t,x=m===void 0?!1:m,g=u===void 0?null:u,w=f===void 0?0:f,v=y===void 0?!1:y,S=h===void 0?!1:h,{t:P}=ut(),{git:j}=Yn();let C;e[0]!==n||e[1]!==r.path?(C=Xe=>Xe.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=C):C=e[2];const I=pn(C),R=pn(Mk),k=De(Rk),[A,N]=l.useState(!x),[D,T]=l.useState(!1),[M,$]=l.useState(0),[F,_]=l.useState(null),[O,L]=l.useState(!1),[K,B]=l.useState(!1),re=l.useRef(null),oe=l.useRef(null);let ee;e[3]!==r?(ee=vx(r),e[3]=r,e[4]=ee):ee=e[4];const ae=ee,ge=a==="side-by-side";let ne;e:{if(!I){ne=null;break e}let Xe;e[5]!==I.isBinary||e[6]!==I.modified||e[7]!==I.original?(Xe={original:I.original,modified:I.modified,isBinary:I.isBinary},e[5]=I.isBinary,e[6]=I.modified,e[7]=I.original,e[8]=Xe):Xe=e[8],ne=Xe}const E=ne;let z;e[9]!==r.path||e[10]!==p?(z=Xe=>{oe.current=Xe,p(r.path,Xe)},e[9]=r.path,e[10]=p,e[11]=z):z=e[11];const J=z;let H;e[12]===Symbol.for("react.memo_cache_sentinel")?(H=Xe=>{N(Xe),Xe&&T(!0)},e[12]=H):H=e[12];const te=H;let ce;e[13]!==r.path||e[14]!==d?(ce=()=>{d(r.path)},e[13]=r.path,e[14]=d,e[15]=ce):ce=e[15];const Se=ce;let pe,we;e[16]!==D||e[17]!==A||e[18]!==o?(pe=()=>{if(!A||D)return;const Xe=oe.current;if(!Xe)return;if(!o.current||typeof IntersectionObserver>"u"){T(!0);return}const dt=new IntersectionObserver(et=>{et.some(Ek)&&(T(!0),dt.disconnect())},{root:o.current,rootMargin:"200px 0px",threshold:.1});return dt.observe(Xe),()=>dt.disconnect()},we=[D,A,o],e[16]=D,e[17]=A,e[18]=o,e[19]=pe,e[20]=we):(pe=e[19],we=e[20]),l.useEffect(pe,we);let W,ue;e[21]!==w||e[22]!==g||e[23]!==r.path?(W=()=>{w<=0||g!==r.path||(N(!0),T(!0))},ue=[w,g,r.path],e[21]=w,e[22]=g,e[23]=r.path,e[24]=W,e[25]=ue):(W=e[24],ue=e[25]),l.useEffect(W,ue);let Y,le;e[26]!==E||e[27]!==M||e[28]!==n||e[29]!==r.path||e[30]!==j||e[31]!==D||e[32]!==A||e[33]!==R?(Y=()=>{if(!A||!D)return;if(!n||E){re.current=null,L(!1);return}const Xe=`${n}::${r.path}::${M}`;if(re.current===Xe)return;re.current=Xe,_(null),L(!0);let dt=!1;const et=j.getGitFileDiff(n,{path:r.path}),ct=new Promise(Fk);return Promise.race([et,ct]).then(at=>{dt||(R(n,r.path,{original:at.original??"",modified:at.modified??"",isBinary:at.isBinary}),L(!1))}).catch(at=>{if(dt)return;const ye=at instanceof Error?at.message:String(at);_(ye),L(!1)}),()=>{dt=!0,re.current===Xe&&(re.current=null)}},le=[n,E,M,r.path,j,D,A,R],e[26]=E,e[27]=M,e[28]=n,e[29]=r.path,e[30]=j,e[31]=D,e[32]=A,e[33]=R,e[34]=Y,e[35]=le):(Y=e[34],le=e[35]),l.useEffect(Y,le);let Z;e[36]!==Se||e[37]!==A?(Z=()=>{te(!A),Se()},e[36]=Se,e[37]=A,e[38]=Z):Z=e[38];const Ie=Z,Ne=A?"rounded-b-none":"rounded-b-xl",X=c?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let he;e[39]!==Ne||e[40]!==X?(he=me("group/header relative flex w-full items-center gap-2 px-3 py-1.5 rounded-t-xl border border-border/60 overflow-hidden","bg-background",Ne,"text-muted-foreground hover:text-foreground",X),e[39]=Ne,e[40]=X,e[41]=he):he=e[41];let je;e[42]===Symbol.for("react.memo_cache_sentinel")?(je=s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-interactive-hover"}),e[42]=je):je=e[42];let be;e[43]!==A?(be=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:A?s.jsx(ks,{className:"size-4"}):s.jsx($n,{className:"size-4"})}),e[43]=A,e[44]=be):be=e[44];let fe;e[45]!==ae.color?(fe={color:ae.color},e[45]=ae.color,e[46]=fe):fe=e[46];let Pe;e[47]!==ae.descriptionKey||e[48]!==P?(Pe=P(ae.descriptionKey),e[47]=ae.descriptionKey,e[48]=P,e[49]=Pe):Pe=e[49];let Be;e[50]!==ae.descriptionKey||e[51]!==P?(Be=P(ae.descriptionKey),e[50]=ae.descriptionKey,e[51]=P,e[52]=Be):Be=e[52];let G;e[53]!==ae.code||e[54]!==fe||e[55]!==Pe||e[56]!==Be?(G=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:fe,title:Pe,"aria-label":Be,children:ae.code}),e[53]=ae.code,e[54]=fe,e[55]=Pe,e[56]=Be,e[57]=G):G=e[57];const ke=r.path;let Ee;e[58]!==r.path?(Ee=s.jsx(Dr,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[58]=r.path,e[59]=Ee):Ee=e[59];let Ae;if(e[60]!==r.path){e:{const Xe=r.path.lastIndexOf("/");if(Xe===-1){let _e;e[62]===Symbol.for("react.memo_cache_sentinel")?(_e={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[62]=_e):_e=e[62],Ae=s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:_e,children:r.path});break e}const dt=r.path.slice(0,Xe),et=r.path.slice(Xe+1);let ct;e[63]===Symbol.for("react.memo_cache_sentinel")?(ct={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[63]=ct):ct=e[63];let at;e[64]!==dt?(at=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:ct,children:dt}),e[64]=dt,e[65]=at):at=e[65];let ye;e[66]===Symbol.for("react.memo_cache_sentinel")?(ye=s.jsx("span",{className:"text-muted-foreground",children:"/"}),e[66]=ye):ye=e[66];let Ge;e[67]!==et?(Ge=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[ye,s.jsx("span",{className:"text-foreground",children:et})]}),e[67]=et,e[68]=Ge):Ge=e[68];let $e;e[69]!==at||e[70]!==Ge?($e=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[at,Ge]}),e[69]=at,e[70]=Ge,e[71]=$e):$e=e[71],Ae=$e}e[60]=r.path,e[61]=Ae}else Ae=e[61];let xe;e[72]!==Ee||e[73]!==Ae?(xe=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[Ee,Ae]}),e[72]=Ee,e[73]=Ae,e[74]=xe):xe=e[74];let V;e[75]!==r.path||e[76]!==xe?(V=s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:ke,children:xe}),e[75]=r.path,e[76]=xe,e[77]=V):V=e[77];let de;e[78]!==be||e[79]!==G||e[80]!==V?(de=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[be,G,V]}),e[78]=be,e[79]=G,e[80]=V,e[81]=de):de=e[81];let Me;e[82]!==r.deletions||e[83]!==r.insertions?(Me=ac(r.insertions,r.deletions),e[82]=r.deletions,e[83]=r.insertions,e[84]=Me):Me=e[84];let Le;e[85]!==E||e[86]!==r.path||e[87]!==S||e[88]!==b||e[89]!==v||e[90]!==P?(Le=v&&b?s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:P("diffView.actions.openFileInEditorAtChange"),onClick:Xe=>{Xe.stopPropagation(),b(r.path,E)},disabled:S,children:S?s.jsx(ts,{className:"size-3.5 animate-spin"}):s.jsx(ea,{className:"size-3.5"})}):null,e[85]=E,e[86]=r.path,e[87]=S,e[88]=b,e[89]=v,e[90]=P,e[91]=Le):Le=e[91];const se=ge?"side-by-side":"unified";let ie;e[92]!==r.path||e[93]!==k?(ie=Xe=>{const dt=Xe==="side-by-side"?"side-by-side":"inline";k(r.path,dt)},e[92]=r.path,e[93]=k,e[94]=ie):ie=e[94];let U;e[95]!==se||e[96]!==ie?(U=s.jsx(vg,{mode:se,onModeChange:ie,className:"opacity-70"}),e[95]=se,e[96]=ie,e[97]=U):U=e[97];let Ve;e[98]!==Me||e[99]!==Le||e[100]!==U?(Ve=s.jsxs("div",{className:"relative flex items-center gap-2",children:[Me,Le,U]}),e[98]=Me,e[99]=Le,e[100]=U,e[101]=Ve):Ve=e[101];let He;e[102]!==Ie||e[103]!==he||e[104]!==de||e[105]!==Ve?(He=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:Ie,className:he,children:[je,de,Ve]})}),e[102]=Ie,e[103]=he,e[104]=de,e[105]=Ve,e[106]=He):He=e[106];let Ke;e[107]!==E||e[108]!==F||e[109]!==r.deletions||e[110]!==r.insertions||e[111]!==r.path||e[112]!==K||e[113]!==A||e[114]!==O||e[115]!==ge||e[116]!==i?(Ke=A&&s.jsxs("div",{className:"relative border border-t-0 border-border/60 bg-background rounded-b-xl overflow-hidden",children:[F?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:F}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>$(Ok),children:"Retry"})]}):null,O&&!E&&!F?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(ts,{size:16,className:"animate-spin"}),"Loading diff…"]}):null,E&&!K&&r.insertions+r.deletions>Ep?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:()=>B(!0),children:"Render anyway"})]}):null,E&&(K||r.insertions+r.deletions<=Ep)?s.jsx(Ak,{filePath:r.path,diff:E,renderSideBySide:ge,wrapLines:i}):null]}),e[107]=E,e[108]=F,e[109]=r.deletions,e[110]=r.insertions,e[111]=r.path,e[112]=K,e[113]=A,e[114]=O,e[115]=ge,e[116]=i,e[117]=Ke):Ke=e[117];let Ze;return e[118]!==J||e[119]!==He||e[120]!==Ke?(Ze=s.jsxs("div",{ref:J,className:"scroll-mt-4",children:[He,Ke]}),e[118]=J,e[119]=He,e[120]=Ke,e[121]=Ze):Ze=e[121],Ze}),wx=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:a=!1})=>{const{t:i}=ut(),{git:o,files:c}=Yn(),d=ta(),{screenWidth:p,isMobile:m}=dn(),u=bg(d??null),f=bc(d??null),y=yg(d??null),h=pn(de=>de.setActiveDirectory),b=pn(de=>de.ensureStatus),x=pn(de=>de.fetchStatus),g=pn(de=>de.setDiff),[w,v]=l.useState(null),[S,P]=l.useState(null),[j,C]=l.useState(0),[I,R]=l.useState(null),[k,A]=l.useState(0),[N,D]=l.useState(null),T=l.useRef(null),M=De(de=>de.pendingDiffFile),$=De(de=>de.setPendingDiffFile),F=De(de=>de.diffLayoutPreference),_=De(de=>de.diffFileLayout),O=De(de=>de.setDiffFileLayout),L=De(de=>de.diffWrapLines),K=De(de=>de.setDiffWrapLines),B=De(de=>de.diffViewMode),re=De(de=>de.setDiffViewMode),oe=De(de=>de.openContextFileAtLine),ee=L,ae=B==="stacked",ge=m||p<=768,ne=!t&&!ge&&p>=1024,E=l.useRef(null),z=l.useRef(new Map),J=l.useRef(null),H=l.useRef(null),te=l.useRef(!1);l.useEffect(()=>{if(!r||!ae||!I)return;const de=E.current;if(!de)return;let Me=null,Le=!1,se=0;const ie=Date.now()+1200;let U=0;const Ve=()=>{Le||(Le=!0,R(null))},He=()=>{Ve()},Ke=()=>{if(U>0){U-=1;return}Ve()};window.addEventListener("wheel",He,{passive:!0,capture:!0}),window.addEventListener("touchstart",He,{passive:!0,capture:!0}),window.addEventListener("pointerdown",He,{capture:!0}),window.addEventListener("keydown",He,{capture:!0}),de.addEventListener("scroll",Ke,{passive:!0});const Ze=()=>{if(Le||Date.now()>ie){Ve();return}const Xe=E.current,dt=z.current.get(I);if(!Xe||!dt){Ve();return}const et=Xe.getBoundingClientRect(),at=dt.getBoundingClientRect().top-et.top;if(Math.abs(at)<=1){if(se+=1,se>=2){Ve();return}}else{se=0;const ye=Math.max(0,Xe.scrollHeight-Xe.clientHeight),Ge=Math.min(ye,Math.max(0,Xe.scrollTop+at));if(Math.abs(Ge-Xe.scrollTop)<=.5){Ve();return}U+=1,Xe.scrollTop=Ge}Me=window.requestAnimationFrame(Ze)};return Me=window.requestAnimationFrame(Ze),()=>{Le=!0,Me!==null&&window.cancelAnimationFrame(Me),window.removeEventListener("wheel",He,!0),window.removeEventListener("touchstart",He,!0),window.removeEventListener("pointerdown",He,!0),window.removeEventListener("keydown",He,!0),de.removeEventListener("scroll",Ke)}},[ae,r,I]);const ce=l.useMemo(()=>{if(!f?.files)return[];const de=f.diffStats??{};return f.files.map(Me=>({...Me,insertions:de[Me.path]?.insertions??0,deletions:de[Me.path]?.deletions??0,isNew:yk(Me)})).sort((Me,Le)=>Me.path.localeCompare(Le.path))},[f]),Se=l.useMemo(()=>w?ce.find(de=>de.path===w)??null:null,[ce,w]),pe=l.useCallback(de=>{const Me=_[de.path];if(Me)return Me;if(F==="inline")return"inline";if(F==="side-by-side")return"side-by-side";const Le=p<fk;return de.isNew||Le?"inline":"side-by-side"},[_,F,p]),we=l.useMemo(()=>Se?pe(Se):null,[pe,Se]);l.useEffect(()=>{d&&(h(d),b(d,o))},[d,h,b,o]),l.useEffect(()=>{if(d)return Tr.onGitRefreshHint(de=>{Fp(de.directory)===Fp(d)&&x(d,o)})},[d,x,o]),l.useEffect(()=>{M&&(v(M),$(null),ae&&(te.current=!0,J.current=M,P(M),C(de=>de+1)))},[ae,M,$]),l.useEffect(()=>{!w&&!M&&ce.length>0&&v(ce[0].path)},[ce,w,M]),l.useEffect(()=>{w&&ce.length>0&&(ce.some(Me=>Me.path===w)||v(ce[0]?.path??null))},[ce,w]);const W=l.useCallback((de,Me)=>{const Le=z.current;Me?Le.set(de,Me):Le.delete(de)},[]),ue=l.useCallback(de=>{const Me=z.current.get(de),Le=E.current;if(!Me||!Le)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const se=Le.getBoundingClientRect(),U=Me.getBoundingClientRect().top-se.top,Ve=Math.max(0,Le.scrollHeight-Le.clientHeight),He=Le.scrollTop+U,Ke=Math.min(Ve,Math.max(0,He)),Ze=Math.abs(Ke-Le.scrollTop)>.5;Le.scrollTop=Ke;const Xe=Math.abs(U)<=1,dt=Ke<=.5||Ke>=Ve-.5;return{ok:!0,aligned:Xe,didMove:Ze,atScrollLimit:dt,delta:U}},[]);l.useEffect(()=>{if(!ae){J.current=null,te.current=!1,H.current!==null&&(window.cancelAnimationFrame(H.current),H.current=null);return}if(!J.current)return;let Me=0;const Le=120;let se=!1,ie=0,U=!1,Ve=0;const He=Date.now()+2e3,Ke=()=>{U||(U=!0,window.removeEventListener("wheel",Xe,!0),window.removeEventListener("touchstart",Xe,!0),window.removeEventListener("pointerdown",Xe,!0),window.removeEventListener("keydown",Xe,!0),et?.removeEventListener("scroll",dt))},Ze=()=>{se||(se=!0,Ke(),J.current=null,te.current=!1,H.current!==null&&(window.cancelAnimationFrame(H.current),H.current=null))},Xe=()=>{Ze()},dt=()=>{if(ie>0){ie-=1;return}Ze()},et=E.current;window.addEventListener("wheel",Xe,{passive:!0,capture:!0}),window.addEventListener("touchstart",Xe,{passive:!0,capture:!0}),window.addEventListener("pointerdown",Xe,{capture:!0}),window.addEventListener("keydown",Xe,{capture:!0}),et?.addEventListener("scroll",dt,{passive:!0});const ct=()=>{if(Date.now()>He){Ze(),H.current=null;return}if(se){H.current=null;return}const at=J.current;if(!at){Ze(),H.current=null;return}ie+=1;const ye=ue(at);if(!ye.ok){ie=Math.max(0,ie-1),Me+=1,Me<Le?H.current=window.requestAnimationFrame(ct):(Ze(),H.current=null);return}if(!ye.aligned){if(Me+=1,ye.didMove){if(Ve=0,Me<Le){H.current=window.requestAnimationFrame(ct);return}}else if(Ve+=1,Ve<6&&(ye.atScrollLimit||Math.abs(ye.delta)>1)){H.current=window.requestAnimationFrame(ct);return}}r&&te.current&&R(at),Ze()};return H.current=window.requestAnimationFrame(ct),()=>{se=!0,Ke(),H.current!==null&&(window.cancelAnimationFrame(H.current),H.current=null)}},[ae,r,ue,w,j]);const Y=l.useCallback(de=>{v(de)},[]),le=l.useCallback(de=>{if(H.current!==null&&(window.cancelAnimationFrame(H.current),H.current=null),J.current=null,v(de),!ae){te.current=!1;return}te.current=!0,J.current=de,ue(de)},[ae,ue]),Z=l.useCallback(de=>{re(de),de==="stacked"&&w&&(ue(w).aligned||(J.current=w))},[ue,w,re]),Ie=l.useCallback(de=>{const Me=de==="side-by-side"?"side-by-side":"inline";if(ae){ce.forEach(Le=>{O(Le.path,Me)});return}Se&&O(Se.path,Me)},[ce,ae,Se,O]),Ne=(we??"side-by-side")==="side-by-side",X=!n&&(!ae||!ne),he=pn(l.useCallback(de=>!d||!w?null:de.directories.get(d)?.diffCache.get(w)??null,[d,w])),je=l.useMemo(()=>he?{original:he.original,modified:he.modified,isBinary:he.isBinary}:null,[he]),[be,fe]=l.useState(null),Pe=l.useCallback(async(de,Me)=>{if(!(!d||!de)){fe(de);try{let Le=null;if(Me&&!Me.isBinary&&!Qi(de)&&(Le=Op(Me.original,Me.modified)),Le===null)try{const He=await o.getGitDiff(d,{path:de,contextLines:3});Le=jk(He.diff)}catch{Le=null}let se=Me;if(Le===null||!se){const He=await o.getGitFileDiff(d,{path:de});se={original:He.original??"",modified:He.modified??"",isBinary:He.isBinary},g(d,de,se)}const ie=Le??(se.isBinary||Qi(de)?1:Op(se.original,se.modified)),U=wk(d,de),Ve=await Ju(c,U);if(!Ve.ok){q.error(Yu(Ve.reason));return}oe(d,U,ie,1)}finally{fe(Le=>Le===de?null:Le)}}},[d,c,o,oe,g]),Be=l.useCallback(async()=>{w&&await Pe(w,je)},[Pe,je,w]),G=!!(w&&be===w),ke=!!he,Ee=!ae&&!!w&&!ke;l.useEffect(()=>{if(ae)return;if(D(null),!d||!w){T.current=null;return}if(he){T.current=null;return}const de=`${d}::${w}::${k}`;if(T.current===de)return;T.current=de;let Me=!1;const Le=o.getGitFileDiff(d,{path:w}),se=Zd,ie=new Promise((U,Ve)=>{setTimeout(()=>Ve(new Error(`Timed out after ${se}ms`)),se)});return Promise.race([Le,ie]).then(U=>{Me||g(d,w,{original:U.original??"",modified:U.modified??"",isBinary:U.isBinary})}).catch(U=>{if(Me)return;const Ve=U instanceof Error?U.message:String(U);D(Ve)}),()=>{Me=!0,T.current===de&&(T.current=null)}},[d,ae,w,he,o,g,k]);const Ae=()=>!d||!w||!je?null:s.jsx(Pk,{filePath:w,diff:je,isVisible:!0,renderSideBySide:Ne,wrapLines:ee},w),xe=()=>{if(!d)return null;const de=gk(ce.length);return s.jsxs("div",{className:"flex flex-1 min-h-0 h-full gap-3 px-3 pb-3 pt-2",children:[ne&&s.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:i("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:ce.length})]}),s.jsx(kk,{changedFiles:ce,selectedFile:w,onSelectFile:le})]}),s.jsx(Ps,{ref:E,outerClassName:"flex-1 min-h-0 h-full",className:"pr-2",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx("div",{className:"flex flex-col gap-3",children:ce.map((Me,Le)=>s.jsx(Dk,{directory:d,file:Me,layout:pe(Me),wrapLines:ee,scrollRootRef:E,isSelected:Me.path===w,onSelect:Y,registerSectionRef:W,defaultCollapsed:e?!0:Le>=de,expandRequestPath:S,expandRequestNonce:j,showOpenInEditorAction:a,isOpeningInEditor:be===Me.path,onOpenInEditor:(se,ie)=>{Pe(se,ie)}},Me.path))})})]})},V=()=>d?y&&!f?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(ts,{size:16,className:"animate-spin"}),i("diffView.state.loadingRepositoryStatus")]}):u===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.notGitRepository")}):ce.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.cleanWorkingTree")}):ae?xe():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:[Ae(),Ee&&!ke&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted-foreground",children:N?s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:i("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:N}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>{D(null),A(de=>de+1)},children:i("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(ts,{size:16,className:"animate-spin"}),i("diffView.state.loadingDiff")]})})]}):s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 bg-background",children:[!m&&s.jsxs("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:[s.jsx(pc,{size:16}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:y&&!f?i("diffView.state.loadingChanges"):ce.length===1?i("diffView.summary.changedFilesSingle",{count:ce.length}):i("diffView.summary.changedFilesPlural",{count:ce.length})})]}),!ge&&s.jsx(Sk,{mode:B,onModeChange:Z}),X&&s.jsx(Nk,{changedFiles:ce,selectedFile:w,selectedFileEntry:Se,onSelectFile:le,isMobile:ge,showModeSelector:ge,mode:B,onModeChange:Z}),s.jsx("div",{className:"flex-1"}),Se&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>K(!L),className:me("h-5 w-5 p-0 transition-opacity",ee?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:i(ee?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(_f,{className:"size-4"})}),a&&Se&&!ae&&s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{Be()},disabled:G,title:i("diffView.actions.openFileAtFirstChangedLine"),children:G?s.jsx(ts,{className:"size-3.5 animate-spin"}):s.jsx(ea,{className:"size-3.5"})}),Se&&we&&s.jsx(vg,{mode:we==="side-by-side"?"side-by-side":"unified",onModeChange:Ie})]}),V()]})},Tk=()=>{const t=nt.c(6),{git:e}=Yn(),n=ta(),r=pn(Lk),a=pn($k),i=o1(n??null);let o,c;return t[0]!==n||t[1]!==a||t[2]!==e||t[3]!==r?(o=()=>{n&&(r(n),a(n,e))},c=[n,r,a,e],t[0]=n,t[1]=a,t[2]=e,t[3]=r,t[4]=o,t[5]=c):(o=t[4],c=t[5]),l.useEffect(o,c),i};function Mk(t){return t.setDiff}function Rk(t){return t.setDiffFileLayout}function Ek(t){return t.isIntersecting}function Fk(t,e){setTimeout(()=>e(new Error(`Timed out after ${Zd}ms`)),Zd)}function Ok(t){return t+1}function Lk(t){return t.setActiveDirectory}function $k(t){return t.ensureStatus}const Bk=Object.freeze(Object.defineProperty({__proto__:null,DiffView:wx,useDiffFileCount:Tk},Symbol.toStringTag,{value:"Module"})),_k={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},Vk={case:"Match case",re:"Regular expression",word:"Match whole word"};function zk(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(_k)){const a=e.querySelector(`button[name="${n}"]`);a&&!a.title&&(a.title=r)}for(const[n,r]of Object.entries(Vk)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=r)}}}const Lp=new so,$p=new so,Bp=new so,_p=new so,Vp=new so,zp=new so,Up=t=>t,od=ey,Uk=ty,Wk=sy;class Kk extends ny{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 Wp=(t,e)=>!t||t.length===0?[]:Zb.define({create(n){const r=new Vf,a=[...t].sort((i,o)=>i.afterLine-o.afterLine);for(const i of a){const o=n.doc.lines;if(i.afterLine>o)continue;const c=n.doc.line(i.afterLine);r.add(c.to,c.to,zf.widget({widget:new Kk(i.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>or.decorations.from(n)}),Kp=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return Xb.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 Vf;for(let i=e;i<=n&&i<=r.state.doc.lines;i+=1){const o=r.state.doc.line(i);a.add(o.from,o.from,zf.line({class:"oc-cm-selected-line"}))}return a.finish()}},{decorations:r=>r.decorations})};function eu({value:t,onChange:e,extensions:n,className:r,readOnly:a,lineNumbersConfig:i,highlightLines:o,onViewReady:c,onViewDestroy:d,blockWidgets:p,enableSearch:m,searchOpen:u,onSearchOpenChange:f}){const y=l.useRef(null),h=l.useRef(null),b=l.useRef(t),x=l.useRef(e),g=l.useRef(c),w=l.useRef(d),v=l.useRef(f),S=l.useRef(p),P=l.useRef(new Map),[j,C]=l.useState([]),I=l.useCallback(k=>{const A=(k??[]).map(N=>{const D=P.current.get(N.id);return D?{id:N.id,content:N.content,container:D}:null}).filter(N=>N!==null);C(N=>N.length===A.length&&N.every((D,T)=>{const M=A[T];return D.id===M.id&&D.content===M.content&&D.container===M.container})?N:A)},[]),R=l.useCallback(k=>{const A=y.current,N=k??h.current;if(!A||!N)return;const D=N.dom.querySelector(".cm-gutters"),T=D instanceof HTMLElement?D.getBoundingClientRect().width:0;A.style.setProperty("--oc-editor-gutter-width",`${T}px`)},[]);return l.useEffect(()=>{b.current=t},[t]),l.useEffect(()=>{x.current=e},[e]),l.useEffect(()=>{g.current=c,w.current=d},[c,d]),l.useEffect(()=>{v.current=f},[f]),l.useEffect(()=>{S.current=p,I(p)},[p,I]),l.useEffect(()=>{if(!y.current)return;const k=(()=>{if(typeof document>"u")return null;const N=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(N)return N;const D=window.__OPENCHAMBER_CSP_NONCE__;return typeof D=="string"&&D.length>0?D:null})(),A=Kb.create({doc:b.current,extensions:[...k?[or.cspNonce.of(k)]:[],Hb({fixed:!0}),Lp.of(cm(i)),Gb(),qb.of(" "),Rc.of([Qb,...Jb,...Yb]),or.updateListener.of(N=>{R(N.view),(N.viewportChanged||N.geometryChanged)&&I(S.current);const D=dm(N.startState),T=dm(N.state);if(D!==T&&v.current?.(T),!N.docChanged)return;const M=N.state.doc.toString();b.current=M,x.current(M),I(S.current)}),$p.of(or.editable.of(!a)),Bp.of(n??[]),_p.of(Kp(o)),Vp.of(Wp(p,P.current)),zp.of(m?[um({top:!0}),Rc.of(Up(mm))]:[])]});return h.current=new or({state:A,parent:y.current}),od(h.current,h.current.state.doc.length,200),h.current.requestMeasure(),requestAnimationFrame(()=>{R(h.current),I(S.current)}),h.current&&g.current?.(h.current),()=>{w.current?.(),h.current?.destroy(),h.current=null,C([])}},[S,R,I]),l.useEffect(()=>{const k=h.current;k&&(k.dispatch({effects:[Lp.reconfigure(cm(i)),$p.reconfigure(or.editable.of(!a)),Bp.reconfigure(n??[]),_p.reconfigure(Kp(o)),Vp.reconfigure(Wp(p,P.current)),zp.reconfigure(m?[um({top:!0}),Rc.of(Up(mm))]:[])]}),od(k,k.state.doc.length,200),k.requestMeasure(),requestAnimationFrame(()=>{R(k),I(S.current)}))},[n,o,i,a,p,m,R,I]),l.useEffect(()=>{const k=h.current;!k||m===!1||(u?(Uk(k),requestAnimationFrame(()=>{zk(k.dom)})):Wk(k))},[u,m]),l.useEffect(()=>{const k=h.current;if(!k)return;const A=k.state.doc.toString();A!==t&&(k.dispatch({changes:{from:0,to:A.length,insert:t}}),od(k,k.state.doc.length,300),k.requestMeasure(),requestAnimationFrame(()=>R(k)))},[t,R]),s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:y,className:me("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",r)}),j.map(k=>wo.createPortal(k.content,k.container,k.id))]})}const Hk=(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)},Hp=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},Gp=(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:ry.cursor(i),effects:or.scrollIntoView(i,{y:"center"})})};function Gk({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:a}=ut(),[i,o]=l.useState(""),c=l.useRef(null),d=l.useRef(!1),p=l.useRef(null),m=l.useRef(null),u=l.useMemo(()=>Hk(i,n),[i,n]);l.useEffect(()=>{!t||!n||(d.current=!1,c.current=Hp(n,n.state.selection),o(""))},[t,n]),l.useEffect(()=>{t&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[t]),l.useEffect(()=>{if(!(!t||!n||!c.current)){if(u===null){const{selection:x}=c.current;n.dispatch({selection:x,effects:or.scrollIntoView(x.main.from,{y:"center"})});return}Gp(n,u,c.current.character)}},[u,t,n]);const f=l.useCallback(()=>{if(!n||d.current||!c.current)return;const{selection:x}=c.current;n.dispatch({selection:x,effects:or.scrollIntoView(x.main.from,{y:"center"})})},[n]),y=l.useCallback(x=>{x||f(),e(x)},[e,f]),h=l.useCallback(()=>{!n||u===null||!c.current||(d.current=!0,Gp(n,u,c.current.character),e(!1),n.focus())},[u,e,n]);l.useEffect(()=>{if(!t)return;const x=w=>{const v=p.current,S=w.target;!v||!(S instanceof Node)||v.contains(S)||y(!1)},g=w=>{w.key==="Escape"&&(w.preventDefault(),y(!1))};return document.addEventListener("pointerdown",x,!0),document.addEventListener("keydown",g,!0),()=>{document.removeEventListener("pointerdown",x,!0),document.removeEventListener("keydown",g,!0)}},[y,t,r]);const b=l.useMemo(()=>{if(!n)return a("goToLineDialog.helper.editorUnavailable");if(u===null){const x=c.current??Hp(n,n.state.selection);return a("goToLineDialog.helper.currentLineRange",{current:x.lineNumber,max:n.state.doc.lines})}return a("goToLineDialog.helper.goToLine",{line:u})},[u,a,n]);return r==="inline"?t?s.jsxs("div",{ref:p,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(Bt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),h())},placeholder:a("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(ve,{variant:"outline",size:"xs",onClick:h,disabled:!n||u===null,className:"h-6 px-2",children:a("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:p,className:me("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",t?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(Bt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),h())},placeholder:a("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:b})]})})}const tu=t=>{const e=nt.c(11),{currentMode:n,onToggle:r}=t,a=n==="preview",i=a?"Switch to edit mode":"Switch to preview mode",o=a?"Edit":"Preview";let c;e[0]!==a?(c=a?s.jsx(Mu,{className:"size-4","aria-hidden":"true"}):s.jsx(Ru,{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(kt,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",onClick:r,"aria-label":i,className:"h-5 w-5 p-0",children:c})}),e[2]=i,e[3]=r,e[4]=c,e[5]=d):d=e[5];let p;e[6]!==o?(p=s.jsx(It,{sideOffset:8,children:o}),e[6]=o,e[7]=p):p=e[7];let m;return e[8]!==d||e[9]!==p?(m=s.jsxs(St,{children:[d,p]}),e[8]=d,e[9]=p,e[10]=m):m=e[10],m},su=ay.define(iy);function qk(t){const e=t.trim().toLowerCase();switch(e){case"bash":case"sh":case"zsh":case"shell":case"shellsession":case"console":return su;case"json":case"jsonc":case"json5":return Kf().language;case"js":case"javascript":return Ti().language;case"jsx":return Ti({jsx:!0}).language;case"ts":case"typescript":return Ti({typescript:!0}).language;case"tsx":return Ti({typescript:!0,jsx:!0}).language;case"html":return Md().language;case"css":return Wf().language;case"py":case"python":return Uf().language;case"heex":case"eex":case"leex":return Md().language;default:return Hf.matchLanguageName(Gf,e,!0)}}const jx=t=>t.split("/").pop()?.toLowerCase()??"",Qk=t=>{const e=jx(t);return e?Hf.matchFilename(Gf,e):null},Jk=()=>fo(Rd.define([{tag:[rt.heading1,rt.heading2,rt.heading3,rt.heading4,rt.heading5,rt.heading6],fontWeight:"600"},{tag:rt.strong,fontWeight:"600"},{tag:rt.emphasis,fontStyle:"italic"},{tag:rt.strikethrough,textDecoration:"line-through"},{tag:[rt.link,rt.url],color:"var(--markdown-link, currentColor)",textDecoration:"underline"},{tag:rt.monospace,color:"var(--markdown-inline-code, currentColor)",backgroundColor:"var(--markdown-inline-code-bg, transparent)"},{tag:rt.quote,color:"var(--markdown-blockquote, currentColor)",fontStyle:"italic"},{tag:rt.list,color:"color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)"},{tag:rt.heading,color:"var(--markdown-heading1, currentColor)"}]));function Nx(t){const e=t.toLowerCase();switch(jx(e)){case"makefile":case"gnumakefile":return su}const r=e.lastIndexOf("."),a=r>=0?e.slice(r+1):"";switch(a){case"ts":case"tsx":case"mts":case"cts":return Ti({typescript:!0,jsx:a==="tsx"});case"js":case"jsx":case"mjs":case"cjs":return Ti({typescript:!1,jsx:a==="jsx"});case"json":case"jsonc":case"json5":case"jsonl":case"ndjson":case"geojson":return Kf();case"css":case"scss":case"sass":case"less":return Wf();case"html":case"htm":return Md();case"md":case"mdx":case"markdown":case"mdown":case"mkd":return[oy({codeLanguages:qk}),Jk()];case"sh":case"bash":case"zsh":case"fish":case"env":return su;case"py":case"pyw":case"pyi":return Uf();default:return null}}async function Yk(t){const e=Qk(t);if(!e)return null;if(e.support)return e.support;try{return await e.load()}catch{return null}}function nu(t){const e=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",r=t.colors.syntax.highlights||{},a=t.colors.syntax.tokens||{},i=or.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:"var(--text-code)",lineHeight:"1.5rem",position:"relative"},".cm-scroller":{fontFamily:n,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:a.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:a.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:a.boolean||t.colors.syntax.base.number},".cm-builtin":{color:a.functionCall||t.colors.syntax.base.function},".cm-def":{color:a.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:a.variableOther||a.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:a.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:a.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:a.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:a.tag||t.colors.syntax.base.keyword},".cm-link":{color:a.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:r.lineNumber||t.colors.syntax.base.comment,borderRight:`1px solid ${t.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:r.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${t.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:t.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:t.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:t.colors.interactive.hover,color:t.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:e}),o=Rd.define([{tag:[rt.comment,rt.docComment,rt.meta,rt.documentMeta],class:"cm-comment"},{tag:[rt.keyword,rt.controlKeyword,rt.moduleKeyword,rt.definitionKeyword,rt.modifier],class:"cm-keyword"},{tag:[rt.operatorKeyword,rt.operator,rt.derefOperator,rt.updateOperator,rt.definitionOperator,rt.typeOperator,rt.controlOperator,rt.logicOperator,rt.bitwiseOperator,rt.arithmeticOperator,rt.compareOperator],class:"cm-operator"},{tag:[rt.punctuation,rt.separator,rt.bracket,rt.paren,rt.brace,rt.squareBracket,rt.angleBracket],class:"cm-punctuation"},{tag:[rt.string,rt.regexp,rt.attributeValue,rt.special(rt.string),rt.monospace],class:"cm-string"},{tag:rt.escape,class:"cm-string-2"},{tag:[rt.number,rt.bool,rt.atom,rt.null,rt.self],class:"cm-number"},{tag:[rt.function(rt.variableName),rt.function(rt.definition(rt.variableName)),rt.function(rt.propertyName),rt.standard(rt.variableName),rt.special(rt.variableName)],class:"cm-builtin"},{tag:rt.definition(rt.variableName),class:"cm-def"},{tag:[rt.variableName,rt.local(rt.variableName),rt.constant(rt.variableName),rt.literal],class:"cm-variable"},{tag:rt.propertyName,class:"cm-property"},{tag:rt.attributeName,class:"cm-attribute"},{tag:[rt.className,rt.typeName,rt.namespace],class:"cm-variable-3"},{tag:[rt.tagName,rt.labelName,rt.annotation,rt.macroName],class:"cm-tag"},{tag:rt.link,class:"cm-link"},{tag:[rt.heading,rt.heading1,rt.heading2,rt.heading3,rt.heading4,rt.heading5,rt.heading6],class:"cm-keyword"}]),c=Rd.define([{tag:[rt.comment,rt.docComment,rt.meta,rt.documentMeta],color:t.colors.syntax.base.comment},{tag:[rt.keyword,rt.controlKeyword,rt.moduleKeyword,rt.definitionKeyword,rt.modifier],color:t.colors.syntax.base.keyword},{tag:[rt.operatorKeyword,rt.operator,rt.derefOperator,rt.updateOperator,rt.definitionOperator,rt.typeOperator,rt.controlOperator,rt.logicOperator,rt.bitwiseOperator,rt.arithmeticOperator,rt.compareOperator],color:t.colors.syntax.base.operator},{tag:[rt.string,rt.regexp,rt.attributeValue,rt.special(rt.string),rt.monospace],color:t.colors.syntax.base.string},{tag:rt.escape,color:a.stringEscape||t.colors.syntax.base.string},{tag:[rt.number,rt.bool,rt.atom,rt.null,rt.self],color:t.colors.syntax.base.number},{tag:[rt.function(rt.variableName),rt.function(rt.definition(rt.variableName)),rt.function(rt.propertyName),rt.standard(rt.variableName),rt.special(rt.variableName)],color:t.colors.syntax.base.function},{tag:rt.definition(rt.variableName),color:a.variableGlobal||t.colors.syntax.base.variable},{tag:[rt.variableName,rt.local(rt.variableName),rt.constant(rt.variableName),rt.literal],color:t.colors.syntax.base.variable},{tag:rt.propertyName,color:a.variableProperty||t.colors.syntax.base.variable},{tag:rt.attributeName,color:a.variableOther||t.colors.syntax.base.variable},{tag:[rt.className,rt.typeName,rt.namespace],color:t.colors.syntax.base.type},{tag:[rt.tagName,rt.labelName,rt.annotation,rt.macroName],color:a.tag||t.colors.syntax.base.keyword},{tag:rt.link,color:a.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[rt.punctuation,rt.separator,rt.bracket,rt.paren,rt.brace,rt.squareBracket,rt.angleBracket],color:a.punctuation||t.colors.syntax.base.comment}]);return[i,fo(ly,{fallback:!0}),fo(cy),fo(o),fo(c)]}const Xk=t=>{const e=kn(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},Zk=t=>{const e=nt.c(8),{label:n,iconDataUrl:r}=t,[a,i]=l.useState(!1);let o;e[0]!==n?(o=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=o):o=e[1];const c=o;if(r&&!a){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>i(!0),e[2]=m):m=e[2];let u;return e[3]!==r?(u=s.jsx("img",{src:r,alt:"",className:"h-4 w-4 rounded-sm",onError:m}),e[3]=r,e[4]=u):u=e[4],u}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=me("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=d):d=e[5];let p;return e[6]!==c?(p=s.jsx("span",{className:d,children:c}),e[6]=c,e[7]=p):p=e[7],p},e3=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),kn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const a=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!a&&!i&&(r=r.replace(/\/+$/,"")),r},t3=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),qp=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,ic=(t,e)=>{const n=kn(e),r=kn(t);if(!n||!r)return!1;const a=qp(n),i=qp(r);return i===a||i.startsWith(`${a}/`)},Qp=(t,e)=>{const n=kn(e),r=kn(t);if(!ic(r,n))return[];const i=r.slice(n.length).replace(/^\//,"").split("/"),o=[];let c=n;for(let d=0;d<i.length-1;d++)c=c?`${c}/${i[d]}`:i[d],o.push(c);return o},ru=(t,e)=>{if(!e)return"";const n=kn(e);if(!t||!ic(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},s3=new Set(["node_modules"]),n3=t=>{const e=nt.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},r3=t=>s3.has(t),a3=t=>{const e=kn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},i3=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},lo=2e5,Sx="openchamber:files:auto-save-enabled",o3=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(Sx)!=="false"}catch{return!0}},kx=(t,e)=>s.jsx(Dr,{filePath:t,extension:e}),l3=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},c3=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},ld=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},d3=t=>{const e=nt.c(62),{node:n,root:r,isExpanded:a,isActive:i,isMobile:o,alwaysShowActions:c,status:d,badge:p,permissions:m,downloadFile:u,contextMenuPath:f,setContextMenuPath:y,onSelect:h,onToggle:b,onRevealPath:x,onOpenDialog:g}=t,{t:w}=ut(),v=n.type==="directory",{canRename:S,canCreateFile:P,canCreateFolder:j,canDelete:C,canReveal:I}=m;let R;e[0]!==P||e[1]!==j||e[2]!==C||e[3]!==S||e[4]!==I||e[5]!==n.path||e[6]!==y?(R=ae=>{!S&&!P&&!j&&!C&&!I||(ae?.preventDefault(),y(n.path))},e[0]=P,e[1]=j,e[2]=C,e[3]=S,e[4]=I,e[5]=n.path,e[6]=y,e[7]=R):R=e[7];const k=R;let A;e[8]!==v||e[9]!==n||e[10]!==h||e[11]!==b?(A=()=>{v?b(n.path):h(n)},e[8]=v,e[9]=n,e[10]=h,e[11]=b,e[12]=A):A=e[12];const N=A;let D;e[13]!==n.path||e[14]!==y?(D=ae=>{ae.stopPropagation(),y(n.path)},e[13]=n.path,e[14]=y,e[15]=D):D=e[15];const T=D,M=o?void 0:k,$=o?void 0:k,F=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let _;e[16]!==F?(_=me("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",F),e[16]=F,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(Au,{className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(Pu,{className:"h-4 w-4 flex-shrink-0 text-primary/60"}):kx(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 L;e[23]!==n.name||e[24]!==n.path?(L=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]=L):L=e[25];let K;e[26]!==v||e[27]!==d?(K=!v&&d&&s.jsx(n3,{status:d}),e[26]=v,e[27]=d,e[28]=K):K=e[28];let B;e[29]!==p||e[30]!==v?(B=v&&p&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[p.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",p.modified]}),p.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",p.added]})]}),e[29]=p,e[30]=v,e[31]=B):B=e[31];let re;e[32]!==N||e[33]!==K||e[34]!==B||e[35]!==$||e[36]!==_||e[37]!==O||e[38]!==L?(re=s.jsxs("button",{type:"button",onClick:N,onContextMenu:$,className:_,children:[O,L,K,B]}),e[32]=N,e[33]=K,e[34]=B,e[35]=$,e[36]=_,e[37]=O,e[38]=L,e[39]=re):re=e[39];let oe;e[40]!==c||e[41]!==P||e[42]!==j||e[43]!==C||e[44]!==S||e[45]!==I||e[46]!==f||e[47]!==u||e[48]!==T||e[49]!==v||e[50]!==o||e[51]!==n||e[52]!==g||e[53]!==x||e[54]!==r||e[55]!==y||e[56]!==w?(oe=(S||P||j||C||I)&&s.jsx("div",{className:me("absolute right-1 top-1/2 -translate-y-1/2",c?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(_s,{open:f===n.path,onOpenChange:ae=>y(ae?n.path:null),children:[s.jsx($s,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:T,children:s.jsx(Tu,{className:"h-4 w-4"})})}),s.jsxs(Bs,{align:"end",side:"bottom",onCloseAutoFocus:()=>y(null),children:[S&&s.jsxs(Lt,{onClick:ae=>{ae.stopPropagation(),g("rename",n)},children:[s.jsx(ea,{className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.rename")]}),s.jsxs(Lt,{onClick:ae=>{ae.stopPropagation(),Wn(n.path).then(ge=>{if(ge.ok){q.success(w("sidebarFilesTree.toast.pathCopied"));return}q.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(vr,{className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.copyPath")]}),s.jsxs(Lt,{onClick:ae=>{ae.stopPropagation();const ge=ru(r,n.path)||n.path;Wn(ge).then(ne=>{if(ne.ok){q.success(w("filesView.toast.relativePathCopied"));return}q.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(Qf,{className:"mr-2 h-4 w-4"})," ",w("filesView.tree.menu.copyRelativePath")]}),!v&&u&&s.jsxs(Lt,{onClick:ae=>{ae.stopPropagation(),u(n.path)},children:[s.jsx(Xr,{className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.save")]}),I&&s.jsxs(Lt,{onClick:ae=>{ae.stopPropagation(),x(n.path)},children:[s.jsx(Bf,{className:"mr-2 h-4 w-4"})," ",w(zu())]}),v&&(P||j)&&s.jsxs(s.Fragment,{children:[s.jsx(Ln,{}),P&&s.jsxs(Lt,{onClick:ae=>{ae.stopPropagation(),g("createFile",n)},children:[s.jsx(hc,{className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.newFile")]}),j&&s.jsxs(Lt,{onClick:ae=>{ae.stopPropagation(),g("createFolder",n)},children:[s.jsx(Aa,{className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.newFolder")]})]}),C&&s.jsxs(s.Fragment,{children:[s.jsx(Ln,{}),s.jsxs(Lt,{onClick:ae=>{ae.stopPropagation(),g("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(an,{className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=c,e[41]=P,e[42]=j,e[43]=C,e[44]=S,e[45]=I,e[46]=f,e[47]=u,e[48]=T,e[49]=v,e[50]=o,e[51]=n,e[52]=g,e[53]=x,e[54]=r,e[55]=y,e[56]=w,e[57]=oe):oe=e[57];let ee;return e[58]!==re||e[59]!==oe||e[60]!==M?(ee=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:M,children:[re,oe]}),e[58]=re,e[59]=oe,e[60]=M,e[61]=ee):ee=e[61],ee},Cx=({mode:t="full"})=>{const{t:e}=ut(),{files:n,runtime:r}=Yn(),{currentTheme:a,availableThemes:i,lightThemeId:o,darkThemeId:c}=Er(),{isMobile:d,isTablet:p,screenWidth:m}=dn(),u=d||p,f=yc(),y=_u(),h=ta()??"",b=kn(h.trim()),x=d||t!=="editor-only",g=t==="editor-only"&&!d,w=Vu(Ce=>Ce.searchFiles),v=bc(h),[S,P]=l.useState(""),j=vc(S,200),C=l.useRef(null),[I,R]=l.useState(!1),[k,A]=l.useState(!0),[N,D]=l.useState(!1),[T,M]=l.useState(!1),[$,F]=l.useState(!1),_=l.useRef(null),O=l.useRef(0),L=l.useCallback(Ce=>{O.current=Math.max(0,O.current+(Ce?1:-1))},[]),K=l.useCallback(Ce=>Ce instanceof Element?Ce.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);l.useEffect(()=>{if(!$)return;const Ce=qe=>{O.current>0||K(qe.target)||_.current&&!_.current.contains(qe.target)&&F(!1)};return document.addEventListener("mousedown",Ce),()=>document.removeEventListener("mousedown",Ce)},[K,$]);const[B,re]=l.useState("edit"),[oe,ee]=l.useState("edit"),[ae,ge]=l.useState("tree"),[ne,E]=l.useState("edit"),z=l.useRef({}),J=l.useRef({}),H=l.useRef({}),te=l.useMemo(()=>i.find(Ce=>Ce.metadata.id===o)??Gi(!1),[i,o]),ce=l.useMemo(()=>i.find(Ce=>Ce.metadata.id===c)??Gi(!0),[i,c]);l.useEffect(()=>{qi(te),qi(ce)},[te,ce]);const Se=l.useMemo(()=>[],[]),pe=qn(Ce=>b?Ce.byRoot[b]?.openPaths??Se:Se),we=qn(Ce=>b?Ce.byRoot[b]?.selectedPath??null:null),W=qn(Ce=>b?Ce.byRoot[b]?.expandedPaths??Se:Se),ue=qn(Ce=>Ce.addOpenPath),Y=qn(Ce=>Ce.removeOpenPath),le=qn(Ce=>Ce.removeOpenPathsByPrefix),Z=qn(Ce=>Ce.setSelectedPath),Ie=qn(Ce=>Ce.toggleExpandedPath),Ne=qn(Ce=>Ce.expandPaths),X=l.useCallback(Ce=>{const qe=kn(Ce),pt=qe.split("/"),ft=pt[pt.length-1]||qe,Ot=ft.includes(".")?ft.split(".").pop()?.toLowerCase():void 0;return{name:ft,path:qe,type:"file",extension:Ot}},[]),he=l.useMemo(()=>pe.map(X),[pe,X]),je=l.useMemo(()=>we??pe[0]??null,[pe,we]),be=l.useMemo(()=>je?X(je):null,[je,X]),fe=be?.path??"",Pe=!!(b&&fe&&!ic(fe,b)),Be=l.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&Pe}),[t,Pe]),G=l.useRef(null),[ke,Ee]=l.useState({left:!1,right:!1}),Ae=l.useCallback(()=>{const Ce=G.current;Ce&&Ee({left:Ce.scrollLeft>2,right:Ce.scrollLeft+Ce.clientWidth<Ce.scrollWidth-2})},[]);l.useEffect(()=>{const Ce=G.current;if(!Ce)return;Ae(),Ce.addEventListener("scroll",Ae,{passive:!0});const qe=new ResizeObserver(Ae);return qe.observe(Ce),()=>{Ce.removeEventListener("scroll",Ae),qe.disconnect()}},[Ae,he.length]);const[xe,V]=l.useState({}),de=l.useRef(new Set),Me=l.useRef(new Set),Le=l.useRef(new Map),se=l.useRef(0),[ie,U]=l.useState([]),[Ve,He]=l.useState(!1),[Ke,Ze]=l.useState(""),[Xe,dt]=l.useState(!1),[et,ct]=l.useState(null),[at,ye]=l.useState(""),[Ge,$e]=l.useState(null),[_e,tt]=l.useState(""),[Qe,ze]=l.useState(!1),gt=l.useRef(null),Vt=l.useRef(null),Kt=l.useRef(0),[Jt,At]=l.useState("idle"),[jt,ns]=l.useState(o3),[ot,Zt]=l.useState(!1),Yt=l.useRef(null),es=l.useRef(null),ls=l.useRef(null),ds=l.useRef(!1),gs=l.useRef(null),us=l.useRef(null),Ct=l.useRef(null),Ue=l.useRef(null),[Dt,Tt]=l.useState(0),wt=l.useRef(null),Wt=l.useRef({key:"",attempts:0});l.useEffect(()=>()=>{wt.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(wt.current),wt.current=null)},[]);const[_t,Vs]=l.useState(null),[mt,cs]=l.useState(null),[qt,Ds]=l.useState(""),[Os,Q]=l.useState(!1),[ht,vt]=l.useState(null),[zt,ss]=l.useState(!1),[is,Ss]=l.useState(!1),[Ms,We]=l.useState(!1),xt=!!n.writeFile,Pt=!!n.createDirectory,Mt=!!n.rename,as=!!n.delete,st=!!n.revealPath,Et=Br(Ce=>Ce.availableApps),os=Br(Ce=>Ce.isCacheStale),rs=Br(Ce=>Ce.initialize),$t=Br(Ce=>Ce.loadInstalledApps);l.useEffect(()=>{rs()},[rs]);const xs=l.useCallback(Ce=>{n.revealPath&&n.revealPath(Ce).catch(()=>{q.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),bn=l.useCallback(async Ce=>{if(!be?.path||await l1(be.path,Ce.id,Ce.appName)||await Hl(be.path,Ce.appName))return;const ft=Xk(be.path)||b;ft&&await Hl(ft,Ce.appName)||q.error(e("filesView.toast.openInAppFailed",{app:Ce.appName}))},[b,be?.path,e]),en=l.useCallback((Ce,qe)=>{Vs(Ce),cs(qe),Ds(Ce==="rename"&&qe.name||""),Q(!1)},[]),[Ws,hn]=l.useState(null),un=l.useRef(!1),fn=l.useRef(null),[gn,yn]=l.useState(!1),mn=De(Ce=>Ce.setMainTabGuard),Rn=De(Ce=>Ce.pendingFileNavigation),Fr=De(Ce=>Ce.setPendingFileNavigation),Kn=De(Ce=>Ce.pendingFileFocusPath),Fe=De(Ce=>Ce.setPendingFileFocusPath),Nt=De(Ce=>Ce.shortcutOverrides),Xt=yt(Ce=>Ce.settingsDefaultFileViewerPreview);l.useEffect(()=>{const Ce=()=>{un.current=!1,fn.current=null,yn(!1)};return document.addEventListener("mouseup",Ce),()=>document.removeEventListener("mouseup",Ce)},[]),l.useEffect(()=>()=>{gs.current!==null&&window.clearTimeout(gs.current),us.current!==null&&window.clearTimeout(us.current)},[]);const ms=l.useCallback((Ce,qe)=>{const pt=Ce.split(`
|
|
48
|
+
`),ft=Math.max(1,qe.start),Ot=Math.min(pt.length,qe.end);return ft>Ot?"":pt.slice(ft-1,Ot).join(`
|
|
49
|
+
`)},[]),tn=Xu({source:"file",fileLabel:be?.path??null,language:be?.path&&To(be.path)||"text",getCodeForRange:Ce=>ms(Ke,rc(Ce)),toStoreRange:Ce=>({startLine:Ce.start,endLine:Ce.end}),fromDraftRange:Ce=>({start:Ce.startLine,end:Ce.endLine})}),{drafts:sn,commentText:Hs,editingDraftId:Gs,setSelection:nn,saveComment:pr,cancel:lr,reset:ma,startEdit:Bn,deleteDraft:Or}=tn;l.useEffect(()=>{hn(null),ma(),mn(null),tt(""),ze(!1)},[be?.path,ma,mn]),l.useEffect(()=>{nn(Ws)},[Ws,nn]),l.useEffect(()=>{if(!Ws&&!Gs)return;const Ce=pt=>{const ft=pt.target;ft.closest('[data-comment-input="true"]')||ft.closest('[data-comment-card="true"]')||ft.closest(".cm-gutterElement")||ft.closest("[data-sonner-toast]")||ft.closest("[data-sonner-toaster]")||(hn(null),lr())},qe=setTimeout(()=>{document.addEventListener("click",Ce)},100);return()=>{clearTimeout(qe),document.removeEventListener("click",Ce)}},[lr,Gs,Ws]);const _n=l.useCallback((Ce,qe)=>{const pt=qe??Ws??void 0;qe&&hn(qe),pr(Ce,pt),hn(null)},[Ws,pr]),nr=l.useCallback((Ce,qe)=>{const pt=qe.filter(ft=>ft&&typeof ft.name=="string"&&ft.name.length>0).filter(ft=>f||!ft.name.startsWith(".")).filter(ft=>y||!r3(ft.name)).map(ft=>{const Ot=ft.name,Gt=kn(ft.path||""),Rs=Gt?t3(Gt)?Gt:kn(`${Ce}/${Gt}`):kn(`${Ce}/${Ot}`),Ys=ft.isDirectory?"directory":"file",Zn=Ys==="file"&&Ot.includes(".")?Ot.split(".").pop()?.toLowerCase():void 0;return{name:Ot,path:Rs,type:Ys,extension:Zn}});return e3(pt)},[y,f]),vn=l.useCallback(async Ce=>{const qe=kn(Ce.trim());if(!qe||de.current.has(qe)||Me.current.has(qe))return;Me.current=new Set(Me.current),Me.current.add(qe);const pt=se.current+1;se.current=pt,Le.current=new Map(Le.current),Le.current.set(qe,pt);const ft=()=>Le.current.get(qe)===pt,Ot=!y;await(r.isDesktop?n.listDirectory(qe,{respectGitignore:Ot}).then(Rs=>Rs.entries.map(Ys=>({name:Ys.name,path:Ys.path,isDirectory:Ys.isDirectory}))):Mn.listLocalDirectory(qe,{respectGitignore:Ot}).then(Rs=>Rs.map(Ys=>({name:Ys.name,path:Ys.path,isDirectory:Ys.isDirectory})))).then(Rs=>{if(!ft())return;const Ys=nr(qe,Rs);de.current=new Set(de.current),de.current.add(qe),V(Zn=>({...Zn,[qe]:Ys}))}).catch(()=>{ft()&&V(Rs=>({...Rs,[qe]:Rs[qe]??[]}))}).finally(()=>{ft()&&(Le.current=new Map(Le.current),Le.current.delete(qe),Me.current=new Set(Me.current),Me.current.delete(qe))})},[n,nr,r.isDesktop,y]),cr=l.useCallback(async()=>{b&&(de.current=new Set,Me.current=new Set,Le.current=new Map,V(Ce=>Object.keys(Ce).length===0?Ce:{}),await vn(b))},[vn,b]),En=l.useCallback(async Ce=>{if(!Ce){await cr();return}const qe=kn(Ce);de.current=new Set(de.current),de.current.delete(qe),Me.current=new Set(Me.current),Me.current.delete(qe),await vn(qe)},[vn,cr]),Ur=l.useRef(""),Wr=l.useRef("");l.useEffect(()=>{if(!b)return;const Ce=`${b}|h${f?"1":"0"}|g${y?"1":"0"}`,qe=Ur.current!==b,pt=Wr.current!==Ce;!qe&&!pt||(qe&&(Ur.current=b,Ze(""),ct(null),ye(""),$e(null),R(!1)),pt&&(Wr.current=Ce,de.current=new Set,Me.current=new Set,Le.current=new Map,V(ft=>Object.keys(ft).length===0?ft:{}),vn(b)))},[vn,b,y,f]),l.useEffect(()=>{if(!n.listDirectory)return;const Ce=()=>{if(!document.hidden&&W.length>0)for(const qe of W)En(qe)};return document.addEventListener("visibilitychange",Ce),()=>document.removeEventListener("visibilitychange",Ce)},[W,n.listDirectory,En]),l.useEffect(()=>{if(!n.listDirectory||W.length===0)return;const Ce=setInterval(()=>{if(!document.hidden)for(const qe of W)En(qe)},8e3);return()=>clearInterval(Ce)},[W,n.listDirectory,En]);const Pa=l.useCallback(async Ce=>{if(Ce?.preventDefault(),!mt||!_t)return;Q(!0);const qe=()=>{Vs(null)},pt=Ot=>{q.error(Ot)},ft=()=>{Q(!1)};if(_t==="createFile"){if(!qt.trim()){pt(e("sidebarFilesTree.toast.filenameRequired")),ft();return}if(!n.writeFile){pt(e("sidebarFilesTree.toast.writeNotSupported")),ft();return}const Ot=mt.path,Gt=Ot?`${Ot}/`:"",Rs=kn(`${Gt}${qt.trim()}`);await n.writeFile(Rs,"").then(async Ys=>{Ys.success&&(q.success(e("sidebarFilesTree.toast.fileCreated")),await En(Ot)),qe()}).catch(()=>pt(e("sidebarFilesTree.toast.operationFailed"))).finally(ft);return}if(_t==="createFolder"){if(!qt.trim()){pt(e("sidebarFilesTree.toast.folderNameRequired")),ft();return}const Ot=mt.path,Gt=Ot?`${Ot}/`:"",Rs=kn(`${Gt}${qt.trim()}`);await n.createDirectory(Rs).then(async Ys=>{Ys.success&&(q.success(e("sidebarFilesTree.toast.folderCreated")),await En(Ot)),qe()}).catch(()=>pt(e("sidebarFilesTree.toast.operationFailed"))).finally(ft);return}if(_t==="rename"){if(!qt.trim()){pt(e("sidebarFilesTree.toast.nameRequired")),ft();return}if(!n.rename){pt(e("sidebarFilesTree.toast.renameNotSupported")),ft();return}const Ot=mt.path,Gt=Ot.split("/").slice(0,-1).join("/"),Rs=Gt?`${Gt}/`:"",Ys=kn(`${Rs}${qt.trim()}`);await n.rename(Ot,Ys).then(async Zn=>{Zn.success&&(q.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await En(Gt),b&&le(b,Ot),(be?.path===Ot||be?.path.startsWith(`${Ot}/`))&&(b&&Z(b,null),Ze(""),ct(null),ye(""),$e(null),d&&R(!1))),qe()}).catch(()=>pt(e("sidebarFilesTree.toast.operationFailed"))).finally(ft);return}if(_t==="delete"){if(!n.delete){pt(e("sidebarFilesTree.toast.deleteNotSupported")),ft();return}const Ot=mt.path,Gt=Ot.split("/").slice(0,-1).join("/");await n.delete(Ot).then(async Rs=>{Rs.success&&(q.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await En(Gt),b&&le(b,Ot),(be?.path===Ot||be?.path.startsWith(`${Ot}/`))&&(b&&Z(b,null),Ze(""),ct(null),ye(""),$e(null),d&&R(!1))),qe()}).catch(()=>pt(e("sidebarFilesTree.toast.operationFailed"))).finally(ft);return}ft()},[_t,mt,qt,n,En,d,le,b,be?.path,Z,e]);l.useEffect(()=>{if(!h){U([]),He(!1);return}const Ce=j.trim();if(!Ce){U([]),He(!1);return}let qe=!1;return He(!0),w(h,Ce,150,{includeHidden:f,respectGitignore:!y,type:"file"}).then(pt=>{if(qe)return;const Ot=pt.filter(Gt=>y||!a3(Gt.path)).map(Gt=>({name:Gt.name,path:kn(Gt.path),type:"file",extension:Gt.extension,relativePath:Gt.relativePath}));U(Ot)}).catch(()=>{qe||U([])}).finally(()=>{qe||He(!1)}),()=>{qe=!0}},[h,j,w,f,y]);const sa=l.useCallback(async(Ce,qe)=>{if(n.readFile)return(await n.readFile(Ce,qe)).content??"";const pt=new URLSearchParams({path:Ce});qe?.allowOutsideWorkspace&&pt.set("allowOutsideWorkspace","true"),qe?.optional&&pt.set("optional","true");const ft=await fetch(`/api/fs/read?${pt.toString()}`,{cache:qe?.optional?"no-store":"default"});if(!ft.ok){const Ot=await ft.json().catch(()=>({error:ft.statusText}));throw new Error(Ot.error||e("filesView.error.readFileFailed"))}return ft.text()},[n,e]),Hn=l.useCallback(async(Ce,qe)=>{if(n.statFile){const pt=await n.statFile(Ce,qe);return{path:pt.path,size:pt.size,mtimeMs:pt.mtimeMs}}return null},[n]),Nn=l.useMemo(()=>Ke.length>lo?`${Ke.slice(0,lo)}
|
|
50
|
+
|
|
51
|
+
… truncated …`:Ke,[Ke]),ln=l.useMemo(()=>_e!==Nn,[_e,Nn]),kr=l.useCallback(async()=>{if(!be||!n.writeFile)return q.error(e("filesView.toast.savingNotSupported")),!1;if(!ln)return!0;ze(!0);try{return(await n.writeFile(be.path,_e))?.success?(Ze(_e),Hn(be.path).then(qe=>{qe&&(Vt.current=qe)}).catch(()=>{}),!0):(q.error(e("filesView.toast.writeFileFailed")),!1)}catch(Ce){return q.error(Ce instanceof Error?Ce.message:e("filesView.toast.saveFailed")),!1}finally{ze(!1)}},[_e,n,ln,Hn,be,e]);l.useEffect(()=>{if(!ln){mn(null);return}const Ce=qe=>ds.current?(ds.current=!1,!0):(Zt(!0),es.current=qe,!1);return mn(Ce),()=>{De.getState().mainTabGuard===Ce&&mn(null)}},[ln,mn]),l.useEffect(()=>{try{window.localStorage.setItem(Sx,jt?"true":"false")}catch{}},[jt]),l.useEffect(()=>{jt||(At("idle"),gt.current&&(clearTimeout(gt.current),gt.current=null))},[jt]);const Kr=1500;l.useEffect(()=>{const Ce=!!(be&&n.writeFile);if(!(!jt||!ln||!Ce||Qe))return gt.current=setTimeout(()=>{kr().then(qe=>{qe&&(At("saved"),setTimeout(()=>At("idle"),2e3))})},Kr),()=>{gt.current&&(clearTimeout(gt.current),gt.current=null)}},[jt,_e,ln,be,n.writeFile,Qe,kr]),l.useEffect(()=>{At("idle")},[be?.path]),l.useEffect(()=>{const Ce=qe=>{$u(qe)&&(qe.key.toLowerCase()==="s"?(qe.preventDefault(),gt.current&&(clearTimeout(gt.current),gt.current=null),Qe||kr().then(pt=>{pt&&(At("saved"),setTimeout(()=>At("idle"),2e3))})):qe.key.toLowerCase()==="f"&&(qe.preventDefault(),M(!0)))};return window.addEventListener("keydown",Ce),()=>window.removeEventListener("keydown",Ce)},[Qe,kr]);const mi=l.useCallback(async Ce=>{const qe=Kt.current+1;Kt.current=qe;const pt=()=>{if(!b)return!1;const Rs=qn.getState().byRoot[b],Ys=Rs?.selectedPath??Rs?.openPaths[0]??null;return Kt.current===qe&&Ys===Ce.path};ct(null),ye(""),$e(null);const ft=Qi(Ce.path),Ot=Ce.path.toLowerCase().endsWith(".svg");if(d&&R(!0),r.isDesktop&&ft&&!Ot){Ze(""),tt(""),dt(!0);return}if(!r.isDesktop&&ft&&!Ot){Ze(""),tt(""),$e(Ce.path),dt(!1);return}dt(!0);const Gt={allowOutsideWorkspace:t==="editor-only"&&!!b&&!ic(Ce.path,b)};await sa(Ce.path,Gt).then(Rs=>{pt()&&(Ze(Rs),tt(Rs.length>lo?`${Rs.slice(0,lo)}
|
|
52
|
+
|
|
53
|
+
… truncated …`:Rs),$e(Ce.path),Hn(Ce.path,Gt).then(Ys=>{Ys&&pt()&&(Vt.current=Ys)}).catch(()=>{}))}).catch(Rs=>{if(pt()){if(i3(Rs)){if(dt(!1),b&&Z(b,null),ct(null),Ze(""),tt(""),$e(null),Vt.current=null,S.trim().length>0&&P(""),d&&R(!1),b){const Zn=[...Qp(Ce.path,b),Ce.path];Zn.length>0&&Ne(b,Zn);for(const tl of Zn)de.current.has(tl)||vn(tl)}return}Ze(""),tt(""),ct(Rs instanceof Error?Rs.message:e("filesView.error.readFileFailed")),Vt.current=null}}).finally(()=>{pt()&&dt(!1)})},[Ne,d,vn,t,sa,Hn,b,r.isDesktop,S,Z,e]),pa=l.useCallback(async(Ce,qe)=>{if(!b)return;const pt=Qp(Ce,b),ft=qe?[...pt,Ce]:pt;ft.length>0&&Ne(b,ft);for(const Ot of ft)de.current.has(Ot)||await vn(Ot)},[Ne,vn,b]),pi=l.useCallback((Ce,qe)=>{const pt=qe.findIndex(ft=>ft.path===Ce);return pt===-1||qe.length<=1?null:qe[pt+1]??qe[pt-1]??null},[]),Dn=l.useCallback(async Ce=>{if(ds.current)ds.current=!1;else if(ln){Zt(!0),Yt.current=Ce;return}b&&(Z(b,Ce.path),ue(b,Ce.path),pa(Ce.path,!1)),ct(null),ye(""),Ze(""),tt(""),$e(null),d&&R(!0)},[ue,pa,ln,d,b,Z]);l.useEffect(()=>{be?.path&&pa(be.path,!1)},[pa,be?.path]),l.useEffect(()=>{if(!be){Kt.current+=1,dt(!1);return}Ge!==be.path&&mi(be)},[mi,Ge,be]);const hi=l.useRef(ln);hi.current=ln,l.useEffect(()=>{if(!be?.path||Ge!==be.path)return;let Ce=!1;const qe=window.setInterval(()=>{document.hidden||Hn(be.path,Be).then(pt=>{if(Ce||!pt)return;const ft=Vt.current;if(!ft||ft.path!==be.path){Vt.current=pt;return}const Ot=pt.mtimeMs!==void 0&&ft.mtimeMs!==void 0&&pt.mtimeMs!==ft.mtimeMs,Gt=pt.size!==ft.size;!Ot&&!Gt||hi.current||(Vt.current=pt,$e(null))}).catch(()=>{})},2e3);return()=>{Ce=!0,window.clearInterval(qe)}},[Ge,Hn,be?.path,Be]);const fi=l.useCallback(()=>{const Ce=Yt.current,qe=es.current,pt=ls.current;if(Yt.current=null,es.current=null,ls.current=null,ds.current=!0,Zt(!1),tt(Nn),pt){b&&Y(b,pt),be?.path===pt&&(Ce?Dn(Ce):(b&&Z(b,null),Ze(""),ct(null),ye(""),$e(null),d&&R(!1)));return}if(Ce){Dn(Ce);return}qe&&(mn(null),De.getState().setActiveMainTab(qe))},[Nn,Dn,d,Y,b,be?.path,mn,Z]),gi=l.useCallback(async()=>{const Ce=Yt.current,qe=es.current,pt=ls.current;if(!await kr()){ds.current=!1;return}if(Yt.current=null,es.current=null,ls.current=null,ds.current=!0,Zt(!1),pt){b&&Y(b,pt),be?.path===pt&&(Ce?await Dn(Ce):(b&&Z(b,null),Ze(""),ct(null),ye(""),$e(null),d&&R(!1)));return}if(Ce){await Dn(Ce);return}qe&&(mn(null),De.getState().setActiveMainTab(qe))},[Dn,d,Y,b,kr,be?.path,mn,Z]),Xn=l.useCallback(Ce=>{const qe=be?.path===Ce,pt=pi(Ce,he);if(qe&&ln){Zt(!0),Yt.current=pt,ls.current=Ce;return}if(b&&Y(b,Ce),!!qe){if(pt){Dn(pt);return}b&&Z(b,null),Ze(""),ct(null),ye(""),$e(null),d&&R(!1)}},[pi,Dn,ln,d,he,Y,b,be?.path,Z]),Re=l.useCallback(Ce=>{if(pe.includes(Ce))return"open";if(v?.files){const qe=Ce.startsWith(b+"/")?Ce.slice(b.length+1):Ce,pt=v.files.find(ft=>ft.path===qe);if(pt){if(pt.index==="A"||pt.working_dir==="?")return"git-added";if(pt.index==="D")return"git-deleted";if(pt.index==="M"||pt.working_dir==="M")return"git-modified"}}return null},[pe,v,b]),Je=l.useCallback(Ce=>{if(!v?.files)return null;const qe=Ce.startsWith(b+"/")?Ce.slice(b.length+1):Ce,pt=qe?`${qe}/`:"";let ft=0,Ot=0;for(const Gt of v.files)Gt.path.startsWith(pt)&&((Gt.index==="M"||Gt.working_dir==="M")&&ft++,(Gt.index==="A"||Gt.working_dir==="?")&&Ot++);return ft+Ot>0?{modified:ft,added:Ot}:null},[v,b]),Ye=l.useCallback(async Ce=>{const qe=kn(Ce);b&&(Ie(b,qe),de.current.has(qe)||await vn(qe))},[vn,b,Ie]),it=l.useMemo(()=>({canRename:Mt,canCreateFile:xt,canCreateFolder:Pt,canDelete:as,canReveal:st}),[Mt,xt,Pt,as,st]);function Ft(Ce,qe){const pt=xe[Ce]??[];return pt.map((ft,Ot)=>{const Gt=ft.type==="directory",Rs=Gt&&W.includes(ft.path),Ys=be?.path===ft.path,Zn=Ot===pt.length-1;return s.jsxs("li",{className:"relative",children:[qe>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Zn&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(d3,{node:ft,root:b,isExpanded:Rs,isActive:Ys,isMobile:d,alwaysShowActions:u,status:Gt?void 0:Re(ft.path),badge:Gt?Je(ft.path):void 0,permissions:it,downloadFile:n.downloadFile,contextMenuPath:ht,setContextMenuPath:vt,onSelect:Dn,onToggle:Ye,onRevealPath:xs,onOpenDialog:en}),Gt&&Rs&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Ft(ft.path,qe+1)})]},ft.path)})}const Ut=!!(be?.path&&Qi(be.path)),Ks=!!(be?.path&&be.path.toLowerCase().endsWith(".svg")),wn=l.useMemo(()=>kn(Rn?.path??""),[Rn?.path]),dr=!!(Rn&&wn&&fe&&fe===wn&&!Xe&&!et&&!Ut),xi=l.useMemo(()=>ru(b,fe),[fe,b]),Jo=!!(be&&(!Ut||Ks)&&Ke.length>0),bi=!!(be&&xi.length>0),ur=!!(be&&!Pe&&!Ut&&n.writeFile&&Ke.length<=lo),Hr=!!(be?.path&&l3(be.path)),yi=!!(be?.path&&c3(be.path)),vi=!!(be?.path&&ld(be.path)),ro=!!(be&&!Ut)&&!Hr&&!(vi&&ne==="preview"),ha=l.useMemo(()=>fe?Nx(fe):null,[fe]),[Da,cn]=l.useState(null);l.useEffect(()=>{let Ce=!1;const qe=be?.path;if(!qe||ha){cn(null);return}return cn(null),Yk(qe).then(pt=>{Ce||cn(pt)}),()=>{Ce=!0}},[be?.path,ha]),l.useEffect(()=>{!ur&&B==="edit"&&re("view")},[ur,B]);const wi="openchamber:files:md-viewer-mode",ji="openchamber:files:html-viewer-mode",Yo="openchamber:files:json-viewer-mode";l.useEffect(()=>{const Ce=be?.path;if(!Ce)return;const qe=Xt?"view":"edit";re(z.current[Ce]??qe);let pt=Xt?"preview":"edit";try{const Gt=localStorage.getItem(wi);(Gt==="preview"||Gt==="edit")&&(pt=Gt)}catch{}ee(J.current[Ce]??pt);let ft=Xt?"preview":"edit";try{const Gt=localStorage.getItem(ji);(Gt==="preview"||Gt==="edit")&&(ft=Gt)}catch{}E(H.current[Ce]??ft);let Ot=Xt?"tree":"text";try{const Gt=localStorage.getItem(Yo);(Gt==="tree"||Gt==="text")&&(Ot=Gt)}catch{}ge(Ot)},[be?.path,Xt]);const Ic=l.useCallback(Ce=>{const qe=be?.path;qe&&(z.current[qe]=Ce),re(Ce)},[be?.path]),Ta=l.useCallback(Ce=>{const qe=be?.path;qe&&(J.current[qe]=Ce),ee(Ce);try{localStorage.setItem(wi,Ce)}catch{}},[be?.path]),Sn=l.useCallback(()=>oe,[oe]),Ac=l.useCallback(Ce=>{ge(Ce);try{localStorage.setItem(Yo,Ce)}catch{}},[]),Pc=l.useCallback(Ce=>{const qe=be?.path;qe&&(H.current[qe]=Ce),E(Ce);try{localStorage.setItem(ji,Ce)}catch{}},[be?.path]),Xo=l.useCallback(()=>ne,[ne]);l.useEffect(()=>{if(!Rn||!b)return;const Ce=()=>{typeof window>"u"||wt.current===null&&(wt.current=window.requestAnimationFrame(()=>{wt.current=null,Tt(na=>na+1)}))},qe=(na,Ra)=>{if(na.state.doc.length!==Ra.length)return!1;if(Ra.length===0)return!0;const Mc=Math.min(128,Ra.length);if(na.state.sliceDoc(0,Mc)!==Ra.slice(0,Mc))return!1;const lm=Math.max(0,Ra.length-Mc);return na.state.sliceDoc(lm,Ra.length)===Ra.slice(lm)},pt=kn(Rn.path);if(!pt){Fr(null),Wt.current={key:"",attempts:0};return}const ft=`${pt}:${Rn.line}:${Rn.column??1}`;if(Wt.current.key!==ft&&(Wt.current={key:ft,attempts:0}),be?.path!==pt){if(ot)return;Dn(X(pt));return}if(Xe||Ge!==pt)return;if(et||Ut){Fr(null),Wt.current={key:"",attempts:0};return}if(!ur)return;if(B!=="edit"){re("edit");return}const Ot=Ct.current;if(!Ot){Ce();return}if(!qe(Ot,_e)){Ce();return}const Gt=Math.max(1,Math.min(Rn.line,Ot.state.doc.lines)),Rs=Ot.state.doc.line(Gt),Ys=Math.max(1,Rn.column||1),Zn=Math.max(0,Rs.to-Rs.from),tl=Math.min(Zn,Ys-1),ao=Rs.from+tl;if(!(Ot.state.selection.main.head===ao)||Wt.current.attempts===0){Wt.current.attempts+=1,Ot.dispatch({selection:{anchor:ao},effects:or.scrollIntoView(ao,{y:"center"})}),Ot.focus(),Ce();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const na=Ct.current;na&&(na.dispatch({selection:{anchor:ao},effects:or.scrollIntoView(ao,{y:"center"})}),na.focus())}),Fr(null),Wt.current={key:"",attempts:0}},[ur,ot,_e,Dt,et,Xe,Ut,Ge,Dn,Rn,b,be?.path,Fr,B,X]),l.useEffect(()=>{if(!Kn||!b)return;const Ce=kn(Kn);if(!Ce){Fe(null);return}if(be?.path!==Ce){if(ot)return;Dn(X(Ce));return}if(!(Xe||Ge!==Ce||et||Ut)){if(ur&&B==="edit"){const qe=Ct.current;if(!qe)return;qe.focus()}Fe(null)}},[ur,ot,et,Xe,Dn,Ut,Ge,Kn,b,be?.path,Fe,B,X]);const fa=l.useCallback(Ce=>{if(!d||!Ce||!Ce.hasFocus||typeof window>"u")return;const qe=window.visualViewport;if(!qe)return;const pt=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,pt-(qe.offsetTop+qe.height))<=0)return;const Ot=Ce.state.selection.main.head,Gt=Ce.coordsAtPos(Ot);if(!Gt)return;const Rs=Math.round(qe.offsetTop+qe.height),Zn=Gt.bottom+20-Rs;Zn<=0||(Ce.scrollDOM.scrollTop+=Zn)},[d]);l.useEffect(()=>{if(!d||typeof window>"u")return;const Ce=()=>{window.requestAnimationFrame(()=>{fa(Ct.current)})},qe=window.visualViewport;return qe?.addEventListener("resize",Ce),qe?.addEventListener("scroll",Ce),document.addEventListener("selectionchange",Ce),()=>{qe?.removeEventListener("resize",Ce),qe?.removeEventListener("scroll",Ce),document.removeEventListener("selectionchange",Ce)}},[d,fa]),l.useEffect(()=>{if(!ur||B!=="edit"||d)return;const Ce=ia("open_go_to_line",Nt),qe=pt=>{const ft=pt.target;if(ft?.closest('[role="dialog"]'))return;const Ot=!!ft?.closest(".cm-editor");ft?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!Ot||!document.activeElement?.closest(".cm-editor")||kl(pt,Ce)&&(pt.preventDefault(),We(!0))};return window.addEventListener("keydown",qe),()=>window.removeEventListener("keydown",qe)},[ur,d,Nt,B]);const Zo=l.useMemo(()=>{if(!be?.path)return[nu(a)];const Ce=[nu(a)],qe=ha??Da;return qe&&Ce.push(qe),k&&Ce.push(or.lineWrapping),d&&Ce.push(or.updateListener.of(pt=>{pt.view.hasFocus&&(pt.selectionSet||pt.focusChanged||pt.viewportChanged||pt.geometryChanged)&&window.requestAnimationFrame(()=>{fa(pt.view)})})),Ce},[a,be?.path,ha,Da,k,d,fa]),Ma=l.useMemo(()=>({light:te.metadata.id,dark:ce.metadata.id}),[te.metadata.id,ce.metadata.id]),Ni=be?.path&&Ut?r.isDesktop?Ks?`data:${Im(be.path)};utf8,${encodeURIComponent(Ke)}`:at:Ks?`data:${Im(be.path)};utf8,${encodeURIComponent(Ke)}`:`/api/fs/raw?${new URLSearchParams({path:be.path,...Be.allowOutsideWorkspace?{allowOutsideWorkspace:"true"}:{}}).toString()}`:"";l.useEffect(()=>{let Ce=!1;return(async()=>{if(!r.isDesktop||!be?.path||!Ut||Ks){ye("");return}ct(null),await(n.readFileBinary?n.readFileBinary(be.path,Be).then(ft=>ft.dataUrl):Promise.resolve(uy(be.path,"asset"))).then(ft=>{Ce||(ye(ft),$e(be.path))}).catch(ft=>{Ce||(ye(""),ct(ft instanceof Error?ft.message:e("filesView.error.readFileFailed")),$e(null))}).finally(()=>{Ce||dt(!1)})})(),()=>{Ce=!0}},[n,Ut,Ks,r.isDesktop,be?.path,Be,e]);const Dc=()=>s.jsx(ws,{open:!!_t,onOpenChange:Ce=>!Ce&&Vs(null),children:s.jsxs(vs,{children:[s.jsxs(Cs,{children:[s.jsxs(js,{children:[_t==="createFile"&&e("filesView.dialog.createFile.title"),_t==="createFolder"&&e("filesView.dialog.createFolder.title"),_t==="rename"&&e("filesView.dialog.rename.title"),_t==="delete"&&e("filesView.dialog.delete.title")]}),s.jsxs(Fs,{children:[_t==="createFile"&&e("filesView.dialog.createFile.description",{path:mt?.path??e("filesView.dialog.rootFallback")}),_t==="createFolder"&&e("filesView.dialog.createFolder.description",{path:mt?.path??e("filesView.dialog.rootFallback")}),_t==="rename"&&e("filesView.dialog.rename.description",{name:mt?.name??""}),_t==="delete"&&e("filesView.dialog.delete.description",{name:mt?.name??""})]})]}),_t!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Bt,{value:qt,onChange:Ce=>Ds(Ce.target.value),placeholder:e(_t==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:Ce=>{Ce.key==="Enter"&&Pa()},autoFocus:!0})}),s.jsxs(Xs,{children:[s.jsx(ve,{variant:"outline",onClick:()=>Vs(null),disabled:Os,children:e("filesView.dialog.cancel")}),s.jsx(ve,{variant:_t==="delete"?"destructive":"default",onClick:()=>{Pa()},disabled:Os||_t!=="delete"&&!qt.trim(),children:Os?s.jsx(ts,{className:"animate-spin"}):e(_t==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm")})]})]})}),Tc=l.useMemo(()=>gx({drafts:sn,editingDraftId:Gs,commentText:Hs,selection:Ws,isDragging:gn,fileLabel:be?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:Ce=>({start:Ce.startLine,end:Ce.endLine}),onSave:_n,onCancel:()=>{hn(null),lr()},onEdit:Ce=>{Bn(Ce),hn({start:Ce.startLine,end:Ce.endLine})},onDelete:Or}),[lr,Hs,Or,Gs,sn,_n,gn,Ws,be?.path,Bn]),el=l.useCallback((Ce,qe)=>s.jsx("div",{className:"h-full",children:s.jsx(dy,{file:{name:Ce.name,contents:qe,lang:To(Ce.path)||void 0},options:{disableFileHeader:!0,overflow:k?"wrap":"scroll",theme:Ma,themeType:a.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[a.metadata.variant,Ma,k]),Te=({exitFullscreenOnly:Ce=!1}={})=>be?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:[ur&&B==="edit"&&s.jsxs(s.Fragment,{children:[Qe?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(ts,{className:"h-3.5 w-3.5 animate-spin"}),e("filesView.editor.saving")]}):jt&&Jt==="saved"&&!ln?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(Zs,{className:"h-3.5 w-3.5"}),e("filesView.editor.saved")]}):ln?s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>{kr()},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(jt?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${Jl()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${Jl()}+S`}),children:s.jsx(my,{className:"h-4 w-4"})}):null,s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>ns(qe=>!qe),className:me("h-6 w-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",jt?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(jt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(jt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:jt?s.jsx(py,{className:"size-4"}):s.jsx(hy,{className:"size-4"})})]}),s.jsxs(_s,{onOpenChange:L,children:[s.jsx($s,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",className:"h-6 w-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(fy,{className:"h-4 w-4"})})}),s.jsxs(Bs,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Et.map(qe=>s.jsxs(Lt,{className:"flex items-center gap-2",onClick:()=>{bn(qe)},children:[s.jsx(Zk,{label:qe.label,iconDataUrl:qe.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:qe.label})]},qe.id)),os?s.jsxs(Lt,{className:"flex items-center gap-2",onClick:()=>{$t(!0)},children:[s.jsx(In,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Ut&&s.jsxs(s.Fragment,{children:[s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>A(!k),className:me("h-6 w-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",k?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(k?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(_f,{className:"size-4"})}),B==="edit"&&s.jsxs(s.Fragment,{children:[s.jsx(ve,{variant:"ghost",size:"sm",onClick:qe=>{M(!T),qe.currentTarget.blur()},className:"h-6 w-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(Jn,{className:"size-4"})}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:qe=>{We(pt=>!pt),qe.currentTarget.blur()},className:"h-6 w-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(gy,{className:"size-4"})}),s.jsx(Gk,{open:Ms,onOpenChange:We,view:Ct.current,variant:"inline"})]})]}),ro&&ur&&!yi&&!vi&&s.jsx(tu,{currentMode:B==="view"?"preview":"edit",onToggle:()=>{Ic(B==="view"?"edit":"view")}}),(Hr||ld(be?.path??""))&&s.jsx(tu,{currentMode:Hr?Sn():Xo(),onToggle:()=>{ld(be?.path??"")?Pc(Xo()==="preview"?"edit":"preview"):Ta(Sn()==="preview"?"edit":"preview")}}),yi&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>Ac(ae==="tree"?"text":"tree"),className:"h-6 w-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(ae==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:ae==="tree"?s.jsx(xy,{className:"size-4"}):s.jsx(qf,{className:"size-4"})}),Jo&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:async()=>{(await Wn(Ke)).ok?(ss(!0),gs.current!==null&&window.clearTimeout(gs.current),gs.current=window.setTimeout(()=>{ss(!1)},1200)):q.error(e("filesView.toast.copyFailed"))},className:"h-6 w-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:zt?s.jsx(Zs,{className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(ni,{className:"h-4 w-4"})}),bi&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:async()=>{(await Wn(xi)).ok?(Ss(!0),us.current!==null&&window.clearTimeout(us.current),us.current=window.setTimeout(()=>{Ss(!1)},1200)):q.error(e("filesView.toast.copyFailed"))},className:"h-6 w-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:xi}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:xi}),children:is?s.jsx(Zs,{className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(Qf,{className:"h-4 w-4"})}),n.downloadFile&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>{const qe=n.downloadFile;qe&&qe(be.path)},className:"h-6 w-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(Xr,{className:"h-4 w-4"})}),Ce?s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>D(!1),className:"h-6 w-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(Ed,{className:"h-4 w-4"})}):!d&&t==="full"&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>D(!N),className:"h-6 w-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:N?s.jsx(Ed,{className:"h-4 w-4"}):s.jsx(Jf,{className:"h-4 w-4"})})]}):null,bt=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(ws,{open:ot,onOpenChange:Ce=>{Ce||Zt(!0)},children:s.jsxs(vs,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:e("filesView.unsaved.title")}),s.jsx(Fs,{children:e("filesView.unsaved.description")})]}),s.jsxs(Xs,{children:[s.jsx(ve,{variant:"outline",onClick:()=>{gi()},disabled:Qe,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(ve,{variant:"destructive",onClick:fi,children:e("filesView.unsaved.discard")})]})]})}),s.jsx("div",{className:me("flex flex-col flex-shrink-0",x&&"border-b border-border/40"),children:x?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[d&&I&&s.jsx("button",{type:"button",onClick:()=>R(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex h-7 w-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(Wi,{className:"h-5 w-5"})}),d?be?s.jsxs(_s,{children:[s.jsx($s,{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(Dr,{filePath:be.path,extension:be.extension,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:be.name}),s.jsx(ks,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Bs,{align:"start",className:"min-w-[16rem]",children:he.map(Ce=>{const qe=be?.path===Ce.path;return s.jsxs(Lt,{onSelect:pt=>{if(pt.target.closest("[data-close-open-file]")){pt.preventDefault();return}qe||Dn(Ce)},className:me("flex items-center justify-between gap-2",qe&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 truncate",children:[s.jsx(Dr,{filePath:Ce.path,extension:Ce.extension,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Ce.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:pt=>{pt.preventDefault(),pt.stopPropagation()},onClick:pt=>{pt.preventDefault(),pt.stopPropagation(),Xn(Ce.path)},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:Ce.name}),children:s.jsx(Is,{className:"h-3.5 w-3.5"})})]},Ce.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):he.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[ke.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"}),ke.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:G,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:he.map(Ce=>{const qe=be?.path===Ce.path;return s.jsxs("div",{title:ru(b,Ce.path),className:me("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",qe?"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(Dr,{filePath:Ce.path,extension:Ce.extension,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{qe||Dn(Ce)},className:"max-w-[12rem] truncate text-left",children:Ce.name}),s.jsx("button",{type:"button",onClick:pt=>{pt.stopPropagation(),Xn(Ce.path)},className:me("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!qe&&!u&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:Ce.name}),children:s.jsx(Is,{size:14})})]},Ce.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:[be&&!T&&s.jsx("div",{ref:_,className:"absolute right-3 top-3 z-30",onMouseEnter:()=>F(!0),onMouseLeave:()=>{O.current>0||F(!1)},children:$?Te():s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>F(!0),className:"h-8 w-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(Tu,{className:"h-4 w-4"})})}),s.jsx(Ps,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:be?Xe?g?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(ts,{className:"h-4 w-4 animate-spin"}),e("filesView.state.loading")]}):et?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:et}):Ut?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:Ni,alt:be?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"})}):be&&yi&&ae==="tree"?s.jsx(on,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(ej,{jsonString:Ke,maxHeight:"100%",initiallyExpandedDepth:2})})}):be&&Hr&&Sn()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[Ke.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(Ke.length/1024)})}),s.jsx(on,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(ai,{content:Ke,className:"typography-markdown-body",stripFrontmatter:!0})})]}):be&&vi&&ne==="preview"?s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{srcDoc:(()=>{const Ce=be.path.substring(0,be.path.lastIndexOf("/")+1);if(!Ce)return Ke;const qe=`<base href="${r.isDesktop,Ce}">`;return Ke.replace(/<head([^>]*)>/i,`<head$1>${qe}`)})(),className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")})}):be&&ro&&B==="view"?el(be,_e):s.jsxs("div",{className:me("relative h-full",dr&&"overflow-hidden"),ref:Ue,children:[s.jsx("div",{className:me("h-full",dr&&"invisible"),children:s.jsx(eu,{value:_e,onChange:tt,readOnly:!ur,extensions:Zo,className:"h-full",blockWidgets:Tc,onViewReady:Ce=>{Ct.current=Ce,Tt(qe=>qe+1),window.requestAnimationFrame(()=>{fa(Ce)})},onViewDestroy:()=>{Ct.current&&(Ct.current=null),Tt(Ce=>Ce+1)},enableSearch:!0,searchOpen:T,onSearchOpenChange:M,highlightLines:Ws?{start:Math.min(Ws.start,Ws.end),end:Math.max(Ws.start,Ws.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(Ce,qe,pt)=>{if(!(pt instanceof MouseEvent)||pt.button!==0)return!1;pt.preventDefault();const ft=Ce.state.doc.lineAt(qe.from).number;if(d&&Ws&&!pt.shiftKey){const Ot=Math.min(Ws.start,Ws.end,ft),Gt=Math.max(Ws.start,Ws.end,ft);return hn({start:Ot,end:Gt}),un.current=!1,fn.current=null,yn(!1),!0}if(un.current=!0,fn.current=ft,yn(!0),Ws&&pt.shiftKey){const Ot=Math.min(Ws.start,ft),Gt=Math.max(Ws.end,ft);hn({start:Ot,end:Gt})}else hn({start:ft,end:ft});return!0},mouseover:(Ce,qe,pt)=>{if(!(pt instanceof MouseEvent)||pt.buttons!==1||!un.current||fn.current===null)return!1;const ft=Ce.state.doc.lineAt(qe.from).number,Ot=Math.min(fn.current,ft),Gt=Math.max(fn.current,ft);return hn({start:Ot,end:Gt}),yn(!0),!1},mouseup:()=>(un.current=!1,fn.current=null,yn(!1),!1)}}})}),dr&&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(ts,{className:"h-4 w-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),lt=!!(b&&xe[b]),Qt=s.jsxs("section",{className:me("flex min-h-0 flex-col overflow-hidden",d?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:me("flex flex-col gap-2 py-2",d?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(Jn,{className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(Bt,{ref:C,value:S,onChange:Ce=>P(Ce.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),S.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{P(""),C.current?.focus()},children:s.jsx(Is,{className:"h-4 w-4"})})]}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>en("createFile",{path:h,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),children:s.jsx(hc,{className:"h-4 w-4"})}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>en("createFolder",{path:h,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),children:s.jsx(Aa,{className:"h-4 w-4"})}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>{cr()},className:"h-8 w-8 p-0 flex-shrink-0",children:s.jsx(In,{className:"h-4 w-4"})})]})}),s.jsx(Ps,{outerClassName:"flex-1 min-h-0",className:me("py-2",d?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:Ve?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(ts,{className:"h-4 w-4 animate-spin"}),e("filesView.tree.search.searching")]}):ie.length>0?ie.map(Ce=>{const qe=be?.path===Ce.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{Dn(Ce)},className:me("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",qe?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[kx(Ce.path,Ce.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:Ce.path,children:Ce.relativePath??Ce.path})]})},Ce.path)}):lt?Ft(b,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Ts=t==="full"&&N&&be&&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:Te({exitFullscreenOnly:!0})}),s.jsx(Ps,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:Xe?g?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(ts,{className:"h-4 w-4 animate-spin"}),"Loading…"]}):et?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:et}):Ut?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:Ni,alt:be.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"})}):Hr&&Sn()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[Ke.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(Ke.length/1024)})}),s.jsx(on,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(ai,{content:Ke,className:"typography-markdown-body",stripFrontmatter:!0})})]}):ro&&B==="view"?el(be,_e):s.jsxs("div",{className:me("relative h-full",dr&&"overflow-hidden"),children:[s.jsx("div",{className:me("h-full",dr&&"invisible"),children:s.jsx(eu,{value:_e,onChange:tt,readOnly:!ur,extensions:Zo,className:"h-full",onViewReady:Ce=>{Ct.current=Ce,window.requestAnimationFrame(()=>{fa(Ce)})},onViewDestroy:()=>{Ct.current&&(Ct.current=null)}})}),dr&&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(ts,{className:"h-4 w-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[Dc(),Ts,d?I?bt:Qt: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:bt})}):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:Qt}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:bt})]})]})},u3=Object.freeze(Object.defineProperty({__proto__:null,FilesView:Cx},Symbol.toStringTag,{value:"Module"})),_r=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},cd=(t,e)=>{const n=_r(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},m3=(t,e,n)=>cd(cd(cd(t,".opencode"),"plans"),`${e}-${n}.md`),p3=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,h3=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},f3=(t,e)=>{const n=_r(e.currentDirectory),r=_r(e.homeDirectory),a=_r(t);return n&&a.startsWith(n+"/")?a.slice(n.length+1):r&&a===r?"~":r&&a.startsWith(r+"/")?`~${a.slice(r.length)}`:a},g3=(t,e,n)=>{const r=_r(t.trim());if(!r)return null;const a=n?e.find(o=>o.id===n)??null:null;if(a?.path){const o=_r(a.path);if(r===o||r.startsWith(`${o}/`))return{id:a.id,path:a.path}}const i=e.filter(o=>{const c=_r(o.path);return r===c||r.startsWith(`${c}/`)}).sort((o,c)=>_r(c.path).length-_r(o.path).length)[0];return i?{id:i.id,path:i.path}:null},Ix=({targetPath:t=null})=>{const{t:e}=ut(),n=Ht(xe=>xe.currentSessionId),r=Ht(xe=>xe.createSession),a=Ht(xe=>xe.initializeNewOpenChamberSession),i=Ht(xe=>xe.sendMessage),o=Ht(xe=>xe.setCurrentSession),c=Wo(),d=qs(xe=>xe.homeDirectory),p=Lu(xe=>xe.planModeEnabled),m=Es(xe=>xe.projects),u=Es(xe=>xe.activeProjectId),f=pn(xe=>xe.directories),y=ta()??"",h=De(xe=>xe.setActiveMainTab),b=De(xe=>xe.setSessionSwitcherOpen),x=Yn(),{isMobile:g}=dn(),{currentTheme:w}=Er();l.useMemo(()=>wg(w),[w]);const v=l.useMemo(()=>n?c.find(xe=>xe.id===n)??null:null,[n,c]),S=l.useMemo(()=>{const xe=typeof v?.directory=="string"?v.directory:"";return _r(xe||"")},[v?.directory]),P=l.useMemo(()=>_r(y||S),[y,S]),j=l.useMemo(()=>g3(P,m,u),[u,P,m]),C=l.useMemo(()=>j?f.get(j.path)?.isGitRepo===!0:!1,[j,f]),[I,R]=l.useState(null),[k,A]=l.useState(!1),[N,D]=l.useState(null),T=l.useMemo(()=>!N||!S||!d?N:f3(N,{currentDirectory:S,homeDirectory:d}),[N,S,d]),[M,$]=l.useState(""),[F,_]=l.useState(null),O=l.useMemo(()=>T&&T.split("/").pop()||e("planView.file.defaultName"),[T,e]),L=l.useMemo(()=>M.trim()&&c1(M).title||e("planView.title.default"),[M,e]),K=l.useMemo(()=>L.trim()||e("planView.title.default"),[L,e]),[B,re]=l.useState(!1),[oe,ee]=l.useState(!1),[ae,ge]=l.useState("edit"),ne=l.useRef(null),[E,z]=l.useState(null),J=l.useRef(null),H=l.useRef(null),te="openchamber:plan:md-viewer-mode";l.useEffect(()=>{try{const xe=localStorage.getItem(te);if(!xe)return;const V=JSON.parse(xe);(V==="preview"||V==="edit")&&ge(V)}catch{}},[]);const ce=l.useCallback(xe=>{ge(xe);try{localStorage.setItem(te,JSON.stringify(xe))}catch{}},[]),Se=l.useRef(!1),pe=l.useRef(null),[we,W]=l.useState(!1);l.useEffect(()=>{const xe=()=>{Se.current=!1,pe.current=null,W(!1)};return document.addEventListener("mouseup",xe),()=>document.removeEventListener("mouseup",xe)},[]);const ue=l.useCallback((xe,V)=>{const de=xe.split(`
|
|
54
|
+
`),Me=Math.max(1,V.start),Le=Math.min(de.length,V.end);return Me>Le?"":de.slice(Me-1,Le).join(`
|
|
55
|
+
`)},[]),Y=Xu({source:"plan",fileLabel:O,language:N&&To(N)||"markdown",getCodeForRange:xe=>ue(M,rc(xe)),toStoreRange:xe=>({startLine:xe.start,endLine:xe.end}),fromDraftRange:xe=>({start:xe.startLine,end:xe.endLine})}),{drafts:le,commentText:Z,editingDraftId:Ie,setSelection:Ne,saveComment:X,cancel:he,reset:je,startEdit:be,deleteDraft:fe}=Y;l.useEffect(()=>{z(null),je()},[M,je]),l.useEffect(()=>{Ne(E)},[E,Ne]);const Pe=l.useCallback(()=>{z(null),he()},[he]),Be=l.useCallback((xe,V)=>{V&&z(V),X(xe,V??E??void 0),z(null)},[E,X]);l.useEffect(()=>{if(!E)return;const xe=de=>{const Me=de.target;Me.closest('[data-comment-card="true"]')||Me.closest('[data-comment-input="true"]')||Me.closest(".oc-block-widget")||Me.closest(".cm-gutterElement")||Me.closest("[data-sonner-toast]")||Me.closest("[data-sonner-toaster]")||(z(null),he())},V=window.setTimeout(()=>{document.addEventListener("click",xe)},100);return()=>{window.clearTimeout(V),document.removeEventListener("click",xe)}},[he,Ie,g,E]);const G=l.useMemo(()=>{const xe=[nu(w)],V=Nx(N||"plan.md");return V&&xe.push(V),xe.push(or.lineWrapping),xe},[w,N]);l.useEffect(()=>{if(!p&&!t){D(null),$(""),re(!1);return}let xe=!1;const V=async Me=>{if(x.files?.readFile)return(await x.files.readFile(Me))?.content??"";const Le=yr()?.files;if(Le?.readFile)return(await Le.readFile(Me,{optional:!0}))?.content??"";const se=await fetch(`/api/fs/read?path=${encodeURIComponent(Me)}&optional=true`,{cache:"no-store"});if(!se.ok)throw new Error(`Failed to read plan file (${se.status})`);return se.text()};return(async()=>{if(D(null),$(""),_(null),t){re(!0);try{const Me=await V(t);if(xe)return;D(t),$(Me)}catch{if(xe)return;D(null),$("")}finally{xe||re(!1)}return}if(!v?.slug||!v?.time?.created||!S){D(null),$("");return}re(!0);try{const Me=m3(S,v.time.created,v.slug),Le=h3(p3(v.time.created,v.slug),d||null);let se=null,ie=null;try{ie=await V(Me),se=Me}catch{}if(!se)try{ie=await V(Le),se=Le}catch{}if(xe)return;if(!se||ie===null){D(null),$("");return}D(se),$(ie)}catch{if(xe)return;D(null),$("")}finally{xe||re(!1)}})(),()=>{xe=!0}},[d,p,x.files,S,v?.slug,v?.time?.created,t]),l.useEffect(()=>{if(!N){_(null);return}const xe=window.setTimeout(async()=>{_(null);try{if(x.files?.writeFile){if(!(await x.files.writeFile(N,M))?.success)throw new Error(e("planView.error.writeFailed"))}else{const V=await fetch("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:N,content:M})});if(!V.ok)throw new Error(e("planView.error.writePlanFileFailed",{status:V.status}))}}catch(V){_(V instanceof Error?V.message:e("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(xe)}},[M,N,x.files,e]),l.useEffect(()=>()=>{ne.current!==null&&window.clearTimeout(ne.current)},[]);const ke=l.useCallback(()=>{h("chat"),b(!1)},[h,b]),Ee=l.useCallback(async xe=>{if(!j||!I)return;const V=await zn(I.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:K}),Me=[{synthetic:!0,text:await zn(I.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:K,plan_path:N??""})}];A(!0);try{ke();let Le=null,se=j.path;if(I.target==="worktree"){if(!C)return;const U=await gg(j.path,xg());if(!U?.id)return;Le=U.id,se=null}else{const U=await r(void 0,j.path,null);if(!U?.id)return;Le=U.id,se=U.directory??j.path,a(U.id,yt.getState().agents??[])}if(!Le)return;const ie=xc.getState();ie.saveSessionModelSelection(Le,xe.providerID,xe.modelID),xe.agent.trim()&&(ie.saveSessionAgentSelection(Le,xe.agent),ie.saveAgentModelForSession(Le,xe.agent,xe.providerID,xe.modelID),ie.saveAgentModelVariantForSession(Le,xe.agent,xe.providerID,xe.modelID,xe.variant||void 0)),o(Le,se),await i(V,xe.providerID,xe.modelID,xe.agent.trim()||void 0,void 0,void 0,Me,xe.variant||void 0),R(null)}finally{A(!1)}},[C,r,j,a,I,N,ke,i,K,o]),Ae=l.useMemo(()=>gx({drafts:le,editingDraftId:Ie,commentText:Z,selection:E,isDragging:we,fileLabel:O,newWidgetId:"plan-new-comment-input",mapDraftToRange:xe=>({start:xe.startLine,end:xe.endLine}),onSave:Be,onCancel:Pe,onEdit:xe=>{be(xe),z({start:xe.startLine,end:xe.endLine})},onDelete:fe}),[Z,fe,Ie,Pe,Be,we,E,le,O,be]);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:L}),F?s.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:F,children:e("planView.error.saveFailed")}):null]}),N?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(_s,{children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx($s,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.improvePlanAria"),disabled:!M.trim(),children:s.jsx(by,{className:"size-4"})})})}),s.jsx(It,{sideOffset:8,children:e("planView.actions.improve")})]}),s.jsxs(Bs,{align:"end",children:[s.jsx(Lt,{onClick:()=>R({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(Lt,{onClick:()=>R({action:"improve",target:"worktree"}),disabled:!C,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsxs(_s,{children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx($s,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.implementPlanAria"),disabled:!M.trim(),children:s.jsx(yy,{className:"size-4"})})})}),s.jsx(It,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs(Bs,{align:"end",children:[s.jsx(Lt,{onClick:()=>R({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(Lt,{onClick:()=>R({action:"implement",target:"worktree"}),disabled:!C,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(tu,{currentMode:ae,onToggle:()=>ce(ae==="preview"?"edit":"preview")}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:async()=>{(await Wn(M)).ok&&(ee(!0),ne.current!==null&&window.clearTimeout(ne.current),ne.current=window.setTimeout(()=>{ee(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:oe?s.jsx(Zs,{className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(ni,{className:"h-4 w-4"})})]}):null]}),s.jsx(ex,{open:I!==null,onOpenChange:xe=>{!xe&&!k&&R(null)},target:I?.target??"session",projectDirectory:j?.path??null,submitting:k,onConfirm:Ee}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(Ps,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:B?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:ae==="preview"?s.jsx("div",{className:"h-full overflow-auto p-3",children:s.jsx(on,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("planView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("planView.error.switchToEditMode")})]}),children:s.jsx(ai,{content:M,className:"typography-markdown-body"})})}):s.jsx("div",{className:"relative h-full",ref:H,children:s.jsx(eu,{value:M,onChange:$,readOnly:!1,className:"h-full",extensions:G,onViewReady:xe=>{J.current=xe},onViewDestroy:()=>{J.current=null},blockWidgets:Ae,highlightLines:E?{start:Math.min(E.start,E.end),end:Math.max(E.start,E.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(xe,V,de)=>{if(!(de instanceof MouseEvent)||de.button!==0)return!1;de.preventDefault();const Me=xe.state.doc.lineAt(V.from).number;if(g&&E&&!de.shiftKey){const Le=Math.min(E.start,E.end,Me),se=Math.max(E.start,E.end,Me);return z({start:Le,end:se}),Se.current=!1,pe.current=null,W(!1),!0}if(Se.current=!0,pe.current=Me,W(!0),E&&de.shiftKey){const Le=Math.min(E.start,Me),se=Math.max(E.end,Me);z({start:Le,end:se})}else z({start:Me,end:Me});return!0},mouseover:(xe,V,de)=>{if(!(de instanceof MouseEvent)||de.buttons!==1||!Se.current||pe.current===null)return!1;const Me=xe.state.doc.lineAt(V.from).number,Le=Math.min(pe.current,Me),se=Math.max(pe.current,Me);return z({start:Le,end:se}),W(!0),!1},mouseup:()=>(Se.current=!1,pe.current=null,W(!1),!1)}}})})})})})})]})},x3=Object.freeze(Object.defineProperty({__proto__:null,PlanView:Ix},Symbol.toStringTag,{value:"Module"})),au={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},Rl={user:0,assistant:0,tool:0,other:0},_a=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,Jp=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(p=>p.tokens!==void 0)?.tokens;if(typeof n=="number")return{...au,total:_a(n)};if(!n||typeof n!="object")return au;const r=n,a=_a(r.input),i=_a(r.output),o=_a(r.reasoning),c=_a(r.cache?.read),d=_a(r.cache?.write);return{input:a,output:i,reasoning:o,cacheRead:c,cacheWrite:d,total:a+i+o+c+d}},b3=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},fr=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+fr(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+fr(n),0):0,y3=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...Rl,assistant:fr(n.text)+fr(n.content)};const a=b3(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:fr(n.input)+fr(n.output)+fr(n.error)+fr(n.call?.input)+fr(n.call?.output)+fr(n.call?.error)+fr(n.raw)+Math.round(fr(n.metadata)*.25)+Math.round(fr(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}},Yp=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),v3=t=>{const e=Ko(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},w3=(t,e)=>{if(t.length===0)return{...Rl};const n=t.reduce((r,a)=>{const i=v3(a);let o={...Rl};for(const c of a.parts)o=Yp(o,y3(c,i));return Yp(r,o)},{...Rl});return n.user+=e.length,{user:Math.ceil(n.user/4),assistant:Math.ceil(n.assistant/4),tool:Math.ceil(n.tool/4),other:Math.ceil(n.other/4)}},Di=t=>t.toLocaleString(),j3=t=>!Number.isFinite(t)||t<=0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`,N3=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),S3=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),k3=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,C3=(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}},I3=()=>{const t=nt.c(199),{t:e}=ut(),{currentTheme:n}=Er();let r;t[0]!==n?(r=wg(n),t[0]=n,t[1]=r):r=t[1];const a=r;let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i={},t[2]=i):i=t[2];const[o,c]=l.useState(i),[d,p]=l.useState(null),m=l.useRef(null),u=Ht(A3),f=Wo(),y=d1(u??""),h=yt(P3);let b;t[3]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null),c(D3),p(null)},t[3]=b):b=t[3];let x;t[4]!==u?(x=[u],t[4]=u,t[5]=x):x=t[5],l.useEffect(b,x);let g,w;t[6]===Symbol.for("react.memo_cache_sentinel")?(g=()=>()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},w=[],t[6]=g,t[7]=w):(g=t[6],w=t[7]),l.useEffect(g,w);let v;t[8]===Symbol.for("react.memo_cache_sentinel")?(v=async(At,jt)=>{(await Wn(jt)).ok?(p(At),m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{p(ot=>ot===At?null:ot),m.current=null},2e3)):p(null)},t[8]=v):v=t[8];const S=v;let P;t[9]!==u||t[10]!==f?(P=u?f.find(At=>At.id===u)??null:null,t[9]=u,t[10]=f,t[11]=P):P=t[11];const j=P;let C,I,R,k,A;if(t[12]!==h||t[13]!==y){C=y.filter(T3);let At;t[19]!==y?(At=y.filter(M3),t[19]=y,t[20]=At):At=t[20],A=At;let jt=null;for(let ot=C.length-1;ot>=0;ot=ot-1,ot){const Zt=C[ot];if(Jp(Zt).total>0){jt=Zt;break}}R=jt?Jp(jt):au,k=C.reduce(R3,0);const ns=jt?.info??null;I=C3(h,ns?.providerID||"",ns?.modelID||""),t[12]=h,t[13]=y,t[14]=C,t[15]=I,t[16]=R,t[17]=k,t[18]=A}else C=t[14],I=t[15],R=t[16],k=t[17],A=t[18];const N=I,D=N.contextLimit,T=D&&D>0?Math.min(999,R.total/D*100):0;let M;if(t[21]!==y){const At=[...y].reverse().find(E3)?.info?.system||"";M=w3(y,At),t[21]=y,t[22]=M}else M=t[22];const $=M,F=$.user,_=$.assistant,O=$.tool,L=Math.max(0,R.input-F-_-O),K=F+_+O+L,B=y[0]?.info?.time?.created,re=y.length>0?y[y.length-1]?.info?.time?.created:null;let oe;t[23]!==j?.title||t[24]!==e?(oe=j?.title||e("contextSidebar.session.untitled"),t[23]=j?.title,t[24]=e,t[25]=oe):oe=t[25];const ee=j?.time?.created??B??null,ae=re??j?.time?.created??null;let ge;t[26]!==_||t[27]!==L||t[28]!==O||t[29]!==F?(ge={user:F,assistant:_,tool:O,other:L},t[26]=_,t[27]=L,t[28]=O,t[29]=F,t[30]=ge):ge=t[30];let ne;t[31]!==C.length||t[32]!==K||t[33]!==D||t[34]!==N||t[35]!==y.length||t[36]!==oe||t[37]!==ee||t[38]!==ae||t[39]!==ge||t[40]!==R||t[41]!==k||t[42]!==T||t[43]!==A.length?(ne={sessionTitle:oe,messagesCount:y.length,userMessagesCount:A.length,assistantMessagesCount:C.length,createdAt:ee,lastActivityAt:ae,providerModel:N,tokenBreakdown:R,usagePercent:T,totalAssistantCost:k,contextLimit:D,breakdown:ge,breakdownTotal:K},t[31]=C.length,t[32]=K,t[33]=D,t[34]=N,t[35]=y.length,t[36]=oe,t[37]=ee,t[38]=ae,t[39]=ge,t[40]=R,t[41]=k,t[42]=T,t[43]=A.length,t[44]=ne):ne=t[44];const E=ne;if(!u){let At;t[45]!==e?(At=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=At):At=t[46];let jt;return t[47]!==At?(jt=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:At}),t[47]=At,t[48]=jt):jt=t[48],jt}let z;t[49]!==e?(z=e("contextSidebar.breakdown.user"),t[49]=e,t[50]=z):z=t[50];let J;t[51]!==z||t[52]!==E.breakdown.user?(J={key:"user",label:z,value:E.breakdown.user,color:"var(--status-success)"},t[51]=z,t[52]=E.breakdown.user,t[53]=J):J=t[53];let H;t[54]!==e?(H=e("contextSidebar.breakdown.assistant"),t[54]=e,t[55]=H):H=t[55];let te;t[56]!==H||t[57]!==E.breakdown.assistant?(te={key:"assistant",label:H,value:E.breakdown.assistant,color:"var(--primary-base)"},t[56]=H,t[57]=E.breakdown.assistant,t[58]=te):te=t[58];let ce;t[59]!==e?(ce=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=ce):ce=t[60];let Se;t[61]!==ce||t[62]!==E.breakdown.tool?(Se={key:"tool",label:ce,value:E.breakdown.tool,color:"var(--status-warning)"},t[61]=ce,t[62]=E.breakdown.tool,t[63]=Se):Se=t[63];let pe;t[64]!==e?(pe=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=pe):pe=t[65];let we;t[66]!==pe||t[67]!==E.breakdown.other?(we={key:"other",label:pe,value:E.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=pe,t[67]=E.breakdown.other,t[68]=we):we=t[68];let W;t[69]!==J||t[70]!==te||t[71]!==Se||t[72]!==we?(W=[J,te,Se,we],t[69]=J,t[70]=te,t[71]=Se,t[72]=we,t[73]=W):W=t[73];const ue=W;let Y;t[74]!==E.sessionTitle?(Y=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:E.sessionTitle}),t[74]=E.sessionTitle,t[75]=Y):Y=t[75];let le;t[76]!==E.providerModel.modelName||t[77]!==E.providerModel.providerName?(le=s.jsxs("span",{children:[E.providerModel.providerName," / ",E.providerModel.modelName]}),t[76]=E.providerModel.modelName,t[77]=E.providerModel.providerName,t[78]=le):le=t[78];let Z;t[79]!==E.createdAt?(Z=E.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:N3(E.createdAt)})]}),t[79]=E.createdAt,t[80]=Z):Z=t[80];let Ie;t[81]!==le||t[82]!==Z?(Ie=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:[le,Z]}),t[81]=le,t[82]=Z,t[83]=Ie):Ie=t[83];let Ne;t[84]!==Y||t[85]!==Ie?(Ne=s.jsxs("div",{className:"mb-6",children:[Y,Ie]}),t[84]=Y,t[85]=Ie,t[86]=Ne):Ne=t[86];let X;t[87]!==e?(X=e("contextSidebar.section.context"),t[87]=e,t[88]=X):X=t[88];let he;t[89]!==X?(he=s.jsx("span",{className:"typography-micro text-muted-foreground",children:X}),t[89]=X,t[90]=he):he=t[90];let je;t[91]!==E.tokenBreakdown.total?(je=Di(E.tokenBreakdown.total),t[91]=E.tokenBreakdown.total,t[92]=je):je=t[92];let be;t[93]!==E.contextLimit?(be=E.contextLimit?` / ${Di(E.contextLimit)}`:"",t[93]=E.contextLimit,t[94]=be):be=t[94];let fe;t[95]!==je||t[96]!==be?(fe=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[je,be]}),t[95]=je,t[96]=be,t[97]=fe):fe=t[97];let Pe;t[98]!==he||t[99]!==fe?(Pe=s.jsxs("div",{className:"flex items-baseline justify-between",children:[he,fe]}),t[98]=he,t[99]=fe,t[100]=Pe):Pe=t[100];let Be;t[101]!==E.usagePercent?(Be=E.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,E.usagePercent)}%`,backgroundColor:E.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[101]=E.usagePercent,t[102]=Be):Be=t[102];let G;t[103]!==Be?(G=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:Be}),t[103]=Be,t[104]=G):G=t[104];let ke;t[105]!==e||t[106]!==E.usagePercent?(ke=e("contextSidebar.context.percentUsed",{percent:E.usagePercent.toFixed(1)}),t[105]=e,t[106]=E.usagePercent,t[107]=ke):ke=t[107];let Ee;t[108]!==ke?(Ee=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:ke}),t[108]=ke,t[109]=Ee):Ee=t[109];let Ae;t[110]!==Pe||t[111]!==G||t[112]!==Ee?(Ae=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Pe,G,Ee]}),t[110]=Pe,t[111]=G,t[112]=Ee,t[113]=Ae):Ae=t[113];let xe;t[114]!==e?(xe=e("contextSidebar.stats.messages"),t[114]=e,t[115]=xe):xe=t[115];let V;t[116]!==E.messagesCount?(V=Di(E.messagesCount),t[116]=E.messagesCount,t[117]=V):V=t[117];let de;t[118]!==xe||t[119]!==V?(de={label:xe,value:V},t[118]=xe,t[119]=V,t[120]=de):de=t[120];let Me;t[121]!==e?(Me=e("contextSidebar.stats.user"),t[121]=e,t[122]=Me):Me=t[122];let Le;t[123]!==E.userMessagesCount?(Le=Di(E.userMessagesCount),t[123]=E.userMessagesCount,t[124]=Le):Le=t[124];let se;t[125]!==Me||t[126]!==Le?(se={label:Me,value:Le},t[125]=Me,t[126]=Le,t[127]=se):se=t[127];let ie;t[128]!==e?(ie=e("contextSidebar.stats.assistant"),t[128]=e,t[129]=ie):ie=t[129];let U;t[130]!==E.assistantMessagesCount?(U=Di(E.assistantMessagesCount),t[130]=E.assistantMessagesCount,t[131]=U):U=t[131];let Ve;t[132]!==ie||t[133]!==U?(Ve={label:ie,value:U},t[132]=ie,t[133]=U,t[134]=Ve):Ve=t[134];let He;t[135]!==e?(He=e("contextSidebar.stats.cost"),t[135]=e,t[136]=He):He=t[136];let Ke;t[137]!==E.totalAssistantCost?(Ke=j3(E.totalAssistantCost),t[137]=E.totalAssistantCost,t[138]=Ke):Ke=t[138];let Ze;t[139]!==He||t[140]!==Ke?(Ze={label:He,value:Ke},t[139]=He,t[140]=Ke,t[141]=Ze):Ze=t[141];let Xe;t[142]!==de||t[143]!==se||t[144]!==Ve||t[145]!==Ze?(Xe=[de,se,Ve,Ze],t[142]=de,t[143]=se,t[144]=Ve,t[145]=Ze,t[146]=Xe):Xe=t[146];const dt=Xe;let et;t[147]!==dt?(et=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:dt.map(F3)}),t[147]=dt,t[148]=et):et=t[148];let ct;t[149]!==e?(ct=e("contextSidebar.section.lastAssistantMessage"),t[149]=e,t[150]=ct):ct=t[150];let at;t[151]!==ct?(at=s.jsx("div",{className:"typography-micro text-muted-foreground",children:ct}),t[151]=ct,t[152]=at):at=t[152];let ye;t[153]!==e||t[154]!==E.tokenBreakdown.cacheRead||t[155]!==E.tokenBreakdown.cacheWrite||t[156]!==E.tokenBreakdown.input||t[157]!==E.tokenBreakdown.output||t[158]!==E.tokenBreakdown.reasoning?(ye=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:E.tokenBreakdown.input},{label:e("contextSidebar.tokens.output"),value:E.tokenBreakdown.output},{label:e("contextSidebar.tokens.reasoning"),value:E.tokenBreakdown.reasoning},{label:e("contextSidebar.tokens.cacheRead"),value:E.tokenBreakdown.cacheRead},{label:e("contextSidebar.tokens.cacheWrite"),value:E.tokenBreakdown.cacheWrite}].map(O3)}),t[153]=e,t[154]=E.tokenBreakdown.cacheRead,t[155]=E.tokenBreakdown.cacheWrite,t[156]=E.tokenBreakdown.input,t[157]=E.tokenBreakdown.output,t[158]=E.tokenBreakdown.reasoning,t[159]=ye):ye=t[159];let Ge;t[160]!==at||t[161]!==ye?(Ge=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[at,ye]}),t[160]=at,t[161]=ye,t[162]=Ge):Ge=t[162];let $e;t[163]!==ue||t[164]!==E.breakdownTotal?($e=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ue.map(At=>At.value<=0||E.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${At.value/E.breakdownTotal*100}%`,backgroundColor:At.color}},At.key))}),t[163]=ue,t[164]=E.breakdownTotal,t[165]=$e):$e=t[165];let _e;t[166]!==ue||t[167]!==E.breakdownTotal?(_e=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:ue.map(At=>{const jt=E.breakdownTotal>0?At.value/E.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:At.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[At.label," ",s.jsxs("span",{className:"tabular-nums",children:[jt.toFixed(0),"%"]})]})]},At.key)})}),t[166]=ue,t[167]=E.breakdownTotal,t[168]=_e):_e=t[168];let tt;t[169]!==$e||t[170]!==_e?(tt=s.jsxs("div",{className:"mb-6",children:[$e,_e]}),t[169]=$e,t[170]=_e,t[171]=tt):tt=t[171];let Qe;t[172]!==e?(Qe=e("contextSidebar.section.rawMessages"),t[172]=e,t[173]=Qe):Qe=t[173];let ze;t[174]!==Qe?(ze=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Qe}),t[174]=Qe,t[175]=ze):ze=t[175];let gt;if(t[176]!==d||t[177]!==o||t[178]!==y||t[179]!==a||t[180]!==e){let At;t[182]!==d||t[183]!==o||t[184]!==a||t[185]!==e?(At=jt=>{const ns=Ko(jt.info).role,ot=o[jt.info.id]===!0,Zt=d===jt.info.id,Yt=jt.info.time?.created??null,es=ot?JSON.stringify({info:jt.info,parts:jt.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":ot,onClick:()=>{c(ls=>({...ls,[jt.info.id]:ls[jt.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:k3(ns)}),s.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground",children:jt.info.id})]}),s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:S3(Yt)})]})}),ot&&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:ls=>{ls.stopPropagation(),S(jt.info.id,es)},"aria-label":e(Zt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Zt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Zt?s.jsx(Zs,{className:"size-3.5"}):s.jsx(vr,{className:"size-3.5"})})}),s.jsx(vy,{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:es})]})})]},jt.info.id)},t[182]=d,t[183]=o,t[184]=a,t[185]=e,t[186]=At):At=t[186],gt=[...y].reverse().map(At),t[176]=d,t[177]=o,t[178]=y,t[179]=a,t[180]=e,t[181]=gt}else gt=t[181];let Vt;t[187]!==gt?(Vt=s.jsx("div",{className:"mt-2.5 space-y-1",children:gt}),t[187]=gt,t[188]=Vt):Vt=t[188];let Kt;t[189]!==ze||t[190]!==Vt?(Kt=s.jsxs("div",{children:[ze,Vt]}),t[189]=ze,t[190]=Vt,t[191]=Kt):Kt=t[191];let Jt;return t[192]!==Ne||t[193]!==Ae||t[194]!==et||t[195]!==Ge||t[196]!==tt||t[197]!==Kt?(Jt=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[Ne,Ae,et,Ge,tt,Kt]})}),t[192]=Ne,t[193]=Ae,t[194]=et,t[195]=Ge,t[196]=tt,t[197]=Kt,t[198]=Jt):Jt=t[198],Jt};function A3(t){return t.currentSessionId}function P3(t){return t.providers}function D3(t){return Object.keys(t).length>0?{}:t}function T3(t){return Ko(t.info).role==="assistant"}function M3(t){return Ko(t.info).isUser}function R3(t,e){const n=_a(e.info.cost);return t+n}function E3(t){return Ko(t.info).isUser&&typeof t.info.system=="string"}function F3(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 O3(t){return s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:Di(t.value)})]},t.label)}const L3=360,$3=1400,Ax=600,B3=24,Xp=200,_3=(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",Zp=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"},V3=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:a,intro:i})=>{const o=r.text.trim(),c=Object.entries(r.attributes).map(([y,h])=>`${y}="${h}"`).join(" "),d=r.computedStyle,p=r.bounds,m=r.center,u=i.replace(/[.:]+$/g,""),f=r.ancestry.map(y=>y.selectorPart).join(" > ");return[`${u}:`,`Page: ${t||"preview"}`,`Viewport: ${e.width}x${e.height}, DPR ${n}`,`Screenshot: ${a?"attached":"not attached"}`,`Element: ${r.tag}`,o?`Text: ${o}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,f?`- Ancestry: ${f}`:null,c?`- Attributes: ${c}`:null,`- Bounds: x=${Math.round(p.x)}, y=${Math.round(p.y)}, width=${Math.round(p.width)}, height=${Math.round(p.height)}`,`- Center: x=${Math.round(m.x)}, y=${Math.round(m.y)}`,`Styles: display=${d.display}; position=${d.position}; font=${d.fontWeight} ${d.fontSize} / ${d.lineHeight} ${d.fontFamily}; color=${d.color}; background=${d.backgroundColor}; z-index=${d.zIndex}`].filter(y=>typeof y=="string").join(`
|
|
56
|
+
`)},z3=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((b,x)=>{i.onload=()=>b(),i.onerror=()=>x(new Error("Failed to load desktop preview screenshot")),i.src=`data:${a.mime};base64,${a.base64}`});const o=Math.max(1,i.naturalWidth||a.width||Math.floor(r.width)),c=Math.max(1,i.naturalHeight||a.height||Math.floor(r.height)),p=Math.min(1,1200/o),m=document.createElement("canvas");m.width=Math.floor(o*p),m.height=Math.floor(c*p);const u=m.getContext("2d");if(!u)return null;u.scale(p,p),u.drawImage(i,0,0,o,c);const f=o/Math.max(1,r.width),y=c/Math.max(1,r.height);u.fillStyle="rgba(37, 99, 235, 0.28)",u.strokeStyle="rgb(37, 99, 235)",u.lineWidth=Math.max(2,2*f),u.fillRect(e.bounds.x*f,e.bounds.y*y,e.bounds.width*f,e.bounds.height*y),u.strokeRect(e.bounds.x*f,e.bounds.y*y,e.bounds.width*f,e.bounds.height*y);const h=await new Promise(b=>m.toBlob(b,"image/jpeg",.82));return h?new File([h],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(r){return console.warn("[preview] failed to capture annotation screenshot:",r),null}return null},U3=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},eh=t=>Number.isFinite(t)?Math.min($3,Math.max(L3,Math.round(t))):Ax,W3=(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},K3=(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":"contextPanel.mode.context"),H3=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},G3=(t,e)=>{if(t.label)return t.label;if(t.mode==="file")return H3(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 K3(t.mode,e)},q3=t=>{if(t.mode==="file")return t.targetPath?s.jsx(Dr,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(wy,{className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(Ul,{className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(jy,{className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(mc,{className:"h-3.5 w-3.5"});if(t.mode==="preview")return s.jsx(ti,{className:"h-3.5 w-3.5 text-[var(--status-info)]"})},Q3=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,J3=(t,e)=>{if(typeof window>"u")return"";const n=new URL(window.location.pathname,window.location.origin);return n.searchParams.set("ocPanel","session-chat"),n.searchParams.set("sessionId",t),e&&e.trim().length>0?n.searchParams.set("directory",e):n.searchParams.delete("directory"),n.hash="",n.toString()},Y3=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,za=new Map,X3=3e4,Z3=t=>{const e=za.get(t);return e?e.expiresAt-Date.now()<=X3?(za.delete(t),null):e:null},e5=({rawUrl:t,onNavigate:e})=>{const{t:n}=ut(),{currentTheme:r}=Er(),[a,i]=l.useReducer(pe=>pe+1,0),[o,c]=l.useReducer(pe=>pe+1,0),[d,p]=l.useState({status:"idle"}),m=l.useRef(null),u=l.useRef(1),[f,y]=l.useState(!1),[h,b]=l.useState(!1),[x,g]=l.useState("all"),[w,v]=l.useState([]),[S,P]=l.useState(!1),[j,C]=l.useState(null),I=Ht(pe=>pe.currentSessionId),R=Ht(pe=>pe.newSessionDraft?.open),k=go(pe=>pe.addDraft),A=Hi(pe=>pe.addAttachedFile);let N=null;try{N=t?new URL(t):null}catch{N=null}const D=N?N.hostname==="localhost"||N.hostname==="127.0.0.1"||N.hostname==="::1"||N.hostname==="[::1]"||N.hostname==="0.0.0.0":!1,T=N?N.hostname==="0.0.0.0"?new URL(N.toString().replace("0.0.0.0","127.0.0.1")):N:null,M=T?T.toString():"",$=r.metadata.variant;l.useEffect(()=>{if(!M||!D){p({status:"idle"});return}const pe=Z3(M);if(pe){p({status:"ready",proxyBasePath:pe.proxyBasePath,expiresAt:pe.expiresAt});return}let we=!1;return p({status:"loading"}),(async()=>{try{const W=await fetch("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:M})});if(!W.ok){za.delete(M);const Z=await W.json().catch(()=>({})),Ie=typeof Z?.error=="string"?Z.error:`HTTP ${W.status}`;we||p({status:"error",message:Ie});return}const ue=await W.json(),Y=typeof ue.proxyBasePath=="string"?ue.proxyBasePath:"",le=typeof ue.expiresAt=="number"?ue.expiresAt:0;if(!Y){za.delete(M),we||p({status:"error",message:n("contextPanel.preview.proxyError")});return}za.set(M,{proxyBasePath:Y,expiresAt:le}),we||p({status:"ready",proxyBasePath:Y,expiresAt:le})}catch(W){if(za.delete(M),!we){const ue=W instanceof Error?W.message:String(W);p({status:"error",message:ue})}}})(),()=>{we=!0}},[D,o,n,M]);const F=T&&(T.protocol==="http:"||T.protocol==="https:")?T.toString():"",_=D&&d.status==="ready"&&T?(()=>{const pe=T.pathname||"/",we=new URLSearchParams(T.search);we.set("ocPreview",String(a));const W=we.toString(),ue=T.hash||"";return`${d.proxyBasePath}${pe}${W?`?${W}`:""}${ue}`})():"",O=D?_:F,L=O||F,K=D&&(d.status==="loading"||d.status==="idle"),B=D&&d.status==="error",re=l.useCallback(pe=>{const we=I??(R?"draft":null);if(!we){q.error(n("contextPanel.preview.inspect.attachNoSession"));return}const W=t||O||"",ue=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},Y=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let le=!1;try{const Z=m.current,Ie=Z?await z3(Z,pe):null;Ie&&(await A(Ie),le=!0)}catch{le=!1}k({sessionKey:we,source:"preview-annotation",fileLabel:W||"preview",startLine:1,endLine:1,code:V3({pageUrl:W,viewport:ue,devicePixelRatio:Y,target:pe,screenshotAttached:le,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),q.success(n("contextPanel.preview.inspect.attached"))})()},[A,k,I,O,R,t,n]);l.useEffect(()=>{y(!1),v([]),b(!1),g("all"),P(!1),C(null),u.current=1},[O]),l.useEffect(()=>{const pe=m.current?.contentWindow;!f||!pe||pe.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:S},window.location.origin)},[f,S]),l.useEffect(()=>{const pe=m.current?.contentWindow;!f||!pe||pe.postMessage({source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:$},window.location.origin)},[f,$]),l.useEffect(()=>{if(!S||typeof window>"u")return;const pe=we=>{we.key==="Escape"&&(we.preventDefault(),we.stopImmediatePropagation(),P(!1))};return window.addEventListener("keydown",pe,!0),()=>window.removeEventListener("keydown",pe,!0)},[S]),l.useEffect(()=>{if(!D||typeof window>"u")return;const pe=ue=>{if(typeof ue=="string")return ue;if(ue==null)return"";try{return JSON.stringify(ue)}catch{return String(ue)}},we=ue=>{const Y=u.current;u.current+=1,v(le=>{const Z=[...le,{...ue,id:Y}];return Z.length>Xp?Z.slice(Z.length-Xp):Z})},W=ue=>{if(ue.source!==m.current?.contentWindow)return;const Y=ue.data;if(!(!Y||Y.source!=="openchamber-preview-bridge"||Y.version!==1)){if(Y.type==="ready"){y(!0);return}if(Y.type==="console"){const le=Y.level==="error"||Y.level==="warn"||Y.level==="info"||Y.level==="debug"?Y.level:"log",Z=Array.isArray(Y.args)?Y.args.map(pe).filter(Boolean):[];we({level:le,message:Z.join(" "),ts:typeof Y.ts=="number"?Y.ts:Date.now()});return}if(Y.type==="runtime-error"){const le=pe(Y.filename),Z=typeof Y.line=="number"?Y.line:null,Ie=typeof Y.column=="number"?Y.column:null,Ne=le?`${le}${Z!==null?`:${Z}${Ie!==null?`:${Ie}`:""}`:""}`:"",X=pe(Y.stack);we({level:"runtime",message:pe(Y.message)||n("contextPanel.preview.console.runtimeError"),details:[Ne,X].filter(Boolean).join(`
|
|
57
|
+
`),ts:typeof Y.ts=="number"?Y.ts:Date.now()});return}if(Y.type==="resource-error"){const le=pe(Y.tag)||"resource",Z=pe(Y.url);we({level:"resource",message:Z?`${le}: ${Z}`:le,details:pe(Y.outerHTML),ts:typeof Y.ts=="number"?Y.ts:Date.now()});return}if(Y.type==="hover"){C(Zp(Y.target)?Y.target:null);return}if(Y.type==="select"&&Zp(Y.target)){C(Y.target),P(!1),re(Y.target);return}if(Y.type==="navigate-preview"){const le=typeof Y.url=="string"?Y.url:"",Z=Y.navigation==="external"?"external":"proxy";if(le&&Z==="external"){mr(le);return}le&&e(le)}}};return window.addEventListener("message",W),()=>{window.removeEventListener("message",W)}},[re,D,e,n]);const oe=w.filter(pe=>pe.level==="error"||pe.level==="runtime"||pe.level==="resource").length,ee=w.filter(pe=>_3(pe,x)),ae=l.useCallback(()=>{const pe=[`Preview URL: ${t||O||""}`,`Events: ${w.length}`,""].join(`
|
|
58
|
+
`),we=w.map(W=>{const ue=new Date(W.ts).toISOString(),Y=W.details?`
|
|
59
|
+
${W.details}`:"";return`[${ue}] [${W.level}] ${W.message}${Y}`}).join(`
|
|
60
|
+
`);Wn(`${pe}${we}`).then(W=>{W.ok?q.success(n("contextPanel.preview.console.copied")):q.error(n("contextPanel.preview.console.copyFailed"))})},[w,O,t,n]),ge=l.useCallback(()=>{const pe=I??(R?"draft":null);if(!pe){q.error(n("contextPanel.preview.console.attachNoSession"));return}const we=[`Preview URL: ${t||O||""}`,`Events: ${w.length}`,""].join(`
|
|
61
|
+
`),W=w.map(ue=>{const Y=new Date(ue.ts).toISOString(),le=ue.details?`
|
|
62
|
+
${ue.details}`:"";return`[${Y}] [${ue.level}] ${ue.message}${le}`}).join(`
|
|
63
|
+
`);k({sessionKey:pe,source:"preview-console",fileLabel:t||O||"preview",startLine:1,endLine:Math.max(1,w.length),code:`${we}${W}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),q.success(n("contextPanel.preview.console.attached"))},[k,w,I,O,R,t,n]),[ne,E]=l.useState("unknown"),z=l.useRef(0),J=l.useRef(0),H=15e3;l.useEffect(()=>{if(!_){E("unknown"),z.current=0,J.current=0;return}let pe=!1;return z.current||(z.current=Date.now(),J.current=0),E("unknown"),(async()=>{const W=await(async()=>{try{return await fetch(_,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(pe)return;if(!W){E("unreachable");return}if(W.status===403||W.status===404){za.delete(M),p({status:"loading"}),c();return}if(W.status!==502){E("reachable");return}const ue=z.current||Date.now();if(Date.now()-ue<H){E("starting"),J.current+=1;const le=J.current,Z=Math.min(2e3,250*Math.pow(2,Math.min(4,le)));setTimeout(()=>{pe||i()},Z).unref?.();return}E("unreachable")})(),()=>{pe=!0}},[_,a,M]);const te=D&&d.status==="ready"&&(ne==="unknown"||ne==="starting"),ce=D&&d.status==="ready"&&ne==="unreachable",Se=l.useCallback(pe=>{if(!D||d.status!=="ready"||typeof window>"u")return;const we=pe.currentTarget.contentWindow;if(we)try{const W=we.location;if(W.origin!==window.location.origin||W.pathname.startsWith(d.proxyBasePath))return;const ue=`${d.proxyBasePath}${W.pathname}${W.search}${W.hash}`;we.location.replace(ue)}catch{}},[D,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:L||t,children:L||t||n("contextPanel.preview.empty")}),s.jsx(ve,{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(In,{className:"h-3.5 w-3.5"})}),s.jsx(ve,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{F&&mr(F)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!F,children:s.jsx(Pr,{className:"h-3.5 w-3.5"})}),D?s.jsx(ve,{type:"button",size:"sm",variant:S?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>P(pe=>!pe),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!f,children:s.jsx(Ny,{className:"h-3.5 w-3.5"})}):null,D?s.jsxs(ve,{type:"button",size:"sm",variant:h?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>b(pe=>!pe),title:n(f?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),"aria-label":n(f?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),disabled:!f&&w.length===0,children:[s.jsx(Za,{className:"h-3.5 w-3.5"}),oe>0?s.jsx("span",{className:"typography-micro text-status-error",children:oe}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[te?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")})]}):ce?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(ve,{type:"button",size:"sm",variant:"outline",onClick:()=>i(),children:n("contextPanel.preview.actions.retry")})]}):O&&(!D||ne==="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:Se,sandbox:D?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${O}:${a}`),S&&j?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:j.bounds.x,top:j.bounds.y,width:j.bounds.width,height:j.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[j.tag,j.text?` · ${j.text}`:""]})}):null]}):K?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):B?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.proxyError")}),d.status==="error"?s.jsx("div",{className:"text-center text-xs opacity-70",children:d.message}):null]}):s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.invalidUrl")}),h?s.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:n("contextPanel.preview.console.title")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(ve,{type:"button",size:"xs",variant:"ghost",onClick:ge,disabled:w.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(ve,{type:"button",size:"xs",variant:"ghost",onClick:ae,disabled:w.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(ve,{type:"button",size:"xs",variant:"ghost",onClick:()=>v([]),disabled:w.length===0,children:n("contextPanel.preview.console.clear")})]})]}),s.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(pe=>s.jsx(ve,{type:"button",size:"xs",variant:x===pe?"secondary":"ghost",onClick:()=>g(pe),children:n(pe==="all"?"contextPanel.preview.console.filter.all":pe==="errors"?"contextPanel.preview.console.filter.errors":pe==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},pe))}),s.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:w.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.empty")}):ee.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):ee.map(pe=>s.jsx("div",{className:"border-b border-border/30 px-2 py-1 last:border-b-0",children:s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:me("shrink-0 uppercase",pe.level==="error"||pe.level==="runtime"||pe.level==="resource"?"text-status-error":pe.level==="warn"?"text-status-warning":"text-muted-foreground"),children:pe.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:pe.message})]})},pe.id))})]}):null]})]})},t5=()=>{const{t}=ut(),e=ta()??"",n=l.useMemo(()=>U3(e),[e]),r=De(H=>n?H.contextPanelByDirectory[n]:void 0),a=De(H=>H.closeContextPanel),i=De(H=>H.closeContextPanelTab),o=De(H=>H.toggleContextPanelExpanded),c=De(H=>H.setContextPanelWidth),d=De(H=>H.setActiveContextPanelTab),p=De(H=>H.reorderContextPanelTabs),m=De(H=>H.setPendingDiffFile),u=qn(H=>H.setSelectedPath),f=De(H=>H.openContextPreview),{themeMode:y,lightThemeId:h,darkThemeId:b,currentTheme:x}=Er(),g=l.useMemo(()=>r?.tabs??[],[r?.tabs]),w=g.find(H=>H.id===r?.activeTabId)??g[g.length-1]??null,v=!!(r?.isOpen&&w),S=!!(v&&r?.expanded),P=eh(r?.width??Ax),[j,C]=l.useState(!1),I=l.useRef(0),R=l.useRef(P),k=l.useRef(null),A=l.useRef(null),N=l.useRef(null),D=l.useRef(new Map),T=l.useRef(!1);l.useEffect(()=>{if(!v||T.current){T.current=v;return}const H=window.requestAnimationFrame(()=>{N.current?.focus({preventScroll:!0})});return T.current=!0,()=>window.cancelAnimationFrame(H)},[v]);const M=l.useCallback(H=>{const te=N.current;te&&te.style.setProperty("--oc-context-panel-width",`${H}px`)},[]),$=l.useCallback(H=>{if(!(!v||S||!n)){try{H.currentTarget.setPointerCapture(H.pointerId)}catch{}A.current=H.pointerId,C(!0),I.current=H.clientX,R.current=P,k.current=P,M(P),H.preventDefault()}},[M,n,S,v,P]),F=l.useCallback(H=>{if(!j||A.current!==H.pointerId)return;const te=I.current-H.clientX,ce=eh(R.current+te);k.current!==ce&&(k.current=ce,M(ce))},[M,j]),_=l.useCallback(H=>{if(A.current!==H.pointerId||!n)return;try{H.currentTarget.releasePointerCapture(H.pointerId)}catch{}const te=k.current??P;C(!1),A.current=null,k.current=null,c(n,te)},[n,c,P]);l.useEffect(()=>{j||(k.current=null)},[j]);const O=l.useCallback(()=>{n&&a(n)},[a,n]),L=l.useCallback(()=>{n&&o(n)},[n,o]),K=l.useCallback(H=>{H.key==="Escape"&&(H.preventDefault(),H.stopPropagation(),O())},[O]);l.useEffect(()=>{if(!(!n||!w)){if(w.mode==="file"&&w.targetPath){u(n,w.targetPath);return}w.mode==="diff"&&w.targetPath&&m(w.targetPath)}},[w,n,m,u]);const B=w?.mode==="chat"?w.id:null,re=l.useCallback(()=>{if(typeof window>"u")return;const H={themeMode:y,lightThemeId:h,darkThemeId:b,currentTheme:x};for(const te of D.current.values()){const ce=te.contentWindow;if(!ce)continue;const Se=ce.__openchamberApplyThemeSync;if(typeof Se=="function")try{Se(H);continue}catch{}ce.postMessage({type:"openchamber:theme-sync",payload:H},window.location.origin)}},[x,b,h,y]),oe=l.useCallback(()=>{if(!(typeof window>"u"))for(const[H,te]of D.current.entries()){const ce=te.contentWindow;if(!ce)continue;const Se={visible:B===H},pe=ce.__openchamberSetEmbeddedVisibility;if(typeof pe=="function")try{pe(Se);continue}catch{}ce.postMessage({type:"openchamber:embedded-visibility",payload:Se},window.location.origin)}},[B]);l.useLayoutEffect(()=>{g.some(te=>te.mode==="chat")&&(re(),oe())},[b,h,oe,re,g,y]);const ee=l.useMemo(()=>g.map(H=>{const te=G3(H,t),ce=Y3(te,B3),Se=W3(H.targetPath,e);return{id:H.id,label:ce,icon:q3(H),title:Se?`${te}: ${Se}`:te,closeLabel:t("contextPanel.tab.closeTabAria",{label:ce})}}),[e,t,g]),ae=w?.mode==="diff"?s.jsx(wx,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,hideFileSelector:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0}):w?.mode==="context"?s.jsx(I3,{}):w?.mode==="plan"?s.jsx(Ix,{targetPath:w.targetPath}):w?.mode==="preview"?s.jsx(e5,{rawUrl:w.targetPath??"",onNavigate:H=>f(e,H)}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(ti,{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")})]}),ge=l.useMemo(()=>g.filter(H=>H.mode==="chat"),[g]),ne=l.useMemo(()=>g.some(H=>H.mode==="file"),[g]),E=w?.mode==="file",z=s.jsxs("header",{className:"flex h-8 items-stretch border-b border-transparent",children:[s.jsx(zr,{items:ee,activeId:w?.id??null,onSelect:H=>{n&&d(n,H)},onClose:H=>{n&&i(n,H)},onReorder:(H,te)=>{n&&p(n,H,te)},layoutMode:"scrollable",variant:"default"}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[s.jsx(ve,{type:"button",variant:"ghost",size:"sm",onClick:L,className:"h-7 w-7 p-0",title:t(S?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(S?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:S?s.jsx(Ed,{className:"h-3.5 w-3.5"}):s.jsx(Jf,{className:"h-3.5 w-3.5"})}),s.jsx(ve,{type:"button",variant:"ghost",size:"sm",onClick:O,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(Is,{className:"h-3.5 w-3.5"})})]})]});if(!v)return null;const J=S?{"--oc-context-panel-width":"100%",width:"100%",minWidth:"100%",maxWidth:"100%"}:{width:"var(--oc-context-panel-width)",minWidth:"var(--oc-context-panel-width)",maxWidth:"var(--oc-context-panel-width)","--oc-context-panel-width":`${j?k.current??P:P}px`};return s.jsxs("aside",{ref:N,"data-context-panel":"true",tabIndex:-1,className:me("flex min-h-0 flex-col overflow-hidden bg-background",!S&&"border-l border-border/40",S?"absolute inset-0 z-20 min-w-0":"relative h-full flex-shrink-0",j?"transition-none":"transition-[width] duration-200 ease-in-out"),onKeyDownCapture:K,style:J,children:[!S&&s.jsx("div",{className:me("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",j&&"bg-[var(--interactive-border)]"),onPointerDown:$,onPointerMove:F,onPointerUp:_,onPointerCancel:_,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),z,s.jsxs("div",{className:me("relative min-h-0 flex-1 overflow-hidden",j&&"pointer-events-none"),children:[ne?s.jsx("div",{className:me("absolute inset-0",E?"block":"hidden"),children:s.jsx(Cx,{mode:"editor-only"})}):null,ge.map(H=>{const te=Q3(H.dedupeKey);if(!te)return null;const ce=J3(te,n||null);return ce?s.jsx("iframe",{ref:Se=>{if(!Se){D.current.delete(H.id);return}D.current.set(H.id,Se)},src:ce,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:te}),className:me("absolute inset-0 h-full w-full border-0 bg-background",B===H.id?"block":"hidden"),onLoad:()=>{re(),oe()}},H.id):null}),w?.mode!=="chat"&&!E?ae:null]})]})},Zu=[{slug:"home",title:"Settings",group:"general",kind:"single",description:"Search and jump to common pages.",keywords:["search","settings"]},{slug:"projects",title:"Projects",group:"projects",kind:"split",keywords:["project","projects","worktree","worktrees","repo","repository","directory"]},{slug:"remote-instances",title:"Remote Instances",group:"projects",kind:"split",keywords:["ssh","remote","instances","tunnels","forwarding","connection"],isAvailable:t=>t.isDesktop&&!t.isWeb&&!t.isVSCode},{slug:"providers",title:"Providers",group:"opencode",kind:"split",keywords:["provider","providers","models","model","api key","api keys","openai","anthropic","ollama","credentials"]},{slug:"usage",title:"Usage",group:"usage",kind:"split",keywords:["quota","billing","tokens","usage","limits"]},{slug:"agents",title:"Agents",group:"opencode",kind:"split",keywords:["agent","agents","prompts","tools","permissions"]},{slug:"behavior",title:"Behavior",group:"opencode",kind:"single",keywords:["behavior","agents.md","system prompt","global rules","instructions","override"]},{slug:"commands",title:"Commands",group:"opencode",kind:"split",keywords:["command","commands","slash","macros","automation"]},{slug:"mcp",title:"MCP",group:"opencode",kind:"split",keywords:["mcp","model context protocol","servers","tools","remote","stdio"]},{slug:"skills.installed",title:"Skills",group:"skills",kind:"split",keywords:["skill","skills","instructions","install","catalog"]},{slug:"skills.catalog",title:"Skills Catalog",group:"skills",kind:"single",keywords:["install","catalog","external","repository","skills catalog"]},{slug:"git",title:"Git",group:"git",kind:"single",keywords:["git","github","identity","identities","ssh","profiles","credentials","keys","commit","gitmoji","oauth","prs","issues"],isAvailable:t=>!t.isVSCode},{slug:"appearance",title:"Appearance",group:"appearance",kind:"single",keywords:["theme","font","spacing","padding","corner radius","radius","input bar","keyboard","viewport","mobile","terminal","pwa","install name","app shortcuts"]},{slug:"chat",title:"Chat",group:"general",kind:"single",keywords:["tools","diff","reasoning","dotfiles","draft","queue","output","copy","image","split messages","message actions"]},{slug:"shortcuts",title:"Shortcuts",group:"general",kind:"single",keywords:["keyboard","hotkeys","shortcuts","bindings"],isAvailable:t=>!t.isVSCode},{slug:"sessions",title:"Sessions",group:"general",kind:"single",keywords:["defaults","default agent","default model","retention","memory","limits","zen"]},{slug:"magic-prompts",title:"Magic Prompts",group:"general",kind:"split",keywords:["prompts","templates","git","github","review","commit","pull request"],isAvailable:t=>!t.isVSCode},{slug:"notifications",title:"Notifications",group:"general",kind:"single",keywords:["alerts","native","summary","summarization"]},{slug:"voice",title:"Voice",group:"advanced",kind:"single",keywords:["tts","speech","voice"],isAvailable:t=>!t.isVSCode},{slug:"tunnel",title:"Remote Tunnel",group:"advanced",kind:"single",keywords:["tunnel","cloudflare","qr","remote","mobile","share"],isAvailable:t=>!t.isVSCode}],s5={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function bo(t){const e=t.trim().toLowerCase();return Zu.find(n=>n.slug===e)??null}function Px(t){const e=(t??"").trim().toLowerCase();if(!e)return"home";const n=s5[e];if(n)return n;const r=bo(e);return r?r.slug:"home"}const Dx=t=>t.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),Qo=t=>{const e=nt.c(39),{className:n}=t,{t:r}=ut(),a=Es(n5),i=Es(r5),o=Es(a5),c=jn();let d;e[0]!==a?(d=[...a].sort(i5),e[0]=a,e[1]=d):d=e[1];const p=d;let m;e:{if(p.length===0){m=null;break e}let T;e[2]!==i||e[3]!==p?(T=p.find(M=>M.id===i)??p[0],e[2]=i,e[3]=p,e[4]=T):T=e[4],m=T}const u=m;if(c||p.length===0)return null;let f;e[5]!==u||e[6]!==r?(f=u?.label&&u.label.trim().length>0?u.label:u?.path.split("/").filter(Boolean).pop()||u?.path||r("settings.shared.projectSelector.fallbackProject"),e[5]=u,e[6]=r,e[7]=f):f=e[7];const y=f;let h;e[8]!==y?(h=Dx(y),e[8]=y,e[9]=h):h=e[9];const b=h;let x;e[10]!==n?(x=me(n),e[10]=n,e[11]=x):x=e[11];let g;e[12]!==r?(g=r("settings.shared.projectSelector.switchProjectAria"),e[12]=r,e[13]=g):g=e[13];let w;e[14]!==r?(w=r("settings.shared.projectSelector.switchProjectTitle"),e[14]=r,e[15]=w):w=e[15];let v,S;e[16]===Symbol.for("react.memo_cache_sentinel")?(v=me("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),S=s.jsx(Un,{className:"h-4 w-4 opacity-70"}),e[16]=v,e[17]=S):(v=e[16],S=e[17]);let P;e[18]!==b?(P=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:b}),e[18]=b,e[19]=P):P=e[19];let j;e[20]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(ks,{className:"size-4 opacity-50"}),e[20]=j):j=e[20];let C;e[21]!==P||e[22]!==g||e[23]!==w?(C=s.jsx($s,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":g,title:w,className:v,children:[S,P,j]})}),e[21]=P,e[22]=g,e[23]=w,e[24]=C):C=e[24];const I=u?.id??"";let R;e[25]!==o?(R=T=>{T&&o(T)},e[25]=o,e[26]=R):R=e[26];let k;e[27]!==p?(k=p.map(o5),e[27]=p,e[28]=k):k=e[28];let A;e[29]!==I||e[30]!==R||e[31]!==k?(A=s.jsx(Bs,{align:"start",className:"w-auto",children:s.jsx(ql,{value:I,onValueChange:R,children:k})}),e[29]=I,e[30]=R,e[31]=k,e[32]=A):A=e[32];let N;e[33]!==C||e[34]!==A?(N=s.jsxs(_s,{children:[C,A]}),e[33]=C,e[34]=A,e[35]=N):N=e[35];let D;return e[36]!==N||e[37]!==x?(D=s.jsx("div",{className:x,children:N}),e[36]=N,e[37]=x,e[38]=D):D=e[38],D};function n5(t){return t.projects}function r5(t){return t.activeProjectId}function a5(t){return t.setActiveProject}function i5(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function o5(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,n=Dx(e);return s.jsx(Ql,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},t.id)}function l5(t,e){return`opencode:sidebar-group:${t}:${e}`}const iu=t=>{const e=nt.c(33),{label:n,count:r,storageKey:a,defaultExpanded:i,children:o}=t,c=i===void 0?!0:i;let d;e[0]!==n||e[1]!==a?(d=l5(a,n),e[0]=n,e[1]=a,e[2]=d):d=e[2];const p=d,m=l.useId();let u;e[3]!==c||e[4]!==p?(u=()=>{try{const A=localStorage.getItem(p);if(A!==null)return A==="true"}catch{}return c},e[3]=c,e[4]=p,e[5]=u):u=e[5];const[f,y]=Oe.useState(u);let h,b;e[6]!==f||e[7]!==p?(h=()=>{try{localStorage.setItem(p,String(f))}catch{}},b=[p,f],e[6]=f,e[7]=p,e[8]=h,e[9]=b):(h=e[8],b=e[9]),Oe.useEffect(h,b);let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=()=>y(c5),e[10]=x):x=e[10];let g;e[11]===Symbol.for("react.memo_cache_sentinel")?(g=me("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=g):g=e[11];const w=!f&&"-rotate-90";let v;e[12]!==w?(v=me("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",w),e[12]=w,e[13]=v):v=e[13];let S;e[14]!==v?(S=s.jsx(ks,{className:v}),e[14]=v,e[15]=S):S=e[15];let P;e[16]!==n?(P=s.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=P):P=e[17];let j;e[18]!==r?(j=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:r}),e[18]=r,e[19]=j):j=e[19];let C;e[20]!==m||e[21]!==f||e[22]!==S||e[23]!==P||e[24]!==j?(C=s.jsxs("button",{type:"button",onClick:x,"aria-expanded":f,"aria-controls":m,className:g,children:[S,P,j]}),e[20]=m,e[21]=f,e[22]=S,e[23]=P,e[24]=j,e[25]=C):C=e[25];const I=!f;let R;e[26]!==o||e[27]!==m||e[28]!==I?(R=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:o}),e[26]=o,e[27]=m,e[28]=I,e[29]=R):R=e[29];let k;return e[30]!==C||e[31]!==R?(k=s.jsxs("div",{children:[C,R]}),e[30]=C,e[31]=R,e[32]=k):k=e[32],k};function c5(t){return!t}const d5=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},u5=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())},th=t=>{const e=u5(d5(t));if(e.length===0)return;const n={};for(const a of e)a.permission&&((n[a.permission]||={})[a.pattern]=a.action);const r={};for(const[a,i]of Object.entries(n)){const o=Object.keys(i);if(o.length===1&&o[0]==="*"){r[a]=i["*"];continue}r[a]=i}return Object.keys(r).length>0?r:void 0},m5=({onItemSelect:t})=>{const{t:e}=ut(),[n,r]=l.useState(null),[a,i]=l.useState(""),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(!1),[f,y]=l.useState(null),{selectedAgentName:h,agents:b,setSelectedAgent:x,setAgentDraft:g,createAgent:w,deleteAgent:v,loadAgents:S}=Ki(Sr(L=>({selectedAgentName:L.selectedAgentName,agents:L.agents,setSelectedAgent:L.setSelectedAgent,setAgentDraft:L.setAgentDraft,createAgent:L.createAgent,deleteAgent:L.deleteAgent,loadAgents:L.loadAgents})));l.useEffect(()=>{S()},[S]);const P="bg-background",j=()=>{const L="new-agent";let K=L,B=1;for(;b.some(re=>re.name===K);)K=`${L}-${B}`,B++;g({name:K,scope:"user"}),x(K),t?.()},C=async L=>{if(Ri(L)){q.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}c(L),p("delete")},I=async L=>{Ri(L)&&(c(L),p("reset"))},R=()=>{c(null),p(null)},k=async()=>{if(!o||!d)return;u(!0),await v(o.name)?(d==="delete"?q.success(e("settings.agents.sidebar.toast.agentDeleted",{name:o.name})):q.success(e("settings.agents.sidebar.toast.agentReset",{name:o.name})),R()):d==="delete"?q.error(e("settings.agents.sidebar.toast.deleteFailed")):q.error(e("settings.agents.sidebar.toast.resetFailed")),u(!1)},A=L=>{const K=L.name;let B=1,re=`${K}-copy`;for(;b.some(ge=>ge.name===re);)B++,re=`${K}-copy-${B}`;const oe=L,ee=L.model?.providerID&&L.model?.modelID?`${L.model.providerID}/${L.model.modelID}`:null,ae=L;g({name:re,scope:oe.scope||"user",description:L.description,model:ee,temperature:L.temperature,top_p:L.topP,prompt:L.prompt,mode:L.mode,permission:th(L.permission),disable:ae.disable}),x(re)},N=L=>{i(L.name),r(L)},D=async()=>{if(!n)return;const L=a.trim().replace(/\s+/g,"-");if(!L){q.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(L===n.name){r(null);return}if(b.some(oe=>oe.name===L)){q.error(e("settings.agents.sidebar.toast.agentExists"));return}const K=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,B=n;await w({name:L,description:n.description,model:K,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:th(n.permission),disable:B.disable,scope:B.scope})?await v(n.name)?(q.success(`Agent renamed to "${L}"`),x(L)):q.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):q.error(e("settings.agents.sidebar.toast.renameFailed")),r(null)},T=L=>{switch(L){case"primary":return s.jsx(Eu,{className:"h-3 w-3 text-primary"});case"all":return s.jsx(ky,{className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(Sy,{className:"h-3 w-3 text-primary"});default:return null}},M=b.filter(L=>!u1(L)),$=M.filter(Ri),F=M.filter(L=>!Ri(L)),{groupedCustomAgents:_,ungroupedCustomAgents:O}=Oe.useMemo(()=>{const L={},K=[];for(const re of F){const oe=re;oe.group?(L[oe.group]||(L[oe.group]=[]),L[oe.group].push(re)):K.push(re)}return{groupedCustomAgents:Object.keys(L).sort((re,oe)=>re.localeCompare(oe)).map(re=>({name:re,agents:L[re]})),ungroupedCustomAgents:K}},[F]);return s.jsxs("div",{className:me("flex h-full flex-col",P),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.agents.sidebar.title")}),s.jsx(Qo,{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:M.length})}),s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:s.jsx(zs,{className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ps,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:M.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(Jr,{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(L=>s.jsx(dd,{agent:L,isSelected:h===L.name,onSelect:()=>{x(L.name),t?.()},onReset:()=>I(L),onDuplicate:()=>A(L),getAgentModeIcon:T,isMenuOpen:f===L.name,onMenuOpenChange:K=>y(K?L.name:null)},L.name))]}),F.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:L,agents:K})=>s.jsx(iu,{label:L,count:K.length,storageKey:"agents",children:K.map(B=>s.jsx(dd,{agent:B,isSelected:h===B.name,onSelect:()=>{x(B.name),t?.()},onRename:()=>N(B),onDelete:()=>C(B),onDuplicate:()=>A(B),getAgentModeIcon:T,isMenuOpen:f===B.name,onMenuOpenChange:re=>y(re?B.name:null)},B.name))},L)),O.map(L=>s.jsx(dd,{agent:L,isSelected:h===L.name,onSelect:()=>{x(L.name),t?.()},onRename:()=>N(L),onDelete:()=>C(L),onDuplicate:()=>A(L),getAgentModeIcon:T,isMenuOpen:f===L.name,onMenuOpenChange:K=>y(K?L.name:null)},L.name))]})]})}),s.jsx(ws,{open:o!==null&&d!==null,onOpenChange:L=>{!L&&!m&&R()},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Fs,{children:d==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:o?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:o?.name??""})})]}),s.jsxs(Xs,{children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:R,disabled:m,children:e("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",onClick:k,disabled:m,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(ws,{open:n!==null,onOpenChange:L=>!L&&r(null),children:s.jsxs(vs,{children:[s.jsxs(Cs,{children:[s.jsx(js,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Fs,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),s.jsx(Bt,{value:a,onChange:L=>i(L.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:L=>{L.key==="Enter"&&D()}}),s.jsxs(Xs,{children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>r(null),children:e("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",onClick:D,children:e("settings.common.actions.rename")})]})]})})]})},dd=t=>{const e=nt.c(58),{agent:n,isSelected:r,onSelect:a,onDelete:i,onReset:o,onRename:c,onDuplicate:d,getAgentModeIcon:p,isMenuOpen:m,onMenuOpenChange:u}=t,{t:f}=ut(),y=n;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=Mo(),e[0]=h):h=e[0];const b=h,x=r?"bg-interactive-selection":"hover:bg-interactive-hover";let g;e[1]!==x?(g=me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",x),e[1]=x,e[2]=g):g=e[2];let w;e[3]!==u?(w=b?void 0:K=>{K.preventDefault(),u(!0)},e[3]=u,e[4]=w):w=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 S;e[7]!==n.mode||e[8]!==p?(S=p(n.mode),e[7]=n.mode,e[8]=p,e[9]=S):S=e[9];let P;e[10]!==n||e[11]!==y.scope||e[12]!==f?(P=(y.scope||Ri(n))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:Ri(n)?f("settings.agents.sidebar.badge.system"):y.scope}),e[10]=n,e[11]=y.scope,e[12]=f,e[13]=P):P=e[13];let j;e[14]!==v||e[15]!==S||e[16]!==P?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[v,S,P]}),e[14]=v,e[15]=S,e[16]=P,e[17]=j):j=e[17];let C;e[18]!==n.description?(C=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[18]=n.description,e[19]=C):C=e[19];let I;e[20]!==a||e[21]!==j||e[22]!==C?(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:[j,C]}),e[20]=a,e[21]=j,e[22]=C,e[23]=I):I=e[23];let R;e[24]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx($s,{asChild:!0,children:s.jsx(ve,{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(la,{className:"h-3.5 w-3.5"})})}),e[24]=R):R=e[24];let k;e[25]!==c||e[26]!==f?(k=c&&s.jsxs(Lt,{onClick:K=>{K.stopPropagation(),c()},children:[s.jsx(ea,{className:"h-4 w-4 mr-px"}),f("settings.common.actions.rename")]}),e[25]=c,e[26]=f,e[27]=k):k=e[27];let A;e[28]!==d?(A=K=>{K.stopPropagation(),d()},e[28]=d,e[29]=A):A=e[29];let N;e[30]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(vr,{className:"h-4 w-4 mr-px"}),e[30]=N):N=e[30];let D;e[31]!==f?(D=f("settings.common.actions.duplicate"),e[31]=f,e[32]=D):D=e[32];let T;e[33]!==A||e[34]!==D?(T=s.jsxs(Lt,{onClick:A,children:[N,D]}),e[33]=A,e[34]=D,e[35]=T):T=e[35];let M;e[36]!==o||e[37]!==f?(M=o&&s.jsxs(Lt,{onClick:K=>{K.stopPropagation(),o()},children:[s.jsx(Fn,{className:"h-4 w-4 mr-px"}),f("settings.common.actions.reset")]}),e[36]=o,e[37]=f,e[38]=M):M=e[38];let $;e[39]!==i||e[40]!==f?($=i&&s.jsxs(Lt,{onClick:K=>{K.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(an,{className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]}),e[39]=i,e[40]=f,e[41]=$):$=e[41];let F;e[42]!==k||e[43]!==T||e[44]!==M||e[45]!==$?(F=s.jsxs(Bs,{align:"end",className:"w-fit min-w-20",children:[k,T,M,$]}),e[42]=k,e[43]=T,e[44]=M,e[45]=$,e[46]=F):F=e[46];let _;e[47]!==m||e[48]!==u||e[49]!==F?(_=s.jsxs(_s,{open:m,onOpenChange:u,children:[R,F]}),e[47]=m,e[48]=u,e[49]=F,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 L;return e[54]!==O||e[55]!==g||e[56]!==w?(L=s.jsx("div",{className:g,onContextMenu:w,children:O}),e[54]=O,e[55]=g,e[56]=w,e[57]=L):L=e[57],L};function sh(t,e,n){return Math.min(n,Math.max(e,t))}function p5(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 nh(t,e){const n=p5(e);return n<=0?t:Number(t.toFixed(n))}const Cn=Oe.forwardRef((t,e)=>{const n=nt.c(125);let r,a,i,o,c,d,p,m,u,f,y,h,b;n[0]!==t?({value:b,onValueChange:p,min:u,max:f,step:y,className:r,containerClassName:a,onBlur:c,disabled:i,fallbackValue:o,onClear:d,emptyLabel:h,...m}=t,n[0]=t,n[1]=r,n[2]=a,n[3]=i,n[4]=o,n[5]=c,n[6]=d,n[7]=p,n[8]=m,n[9]=u,n[10]=f,n[11]=y,n[12]=h,n[13]=b):(r=n[1],a=n[2],i=n[3],o=n[4],c=n[5],d=n[6],p=n[7],m=n[8],u=n[9],f=n[10],y=n[11],h=n[12],b=n[13]);const x=u===void 0?-1/0:u,g=f===void 0?1/0:f,w=y===void 0?1:y,v=h===void 0?"—":h,{t:S}=ut();let P;n[14]!==b?(P=()=>b===void 0?"":String(b),n[14]=b,n[15]=P):P=n[15];const[j,C]=Oe.useState(P),{isMobile:I}=dn(),R=Oe.useRef(!1),k=Oe.useRef(null);let A;n[16]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{if(typeof document>"u"||typeof window>"u")return;k.current?.();const je=Pe=>{Pe.preventDefault(),Pe.stopPropagation(),Pe.stopImmediatePropagation?.(),k.current?.()},be=window.setTimeout(()=>{k.current?.()},700),fe=()=>{window.clearTimeout(be),document.removeEventListener("click",je,!0),k.current=null};k.current=fe,document.addEventListener("click",je,!0)},n[16]=A):A=n[16];const N=A;let D,T;n[17]===Symbol.for("react.memo_cache_sentinel")?(D=()=>()=>{k.current?.()},T=[],n[17]=D,n[18]=T):(D=n[17],T=n[18]),Oe.useEffect(D,T);let M,$;n[19]!==b?($=()=>{C(b===void 0?"":String(b))},M=[b],n[19]=b,n[20]=M,n[21]=$):(M=n[20],$=n[21]),Oe.useEffect($,M);let F;e:{if(b!==void 0){F=b;break e}if(o!==void 0){F=o;break e}if(Number.isFinite(x)){F=x;break e}F=0}const _=F;let O;n[22]!==g||n[23]!==x||n[24]!==p||n[25]!==w?(O=je=>{const be=sh(je,x,g);p(nh(be,w))},n[22]=g,n[23]=x,n[24]=p,n[25]=w,n[26]=O):O=n[26];const L=O;let K;n[27]!==L||n[28]!==d?(K=je=>{const be=je.target.value;if(C(be),be.trim()===""){d?.();return}const fe=Number(be);Number.isFinite(fe)&&L(fe)},n[27]=L,n[28]=d,n[29]=K):K=n[29];const B=K;let re;n[30]!==j||n[31]!==g||n[32]!==x||n[33]!==c||n[34]!==d||n[35]!==p||n[36]!==w||n[37]!==b?(re=je=>{if(j.trim()===""){d||C(b===void 0?"":String(b)),c?.(je);return}const be=Number(j);if(!Number.isFinite(be))C(b===void 0?"":String(b));else{const fe=sh(be,x,g),Pe=nh(fe,w);Pe!==b&&p(Pe),C(String(Pe))}c?.(je)},n[30]=j,n[31]=g,n[32]=x,n[33]=c,n[34]=d,n[35]=p,n[36]=w,n[37]=b,n[38]=re):re=n[38];const oe=re,ee=!!(i||_>=g),ae=!!(i||_<=x);let ge;n[39]!==_||n[40]!==L||n[41]!==ae||n[42]!==w?(ge=()=>{ae||L(_-w)},n[39]=_,n[40]=L,n[41]=ae,n[42]=w,n[43]=ge):ge=n[43];const ne=ge;let E;n[44]!==_||n[45]!==L||n[46]!==ee||n[47]!==w?(E=()=>{ee||L(_+w)},n[44]=_,n[45]=L,n[46]=ee,n[47]=w,n[48]=E):E=n[48];const z=E;let J;if(n[49]!==r||n[50]!==a||n[51]!==ae||n[52]!==j||n[53]!==v||n[54]!==ne||n[55]!==z||n[56]!==ee||n[57]!==I||n[58]!==S||n[59]!==b){J=Symbol.for("react.early_return_sentinel");e:{const je=fe=>Pe=>{Pe.preventDefault(),Pe.stopPropagation(),R.current=!0,N(),fe()},be=fe=>Pe=>{if(R.current){R.current=!1,Pe.preventDefault(),Pe.stopPropagation();return}fe()};if(I){let fe;n[61]!==a?(fe=me("flex h-9 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent select-none overscroll-contain","[-webkit-user-select:none] [-webkit-touch-callout:none]","disabled:pointer-events-none disabled:opacity-50",a),n[61]=a,n[62]=fe):fe=n[62];let Pe;n[63]!==S?(Pe=S("numberInput.actions.decreaseAria"),n[63]=S,n[64]=Pe):Pe=n[64];const Be=je(ne),G=be(ne),ke=!ae&&"active:bg-interactive-hover";let Ee;n[65]!==ke?(Ee=me("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",ke),n[65]=ke,n[66]=Ee):Ee=n[66];let Ae;n[67]===Symbol.for("react.memo_cache_sentinel")?(Ae=s.jsx(Kl,{className:"block h-4 w-4"}),n[67]=Ae):Ae=n[67];const xe=s.jsx("button",{type:"button","aria-label":Pe,disabled:ae,onTouchStart:Be,onClick:G,className:Ee,children:Ae});let V;n[68]!==r?(V=me("flex h-full min-w-0 w-14 items-center justify-center bg-transparent px-1.5","text-center text-[16px] leading-none text-foreground [font-variant-numeric:tabular-nums]",r),n[68]=r,n[69]=V):V=n[69];const de=b===void 0?v:j;let Me;n[70]!==V||n[71]!==de?(Me=s.jsx("div",{className:V,"aria-live":"polite",children:de}),n[70]=V,n[71]=de,n[72]=Me):Me=n[72];let Le;n[73]!==S?(Le=S("numberInput.actions.increaseAria"),n[73]=S,n[74]=Le):Le=n[74];const se=je(z),ie=be(z),U=!ee&&"active:bg-interactive-hover";let Ve;n[75]!==U?(Ve=me("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",U),n[75]=U,n[76]=Ve):Ve=n[76];let He;n[77]===Symbol.for("react.memo_cache_sentinel")?(He=s.jsx(zs,{className:"block h-4 w-4"}),n[77]=He):He=n[77];const Ke=s.jsx("button",{type:"button","aria-label":Le,disabled:ee,onTouchStart:se,onClick:ie,className:Ve,children:He});let Ze;n[78]!==fe||n[79]!==xe||n[80]!==Me||n[81]!==Ke?(Ze=s.jsxs("div",{className:fe,children:[xe,Me,Ke]}),n[78]=fe,n[79]=xe,n[80]=Me,n[81]=Ke,n[82]=Ze):Ze=n[82],J=Ze;break e}}n[49]=r,n[50]=a,n[51]=ae,n[52]=j,n[53]=v,n[54]=ne,n[55]=z,n[56]=ee,n[57]=I,n[58]=S,n[59]=b,n[60]=J}else J=n[60];if(J!==Symbol.for("react.early_return_sentinel"))return J;let H;n[83]!==a?(H=me("flex h-7 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent","disabled:pointer-events-none disabled:opacity-50",a),n[83]=a,n[84]=H):H=n[84];let te;n[85]!==S?(te=S("numberInput.actions.decreaseAria"),n[85]=S,n[86]=te):te=n[86];let ce;n[87]!==_||n[88]!==L||n[89]!==w?(ce=()=>L(_-w),n[87]=_,n[88]=L,n[89]=w,n[90]=ce):ce=n[90];let Se,pe;n[91]===Symbol.for("react.memo_cache_sentinel")?(Se=me("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),pe=s.jsx(Kl,{className:"block h-3.5 w-3.5"}),n[91]=Se,n[92]=pe):(Se=n[91],pe=n[92]);let we;n[93]!==ae||n[94]!==te||n[95]!==ce?(we=s.jsx("button",{type:"button","aria-label":te,disabled:ae,onClick:ce,className:Se,children:pe}),n[93]=ae,n[94]=te,n[95]=ce,n[96]=we):we=n[96];const W=m.inputMode??"numeric";let ue;n[97]!==r?(ue=me("h-full min-w-0 w-14 bg-transparent px-1.5 text-center typography-ui-label leading-none text-foreground [font-variant-numeric:tabular-nums]","placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground","appearance-none outline-none [appearance:textfield] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","disabled:pointer-events-none disabled:cursor-not-allowed",r),n[97]=r,n[98]=ue):ue=n[98];let Y;n[99]!==i||n[100]!==j||n[101]!==oe||n[102]!==B||n[103]!==m||n[104]!==e||n[105]!==W||n[106]!==ue?(Y=s.jsx("input",{...m,ref:e,type:"text",inputMode:W,value:j,onChange:B,onBlur:oe,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:ue}),n[99]=i,n[100]=j,n[101]=oe,n[102]=B,n[103]=m,n[104]=e,n[105]=W,n[106]=ue,n[107]=Y):Y=n[107];let le;n[108]!==S?(le=S("numberInput.actions.increaseAria"),n[108]=S,n[109]=le):le=n[109];let Z;n[110]!==_||n[111]!==L||n[112]!==w?(Z=()=>L(_+w),n[110]=_,n[111]=L,n[112]=w,n[113]=Z):Z=n[113];let Ie,Ne;n[114]===Symbol.for("react.memo_cache_sentinel")?(Ie=me("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),Ne=s.jsx(zs,{className:"block h-3.5 w-3.5"}),n[114]=Ie,n[115]=Ne):(Ie=n[114],Ne=n[115]);let X;n[116]!==ee||n[117]!==le||n[118]!==Z?(X=s.jsx("button",{type:"button","aria-label":le,disabled:ee,onClick:Z,className:Ie,children:Ne}),n[116]=ee,n[117]=le,n[118]=Z,n[119]=X):X=n[119];let he;return n[120]!==H||n[121]!==we||n[122]!==Y||n[123]!==X?(he=s.jsxs("div",{className:H,children:[we,Y,X]}),n[120]=H,n[121]=we,n[122]=Y,n[123]=X,n[124]=he):he=n[124],he});Cn.displayName="NumberInput";const rh=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],El=t=>t==="allow"||t==="ask"||t==="deny",Ua=(t,e)=>`${t}::${e}`,di=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&El(n.action)&&e.set(Ua(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},hl=t=>{const e=new Map;for(const n of di(t))e.set(Ua(n.permission,n.pattern),n);return e},ah=t=>[...t].sort((e,n)=>{const r=e.permission.localeCompare(n.permission);return r!==0?r:e.pattern.localeCompare(n.pattern)}),h5=(t,e)=>{const n=ah(di(t)),r=ah(di(e));return n.length!==r.length?!1:n.every((a,i)=>{const o=r[i];return a.permission===o.permission&&a.pattern===o.pattern&&a.action===o.action})},f5=t=>t.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",g5=(t,e)=>di(t).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),x5=t=>{if(El(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(El(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))El(i)&&e.push({permission:n,pattern:a,action:i})}return e},b5=(t,e)=>{const n=di(e),r={};for(const i of n)(r[i.permission]||={})[i.pattern]=i.action;const a={"*":t};for(const[i,o]of Object.entries(r))if(i!=="*"){if(Object.keys(o).length===1&&o["*"]){a[i]=o["*"];continue}a[i]=o}return a},y5=()=>{const{t}=ut(),{isMobile:e}=dn(),{selectedAgentName:n,getAgentByName:r,createAgent:a,updateAgent:i,agents:o,agentDraft:c,setAgentDraft:d}=Ki(Sr(fe=>({selectedAgentName:fe.selectedAgentName,getAgentByName:fe.getAgentByName,createAgent:fe.createAgent,updateAgent:fe.updateAgent,agents:fe.agents,agentDraft:fe.agentDraft,setAgentDraft:fe.setAgentDraft}))),p=n?r(n):null,m=!!(c&&c.name===n&&!p),[u,f]=l.useState(""),[y,h]=l.useState("user"),[b,x]=l.useState(""),[g,w]=l.useState("subagent"),[v,S]=l.useState(""),[P,j]=l.useState(void 0),[C,I]=l.useState(void 0),[R,k]=l.useState(""),[A,N]=l.useState("allow"),[D,T]=l.useState([]),[M,$]=l.useState([]),[F,_]=l.useState(""),[O,L]=l.useState("*"),[K,B]=l.useState(!1),[re,oe]=l.useState(!1),ee=l.useRef(null),ae=qs(fe=>fe.currentDirectory??null),[ge,ne]=l.useState([]),E=jg(fe=>fe.permission);l.useEffect(()=>{let fe=!1;return(async()=>{const Be=await Mn.listToolIds({directory:ae});if(fe)return;const G=new Set(["write","patch","multiedit"]),ke=Be.map(Ee=>typeof Ee=="string"?Ee.trim():"").filter(Boolean).filter(Ee=>Ee!=="*").filter(Ee=>Ee!=="invalid").filter(Ee=>!G.has(Ee));ne(Array.from(new Set(ke)).sort((Ee,Ae)=>Ee.localeCompare(Ae)))})(),()=>{fe=!0}},[ae]);const z=l.useMemo(()=>{const fe=new Set;for(const Pe of o){const Be=di(Array.isArray(Pe.permission)?Pe.permission:[]);for(const G of Be)G.permission&&G.permission!=="*"&&G.permission!=="invalid"&&fe.add(G.permission)}for(const Pe of Object.values(E))for(const Be of Pe){const G=Be.permission?.trim();G&&G!=="invalid"&&fe.add(G)}for(const Pe of ge)fe.add(Pe);return Array.from(fe).sort((Pe,Be)=>Pe.localeCompare(Be))},[o,E,ge]),J=l.useMemo(()=>hl(D),[D]),H=l.useMemo(()=>hl(M),[M]),te=l.useCallback(fe=>H.get(Ua(fe,"*"))?.action,[H]),ce=l.useCallback(fe=>M.filter(Pe=>Pe.permission===fe&&Pe.pattern!=="*").sort((Pe,Be)=>Pe.pattern.localeCompare(Be.pattern)),[M]),Se=l.useMemo(()=>{const fe=new Set;for(const Pe of rh)fe.add(Pe);for(const Pe of z)fe.add(Pe);return Array.from(fe).sort((Pe,Be)=>Pe.localeCompare(Be))},[z]),pe=l.useCallback(fe=>{const Pe=fe==="*"?A:te(fe)??A,Be=ce(fe),G=!1,ke=Be.reduce((Ae,xe)=>(Ae[xe.action]=(Ae[xe.action]??0)+1,Ae),{allow:0,ask:0,deny:0}),Ee=["allow","ask","deny"].filter(Ae=>ke[Ae]>0).map(Ae=>`${ke[Ae]} ${Ae}`).join(", ");return{defaultAction:Pe,patternRulesCount:Be.length,patternSummary:Ee,hasDefaultHint:G}},[ce,te,A]),we=l.useCallback(fe=>t(fe==="allow"?"settings.common.permission.allow":fe==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[t]),W=l.useCallback(fe=>fe==="global"?t("settings.common.scope.global"):we(fe),[we,t]),ue=l.useMemo(()=>{const fe=new Set;for(const Pe of rh)fe.add(Pe);for(const Pe of z)fe.add(Pe);return Array.from(fe).sort((Pe,Be)=>Pe.localeCompare(Be))},[z]),Y=l.useCallback((fe,Pe,Be)=>{$(G=>{const ke=hl(G);return ke.set(Ua(fe,Pe),{permission:fe,pattern:Pe,action:Be}),Array.from(ke.values())})},[]),le=l.useCallback((fe,Pe)=>{$(Be=>{const G=hl(Be);return G.delete(Ua(fe,Pe)),Array.from(G.values())})},[]),Z=l.useCallback((fe,Pe)=>{const Be=J.get(Ua(fe,Pe));if(Be){Y(fe,Pe,Be.action);return}le(fe,Pe)},[J,le,Y]),Ie=l.useCallback((fe,Pe,Be)=>{Y(fe,Pe,Be)},[Y]),Ne=l.useCallback(fe=>{N(fe),$(Pe=>Pe.filter(Be=>!(Be.pattern==="*"&&Be.action===fe)))},[]),X=l.useCallback(fe=>{const Pe=F.trim();if(!Pe){q.error(t("settings.agents.page.toast.permissionNameRequired"));return}const Be=O.trim()||"*";if(Pe==="*"&&Be==="*"){Ne(fe),_(""),L("*");return}Be==="*"&&Pe!=="*"&&fe===A?le(Pe,"*"):Y(Pe,Be,fe),_(""),L("*")},[A,F,O,le,Ne,t,Y]),he=l.useCallback(fe=>fe==="*"?t("settings.agents.page.permissions.defaultLabel"):fe==="webfetch"?"WebFetch":fe==="websearch"?"WebSearch":fe==="codesearch"?"CodeSearch":fe==="doom_loop"?"Doom Loop":fe==="external_directory"?"External Directory":fe==="todowrite"?"TodoWrite":fe==="todoread"?"TodoRead":fe.split(/[_-]+/g).filter(Boolean).map(Pe=>Pe.charAt(0).toUpperCase()+Pe.slice(1)).join(" "),[t]);l.useEffect(()=>{_(""),L("*");const fe=Pe=>{const Be=di(Pe),G=f5(Be),ke=g5(Be,G);return N(G),T(ke),$(ke),{global:G,rules:ke}};if(m&&c){const Pe=c.name||"",Be=c.scope||"user",G=c.description||"",ke=c.mode||"subagent",Ee=c.model||"",Ae=c.temperature,xe=c.top_p,V=c.prompt||"";f(Pe),h(Be),x(G),w(ke),S(Ee),j(Ae),I(xe),k(V);const de=x5(c.permission),Me=fe(de);ee.current={draftName:Pe,draftScope:Be,description:G,mode:ke,model:Ee,temperature:Ae,topP:xe,prompt:V,globalPermission:Me.global,permissionRules:Me.rules};return}if(p&&n===p.name){const Pe=p.description||"",Be=p.mode||"subagent",G=p.model?.providerID&&p.model?.modelID?`${p.model.providerID}/${p.model.modelID}`:"",ke=p.temperature,Ee=p.topP,Ae=p.prompt||"";x(Pe),w(Be),S(G),j(ke),I(Ee),k(Ae);const xe=fe(Array.isArray(p.permission)?p.permission:[]);ee.current={draftName:"",draftScope:"user",description:Pe,mode:Be,model:G,temperature:ke,topP:Ee,prompt:Ae,globalPermission:xe.global,permissionRules:xe.rules}}},[c,m,p,n]);const je=l.useMemo(()=>{const fe=ee.current;return fe?!!(m&&(u!==fe.draftName||y!==fe.draftScope)||b!==fe.description||g!==fe.mode||v!==fe.model||P!==fe.temperature||C!==fe.topP||R!==fe.prompt||A!==fe.globalPermission||!h5(M,fe.permissionRules)):!1},[b,u,y,A,m,g,v,M,R,P,C]),be=async()=>{const fe=m?u.trim().replace(/\s+/g,"-"):n?.trim();if(!fe){q.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&o.some(Pe=>Pe.name===fe)){q.error(t("settings.agents.sidebar.toast.agentExists"));return}oe(!0);try{const Pe=v.trim(),Be=b5(A,M),G={name:fe,description:b.trim()||void 0,mode:g,model:Pe===""?null:Pe,temperature:P,top_p:C,prompt:R.trim()||void 0,permission:Be,scope:m?y:void 0};let ke;m?(ke=await a(G),ke&&d(null)):ke=await i(fe,G),ke?q.success(t(m?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):q.error(t(m?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(Pe){console.error("Error saving agent:",Pe);const Be=Pe instanceof Error&&Pe.message?Pe.message:t("settings.agents.page.toast.saveUnexpectedError");q.error(Be)}finally{oe(!1)}};return n?s.jsx(Ps,{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(Bt,{value:u,onChange:fe=>f(fe.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(ps,{value:y,onValueChange:fe=>h(fe),children:[s.jsx(hs,{className:"w-fit min-w-[100px]",children:s.jsx(ys,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(fs,{align:"end",children:[s.jsx(Rt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Yr,{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(Un,{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(An,{value:b,onChange:fe=>x(fe.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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{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(ve,{variant:"chip",size:"xs","aria-pressed":g==="primary",onClick:()=>w("primary"),className:"!font-normal",children:t("settings.agents.page.mode.primary")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":g==="subagent",onClick:()=>w("subagent"),className:"!font-normal",children:t("settings.agents.page.mode.subagent")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":g==="all",onClick:()=>w("all"),className:"!font-normal",children:t("settings.agents.page.mode.all")})]})]})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.modelParameters")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.overrideModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(qo,{providerId:Ji(v)?.providerId??"",modelId:Ji(v)?.modelId??"",onChange:(fe,Pe)=>{S(fe&&Pe?`${fe}/${Pe}`:"")}})})]}),s.jsxs("div",{className:me("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:me("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.temperature")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.temperatureTooltip")})]})]}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.agents.page.field.temperatureRange")})]}),s.jsxs("div",{className:me("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(Cn,{value:P,fallbackValue:.7,onValueChange:j,onClear:()=>j(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),P!==void 0&&s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(Is,{className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:me("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:me("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.topP")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.topPTooltip")})]})]}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.agents.page.field.topPRange")})]}),s.jsxs("div",{className:me("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(Cn,{value:C,fallbackValue:.9,onValueChange:I,onClear:()=>I(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),C!==void 0&&s.jsx(ve,{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(Is,{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(An,{value:R,onChange:fe=>k(fe.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(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>B(fe=>!fe),children:t(K?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),K?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(ps,{value:A,onValueChange:fe=>Ne(fe),children:[s.jsx(hs,{className:"w-[100px]",children:s.jsx(ys,{children:we(A)})}),s.jsxs(fs,{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:Se.filter(fe=>fe!=="*").map(fe=>{const Pe=he(fe),{defaultAction:Be,patternRulesCount:G}=pe(fe),ke=te(fe),Ee=ke??"global",Ae=ce(fe),xe=["allow","ask","deny"].filter(V=>V!==A);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:Pe}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:fe})]}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:G>0?t("settings.agents.page.permissions.globalSummary",{summary:Be}):Be})]}),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:"*"}),ke&&s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>Z(fe,"*"),className:"px-1.5 py-0 h-5",children:s.jsx(Kl,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(ps,{value:Ee,onValueChange:V=>{if(V==="global"){le(fe,"*");return}Y(fe,"*",V)},children:[s.jsx(hs,{className:"w-[90px]",children:s.jsx(ys,{children:W(Ee)})}),s.jsxs(fs,{children:[s.jsx(Rt,{value:"global",children:t("settings.common.scope.global")}),xe.map(V=>s.jsx(Rt,{value:V,className:"capitalize",children:we(V)},V))]})]})]}),Ae.map(V=>{const de=Ua(V.permission,V.pattern),Me=J.get(de),Le=!Me,se=!!(Me&&Me.action!==V.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:V.pattern}),Le&&s.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:t("settings.common.badge.new")}),se&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:t("settings.common.badge.modified")}),(Le||se)&&s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>Le?le(V.permission,V.pattern):Z(V.permission,V.pattern),className:"px-1.5 py-0 h-5",children:s.jsx(Kl,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(ps,{value:V.action,onValueChange:ie=>Ie(V.permission,V.pattern,ie),children:[s.jsx(hs,{className:"w-[90px]",children:s.jsx(ys,{children:we(V.action)})}),s.jsxs(fs,{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")})]})]})]},de)})]})]},fe)})}),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(ps,{value:F,onValueChange:_,children:[s.jsx(hs,{className:"w-full sm:w-[160px]",children:F?s.jsx("span",{className:"truncate",children:he(F)}):s.jsx("span",{className:"text-muted-foreground",children:t("settings.agents.page.permissions.permissionPlaceholder")})}),s.jsx(fs,{children:ue.map(fe=>s.jsx(Rt,{value:fe,children:s.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:s.jsx("span",{children:he(fe)})})},fe))})]}),s.jsx(Bt,{value:O,onChange:fe=>L(fe.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(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>X("allow"),children:t("settings.common.permission.allow")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>X("ask"),children:t("settings.common.permission.ask")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>X("deny"),children:t("settings.common.permission.deny")})]})]})]})]}):s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:Se.map((fe,Pe)=>{const{defaultAction:Be,patternRulesCount:G,patternSummary:ke,hasDefaultHint:Ee}=pe(fe),Ae=he(fe),xe=Ee?`${Be} (env blocked)`:Be;return s.jsxs("div",{className:me("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",Pe>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:Ae}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:fe})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[G>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:xe})}):s.jsx("span",{className:me("typography-micro capitalize px-1.5 py-0.5 rounded",xe==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":xe==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:xe}),G>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:ke})})]})]},fe)})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(ve,{onClick:be,disabled:re||!je,size:"xs",className:"!font-normal",children:t(re?"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(Jr,{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")})]})})},v5="~/.config/opencode/AGENTS.md",Tx=async(t,e)=>{const n=await t.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},w5=t=>t.length>0&&!t.endsWith(`
|
|
64
|
+
`)?`${t}
|
|
65
|
+
`:t,fl={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},j5=(t,e)=>t==="custom"?e:p1(t),N5=t=>t==="custom"?"custom":Ng(t)?t:"concise",ih={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"},oh=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 Tx(n,e))},S5=()=>{const{t}=ut(),[e,n]=l.useState(""),[r,a]=l.useState(fl.responseStyleEnabled),[i,o]=l.useState(fl.responseStylePreset),[c,d]=l.useState(fl.responseStyleCustomInstructions),[p,m]=l.useState(!0),[u,f]=l.useState(!1),[y,h]=l.useState(""),b=l.useRef(null);l.useEffect(()=>{const v=new AbortController;return(async()=>{try{const[P,j]=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 C=fl;if(P.ok){const I=await P.json();C={...C,responseStyleEnabled:I.responseStyleEnabled===!0,responseStylePreset:N5(I.responseStylePreset),responseStyleCustomInstructions:typeof I.responseStyleCustomInstructions=="string"?I.responseStyleCustomInstructions:""},typeof I.globalBehaviorPrompt=="string"&&(C={...C,prompt:I.globalBehaviorPrompt})}if(!C.prompt.trim()&&j.ok){const I=await j.json();typeof I.content=="string"&&(C={...C,prompt:I.content})}n(C.prompt),a(C.responseStyleEnabled),o(C.responseStylePreset),d(C.responseStyleCustomInstructions),h(C.prompt),b.current={enabled:C.responseStyleEnabled,preset:C.responseStylePreset,custom:C.responseStyleCustomInstructions}}catch(P){P.name!=="AbortError"&&console.warn("Failed to load behavior settings:",P)}finally{m(!1)}})(),()=>v.abort()},[]),l.useEffect(()=>{if(p)return;const v=b.current;if(v&&v.enabled===r&&v.preset===i&&v.custom===c)return;const S={enabled:r,preset:i,custom:c},P=setTimeout(async()=>{try{await oh({responseStyleEnabled:S.enabled,responseStylePreset:S.preset,responseStyleCustomInstructions:S.custom},t("settings.behavior.page.toast.saveFailed")),b.current=S}catch(j){const C=j instanceof Error?j.message:t("settings.behavior.page.toast.saveFailed");q.error(C)}},400);return()=>clearTimeout(P)},[r,i,c,p,t]);const x=j5(i,c),g=e!==y,w=async()=>{f(!0);try{const v=w5(e),S=await fetch("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:v})});if(!S.ok)throw new Error(await Tx(S,t("settings.behavior.page.toast.saveFailed")));await oh({globalBehaviorPrompt:v},t("settings.behavior.page.toast.saveFailed")),n(v),h(v),q.success(t("settings.behavior.page.toast.saved"))}catch(v){console.error("Failed to save behavior:",v);const S=v instanceof Error?v.message:t("settings.behavior.page.toast.saveFailed");q.error(S)}finally{f(!1)}};return s.jsx(Ps,{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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{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:v5})})]})})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsx(An,{value:e,onChange:v=>n(v.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:p,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(ve,{onClick:w,disabled:u||!g||p,size:"xs",className:"!font-normal",children:t(u?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]})]}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.behavior.page.section.responseStyle")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{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(bs,{checked:r,onChange:a,disabled:p,ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),t("settings.behavior.page.responseStyle.enable")]}),s.jsxs(ps,{value:i,onValueChange:v=>o(v),disabled:p||!r,children:[s.jsx(hs,{className:"w-full sm:w-56",size:"lg",children:s.jsx(ys,{children:v=>v==="custom"?t("settings.behavior.page.responseStyle.option.custom"):Ng(v)?t(ih[v]):null})}),s.jsxs(fs,{children:[m1.map(v=>s.jsx(Rt,{value:v,children:t(ih[v])},v)),s.jsx(Rt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]}),s.jsx(An,{value:x,onChange:v=>d(v.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:p||!r||i!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},k5=t=>{const e=nt.c(169),{onItemSelect:n}=t,{t:r}=ut(),[a,i]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(null),[f,y]=l.useState(!1),[h,b]=l.useState(null),{selectedCommandName:x,commands:g,setSelectedCommand:w,setCommandDraft:v,createCommand:S,deleteCommand:P,loadCommands:j}=Uu(Sr(C5)),C=wa(I5),I=wa(A5);let R,k;e[0]!==j||e[1]!==I?(R=()=>{j(),I()},k=[j,I],e[0]=j,e[1]=I,e[2]=R,e[3]=k):(R=e[2],k=e[3]),l.useEffect(R,k);let A;e[4]!==C?(A=new Set(C.map(P5)),e[4]=C,e[5]=A):A=e[5];const N=A;let D;if(e[6]!==g||e[7]!==N){let $e;e[9]!==N?($e=_e=>!N.has(_e.name),e[9]=N,e[10]=$e):$e=e[10],D=g.filter($e),e[6]=g,e[7]=N,e[8]=D}else D=e[8];const T=D;let M,$;e[11]!==x||e[12]!==w||e[13]!==N?(M=()=>{x&&N.has(x)&&w(null)},$=[x,w,N],e[11]=x,e[12]=w,e[13]=N,e[14]=M,e[15]=$):(M=e[14],$=e[15]),l.useEffect(M,$);let F;e[16]!==g||e[17]!==n||e[18]!==v||e[19]!==w?(F=()=>{let $e="new-command",_e=1;for(;g.some(tt=>tt.name===$e);)$e=`new-command-${_e}`,_e++;v({name:$e,scope:"user"}),w($e),n?.()},e[16]=g,e[17]=n,e[18]=v,e[19]=w,e[20]=F):F=e[20];const _=F;let O;e[21]!==r?(O=async $e=>{if($i($e)){q.error(r("settings.commands.sidebar.toast.builtInCannotDelete"));return}p($e),u("delete")},e[21]=r,e[22]=O):O=e[22];const L=O;let K;e[23]===Symbol.for("react.memo_cache_sentinel")?(K=async $e=>{$i($e)&&(p($e),u("reset"))},e[23]=K):K=e[23];const B=K;let re;e[24]===Symbol.for("react.memo_cache_sentinel")?(re=()=>{p(null),u(null)},e[24]=re):re=e[24];const oe=re;let ee;e[25]!==d||e[26]!==m||e[27]!==P||e[28]!==r?(ee=async()=>{if(!d||!m)return;y(!0),await P(d.name)?(m==="delete"?q.success(r("settings.commands.sidebar.toast.commandDeleted",{name:d.name})):q.success(r("settings.commands.sidebar.toast.commandReset",{name:d.name})),oe()):m==="delete"?q.error(r("settings.commands.sidebar.toast.deleteFailed")):q.error(r("settings.commands.sidebar.toast.resetFailed")),y(!1)},e[25]=d,e[26]=m,e[27]=P,e[28]=r,e[29]=ee):ee=e[29];const ae=ee;let ge;e[30]!==g||e[31]!==v||e[32]!==w?(ge=$e=>{const _e=$e.name;let tt=1,Qe=`${_e}-copy`;for(;g.some(ze=>ze.name===Qe);)tt++,Qe=`${_e}-copy-${tt}`;v({name:Qe,scope:$e.scope||"user",description:$e.description,template:$e.template,agent:$e.agent,model:$e.model}),w(Qe)},e[30]=g,e[31]=v,e[32]=w,e[33]=ge):ge=e[33];const ne=ge;let E;e[34]===Symbol.for("react.memo_cache_sentinel")?(E=$e=>{c($e.name),i($e)},e[34]=E):E=e[34];const z=E;let J;e[35]!==g||e[36]!==S||e[37]!==P||e[38]!==a||e[39]!==o||e[40]!==w||e[41]!==r?(J=async()=>{if(!a)return;const $e=o.trim().replace(/\s+/g,"-");if(!$e){q.error(r("settings.commands.sidebar.toast.commandNameRequired"));return}if($e===a.name){i(null);return}if(g.some(tt=>tt.name===$e)){q.error(r("settings.commands.sidebar.toast.commandExists"));return}await S({name:$e,description:a.description,template:a.template,agent:a.agent,model:a.model})?await P(a.name)?(q.success(`Command renamed to "${$e}"`),w($e)):q.error(r("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):q.error(r("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=g,e[36]=S,e[37]=P,e[38]=a,e[39]=o,e[40]=w,e[41]=r,e[42]=J):J=e[42];const H=J;let te,ce,Se,pe,we,W;if(e[43]!==T||e[44]!==_||e[45]!==L||e[46]!==ne||e[47]!==n||e[48]!==h||e[49]!==x||e[50]!==w||e[51]!==r){const $e=T.filter($i),_e=T.filter(D5);e[58]===Symbol.for("react.memo_cache_sentinel")?(we=me("flex h-full flex-col","bg-background"),e[58]=we):we=e[58];let tt;e[59]!==r?(tt=r("settings.commands.sidebar.title"),e[59]=r,e[60]=tt):tt=e[60];let Qe;e[61]!==tt?(Qe=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:tt}),e[61]=tt,e[62]=Qe):Qe=e[62];let ze;e[63]===Symbol.for("react.memo_cache_sentinel")?(ze=s.jsx(Qo,{className:"mb-3"}),e[63]=ze):ze=e[63];let gt;e[64]!==T.length||e[65]!==r?(gt=r("settings.commands.sidebar.total",{count:T.length}),e[64]=T.length,e[65]=r,e[66]=gt):gt=e[66];let Vt;e[67]!==gt?(Vt=s.jsx("span",{className:"typography-meta text-muted-foreground",children:gt}),e[67]=gt,e[68]=Vt):Vt=e[68];let Kt;e[69]===Symbol.for("react.memo_cache_sentinel")?(Kt=s.jsx(zs,{className:"h-3.5 w-3.5"}),e[69]=Kt):Kt=e[69];let Jt;e[70]!==_?(Jt=s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:_,children:Kt}),e[70]=_,e[71]=Jt):Jt=e[71];let At;e[72]!==Vt||e[73]!==Jt?(At=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Vt,Jt]}),e[72]=Vt,e[73]=Jt,e[74]=At):At=e[74],e[75]!==Qe||e[76]!==At?(W=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Qe,ze,At]}),e[75]=Qe,e[76]=At,e[77]=W):W=e[77],te=Ps,ce="flex-1 min-h-0",Se="space-y-1 px-3 py-2",pe=T.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(Za,{className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[$e.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.commands.sidebar.section.builtIn")}),[...$e].sort(T5).map(jt=>s.jsx(lh,{command:jt,isSelected:x===jt.name,onSelect:()=>{w(jt.name),n?.()},onReset:()=>B(jt),onDuplicate:()=>ne(jt),isMenuOpen:h===jt.name,onMenuOpenChange:ns=>b(ns?jt.name:null)},jt.name))]}),_e.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")}),[..._e].sort(M5).map(jt=>s.jsx(lh,{command:jt,isSelected:x===jt.name,onSelect:()=>{w(jt.name),n?.()},onRename:()=>z(jt),onDelete:()=>L(jt),onDuplicate:()=>ne(jt),isMenuOpen:h===jt.name,onMenuOpenChange:ns=>b(ns?jt.name:null)},jt.name))]})]}),e[43]=T,e[44]=_,e[45]=L,e[46]=ne,e[47]=n,e[48]=h,e[49]=x,e[50]=w,e[51]=r,e[52]=te,e[53]=ce,e[54]=Se,e[55]=pe,e[56]=we,e[57]=W}else te=e[52],ce=e[53],Se=e[54],pe=e[55],we=e[56],W=e[57];let ue;e[78]!==te||e[79]!==ce||e[80]!==Se||e[81]!==pe?(ue=s.jsx(te,{outerClassName:ce,className:Se,children:pe}),e[78]=te,e[79]=ce,e[80]=Se,e[81]=pe,e[82]=ue):ue=e[82];const Y=d!==null&&m!==null;let le;e[83]!==f?(le=$e=>{!$e&&!f&&oe()},e[83]=f,e[84]=le):le=e[84];let Z;e[85]!==m||e[86]!==r?(Z=r(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=r,e[87]=Z):Z=e[87];let Ie;e[88]!==Z?(Ie=s.jsx(js,{children:Z}),e[88]=Z,e[89]=Ie):Ie=e[89];let Ne;e[90]!==d?.name||e[91]!==m||e[92]!==r?(Ne=m==="delete"?r("settings.commands.sidebar.dialog.deleteDescription",{name:d?.name??""}):r("settings.commands.sidebar.dialog.resetDescription",{name:d?.name??""}),e[90]=d?.name,e[91]=m,e[92]=r,e[93]=Ne):Ne=e[93];let X;e[94]!==Ne?(X=s.jsx(Fs,{children:Ne}),e[94]=Ne,e[95]=X):X=e[95];let he;e[96]!==Ie||e[97]!==X?(he=s.jsxs(Cs,{children:[Ie,X]}),e[96]=Ie,e[97]=X,e[98]=he):he=e[98];let je;e[99]!==r?(je=r("settings.common.actions.cancel"),e[99]=r,e[100]=je):je=e[100];let be;e[101]!==f||e[102]!==je?(be=s.jsx(ve,{size:"sm",variant:"ghost",onClick:oe,disabled:f,children:je}),e[101]=f,e[102]=je,e[103]=be):be=e[103];let fe;e[104]!==m||e[105]!==r?(fe=r(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=r,e[106]=fe):fe=e[106];let Pe;e[107]!==ae||e[108]!==f||e[109]!==fe?(Pe=s.jsx(ve,{size:"sm",onClick:ae,disabled:f,children:fe}),e[107]=ae,e[108]=f,e[109]=fe,e[110]=Pe):Pe=e[110];let Be;e[111]!==be||e[112]!==Pe?(Be=s.jsxs(Xs,{children:[be,Pe]}),e[111]=be,e[112]=Pe,e[113]=Be):Be=e[113];let G;e[114]!==he||e[115]!==Be?(G=s.jsxs(vs,{className:"max-w-md",children:[he,Be]}),e[114]=he,e[115]=Be,e[116]=G):G=e[116];let ke;e[117]!==Y||e[118]!==le||e[119]!==G?(ke=s.jsx(ws,{open:Y,onOpenChange:le,children:G}),e[117]=Y,e[118]=le,e[119]=G,e[120]=ke):ke=e[120];const Ee=a!==null;let Ae;e[121]===Symbol.for("react.memo_cache_sentinel")?(Ae=$e=>!$e&&i(null),e[121]=Ae):Ae=e[121];let xe;e[122]!==r?(xe=r("settings.commands.sidebar.renameDialog.title"),e[122]=r,e[123]=xe):xe=e[123];let V;e[124]!==xe?(V=s.jsx(js,{children:xe}),e[124]=xe,e[125]=V):V=e[125];const de=a?.name??"";let Me;e[126]!==r||e[127]!==de?(Me=r("settings.commands.sidebar.renameDialog.description",{name:de}),e[126]=r,e[127]=de,e[128]=Me):Me=e[128];let Le;e[129]!==Me?(Le=s.jsx(Fs,{children:Me}),e[129]=Me,e[130]=Le):Le=e[130];let se;e[131]!==V||e[132]!==Le?(se=s.jsxs(Cs,{children:[V,Le]}),e[131]=V,e[132]=Le,e[133]=se):se=e[133];let ie;e[134]===Symbol.for("react.memo_cache_sentinel")?(ie=$e=>c($e.target.value),e[134]=ie):ie=e[134];let U;e[135]!==r?(U=r("settings.commands.sidebar.renameDialog.placeholder"),e[135]=r,e[136]=U):U=e[136];let Ve;e[137]!==H?(Ve=$e=>{$e.key==="Enter"&&H()},e[137]=H,e[138]=Ve):Ve=e[138];let He;e[139]!==o||e[140]!==U||e[141]!==Ve?(He=s.jsx(Bt,{value:o,onChange:ie,placeholder:U,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Ve}),e[139]=o,e[140]=U,e[141]=Ve,e[142]=He):He=e[142];let Ke;e[143]===Symbol.for("react.memo_cache_sentinel")?(Ke=()=>i(null),e[143]=Ke):Ke=e[143];let Ze;e[144]!==r?(Ze=r("settings.common.actions.cancel"),e[144]=r,e[145]=Ze):Ze=e[145];let Xe;e[146]!==Ze?(Xe=s.jsx(ve,{size:"sm",variant:"ghost",onClick:Ke,children:Ze}),e[146]=Ze,e[147]=Xe):Xe=e[147];let dt;e[148]!==r?(dt=r("settings.common.actions.rename"),e[148]=r,e[149]=dt):dt=e[149];let et;e[150]!==H||e[151]!==dt?(et=s.jsx(ve,{size:"sm",onClick:H,children:dt}),e[150]=H,e[151]=dt,e[152]=et):et=e[152];let ct;e[153]!==Xe||e[154]!==et?(ct=s.jsxs(Xs,{children:[Xe,et]}),e[153]=Xe,e[154]=et,e[155]=ct):ct=e[155];let at;e[156]!==se||e[157]!==He||e[158]!==ct?(at=s.jsxs(vs,{children:[se,He,ct]}),e[156]=se,e[157]=He,e[158]=ct,e[159]=at):at=e[159];let ye;e[160]!==Ee||e[161]!==at?(ye=s.jsx(ws,{open:Ee,onOpenChange:Ae,children:at}),e[160]=Ee,e[161]=at,e[162]=ye):ye=e[162];let Ge;return e[163]!==we||e[164]!==W||e[165]!==ue||e[166]!==ke||e[167]!==ye?(Ge=s.jsxs("div",{className:we,children:[W,ue,ke,ye]}),e[163]=we,e[164]=W,e[165]=ue,e[166]=ke,e[167]=ye,e[168]=Ge):Ge=e[168],Ge},lh=t=>{const e=nt.c(53),{command:n,isSelected:r,onSelect:a,onDelete:i,onReset:o,onRename:c,onDuplicate:d,isMenuOpen:p,onMenuOpenChange:m}=t,{t:u}=ut();let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Mo(),e[0]=f):f=e[0];const y=f,h=r?"bg-interactive-selection":"hover:bg-interactive-hover";let b;e[1]!==h?(b=me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",h),e[1]=h,e[2]=b):b=e[2];let x;e[3]!==m?(x=y?void 0:_=>{_.preventDefault(),m(!0)},e[3]=m,e[4]=x):x=e[4];let g;e[5]!==n.name?(g=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[5]=n.name,e[6]=g):g=e[6];let w;e[7]!==n||e[8]!==u?(w=(n.scope||$i(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:$i(n)?u("settings.agents.sidebar.badge.system"):n.scope}),e[7]=n,e[8]=u,e[9]=w):w=e[9];let v;e[10]!==g||e[11]!==w?(v=s.jsxs("div",{className:"flex items-center gap-2",children:[g,w]}),e[10]=g,e[11]=w,e[12]=v):v=e[12];let S;e[13]!==n.description?(S=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[13]=n.description,e[14]=S):S=e[14];let P;e[15]!==a||e[16]!==v||e[17]!==S?(P=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,S]}),e[15]=a,e[16]=v,e[17]=S,e[18]=P):P=e[18];let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx($s,{asChild:!0,children:s.jsx(ve,{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(la,{className:"h-3.5 w-3.5"})})}),e[19]=j):j=e[19];let C;e[20]!==c||e[21]!==u?(C=c&&s.jsxs(Lt,{onClick:_=>{_.stopPropagation(),c()},children:[s.jsx(ea,{className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),e[20]=c,e[21]=u,e[22]=C):C=e[22];let I;e[23]!==d?(I=_=>{_.stopPropagation(),d()},e[23]=d,e[24]=I):I=e[24];let R;e[25]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(vr,{className:"h-4 w-4 mr-px"}),e[25]=R):R=e[25];let k;e[26]!==u?(k=u("settings.common.actions.duplicate"),e[26]=u,e[27]=k):k=e[27];let A;e[28]!==I||e[29]!==k?(A=s.jsxs(Lt,{onClick:I,children:[R,k]}),e[28]=I,e[29]=k,e[30]=A):A=e[30];let N;e[31]!==o||e[32]!==u?(N=o&&s.jsxs(Lt,{onClick:_=>{_.stopPropagation(),o()},children:[s.jsx(Fn,{className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),e[31]=o,e[32]=u,e[33]=N):N=e[33];let D;e[34]!==i||e[35]!==u?(D=i&&s.jsxs(Lt,{onClick:_=>{_.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(an,{className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]}),e[34]=i,e[35]=u,e[36]=D):D=e[36];let T;e[37]!==C||e[38]!==A||e[39]!==N||e[40]!==D?(T=s.jsxs(Bs,{align:"end",className:"w-fit min-w-20",children:[C,A,N,D]}),e[37]=C,e[38]=A,e[39]=N,e[40]=D,e[41]=T):T=e[41];let M;e[42]!==p||e[43]!==m||e[44]!==T?(M=s.jsxs(_s,{open:p,onOpenChange:m,children:[j,T]}),e[42]=p,e[43]=m,e[44]=T,e[45]=M):M=e[45];let $;e[46]!==M||e[47]!==P?($=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[P,M]}),e[46]=M,e[47]=P,e[48]=$):$=e[48];let F;return e[49]!==$||e[50]!==b||e[51]!==x?(F=s.jsx("div",{className:b,onContextMenu:x,children:$}),e[49]=$,e[50]=b,e[51]=x,e[52]=F):F=e[52],F};function C5(t){return{selectedCommandName:t.selectedCommandName,commands:t.commands,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function I5(t){return t.skills}function A5(t){return t.loadSkills}function P5(t){return t.name}function D5(t){return!$i(t)}function T5(t,e){return t.name.localeCompare(e.name)}function M5(t,e){return t.name.localeCompare(e.name)}const R5=()=>{const{t}=ut(),{selectedCommandName:e,getCommandByName:n,createCommand:r,updateCommand:a,commands:i,commandDraft:o,setCommandDraft:c}=Uu(Sr(A=>({selectedCommandName:A.selectedCommandName,getCommandByName:A.getCommandByName,createCommand:A.createCommand,updateCommand:A.updateCommand,commands:A.commands,commandDraft:A.commandDraft,setCommandDraft:A.setCommandDraft}))),d=e?n(e):null,p=!!(o&&o.name===e&&!d),[m,u]=l.useState(""),[f,y]=l.useState("user"),[h,b]=l.useState(""),[x,g]=l.useState(""),[w,v]=l.useState(""),[S,P]=l.useState(""),[j,C]=l.useState(!1),I=l.useRef(null);l.useEffect(()=>{if(p&&o){const A=o.name||"",N=o.scope||"user",D=o.description||"",T=o.agent||"",M=o.model||"",$=o.template||"";u(A),y(N),b(D),g(T),v(M),P($),I.current={draftName:A,draftScope:N,description:D,agent:T,model:M,template:$}}else if(d){const A=d.description||"",N=d.agent||"",D=d.model||"",T=d.template||"";b(A),g(N),v(D),P(T),I.current={draftName:"",draftScope:"user",description:A,agent:N,model:D,template:T}}},[d,p,e,i,o]);const R=l.useMemo(()=>{const A=I.current;return A?!!(p&&(m!==A.draftName||f!==A.draftScope)||h!==A.description||x!==A.agent||w!==A.model||S!==A.template):!1},[x,h,m,f,p,w,S]),k=async()=>{const A=p?m.trim().replace(/\s+/g,"-"):e?.trim();if(!A){q.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!S.trim()){q.error(t("settings.commands.page.toast.templateRequired"));return}if(p&&i.some(N=>N.name===A)){q.error(t("settings.commands.sidebar.toast.commandExists"));return}C(!0);try{const N=x.trim(),D=w.trim(),T=S.trim(),M={name:A,description:h.trim()||void 0,agent:N===""?null:N,model:D===""?null:D,template:T,scope:p?f:void 0};let $;p?($=await r(M),$&&c(null)):$=await a(A,M),$?q.success(t(p?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):q.error(t(p?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(N){console.error("Error saving command:",N),q.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{C(!1)}};return e?s.jsx(Ps,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:p?t("settings.commands.page.title.new"):`/${e}`}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t(p?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.identity")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[p&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.commands.page.field.commandName")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),s.jsx(Bt,{value:m,onChange:A=>u(A.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(ps,{value:f,onValueChange:A=>y(A),children:[s.jsx(hs,{className:"w-fit min-w-[100px]",children:s.jsx(ys,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(fs,{align:"end",children:[s.jsx(Rt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Yr,{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(Un,{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(An,{value:h,onChange:A=>b(A.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(Sc,{agentName:x,onChange:A=>g(A)})})]}),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(qo,{providerId:Ji(w)?.providerId??"",modelId:Ji(w)?.modelId??"",onChange:(A,N)=>{v(A&&N?`${A}/${N}`:"")}})})]})]})]}),s.jsxs("div",{className:"mb-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.template")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(An,{value:S,onChange:A=>P(A.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(ve,{onClick:k,disabled:j||!R,size:"xs",className:"!font-normal",children:t(j?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(Za,{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")})]})})},ch=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},dh=t=>{const e=nt.c(5),{tone:n,enabled:r}=t;if(!r){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=o):o=e[0],o}let a;e[1]!==n?(a=me("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[n]),e[1]=n,e[2]=a):a=e[2];let i;return e[3]!==a?(i=s.jsx("span",{className:a}),e[3]=a,e[4]=i):i=e[4],i},E5=t=>{const e=nt.c(116),{onItemSelect:n}=t,{t:r}=ut(),{mcpServers:a,selectedMcpName:i,setSelectedMcp:o,setMcpDraft:c,loadMcpConfigs:d,deleteMcp:p}=Lo(Sr(F5)),m=qs(O5);let u;e[0]!==m?(u=xe=>xe.getStatusForDirectory(m??null),e[0]=m,e[1]=u):u=e[1];const f=Tn(u),y=Tn(L5),h=Tn($5),[b,x]=l.useState(null),[g,w]=l.useState(!1),[v,S]=l.useState(null),[P,j]=l.useState(!1);let C;e[2]!==a?(C=a.filter(B5),e[2]=a,e[3]=C):C=e[3];const I=C;let R;e[4]!==a?(R=a.filter(_5),e[4]=a,e[5]=R):R=e[5];const k=R;let A,N;e[6]!==d?(A=()=>{d()},N=[d],e[6]=d,e[7]=A,e[8]=N):(A=e[7],N=e[8]),l.useEffect(A,N);let D;e[9]!==m||e[10]!==h||e[11]!==P||e[12]!==y?(D=()=>{if(P)return;j(!0);const xe=new Promise(V5);Promise.all([y({directory:m,silent:!0}),xe]).then(()=>{const V=h(m);V&&q.error(V)}).finally(()=>{j(!1)})},e[9]=m,e[10]=h,e[11]=P,e[12]=y,e[13]=D):D=e[13];const T=D;let M;e[14]!==a||e[15]!==n||e[16]!==c||e[17]!==o?(M=()=>{let xe="new-mcp-server",V=1;for(;a.some(Me=>Me.name===xe);)xe=`new-mcp-server-${V}`,V++;c({name:xe,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),o(xe),n?.()},e[14]=a,e[15]=n,e[16]=c,e[17]=o,e[18]=M):M=e[18];const $=M;let F;e[19]!==p||e[20]!==b||e[21]!==r?(F=async()=>{if(!b)return;w(!0);const xe=await p(b.name);xe.ok?xe.reloadFailed?q.warning(xe.message||`MCP server "${b.name}" deleted, but OpenCode reload failed`,{description:xe.warning||r("settings.mcp.sidebar.toast.refreshListIfStale")}):q.success(xe.message||r("settings.mcp.sidebar.toast.serverDeleted",{name:b.name})):q.error(r("settings.mcp.sidebar.toast.deleteFailed")),x(null),w(!1)},e[19]=p,e[20]=b,e[21]=r,e[22]=F):F=e[22];const _=F;let O;e[23]===Symbol.for("react.memo_cache_sentinel")?(O=me("flex h-full flex-col","bg-background"),e[23]=O):O=e[23];let L;e[24]!==r?(L=r("settings.mcp.sidebar.title"),e[24]=r,e[25]=L):L=e[25];let K;e[26]!==L?(K=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:L}),e[26]=L,e[27]=K):K=e[27];let B;e[28]!==r?(B=r("settings.mcp.sidebar.actions.refreshStatusAria"),e[28]=r,e[29]=B):B=e[29];let re;e[30]!==r?(re=r("settings.mcp.sidebar.actions.refreshStatusTitle"),e[30]=r,e[31]=re):re=e[31];const oe=P&&"animate-spin";let ee;e[32]!==oe?(ee=me("h-4 w-4",oe),e[32]=oe,e[33]=ee):ee=e[33];let ae;e[34]!==ee?(ae=s.jsx(In,{className:ee}),e[34]=ee,e[35]=ae):ae=e[35];let ge;e[36]!==T||e[37]!==P||e[38]!==B||e[39]!==re||e[40]!==ae?(ge=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:P,onClick:T,"aria-label":B,title:re,children:ae}),e[36]=T,e[37]=P,e[38]=B,e[39]=re,e[40]=ae,e[41]=ge):ge=e[41];let ne;e[42]!==K||e[43]!==ge?(ne=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[K,ge]}),e[42]=K,e[43]=ge,e[44]=ne):ne=e[44];let E;e[45]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(Qo,{className:"mb-3"}),e[45]=E):E=e[45];let z;e[46]!==a.length||e[47]!==r?(z=r("settings.mcp.sidebar.total",{count:a.length}),e[46]=a.length,e[47]=r,e[48]=z):z=e[48];let J;e[49]!==z?(J=s.jsx("span",{className:"typography-meta text-muted-foreground",children:z}),e[49]=z,e[50]=J):J=e[50];let H;e[51]!==r?(H=r("settings.mcp.sidebar.actions.addServerTitle"),e[51]=r,e[52]=H):H=e[52];let te;e[53]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx(zs,{className:"h-3.5 w-3.5"}),e[53]=te):te=e[53];let ce;e[54]!==$||e[55]!==H?(ce=s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:$,title:H,children:te}),e[54]=$,e[55]=H,e[56]=ce):ce=e[56];let Se;e[57]!==J||e[58]!==ce?(Se=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[J,ce]}),e[57]=J,e[58]=ce,e[59]=Se):Se=e[59];let pe;e[60]!==ne||e[61]!==Se?(pe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ne,E,Se]}),e[60]=ne,e[61]=Se,e[62]=pe):pe=e[62];let we;e[63]!==a.length||e[64]!==f||e[65]!==n||e[66]!==v||e[67]!==I||e[68]!==i||e[69]!==c||e[70]!==o||e[71]!==r||e[72]!==k?(we=s.jsx(Ps,{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(Yf,{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(xe=>{const V=f[xe.name],de=ch(V?.status),Me=i===xe.name,Le=Mo();return s.jsxs("div",{className:me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Me?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Le?void 0:se=>{se.preventDefault(),S(xe.name)},children:[s.jsxs("button",{onClick:()=>{o(xe.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(dh,{tone:de,enabled:xe.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:xe.name}),s.jsx("span",{title:xe.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:xe.type==="local"?s.jsx(ei,{className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(ti,{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:xe.type==="local"?xe.command?.join(" ")??"":xe.url??""})]}),s.jsxs(_s,{open:v===xe.name,onOpenChange:se=>S(se?xe.name:null),children:[s.jsx($s,{asChild:!0,children:s.jsx(ve,{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(la,{className:"h-3.5 w-3.5"})})}),s.jsx(Bs,{align:"end",className:"w-fit min-w-20",children:s.jsxs(Lt,{onClick:se=>{se.stopPropagation(),x(xe)},className:"text-destructive focus:text-destructive",children:[s.jsx(an,{className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},xe.name)})]}),k.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")}),k.map(xe=>{const V=f[xe.name],de=ch(V?.status),Me=i===xe.name,Le=Mo();return s.jsxs("div",{className:me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Me?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Le?void 0:se=>{se.preventDefault(),S(xe.name)},children:[s.jsxs("button",{onClick:()=>{o(xe.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(dh,{tone:de,enabled:xe.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:xe.name}),s.jsx("span",{title:xe.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:xe.type==="local"?s.jsx(ei,{className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(ti,{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:xe.type==="local"?xe.command?.join(" ")??"":xe.url??""})]}),s.jsxs(_s,{open:v===xe.name,onOpenChange:se=>S(se?xe.name:null),children:[s.jsx($s,{asChild:!0,children:s.jsx(ve,{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(la,{className:"h-3.5 w-3.5"})})}),s.jsx(Bs,{align:"end",className:"w-fit min-w-20",children:s.jsxs(Lt,{onClick:se=>{se.stopPropagation(),x(xe)},className:"text-destructive focus:text-destructive",children:[s.jsx(an,{className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},xe.name)})]})]})}),e[63]=a.length,e[64]=f,e[65]=n,e[66]=v,e[67]=I,e[68]=i,e[69]=c,e[70]=o,e[71]=r,e[72]=k,e[73]=we):we=e[73];const W=b!==null;let ue;e[74]!==g?(ue=xe=>{!xe&&!g&&x(null)},e[74]=g,e[75]=ue):ue=e[75];let Y;e[76]!==r?(Y=r("settings.mcp.sidebar.deleteDialog.title"),e[76]=r,e[77]=Y):Y=e[77];let le;e[78]!==Y?(le=s.jsx(js,{children:Y}),e[78]=Y,e[79]=le):le=e[79];const Z=b?.name||"";let Ie;e[80]!==r||e[81]!==Z?(Ie=r("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:Z}),e[80]=r,e[81]=Z,e[82]=Ie):Ie=e[82];let Ne;e[83]===Symbol.for("react.memo_cache_sentinel")?(Ne=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[83]=Ne):Ne=e[83];let X;e[84]!==Ie?(X=s.jsxs(Fs,{children:[Ie," ",Ne,"."]}),e[84]=Ie,e[85]=X):X=e[85];let he;e[86]!==le||e[87]!==X?(he=s.jsxs(Cs,{children:[le,X]}),e[86]=le,e[87]=X,e[88]=he):he=e[88];let je;e[89]===Symbol.for("react.memo_cache_sentinel")?(je=()=>x(null),e[89]=je):je=e[89];let be;e[90]!==r?(be=r("settings.common.actions.cancel"),e[90]=r,e[91]=be):be=e[91];let fe;e[92]!==g||e[93]!==be?(fe=s.jsx(ve,{size:"sm",variant:"ghost",onClick:je,disabled:g,children:be}),e[92]=g,e[93]=be,e[94]=fe):fe=e[94];let Pe;e[95]!==g||e[96]!==r?(Pe=r(g?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[95]=g,e[96]=r,e[97]=Pe):Pe=e[97];let Be;e[98]!==_||e[99]!==g||e[100]!==Pe?(Be=s.jsx(ve,{size:"sm",onClick:_,disabled:g,children:Pe}),e[98]=_,e[99]=g,e[100]=Pe,e[101]=Be):Be=e[101];let G;e[102]!==fe||e[103]!==Be?(G=s.jsxs(Xs,{children:[fe,Be]}),e[102]=fe,e[103]=Be,e[104]=G):G=e[104];let ke;e[105]!==he||e[106]!==G?(ke=s.jsxs(vs,{className:"max-w-md",children:[he,G]}),e[105]=he,e[106]=G,e[107]=ke):ke=e[107];let Ee;e[108]!==W||e[109]!==ue||e[110]!==ke?(Ee=s.jsx(ws,{open:W,onOpenChange:ue,children:ke}),e[108]=W,e[109]=ue,e[110]=ke,e[111]=Ee):Ee=e[111];let Ae;return e[112]!==pe||e[113]!==we||e[114]!==Ee?(Ae=s.jsxs("div",{className:O,children:[pe,we,Ee]}),e[112]=pe,e[113]=we,e[114]=Ee,e[115]=Ae):Ae=e[115],Ae};function F5(t){return{mcpServers:t.mcpServers,selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function O5(t){return t.currentDirectory}function L5(t){return t.refresh}function $5(t){return t.getErrorForDirectory}function B5(t){return t.scope==="project"}function _5(t){return t.scope!=="project"}function V5(t){return setTimeout(t,500)}function ka(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function co(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function Oa(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function ud(t,e,n){const r=z5(n),a=typeof n.url=="string"?n.url.trim():"",i=uh(n,"env","environment"),o=uh(n,"headers"),c=U5(n),d=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientId??"").trim():"",p=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientSecret??"").trim():"",m=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.scope??"").trim():"",u=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.redirectUri??"").trim():"",f=W5(n),y=K5(n);return{ok:!0,name:t,type:e,command:r,url:a,environment:i,headers:o,oauthEnabled:c,oauthClientId:d,oauthClientSecret:p,oauthScope:m,oauthRedirectUri:u,timeout:f,enabled:y}}function z5(t){const e=t.command,n=t.args;if(co(e)&&co(n))return[...e,...n];if(co(e))return e;if(typeof e=="string"&&e.trim()){const r=e.trim().split(/\s+/);return co(n)?[...r,...n]:r}return co(n)?n:[]}function uh(t,...e){for(const n of e){const r=t[n];if(!ka(r))continue;const a=Object.entries(r).filter(([i,o])=>i&&typeof o=="string");if(a.length>0)return a.map(([i,o])=>({key:i,value:String(o)}))}return[]}function U5(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!ka(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 W5(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 K5(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function H5(t){const e=t.mcpServers;if(ka(e)){const r=Object.keys(e);if(r.length===1){const a=r[0],i=e[a];if(ka(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"&&ka(a)});if(n.length===1){const r=n[0],a=t[r];if(Mx(a))return{name:r,entry:a}}return null}function Mx(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function G5(t,e){let n;try{const o=t.trim();if(!o)return Oa("No JSON content provided");n=JSON.parse(o)}catch(o){return Oa(o instanceof Error?`Invalid JSON: ${o.message}`:"Invalid JSON")}if(!ka(n))return Oa("Expected a JSON object, not an array or primitive");const r=n,a=r.mcpServers;if(ka(a)){const o=Object.keys(a);if(o.length===0)return Oa("mcpServers object is empty",n);if(o.length>1)return Oa("Paste one server at a time. Found "+o.length+" servers in mcpServers",n);const c=o[0],d=a[c];return ka(d)?ud(c,md(d),d):Oa("Server entry is not a valid object",n)}const i=H5(r);if(i)return ud(i.name,md(i.entry),i.entry);if(Mx(r)){const o=md(r),c=typeof r.name=="string"&&r.name.trim()?r.name.trim():e?.fallbackName;return ud(c,o,r)}return Oa("No recognizable MCP server configuration found in JSON",n)}function md(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 q5(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 Rx="/mcp/oauth/callback",Q5=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}},Ex=t=>{const e=J5(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}},em=t=>{const e=t.get("state");return typeof e!="string"?null:e.trim()||null},J5=t=>{if(typeof t!="string"||!t.trim())return null;const e=Q5(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 Y5(t){const e=[];let n="",r=!1,a=!1;for(let i=0;i<t.length;i++){const o=t[i];if(o==="'"&&!a){r=!r;continue}if(o==='"'&&!r){a=!a;continue}if((o===" "||o===" ")&&!r&&!a){n&&(e.push(n),n="");continue}n+=o}return n&&e.push(n),e}function X5(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:Ex(n.searchParams),stateKey:em(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const Z5=({value:t,onChange:e,pasteCommandTitle:n,pasteCommandLabel:r,pasteSuccess:a,clipboardReadFailed:i,preview:o})=>{const[c,d]=l.useState(()=>t.join(`
|
|
66
|
+
`)),p=l.useRef(t);l.useEffect(()=>{JSON.stringify(p.current)!==JSON.stringify(t)&&(p.current=t,d(t.join(`
|
|
67
|
+
`)))},[t]);const m=f=>{const y=f.split(`
|
|
68
|
+
`).filter(h=>h.trim().length>0);e(y)},u=async()=>{try{const y=(await navigator.clipboard.readText()).trim(),h=y.includes(`
|
|
69
|
+
`)?y.split(`
|
|
70
|
+
`).filter(b=>b.trim()):Y5(y);d(h.join(`
|
|
71
|
+
`)),e(h),q.success(a(h.length))}catch{q.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(ve,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:u,type:"button",title:n,children:[s.jsx(ni,{className:"h-3 w-3"}),r]})}),s.jsx(An,{value:c,onChange:f=>{d(f.target.value),m(f.target.value)},onBlur:()=>{const f=c.split(`
|
|
72
|
+
`).map(y=>y.trimEnd()).join(`
|
|
73
|
+
`);d(f),m(f)},placeholder:`npx
|
|
74
|
+
-y
|
|
75
|
+
@modelcontextprotocol/server-postgres
|
|
76
|
+
postgresql://user:pass@host/db`,rows:Math.max(4,t.length+1),className:"font-mono typography-meta resize-y min-h-[80px]",spellCheck:!1}),t.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:o(t.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:t.map((f,y)=>s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",y,"]"]}),f]},y))})})]})]})},eC=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),mh=({value:t,onChange:e,keyTransform:n=eC,keyPlaceholder:r="API_KEY",keyInputClassName:a="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:i="Paste .env",pasteTitle:o="Paste KEY=VALUE lines from clipboard",noPairsFoundError:c,importSuccess:d,clipboardReadFailed:p,keyLabel:m,valueLabel:u,valuePlaceholder:f,hideValueTitle:y,showValueTitle:h,addVariable:b,plainTextWarning:x,removeVariableAria:g})=>{const[w,v]=l.useState(new Set),S=()=>e([...t,{key:"",value:""}]),P=k=>{e(t.filter((A,N)=>N!==k)),v(A=>{const N=new Set(A);return N.delete(k),N})},j=(k,A,N)=>{const D=[...t];D[k]={...D[k],[A]:N},e(D)},C=k=>{v(A=>{const N=new Set(A);return N.has(k)?N.delete(k):N.add(k),N})},I=async()=>{try{const k=await navigator.clipboard.readText(),A=[];for(const D of k.split(`
|
|
77
|
+
`)){const T=D.trim();if(!T||T.startsWith("#"))continue;const M=T.indexOf("=");if(M===-1)continue;const $=T.slice(0,M).trim();let F=T.slice(M+1).trim();(F.startsWith('"')&&F.endsWith('"')||F.startsWith("'")&&F.endsWith("'"))&&(F=F.slice(1,-1)),$&&A.push({key:$,value:F})}if(A.length===0){q.error(c);return}const N=[...t];for(const D of A){const T=N.findIndex(M=>M.key===D.key);T!==-1?N[T]=D:N.push(D)}e(N),q.success(d(A.length))}catch{q.error(p)}},R=t.some(k=>k.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(ve,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:I,type:"button",title:o,children:[s.jsx(ni,{className:"h-3 w-3"}),i]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((k,A)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bt,{value:k.key,onChange:N=>j(A,"key",n(N.target.value)),placeholder:r,className:a,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(Bt,{type:w.has(A)?"text":"password",value:k.value,onChange:N=>j(A,"value",N.target.value),placeholder:f,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>C(A),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:w.has(A)?y:h,children:w.has(A)?s.jsx(Ru,{className:"h-3.5 w-3.5"}):s.jsx(Mu,{className:"h-3.5 w-3.5"})})]}),s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>P(A),"aria-label":g,children:s.jsx(an,{className:"h-3.5 w-3.5"})})]},A))}),s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:S,type:"button",children:[s.jsx(zs,{className:"h-3.5 w-3.5"}),b]}),R&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:x})]})},ph=t=>{const e=nt.c(14),{status:n,enabled:r,getStatusLabel:a,variant:i}=t,o=i===void 0?"compact":i;if(!r||!n)return null;let c,d;if(e[0]!==a||e[1]!==n||e[2]!==o){d=Symbol.for("react.early_return_sentinel");e:{const f={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[n]??{text:"text-muted-foreground",bg:""};if(o==="pill"){const y=me("typography-micro font-medium rounded-full px-2 py-0.5",f.text,f.bg);let h;e[5]!==a||e[6]!==n?(h=a(n),e[5]=a,e[6]=n,e[7]=h):h=e[7],d=s.jsxs("span",{className:y,children:["● ",h]});break e}c=me("typography-micro font-medium",f.text)}e[0]=a,e[1]=n,e[2]=o,e[3]=c,e[4]=d}else c=e[3],d=e[4];if(d!==Symbol.for("react.early_return_sentinel"))return d;let p;e[8]!==a||e[9]!==n?(p=a(n),e[8]=a,e[9]=n,e[10]=p):p=e[10];let m;return e[11]!==c||e[12]!==p?(m=s.jsxs("span",{className:c,children:["● ",p]}),e[11]=c,e[12]=p,e[13]=m):m=e[13],m},tC=(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")}},sC=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)]"}},nC=(t,e,n,r)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||n||r),hh=(t,e)=>{if(typeof window>"u")return null;const n=new URL(Rx,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()},rC=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")}},aC=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},uo=async t=>{typeof t!="string"||!t.trim()||await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},pd=(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},iC=(t,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${n}`},oC=()=>{const{t}=ut(),e=l.useCallback((Ue,Dt)=>t(Ue,Dt),[t]),{selectedMcpName:n,mcpServers:r,mcpDraft:a,setMcpDraft:i,setSelectedMcp:o,getMcpByName:c,createMcp:d,updateMcp:p,deleteMcp:m}=Lo(Sr(Ue=>({selectedMcpName:Ue.selectedMcpName,mcpServers:Ue.mcpServers,mcpDraft:Ue.mcpDraft,setMcpDraft:Ue.setMcpDraft,setSelectedMcp:Ue.setSelectedMcp,getMcpByName:Ue.getMcpByName,createMcp:Ue.createMcp,updateMcp:Ue.updateMcp,deleteMcp:Ue.deleteMcp}))),u=qs(Ue=>Ue.currentDirectory),f=l.useMemo(()=>jn(),[]),y=Tn(Ue=>Ue.getStatusForDirectory(u??null)),h=Tn(Ue=>Ue.getDiagnosticForDirectory(u??null)),b=Tn(Ue=>Ue.refresh),x=Tn(Ue=>Ue.connect),g=Tn(Ue=>Ue.disconnect),w=Tn(Ue=>Ue.startAuth),v=Tn(Ue=>Ue.completeAuth),S=Tn(Ue=>Ue.clearAuth),P=Tn(Ue=>Ue.testConnection),j=n?c(n):null,C=!!(a&&a.name===n&&!j),[I,R]=l.useState(""),[k,A]=l.useState("user"),[N,D]=l.useState("local"),[T,M]=l.useState([]),[$,F]=l.useState(""),[_,O]=l.useState([]),[L,K]=l.useState([]),[B,re]=l.useState(!0),[oe,ee]=l.useState(""),[ae,ge]=l.useState(""),[ne,E]=l.useState(""),[z,J]=l.useState(""),[H,te]=l.useState(""),[ce,Se]=l.useState(!0),[pe,we]=l.useState(!1),[W,ue]=l.useState(!1),[Y,le]=l.useState(!1),[Z,Ie]=l.useState(!1),[Ne,X]=l.useState(!1),[he,je]=l.useState(!1),[be,fe]=l.useState(!1),[Pe,Be]=l.useState(!1),[G,ke]=l.useState(null),[Ee,Ae]=l.useState(null),[xe,V]=l.useState(""),[de,Me]=l.useState(!1),Le=l.useRef(0),se=l.useRef(!1),[ie,U]=l.useState(!1),[Ve,He]=l.useState(!1),[Ke,Ze]=l.useState(""),[Xe,dt]=l.useState(null),et=l.useMemo(()=>iC(n,u),[u,n]),ct=l.useRef(et),at=l.useRef(null),ye=l.useCallback(()=>{ke(null),Ae(null),V(""),Me(!1),Le.current=0,Be(!1),X(!1),je(!1),se.current=!1},[]),Ge=l.useCallback(()=>{Ze(""),dt(null),He(!0)},[]),$e=l.useCallback(async()=>{try{const Ue=await navigator.clipboard.readText();Ze(Ue),dt(null)}catch{q.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),_e=l.useCallback(()=>{const Ue=G5(Ke,{fallbackName:I});if(!Ue.ok){dt(Ue.error);return}const Tt=q5(Ue,{name:I,scope:k,type:N,command:T,url:$,environment:_,headers:L,oauthEnabled:B,oauthClientId:oe,oauthClientSecret:ae,oauthScope:ne,oauthRedirectUri:z,timeout:H,enabled:ce},{isNewServer:C});R(Tt.name),D(Tt.type),M(Tt.command??[]),F(Tt.url??""),O(Tt.environment??[]),K(Tt.headers??[]),re(Tt.oauthEnabled??!1),ee(Tt.oauthClientId??""),ge(Tt.oauthClientSecret??""),E(Tt.oauthScope??""),J(Tt.oauthRedirectUri??""),te(Tt.timeout??""),Se(Tt.enabled??!0),He(!1),Ze(""),dt(null),q.success(t("settings.mcp.page.toast.configImported"))},[Ke,I,k,N,T,$,_,L,B,oe,ae,ne,z,H,ce,C,t]);l.useEffect(()=>{if(C&&a){R(a.name),A(a.scope||"user"),D(a.type),M(a.command),F(a.url),O(a.environment),K(a.headers),re(a.oauthEnabled),ee(a.oauthClientId),ge(a.oauthClientSecret),E(a.oauthScope),J(a.oauthRedirectUri),te(a.timeout),Se(a.enabled),U(!1),at.current={mcpType:a.type,command:a.command,url:a.url,envEntries:a.environment,headerEntries:a.headers,oauthEnabled:a.oauthEnabled,oauthClientId:a.oauthClientId,oauthClientSecret:a.oauthClientSecret,oauthScope:a.oauthScope,oauthRedirectUri:a.oauthRedirectUri,timeout:a.timeout,enabled:a.enabled};return}if(j){A(j.scope==="project"?"project":"user");const Ue=ep(j.environment),Dt=j.type==="remote"?j:null,Tt=ep(Dt?.headers),wt=Dt?.oauth,Wt=wt&&typeof wt=="object"?wt:null,_t=wt!==!1,Vs=j.type,mt=Vs==="local"?j.command??[]:[],cs=Vs==="remote"?j.url??"":"",qt=typeof Dt?.timeout=="number"&&Number.isFinite(Dt.timeout)?String(Dt.timeout):"";D(Vs),M(mt),F(cs),O(Ue),K(Tt),re(_t),ee(_t?Wt?.clientId??"":""),ge(_t?Wt?.clientSecret??"":""),E(_t?Wt?.scope??"":""),J(_t?Wt?.redirectUri??"":""),te(qt),Se(j.enabled),U(!1),at.current={mcpType:Vs,command:mt,url:cs,envEntries:Ue,headerEntries:Tt,oauthEnabled:_t,oauthClientId:_t?Wt?.clientId??"":"",oauthClientSecret:_t?Wt?.clientSecret??"":"",oauthScope:_t?Wt?.scope??"":"",oauthRedirectUri:_t?Wt?.redirectUri??"":"",timeout:qt,enabled:j.enabled}}},[j,C,a]);const tt=l.useMemo(()=>{const Ue=at.current;return Ue?N!==Ue.mcpType||ce!==Ue.enabled||JSON.stringify(T)!==JSON.stringify(Ue.command)||$!==Ue.url||JSON.stringify(_)!==JSON.stringify(Ue.envEntries)||JSON.stringify(L)!==JSON.stringify(Ue.headerEntries)||B!==Ue.oauthEnabled||oe!==Ue.oauthClientId||ae!==Ue.oauthClientSecret||ne!==Ue.oauthScope||z!==Ue.oauthRedirectUri||H!==Ue.timeout:!1},[N,T,$,_,L,B,oe,ae,ne,z,H,ce]),Qe=async()=>{const Ue=C?I.trim():n??"";if(!Ue){q.error(t("settings.mcp.page.toast.nameRequired"));return}if(C&&r.some(Tt=>Tt.name===Ue)){q.error(t("settings.mcp.page.toast.serverNameExists"));return}if(N==="local"&&T.filter(Boolean).length===0){q.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(N==="remote"&&!$.trim()){q.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const Dt={name:Ue,scope:k,type:N,command:T,url:$,environment:_,headers:L,oauthEnabled:B,oauthClientId:oe,oauthClientSecret:ae,oauthScope:ne,oauthRedirectUri:z,timeout:H,enabled:ce};we(!0);try{const Tt=C?await d(Dt):await p(Ue,Dt);Tt.ok?(await uo(Ee),ye(),C&&(i(null),o(Ue)),await b({directory:u,silent:!0}),Tt.reloadFailed?q.warning(Tt.message||t(C?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:Tt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):q.success(Tt.message||t(C?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):q.error(t("settings.mcp.page.toast.saveFailed"))}catch(Tt){q.error(Tt instanceof Error?Tt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{we(!1)}},ze=async()=>{if(!n)return;le(!0);const Ue=await m(n);Ue.ok?(await uo(Ee),ye(),Ue.reloadFailed?q.warning(Ue.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:Ue.warning||t("settings.mcp.page.toast.refreshListIfStale")}):q.success(Ue.message||t("settings.mcp.page.toast.serverDeleted",{name:n})),ue(!1)):q.error(t("settings.mcp.page.toast.deleteFailed")),le(!1)},gt=async()=>{if(n){Ie(!0);try{if(y[n]?.status==="connected")await g(n,u),q.success(t("settings.mcp.page.toast.disconnected"));else{await x(n,u),await b({directory:u,silent:!0});const Dt=Tn.getState().getStatusForDirectory(u??null)[n];Dt?.status==="connected"?q.success(t("settings.mcp.page.toast.connected")):Dt?.status==="needs_auth"?q.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Dt?.status==="needs_client_registration"?q.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):Dt?.status==="failed"?q.error(Dt.error||t("settings.mcp.page.toast.connectionFailed")):q.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await b({directory:u,silent:!0})}catch(Ue){q.error(Ue instanceof Error?Ue.message:t("settings.mcp.page.toast.connectionFailed"))}finally{Ie(!1)}}},Vt=l.useCallback(()=>C?(q.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):tt?(q.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[tt,C,t]),Kt=l.useCallback(async(Ue=!1)=>{try{await b({directory:u,silent:Ue})}catch(Dt){Ue||q.error(Dt instanceof Error?Dt.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[u,b,t]);l.useEffect(()=>{Kt(!0)},[Kt]),l.useEffect(()=>{ct.current=et,Ie(!1),fe(!1),ye()},[ye,et]);const Jt=l.useCallback(async()=>{if(!n||N!=="remote"||!Vt())return;X(!0);const Ue=et;let Dt=null;try{const Tt=Tn.getState().getStatusForDirectory(u??null)[n]?.status;se.current=Tt==="needs_auth"||Tt==="needs_client_registration";const wt=hh(n,u);if(!wt)throw new Error(t("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!z.trim()&&!f){const mt=await p(n,{oauthEnabled:B,oauthClientId:oe,oauthClientSecret:ae,oauthScope:ne,oauthRedirectUri:wt});if(!mt.ok)throw new Error(t("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(mt.reloadFailed)throw new Error(mt.warning||mt.message||t("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(ct.current!==Ue)return;J(wt),at.current=at.current?{...at.current,oauthRedirectUri:wt}:at.current}const Wt=await w(n,u),_t=em(new URL(Wt).searchParams);if(_t&&(Dt=_t,await rC({state:_t,name:n,directory:u})),ct.current!==Ue)return;ke(Wt),Ae(_t??null),Me(!0),Le.current=0;const Vs=await mr(Wt);if(ct.current!==Ue)return;Vs?q.message(t(f?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):q.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(Tt){await uo(Dt),ct.current===Ue&&q.error(pd(Tt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{ct.current===Ue&&X(!1)}},[u,f,N,oe,ae,B,z,ne,Vt,et,n,w,t,e,p]),At=l.useCallback(async()=>{if(!n||!Vt())return;je(!0);const Ue=et;try{if(await S(n,u),ct.current!==Ue)return;ke(null),Ae(null),V(""),Me(!1),Le.current=0,await uo(Ee),q.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(Dt){ct.current===Ue&&q.error(pd(Dt,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{ct.current===Ue&&je(!1)}},[Ee,S,u,Vt,et,n,t,e]),jt=l.useCallback(async()=>{if(!G)return;if((await Wn(G)).ok){q.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}q.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[G,t]),ns=l.useCallback(async()=>{const Ue=X5(xe);if(!Ue.code){q.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const Dt=Ue.stateKey?await aC(Ue.stateKey):null,Tt=Ue.context??Dt,wt=Tt?.name??n,Wt=Tt?.directory??u;if(!wt){q.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!Tt&&!Vt())return;Be(!0);const _t=et;try{if(await v(wt,Ue.code,Wt),await uo(Ue.stateKey??Ee),ct.current!==_t)return;V(""),ke(null),Ae(null),Me(!1),Le.current=0,q.success(wt===n?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:wt}))}catch(Vs){ct.current===_t&&q.error(pd(Vs,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{ct.current===_t&&Be(!1)}},[xe,Ee,v,u,Vt,et,n,t,e]),ot=l.useCallback(async()=>{if(!(!n||!Vt())){if(!ce){q.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}fe(!0);try{const Ue=await P(n,u),Dt=Ue.status?.status;Ue.warning?q.warning(Ue.warning):Dt==="connected"?q.success(t("settings.mcp.page.toast.connectionTestSucceeded")):Dt==="needs_auth"?q.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Dt==="needs_client_registration"?q.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):Dt==="failed"?q.error(Ue.status?.error||Ue.error||t("settings.mcp.page.toast.connectionTestFailed")):Ue.error?q.error(Ue.error):q.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(Ue){q.error(Ue instanceof Error?Ue.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{fe(!1)}}},[u,ce,Vt,n,t,P]);if(l.useEffect(()=>{if(!de||!n)return;const Ue=window.setInterval(()=>{(async()=>{Le.current+=1,await b({directory:u,silent:!0});const Dt=Tn.getState().getStatusForDirectory(u??null)[n];if(Dt){if(se.current&&Dt.status!=="needs_auth"&&Dt.status!=="needs_client_registration"){Me(!1),Le.current=0,se.current=!1,ke(null),V(""),Dt.status==="connected"&&q.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!se.current&&Dt.status==="failed"){Me(!1),Le.current=0,se.current=!1,q.error(Dt.error||t("settings.mcp.page.toast.authorizationFailed"));return}Le.current>=30&&(Me(!1),Le.current=0,se.current=!1,q.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(Ue)}},[u,de,b,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(Yf,{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 Zt=y[n],Yt=n?h[n]:void 0,es=Zt??Yt,ls=Zt?.status==="connected",ds=Zt?.status==="needs_auth"||Zt?.status==="needs_client_registration",gs=f?null:hh(n,u),us=tC(es?.status,e,es&&"error"in es?es.error:void 0),Ct=Ue=>{switch(Ue){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 Ue}};return s.jsxs(Ps,{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:[C?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(ph,{status:es?.status,enabled:ce,getStatusLabel:Ct,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:C?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(N==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")})}),!C&&s.jsxs(s.Fragment,{children:[s.jsx(ve,{variant:ls?"outline":"default",size:"xs",className:"!font-normal",onClick:gt,disabled:Z||!ce,children:t(Z?"settings.mcp.page.actions.working":ls?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),N==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(ve,{variant:ds?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{Jt()},disabled:Ne||!ce,children:t(Ne?"settings.mcp.page.actions.starting":ds?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{At()},disabled:he||!ce,children:t(he?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),ls&&s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ot()},disabled:be||!ce,children:t(be?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!C&&nC(es?.status,G,ds,de)&&s.jsx("div",{className:"mb-6 px-2",children:s.jsxs("div",{className:me("rounded-lg border p-3",sC(es?.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(ph,{status:es?.status,enabled:ce,getStatusLabel:Ct})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:us}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:k==="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:!ls&&s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ot()},disabled:be||!ce,children:t(be?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),G&&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:G}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{mr(G)},children:[s.jsx(Pr,{className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{jt()},children:[s.jsx(ni,{className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),N==="remote"&&(ds||de||G)&&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(An,{value:xe,onChange:Ue=>V(Ue.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(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ns()},disabled:Pe,children:t(Pe?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),de&&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:[C&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.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(Bt,{value:I,onChange:Ue=>R(Ue.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(ps,{value:k,onValueChange:Ue=>A(Ue),children:[s.jsx(hs,{className:"!h-7 !w-7 !min-w-0 !px-0 !py-0 justify-center [&>svg:last-child]:hidden",title:t(k==="user"?"settings.common.scope.global":"settings.common.scope.project"),children:k==="user"?s.jsx(Yr,{className:"h-3.5 w-3.5"}):s.jsx(Un,{className:"h-3.5 w-3.5"})}),s.jsxs(fs,{align:"end",children:[s.jsx(Rt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Yr,{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(Un,{className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),C&&s.jsx("div",{className:"py-1.5",children:s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:Ge,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(Cy,{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":ce,onClick:()=>Se(!ce),onKeyDown:Ue=>{(Ue.key===" "||Ue.key==="Enter")&&(Ue.preventDefault(),Se(!ce))},children:[s.jsx(bs,{checked:ce,onChange:Se,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(ve,{variant:"chip",size:"xs","aria-pressed":N==="local",onClick:()=>D("local"),className:"!font-normal",children:t("settings.mcp.page.transport.local")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":N==="remote",onClick:()=>D("remote"),className:"!font-normal",children:t("settings.mcp.page.transport.remote")})]})]})})]})]}),s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t(N==="local"?"settings.mcp.page.connection.command":"settings.mcp.page.connection.serverUrl")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:N==="local"?s.jsx(Z5,{value:T,onChange:M,pasteCommandTitle:t("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:t("settings.mcp.page.connection.pasteCommand"),pasteSuccess:Ue=>t("settings.mcp.page.toast.pastedArgumentsCount",{count:Ue}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),preview:Ue=>t("settings.mcp.page.connection.previewArgs",{count:Ue})}):s.jsx(Bt,{value:$,onChange:Ue=>F(Ue.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"})})]}),N==="remote"&&s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.mcp.page.advanced.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs(wr,{open:ie,onOpenChange:U,children:[s.jsxs(Rr,{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(B?"settings.mcp.page.advanced.autoDetect":"settings.mcp.page.advanced.custom")," · ",L.length," ",t("settings.mcp.page.advanced.headers"),H?` · ${H}ms`:"",")"]})]}),ie?s.jsx(ks,{className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx($n,{className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(jr,{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(Bt,{type:"number",min:"1",step:"1",value:H,onChange:Ue=>te(Ue.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"),L.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",L.length,")"]})]}),s.jsx(mh,{value:L,onChange:K,keyTransform:Ue=>Ue.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:Ue=>t("settings.mcp.page.toast.importedVariablesCount",{count:Ue}),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":B,onClick:()=>re(!B),onKeyDown:Ue=>{(Ue.key===" "||Ue.key==="Enter")&&(Ue.preventDefault(),re(!B))},children:[s.jsx(bs,{checked:B,onChange:re,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(Bt,{value:oe,onChange:Ue=>ee(Ue.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientIdPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Bt,{value:ae,onChange:Ue=>ge(Ue.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientSecretPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Bt,{value:ne,onChange:Ue=>E(Ue.target.value),placeholder:t("settings.mcp.page.advanced.oauthScopesPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Bt,{value:z,onChange:Ue=>J(Ue.target.value),placeholder:t("settings.mcp.page.advanced.oauthRedirectUriPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.advanced.oauthHint")}),gs&&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:gs})]})]})]})})]})})]}),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(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>O([{key:"",value:""}]),children:[s.jsx(zs,{className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(mh,{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:Ue=>t("settings.mcp.page.toast.importedVariablesCount",{count:Ue}),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(ve,{onClick:Qe,disabled:pe||!tt&&!C,size:"xs",className:"!font-normal",children:t(pe?"settings.common.actions.saving":C?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!C&&s.jsx(ve,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ue(!0),children:t("settings.common.actions.delete")})]})]}),s.jsx(ws,{open:Ve,onOpenChange:Ue=>{Ue||(He(!1),Ze(""),dt(null))},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Fs,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(An,{value:Ke,onChange:Ue=>{Ze(Ue.target.value),dt(null)},placeholder:`{
|
|
78
|
+
"mcpServers": {
|
|
79
|
+
"postgres": {
|
|
80
|
+
"command": "npx",
|
|
81
|
+
"args": ["-y", "@modelcontextprotocol/server-postgres"]
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}`,rows:8,className:"font-mono typography-meta resize-y",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),Xe&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:Xe}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:$e,type:"button",children:[s.jsx(ni,{className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(Xs,{children:[s.jsx(ve,{variant:"outline",onClick:()=>{He(!1),Ze(""),dt(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(ve,{onClick:_e,disabled:!Ke.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(ws,{open:W,onOpenChange:Ue=>{!Ue&&!Y&&ue(!1)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("settings.mcp.page.deleteDialog.title",{name:n??""})}),s.jsxs(Fs,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(Xs,{children:[s.jsx(ve,{variant:"outline",onClick:()=>ue(!1),disabled:Y,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(ve,{variant:"destructive",size:"sm",onClick:ze,disabled:Y,children:t(Y?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},lC=t=>{const e=nt.c(150),{onItemSelect:n}=t,{t:r}=ut(),[a,i]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(!1),[f,y]=l.useState(null),{selectedSkillName:h,skills:b,setSelectedSkill:x,setSkillDraft:g,createSkill:w,deleteSkill:v,getSkillDetail:S}=wa(Sr(cC));let P;e[0]!==n||e[1]!==x||e[2]!==g||e[3]!==b?(P=()=>{let $e="new-skill",_e=1;for(;b.some(tt=>tt.name===$e);)$e=`new-skill-${_e}`,_e++;g({name:$e,scope:"user",source:"opencode",description:""}),x($e),n?.()},e[0]=n,e[1]=x,e[2]=g,e[3]=b,e[4]=P):P=e[4];const j=P;let C;e[5]===Symbol.for("react.memo_cache_sentinel")?(C=async $e=>{p($e)},e[5]=C):C=e[5];const I=C;let R;e[6]!==d||e[7]!==v||e[8]!==r?(R=async()=>{if(!d)return;u(!0),await v(d.name)?(q.success(r("settings.skills.sidebar.toast.skillDeleted",{name:d.name})),p(null)):q.error(r("settings.skills.sidebar.toast.deleteSkillFailed")),u(!1)},e[6]=d,e[7]=v,e[8]=r,e[9]=R):R=e[9];const k=R;let A;e[10]!==S||e[11]!==x||e[12]!==g||e[13]!==b||e[14]!==r?(A=async $e=>{const _e=$e.name;let tt=1,Qe=`${_e}-copy`;for(;b.some(gt=>gt.name===Qe);)tt++,Qe=`${_e}-copy-${tt}`;const ze=await S($e.name);if(!ze){q.error(r("settings.skills.sidebar.toast.duplicateLoadFailed"));return}g({name:Qe,scope:$e.scope||"user",source:$e.source||"opencode",description:(ze.sources.md.fields.includes("description"),""),instructions:""}),x(Qe)},e[10]=S,e[11]=x,e[12]=g,e[13]=b,e[14]=r,e[15]=A):A=e[15];const N=A;let D;e[16]===Symbol.for("react.memo_cache_sentinel")?(D=$e=>{c($e.name),i($e)},e[16]=D):D=e[16];const T=D;let M;e[17]!==w||e[18]!==v||e[19]!==S||e[20]!==a||e[21]!==o||e[22]!==x||e[23]!==b||e[24]!==r?(M=async()=>{if(!a)return;const $e=o.trim().replace(/\s+/g,"-").toLowerCase();if(!$e){q.error(r("settings.skills.page.toast.skillNameRequired"));return}if($e===a.name){i(null);return}if(b.some(Qe=>Qe.name===$e)){q.error(r("settings.skills.page.toast.skillExists"));return}if(!await S(a.name)){q.error(r("settings.skills.sidebar.toast.renameLoadFailed")),i(null);return}await w({name:$e,description:"Renamed skill",scope:a.scope,source:a.source})?await v(a.name)?(q.success(`Skill renamed to "${$e}"`),x($e)):q.error(r("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):q.error(r("settings.skills.sidebar.toast.renameFailed")),i(null)},e[17]=w,e[18]=v,e[19]=S,e[20]=a,e[21]=o,e[22]=x,e[23]=b,e[24]=r,e[25]=M):M=e[25];const $=M;let F;e[26]!==b?(F=b.filter(dC),e[26]=b,e[27]=F):F=e[27];const _=F;let O;e[28]!==b?(O=b.filter(uC),e[28]=b,e[29]=O):O=e[29];const L=O;let K;e[30]===Symbol.for("react.memo_cache_sentinel")?(K=function(_e){const tt={},Qe=[];for(const gt of _e)gt.group?(tt[gt.group]||(tt[gt.group]=[]),tt[gt.group].push(gt)):Qe.push(gt);const ze=Object.keys(tt).sort(mC).map(gt=>({name:gt,skills:[...tt[gt]].sort(pC)}));return Qe.sort(hC),{sortedGroups:ze,ungrouped:Qe}},e[30]=K):K=e[30];const B=K;let re;e[31]!==_?(re=B(_),e[31]=_,e[32]=re):re=e[32];const oe=re;let ee;e[33]!==L?(ee=B(L),e[33]=L,e[34]=ee):ee=e[34];const ae=ee;let ge;e[35]===Symbol.for("react.memo_cache_sentinel")?(ge=me("flex h-full flex-col","bg-background"),e[35]=ge):ge=e[35];let ne;e[36]!==r?(ne=r("settings.skills.sidebar.title"),e[36]=r,e[37]=ne):ne=e[37];let E;e[38]!==ne?(E=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:ne}),e[38]=ne,e[39]=E):E=e[39];let z;e[40]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(Qo,{className:"mb-3"}),e[40]=z):z=e[40];let J;e[41]!==b.length||e[42]!==r?(J=r("settings.skills.sidebar.total",{count:b.length}),e[41]=b.length,e[42]=r,e[43]=J):J=e[43];let H;e[44]!==J?(H=s.jsx("span",{className:"typography-meta text-muted-foreground",children:J}),e[44]=J,e[45]=H):H=e[45];let te;e[46]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx(zs,{className:"h-3.5 w-3.5"}),e[46]=te):te=e[46];let ce;e[47]!==j?(ce=s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:te}),e[47]=j,e[48]=ce):ce=e[48];let Se;e[49]!==H||e[50]!==ce?(Se=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[H,ce]}),e[49]=H,e[50]=ce,e[51]=Se):Se=e[51];let pe;e[52]!==E||e[53]!==Se?(pe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[E,z,Se]}),e[52]=E,e[53]=Se,e[54]=pe):pe=e[54];let we;e[55]!==oe||e[56]!==ae||e[57]!==N||e[58]!==n||e[59]!==f||e[60]!==_||e[61]!==h||e[62]!==x||e[63]!==b.length||e[64]!==r||e[65]!==L?(we=s.jsx(Ps,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:b.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(Fu,{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")}),oe.sortedGroups.map($e=>{const{name:_e,skills:tt}=$e;return s.jsx(iu,{label:_e,count:tt.length,storageKey:"project-skills",children:tt.map(Qe=>s.jsx(gl,{skill:Qe,isSelected:h===Qe.name,onSelect:()=>{x(Qe.name),n?.()},onRename:()=>T(Qe),onDelete:()=>I(Qe),onDuplicate:()=>N(Qe),isMenuOpen:f===Qe.name,onMenuOpenChange:ze=>y(ze?Qe.name:null)},Qe.name))},_e)}),oe.ungrouped.map($e=>s.jsx(gl,{skill:$e,isSelected:h===$e.name,onSelect:()=>{x($e.name),n?.()},onRename:()=>T($e),onDelete:()=>I($e),onDuplicate:()=>N($e),isMenuOpen:f===$e.name,onMenuOpenChange:_e=>y(_e?$e.name:null)},$e.name))]}),L.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")}),ae.sortedGroups.map($e=>{const{name:_e,skills:tt}=$e;return s.jsx(iu,{label:_e,count:tt.length,storageKey:"user-skills",children:tt.map(Qe=>s.jsx(gl,{skill:Qe,isSelected:h===Qe.name,onSelect:()=>{x(Qe.name),n?.()},onRename:()=>T(Qe),onDelete:()=>I(Qe),onDuplicate:()=>N(Qe),isMenuOpen:f===Qe.name,onMenuOpenChange:ze=>y(ze?Qe.name:null)},Qe.name))},_e)}),ae.ungrouped.map($e=>s.jsx(gl,{skill:$e,isSelected:h===$e.name,onSelect:()=>{x($e.name),n?.()},onRename:()=>T($e),onDelete:()=>I($e),onDuplicate:()=>N($e),isMenuOpen:f===$e.name,onMenuOpenChange:_e=>y(_e?$e.name:null)},$e.name))]})]})}),e[55]=oe,e[56]=ae,e[57]=N,e[58]=n,e[59]=f,e[60]=_,e[61]=h,e[62]=x,e[63]=b.length,e[64]=r,e[65]=L,e[66]=we):we=e[66];const W=d!==null;let ue;e[67]!==m?(ue=$e=>{!$e&&!m&&p(null)},e[67]=m,e[68]=ue):ue=e[68];let Y;e[69]!==r?(Y=r("settings.skills.sidebar.deleteDialog.title"),e[69]=r,e[70]=Y):Y=e[70];let le;e[71]!==Y?(le=s.jsx(js,{children:Y}),e[71]=Y,e[72]=le):le=e[72];const Z=d?.name??"";let Ie;e[73]!==r||e[74]!==Z?(Ie=r("settings.skills.sidebar.deleteDialog.description",{name:Z}),e[73]=r,e[74]=Z,e[75]=Ie):Ie=e[75];let Ne;e[76]!==Ie?(Ne=s.jsx(Fs,{children:Ie}),e[76]=Ie,e[77]=Ne):Ne=e[77];let X;e[78]!==le||e[79]!==Ne?(X=s.jsxs(Cs,{children:[le,Ne]}),e[78]=le,e[79]=Ne,e[80]=X):X=e[80];let he;e[81]===Symbol.for("react.memo_cache_sentinel")?(he=()=>p(null),e[81]=he):he=e[81];let je;e[82]!==r?(je=r("settings.common.actions.cancel"),e[82]=r,e[83]=je):je=e[83];let be;e[84]!==m||e[85]!==je?(be=s.jsx(ve,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:he,disabled:m,children:je}),e[84]=m,e[85]=je,e[86]=be):be=e[86];let fe;e[87]!==r?(fe=r("settings.common.actions.delete"),e[87]=r,e[88]=fe):fe=e[88];let Pe;e[89]!==k||e[90]!==m||e[91]!==fe?(Pe=s.jsx(ve,{size:"sm",onClick:k,disabled:m,children:fe}),e[89]=k,e[90]=m,e[91]=fe,e[92]=Pe):Pe=e[92];let Be;e[93]!==be||e[94]!==Pe?(Be=s.jsxs(Xs,{children:[be,Pe]}),e[93]=be,e[94]=Pe,e[95]=Be):Be=e[95];let G;e[96]!==X||e[97]!==Be?(G=s.jsxs(vs,{className:"max-w-md",children:[X,Be]}),e[96]=X,e[97]=Be,e[98]=G):G=e[98];let ke;e[99]!==W||e[100]!==ue||e[101]!==G?(ke=s.jsx(ws,{open:W,onOpenChange:ue,children:G}),e[99]=W,e[100]=ue,e[101]=G,e[102]=ke):ke=e[102];const Ee=a!==null;let Ae;e[103]===Symbol.for("react.memo_cache_sentinel")?(Ae=$e=>!$e&&i(null),e[103]=Ae):Ae=e[103];let xe;e[104]!==r?(xe=r("settings.skills.sidebar.renameDialog.title"),e[104]=r,e[105]=xe):xe=e[105];let V;e[106]!==xe?(V=s.jsx(js,{children:xe}),e[106]=xe,e[107]=V):V=e[107];const de=a?.name??"";let Me;e[108]!==r||e[109]!==de?(Me=r("settings.skills.sidebar.renameDialog.description",{name:de}),e[108]=r,e[109]=de,e[110]=Me):Me=e[110];let Le;e[111]!==Me?(Le=s.jsx(Fs,{children:Me}),e[111]=Me,e[112]=Le):Le=e[112];let se;e[113]!==V||e[114]!==Le?(se=s.jsxs(Cs,{children:[V,Le]}),e[113]=V,e[114]=Le,e[115]=se):se=e[115];let ie;e[116]===Symbol.for("react.memo_cache_sentinel")?(ie=$e=>c($e.target.value),e[116]=ie):ie=e[116];let U;e[117]!==r?(U=r("settings.skills.sidebar.renameDialog.placeholder"),e[117]=r,e[118]=U):U=e[118];let Ve;e[119]!==$?(Ve=$e=>{$e.key==="Enter"&&$()},e[119]=$,e[120]=Ve):Ve=e[120];let He;e[121]!==o||e[122]!==U||e[123]!==Ve?(He=s.jsx(Bt,{value:o,onChange:ie,placeholder:U,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Ve}),e[121]=o,e[122]=U,e[123]=Ve,e[124]=He):He=e[124];let Ke;e[125]===Symbol.for("react.memo_cache_sentinel")?(Ke=()=>i(null),e[125]=Ke):Ke=e[125];let Ze;e[126]!==r?(Ze=r("settings.common.actions.cancel"),e[126]=r,e[127]=Ze):Ze=e[127];let Xe;e[128]!==Ze?(Xe=s.jsx(ve,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Ke,children:Ze}),e[128]=Ze,e[129]=Xe):Xe=e[129];let dt;e[130]!==r?(dt=r("settings.common.actions.rename"),e[130]=r,e[131]=dt):dt=e[131];let et;e[132]!==$||e[133]!==dt?(et=s.jsx(ve,{size:"sm",onClick:$,children:dt}),e[132]=$,e[133]=dt,e[134]=et):et=e[134];let ct;e[135]!==Xe||e[136]!==et?(ct=s.jsxs(Xs,{children:[Xe,et]}),e[135]=Xe,e[136]=et,e[137]=ct):ct=e[137];let at;e[138]!==se||e[139]!==He||e[140]!==ct?(at=s.jsxs(vs,{children:[se,He,ct]}),e[138]=se,e[139]=He,e[140]=ct,e[141]=at):at=e[141];let ye;e[142]!==Ee||e[143]!==at?(ye=s.jsx(ws,{open:Ee,onOpenChange:Ae,children:at}),e[142]=Ee,e[143]=at,e[144]=ye):ye=e[144];let Ge;return e[145]!==pe||e[146]!==we||e[147]!==ke||e[148]!==ye?(Ge=s.jsxs("div",{className:ge,children:[pe,we,ke,ye]}),e[145]=pe,e[146]=we,e[147]=ke,e[148]=ye,e[149]=Ge):Ge=e[149],Ge},gl=t=>{const e=nt.c(63),{skill:n,isSelected:r,onSelect:a,onDelete:i,onRename:o,onDuplicate:c,isMenuOpen:d,onMenuOpenChange:p}=t,{t:m}=ut();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=Mo(),e[0]=u):u=e[0];const f=u,y=r?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[1]!==y?(h=me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",y),e[1]=y,e[2]=h):h=e[2];let b;e[3]!==p?(b=f?void 0:re=>{re.preventDefault(),p(!0)},e[3]=p,e[4]=b):b=e[4];let x;e[5]!==n.name?(x=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=x):x=e[6];let g;e[7]!==n.scope?(g=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:n.scope}),e[7]=n.scope,e[8]=g):g=e[8];let w;e[9]!==n.source||e[10]!==m?(w=n.source==="claude"&&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:m("settings.skills.sidebar.badge.claude")}),e[9]=n.source,e[10]=m,e[11]=w):w=e[11];let v;e[12]!==n.source||e[13]!==m?(v=n.source==="agents"&&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:m("settings.skills.sidebar.badge.agents")}),e[12]=n.source,e[13]=m,e[14]=v):v=e[14];let S;e[15]!==x||e[16]!==g||e[17]!==w||e[18]!==v?(S=s.jsxs("div",{className:"flex items-center gap-1.5",children:[x,g,w,v]}),e[15]=x,e[16]=g,e[17]=w,e[18]=v,e[19]=S):S=e[19];let P;e[20]!==a||e[21]!==S?(P=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:S}),e[20]=a,e[21]=S,e[22]=P):P=e[22];let j;e[23]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx($s,{asChild:!0,children:s.jsx(ve,{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(la,{className:"h-3.5 w-3.5"})})}),e[23]=j):j=e[23];let C;e[24]!==o?(C=re=>{re.stopPropagation(),o()},e[24]=o,e[25]=C):C=e[25];let I;e[26]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(ea,{className:"h-4 w-4 mr-px"}),e[26]=I):I=e[26];let R;e[27]!==m?(R=m("settings.common.actions.rename"),e[27]=m,e[28]=R):R=e[28];let k;e[29]!==C||e[30]!==R?(k=s.jsxs(Lt,{onClick:C,children:[I,R]}),e[29]=C,e[30]=R,e[31]=k):k=e[31];let A;e[32]!==c?(A=re=>{re.stopPropagation(),c()},e[32]=c,e[33]=A):A=e[33];let N;e[34]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(vr,{className:"h-4 w-4 mr-px"}),e[34]=N):N=e[34];let D;e[35]!==m?(D=m("settings.common.actions.duplicate"),e[35]=m,e[36]=D):D=e[36];let T;e[37]!==A||e[38]!==D?(T=s.jsxs(Lt,{onClick:A,children:[N,D]}),e[37]=A,e[38]=D,e[39]=T):T=e[39];let M;e[40]!==i?(M=re=>{re.stopPropagation(),i()},e[40]=i,e[41]=M):M=e[41];let $;e[42]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(an,{className:"h-4 w-4 mr-px"}),e[42]=$):$=e[42];let F;e[43]!==m?(F=m("settings.common.actions.delete"),e[43]=m,e[44]=F):F=e[44];let _;e[45]!==M||e[46]!==F?(_=s.jsxs(Lt,{onClick:M,className:"text-destructive focus:text-destructive",children:[$,F]}),e[45]=M,e[46]=F,e[47]=_):_=e[47];let O;e[48]!==k||e[49]!==T||e[50]!==_?(O=s.jsxs(Bs,{align:"end",className:"w-fit min-w-20",children:[k,T,_]}),e[48]=k,e[49]=T,e[50]=_,e[51]=O):O=e[51];let L;e[52]!==d||e[53]!==p||e[54]!==O?(L=s.jsxs(_s,{open:d,onOpenChange:p,children:[j,O]}),e[52]=d,e[53]=p,e[54]=O,e[55]=L):L=e[55];let K;e[56]!==P||e[57]!==L?(K=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[P,L]}),e[56]=P,e[57]=L,e[58]=K):K=e[58];let B;return e[59]!==K||e[60]!==h||e[61]!==b?(B=s.jsx("div",{className:h,onContextMenu:b,children:K}),e[59]=K,e[60]=h,e[61]=b,e[62]=B):B=e[62],B};function cC(t){return{selectedSkillName:t.selectedSkillName,skills:t.skills,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,createSkill:t.createSkill,deleteSkill:t.deleteSkill,getSkillDetail:t.getSkillDetail}}function dC(t){return t.scope==="project"}function uC(t){return t.scope==="user"}function mC(t,e){return t.localeCompare(e)}function pC(t,e){return t.name.localeCompare(e.name)}function hC(t,e){return t.name.localeCompare(e.name)}const fC=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,gC=t=>{const e=t.trim(),n=e.match(/^git@github\.com:([^/\s]+)\/([^\s#]+)$/i);if(n)return`${n[1]}/${n[2].replace(/\.git$/i,"")}`;const r=e.match(/^https?:\/\/github\.com\/([^/\s]+)\/([^\s#]+)$/i);if(r)return`${r[1]}/${r[2].replace(/\.git$/i,"")}`;const a=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return a?`${a[1]}/${a[2].replace(/\.git$/i,"")}`:e},xC=async()=>{try{const t=yr()?.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}},bC=t=>{const e=nt.c(158),{open:n,onOpenChange:r}=t,{t:a}=ut(),i=Qa(yC),o=Qa(vC),c=Qa(wC),d=ar(jC),p=ar(NC),[m,u]=l.useState(""),[f,y]=l.useState(""),[h,b]=l.useState("");let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=[],e[0]=x):x=e[0];const[g,w]=l.useState(x),[v,S]=l.useState(null),[P,j]=l.useState(!1);let C;e[1]===Symbol.for("react.memo_cache_sentinel")?(C=[],e[1]=C):C=e[1];const[I,R]=l.useState(C),[k,A]=l.useState(null),N=l.useRef(0);let D;e[2]===Symbol.for("react.memo_cache_sentinel")?(D=ye=>{N.current=N.current+1,j(!1),S(null),ye?.clearIdentity&&(R([]),A(null))},e[2]=D):D=e[2];const T=D;let M,$;e[3]!==p||e[4]!==n?(M=()=>{n&&(N.current=N.current+1,u(""),y(""),b(""),S(null),j(!1),R([]),A(null),p(),(async()=>{const ye=await xC(),Ge=Array.isArray(ye?.skillCatalogs)?ye?.skillCatalogs:[];w(Ge||[])})())},$=[n,p],e[3]=p,e[4]=n,e[5]=M,e[6]=$):(M=e[5],$=e[6]),l.useEffect(M,$);let F;e[7]!==f?(F=f.trim(),e[7]=f,e[8]=F):F=e[8];const _=F;let O;e[9]!==h?(O=h.trim(),e[9]=h,e[10]=O):O=e[10];const L=O;let K;if(e[11]!==g||e[12]!==_||e[13]!==L){let ye;e[15]!==_||e[16]!==L?(ye=Ge=>{const $e=(Ge.source||"").trim(),_e=(Ge.subpath||"").trim();return $e===_&&_e===L},e[15]=_,e[16]=L,e[17]=ye):ye=e[17],K=g.some(ye),e[11]=g,e[12]=_,e[13]=L,e[14]=K}else K=e[14];const B=K;let re;e[18]!==d||e[19]!==k||e[20]!==m||e[21]!==i||e[22]!==f||e[23]!==h||e[24]!==a?(re=async()=>{const ye=f.trim();if(!ye){q.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||u(gC(ye)),j(!1),S(null);const Ge=N.current+1;N.current=Ge;const $e=await i({source:ye,subpath:h.trim()||void 0,gitIdentityId:k||void 0});if(N.current!==Ge)return;if(!$e.ok){if($e.error?.kind==="authRequired"){if(jn()){q.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const tt=$e.error.identities||[];if(R(tt),!k&&tt.length>0){const Qe=d&&d!=="global"&&tt.some(ze=>ze.id===d)?d:tt[0].id;A(Qe)}q.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}q.error($e.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const _e=$e.items?.length||0;if(S(_e),_e===0){q.error(a("settings.skills.catalog.add.toast.noSkillsFound")),j(!1);return}R([]),j(!0),q.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:_e}))},e[18]=d,e[19]=k,e[20]=m,e[21]=i,e[22]=f,e[23]=h,e[24]=a,e[25]=re):re=e[25];const oe=re;let ee;e[26]!==g||e[27]!==k||e[28]!==B||e[29]!==m||e[30]!==o||e[31]!==r||e[32]!==P||e[33]!==f||e[34]!==h||e[35]!==a?(ee=async()=>{const ye=m.trim(),Ge=f.trim(),$e=h.trim();if(!ye){q.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!Ge){q.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!P){q.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(B){q.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const _e={id:fC(),label:ye,source:Ge,...$e?{subpath:$e}:{},...k?{gitIdentityId:k}:{}},tt=[...g,_e];try{await As({skillCatalogs:tt}),w(tt),q.success(a("settings.skills.catalog.add.toast.catalogAdded")),await o({refresh:!0}),r(!1)}catch(Qe){const ze=Qe;q.error(ze instanceof Error?ze.message:a("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=g,e[27]=k,e[28]=B,e[29]=m,e[30]=o,e[31]=r,e[32]=P,e[33]=f,e[34]=h,e[35]=a,e[36]=ee):ee=e[36];const ae=ee;let ge;e[37]!==a?(ge=a("settings.skills.catalog.add.title"),e[37]=a,e[38]=ge):ge=e[38];let ne;e[39]!==ge?(ne=s.jsx(js,{children:ge}),e[39]=ge,e[40]=ne):ne=e[40];let E;e[41]!==a?(E=a("settings.skills.catalog.add.descriptionPrefix"),e[41]=a,e[42]=E):E=e[42];let z;e[43]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[43]=z):z=e[43];let J;e[44]!==a?(J=a("settings.skills.catalog.add.descriptionSuffix"),e[44]=a,e[45]=J):J=e[45];let H;e[46]!==E||e[47]!==J?(H=s.jsxs(Fs,{children:[E," ",z,J]}),e[46]=E,e[47]=J,e[48]=H):H=e[48];let te;e[49]!==ne||e[50]!==H?(te=s.jsxs(Cs,{children:[ne,H]}),e[49]=ne,e[50]=H,e[51]=te):te=e[51];let ce;e[52]!==a?(ce=a("settings.skills.catalog.add.field.catalogName"),e[52]=a,e[53]=ce):ce=e[53];let Se;e[54]!==ce?(Se=s.jsx("label",{className:"typography-ui-label text-foreground",children:ce}),e[54]=ce,e[55]=Se):Se=e[55];let pe;e[56]===Symbol.for("react.memo_cache_sentinel")?(pe=ye=>u(ye.target.value),e[56]=pe):pe=e[56];let we;e[57]!==a?(we=a("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[57]=a,e[58]=we):we=e[58];let W;e[59]!==m||e[60]!==we?(W=s.jsx(Bt,{value:m,onChange:pe,placeholder:we}),e[59]=m,e[60]=we,e[61]=W):W=e[61];let ue;e[62]!==Se||e[63]!==W?(ue=s.jsxs("div",{className:"space-y-2",children:[Se,W]}),e[62]=Se,e[63]=W,e[64]=ue):ue=e[64];let Y;e[65]!==a?(Y=a("settings.skills.catalog.add.field.repository"),e[65]=a,e[66]=Y):Y=e[66];let le;e[67]!==Y?(le=s.jsx("label",{className:"typography-ui-label text-foreground",children:Y}),e[67]=Y,e[68]=le):le=e[68];let Z;e[69]===Symbol.for("react.memo_cache_sentinel")?(Z=ye=>{y(ye.target.value),T({clearIdentity:!0})},e[69]=Z):Z=e[69];let Ie;e[70]!==a?(Ie=a("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[70]=a,e[71]=Ie):Ie=e[71];let Ne;e[72]!==f||e[73]!==Ie?(Ne=s.jsx(Bt,{value:f,onChange:Z,placeholder:Ie}),e[72]=f,e[73]=Ie,e[74]=Ne):Ne=e[74];let X;e[75]!==a?(X=a("settings.skills.catalog.add.field.repositoryHint"),e[75]=a,e[76]=X):X=e[76];let he;e[77]!==X?(he=s.jsx("p",{className:"typography-micro text-muted-foreground",children:X}),e[77]=X,e[78]=he):he=e[78];let je;e[79]!==le||e[80]!==Ne||e[81]!==he?(je=s.jsxs("div",{className:"space-y-2",children:[le,Ne,he]}),e[79]=le,e[80]=Ne,e[81]=he,e[82]=je):je=e[82];let be;e[83]!==a?(be=a("settings.skills.catalog.add.field.optionalSubpath"),e[83]=a,e[84]=be):be=e[84];let fe;e[85]!==be?(fe=s.jsx("label",{className:"typography-ui-label text-foreground",children:be}),e[85]=be,e[86]=fe):fe=e[86];let Pe;e[87]===Symbol.for("react.memo_cache_sentinel")?(Pe=ye=>{b(ye.target.value),T({clearIdentity:!0})},e[87]=Pe):Pe=e[87];let Be;e[88]!==a?(Be=a("settings.skills.catalog.shared.field.subpathPlaceholder"),e[88]=a,e[89]=Be):Be=e[89];let G;e[90]!==h||e[91]!==Be?(G=s.jsx(Bt,{value:h,onChange:Pe,placeholder:Be}),e[90]=h,e[91]=Be,e[92]=G):G=e[92];let ke;e[93]!==fe||e[94]!==G?(ke=s.jsxs("div",{className:"space-y-2",children:[fe,G]}),e[93]=fe,e[94]=G,e[95]=ke):ke=e[95];let Ee;e[96]!==k||e[97]!==I||e[98]!==a?(Ee=I.length>0&&!jn()?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(ps,{value:k||"",onValueChange:ye=>{A(ye),T()},children:[s.jsx(hs,{className:"w-fit",children:s.jsx("span",{children:I.find(ye=>ye.id===k)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(fs,{align:"start",children:I.map(SC)})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[96]=k,e[97]=I,e[98]=a,e[99]=Ee):Ee=e[99];let Ae;e[100]!==v||e[101]!==a?(Ae=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]=Ae):Ae=e[102];let xe;e[103]!==B||e[104]!==a?(xe=B?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null,e[103]=B,e[104]=a,e[105]=xe):xe=e[105];let V;e[106]!==ue||e[107]!==je||e[108]!==ke||e[109]!==Ee||e[110]!==Ae||e[111]!==xe?(V=s.jsxs("div",{className:"space-y-4",children:[ue,je,ke,Ee,Ae,xe]}),e[106]=ue,e[107]=je,e[108]=ke,e[109]=Ee,e[110]=Ae,e[111]=xe,e[112]=V):V=e[112];let de;e[113]!==r?(de=()=>r(!1),e[113]=r,e[114]=de):de=e[114];let Me;e[115]!==a?(Me=a("settings.common.actions.cancel"),e[115]=a,e[116]=Me):Me=e[116];let Le;e[117]!==de||e[118]!==Me?(Le=s.jsx(ve,{size:"sm",variant:"ghost",onClick:de,children:Me}),e[117]=de,e[118]=Me,e[119]=Le):Le=e[119];let se;e[120]!==oe?(se=()=>{oe()},e[120]=oe,e[121]=se):se=e[121];let ie;e[122]!==c||e[123]!==f?(ie=c||!f.trim(),e[122]=c,e[123]=f,e[124]=ie):ie=e[124];let U;e[125]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(Fd,{className:"h-4 w-4"}),e[125]=U):U=e[125];let Ve;e[126]!==c||e[127]!==a?(Ve=a(c?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[126]=c,e[127]=a,e[128]=Ve):Ve=e[128];let He;e[129]!==se||e[130]!==ie||e[131]!==Ve?(He=s.jsxs(ve,{size:"sm",className:"gap-2",variant:"ghost",onClick:se,disabled:ie,children:[U,Ve]}),e[129]=se,e[130]=ie,e[131]=Ve,e[132]=He):He=e[132];let Ke;e[133]!==ae?(Ke=()=>{ae()},e[133]=ae,e[134]=Ke):Ke=e[134];let Ze;e[135]!==B||e[136]!==m||e[137]!==P||e[138]!==f?(Ze=!P||B||!m.trim()||!f.trim(),e[135]=B,e[136]=m,e[137]=P,e[138]=f,e[139]=Ze):Ze=e[139];let Xe;e[140]!==a?(Xe=a("settings.skills.catalog.add.actions.addCatalog"),e[140]=a,e[141]=Xe):Xe=e[141];let dt;e[142]!==Ke||e[143]!==Ze||e[144]!==Xe?(dt=s.jsx(ve,{size:"sm",onClick:Ke,disabled:Ze,children:Xe}),e[142]=Ke,e[143]=Ze,e[144]=Xe,e[145]=dt):dt=e[145];let et;e[146]!==Le||e[147]!==He||e[148]!==dt?(et=s.jsxs(Xs,{children:[Le,He,dt]}),e[146]=Le,e[147]=He,e[148]=dt,e[149]=et):et=e[149];let ct;e[150]!==te||e[151]!==V||e[152]!==et?(ct=s.jsxs(vs,{className:"max-w-xl",children:[te,V,et]}),e[150]=te,e[151]=V,e[152]=et,e[153]=ct):ct=e[153];let at;return e[154]!==r||e[155]!==n||e[156]!==ct?(at=s.jsx(ws,{open:n,onOpenChange:r,children:ct}),e[154]=r,e[155]=n,e[156]=ct,e[157]=at):at=e[157],at};function yC(t){return t.scanRepo}function vC(t){return t.loadCatalog}function wC(t){return t.isScanning}function jC(t){return t.defaultGitIdentityId}function NC(t){return t.loadDefaultGitIdentityId}function SC(t){return s.jsx(Rt,{value:t.id,children:t.name},t.id)}const kC=t=>{const e=nt.c(85),{open:n,onOpenChange:r,conflicts:a,onConfirm:i}=t,{t:o}=ut();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={},e[0]=c):c=e[0];const[d,p]=l.useState(c);let m,u;e[1]!==a||e[2]!==n?(m=()=>{if(!n)return;const ne={};for(const E of a)ne[E.skillName]="skip";p(ne)},u=[n,a],e[1]=a,e[2]=n,e[3]=m,e[4]=u):(m=e[3],u=e[4]),l.useEffect(m,u);let f;e[5]!==a?(f=ne=>{const E={};for(const z of a)E[z.skillName]=ne;p(E)},e[5]=a,e[6]=f):f=e[6];const y=f;let h;e[7]!==a||e[8]!==d?(h=a.length>0&&a.every(ne=>d[ne.skillName]),e[7]=a,e[8]=d,e[9]=h):h=e[9];const b=h;let x;e[10]!==o?(x=o("settings.skills.catalog.conflicts.title"),e[10]=o,e[11]=x):x=e[11];let g;e[12]!==x?(g=s.jsx(js,{children:x}),e[12]=x,e[13]=g):g=e[13];let w;e[14]!==o?(w=o("settings.skills.catalog.conflicts.description"),e[14]=o,e[15]=w):w=e[15];let v;e[16]!==w?(v=s.jsx(Fs,{children:w}),e[16]=w,e[17]=v):v=e[17];let S;e[18]!==g||e[19]!==v?(S=s.jsxs(Cs,{children:[g,v]}),e[18]=g,e[19]=v,e[20]=S):S=e[20];let P;e[21]!==a.length||e[22]!==o?(P=o("settings.skills.catalog.conflicts.count",{count:a.length}),e[21]=a.length,e[22]=o,e[23]=P):P=e[23];let j;e[24]!==P?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:P}),e[24]=P,e[25]=j):j=e[25];let C;e[26]!==y?(C=()=>y("skip"),e[26]=y,e[27]=C):C=e[27];let I;e[28]!==o?(I=o("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=o,e[29]=I):I=e[29];let R;e[30]!==C||e[31]!==I?(R=s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:C,children:I}),e[30]=C,e[31]=I,e[32]=R):R=e[32];let k;e[33]!==y?(k=()=>y("overwrite"),e[33]=y,e[34]=k):k=e[34];let A;e[35]!==o?(A=o("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=o,e[36]=A):A=e[36];let N;e[37]!==k||e[38]!==A?(N=s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:k,children:A}),e[37]=k,e[38]=A,e[39]=N):N=e[39];let D;e[40]!==R||e[41]!==N?(D=s.jsxs("div",{className:"flex items-center gap-2",children:[R,N]}),e[40]=R,e[41]=N,e[42]=D):D=e[42];let T;e[43]!==j||e[44]!==D?(T=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,D]}),e[43]=j,e[44]=D,e[45]=T):T=e[45];let M;if(e[46]!==a||e[47]!==d||e[48]!==o){let ne;e[50]!==d||e[51]!==o?(ne=E=>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:E.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:o("settings.skills.catalog.conflicts.installedIn",{scope:E.scope==="project"?o("settings.skills.catalog.conflicts.scope.project"):o("settings.skills.catalog.conflicts.scope.user"),source:E.source==="agents"?o("settings.skills.catalog.conflicts.source.agents"):o("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(ps,{value:d[E.skillName]||"skip",onValueChange:z=>p(J=>({...J,[E.skillName]:z})),children:[s.jsx(hs,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(d[E.skillName]||"skip")==="overwrite"?o("settings.skills.catalog.conflicts.decision.overwrite"):o("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(fs,{align:"end",children:[s.jsx(Rt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(Rt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},E.skillName),e[50]=d,e[51]=o,e[52]=ne):ne=e[52],M=a.map(ne),e[46]=a,e[47]=d,e[48]=o,e[49]=M}else M=e[49];let $;e[53]!==M?($=s.jsx("div",{className:"space-y-2",children:M}),e[53]=M,e[54]=$):$=e[54];let F;e[55]!==T||e[56]!==$?(F=s.jsxs("div",{className:"space-y-3",children:[T,$]}),e[55]=T,e[56]=$,e[57]=F):F=e[57];let _;e[58]!==r?(_=()=>r(!1),e[58]=r,e[59]=_):_=e[59];let O;e[60]!==o?(O=o("settings.common.actions.cancel"),e[60]=o,e[61]=O):O=e[61];let L;e[62]!==_||e[63]!==O?(L=s.jsx(ve,{size:"sm",variant:"ghost",onClick:_,children:O}),e[62]=_,e[63]=O,e[64]=L):L=e[64];let K;e[65]!==d||e[66]!==i?(K=()=>i(d),e[65]=d,e[66]=i,e[67]=K):K=e[67];const B=!b;let re;e[68]!==o?(re=o("settings.skills.catalog.conflicts.actions.continue"),e[68]=o,e[69]=re):re=e[69];let oe;e[70]!==K||e[71]!==B||e[72]!==re?(oe=s.jsx(ve,{size:"sm",onClick:K,disabled:B,children:re}),e[70]=K,e[71]=B,e[72]=re,e[73]=oe):oe=e[73];let ee;e[74]!==L||e[75]!==oe?(ee=s.jsxs(Xs,{children:[L,oe]}),e[74]=L,e[75]=oe,e[76]=ee):ee=e[76];let ae;e[77]!==S||e[78]!==F||e[79]!==ee?(ae=s.jsxs(vs,{className:"max-w-2xl",children:[S,F,ee]}),e[77]=S,e[78]=F,e[79]=ee,e[80]=ae):ae=e[80];let ge;return e[81]!==r||e[82]!==n||e[83]!==ae?(ge=s.jsx(ws,{open:n,onOpenChange:r,children:ae}),e[81]=r,e[82]=n,e[83]=ae,e[84]=ge):ge=e[84],ge},tm=[{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 Po(t,e){return t==="project"&&e==="agents"?"project-agents":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function Fx(t){const e=tm.find(n=>n.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const CC=t=>{const e=nt.c(124),{open:n,onOpenChange:r,item:a}=t,{t:i}=ut(),o=Qa(IC),c=Qa(AC),[d,p]=l.useState("user"),[m,u]=l.useState("opencode"),f=Es(PC),y=Es(DC),[h,b]=l.useState(null),[x,g]=l.useState(!1);let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=[],e[0]=w):w=e[0];const[v,S]=l.useState(w),[P,j]=l.useState(null);let C,I;e[1]!==y||e[2]!==n?(C=()=>{n&&(p("user"),u("opencode"),b(y),g(!1),S([]),j(null))},I=[n,y],e[1]=y,e[2]=n,e[3]=C,e[4]=I):(C=e[3],I=e[4]),l.useEffect(C,I);let R;e[5]!==i?(R=Ae=>{switch(Ae){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]=R):R=e[6];const k=R;let A;e[7]!==i?(A=Ae=>{switch(Ae){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]=A):A=e[8];const N=A;let D;e:{if(f.length===0){D=null;break e}if(h&&f.some(Ae=>Ae.id===h)){D=h;break e}if(y&&f.some(Ae=>Ae.id===y)){D=y;break e}D=f[0]?.id??null}const T=D;let M;e:{if(d!=="project"){M=null;break e}const Ae=T;if(!Ae){M=null;break e}let xe;if(e[9]!==Ae||e[10]!==f){let de;e[12]!==Ae?(de=Me=>Me.id===Ae,e[12]=Ae,e[13]=de):de=e[13],xe=f.find(de),e[9]=Ae,e[10]=f,e[11]=xe}else xe=e[11];M=xe?.path??null}const $=M;let F;e[14]!==o||e[15]!==a||e[16]!==r||e[17]!==i?(F=async Ae=>{const xe={skillDir:Ae.skillDir};a?.clawdhub&&(xe.clawdhub={slug:a.clawdhub.slug,version:a.clawdhub.version});const V=await o({source:Ae.source,subpath:Ae.subpath,gitIdentityId:a?.gitIdentityId,scope:Ae.scope,targetSource:Ae.targetSource,selections:[xe],conflictPolicy:"prompt",conflictDecisions:Ae.conflictDecisions},{directory:Ae.directoryOverride??null});if(V.ok){q.success(i("settings.skills.catalog.installSkill.toast.installed")),r(!1);return}if(V.error?.kind==="conflicts"){j({source:Ae.source,subpath:Ae.subpath,scope:Ae.scope,targetSource:Ae.targetSource,skillDir:Ae.skillDir,directoryOverride:Ae.directoryOverride??null}),S(V.error.conflicts),g(!0);return}if(V.error?.kind==="authRequired"){q.error(V.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}q.error(V.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=o,e[15]=a,e[16]=r,e[17]=i,e[18]=F):F=e[18];const _=F;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 L;e[21]!==O?(L=s.jsx(js,{children:O}),e[21]=O,e[22]=L):L=e[22];let K;e[23]!==i?(K=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=K):K=e[24];let B;e[25]!==a.skillName?(B=s.jsx("span",{className:"font-semibold text-foreground",children:a.skillName}),e[25]=a.skillName,e[26]=B):B=e[26];let re;e[27]!==i?(re=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=re):re=e[28];let oe;e[29]!==K||e[30]!==B||e[31]!==re?(oe=s.jsxs(Fs,{children:[K," ",B," ",re]}),e[29]=K,e[30]=B,e[31]=re,e[32]=oe):oe=e[32];let ee;e[33]!==L||e[34]!==oe?(ee=s.jsxs(Cs,{children:[L,oe]}),e[33]=L,e[34]=oe,e[35]=ee):ee=e[35];let ae;e[36]!==i?(ae=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=ae):ae=e[37];let ge;e[38]!==ae?(ge=s.jsx("span",{className:"typography-ui-label text-foreground",children:ae}),e[38]=ae,e[39]=ge):ge=e[39];let ne;e[40]!==d||e[41]!==m?(ne=Po(d,m),e[40]=d,e[41]=m,e[42]=ne):ne=e[42];let E;e[43]===Symbol.for("react.memo_cache_sentinel")?(E=Ae=>{const xe=Fx(Ae);p(xe.scope),u(xe.source==="agents"?"agents":"opencode")},e[43]=E):E=e[43];let z;e[44]!==d?(z=d==="user"?s.jsx(Yr,{className:"h-3.5 w-3.5"}):s.jsx(Un,{className:"h-3.5 w-3.5"}),e[44]=d,e[45]=z):z=e[45];let J;e[46]!==m?(J=m==="agents"?s.jsx(Jr,{className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=J):J=e[47];let H;e[48]!==k||e[49]!==d||e[50]!==m?(H=k(Po(d,m)),e[48]=k,e[49]=d,e[50]=m,e[51]=H):H=e[51];let te;e[52]!==H?(te=s.jsx("span",{children:H}),e[52]=H,e[53]=te):te=e[53];let ce;e[54]!==z||e[55]!==J||e[56]!==te?(ce=s.jsxs(hs,{className:"w-fit gap-1.5",children:[z,J,te]}),e[54]=z,e[55]=J,e[56]=te,e[57]=ce):ce=e[57];let Se;e[58]!==N||e[59]!==k?(Se=tm.map(Ae=>s.jsx(Rt,{value:Ae.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:[Ae.scope==="user"?s.jsx(Yr,{className:"h-3.5 w-3.5"}):s.jsx(Un,{className:"h-3.5 w-3.5"}),Ae.source==="agents"?s.jsx(Jr,{className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:k(Ae.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:N(Ae.value)})]})},Ae.value)),e[58]=N,e[59]=k,e[60]=Se):Se=e[60];let pe;e[61]!==Se?(pe=s.jsx(fs,{align:"start",children:Se}),e[61]=Se,e[62]=pe):pe=e[62];let we;e[63]!==ne||e[64]!==ce||e[65]!==pe?(we=s.jsxs(ps,{value:ne,onValueChange:E,children:[ce,pe]}),e[63]=ne,e[64]=ce,e[65]=pe,e[66]=we):we=e[66];let W;e[67]!==ge||e[68]!==we?(W=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ge,we]}),e[67]=ge,e[68]=we,e[69]=W):W=e[69];let ue;e[70]!==f||e[71]!==T||e[72]!==d||e[73]!==i?(ue=d==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.skills.catalog.installSkill.field.project")}),f.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(ps,{value:T??"",onValueChange:Ae=>b(Ae),disabled:f.length===1,children:[s.jsx(hs,{className:"w-fit",children:s.jsx(ys,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(fs,{align:"start",children:f.map(TC)})]})]}),e[70]=f,e[71]=T,e[72]=d,e[73]=i,e[74]=ue):ue=e[74];let Y;e[75]!==a.warnings?(Y=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]=Y):Y=e[76];let le;e[77]!==W||e[78]!==ue||e[79]!==Y?(le=s.jsxs("div",{className:"mt-2 space-y-3",children:[W,ue,Y]}),e[77]=W,e[78]=ue,e[79]=Y,e[80]=le):le=e[80];let Z;e[81]!==r?(Z=()=>r(!1),e[81]=r,e[82]=Z):Z=e[82];let Ie;e[83]!==i?(Ie=i("settings.common.actions.cancel"),e[83]=i,e[84]=Ie):Ie=e[84];let Ne;e[85]!==Z||e[86]!==Ie?(Ne=s.jsx(ve,{size:"sm",variant:"ghost",onClick:Z,children:Ie}),e[85]=Z,e[86]=Ie,e[87]=Ne):Ne=e[87];const X=c||!a.installable||d==="project"&&!$;let he;e[88]!==$||e[89]!==_||e[90]!==a.repoSource||e[91]!==a.repoSubpath||e[92]!==a.skillDir||e[93]!==d||e[94]!==m?(he=()=>{_({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]=he):he=e[95];let je;e[96]!==c||e[97]!==i?(je=i(c?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=c,e[97]=i,e[98]=je):je=e[98];let be;e[99]!==X||e[100]!==he||e[101]!==je?(be=s.jsx(ve,{size:"sm",disabled:X,onClick:he,children:je}),e[99]=X,e[100]=he,e[101]=je,e[102]=be):be=e[102];let fe;e[103]!==Ne||e[104]!==be?(fe=s.jsxs(Xs,{children:[Ne,be]}),e[103]=Ne,e[104]=be,e[105]=fe):fe=e[105];let Pe;e[106]!==ee||e[107]!==le||e[108]!==fe?(Pe=s.jsxs(vs,{className:"max-w-md",children:[ee,le,fe]}),e[106]=ee,e[107]=le,e[108]=fe,e[109]=Pe):Pe=e[109];let Be;e[110]!==r||e[111]!==n||e[112]!==Pe?(Be=s.jsx(ws,{open:n,onOpenChange:r,children:Pe}),e[110]=r,e[111]=n,e[112]=Pe,e[113]=Be):Be=e[113];let G;e[114]!==P||e[115]!==_?(G=Ae=>{P&&(_({source:P.source,subpath:P.subpath,scope:P.scope,targetSource:P.targetSource,skillDir:P.skillDir,conflictDecisions:Ae,directoryOverride:P.directoryOverride??null}),g(!1))},e[114]=P,e[115]=_,e[116]=G):G=e[116];let ke;e[117]!==v||e[118]!==x||e[119]!==G?(ke=s.jsx(kC,{open:x,onOpenChange:g,conflicts:v,onConfirm:G}),e[117]=v,e[118]=x,e[119]=G,e[120]=ke):ke=e[120];let Ee;return e[121]!==Be||e[122]!==ke?(Ee=s.jsxs(s.Fragment,{children:[Be,ke]}),e[121]=Be,e[122]=ke,e[123]=Ee):Ee=e[123],Ee};function IC(t){return t.installSkills}function AC(t){return t.isInstalling}function PC(t){return t.projects}function DC(t){return t.activeProjectId}function TC(t){return s.jsx(Rt,{value:t.id,children:t.label||t.path},t.id)}const MC=async()=>{try{const t=yr()?.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}},RC=({mode:t,onModeChange:e,showModeTabs:n=!0})=>{const{t:r}=ut(),{sources:a,itemsBySource:i,selectedSourceId:o,setSelectedSource:c,loadCatalog:d,loadSource:p,loadMoreClawdHub:m,isLoadingCatalog:u,isLoadingSource:f,isLoadingMore:y,loadedSourceIds:h,clawdhubHasMoreBySource:b,lastCatalogError:x}=Qa(Sr(L=>({sources:L.sources,itemsBySource:L.itemsBySource,selectedSourceId:L.selectedSourceId,setSelectedSource:L.setSelectedSource,loadCatalog:L.loadCatalog,loadSource:L.loadSource,loadMoreClawdHub:L.loadMoreClawdHub,isLoadingCatalog:L.isLoadingCatalog,isLoadingSource:L.isLoadingSource,isLoadingMore:L.isLoadingMore,loadedSourceIds:L.loadedSourceIds,clawdhubHasMoreBySource:L.clawdhubHasMoreBySource,lastCatalogError:L.lastCatalogError}))),[g,w]=l.useState(""),[v,S]=l.useState(!1),[P,j]=l.useState(!1),[C,I]=l.useState(null),[R,k]=l.useState(!1),[A,N]=l.useState(!1);l.useEffect(()=>{d()},[d]),l.useEffect(()=>{o&&(h[o]||p(o))},[o,h,p]);const D=l.useMemo(()=>o?i[o]||[]:[],[i,o]),T=l.useMemo(()=>{const L=g.trim().toLowerCase();return L?D.filter(K=>{const B=K.skillName.toLowerCase(),re=(K.description||"").toLowerCase(),oe=(K.frontmatterName||"").toLowerCase();return B.includes(L)||re.includes(L)||oe.includes(L)}):D},[D,g]),M=l.useMemo(()=>a.find(L=>L.id===o)||null,[a,o]),$=!!(o&&o.startsWith("custom:")),F=M?.source==="clawdhub:registry"||M?.sourceType==="clawdhub",_=!!(o&&(b[o]??!0)),O=async()=>{if(!(!o||!$)){k(!0);try{const L=await MC(),B=(Array.isArray(L?.skillCatalogs)?L?.skillCatalogs:[]).filter(re=>re.id!==o);await As({skillCatalogs:B}),await d({refresh:!0}),N(!1)}finally{k(!1)}}};return s.jsx(Ps,{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(zr,{items:[{id:"manual",label:r("settings.skills.catalog.page.mode.manual")},{id:"external",label:r("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:L=>e(L),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(ps,{value:o||"",onValueChange:L=>c(L),children:[s.jsx(hs,{className:"w-fit",children:s.jsx(ys,{placeholder:r("settings.skills.catalog.page.field.selectSourcePlaceholder")})}),s.jsx(fs,{align:"start",children:a.map(L=>s.jsx(Rt,{value:L.id,children:L.label},L.id))})]}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{o?p(o,{refresh:!0}):d({refresh:!0})},disabled:u||f,title:r("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(In,{className:me("h-3.5 w-3.5",(u||f)&&"animate-spin")})}),$&&s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>N(!0),disabled:R,title:r("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(an,{className:"h-3.5 w-3.5"})}),s.jsxs(ve,{size:"xs",className:"!font-normal gap-1",onClick:()=>S(!0),children:[s.jsx(zs,{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(Jn,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Bt,{value:g,onChange:L=>w(L.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:T.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:T.length===0&&!f?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:r("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.skills.catalog.page.empty.noSkillsDescription")})]}):f?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(In,{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:T.map(L=>{const K=L.installed?.isInstalled,B=L.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:L.skillName}),K&&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:B||r("settings.skills.catalog.page.badge.unknown")})}),!L.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")})]}),L.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:L.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:r("settings.skills.catalog.shared.noDescription")}),L.clawdhub&&s.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[L.clawdhub.owner&&s.jsxs("span",{children:[r("settings.skills.catalog.page.byOwnerPrefix")," ",s.jsx("span",{className:"font-medium text-foreground/80",children:L.clawdhub.owner})]}),s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(Xr,{className:"h-3 w-3"}),L.clawdhub.downloads?.toLocaleString()??0]}),(L.clawdhub.stars??0)>0&&s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(Nl,{className:"h-3 w-3"}),L.clawdhub.stars]}),s.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",L.clawdhub.version]})]}),L.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:L.warnings.join(" · ")}):null]}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!L.installable,onClick:()=>{I(L),j(!0)},children:r("settings.skills.catalog.shared.actions.install")})]})},`${L.sourceId}:${L.skillDir}`)})})}),F&&_&&!f&&T.length>0&&s.jsx("div",{className:"flex justify-center mt-2 px-2",children:s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:y,children:r(y?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]}),s.jsx(bC,{open:v,onOpenChange:S}),s.jsx(CC,{open:P,onOpenChange:j,item:C}),s.jsx(ws,{open:A,onOpenChange:L=>{R||N(L)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:r("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Fs,{children:r("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(Xs,{children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>N(!1),disabled:R,children:r("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",variant:"destructive",onClick:()=>{O()},disabled:R,children:r("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})},EC=()=>{const t=nt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(RC,{mode:"external",onModeChange:OC,showModeTabs:!1}),t[0]=e):e=t[0],e},FC=()=>{const{t}=ut(),{selectedSkillName:e,getSkillByName:n,getSkillDetail:r,createSkill:a,updateSkill:i,skills:o,skillDraft:c,setSkillDraft:d,setSelectedSkill:p}=wa(Sr(X=>({selectedSkillName:X.selectedSkillName,getSkillByName:X.getSkillByName,getSkillDetail:X.getSkillDetail,createSkill:X.createSkill,updateSkill:X.updateSkill,skills:X.skills,skillDraft:X.skillDraft,setSkillDraft:X.setSkillDraft,setSelectedSkill:X.setSelectedSkill}))),m=e?n(e):null,u=!!(c&&c.name===e&&!m),f=!!(e&&!m&&!c);l.useEffect(()=>{f&&p(null)},[f,p]);const[y,h]=l.useState(""),[b,x]=l.useState("user"),[g,w]=l.useState("opencode"),[v,S]=l.useState(""),[P,j]=l.useState(""),[C,I]=l.useState([]),[R,k]=l.useState([]),[A,N]=l.useState(!1),[D,T]=l.useState(!1),[M,$]=l.useState(""),[F,_]=l.useState(""),[O,L]=l.useState(!1),[K,B]=l.useState(""),[re,oe]=l.useState(""),[ee,ae]=l.useState(null),[ge,ne]=l.useState(!1),[E,z]=l.useState(""),[J,H]=l.useState(null),[te,ce]=l.useState(!1),Se=u?y.trim()!==""||v.trim()!==""||P.trim()!==""||R.length>0:v!==M||P!==F,pe=ee?re!==E:K.trim()!=="",we=l.useCallback(X=>{switch(X){case"project-opencode":return t("settings.skills.location.option.projectOpencode.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]),W=l.useCallback(X=>{switch(X){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);l.useEffect(()=>{(async()=>{if(u&&c)h(c.name||""),x(c.scope||"user"),w(c.source==="agents"?"agents":"opencode"),S(c.description||""),j(c.instructions||""),$(""),_(""),I([]),k(c.pendingFiles||[]);else if(e&&m){T(!0);try{const he=await r(e);if(he){const je=he.sources.md;S(je.description||""),j(je.instructions||""),$(je.description||""),_(je.instructions||""),I(je.supportingFiles||[])}}catch(he){console.error("Failed to load skill details:",he)}finally{T(!1)}}})()},[m,u,e,o,c,r]);const ue=async()=>{const X=u?y.trim().replace(/\s+/g,"-").toLowerCase():e?.trim();if(!X){q.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(X)||X.length>64){q.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!v.trim()){q.error(t("settings.skills.page.toast.descriptionRequired"));return}if(u&&o.some(he=>he.name===X)){q.error(t("settings.skills.page.toast.skillExists"));return}N(!0);try{const he={name:X,description:v.trim(),instructions:P.trim()||void 0,scope:u?b:void 0,source:u?g:void 0,supportingFiles:u&&R.length>0?R:void 0};let je;u?(je=await a(he),je&&(d(null),k([]),p(X))):(je=await i(X,he),je&&($(v.trim()),_(P.trim()))),je?q.success(t(u?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated")):q.error(t(u?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(he){console.error("Error saving skill:",he),q.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{N(!1)}},Y=()=>{ae(null),B(""),oe(""),z(""),L(!0)},le=async X=>{if(ae(X),B(X),u){const je=R.find(be=>be.path===X)?.content||"";oe(je),z(je),L(!0);return}if(e){ne(!0),L(!0);try{const{readSupportingFile:he}=wa.getState(),je=await he(e,X);oe(je||""),z(je||"")}catch{q.error(t("settings.skills.page.toast.loadFileContentFailed")),oe(""),z("")}finally{ne(!1)}}},Z=async()=>{if(!K.trim()){q.error(t("settings.skills.page.toast.fileNameRequired"));return}const X=K.trim(),he=ee!==null;if(u){if(he)k(fe=>fe.map(Pe=>Pe.path===ee?{path:X,content:re}:Pe)),q.success(t("settings.skills.page.toast.fileUpdated",{path:X}));else{if(R.some(fe=>fe.path===X)){q.error(t("settings.skills.page.toast.fileExists"));return}k(fe=>[...fe,{path:X,content:re}]),q.success(t("settings.skills.page.toast.fileAdded",{path:X}))}L(!1),ae(null);return}if(!e){q.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:je}=wa.getState();if(await je(e,X,re)){q.success(he?t("settings.skills.page.toast.fileUpdated",{path:X}):t("settings.skills.page.toast.fileCreated",{path:X})),L(!1),ae(null);const fe=await r(e);fe&&I(fe.sources.md.supportingFiles||[])}else q.error(t(he?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Ie=X=>{if(u){k(he=>he.filter(je=>je.path!==X)),q.success(t("settings.skills.page.toast.fileRemoved",{path:X}));return}e&&H(X)},Ne=async()=>{if(!J||!e)return;ce(!0);const{deleteSupportingFile:X}=wa.getState();if(await X(e,J)){q.success(t("settings.skills.page.toast.fileDeleted",{path:J}));const je=await r(e);je&&I(je.sources.md.supportingFiles||[]),H(null)}else q.error(t("settings.skills.page.toast.deleteFileFailed"));ce(!1)};return!e&&!c||f?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(Fu,{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")})]})}):D?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(Ps,{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.jsxs("h2",{className:"typography-ui-header font-semibold text-foreground truncate flex items-center gap-2",children:[u?t("settings.skills.page.title.newSkill"):e,m?.source==="claude"&&s.jsx("span",{className:"typography-micro font-normal bg-[var(--surface-muted)] text-muted-foreground px-1.5 py-0.5 rounded",children:t("settings.skills.page.badge.claudeCompatible")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:m?t("settings.skills.page.subtitle.skillLocation",{location:we(Po(m.scope,m.source))}):t("settings.skills.page.subtitle.newSkill")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.basicInformation")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[u&&s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.skills.page.field.skillNameLocation")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:t("settings.skills.page.field.skillNameHint")}),s.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[s.jsx(Bt,{value:y,onChange:X=>h(X.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(ps,{value:Po(b,g),onValueChange:X=>{const he=Fx(X);x(he.scope),w(he.source==="agents"?"agents":"opencode")},children:[s.jsxs(hs,{className:"w-fit gap-1.5",children:[b==="user"?s.jsx(Yr,{className:"h-3.5 w-3.5"}):s.jsx(Un,{className:"h-3.5 w-3.5"}),g==="agents"?s.jsx(Jr,{className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:we(Po(b,g))})]}),s.jsx(fs,{align:"start",children:tm.map(X=>s.jsx(Rt,{value:X.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[X.scope==="user"?s.jsx(Yr,{className:"h-3.5 w-3.5"}):s.jsx(Un,{className:"h-3.5 w-3.5"}),X.source==="agents"?s.jsx(Jr,{className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:we(X.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:W(X.value)})]})},X.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(An,{value:v,onChange:X=>S(X.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent"})})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.instructions")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(An,{value:P,onChange:X=>j(X.target.value),placeholder:t("settings.skills.page.field.instructionsPlaceholder"),className:"min-h-[220px] max-h-[60vh] font-mono typography-meta"})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.supportingFiles")}),s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Y,children:[s.jsx(zs,{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 X=u?R:C;return X.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:X.map(he=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>le(he.path),children:[s.jsx(Xf,{className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:he.path}),u&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:t("settings.skills.page.badge.pending")}),s.jsx(ve,{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:je=>{je.stopPropagation(),Ie(he.path)},children:s.jsx(an,{className:"h-3 w-3"})})]},he.path))})})()})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(ve,{onClick:ue,disabled:A||!Se,size:"xs",className:"!font-normal",children:t(A?"settings.common.actions.saving":u?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(ws,{open:J!==null,onOpenChange:X=>{!X&&!te&&H(null)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Fs,{children:t("settings.skills.page.deleteFileDialog.description",{path:J??""})})]}),s.jsxs(Xs,{children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>H(null),disabled:te,children:t("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",variant:"destructive",onClick:Ne,disabled:te,children:t("settings.common.actions.delete")})]})]})}),s.jsx(ws,{open:O,onOpenChange:X=>{L(X),X||ae(null)},children:s.jsxs(vs,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Cs,{className:"flex-shrink-0",children:[s.jsx(js,{children:t(ee?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Fs,{children:t(ee?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),ge?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(Bt,{value:K,onChange:X=>B(X.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:ee!==null}),!ee&&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(An,{value:re,onChange:X=>oe(X.target.value),placeholder:t("settings.skills.page.fileDialog.field.contentPlaceholder"),outerClassName:"h-[45vh] min-h-[250px] max-h-[55vh]",className:"h-full min-h-0 font-mono typography-meta"})]})]}),s.jsxs(Xs,{className:"mt-4",children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>{L(!1),ae(null)},children:t("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",onClick:Z,disabled:ge||!pe,children:t(ee?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},fh=t=>{const e=nt.c(2),{view:n}=t,r=n===void 0?"installed":n;let a;return e[0]!==r?(a=r==="catalog"?s.jsx(EC,{}):s.jsx(FC,{}),e[0]=r,e[1]=a):a=e[1],a};function OC(){}const Ox=t=>{const e=nt.c(26),{header:n,footer:r,children:a,className:i,variant:o}=t,c=o===void 0?"sidebar":o,d=jn(),p=l.useRef(null),[m,u]=l.useState(!1),[f,y]=l.useState(!1),h=c==="background"||d?"bg-background":"bg-sidebar",b=h==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const N=p.current;if(!N){u(!1),y(!1);return}if(!(N.scrollHeight>N.clientHeight+1)){u(!1),y(!1);return}u(N.scrollTop>1),y(N.scrollTop+N.clientHeight<N.scrollHeight-1)},e[0]=x):x=e[0];const g=x;let w;e[1]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{g()},e[1]=w):w=e[1];let v;e[2]!==a?(v=[a,g],e[2]=a,e[3]=v):v=e[3],l.useEffect(w,v);let S,P;e[4]===Symbol.for("react.memo_cache_sentinel")?(S=()=>{const N=p.current;if(!N)return;const D=()=>g();return N.addEventListener("scroll",D,{passive:!0}),()=>N.removeEventListener("scroll",D)},P=[g],e[4]=S,e[5]=P):(S=e[4],P=e[5]),l.useEffect(S,P);let j;e[6]!==h||e[7]!==i?(j=me("flex h-full flex-col",h,i),e[6]=h,e[7]=i,e[8]=j):j=e[8];let C;e[9]!==a?(C=s.jsx(Ps,{ref:p,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:a}),e[9]=a,e[10]=C):C=e[10];let I;e[11]!==b||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, ${b} 0%, transparent 100%)`}}),e[11]=b,e[12]=m,e[13]=I):I=e[13];let R;e[14]!==b||e[15]!==f?(R=f&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${b} 0%, transparent 100%)`}}),e[14]=b,e[15]=f,e[16]=R):R=e[16];let k;e[17]!==R||e[18]!==C||e[19]!==I?(k=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[C,I,R]}),e[17]=R,e[18]=C,e[19]=I,e[20]=k):k=e[20];let A;return e[21]!==r||e[22]!==n||e[23]!==k||e[24]!==j?(A=s.jsxs("div",{className:j,children:[n,k,r]}),e[21]=r,e[22]=n,e[23]=k,e[24]=j,e[25]=A):A=e[25],A},Lx=t=>{const e=nt.c(23),{title:n,metadata:r,selected:a,onSelect:i,icon:o,actions:c,className:d}=t,p=a===void 0?!1:a,m=c&&c.length>0,u=p?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[0]!==d||e[1]!==u?(f=me("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",u,d),e[0]=d,e[1]=u,e[2]=f):f=e[2];let y;e[3]!==n?(y=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n}),e[3]=n,e[4]=y):y=e[4];let h;e[5]!==o||e[6]!==y?(h=s.jsxs("div",{className:"flex items-center gap-1.5",children:[o,y]}),e[5]=o,e[6]=y,e[7]=h):h=e[7];let b;e[8]!==r?(b=r&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:r}),e[8]=r,e[9]=b):b=e[9];let x;e[10]!==i||e[11]!==h||e[12]!==b?(x=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[h,b]}),e[10]=i,e[11]=h,e[12]=b,e[13]=x):x=e[13];let g;e[14]!==c||e[15]!==m?(g=m&&s.jsxs(_s,{children:[s.jsx($s,{asChild:!0,children:s.jsx(ve,{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(la,{className:"h-3.5 w-3.5"})})}),s.jsx(Bs,{align:"end",className:"w-fit min-w-20",children:c.map(LC)})]}),e[14]=c,e[15]=m,e[16]=g):g=e[16];let w;e[17]!==x||e[18]!==g?(w=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,g]}),e[17]=x,e[18]=g,e[19]=w):w=e[19];let v;return e[20]!==f||e[21]!==w?(v=s.jsx("div",{className:f,children:w}),e[20]=f,e[21]=w,e[22]=v):v=e[22],v};function LC(t){const e=t.icon;return s.jsxs(Lt,{onClick:n=>{n.stopPropagation(),t.onClick()},className:me(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(e,{className:"h-4 w-4 mr-px"}),t.label]},t.label)}const $C=t=>{const e=nt.c(41),{onItemSelect:n}=t,{t:r}=ut(),a=Es(BC),i=De(_C),o=De(VC),{currentTheme:c}=Er();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[0]=d):d=e[0];const[p,m]=l.useState(d);let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=jn(),e[1]=u):u=e[1];const f=u,y=zC;let h,b;e[2]!==a||e[3]!==i||e[4]!==o?(h=()=>{if(a.length===0){i!==null&&o(null);return}i&&a.some(k=>k.id===i)||o(a[0].id)},b=[a,i,o],e[2]=a,e[3]=i,e[4]=o,e[5]=h,e[6]=b):(h=e[5],b=e[6]),l.useEffect(h,b);let x;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=me("border-b px-3","pt-4 pb-3"),e[7]=x):x=e[7];let g;e[8]!==r?(g=r("settings.page.projects.title"),e[8]=r,e[9]=g):g=e[9];let w;e[10]!==g?(w=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:g}),e[10]=g,e[11]=w):w=e[11];let 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 S;e[15]!==v?(S=s.jsx("span",{className:"typography-meta text-muted-foreground",children:v}),e[15]=v,e[16]=S):S=e[16];let P;e[17]!==r?(P=!f&&s.jsx(ve,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:y,"aria-label":r("settings.projects.sidebar.actions.addProject"),children:s.jsx(zs,{className:"size-4"})}),e[17]=r,e[18]=P):P=e[18];let j;e[19]!==P||e[20]!==S?(j=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[S,P]}),e[19]=P,e[20]=S,e[21]=j):j=e[21];let C;e[22]!==j||e[23]!==w?(C=s.jsxs("div",{className:x,children:[w,j]}),e[22]=j,e[23]=w,e[24]=C):C=e[24];let I;if(e[25]!==p||e[26]!==c||e[27]!==n||e[28]!==a||e[29]!==i||e[30]!==o){let k;e[32]!==p||e[33]!==c||e[34]!==n||e[35]!==i||e[36]!==o?(k=A=>{const N=A.id===i,D=A.icon?jc[A.icon]:null,T=`${A.id}:${A.iconImage?.updatedAt??0}`,M=p.has(T)?null:Ho(A,{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),$=A.color?Go[A.color]??null:null,F=M?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:A.iconBackground?{backgroundColor:A.iconBackground}:void 0,children:s.jsx("img",{src:M,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>{m(_=>{if(_.has(T))return _;const O=new Set(_);return O.add(T),O})}})}):D?s.jsx(D,{className:me("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:$?{color:$}:void 0}):s.jsx(Un,{className:me("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:$?{color:$}:void 0});return s.jsx(Lx,{title:A.label||A.path,icon:F,selected:N,onSelect:()=>{o(A.id),n?.()}},A.id)},e[32]=p,e[33]=c,e[34]=n,e[35]=i,e[36]=o,e[37]=k):k=e[37],I=a.map(k),e[25]=p,e[26]=c,e[27]=n,e[28]=a,e[29]=i,e[30]=o,e[31]=I}else I=e[31];let R;return e[38]!==C||e[39]!==I?(R=s.jsx(Ox,{variant:"background",header:C,children:I}),e[38]=C,e[39]=I,e[40]=R):R=e[40],R};function BC(t){return t.projects}function _C(t){return t.settingsProjectsSelectedId}function VC(t){return t.setSettingsProjectsSelectedId}function zC(){Tr.requestDirectoryDialog()}const UC=({projectRef:t=null})=>{const{t:e}=ut(),{isMobile:n,isTablet:r}=dn(),a=n||r,i=Es(D=>D.getActiveProject()),o=t?.path??i?.path??null,c=Ht(D=>D.getWorktreeMetadata),d=Wo(),p=qs(D=>D.homeDirectory),[m,u]=l.useState([]),[f,y]=l.useState(!1),[h,b]=l.useState(null),[x,g]=l.useState([]),[w,v]=l.useState(!1),S=l.useMemo(()=>t?.id&&t?.path?{id:t.id,path:t.path}:!i?.id||!o?null:{id:i.id,path:o},[i?.id,o,t?.id,t?.path]),P=l.useCallback(async()=>{if(!(!S||h===!1))try{const D=await _d(S);g(D)}catch{}},[S,h]);l.useEffect(()=>{if(!o)return;let D=!1;return b(null),(async()=>{try{const T=await Sg(o);if(D)return;b(T)}catch{}})(),()=>{D=!0}},[o]),l.useEffect(()=>{if(!S){g([]),v(!1);return}if(h===!1){g([]),v(!1);return}let D=!1;return v(!0),g([]),(async()=>{try{const T=await _d(S);if(D)return;g(T)}catch{}finally{D||v(!1)}})(),()=>{D=!0}},[S,h]),l.useEffect(()=>{if(!S)return;let D=!1;return y(!0),(async()=>{try{const T=await Wu(S);D||u(T.length>0?T:[""])}catch{D||u([""])}finally{D||y(!1)}})(),()=>{D=!0}},[S]);const j=l.useCallback((D,T)=>{u(M=>{const $=[...M];return $[D]=T,$})},[]),C=l.useCallback(()=>{u(D=>[...D,""])},[]),I=l.useCallback(async D=>{if(!S)return;const T=D.filter(M=>M.trim().length>0);await kg(S,T)},[S]),R=l.useCallback(D=>{u(T=>{const M=T.filter(($,F)=>F!==D);return I(M),M.length>0?M:[""]})},[I]),k=l.useCallback(()=>{I(m)},[I,m]),A=l.useCallback(D=>{const T=B=>B.replace(/\\/g,"/").replace(/\/+$/,""),M=T(D.path),$=d.filter(B=>{const re=c(B.id);if(re?.path&&T(re.path)===M)return!0;const oe=B.directory;return!!(oe&&T(oe)===M)}),F=new Set($.map(B=>B.id)),_=B=>{const re=d.filter(ee=>{const ae=ee.parentID;return ae&&B.has(ae)});if(re.length===0)return[];const oe=new Set(re.map(ee=>ee.id));return[...re,..._(oe)]},O=_(F),L=new Set,K=[...$,...O].filter(B=>L.has(B.id)?!1:(L.add(B.id),!0));Tr.requestDelete({sessions:K,mode:"worktree",worktree:D})},[d,c]),N=l.useMemo(()=>d.map(D=>D.id).join(","),[d]);return l.useEffect(()=>{h&&o&&P()},[N,h,o,P]),o?h===!1?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.gitOnly")}):s.jsxs("div",{className:"max-w-[44rem] space-y-5",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.openchamber.worktrees.setup.title")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(It,{sideOffset:8,className:"max-w-xs",children:[e("settings.openchamber.worktrees.setup.tooltipPrefix")," ",s.jsx("code",{className:"font-mono text-xs bg-sidebar-accent/50 px-1 rounded",children:"$ROOT_PROJECT_PATH"})," ",e("settings.openchamber.worktrees.setup.tooltipSuffix")]})]})]})}),f?s.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.setup.loading")}):s.jsxs("div",{className:"space-y-2 px-1",children:[m.map((D,T)=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Bt,{value:D,onChange:M=>j(T,M.target.value),onBlur:k,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:()=>{R(T)},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(Is,{className:"h-4 w-4"})})]},T)),s.jsxs(ve,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:C,children:[s.jsx(zs,{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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:e("settings.openchamber.worktrees.list.tooltip")})]})]})}),w?s.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.list.loading")}):x.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-1",children:e("settings.openchamber.worktrees.list.empty")}):s.jsx("div",{className:"space-y-1 px-1 max-w-[32.5rem]",children:x.map(D=>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:D.label||D.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:Ro(D.path,p)})]}),s.jsx("button",{type:"button",onClick:()=>A(D),className:me("flex-shrink-0 flex h-7 w-7 items-center justify-center rounded text-muted-foreground/50 hover:text-destructive hover:bg-destructive/10 transition-opacity focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",a?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":e("settings.openchamber.worktrees.list.deleteWorktreeAria",{name:D.branch||D.label||D.path}),children:s.jsx(an,{className:"h-4 w-4"})})]},D.path))})]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.selectProject")})},WC=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,KC=()=>({id:WC(),name:"",command:"",icon:"play"}),HC=({projectRef:t})=>{const{t:e}=ut(),n=l.useMemo(()=>Pn(),[]),r=rn(C=>C.instances),a=rn(C=>C.load),[i,o]=l.useState([]),[c,d]=l.useState(!1),[p,m]=l.useState(!1),[u,f]=l.useState(null),[y,h]=l.useState({});l.useEffect(()=>{n&&a().catch(()=>{})},[n,a]),l.useEffect(()=>{let C=!1;return d(!0),(async()=>{try{const I=await Bd(t);if(C)return;o(I.actions),f(JSON.stringify({actions:I.actions}))}catch{if(C)return;o([]),f(JSON.stringify({actions:[]}))}finally{C||d(!1)}})(),()=>{C=!0}},[t]);const b=l.useMemo(()=>n?Yg(r):[],[r,n]),x=l.useMemo(()=>i.some(I=>I.name.trim().length===0||I.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[i,e]),g=l.useMemo(()=>u===null?!1:u!==JSON.stringify({actions:i}),[i,u]),w=l.useCallback(()=>{const C=KC();o(I=>[...I,C]),h(I=>({...I,[C.id]:!0}))},[]),v=l.useCallback(C=>{o(I=>I.filter(R=>R.id!==C)),h(I=>{const R={...I};return delete R[C],R})},[]),S=l.useCallback((C,I)=>{o(R=>R.map(k=>k.id===C?I(k):k))},[]),P=l.useCallback(async()=>{if(x){q.error(x);return}m(!0);try{if(!await h1(t,{actions:i,primaryActionId:null})){q.error(e("settings.projects.actions.toast.saveFailed"));return}f(JSON.stringify({actions:i})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(Gd,{detail:{projectId:t.id}})),q.success(e("settings.projects.actions.toast.saved"))}catch{q.error(e("settings.projects.actions.toast.saveFailed"))}finally{m(!1)}},[i,t,e,x]),j=!p&&!c&&g&&!x;return s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 flex items-start justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e("settings.projects.actions.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.description")})]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:w,children:[s.jsx(zs,{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(C=>{const I=C.icon||"play",R=Dl[I]||Gr,k=y[C.id]??!1,A=C.name.trim()||e("settings.projects.actions.state.untitled");return s.jsxs(wr,{open:k,onOpenChange:N=>{h(D=>({...D,[C.id]:N}))},className:me("py-1.5"),children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs(Rr,{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:[k?s.jsx(ks,{className:"h-4 w-4 text-muted-foreground"}):s.jsx($n,{className:"h-4 w-4 text-muted-foreground"}),s.jsx(R,{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:A})})})]}),s.jsx(ve,{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(C.id),children:s.jsx(an,{className:"h-3.5 w-3.5"})})]}),s.jsx(jr,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-2 pb-6 pl-3 pr-3",children:[s.jsxs("div",{className:"flex items-center gap-2 py-1",children:[s.jsxs(_s,{children:[s.jsx($s,{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(R,{className:"h-4 w-4"})})}),s.jsx(Bs,{align:"start",className:"w-56 p-2",children:s.jsx("div",{className:"grid grid-cols-6 gap-1",children:Qg.map(N=>{const D=N.Icon,T=(C.icon||"play")===N.key;return s.jsx("button",{type:"button",onClick:()=>S(C.id,M=>({...M,icon:N.key})),className:me("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",T&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:N.label}),children:s.jsx(D,{className:"h-4 w-4"})},N.key)})})})]}),s.jsx(Bt,{value:C.name,onChange:N=>S(C.id,D=>({...D,name:N.target.value})),placeholder:e("settings.projects.actions.field.actionNamePlaceholder"),className:"h-7 max-w-[14rem]"})]}),s.jsxs("div",{className:"py-1",children:[s.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.command")}),s.jsx(An,{value:C.command,onChange:N=>S(C.id,D=>({...D,command:N.target.value})),placeholder:e("settings.projects.actions.field.commandPlaceholder"),className:"min-h-[88px] max-w-[30rem] font-mono text-xs"})]}),s.jsxs("div",{className:"py-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.projects.actions.field.autoOpenUrl")}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2",role:"button",tabIndex:0,"aria-pressed":C.autoOpenUrl===!0,onClick:()=>S(C.id,N=>({...N,...N.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),S(C.id,D=>({...D,...D.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[s.jsx(bs,{checked:C.autoOpenUrl===!0,onChange:N=>S(C.id,D=>({...D,...N?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:A})}),s.jsx("span",{className:"typography-ui-label font-normal text-foreground/80",children:e("settings.projects.actions.field.autoOpenUrlDescription")})]})]}),C.autoOpenUrl===!0?s.jsxs("div",{className:"mt-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bt,{value:C.openUrl||"",onChange:N=>S(C.id,D=>({...D,openUrl:N.target.value})),placeholder:e("settings.projects.actions.field.overrideUrlPlaceholder"),className:"h-7 w-full max-w-[24rem]"}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{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")}),b.length>0?s.jsxs(ps,{value:C.desktopOpenSshForward&&b.some(N=>N.id===C.desktopOpenSshForward)?C.desktopOpenSshForward:"__none__",onValueChange:N=>{S(C.id,D=>({...D,...N==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:N}}))},children:[s.jsx(hs,{className:"h-7 w-full max-w-[30rem]",children:s.jsx(ys,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),s.jsxs(fs,{children:[s.jsx(Rt,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),b.map(N=>s.jsx(Rt,{value:N.id,children:N.label},N.id))]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.noDesktopSshForwards")})]}):null]}):null]})]})})]},C.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(ve,{type:"button",size:"xs",className:"!font-normal",onClick:P,disabled:!j,children:e(p?"settings.common.actions.saving":"settings.projects.actions.actions.save")})]})]})]})},GC=()=>{const t=nt.c(201),{t:e}=ut(),n=Es(qC),r=Es(QC),a=Es(JC),i=Es(YC),o=Es(XC),c=De(ZC),d=De(e4),{currentTheme:p}=Er();let m;e:{if(!c){m=null;break e}let wt;t[0]!==n||t[1]!==c?(wt=n.find(Wt=>Wt.id===c)??null,t[0]=n,t[1]=c,t[2]=wt):wt=t[2],m=wt}const u=m;let f,y;t[3]!==n||t[4]!==c||t[5]!==d?(f=()=>{if(n.length===0){d(null);return}c&&n.some(wt=>wt.id===c)||d(n[0].id)},y=[n,c,d],t[3]=n,t[4]=c,t[5]=d,t[6]=f,t[7]=y):(f=t[6],y=t[7]),l.useEffect(f,y);const[h,b]=l.useState(""),[x,g]=l.useState(null),[w,v]=l.useState(null),[S,P]=l.useState(null),[j,C]=l.useState(!1),[I,R]=l.useState(!1),[k,A]=l.useState(!1),[N,D]=l.useState(!1),[T,M]=l.useState(null),[$,F]=l.useState(null),[_,O]=l.useState(!1),L=l.useRef(null);let K;t[8]===Symbol.for("react.memo_cache_sentinel")?(K=()=>{M(null),F(t4)},t[8]=K):K=t[8];const B=K;let re;e:{if(!u){re=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],re=wt}const oe=re;let ee,ae;t[12]!==u?(ee=()=>{if(!u){b(""),g(null),v(null),P(null);return}b(u.label??""),g(u.icon??null),v(u.color??null),P(u.iconBackground??null),D(!1),B(),O(!1)},ae=[u,B],t[12]=u,t[13]=ee,t[14]=ae):(ee=t[13],ae=t[14]),l.useEffect(ee,ae);let ge,ne;t[15]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>()=>{B()},ne=[B],t[15]=ge,t[16]=ne):(ge=t[15],ne=t[16]),l.useEffect(ge,ne);let E;t[17]!==w||t[18]!==x||t[19]!==S||t[20]!==h||t[21]!==N||t[22]!==T||t[23]!==u?(E=!!u&&(h.trim()!==(u?.label??"").trim()||x!==(u?.icon??null)||w!==(u?.color??null)||S!==(u?.iconBackground??null)||N||!!T),t[17]=w,t[18]=x,t[19]=S,t[20]=h,t[21]=N,t[22]=T,t[23]=u,t[24]=E):E=t[24];const z=E;let J;t[25]!==w||t[26]!==x||t[27]!==S||t[28]!==h||t[29]!==N||t[30]!==T||t[31]!==i||t[32]!==u||t[33]!==e||t[34]!==r||t[35]!==a?(J=async()=>{if(!u)return;if(T){C(!0);const Wt=await a(u.id,T);if(C(!1),!Wt.ok){q.error(Wt.error||e("settings.projects.page.toast.uploadIconFailed"));return}q.success(e("settings.projects.page.toast.iconUpdated")),B(),D(!1)}const wt=N&&!!u.iconImage;if(wt){R(!0);const Wt=await i(u.id);if(R(!1),!Wt.ok){q.error(Wt.error||e("settings.projects.page.toast.removeIconFailed"));return}q.success(e("settings.projects.page.toast.iconRemoved")),D(!1),P(null)}r(u.id,{label:h.trim(),icon:x,color:w,iconBackground:wt?null:S})},t[25]=w,t[26]=x,t[27]=S,t[28]=h,t[29]=N,t[30]=T,t[31]=i,t[32]=u,t[33]=e,t[34]=r,t[35]=a,t[36]=J):J=t[36];const H=J,te=w?Go[w]??null:null,ce=!!u?.iconImage,Se=!!(T&&$),pe=u?.iconImage?.source==="custom",we=ce&&!N||Se,W=we;let ue;t[37]!==p||t[38]!==Se||t[39]!==ce||t[40]!==N||t[41]!==$||t[42]!==_||t[43]!==u?(ue=_?null:Se?$:u&&ce&&!N?Ho(u,{themeVariant:p.metadata.variant,iconColor:p.colors.surface.foreground}):null,t[37]=p,t[38]=Se,t[39]=ce,t[40]=N,t[41]=$,t[42]=_,t[43]=u,t[44]=ue):ue=t[44];const Y=ue;let le;t[45]!==j||t[46]!==u?(le=wt=>{!u||!wt||j||(D(!1),O(!1),M(wt),F(Wt=>(Wt&&URL.revokeObjectURL(Wt),URL.createObjectURL(wt))))},t[45]=j,t[46]=u,t[47]=le):le=t[47];const Z=le;let Ie;t[48]!==Se||t[49]!==W||t[50]!==ce||t[51]!==I||t[52]!==u?(Ie=()=>{!u||!W||I||(Se&&B(),D(!!ce),O(!1))},t[48]=Se,t[49]=W,t[50]=ce,t[51]=I,t[52]=u,t[53]=Ie):Ie=t[53];const Ne=Ie;let X;t[54]!==o||t[55]!==k||t[56]!==u||t[57]!==e?(X=async()=>{!u||k||(B(),D(!1),O(!1),A(!0),o(u.id).then(wt=>{if(!wt.ok){q.error(wt.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(wt.skipped){q.success(e("settings.projects.page.toast.customIconAlreadySet"));return}q.success(e("settings.projects.page.toast.iconDiscovered"))}).finally(()=>{A(!1)}))},t[54]=o,t[55]=k,t[56]=u,t[57]=e,t[58]=X):X=t[58];const he=X;if(!u){let wt;t[59]!==e?(wt=e("settings.projects.page.empty.noProjects"),t[59]=e,t[60]=wt):wt=t[60];let Wt;return t[61]!==wt?(Wt=s.jsx(Ps,{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]=Wt):Wt=t[62],Wt}let je;t[63]!==u.label||t[64]!==e?(je=u.label??e("settings.projects.page.title.default"),t[63]=u.label,t[64]=e,t[65]=je):je=t[65];let be;t[66]!==je?(be=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:je}),t[66]=je,t[67]=be):be=t[67];let fe;t[68]!==u.path?(fe=s.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:u.path,children:u.path}),t[68]=u.path,t[69]=fe):fe=t[69];let Pe;t[70]!==be||t[71]!==fe?(Pe=s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[be,fe]})}),t[70]=be,t[71]=fe,t[72]=Pe):Pe=t[72];let Be;t[73]!==e?(Be=e("settings.projects.page.field.projectName"),t[73]=e,t[74]=Be):Be=t[74];let G;t[75]!==Be?(G=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:Be})}),t[75]=Be,t[76]=G):G=t[76];let ke;t[77]===Symbol.for("react.memo_cache_sentinel")?(ke=wt=>b(wt.target.value),t[77]=ke):ke=t[77];let Ee;t[78]!==e?(Ee=e("settings.projects.page.field.projectNamePlaceholder"),t[78]=e,t[79]=Ee):Ee=t[79];let Ae;t[80]!==h||t[81]!==Ee?(Ae=s.jsx("div",{className:"mt-1.5 flex min-w-0 items-center gap-2",children:s.jsx(Bt,{value:h,onChange:ke,placeholder:Ee,className:"h-7 min-w-0 w-full sm:max-w-[19rem]"})}),t[80]=h,t[81]=Ee,t[82]=Ae):Ae=t[82];let xe;t[83]!==G||t[84]!==Ae?(xe=s.jsxs("div",{className:"py-1.5",children:[G,Ae]}),t[83]=G,t[84]=Ae,t[85]=xe):xe=t[85];let V;t[86]!==e?(V=e("settings.projects.page.field.accentColor"),t[86]=e,t[87]=V):V=t[87];let de;t[88]!==V?(de=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:V})}),t[88]=V,t[89]=de):de=t[89];let Me;t[90]===Symbol.for("react.memo_cache_sentinel")?(Me=()=>v(null),t[90]=Me):Me=t[90];const Le=w===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let se;t[91]!==Le?(se=me("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Le),t[91]=Le,t[92]=se):se=t[92];let ie;t[93]!==e?(ie=e("settings.projects.page.field.none"),t[93]=e,t[94]=ie):ie=t[94];let U;t[95]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(Is,{className:"h-4 w-4 text-muted-foreground"}),t[95]=U):U=t[95];let Ve;t[96]!==se||t[97]!==ie?(Ve=s.jsx("button",{type:"button",onClick:Me,className:se,title:ie,children:U}),t[96]=se,t[97]=ie,t[98]=Ve):Ve=t[98];let He;t[99]!==w?(He=f1.map(wt=>s.jsx("button",{type:"button",onClick:()=>v(wt.key),className:me("h-7 w-7 rounded-md border transition-colors",w===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]=w,t[100]=He):He=t[100];let Ke;t[101]!==Ve||t[102]!==He?(Ke=s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[Ve,He]}),t[101]=Ve,t[102]=He,t[103]=Ke):Ke=t[103];let Ze;t[104]!==de||t[105]!==Ke?(Ze=s.jsxs("div",{className:"py-1.5",children:[de,Ke]}),t[104]=de,t[105]=Ke,t[106]=Ze):Ze=t[106];let Xe;t[107]!==e?(Xe=e("settings.projects.page.field.projectIcon"),t[107]=e,t[108]=Xe):Xe=t[108];let dt;t[109]!==Xe?(dt=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:Xe})}),t[109]=Xe,t[110]=dt):dt=t[110];let et;t[111]!==Z?(et=s.jsx("input",{ref:L,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:wt=>{const Wt=wt.target.files?.[0]??null;Z(Wt),wt.currentTarget.value=""}}),t[111]=Z,t[112]=et):et=t[112];let ct;t[113]===Symbol.for("react.memo_cache_sentinel")?(ct=()=>g(null),t[113]=ct):ct=t[113];const at=x===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let ye;t[114]!==at?(ye=me("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",at),t[114]=at,t[115]=ye):ye=t[115];let Ge;t[116]!==e?(Ge=e("settings.projects.page.field.none"),t[116]=e,t[117]=Ge):Ge=t[117];let $e;t[118]===Symbol.for("react.memo_cache_sentinel")?($e=s.jsx(Is,{className:"h-4 w-4 text-muted-foreground"}),t[118]=$e):$e=t[118];let _e;t[119]!==ye||t[120]!==Ge?(_e=s.jsx("button",{type:"button",onClick:ct,className:ye,title:Ge,children:$e}),t[119]=ye,t[120]=Ge,t[121]=_e):_e=t[121];let tt;t[122]!==te||t[123]!==x?(tt=g1.map(wt=>{const Wt=wt.Icon;return s.jsx("button",{type:"button",onClick:()=>g(wt.key),className:me("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(Wt,{className:"w-4 h-4",style:te&&x===wt.key?{color:te}:void 0})},wt.key)}),t[122]=te,t[123]=x,t[124]=tt):tt=t[124];let Qe;t[125]!==_e||t[126]!==tt?(Qe=s.jsxs("div",{className:"mt-1.5 flex max-w-[22rem] flex-wrap items-center gap-2",children:[_e,tt]}),t[125]=_e,t[126]=tt,t[127]=Qe):Qe=t[127];let ze;t[128]!==we||t[129]!==S||t[130]!==Y||t[131]!==e?(ze=we&&Y&&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:S?{backgroundColor:S}:void 0,children:s.jsx("img",{src:Y,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>O(!0)})})})]}),t[128]=we,t[129]=S,t[130]=Y,t[131]=e,t[132]=ze):ze=t[132];let gt;t[133]!==we||t[134]!==S||t[135]!==e?(gt=we&&s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[s.jsx("input",{type:"color",value:S??"#000000",onChange:wt=>P(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(Bt,{value:S??"",onChange:wt=>P(wt.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),s.jsx(ve,{type:"button",size:"xs",variant:"outline",onClick:()=>P(null),className:"h-7 w-7 p-0","aria-label":e("settings.projects.page.field.clearIconBackgroundAria"),title:e("settings.projects.page.field.clearBackground"),disabled:!S,children:s.jsx(Is,{className:"h-3.5 w-3.5"})})]}),t[133]=we,t[134]=S,t[135]=e,t[136]=gt):gt=t[136];let Vt;t[137]!==he||t[138]!==pe||t[139]!==k||t[140]!==j||t[141]!==e?(Vt=!pe&&s.jsxs(s.Fragment,{children:[s.jsx(ve,{size:"xs",className:"h-6 !font-normal",onClick:()=>L.current?.click(),disabled:j,children:e(j?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),s.jsx(ve,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{he()},disabled:k,children:e(k?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),t[137]=he,t[138]=pe,t[139]=k,t[140]=j,t[141]=e,t[142]=Vt):Vt=t[142];let Kt;t[143]!==Ne||t[144]!==W||t[145]!==I||t[146]!==e?(Kt=W&&s.jsx(ve,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{Ne()},disabled:I,children:e(I?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),t[143]=Ne,t[144]=W,t[145]=I,t[146]=e,t[147]=Kt):Kt=t[147];let Jt;t[148]!==I||t[149]!==N||t[150]!==e?(Jt=N&&s.jsx(ve,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>D(!1),disabled:I,children:e("settings.projects.page.actions.undoRemove")}),t[148]=I,t[149]=N,t[150]=e,t[151]=Jt):Jt=t[151];let At;t[152]!==Vt||t[153]!==Kt||t[154]!==Jt?(At=s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Vt,Kt,Jt]}),t[152]=Vt,t[153]=Kt,t[154]=Jt,t[155]=At):At=t[155];let jt;t[156]!==dt||t[157]!==et||t[158]!==Qe||t[159]!==ze||t[160]!==gt||t[161]!==At?(jt=s.jsxs("div",{className:"py-1.5",children:[dt,et,Qe,ze,gt,At]}),t[156]=dt,t[157]=et,t[158]=Qe,t[159]=ze,t[160]=gt,t[161]=At,t[162]=jt):jt=t[162];let ns;t[163]!==xe||t[164]!==Ze||t[165]!==jt?(ns=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[xe,Ze,jt]}),t[163]=xe,t[164]=Ze,t[165]=jt,t[166]=ns):ns=t[166];let ot;t[167]!==z||t[168]!==I||t[169]!==j||t[170]!==h?(ot=!z||h.trim().length===0||j||I,t[167]=z,t[168]=I,t[169]=j,t[170]=h,t[171]=ot):ot=t[171];let Zt;t[172]!==e?(Zt=e("settings.common.actions.saveChanges"),t[172]=e,t[173]=Zt):Zt=t[173];let Yt;t[174]!==H||t[175]!==ot||t[176]!==Zt?(Yt=s.jsx("div",{className:"mt-0.5 px-2 py-1",children:s.jsx(ve,{onClick:H,disabled:ot,size:"xs",className:"!font-normal",children:Zt})}),t[174]=H,t[175]=ot,t[176]=Zt,t[177]=Yt):Yt=t[177];let es;t[178]!==ns||t[179]!==Yt?(es=s.jsxs("div",{className:"mb-8",children:[ns,Yt]}),t[178]=ns,t[179]=Yt,t[180]=es):es=t[180];let ls;t[181]!==oe?(ls=oe&&s.jsx(HC,{projectRef:oe}),t[181]=oe,t[182]=ls):ls=t[182];let ds;t[183]!==ls?(ds=s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:ls})}),t[183]=ls,t[184]=ds):ds=t[184];let gs;t[185]!==e?(gs=e("settings.projects.page.section.worktree"),t[185]=e,t[186]=gs):gs=t[186];let us;t[187]!==gs?(us=s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:gs})}),t[187]=gs,t[188]=us):us=t[188];let Ct;t[189]!==oe?(Ct=oe&&s.jsx(UC,{projectRef:oe}),t[189]=oe,t[190]=Ct):Ct=t[190];let Ue;t[191]!==Ct?(Ue=s.jsx("section",{className:"px-2 pb-2 pt-0",children:Ct}),t[191]=Ct,t[192]=Ue):Ue=t[192];let Dt;t[193]!==us||t[194]!==Ue?(Dt=s.jsxs("div",{className:"mb-8",children:[us,Ue]}),t[193]=us,t[194]=Ue,t[195]=Dt):Dt=t[195];let Tt;return t[196]!==Pe||t[197]!==es||t[198]!==ds||t[199]!==Dt?(Tt=s.jsx(Ps,{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:[Pe,es,ds,Dt]})}),t[196]=Pe,t[197]=es,t[198]=ds,t[199]=Dt,t[200]=Tt):Tt=t[200],Tt};function qC(t){return t.projects}function QC(t){return t.updateProjectMeta}function JC(t){return t.uploadProjectIcon}function YC(t){return t.removeProjectIcon}function XC(t){return t.discoverProjectIcon}function ZC(t){return t.settingsProjectsSelectedId}function e4(t){return t.setSettingsProjectsSelectedId}function t4(t){return t&&URL.revokeObjectURL(t),null}const s4=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`,n4=()=>Math.floor(2e4+Math.random()*3e4),r4=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")},a4=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"}},i4=({onItemSelect:t})=>{const{t:e}=ut(),n=rn(g=>g.instances),r=rn(g=>g.statusesById),a=rn(g=>g.isLoading),i=rn(g=>g.load),o=rn(g=>g.loadImports),c=rn(g=>g.createFromCommand),d=rn(g=>g.connect),p=rn(g=>g.disconnect),m=rn(g=>g.retry),u=rn(g=>g.removeInstance),f=rn(g=>g.upsertInstance),y=De(g=>g.settingsRemoteInstancesSelectedId),h=De(g=>g.setSettingsRemoteInstancesSelectedId);l.useEffect(()=>{i(),o()},[i,o]),l.useEffect(()=>{if(!a){if(n.length===0){y!==null&&h(null);return}y&&n.some(g=>g.id===y)||h(n[0].id)}},[n,a,y,h]);const b=l.useCallback(async()=>{const g=s4();try{await c(g,"ssh user@example.com",e("settings.remoteInstances.sidebar.newSshInstanceName")),h(g),t?.()}catch(w){q.error(e("settings.remoteInstances.sidebar.toast.createFailed"),{description:w instanceof Error?w.message:String(w)})}},[c,t,h,e]),x=l.useCallback(async g=>{try{await d(g.id);return}catch(w){if(!r4(w)||!window.confirm(e("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw w;const S={...g,localForward:{...g.localForward,preferredLocalPort:n4()}};await f(S),await d(S.id),q.success(e("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[d,e,f]);return s.jsx(Ox,{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(ve,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:()=>{b()},"aria-label":e("settings.remoteInstances.sidebar.actions.addSshInstance"),children:s.jsx(zs,{className:"size-4"})})]})]}),children:n.map(g=>{const w=r[g.id],v=g.id===y,S=g.nickname?.trim()||g.sshParsed?.destination||g.id,P=`${e(a4(w?.phase))}${w?.localUrl?` · ${w.localUrl}`:""}`,j=w?.phase==="ready",C=w?.phase==="error"||w?.phase==="degraded";return s.jsx(Lx,{title:S,metadata:P,selected:v,onSelect:()=>{h(g.id),t?.()},actions:[{label:e(j?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect"),icon:j?qr:Zf,onClick:()=>{(j?p(g.id):x(g)).catch(R=>{q.error(e(j?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:R instanceof Error?R.message:String(R)})})}},{label:e("settings.remoteInstances.sidebar.actions.retry"),icon:In,onClick:()=>{C&&m(g.id).catch(I=>{q.error(e("settings.remoteInstances.sidebar.toast.retryFailed"),{description:I instanceof Error?I.message:String(I)})})}},{label:e("settings.remoteInstances.sidebar.actions.remove"),icon:an,destructive:!0,onClick:()=>{u(g.id).then(()=>{if(y===g.id){const I=n.find(R=>R.id!==g.id);h(I?.id||null)}}).catch(I=>{q.error(e("settings.remoteInstances.sidebar.toast.removeFailed"),{description:I instanceof Error?I.message:String(I)})})}}]},g.id)})})},gh=t=>{const e=nt.c(10),{children:n,className:r,outerClassName:a}=t;let i;e[0]!==a?(i=me("h-full",a),e[0]=a,e[1]=i):i=e[1];let o;e[2]!==r?(o=me("mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",r),e[2]=r,e[3]=o):o=e[3];let c;e[4]!==n||e[5]!==o?(c=s.jsx("div",{className:o,children:n}),e[4]=n,e[5]=o,e[6]=c):c=e[6];let d;return e[7]!==i||e[8]!==c?(d=s.jsx(Ps,{outerClassName:i,className:"w-full",children:c}),e[7]=i,e[8]=c,e[9]=d):d=e[9],d},ou=()=>Math.floor(2e4+Math.random()*3e4),o4=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")},l4=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"}},c4=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),$x=t=>!!(t&&c4.has(t)),d4=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||$x(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",u4=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}`,m4=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:ou(),remoteHost:"127.0.0.1",remotePort:80}),p4=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",ra=t=>{const e=nt.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(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),e[2]=i):i=e[2];let o;e[3]!==r?(o=s.jsxs(St,{children:[i,s.jsx(It,{sideOffset:8,className:"max-w-xs",children:s.jsx("div",{className:"typography-meta text-foreground",children:r})})]}),e[3]=r,e[4]=o):o=e[4];let c;return e[5]!==a||e[6]!==o?(c=s.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[a,o]}),e[5]=a,e[6]=o,e[7]=c):c=e[7],c},h4=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"}},xh=(t,e)=>{const n=(t||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},f4=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},g4=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}`},x4=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},b4=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}},y4=()=>{const{t}=ut(),e=rn(V=>V.instances),n=rn(V=>V.statusesById),r=rn(V=>V.importCandidates),a=rn(V=>V.isImportsLoading),i=rn(V=>V.isSaving),o=rn(V=>V.error),c=rn(V=>V.load),d=rn(V=>V.loadImports),p=rn(V=>V.refreshStatuses),m=rn(V=>V.upsertInstance),u=rn(V=>V.createFromCommand),f=rn(V=>V.removeInstance),y=rn(V=>V.connect),h=rn(V=>V.disconnect),b=rn(V=>V.retry),x=De(V=>V.settingsRemoteInstancesSelectedId),g=De(V=>V.setSettingsRemoteInstancesSelectedId),w=l.useMemo(()=>x&&e.find(V=>V.id===x)||null,[e,x]),[v,S]=l.useState(null),[P,j]=l.useState(!1),[C,I]=l.useState(!1),[R,k]=l.useState(null),[A,N]=l.useState([]),[D,T]=l.useState(null),[M,$]=l.useState(""),[F,_]=l.useState(!1),[O,L]=l.useState({}),[K,B]=l.useState(!1),[re,oe]=l.useState(!1),[ee,ae]=l.useState(()=>Date.now());l.useEffect(()=>{c(),d()},[c,d]),l.useEffect(()=>{S(w)},[w]),l.useEffect(()=>{if(!x)return;const V=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||p()},2e3);return()=>{window.clearInterval(V)}},[p,x]),l.useEffect(()=>{let V=null,de=Date.now();const Me=()=>{const se=Date.now();se-de>=1e3&&(ae(se),de=se),V=requestAnimationFrame(Me)};(typeof document>"u"||document.visibilityState==="visible")&&(V=requestAnimationFrame(Me));const Le=()=>{document.visibilityState==="visible"&&V===null?V=requestAnimationFrame(Me):document.visibilityState!=="visible"&&V!==null&&(cancelAnimationFrame(V),V=null)};return document.addEventListener("visibilitychange",Le),()=>{document.removeEventListener("visibilitychange",Le),V!==null&&cancelAnimationFrame(V)}},[]);const ge=x?n[x]:null,ne=ge?.phase,E=ne==="ready",z=ne==="degraded",J=$x(ne),te=E||(J||z),ce=ge?Math.max(0,ee-ge.updatedAtMs):0,Se=z&&ce>12e3,pe=l.useMemo(()=>!v||!w?!1:JSON.stringify(v)!==JSON.stringify(w),[v,w]),we=l.useCallback(V=>{S(de=>de&&V(de))},[]),W=l.useCallback(async()=>{if(!v)return;const V=b4(v);if(!V.sshCommand.trim()){q.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(V.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(V.auth.sshPassword?.enabled&&V.auth.sshPassword.value?.trim()&&V.auth.sshPassword.store!=="settings"){const de=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));V.auth.sshPassword.store=de?"settings":"never",de||(V.auth.sshPassword.value=void 0)}if(V.auth.openchamberPassword?.enabled&&V.auth.openchamberPassword.value?.trim()&&V.auth.openchamberPassword.store!=="settings"){const de=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));V.auth.openchamberPassword.store=de?"settings":"never",de||(V.auth.openchamberPassword.value=void 0)}try{await m(V),q.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(de){q.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:de instanceof Error?de.message:String(de)})}}},[v,t,m]),ue=l.useCallback(async(V,de)=>{const Me=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await u(Me,`ssh ${de}`,V),g(Me),q.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Le){return q.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Le instanceof Error?Le.message:String(Le)}),!1}},[u,g,t]),Y=l.useCallback(()=>{F||(T(null),$(""))},[F]),le=l.useCallback((V,de)=>{if(de){T(V),$(p4(V));return}ue(V,V)},[ue]),Z=l.useCallback(async()=>{const V=D,de=M.trim();if(V){if(!de){q.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}_(!0);try{await ue(V,de)&&(T(null),$(""))}finally{_(!1)}}},[ue,M,D,t]),Ie=l.useCallback(async()=>{if(w)try{await y(w.id);return}catch(V){if(!o4(V)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw V;const Me={...w,localForward:{...w.localForward,preferredLocalPort:ou()}};await m(Me),await y(Me.id),q.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[y,w,t,m]),Ne=l.useCallback(async V=>(await x1(V,600)).map(Me=>g4(Me)),[]),X=l.useCallback(async()=>{if(v){j(!0),I(!0),k(null);try{const V=await Ne(v.id);N(V)}catch(V){N([]),k(V instanceof Error?V.message:String(V))}finally{I(!1)}}},[v,Ne]);l.useEffect(()=>{if(!P||!v)return;let V=!1;const de=async()=>{try{const Le=await Ne(v.id);V||(N(Le),k(null))}catch(Le){V||k(Le instanceof Error?Le.message:String(Le))}};de();const Me=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||de()},1e3);return()=>{V=!0,window.clearInterval(Me)}},[v,P,Ne]);const he=l.useMemo(()=>A.join(`
|
|
85
|
+
`),[A]),je=l.useCallback(()=>{if(!he.trim()){q.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Wn(he).then(V=>{V.ok&&q.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[he,t]),be=l.useCallback(async()=>{if(v)try{await b1(v.id),N([]),q.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(V){q.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:V instanceof Error?V.message:String(V)})}},[v,t]),fe=l.useCallback(async()=>{if(!ge?.localUrl){q.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const V=ge.localUrl.trim();if(!V){q.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}x4(V)},[ge?.localUrl,t]),Pe=l.useCallback(()=>{if(!v)return;B(!0),(te?h(v.id):Ie()).catch(de=>{const Me=te?E?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";q.error(t(Me),{description:de instanceof Error?de.message:String(de)})}).finally(()=>{B(!1)})},[te,Ie,h,v,E,t]),Be=l.useCallback(()=>{if(!v||J)return;oe(!0),(z?h(v.id).then(()=>Ie()):b(v.id)).catch(de=>{q.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:de instanceof Error?de.message:String(de)})}).finally(()=>{oe(!1)})},[Ie,h,v,J,z,b,t]),G=t(J?"settings.remoteInstances.page.actions.connecting":z?Se?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),ke=!K&&!re&&(ne==="error"||ne==="idle"||!ne||z&&Se)&&!J,Ee=t(E?"settings.remoteInstances.sidebar.actions.disconnect":te?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!v)return s.jsxs(gh,{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(V=>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:[V.host,V.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[V.source," config"]})]}),s.jsx(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{le(V.host,V.pattern)},children:t("settings.remoteInstances.page.actions.create")})]},`${V.source}:${V.host}`))})})]}),s.jsx(ws,{open:!!D,onOpenChange:V=>{V||Y()},children:s.jsxs(vs,{className:"sm:max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Fs,{children:D?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:D}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:V=>{V.preventDefault(),Z()},children:[s.jsx(Bt,{value:M,onChange:V=>$(V.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(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Y,disabled:F,children:t("settings.common.actions.cancel")}),s.jsx(ve,{type:"submit",size:"xs",className:"!font-normal",disabled:F,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const Ae=v.remoteOpenchamber.mode==="managed",xe=v.nickname?.trim()||v.sshParsed?.destination||v.id;return s.jsxs(gh,{children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:xe}),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 ${d4(ne)}`}),s.jsx("span",{children:t(l4(ne))}),ge?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:ge.localUrl}):null,Se?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(ve,{type:"button",variant:te?"outline":"default",size:"xs",className:"!font-normal",onClick:Pe,disabled:K||re,children:[te?s.jsx(qr,{className:"h-3.5 w-3.5"}):s.jsx(Zf,{className:"h-3.5 w-3.5"}),Ee]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Be,disabled:!ke,children:[s.jsx(In,{className:`h-3.5 w-3.5 ${J||z&&!Se?"animate-spin":""}`}),G]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{X()},children:[s.jsx(Iy,{className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&f(v.id).then(()=>{g(null),q.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(de=>{q.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:de instanceof Error?de.message:String(de)})})},children:[s.jsx(an,{className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),ge?.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:ge.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(Bt,{className:"h-7 md:max-w-xl",value:v.sshCommand,onChange:V=>we(de=>({...de,sshCommand:V.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(Bt,{className:"h-7 md:max-w-sm",value:v.nickname||"",onChange:V=>we(de=>({...de,nickname:V.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(Cn,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:v.connectionTimeoutSec,onValueChange:V=>{we(de=>({...de,connectionTimeoutSec:Number.isFinite(V)?V:de.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(ra,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(ps,{value:v.remoteOpenchamber.mode,onValueChange:V=>we(de=>({...de,remoteOpenchamber:{...de.remoteOpenchamber,mode:V==="external"?"external":"managed"}})),children:[s.jsx(hs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(fs,{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(ra,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(Cn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:v.remoteOpenchamber.preferredPort,onValueChange:V=>{we(de=>({...de,remoteOpenchamber:{...de.remoteOpenchamber,preferredPort:Number.isFinite(V)&&V>0?V:void 0}}))},onClear:()=>{we(V=>({...V,remoteOpenchamber:{...V.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),Ae?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(ra,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(ps,{value:v.remoteOpenchamber.installMethod,onValueChange:V=>we(de=>({...de,remoteOpenchamber:{...de.remoteOpenchamber,installMethod:V==="npm"||V==="download_release"||V==="upload_bundle"?V:"bun"}})),children:[s.jsx(hs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(fs,{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,Ae?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(ra,{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(Xl,{checked:v.remoteOpenchamber.keepRunning,onCheckedChange:V=>we(de=>({...de,remoteOpenchamber:{...de.remoteOpenchamber,keepRunning:V}}))})})]}):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(ra,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(ps,{value:v.localForward.bindHost,onValueChange:V=>{V==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||we(de=>({...de,localForward:{...de.localForward,bindHost:V==="localhost"||V==="0.0.0.0"?V:"127.0.0.1"}}))},children:[s.jsx(hs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(fs,{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(ra,{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(Cn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:v.localForward.preferredLocalPort,onValueChange:V=>{we(de=>({...de,localForward:{...de.localForward,preferredLocalPort:Number.isFinite(V)&&V>0?V:void 0}}))},onClear:()=>{we(V=>({...V,localForward:{...V.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>we(V=>({...V,localForward:{...V.localForward,preferredLocalPort:ou()}})),children:s.jsx(Ay,{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(Bt,{className:"h-7 md:max-w-sm",type:"password",value:v.auth.sshPassword?.value||"",onChange:V=>we(de=>({...de,auth:{...de.auth,sshPassword:{enabled:V.target.value.trim().length>0,value:V.target.value,store:de.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(Bt,{className:"h-7 md:max-w-sm",type:"password",value:v.auth.openchamberPassword?.value||"",onChange:V=>we(de=>({...de,auth:{...de.auth,openchamberPassword:{enabled:V.target.value.trim().length>0,value:V.target.value,store:de.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((V,de)=>{const Me=et=>{we(ct=>({...ct,portForwards:ct.portForwards.map((at,ye)=>ye===de?et(at):at)}))},Le=V.type==="remote"?"Local target":"Local listen",se=V.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=V.type==="remote"?"Remote listen":"Remote target",U=V.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",Ve=xh(V.localHost||"localhost",V.localPort),He=xh(V.remoteHost||"localhost",V.remotePort),Ke=V.type==="local"&&typeof V.localPort=="number"&&V.localPort>0,Ze=Ke?`http://${f4(V.localHost)}:${V.localPort}`:"",Xe=!!O[V.id],dt=V.type==="local"?t("settings.remoteInstances.page.forwardType.local"):V.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(wr,{open:Xe,onOpenChange:et=>{L(ct=>({...ct,[V.id]:et}))},className:`${de>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(Rr,{className:"flex items-center gap-2 group",children:[s.jsx(ks,{className:`h-4 w-4 text-muted-foreground transition-transform ${Xe?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:u4(V)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:dt})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Xl,{checked:V.enabled,onCheckedChange:et=>Me(ct=>({...ct,enabled:et})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(ve,{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:()=>we(et=>({...et,portForwards:et.portForwards.filter(ct=>ct.id!==V.id)})),children:s.jsx(an,{className:"h-3.5 w-3.5"})})]})]}),s.jsx(jr,{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(h4(V.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(ra,{label:t("settings.remoteInstances.page.field.forwardType"),hint:t("settings.remoteInstances.page.field.forwardTypeHint")})}),s.jsxs(ps,{value:V.type,onValueChange:et=>Me(ct=>({...ct,type:et==="dynamic"||et==="remote"?et:"local"})),children:[s.jsx(hs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(fs,{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(ra,{label:Le,hint:se})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Bt,{className:"h-7 w-32",value:V.localHost||"127.0.0.1",onChange:et=>Me(ct=>({...ct,localHost:et.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Cn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:V.localPort,onValueChange:et=>{Me(ct=>({...ct,localPort:Number.isFinite(et)&&et>0?et:void 0}))},onClear:()=>{Me(et=>({...et,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),V.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(ra,{label:ie,hint:U})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Bt,{className:"h-7 w-32",value:V.remoteHost||"",onChange:et=>Me(ct=>({...ct,remoteHost:et.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Cn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:V.remotePort,onValueChange:et=>{Me(ct=>({...ct,remotePort:Number.isFinite(et)&&et>0?et:void 0}))},onClear:()=>{Me(et=>({...et,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:V.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(Ec,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ve}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):V.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(ei,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:He}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(pm,{className:"h-3.5 w-3.5"}),s.jsx(Ec,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ve}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(Ec,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ve}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(pm,{className:"h-3.5 w-3.5"}),s.jsx(ei,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:He}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),Ke?s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{mr(Ze).then(et=>{et||q.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(Pr,{className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},V.id)}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const V=m4();we(de=>({...de,portForwards:[...de.portForwards,V]})),L(de=>({...de,[V.id]:!0}))},children:[s.jsx(zs,{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((V,de)=>s.jsxs("div",{className:`flex items-center justify-between gap-2 px-1 py-2 ${de>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:[V.host,V.pattern?" (pattern)":""]}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:V.sshCommand})]}),s.jsx(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{le(V.host,V.pattern)},children:t("settings.common.actions.import")})]},`${V.source}:${V.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(ve,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{W()},disabled:!pe||i,children:t("settings.common.actions.saveChanges")}),ge?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Wn(ge.localUrl||"").then(V=>{V.ok&&q.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(vr,{className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{fe()},children:[s.jsx(Pr,{className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,o?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:o}):null]})}),s.jsx(ws,{open:P,onOpenChange:j,children:s.jsxs(vs,{className:"sm:max-w-2xl",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Fs,{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(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:je,disabled:C||!he.trim(),children:[s.jsx(vr,{className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{be()},disabled:C,children:[s.jsx(an,{className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),C?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):R?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:R}):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:A.length>0?A.join(`
|
|
86
|
+
`):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(ws,{open:!!D,onOpenChange:V=>{V||Y()},children:s.jsxs(vs,{className:"sm:max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Fs,{children:D?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:D}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:V=>{V.preventDefault(),Z()},children:[s.jsx(Bt,{value:M,onChange:V=>$(V.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(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Y,disabled:F,children:t("settings.common.actions.cancel")}),s.jsx(ve,{type:"submit",size:"xs",className:"!font-normal",disabled:F,children:t("settings.common.actions.create")})]})]})]})})]})},v4="__add_provider__",w4=()=>{const t=Mn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},j4=({onItemSelect:t})=>{const{t:e}=ut(),n=yt(f=>f.providers),r=yt(f=>f.selectedProviderId),a=yt(f=>f.setSelectedProvider),i=Es(f=>f.activeProjectId),[o,c]=l.useState({}),d=l.useMemo(()=>w4(),[i]);l.useEffect(()=>{if(n.length===0){c({});return}let f=!1;return(async()=>{const h=n.map(async b=>{try{const x=d?`?directory=${encodeURIComponent(d)}`:"",g=await fetch(`/api/provider/${encodeURIComponent(b.id)}/source${x}`,{method:"GET",headers:{Accept:"application/json"}});if(!g.ok)return;const w=await g.json().catch(()=>null),v=w?.sources??w?.data?.sources;if(!v||f)return;c(S=>({...S,[b.id]:v}))}catch{}});await Promise.all(h)})(),()=>{f=!0}},[d,n]);const p="bg-background",m=l.useMemo(()=>n.filter(f=>!!o[f.id]?.project?.exists),[n,o]),u=l.useMemo(()=>n.filter(f=>!o[f.id]?.project?.exists),[n,o]);return s.jsxs("div",{className:me("flex h-full flex-col",p),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.providers.sidebar.title")}),s.jsx(Qo,{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(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{a(v4),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(zs,{className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ps,{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(Ca,{className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.providers.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.providers.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[u.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.providers.sidebar.section.userProviders")}),u.map(f=>s.jsx(bh,{provider:f,selectedProviderId:r,onSelect:()=>{a(f.id),t?.()}},f.id))]}),m.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:me("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",u.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),m.map(f=>s.jsx(bh,{provider:f,selectedProviderId:r,onSelect:()=>{a(f.id),t?.()}},f.id))]})]})})]})},bh=t=>{const e=nt.c(17),{provider:n,selectedProviderId:r,onSelect:a}=t,i=Array.isArray(n.models)?n.models.length:0,o=n.id===r,c=n.id,d=o?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==d?(p=me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",d),e[0]=d,e[1]=p):p=e[1];let m;e[2]!==n.id?(m=s.jsx(Vn,{providerId:n.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=n.id,e[3]=m):m=e[3];const u=n.name||n.id;let f;e[4]!==u?(f=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:u}),e[4]=u,e[5]=f):f=e[5];let y;e[6]!==i?(y=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=y):y=e[7];let h;e[8]!==a||e[9]!==m||e[10]!==f||e[11]!==y?(h=s.jsxs("button",{type:"button",onClick:a,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[m,f,y]}),e[8]=a,e[9]=m,e[10]=f,e[11]=y,e[12]=h):h=e[12];let b;return e[13]!==n.id||e[14]!==p||e[15]!==h?(b=s.jsx("div",{className:p,children:h},c),e[13]=n.id,e[14]=p,e[15]=h,e[16]=b):b=e[16],b},N4=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),yh=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=N4.format(t);return e.endsWith(".0")?e.slice(0,-2):e},xl="__add_provider__",Zi=t=>typeof t=="object"&&t!==null,vh=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()},S4=t=>{if(!Zi(t))return{};const e={};for(const[n,r]of Object.entries(t))Array.isArray(r)&&(e[n]=r.filter(a=>Zi(a)));return e},k4=t=>{if(typeof t=="string")return{id:t};if(!Zi(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}},C4=t=>{let e=[];Array.isArray(t)?e=t:Zi(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const n=e.map(a=>k4(a)).filter(a=>!!a),r=new Set;return n.filter(a=>r.has(a.id)?!1:(r.add(a.id),!0))},I4=()=>{const{t}=ut(),e=yt(Y=>Y.providers),n=yt(Y=>Y.selectedProviderId),r=yt(Y=>Y.setSelectedProvider),a=yt(Y=>Y.getModelMetadata),i=De(Y=>Y.hiddenModels),o=De(Y=>Y.toggleHiddenModel),c=De(Y=>Y.hideAllModels),d=De(Y=>Y.showAllModels),[p,m]=l.useState({}),[u,f]=l.useState(!1),[y,h]=l.useState({}),[b,x]=l.useState(null),[g,w]=l.useState(""),[v,S]=l.useState(null),[P,j]=l.useState({}),[C,I]=l.useState({}),[R,k]=l.useState([]),[A,N]=l.useState(!1),[D,T]=l.useState(null),[M,$]=l.useState(""),[F,_]=l.useState(""),[O,L]=l.useState(!1),[K,B]=l.useState({}),[re,oe]=l.useState(!1);l.useEffect(()=>{!n&&e.length>0&&r(e[0].id)},[e,n,r]),l.useEffect(()=>{let Y=!0;return(async()=>{f(!0);try{const Z=await fetch("/api/provider/auth",{method:"GET",headers:{Accept:"application/json"}});if(!Z.ok)throw new Error(`Auth methods request failed (${Z.status})`);const Ie=await Z.json().catch(()=>({}));if(!Y)return;m(S4(Ie))}catch(Z){if(!Y)return;console.error("Failed to load provider auth methods:",Z),q.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{Y&&f(!1)}})(),()=>{Y=!1}},[t]),l.useEffect(()=>{let Y=!0;return(async()=>{N(!0),T(null);try{const Z=await fetch("/api/provider",{method:"GET",headers:{Accept:"application/json"}});if(!Z.ok)throw new Error(`Provider list request failed (${Z.status})`);const Ie=await Z.json().catch(()=>({}));if(!Y)return;k(C4(Ie))}catch(Z){if(!Y)return;console.error("Failed to load available providers:",Z),T(t("settings.providers.page.state.unableToLoadProviderList"))}finally{Y&&N(!1)}})(),()=>{Y=!1}},[t]);const ee=l.useMemo(()=>new Set(e.map(Y=>Y.id)),[e]),ae=l.useMemo(()=>R.filter(Y=>!ee.has(Y.id)).sort((Y,le)=>{const Z=(Y.name||Y.id).toLowerCase(),Ie=(le.name||le.id).toLowerCase();return Z.localeCompare(Ie)}),[R,ee]);l.useEffect(()=>{n===xl&&M&&!ae.some(Y=>Y.id===M)&&$("")},[n,M,ae]),l.useEffect(()=>{if(n===xl){oe(!0);return}oe(!1)},[n,t]),l.useEffect(()=>{if(!n||n===xl)return;let Y=!1;return(async()=>{try{const Z=await fetch(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),Ie=await Z.json().catch(()=>null);if(!Z.ok)throw new Error(Ie?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const Ne=Ie?.sources??Ie?.data?.sources;!Y&&Ne&&B(X=>({...X,[n]:Ne}))}catch(Z){Y||console.error("Failed to load provider sources:",Z)}})(),()=>{Y=!0}},[n,t]);const ge=e.find(Y=>Y.id===n),ne=n?K[n]:void 0,E=async Y=>{const le=y[Y]?.trim()??"";if(!le){q.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Z=`api:${Y}`;x(Z);try{const Ie=await fetch(`/api/auth/${encodeURIComponent(Y)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"api",key:le})}),Ne=await Ie.json().catch(()=>null);if(!Ie.ok){const X=Ne?.error||t("settings.providers.page.toast.apiKeySaveFailed");throw new Error(X)}q.success(t("settings.providers.page.toast.apiKeySaved")),h(X=>({...X,[Y]:""})),await ko({scopes:["providers"],mode:"active"}),r(Y)}catch(Ie){console.error("Failed to save API key:",Ie),q.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{x(null)}},z=async(Y,le)=>{const Z=`oauth:${Y}:${le}`;x(Z);try{const Ie=await fetch(`/api/provider/${encodeURIComponent(Y)}/oauth/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:le})}),Ne=await Ie.json().catch(()=>null);if(!Ie.ok){const Be=Ne?.error||t("settings.providers.page.toast.oauthStartFailed");throw new Error(Be)}const X=Zi(Ne)?Ne:{},he=Zi(X.data)?X.data:X,je=typeof he.url=="string"&&he.url||typeof he.verification_uri_complete=="string"&&he.verification_uri_complete||typeof he.verification_uri=="string"&&he.verification_uri||void 0,be=typeof he.instructions=="string"&&he.instructions||typeof he.message=="string"&&he.message||void 0,fe=typeof he.user_code=="string"&&he.user_code||typeof he.code=="string"&&he.code||typeof he.userCode=="string"&&he.userCode||void 0;if(!je&&!be&&!fe)throw new Error(t("settings.providers.page.toast.oauthDetailsMissing"));const Pe=`${Y}:${le}`;I(Be=>({...Be,[Pe]:{url:je,instructions:be,userCode:fe}})),je&&mr(je),S({providerId:Y,methodIndex:le}),q.message(t("settings.providers.page.toast.completeOAuthInBrowser"))}catch(Ie){console.error("Failed to start OAuth flow:",Ie),q.error(t("settings.providers.page.toast.oauthStartFailed"))}finally{x(null)}},J=async(Y,le)=>{const Z=`${Y}:${le}`,Ie=P[Z]?.trim(),Ne=`oauth-complete:${Y}:${le}`;x(Ne);try{const X={method:le};Ie&&(X.code=Ie);const he=await fetch(`/api/provider/${encodeURIComponent(Y)}/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(X)}),je=await he.json().catch(()=>null);if(!he.ok){const be=je?.error||t("settings.providers.page.toast.oauthCompleteFailed");throw new Error(be)}q.success(t("settings.providers.page.toast.oauthCompleted")),j(be=>({...be,[Z]:""})),S(null),await ko({scopes:["providers"],mode:"active"}),r(Y)}catch(X){console.error("Failed to complete OAuth flow:",X),q.error(t("settings.providers.page.toast.oauthCompleteFailed"))}finally{x(null)}},H=async Y=>{const le=await Wn(Y);if(le.ok){q.success(t("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",le.error),q.error(t("settings.providers.page.toast.oauthLinkCopyFailed"))},te=async Y=>{const le=await Wn(Y);if(le.ok){q.success(t("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",le.error),q.error(t("settings.providers.page.toast.deviceCodeCopyFailed"))},ce=async Y=>{const le=`disconnect:${Y}`;x(le);try{const Z=await fetch(`/api/provider/${encodeURIComponent(Y)}/auth?scope=all`,{method:"DELETE",headers:{"Content-Type":"application/json"}}),Ie=await Z.json().catch(()=>null);if(!Z.ok){const Ne=Ie?.error||t("settings.providers.page.toast.providerDisconnectFailed");throw new Error(Ne)}q.success(t("settings.providers.page.toast.providerDisconnected")),await ko({scopes:["providers"],mode:"active"})}catch(Z){console.error("Failed to disconnect provider:",Z),q.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{x(null)}},Se=n===xl;if(!Se&&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(Ca,{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(Se)return s.jsx(Ps,{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")}),A?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):D?s.jsx("p",{className:"typography-meta text-muted-foreground",children:D}):ae.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connect.allProvidersConnected")}):s.jsxs(_s,{open:O,onOpenChange:Y=>{L(Y),Y||_("")},children:[s.jsx($s,{asChild:!0,children:s.jsxs("button",{type:"button",className:me("flex items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover h-6 w-fit"),children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[M?s.jsx(Vn,{providerId:M,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:me("truncate typography-ui-label font-normal",M?"text-foreground":"text-muted-foreground"),children:M?ae.find(Y=>Y.id===M)?.name||M:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(ks,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(Bs,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:Y=>Y.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:Y=>Y.stopPropagation(),children:[s.jsx(Jn,{className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:F,onChange:Y=>_(Y.target.value),onKeyDown:Y=>Y.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(Ps,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const Y=ae.filter(le=>{const Z=F.toLowerCase();return(le.name||le.id).toLowerCase().includes(Z)||le.id.toLowerCase().includes(Z)});return Y.length===0?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):Y.map(le=>s.jsxs(Lt,{onSelect:()=>{$(le.id),L(!1),_("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Vn,{providerId:le.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:le.name||le.id})]}),M===le.id&&s.jsx(Zs,{className:"h-4 w-4 text-[var(--primary-base)]"})]},le.id))})()})]})]})]})})]}),M&&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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{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(Bt,{type:"password",value:y[M]??"",onChange:Y=>h(le=>({...le,[M]:Y.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(ve,{size:"xs",className:"!font-normal shrink-0",onClick:()=>E(M),disabled:b===`api:${M}`,children:b===`api:${M}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),(()=>{const le=(p[M]??[]).filter(Z=>vh(Z)==="oauth");return le.length===0?null:s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:le.map((Z,Ie)=>{const Ne=Z.label||Z.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(Ie+1)}),X=`${M}:${Ie}`,he=v?.providerId===M&&v?.methodIndex===Ie;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:Ne}),(Z.description||Z.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(Z.description||Z.help)})]}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>z(M,Ie),disabled:b===`oauth:${M}:${Ie}`,children:t("settings.providers.page.actions.connect")})]}),C[X]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:C[X]?.instructions}),C[X]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:C[X]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>te(C[X]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),C[X]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:C[X]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>mr(C[X]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>H(C[X]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),he&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:P[X]??"",onChange:je=>j(be=>({...be,[X]:je.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(ve,{size:"xs",className:"!font-normal",onClick:()=>J(M,Ie),disabled:b===`oauth-complete:${M}:${Ie}`,children:b===`oauth-complete:${M}:${Ie}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${M}-${Ne}`)})})})()]})]})]})});if(!ge)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(Ca,{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 pe=Array.isArray(ge.models)?ge.models:[],W=(p[ge.id]??[]).filter(Y=>vh(Y)==="oauth"),ue=pe.filter(Y=>{const le=typeof Y?.name=="string"?Y.name:"",Z=typeof Y?.id=="string"?Y.id:"",Ie=g.trim().toLowerCase();return Ie?le.toLowerCase().includes(Ie)||Z.toLowerCase().includes(Ie):!0});return s.jsx(Ps,{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(Vn,{providerId:ge.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:ge.name||ge.id}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s.jsx("span",{className:"font-mono",children:ge.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(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>oe(Y=>!Y),children:t(re?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:re?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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{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(Bt,{type:"password",value:y[ge.id]??"",onChange:Y=>h(le=>({...le,[ge.id]:Y.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(ve,{size:"xs",className:"!font-normal shrink-0",onClick:()=>E(ge.id),disabled:b===`api:${ge.id}`,children:b===`api:${ge.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),W.length>0&&s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:W.map((Y,le)=>{const Z=Y.label||Y.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(le+1)}),Ie=`${ge.id}:${le}`,Ne=v?.providerId===ge.id&&v?.methodIndex===le;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:Z}),(Y.description||Y.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(Y.description||Y.help)})]}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>z(ge.id,le),disabled:b===`oauth:${ge.id}:${le}`,children:t("settings.providers.page.actions.connect")})]}),C[Ie]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:C[Ie]?.instructions}),C[Ie]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:C[Ie]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>te(C[Ie]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),C[Ie]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:C[Ie]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>mr(C[Ie]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>H(C[Ie]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),Ne&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:P[Ie]??"",onChange:X=>j(he=>({...he,[Ie]:X.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(ve,{size:"xs",className:"!font-normal",onClick:()=>J(ge.id,le),disabled:b===`oauth-complete:${ge.id}:${le}`,children:b===`oauth-complete:${ge.id}:${le}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${ge.id}-${Z}`)})})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(Zs,{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:ne&&(ne.auth.exists||ne.user.exists||ne.project.exists||ne.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[ne.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,ne.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,ne.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,ne.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(ve,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ce(ge.id),disabled:b===`disconnect:${ge.id}`,children:b===`disconnect:${ge.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"),pe.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",pe.length,")"]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const Y=pe.map(le=>typeof le?.id=="string"?le.id:"").filter(le=>le.length>0);c(ge.id,Y)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>d(ge.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(Jn,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Bt,{value:g,onChange:Y=>w(Y.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),ue.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:ue.map(Y=>{const le=typeof Y?.id=="string"?Y.id:"",Z=typeof Y?.name=="string"?Y.name:le,Ie=le?a(ge.id,le):void 0,Ne=i.some(be=>be.providerID===ge.id&&be.modelID===le),X=yh(Ie?.limit?.context),he=yh(Ie?.limit?.output),je=[];return Ie?.tool_call&&je.push({key:"tools",icon:Ef,label:t("settings.providers.page.models.capability.toolCalling")}),Ie?.reasoning&&je.push({key:"reasoning",icon:Do,label:t("settings.providers.page.models.capability.reasoning")}),Ie?.attachment&&je.push({key:"image",icon:eg,label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:me("flex items-center gap-3",Ne&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Z}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(X||he)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[X?`${X} ${t("settings.providers.page.models.tokenBadge.context")}`:"",X&&he?" · ":"",he?`${he} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),je.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:je.map(({key:be,icon:fe,label:Pe})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Pe,"aria-label":Pe,children:s.jsx(fe,{className:"h-3 w-3"})},be))}),s.jsx("button",{type:"button",onClick:()=>o(ge.id,le),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:t(Ne?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(Ne?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:Ne?s.jsx(Ru,{className:"h-3.5 w-3.5"}):s.jsx(Mu,{className:"h-3.5 w-3.5"})})]})]})},le)})})]})]})]})})},A4=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)},P4=t=>{const e=nt.c(106),{onItemSelect:n}=t,{t:r}=ut(),a=Ls(D4),i=Ls(T4),o=Ls(M4),c=Ls(R4),d=Ls(E4),p=Ls(F4),m=Ls(O4),u=Ls(L4),f=Ls($4),y=Ls(B4),h=Ls(_4),b=Ls(V4);let x,g;e[0]!==b?(x=()=>{b()},g=[b],e[0]=b,e[1]=x,e[2]=g):(x=e[1],g=e[2]),l.useEffect(x,g);const w=z4;let v;e[3]!==f?(v=fe=>{f(fe),w({usageAutoRefresh:fe})},e[3]=f,e[4]=v):v=e[4];const S=v;let P;e[5]!==y?(P=fe=>{const Pe=Number(fe);Number.isFinite(Pe)&&(y(Pe),w({usageRefreshIntervalMs:Pe}))},e[5]=y,e[6]=P):P=e[6];const j=P;let C;e[7]!==h?(C=fe=>{fe!=="usage"&&fe!=="remaining"||(h(fe),w({usageDisplayMode:fe}))},e[7]=h,e[8]=C):C=e[8];const I=C;let R;e[9]===Symbol.for("react.memo_cache_sentinel")?(R=me("flex h-full flex-col","bg-background"),e[9]=R):R=e[9];let k;e[10]!==r?(k=r("settings.usage.sidebar.title"),e[10]=r,e[11]=k):k=e[11];let A;e[12]!==k?(A=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:k}),e[12]=k,e[13]=A):A=e[13];let N;e[14]!==r?(N=r("settings.usage.sidebar.total",{count:Zr.length}),e[14]=r,e[15]=N):N=e[15];let D;e[16]!==N?(D=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[16]=N,e[17]=D):D=e[17];let T;e[18]!==r?(T=r("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[18]=r,e[19]=T):T=e[19];let M;e[20]!==S||e[21]!==T||e[22]!==p?(M=s.jsx(kt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(bs,{checked:p,onChange:S,ariaLabel:T})})}),e[20]=S,e[21]=T,e[22]=p,e[23]=M):M=e[23];let $;e[24]!==r?($=r("settings.usage.sidebar.tooltip.autoRefresh"),e[24]=r,e[25]=$):$=e[25];let F;e[26]!==$?(F=s.jsx(It,{side:"bottom",children:$}),e[26]=$,e[27]=F):F=e[27];let _;e[28]!==M||e[29]!==F?(_=s.jsxs(St,{children:[M,F]}),e[28]=M,e[29]=F,e[30]=_):_=e[30];const O=String(m),L=!p;let K;e[31]!==r?(K=r("settings.usage.sidebar.field.intervalPlaceholder"),e[31]=r,e[32]=K):K=e[32];let B;e[33]!==K?(B=s.jsx(hs,{className:"w-fit",children:s.jsx(ys,{placeholder:K})}),e[33]=K,e[34]=B):B=e[34];let re;e[35]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsxs(fs,{children:[s.jsx(Rt,{value:"30000",children:"30s"}),s.jsx(Rt,{value:"60000",children:"1m"}),s.jsx(Rt,{value:"300000",children:"5m"})]}),e[35]=re):re=e[35];let oe;e[36]!==j||e[37]!==O||e[38]!==L||e[39]!==B?(oe=s.jsxs(ps,{value:O,onValueChange:j,disabled:L,children:[B,re]}),e[36]=j,e[37]=O,e[38]=L,e[39]=B,e[40]=oe):oe=e[40];let ee;e[41]!==c?(ee=()=>c(),e[41]=c,e[42]=ee):ee=e[42];let ae;e[43]!==r?(ae=r("settings.usage.sidebar.actions.refreshAria"),e[43]=r,e[44]=ae):ae=e[44];let ge;e[45]!==r?(ge=r("settings.usage.sidebar.actions.refreshTitle"),e[45]=r,e[46]=ge):ge=e[46];const ne=d&&"animate-spin";let E;e[47]!==ne?(E=me("h-3.5 w-3.5",ne),e[47]=ne,e[48]=E):E=e[48];let z;e[49]!==E?(z=s.jsx(In,{className:E}),e[49]=E,e[50]=z):z=e[50];let J;e[51]!==d||e[52]!==ee||e[53]!==ae||e[54]!==ge||e[55]!==z?(J=s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:ee,"aria-label":ae,title:ge,disabled:d,children:z}),e[51]=d,e[52]=ee,e[53]=ae,e[54]=ge,e[55]=z,e[56]=J):J=e[56];let H;e[57]!==_||e[58]!==oe||e[59]!==J?(H=s.jsxs("div",{className:"flex items-center gap-2",children:[_,oe,J]}),e[57]=_,e[58]=oe,e[59]=J,e[60]=H):H=e[60];let te;e[61]!==D||e[62]!==H?(te=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[D,H]}),e[61]=D,e[62]=H,e[63]=te):te=e[63];let ce;e[64]!==r?(ce=r("settings.usage.sidebar.field.display"),e[64]=r,e[65]=ce):ce=e[65];let Se;e[66]!==ce?(Se=s.jsx("span",{className:"typography-micro text-muted-foreground",children:ce}),e[66]=ce,e[67]=Se):Se=e[67];let pe;e[68]!==r?(pe=r("settings.usage.sidebar.field.displayModePlaceholder"),e[68]=r,e[69]=pe):pe=e[69];let we;e[70]!==pe?(we=s.jsx(hs,{className:"w-fit",children:s.jsx(ys,{placeholder:pe})}),e[70]=pe,e[71]=we):we=e[71];let W;e[72]!==r?(W=r("settings.usage.sidebar.field.displayModeUsage"),e[72]=r,e[73]=W):W=e[73];let ue;e[74]!==W?(ue=s.jsx(Rt,{value:"usage",children:W}),e[74]=W,e[75]=ue):ue=e[75];let Y;e[76]!==r?(Y=r("settings.usage.sidebar.field.displayModeRemaining"),e[76]=r,e[77]=Y):Y=e[77];let le;e[78]!==Y?(le=s.jsx(Rt,{value:"remaining",children:Y}),e[78]=Y,e[79]=le):le=e[79];let Z;e[80]!==ue||e[81]!==le?(Z=s.jsxs(fs,{children:[ue,le]}),e[80]=ue,e[81]=le,e[82]=Z):Z=e[82];let Ie;e[83]!==I||e[84]!==we||e[85]!==Z||e[86]!==u?(Ie=s.jsxs(ps,{value:u,onValueChange:I,children:[we,Z]}),e[83]=I,e[84]=we,e[85]=Z,e[86]=u,e[87]=Ie):Ie=e[87];let Ne;e[88]!==Se||e[89]!==Ie?(Ne=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[Se,Ie]}),e[88]=Se,e[89]=Ie,e[90]=Ne):Ne=e[90];let X;e[91]!==te||e[92]!==Ne||e[93]!==A?(X=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[A,te,Ne]}),e[91]=te,e[92]=Ne,e[93]=A,e[94]=X):X=e[94];let he;e[95]!==n||e[96]!==a||e[97]!==i||e[98]!==o||e[99]!==r?(he=Zr.map(fe=>{const Pe=a.find(xe=>xe.providerId===fe.id),Be=A4(Pe?.usage),G=Bg(Be),ke=fe.id===i,Ee=Pe?.configured??!1,Ae=Ee?G==="critical"?{backgroundColor:"var(--status-error)"}:G==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",ke?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{o(fe.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:Ae}),s.jsx(Vn,{providerId:fe.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:fe.name}),!Ee&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r("settings.usage.sidebar.status.notSet")})]})},fe.id)}),e[95]=n,e[96]=a,e[97]=i,e[98]=o,e[99]=r,e[100]=he):he=e[100];let je;e[101]!==he?(je=s.jsx(Ps,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:he}),e[101]=he,e[102]=je):je=e[102];let be;return e[103]!==X||e[104]!==je?(be=s.jsxs("div",{className:R,children:[X,je]}),e[103]=X,e[104]=je,e[105]=be):be=e[105],be};function D4(t){return t.results}function T4(t){return t.selectedProviderId}function M4(t){return t.setSelectedProvider}function R4(t){return t.fetchAllQuotas}function E4(t){return t.isLoading}function F4(t){return t.autoRefresh}function O4(t){return t.refreshIntervalMs}function L4(t){return t.displayMode}function $4(t){return t.setAutoRefresh}function B4(t){return t.setRefreshInterval}function _4(t){return t.setDisplayMode}function V4(t){return t.loadSettings}async function z4(t){try{await As(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const hd=t=>{const e=nt.c(49),{title:n,window:r,subtitle:a,showToggle:i,toggleEnabled:o,onToggle:c}=t,d=i===void 0?!1:i,p=o===void 0?!1:o,m=Ls(U4),u=m==="remaining"?r.remainingPercent:r.usedPercent,f=m==="remaining"?"remaining":"used";let y;e[0]!==u||e[1]!==r.valueLabel?(y=Fo(r.valueLabel,u),e[0]=u,e[1]=r.valueLabel,e[2]=y):y=e[2];const h=y,b=r.resetAfterFormatted??r.resetAtFormatted??"";let x;e[3]!==n?(x=Hu(n),e[3]=n,e[4]=x):x=e[4];const g=x;let w;e[5]!==n||e[6]!==r.resetAt||e[7]!==r.usedPercent||e[8]!==r.windowSeconds?(w=Oo(r.usedPercent,r.resetAt,r.windowSeconds,n),e[5]=n,e[6]=r.resetAt,e[7]=r.usedPercent,e[8]=r.windowSeconds,e[9]=w):w=e[9];const v=w;let S;e:{if(!v||v.dailyAllocationPercent===null){S=null;break e}const B=oa(v.elapsedRatio);S=m==="remaining"?100-B:B}const P=S;let j;e[10]!==c||e[11]!==d||e[12]!==p?(j=d&&s.jsx(bs,{checked:p,onChange:B=>c?.(B),ariaLabel:"Show in dropdown"}),e[10]=c,e[11]=d,e[12]=p,e[13]=j):j=e[13];let C;e[14]!==g?(C=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:g}),e[14]=g,e[15]=C):C=e[15];let I;e[16]!==a?(I=a&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:a}),e[16]=a,e[17]=I):I=e[17];let R;e[18]!==C||e[19]!==I?(R=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[C,I]}),e[18]=C,e[19]=I,e[20]=R):R=e[20];let k;e[21]!==R||e[22]!==j?(k=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[j,R]}),e[21]=R,e[22]=j,e[23]=k):k=e[23];const A=h==="-"?"":h;let N;e[24]!==A?(N=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:A}),e[24]=A,e[25]=N):N=e[25];let D;e[26]!==k||e[27]!==N?(D=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[k,N]}),e[26]=k,e[27]=N,e[28]=D):D=e[28];let T;e[29]!==u||e[30]!==P||e[31]!==r.usedPercent?(T=s.jsx($o,{percent:u,tonePercent:r.usedPercent,expectedMarkerPercent:P,className:"h-1.5"}),e[29]=u,e[30]=P,e[31]=r.usedPercent,e[32]=T):T=e[32];const M=b?`Resets ${b}`:"";let $;e[33]!==M?($=s.jsx("span",{className:"typography-micro text-muted-foreground",children:M}),e[33]=M,e[34]=$):$=e[34];let F;e[35]!==f?(F=s.jsx("span",{className:"typography-micro text-muted-foreground",children:f}),e[35]=f,e[36]=F):F=e[36];let _;e[37]!==$||e[38]!==F?(_=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[$,F]}),e[37]=$,e[38]=F,e[39]=_):_=e[39];let O;e[40]!==T||e[41]!==_?(O=s.jsxs("div",{className:"mt-2.5",children:[T,_]}),e[40]=T,e[41]=_,e[42]=O):O=e[42];let L;e[43]!==v?(L=v&&s.jsx("div",{className:"mt-1.5",children:s.jsx(Bo,{paceInfo:v})}),e[43]=v,e[44]=L):L=e[44];let K;return e[45]!==D||e[46]!==O||e[47]!==L?(K=s.jsxs("div",{className:"py-3",children:[D,O,L]}),e[45]=D,e[46]=O,e[47]=L,e[48]=K):K=e[48],K};function U4(t){return t.displayMode}const W4=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},K4=()=>{const{t}=ut(),e=Ls(N=>N.results),n=Ls(N=>N.selectedProviderId),r=Ls(N=>N.setSelectedProvider),a=Ls(N=>N.loadSettings),i=Ls(N=>N.fetchAllQuotas),o=Ls(N=>N.isLoading),c=Ls(N=>N.lastUpdated),d=Ls(N=>N.error),p=Ls(N=>N.dropdownProviderIds),m=Ls(N=>N.setDropdownProviderIds),u=Ls(N=>N.selectedModels),f=Ls(N=>N.toggleModelSelected),y=Ls(N=>N.applyDefaultSelections);Wg(),l.useEffect(()=>{a(),i()},[a,i]),l.useEffect(()=>{if(n||e.length===0)return;const N=e.find(D=>D.configured)?.providerId;r(N??Zr[0]?.id??null)},[e,n,r]);const h=e.find(N=>N.providerId===n)??null,x=Zr.find(N=>N.id===n)?.name??n??t("settings.usage.sidebar.title"),g=h?.usage,w=n?p.includes(n):!1,v=l.useCallback(N=>{if(!n)return;const D=N?Array.from(new Set([...p,n])):p.filter(T=>T!==n);m(D),As({usageDropdownProviders:D})},[p,n,m]),S=l.useMemo(()=>g?.models?Object.entries(g.models).map(([N,D])=>({name:N,windows:D})).filter(N=>Object.keys(N.windows.windows).length>0):[],[g?.models]);l.useEffect(()=>{n&&S.length>0&&y(n,S.map(N=>N.name))},[n,S,y]);const P=l.useMemo(()=>!n||S.length===0?new Map:bj(S,N=>N.name,n),[S,n]),j=l.useMemo(()=>{if(!n)return[];const N=zg(n);return Ug(N)},[n]),[C,I]=l.useState(()=>({})),R=l.useCallback(N=>{I(D=>({...D,[N]:!D[N]}))},[]),k=l.useCallback(N=>{if(!n)return;f(n,N);const D=u[n]??[],M=D.includes(N)?D.filter(F=>F!==N):[...D,N],$={...u,[n]:M};As({usageSelectedModels:$})},[n,u,f]),A=n?u[n]??[]:[];return n?s.jsx(Ps,{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(Vn,{providerId:n,className:"h-5 w-5 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.usage.page.header.providerUsage",{provider:x})}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:o?s.jsx("span",{className:"animate-pulse",children:t("settings.usage.page.header.refreshing")}):t("settings.usage.page.header.lastUpdated",{time:W4(c)})})]})]}),s.jsx("div",{className:"mb-8 px-2",children:s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>v(!w),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),v(!w))},children:[s.jsx(bs,{checked:w,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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:t("settings.usage.page.options.showInHeaderTooltip")})]})]})]})}),!h&&s.jsx("div",{className:"mb-8 px-2",children:s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noData")})}),d&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:t("settings.usage.page.state.refreshFailedTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:d})]}),h&&!h.configured&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),g?.windows&&Object.keys(g.windows).length>0&&s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(g.windows).map(([N,D])=>s.jsx(hd,{title:N,window:D},N))})})}),S.length>0&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.usage.page.section.modelQuotas")})}),s.jsxs("div",{className:"space-y-3",children:[j.map(N=>{const D=P.get(N.id)??[];if(D.length===0)return null;const T=C[N.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(wr,{open:!T,onOpenChange:()=>R(N.id),children:[s.jsxs(Rr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:N.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",D.length,")"]})]}),T?s.jsx($n,{className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(ks,{className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(jr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:D.map(M=>{const $=Object.entries(M.windows.windows);if($.length===0)return null;const[F,_]=$[0],O=A.includes(M.name);return s.jsx(hd,{title:F,subtitle:Yl(M.name),window:_,showToggle:!0,toggleEnabled:O,onToggle:()=>k(M.name)},M.name)})})})]})},N.id)}),(()=>{const N=P.get(null)??[];if(N.length===0)return null;const D=C.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(wr,{open:!D,onOpenChange:()=>R("other"),children:[s.jsxs(Rr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",N.length,")"]})]}),D?s.jsx($n,{className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(ks,{className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(jr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:N.map(T=>{const M=Object.entries(T.windows.windows);if(M.length===0)return null;const[$,F]=M[0],_=A.includes(T.name);return s.jsx(hd,{title:$,subtitle:Yl(T.name),window:F,showToggle:!0,toggleEnabled:_,onToggle:()=>k(T.name)},T.name)})})})]})})})()]})]}),h?.configured&&g&&Object.keys(g.windows??{}).length===0&&S.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")})})},H4="git.commit.generate",lu=Nr(t=>({selectedPromptId:H4,setSelectedPromptId:e=>{t(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),G4=t=>{const e=nt.c(23),{onItemSelect:n}=t,{t:r}=ut(),a=lu(q4),i=lu(Q4);let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=o):o=e[0];let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=c):c=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=d):d=e[2];let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=[o,c,d,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"}]}],e[3]=p):p=e[3];const m=p;let u;e[4]!==r?(u=r("settings.magicPrompts.sidebar.title"),e[4]=r,e[5]=u):u=e[5];let f;e[6]!==u?(f=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:u}),e[6]=u,e[7]=f):f=e[7];let y;e[8]!==r?(y=r("settings.magicPrompts.sidebar.description"),e[8]=r,e[9]=y):y=e[9];let h;e[10]!==y?(h=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:y}),e[10]=y,e[11]=h):h=e[11];let b;e[12]!==f||e[13]!==h?(b=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[f,h]}),e[12]=f,e[13]=h,e[14]=b):b=e[14];let x;e[15]!==n||e[16]!==a||e[17]!==i||e[18]!==r?(x=s.jsx(Ps,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(w=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:r(w.groupKey)}),w.items.map(v=>{const S=a===v.id;return s.jsx("button",{type:"button",onClick:()=>{i(v.id),n?.()},className:me("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",S?"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)})]},w.groupKey))}),e[15]=n,e[16]=a,e[17]=i,e[18]=r,e[19]=x):x=e[19];let g;return e[20]!==x||e[21]!==b?(g=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[b,x]}),e[20]=x,e[21]=b,e[22]=g):g=e[22],g};function q4(t){return t.selectedPromptId}function Q4(t){return t.setSelectedPromptId}const wh={"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"}]}},jh=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Nh=t=>t.endsWith(".visible"),J4=()=>{const{t}=ut(),e=l.useCallback(j=>t(j),[t]),n=lu(j=>j.selectedPromptId),[r,a]=l.useState(!0),[i,o]=l.useState({}),[c,d]=l.useState({}),[p,m]=l.useState({}),[u,f]=l.useState({}),[y,h]=l.useState(!1);l.useEffect(()=>{let j=!0;return(async()=>{a(!0);try{const I=await j1();if(!j)return;o(I)}catch(I){console.warn("Failed to load magic prompts:",I),q.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{j&&a(!1)}})(),()=>{j=!1}},[t]);const b=wh[n]??wh["git.commit.generate"],x=l.useCallback(j=>jh(i,j)?i[j]:_c(j),[i]),g=l.useCallback(j=>c[j]??x(j),[c,x]),w=l.useCallback((j,C)=>{d(I=>I[j]===C?I:{...I,[j]:C})},[]),v=l.useCallback(async j=>{const C=g(j);if(Nh(j)&&C.trim().length===0){q.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(I=>({...I,[j]:!0}));try{const I=C===_c(j)?await Am(j):await y1(j,C);o(I.overrides),q.success(t("settings.magicPrompts.page.toast.saved"))}catch(I){const R=I instanceof Error?I.message:String(I);q.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:R})}finally{m(I=>({...I,[j]:!1}))}},[g,t]),S=l.useCallback(async j=>{f(C=>({...C,[j]:!0}));try{const C=await Am(j);o(C.overrides),d(I=>({...I,[j]:_c(j)})),q.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(C){const I=C instanceof Error?C.message:String(C);q.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:I})}finally{f(C=>({...C,[j]:!1}))}},[t]),P=l.useCallback(async()=>{h(!0);try{const j=await v1();o(j.overrides),d({}),q.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(j){const C=j instanceof Error?j.message:String(j);q.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:C})}finally{h(!1)}},[t]);return r?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl px-6 py-6 space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[s.jsx("div",{className:"space-y-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:e(b.titleKey)}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:e(b.descriptionKey)})]})]})}),s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>{P()},disabled:y||Object.keys(i).length===0,children:t(y?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")})]}),b.blocks.map((j,C)=>{const I=w1(j.id),R=x(j.id),k=g(j.id),A=jh(i,j.id),N=k!==R,D=Nh(j.id)&&k.trim().length===0,T=p[j.id]===!0,M=u[j.id]===!0;return s.jsxs("section",{className:C>0?"space-y-3 pt-5 border-t border-border":"space-y-3",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label text-foreground",children:e(j.titleKey)}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{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(An,{value:k,onChange:$=>w(j.id,$.target.value),className:"min-h-[220px] font-mono text-sm"}),D&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(N?"settings.magicPrompts.page.status.unsavedChanges":A?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>{S(j.id)},disabled:!A||T||M,children:t(M?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(ve,{size:"sm",onClick:()=>{v(j.id)},disabled:!N||T||M||D,children:t(T?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},j.id)})]})})},Bx=()=>{const{t}=ut(),e=yt(u=>u.settingsGitmojiEnabled),n=yt(u=>u.setSettingsGitmojiEnabled),r=_u(),a=De(u=>u.gitChangesViewMode),i=De(u=>u.setGitChangesViewMode),[o,c]=l.useState(!0),d=l.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);l.useEffect(()=>{(async()=>{try{let f=null;if(!f){const y=yr()?.settings;if(y)try{const b=(await y.load())?.settings;b&&(f={gitmojiEnabled:typeof b.gitmojiEnabled=="boolean"?b.gitmojiEnabled:void 0,gitChangesViewMode:b.gitChangesViewMode==="flat"||b.gitChangesViewMode==="tree"?b.gitChangesViewMode:void 0})}catch{}}if(!f){const y=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});y.ok&&(f=await y.json())}f&&(typeof f.gitmojiEnabled=="boolean"&&n(f.gitmojiEnabled),(f.gitChangesViewMode==="flat"||f.gitChangesViewMode==="tree")&&i(f.gitChangesViewMode))}catch(f){console.warn("Failed to load git settings:",f)}finally{c(!1)}})()},[i,n]);const p=l.useCallback(async u=>{n(u);try{await As({gitmojiEnabled:u})}catch(f){console.warn("Failed to save gitmoji setting:",f)}},[n]),m=l.useCallback(u=>{u!==a&&(i(u),As({gitChangesViewMode:u}))},[a,i]);return o?null:s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.git.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"pt-1 pb-1",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.git.changesViewTitle")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.openchamber.git.changesViewAria"),className:"mt-0.5 space-y-0",children:d.map(u=>{const f=a===u.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>{m(u.id)},onKeyDown:y=>{(y.key===" "||y.key==="Enter")&&(y.preventDefault(),m(u.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ai,{checked:f,onChange:()=>{m(u.id)},ariaLabel:t("settings.openchamber.git.optionAria",{option:u.label})}),s.jsx("span",{className:f?"typography-ui-label font-normal text-foreground":"typography-ui-label font-normal text-foreground/50",children:u.label})]},u.id)})})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":e,onClick:()=>{p(!e)},onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),p(!e))},children:[s.jsx(bs,{checked:e,onChange:u=>{p(u)},ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.enableGitmoji")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":r,onClick:()=>Vc(!r),onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),Vc(!r))},children:[s.jsx(bs,{checked:r,onChange:Vc,ariaLabel:t("settings.openchamber.git.showGitignoredAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.showGitignored")})]})]})]})},_x=()=>{const{t}=ut(),{isMobile:e}=dn(),n=yr()?.github,r=sr(I=>I.status),a=sr(I=>I.isLoading),i=sr(I=>I.hasChecked),o=sr(I=>I.refreshStatus),c=sr(I=>I.setStatus),d=l.useCallback(async I=>{await mr(I)},[]),[p,m]=l.useState(!1),[u,f]=l.useState(null),[y,h]=l.useState(null),b=l.useRef(null),x=l.useCallback(()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null),h(null)},[]);l.useEffect(()=>((async()=>{try{i||await o(n)}catch(I){console.warn("Failed to load GitHub auth status:",I)}})(),()=>{x()}),[i,o,n,x]);const g=l.useCallback(async()=>{m(!0);try{const I=n?await n.authStart():await(async()=>{const k=await fetch("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),A=await k.json().catch(()=>null);if(!k.ok||!A||!("deviceCode"in A))throw new Error(A?.error||k.statusText);return A})();f(I),h(Math.max(1,I.interval)*1e3);const R=I.verificationUriComplete||I.verificationUri;d(R)}catch(I){console.error("Failed to start GitHub connect:",I),q.error(t("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[d,n,t]),w=l.useCallback(async I=>{if(n)return n.authComplete(I);const R=await fetch("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:I})}),k=await R.json().catch(()=>null);if(!R.ok||!k)throw new Error(k?.error||R.statusText);return k},[n]);l.useEffect(()=>{if(!(!u?.deviceCode||!y)&&b.current==null)return b.current=window.setInterval(()=>{(async()=>{try{const I=await w(u.deviceCode);if(I.connected){q.success(t("settings.github.page.toast.connected")),f(null),x(),await o(n,{force:!0});return}I.status==="slow_down"&&h(R=>R?R+5e3:5e3),(I.status==="expired_token"||I.status==="access_denied")&&(q.error(I.error||t("settings.github.page.toast.authorizationFailed")),f(null),x())}catch(I){console.warn("GitHub polling failed:",I)}})()},y),()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null)}},[u,y,w,o,n,x,t]);const v=l.useCallback(async()=>{m(!0);try{if(x(),f(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)}q.success(t("settings.github.page.toast.disconnected")),await o(n,{force:!0})}catch(I){console.error("Failed to disconnect GitHub:",I),q.error(t("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[o,n,x,t]),S=l.useCallback(async I=>{if(I){m(!0);try{const R=n?await n.authActivate(I):await(async()=>{const k=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:I})}),A=await k.json().catch(()=>null);if(!k.ok||!A)throw new Error(A?.error||k.statusText);return A})();c(R),q.success(t("settings.github.page.toast.accountSwitched"))}catch(R){console.error("Failed to switch GitHub account:",R),q.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,c,t]);if(a)return null;const P=!!r?.connected,j=r?.user,C=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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{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:[P?s.jsxs("div",{className:me("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:me("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[j?.avatarUrl?s.jsx("img",{src:j.avatarUrl,alt:j.login?t("settings.github.page.avatarAlt.withLogin",{login:j.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:j?.name?.trim()||j?.login||"GitHub"}),s.jsxs("div",{className:me("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(Na,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:j?.login||t("settings.github.page.label.unknownUser")}),j?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),j?.email&&s.jsx("span",{children:j.email})]}),r?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.label.scopes",{value:r.scope})})]})]}),s.jsx(ve,{size:"sm",variant:"outline",onClick:v,disabled:p,className:me("text-[var(--status-error)] hover:text-[var(--status-error)]",e?"w-full":void 0),children:t("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.github.page.status.notConnected")})}),s.jsx(ve,{size:"sm",variant:"default",onClick:g,disabled:p,children:t("settings.github.page.actions.connect")})]}),C.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:C.map(I=>{const R=I.user,k=!!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:[R?.avatarUrl?s.jsx("img",{src:R.avatarUrl,alt:R.login?t("settings.github.page.avatarAlt.withLogin",{login:R.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(Na,{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:R?.name?.trim()||R?.login||"GitHub"}),R?.login&&s.jsx("span",{className:"typography-micro text-muted-foreground truncate font-mono",children:R.login})]})]}),k?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(ve,{size:"sm",variant:"ghost",onClick:()=>S(I.id),disabled:p,children:t("settings.github.page.actions.switchTo")})]},I.id)})})]})]}),P&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(ve,{size:"sm",variant:"outline",onClick:g,disabled:p,className:me(e?"w-full":void 0),children:t("settings.github.page.actions.addAccount")})}),u&&s.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h4",{className:"typography-ui-label text-foreground",children:t("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:u.userCode}),s.jsx(ve,{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(ve,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{x(),f(null)},children:t("settings.common.actions.cancel")})]})]})]})},Sh=[{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:Qs,label:"Branch"},{key:"briefcase",Icon:Cu,label:"Work"},{key:"house",Icon:ku,label:"Personal"},{key:"graduation",Icon:Su,label:"School"},{key:"code",Icon:uc,label:"Code"}],X4=({open:t,onOpenChange:e,profileId:n,importData:r})=>{const{t:a}=ut(),i=ar(B=>B.getProfileById),o=ar(B=>B.createProfile),c=ar(B=>B.updateProfile),d=ar(B=>B.deleteProfile),p=l.useMemo(()=>n&&n!=="new"&&!r?i(n):null,[n,i,r]),m=n==="new"||r!=null,u=n==="global",[f,y]=l.useState(""),[h,b]=l.useState(""),[x,g]=l.useState(""),[w,v]=l.useState("ssh"),[S,P]=l.useState(""),[j,C]=l.useState(""),[I,R]=l.useState("keyword"),[k,A]=l.useState("branch"),[N,D]=l.useState(!1),[T,M]=l.useState(!1),[$,F]=l.useState(!1);l.useEffect(()=>{if(t){if(r){const B=r.host.split("/"),re=B.length>=3?B[B.length-1]:r.host;y(re),b(r.username),g(""),v("token"),P(""),C(r.host),R("string"),A("code")}else if(m)y(""),b(""),g(""),v("ssh"),P(""),C(""),R("keyword"),A("branch");else if(p)y(p.name),b(p.userName),g(p.userEmail),v(p.authType||"ssh"),P(p.sshKey||""),C(p.host||""),R(p.color||"keyword"),A(p.icon||"branch");else if(u){const B=i("global");B&&(y(B.name),b(B.userName),g(B.userEmail),v(B.authType||"ssh"),P(B.sshKey||""),C(B.host||""),R(B.color||"keyword"),A(B.icon||"branch"))}}},[t,n,p,m,r,u,i]);const _=async()=>{if(!h.trim()||!x.trim()){q.error(a("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(w==="token"&&!j.trim()){q.error(a("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}D(!0);try{const B={name:f.trim()||h.trim(),userName:h.trim(),userEmail:x.trim(),authType:w,sshKey:w==="ssh"&&S.trim()||null,host:w==="token"&&j.trim()||null,color:I,icon:k};let re;if(m)re=await o(B);else if(n)re=await c(n,B);else return;re?(q.success(a(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):q.error(a(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(B){console.error("Error saving profile:",B),q.error(a("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{D(!1)}},O=async()=>{if(!(!n||m)){F(!0);try{await d(n)?(q.success(a("settings.gitIdentities.editor.toast.profileDeleted")),M(!1),e(!1)):q.error(a("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(B){console.error("Error deleting profile:",B),q.error(a("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{F(!1)}}},L=l.useMemo(()=>Sh.find(re=>re.key===I)?.cssVar||"var(--syntax-keyword)",[I]),K=r?a("settings.gitIdentities.editor.title.importCredential"):m?a("settings.gitIdentities.editor.title.newIdentity"):u?a("settings.gitIdentities.editor.title.globalIdentity"):p?.name||a("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:K}),s.jsx(Fs,{children:a(u?"settings.gitIdentities.editor.description.globalReadOnly":m?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!u&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-ui-label text-foreground block mb-1.5",children:a("settings.gitIdentities.editor.field.profileName")}),s.jsx(Bt,{value:f,onChange:B=>y(B.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:Sh.map(B=>s.jsx("button",{type:"button",onClick:()=>R(B.key),className:me("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",I===B.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:B.cssVar},title:B.label},B.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(B=>{const re=B.Icon;return s.jsx("button",{type:"button",onClick:()=>A(B.key),className:me("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",k===B.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:B.label,children:s.jsx(re,{className:"w-3.5 h-3.5",style:{color:k===B.key?L:"var(--surface-muted-foreground)"}})},B.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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.userNameTooltip")})]})]}),s.jsx(Bt,{value:h,onChange:B=>b(B.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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.emailAddressTooltip")})]})]}),s.jsx(Bt,{type:"email",value:x,onChange:B=>g(B.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(ve,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="ssh",onClick:()=>v("ssh"),children:[s.jsx(Py,{className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(ve,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="token",onClick:()=>v("token"),children:[s.jsx(Dy,{className:"w-3.5 h-3.5 mr-1"})," ",a("settings.gitIdentities.editor.field.authToken")]})]})]}),w==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]})]}),s.jsx(Bt,{value:S,onChange:B=>P(B.target.value),placeholder:a("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),w==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.hostTooltip")})]})]}),s.jsx(Bt,{value:j,onChange:B=>C(B.target.value),placeholder:a("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(Xs,{className:"gap-2",children:[!u&&!m&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>M(!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(an,{className:"w-3.5 h-3.5 mr-1"})," ",a("settings.common.actions.delete")]}),s.jsx(ve,{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(ve,{size:"sm",onClick:_,disabled:N,children:a(N?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(ws,{open:T,onOpenChange:B=>{$||M(B)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:a("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Fs,{children:a("settings.gitIdentities.page.deleteDialog.description",{name:p?.name||f})})]}),s.jsxs(Xs,{children:[s.jsx(ve,{variant:"ghost",onClick:()=>M(!1),disabled:$,children:a("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",variant:"destructive",onClick:()=>{O()},disabled:$,children:a("settings.common.actions.delete")})]})]})})]})},Z4={branch:Qs,briefcase:Cu,house:ku,graduation:Su,code:uc,heart:Lf},eI={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},tI=()=>{const t=nt.c(116),{t:e}=ut(),{profiles:n,globalIdentity:r,defaultGitIdentityId:a,deleteProfile:i,loadProfiles:o,loadGlobalIdentity:c,loadDiscoveredCredentials:d,loadDefaultGitIdentityId:p,setDefaultGitIdentityId:m,getUnimportedCredentials:u}=ar(Sr(nI)),[f,y]=l.useState(!1),[h,b]=l.useState(null),[x,g]=l.useState(null),[w,v]=l.useState(null),[S,P]=l.useState(!1);let j,C;t[0]!==p||t[1]!==d||t[2]!==c||t[3]!==o?(j=()=>{o(),c(),d(),p()},C=[o,c,d,p],t[0]=p,t[1]=d,t[2]=c,t[3]=o,t[4]=j,t[5]=C):(j=t[4],C=t[5]),l.useEffect(j,C);let I,R,k,A,N,D,T,M,$,F,_,O,L;if(t[6]!==a||t[7]!==w||t[8]!==i||t[9]!==u||t[10]!==r||t[11]!==n||t[12]!==m||t[13]!==e){const X=u();let he;t[27]===Symbol.for("react.memo_cache_sentinel")?(he=(V,de)=>{b(V),g(de??null),y(!0)},t[27]=he):he=t[27];const je=he;let be;t[28]!==a||t[29]!==m||t[30]!==e?(be=async V=>{const de=a===V?null:V;if(!await m(de)){q.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}q.success(e(de?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[28]=a,t[29]=m,t[30]=e,t[31]=be):be=t[31];const fe=be;let Pe;t[32]!==w||t[33]!==i||t[34]!==e?(Pe=async()=>{if(!w)return;P(!0),await i(w.id)?(q.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:w.name})),v(null)):q.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),P(!1)},t[32]=w,t[33]=i,t[34]=e,t[35]=Pe):Pe=t[35],R=Pe,I=Ps,A="h-full",N="w-full bg-background",L="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")?(k=s.jsx(_x,{}),t[36]=k):k=t[36],_="border-t border-border/40 pt-6";let Be;t[37]!==e?(Be=e("settings.gitIdentities.page.section.title"),t[37]=e,t[38]=Be):Be=t[38];let G;t[39]!==Be?(G=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:Be})}),t[39]=Be,t[40]=G):G=t[40];let ke,Ee;t[41]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>je("new"),Ee=s.jsx(zs,{className:"w-3.5 h-3.5 mr-1"}),t[41]=ke,t[42]=Ee):(ke=t[41],Ee=t[42]);let Ae;t[43]!==e?(Ae=e("settings.common.badge.new"),t[43]=e,t[44]=Ae):Ae=t[44];let xe;t[45]!==Ae?(xe=s.jsxs(ve,{size:"sm",variant:"outline",onClick:ke,children:[Ee," ",Ae]}),t[45]=Ae,t[46]=xe):xe=t[46],t[47]!==G||t[48]!==xe?(O=s.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[G,xe]}),t[47]=G,t[48]=xe,t[49]=O):O=t[49],D="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",T=r&&s.jsx(kh,{profile:r,isDefault:a==="global",onEdit:()=>je("global"),onToggleDefault:()=>fe("global"),isReadOnly:!0,hasBorder:n.length>0||X.length>0}),M=n.map((V,de)=>s.jsx(kh,{profile:V,isDefault:a===V.id,onEdit:()=>je(V.id),onToggleDefault:()=>fe(V.id),onDelete:()=>v(V),hasBorder:de<n.length-1||X.length>0},V.id)),$=!r&&n.length===0&&X.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(Ty,{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")})]}),F=X.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")})}),X.map((V,de)=>s.jsx(sI,{credential:V,onImport:()=>je("new",{host:V.host,username:V.username}),hasBorder:de<X.length-1},`${V.host}-${V.username}`))]}),t[6]=a,t[7]=w,t[8]=i,t[9]=u,t[10]=r,t[11]=n,t[12]=m,t[13]=e,t[14]=I,t[15]=R,t[16]=k,t[17]=A,t[18]=N,t[19]=D,t[20]=T,t[21]=M,t[22]=$,t[23]=F,t[24]=_,t[25]=O,t[26]=L}else I=t[14],R=t[15],k=t[16],A=t[17],N=t[18],D=t[19],T=t[20],M=t[21],$=t[22],F=t[23],_=t[24],O=t[25],L=t[26];let K;t[50]!==D||t[51]!==T||t[52]!==M||t[53]!==$||t[54]!==F?(K=s.jsxs("div",{className:D,children:[T,M,$,F]}),t[50]=D,t[51]=T,t[52]=M,t[53]=$,t[54]=F,t[55]=K):K=t[55];let B;t[56]!==K||t[57]!==_||t[58]!==O?(B=s.jsxs("div",{className:_,children:[O,K]}),t[56]=K,t[57]=_,t[58]=O,t[59]=B):B=t[59];let re;t[60]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx(Bx,{}),t[60]=re):re=t[60];let oe;t[61]!==k||t[62]!==B||t[63]!==L?(oe=s.jsxs("div",{className:L,children:[k,B,re]}),t[61]=k,t[62]=B,t[63]=L,t[64]=oe):oe=t[64];let ee;t[65]!==I||t[66]!==A||t[67]!==N||t[68]!==oe?(ee=s.jsx(I,{outerClassName:A,className:N,children:oe}),t[65]=I,t[66]=A,t[67]=N,t[68]=oe,t[69]=ee):ee=t[69];let ae;t[70]!==x||t[71]!==f||t[72]!==h?(ae=s.jsx(X4,{open:f,onOpenChange:y,profileId:h,importData:x}),t[70]=x,t[71]=f,t[72]=h,t[73]=ae):ae=t[73];const ge=w!==null;let ne;t[74]!==S?(ne=X=>{S||X||v(null)},t[74]=S,t[75]=ne):ne=t[75];let E;t[76]!==e?(E=e("settings.gitIdentities.page.deleteDialog.title"),t[76]=e,t[77]=E):E=t[77];let z;t[78]!==E?(z=s.jsx(js,{children:E}),t[78]=E,t[79]=z):z=t[79];const J=w?.name??"";let H;t[80]!==e||t[81]!==J?(H=e("settings.gitIdentities.page.deleteDialog.description",{name:J}),t[80]=e,t[81]=J,t[82]=H):H=t[82];let te;t[83]!==H?(te=s.jsx(Fs,{children:H}),t[83]=H,t[84]=te):te=t[84];let ce;t[85]!==z||t[86]!==te?(ce=s.jsxs(Cs,{children:[z,te]}),t[85]=z,t[86]=te,t[87]=ce):ce=t[87];let Se;t[88]===Symbol.for("react.memo_cache_sentinel")?(Se=()=>v(null),t[88]=Se):Se=t[88];let pe;t[89]!==e?(pe=e("settings.common.actions.cancel"),t[89]=e,t[90]=pe):pe=t[90];let we;t[91]!==S||t[92]!==pe?(we=s.jsx(ve,{variant:"ghost",onClick:Se,disabled:S,children:pe}),t[91]=S,t[92]=pe,t[93]=we):we=t[93];let W;t[94]!==R?(W=()=>{R()},t[94]=R,t[95]=W):W=t[95];let ue;t[96]!==e?(ue=e("settings.common.actions.delete"),t[96]=e,t[97]=ue):ue=t[97];let Y;t[98]!==S||t[99]!==W||t[100]!==ue?(Y=s.jsx(ve,{size:"sm",variant:"destructive",onClick:W,disabled:S,children:ue}),t[98]=S,t[99]=W,t[100]=ue,t[101]=Y):Y=t[101];let le;t[102]!==we||t[103]!==Y?(le=s.jsxs(Xs,{children:[we,Y]}),t[102]=we,t[103]=Y,t[104]=le):le=t[104];let Z;t[105]!==ce||t[106]!==le?(Z=s.jsxs(vs,{className:"max-w-md",children:[ce,le]}),t[105]=ce,t[106]=le,t[107]=Z):Z=t[107];let Ie;t[108]!==ge||t[109]!==ne||t[110]!==Z?(Ie=s.jsx(ws,{open:ge,onOpenChange:ne,children:Z}),t[108]=ge,t[109]=ne,t[110]=Z,t[111]=Ie):Ie=t[111];let Ne;return t[112]!==ee||t[113]!==ae||t[114]!==Ie?(Ne=s.jsxs(s.Fragment,{children:[ee,ae,Ie]}),t[112]=ee,t[113]=ae,t[114]=Ie,t[115]=Ne):Ne=t[115],Ne},kh=t=>{const e=nt.c(54),{profile:n,isDefault:r,onEdit:a,onToggleDefault:i,onDelete:o,isReadOnly:c,hasBorder:d}=t,{t:p}=ut(),m=Z4[n.icon||"branch"]||Qs,u=eI[n.color||""],f=n.authType||"ssh",y=d&&"border-b border-[var(--surface-subtle)]";let h;e[0]!==y?(h=me("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",y),e[0]=y,e[1]=h):h=e[1];let b;e[2]!==a?(b=_=>{(_.key==="Enter"||_.key===" ")&&a()},e[2]=a,e[3]=b):b=e[3];let x;e[4]!==u?(x={color:u},e[4]=u,e[5]=x):x=e[5];let g;e[6]!==m||e[7]!==x?(g=s.jsx(m,{className:"w-4 h-4 shrink-0",style:x}),e[6]=m,e[7]=x,e[8]=g):g=e[8];let w;e[9]!==n.name?(w=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:n.name}),e[9]=n.name,e[10]=w):w=e[10];let v;e[11]!==f?(v=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:f}),e[11]=f,e[12]=v):v=e[12];let S;e[13]!==r||e[14]!==p?(S=r&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:p("settings.gitIdentities.page.badge.default")}),e[13]=r,e[14]=p,e[15]=S):S=e[15];let P;e[16]!==c||e[17]!==p?(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("settings.agents.sidebar.badge.system")}),e[16]=c,e[17]=p,e[18]=P):P=e[18];let j;e[19]!==w||e[20]!==v||e[21]!==S||e[22]!==P?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,v,S,P]}),e[19]=w,e[20]=v,e[21]=S,e[22]=P,e[23]=j):j=e[23];const C=f==="token"&&n.host?n.host:n.userEmail;let I;e[24]!==C?(I=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:C}),e[24]=C,e[25]=I):I=e[25];let R;e[26]!==j||e[27]!==I?(R=s.jsxs("div",{className:"min-w-0",children:[j,I]}),e[26]=j,e[27]=I,e[28]=R):R=e[28];let k;e[29]!==R||e[30]!==g?(k=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[g,R]}),e[29]=R,e[30]=g,e[31]=k):k=e[31];let A;e[32]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx($s,{asChild:!0,children:s.jsx(ve,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:rI,children:s.jsx(la,{className:"h-3.5 w-3.5"})})}),e[32]=A):A=e[32];let N;e[33]!==i?(N=_=>{_.stopPropagation(),i()},e[33]=i,e[34]=N):N=e[34];let D;e[35]!==r||e[36]!==p?(D=p(r?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault"),e[35]=r,e[36]=p,e[37]=D):D=e[37];let T;e[38]!==N||e[39]!==D?(T=s.jsx(Lt,{onClick:N,children:D}),e[38]=N,e[39]=D,e[40]=T):T=e[40];let M;e[41]!==c||e[42]!==o||e[43]!==p?(M=!c&&o&&s.jsxs(Lt,{onClick:_=>{_.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[s.jsx(an,{className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]}),e[41]=c,e[42]=o,e[43]=p,e[44]=M):M=e[44];let $;e[45]!==T||e[46]!==M?($=s.jsxs(_s,{children:[A,s.jsxs(Bs,{align:"end",className:"w-fit min-w-28",children:[T,M]})]}),e[45]=T,e[46]=M,e[47]=$):$=e[47];let F;return e[48]!==a||e[49]!==k||e[50]!==h||e[51]!==$||e[52]!==b?(F=s.jsxs("div",{className:h,onClick:a,role:"button",tabIndex:0,onKeyDown:b,children:[k,$]}),e[48]=a,e[49]=k,e[50]=h,e[51]=$,e[52]=b,e[53]=F):F=e[53],F},sI=t=>{const e=nt.c(21),{credential:n,onImport:r,hasBorder:a}=t,{t:i}=ut();let o;e[0]!==n.host?(o=n.host.split("/"),e[0]=n.host,e[1]=o):o=e[1];const c=o,d=c.length>=3?c[c.length-1]:n.host,p=n.host.includes("/"),m=a&&"border-b border-[var(--surface-subtle)]";let u;e[2]!==m?(u=me("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",m),e[2]=m,e[3]=u):u=e[3];let f;e[4]!==d?(f=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:d}),e[4]=d,e[5]=f):f=e[5];const y=p?n.host:n.username;let h;e[6]!==y?(h=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:y}),e[6]=y,e[7]=h):h=e[7];let b;e[8]!==f||e[9]!==h?(b=s.jsxs("div",{className:"min-w-0",children:[f,h]}),e[8]=f,e[9]=h,e[10]=b):b=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(Xr,{className:"h-3 w-3"}),e[11]=x):x=e[11];let g;e[12]!==i?(g=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=g):g=e[13];let w;e[14]!==r||e[15]!==g?(w=s.jsxs(ve,{size:"sm",variant:"ghost",onClick:r,className:"gap-1 shrink-0",children:[x,g]}),e[14]=r,e[15]=g,e[16]=w):w=e[16];let v;return e[17]!==w||e[18]!==u||e[19]!==b?(v=s.jsxs("div",{className:u,children:[b,w]}),e[17]=w,e[18]=u,e[19]=b,e[20]=v):v=e[20],v};function nI(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 rI(t){return t.stopPropagation()}const Vx=()=>{const t=N1();return{displayMode:t,installed:t!=="browser",browserTab:t==="browser"}},zx=()=>{const t=nt.c(2),[e,n]=l.useState(aI);let r,a;return t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const i=[window.matchMedia("(display-mode: standalone)"),window.matchMedia("(display-mode: minimal-ui)"),window.matchMedia("(display-mode: fullscreen)"),window.matchMedia("(display-mode: window-controls-overlay)")],o=()=>{n(Vx())};o();for(const c of i)c.addEventListener("change",o);return window.addEventListener("appinstalled",o),window.addEventListener("focus",o),()=>{for(const c of i)c.removeEventListener("change",o);window.removeEventListener("appinstalled",o),window.removeEventListener("focus",o)}},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),l.useEffect(r,a),e};function aI(){return Vx()}const iI=[{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"}],oI=[{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"}],lI=[{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"}],cI=[{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"}],mo="OpenChamber - AI Coding Assistant",Ch=[{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"}],Ih=[{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"}],fd=t=>t==="portrait"||t==="landscape"?t:"system",dI=[{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"}],uI=[{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"}],Ah=[{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"}],mI=[{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"}],Ph=[{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"}],Dh=[{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"}],pI=t=>t==="markdown"?"markdown":"plain",sm=({visibleSettings:t})=>{const{locale:e,locales:n,setLocale:r,label:a,t:i}=ut(),o=l.useCallback(Q=>i(Q),[i]),{isMobile:c}=dn(),{browserTab:d}=zx(),p=yc(),m=De(Q=>Q.showReasoningTraces),u=De(Q=>Q.setShowReasoningTraces),f=De(Q=>Q.mermaidRenderingMode),y=De(Q=>Q.setMermaidRenderingMode),h=De(Q=>Q.userMessageRenderingMode),b=De(Q=>Q.setUserMessageRenderingMode),x=De(Q=>Q.stickyUserHeader),g=De(Q=>Q.setStickyUserHeader),w=De(Q=>Q.wideChatLayoutEnabled),v=De(Q=>Q.setWideChatLayoutEnabled),S=De(Q=>Q.chatRenderMode),P=De(Q=>Q.setChatRenderMode),j=De(Q=>Q.activityRenderMode),C=De(Q=>Q.setActivityRenderMode),I=De(Q=>Q.fontSize),R=De(Q=>Q.setFontSize),k=De(Q=>Q.terminalFontSize),A=De(Q=>Q.setTerminalFontSize),N=De(Q=>Q.uiFont),D=De(Q=>Q.setUiFont),T=De(Q=>Q.monoFont),M=De(Q=>Q.setMonoFont),$=De(Q=>Q.padding),F=De(Q=>Q.setPadding),_=De(Q=>Q.inputBarOffset),O=De(Q=>Q.setInputBarOffset),L=De(Q=>Q.mobileKeyboardMode),K=De(Q=>Q.setMobileKeyboardMode),B=De(Q=>Q.diffLayoutPreference),re=De(Q=>Q.setDiffLayoutPreference),oe=De(Q=>Q.diffViewMode),ee=De(Q=>Q.setDiffViewMode),ae=De(Q=>Q.showTerminalQuickKeysOnDesktop),ge=De(Q=>Q.setShowTerminalQuickKeysOnDesktop),ne=Pm(Q=>Q.queueModeEnabled),E=Pm(Q=>Q.setQueueMode),z=De(Q=>Q.persistChatDraft),J=De(Q=>Q.setPersistChatDraft),H=De(Q=>Q.inputSpellcheckEnabled),te=De(Q=>Q.setInputSpellcheckEnabled),ce=De(Q=>Q.showToolFileIcons),Se=De(Q=>Q.setShowToolFileIcons),pe=De(Q=>Q.showExpandedBashTools),we=De(Q=>Q.setShowExpandedBashTools),W=De(Q=>Q.showExpandedEditTools),ue=De(Q=>Q.setShowExpandedEditTools),Y=De(Q=>Q.timeFormatPreference),le=De(Q=>Q.setTimeFormatPreference),Z=De(Q=>Q.weekStartPreference),Ie=De(Q=>Q.setWeekStartPreference),Ne=De(Q=>Q.showSplitAssistantMessageActions),X=De(Q=>Q.setShowSplitAssistantMessageActions),he=De(Q=>Q.showMobileSessionStatusBar),je=De(Q=>Q.setShowMobileSessionStatusBar),be=yt(Q=>Q.settingsMessageStreamTransport),fe=yt(Q=>Q.setSettingsMessageStreamTransport),Pe=De(Q=>Q.isSettingsDialogOpen),{themeMode:Be,setThemeMode:G,availableThemes:ke,customThemesLoading:Ee,reloadCustomThemes:Ae,lightThemeId:xe,darkThemeId:V,setLightThemePreference:de,setDarkThemePreference:Me}=Er(),[Le,se]=l.useState(!1),[ie,U]=l.useState(0),Ve=De(Q=>Q.reportUsage),He=De(Q=>Q.setReportUsage),Ke=l.useCallback(Q=>{He(Q),As({reportUsage:Q})},[He]),Ze=Pe&&(t?t.includes("chatRenderMode"):!0);l.useEffect(()=>{if(!Ze)return;let Q=null,ht=Date.now();const vt=()=>{const ss=Date.now();ss-ht>=420&&(U(is=>(is+1)%24),ht=ss),Q=requestAnimationFrame(vt)};(typeof document>"u"||document.visibilityState==="visible")&&(Q=requestAnimationFrame(vt));const zt=()=>{document.visibilityState==="visible"&&Q===null?Q=requestAnimationFrame(vt):document.visibilityState!=="visible"&&Q!==null&&(cancelAnimationFrame(Q),Q=null)};return document.addEventListener("visibilitychange",zt),()=>{document.removeEventListener("visibilitychange",zt),Q!==null&&cancelAnimationFrame(Q)}},[Ze]);const Xe=l.useCallback(Q=>{b(Q),As({userMessageRenderingMode:Q})},[b]),dt=l.useCallback(Q=>{g(Q),As({stickyUserHeader:Q})},[g]),et=l.useCallback(Q=>{v(Q),As({wideChatLayoutEnabled:Q})},[v]),ct=l.useCallback(Q=>{X(Q),As({showSplitAssistantMessageActions:Q})},[X]),at=l.useCallback(Q=>{te(Q),As({inputSpellcheckEnabled:Q})},[te]),ye=l.useCallback(Q=>{P(Q),As({chatRenderMode:Q})},[P]),Ge=l.useCallback(Q=>{fe(Q),As({messageStreamTransport:Q})},[fe]),$e=l.useCallback(Q=>{C(Q),As({activityRenderMode:Q})},[C]),_e=l.useCallback(Q=>{y(Q),As({mermaidRenderingMode:Q})},[y]),tt=l.useCallback(Q=>{Se(Q),As({showToolFileIcons:Q})},[Se]),Qe=l.useCallback(Q=>{we(Q),As({showExpandedBashTools:Q})},[we]),ze=l.useCallback(Q=>{ue(Q),As({showExpandedEditTools:Q})},[ue]),gt=l.useCallback(Q=>{le(Q),As({timeFormatPreference:Q})},[le]),Vt=l.useCallback(Q=>{Ie(Q),As({weekStartPreference:Q})},[Ie]),Kt=l.useMemo(()=>ke.filter(Q=>Q.metadata.variant==="light").sort((Q,ht)=>Q.metadata.name.localeCompare(ht.metadata.name)),[ke]),Jt=l.useMemo(()=>ke.filter(Q=>Q.metadata.variant==="dark").sort((Q,ht)=>Q.metadata.name.localeCompare(ht.metadata.name)),[ke]),At=l.useMemo(()=>Kt.find(Q=>Q.metadata.id===xe)??Kt[0],[Kt,xe]),jt=l.useMemo(()=>Jt.find(Q=>Q.metadata.id===V)??Jt[0],[Jt,V]),ns=l.useCallback((Q,ht)=>{const vt=ht==="dark"?" Dark":" Light";return Q.endsWith(vt)?Q.slice(0,-vt.length):Q},[]),ot=Q=>t?t.includes(Q):!0,Zt=jn(),Yt=ot("theme")&&!Zt,es=ot("theme")||ot("timeFormat")||ot("weekStart"),ls=Zt?es:ot("theme")||ot("pwaInstallName")||ot("pwaOrientation")||ot("timeFormat")||ot("weekStart"),ds=ot("fontSize")||ot("terminalFontSize")||ot("spacing")||ot("inputBarOffset"),gs=ot("terminalQuickKeys")&&!c,us=ot("mermaidRendering")||ot("userMessageRendering")||ot("chatRenderMode")||ot("messageTransport")||ot("activityRenderMode")&&S==="sorted"||ot("stickyUserHeader")||ot("wideChatLayout")||ot("splitAssistantMessageActions")||ot("diffLayout")||ot("mobileStatusBar")&&c||ot("dotfiles")||ot("reasoning")||ot("queueMode")||ot("persistDraft")||ot("showToolFileIcons")||ot("expandedTools")||!c&&ot("inputSpellcheck"),Ct=ot("pwaInstallName")&&Sa()&&d&&!Pn()&&!Zt,Ue=ot("pwaOrientation")&&Sa()&&!Pn()&&!Zt,Dt=ot("mobileKeyboardMode")&&Sa()&&!Pn()&&!Zt&&S1(),[Tt,wt]=l.useState(""),[Wt,_t]=l.useState("system"),Vs=l.useMemo(()=>{const Q=Ph.find(ht=>ht.id===Y);return o(Q?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Y,o]),mt=l.useMemo(()=>{const Q=Dh.find(ht=>ht.id===Z);return o(Q?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[Z,o]),cs=l.useMemo(()=>{const Q=Ch.find(ht=>ht.id===Wt);return Q?o(Q.labelKey):void 0},[Wt,o]),qt=l.useMemo(()=>{const Q=Ih.find(ht=>ht.id===L);return Q?o(Q.labelKey):void 0},[L,o]),Ds=l.useCallback(async Q=>{if(typeof window>"u")return;const ht=window,zt=Q.trim().replace(/\s+/g," ").slice(0,64);if(await As({pwaAppName:zt}),typeof ht.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const ss=ht.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(zt);wt(ss);return}wt(zt||mo),ht.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Os=l.useCallback(async Q=>{if(typeof window>"u")return;const ht=window,vt=fd(Q);if(await As({pwaOrientation:vt}),typeof ht.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const zt=ht.__OPENCHAMBER_SET_PWA_ORIENTATION__(vt);_t(zt);return}_t(vt),ht.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return l.useEffect(()=>{if(typeof window>"u"||!Ct&&!Ue&&!Dt)return;let Q=!1;return(async()=>{try{const vt=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!vt.ok){Q||wt(mo);return}const zt=await vt.json().catch(()=>({})),is=(typeof zt?.pwaAppName=="string"?zt.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Ss=fd(zt?.pwaOrientation),Ms=Em(zt?.mobileKeyboardMode);Q||(Ct&&wt(is||mo),Ue&&_t(Ss),Dt&&K(Ms))}catch{Q||(Ct&&wt(mo),Ue&&_t("system"),Dt&&K("native"))}})(),()=>{Q=!0}},[K,Dt,Ct,Ue]),s.jsxs("div",{className:"space-y-8",children:[ls&&s.jsxs("div",{className:"mb-8 space-y-6",children:[Yt&&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:iI.map(Q=>s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":Be===Q.value,className:"!font-normal",onClick:()=>G(Q.value),children:o(Q.labelKey)},Q.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(ps,{value:At?.metadata.id??"",onValueChange:de,children:[s.jsx(hs,{"aria-label":i("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:s.jsx(ys,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:At?ns(At.metadata.name,"light"):void 0})}),s.jsx(fs,{children:Kt.map(Q=>s.jsx(Rt,{value:Q.metadata.id,children:ns(Q.metadata.name,"light")},Q.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(ps,{value:jt?.metadata.id??"",onValueChange:Me,children:[s.jsx(hs,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:s.jsx(ys,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:jt?ns(jt.metadata.name,"dark"):void 0})}),s.jsx(fs,{children:Jt.map(Q=>s.jsx(Rt,{value:Q.metadata.id,children:ns(Q.metadata.name,"dark")},Q.metadata.id))})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("button",{type:"button",disabled:Ee||Le,onClick:()=>{const Q=Date.now();se(!0),Ae().finally(()=>{const ht=Date.now()-Q;if(ht<500){window.setTimeout(()=>{se(!1)},500-ht);return}se(!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(Le?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")}),s.jsxs(St,{children:[s.jsx(kt,{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(Us,{className:"h-3.5 w-3.5"})})}),s.jsx(It,{sideOffset:8,children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),es&&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(ps,{value:e,onValueChange:Q=>r(Q),children:[s.jsx(hs,{"aria-label":i("settings.appearance.language.select"),className:"w-fit",children:s.jsx(ys,{children:a(e)})}),s.jsx(fs,{children:n.map(Q=>s.jsx(Rt,{value:Q,children:a(Q)},Q))})]})]}),!Zt&&(ot("timeFormat")||ot("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:[ot("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(ps,{value:Y,onValueChange:Q=>gt(Q),children:[s.jsx(hs,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:s.jsx(ys,{children:Vs})}),s.jsx(fs,{children:Ph.map(Q=>s.jsx(Rt,{value:Q.id,children:o(Q.labelKey)},Q.id))})]})]}),ot("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(ps,{value:Z,onValueChange:Q=>Vt(Q),children:[s.jsx(hs,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:s.jsx(ys,{children:mt})}),s.jsx(fs,{children:Dh.map(Q=>s.jsx(Rt,{value:Q.id,children:o(Q.labelKey)},Q.id))})]})]})]})]}),(Ct||Ue||Dt)&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[Ct&&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(Bt,{value:Tt,onChange:Q=>{wt(Q.target.value)},onBlur:()=>{Ds(Tt)},onKeyDown:Q=>{Q.key==="Enter"&&(Q.preventDefault(),Ds(Tt))},className:"h-7",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>{wt(mo),Ds("")},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(Fn,{className:"h-3.5 w-3.5"})})]})]}),Ue&&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(ps,{value:Wt,onValueChange:Q=>{const ht=fd(Q);_t(ht),Os(ht)},children:[s.jsx(hs,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),className:"w-full",children:s.jsx(ys,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:cs})}),s.jsx(fs,{children:Ch.map(Q=>s.jsx(Rt,{value:Q.id,children:o(Q.labelKey)},Q.id))})]}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>{_t("system"),Os("system")},disabled:Wt==="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(Fn,{className:"h-3.5 w-3.5"})})]})]}),Dt&&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(ps,{value:L,onValueChange:Q=>{const ht=Em(Q);K(ht),As({mobileKeyboardMode:ht})},children:[s.jsx(hs,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),className:"w-full",children:s.jsx(ys,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:qt})}),s.jsx(fs,{children:Ih.map(Q=>s.jsx(Rt,{value:Q.id,children:o(Q.labelKey)},Q.id))})]}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>{K("native"),As({mobileKeyboardMode:"native"})},disabled:L==="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(Fn,{className:"h-3.5 w-3.5"})})]})]})]})]}),ds&&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:[ot("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(ps,{value:N,onValueChange:Q=>D(Q),children:[s.jsx(hs,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:s.jsx(ys,{children:Dm.find(Q=>Q.id===N)?.label})}),s.jsx(fs,{children:Dm.map(Q=>s.jsx(Rt,{value:Q.id,children:s.jsx("span",{style:{fontFamily:Q.stack},children:Q.label})},Q.id))})]}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>D(Tm),disabled:N===Tm,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(Fn,{className:"h-3.5 w-3.5"})})]})]}),ot("terminalFontSize")&&s.jsxs("div",{className:me("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:me("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.codeFont")})}),s.jsxs("div",{className:me("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsxs(ps,{value:T,onValueChange:Q=>M(Q),children:[s.jsx(hs,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:s.jsx(ys,{children:Mm.find(Q=>Q.id===T)?.label})}),s.jsx(fs,{children:Mm.map(Q=>s.jsx(Rt,{value:Q.id,children:s.jsx("span",{style:{fontFamily:Q.stack},children:Q.label})},Q.id))})]}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>M(Rm),disabled:T===Rm,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(Fn,{className:"h-3.5 w-3.5"})})]})]}),ot("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(Cn,{value:I,onValueChange:R,min:50,max:200,step:5,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria"),className:"w-16"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>R(100),disabled:I===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(Fn,{className:"h-3.5 w-3.5"})})]})]}),ot("terminalFontSize")&&s.jsxs("div",{className:me("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:me("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.terminalFontSize")})}),s.jsxs("div",{className:me("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(Cn,{value:k,onValueChange:A,min:9,max:52,step:1,className:"w-16"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>A(13),disabled:k===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(Fn,{className:"h-3.5 w-3.5"})})]})]}),ot("spacing")&&s.jsxs("div",{className:me("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:me("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.spacingDensity")})}),s.jsxs("div",{className:me("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(Cn,{value:$,onValueChange:F,min:50,max:200,step:5,className:"w-16"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>F(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(Fn,{className:"h-3.5 w-3.5"})})]})]}),ot("inputBarOffset")&&s.jsxs("div",{className:me("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:me("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.inputBarOffset")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.inputBarOffsetTooltip")})]})]})}),s.jsxs("div",{className:me("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(Cn,{value:_,onValueChange:O,min:0,max:100,step:5,className:"w-16"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>O(0),disabled:_===0,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:i("settings.common.actions.reset"),children:s.jsx(Fn,{className:"h-3.5 w-3.5"})})]})]})]})]})}),gs&&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")}),ot("terminalQuickKeys")&&!c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ae,onClick:()=>ge(!ae),onKeyDown:Q=>{(Q.key===" "||Q.key==="Enter")&&(Q.preventDefault(),ge(!ae))},children:[s.jsx(bs,{checked:ae,onChange:ge,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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.terminalQuickKeysTooltip")})]})]})]})]})}),us&&s.jsxs("div",{className:"space-y-3",children:[(ot("userMessageRendering")||ot("mermaidRendering")||ot("chatRenderMode")||ot("messageTransport")||ot("activityRenderMode")&&S==="sorted"||ot("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:[ot("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:uI.map(Q=>{const ht=S===Q.id,vt=ie%12;return s.jsxs("button",{type:"button",onClick:()=>ye(Q.id),"aria-pressed":ht,className:me("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",ht?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:me("typography-ui-label",ht?"text-foreground":"text-muted-foreground"),children:o(Q.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:Q.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(zt=>{const ss=zt*3+1,is=vt-ss+1,Ss=is<=0?0:is===1?42:is===2?68:92,Ms=Ss>0;return s.jsxs("div",{className:me("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Ms?"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:`${Ss}%`}})]},zt)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(zt=>{const ss=vt>=(zt+1)*3;return s.jsxs("div",{className:me("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",ss?"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%"}})]},zt)})})})]},Q.id)})})]}),ot("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:Ah.map(Q=>s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":be===Q.id,className:"!font-normal",onClick:()=>Ge(Q.id),children:o(Q.labelKey)},Q.id))}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const Q=Ah.find(ht=>ht.id===be);return Q?.descriptionKey?o(Q.descriptionKey):""})()})]})]}),ot("activityRenderMode")&&S==="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:mI.map(Q=>{const ht=j===Q.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ht,onClick:()=>$e(Q.id),onKeyDown:vt=>{(vt.key===" "||vt.key==="Enter")&&(vt.preventDefault(),$e(Q.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ai,{checked:ht,onChange:()=>$e(Q.id),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:o(Q.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ht?"text-foreground":"text-foreground/50"),children:o(Q.labelKey)})]},Q.id)})})]}),ot("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":pe,onClick:()=>Qe(!pe),onKeyDown:Q=>{(Q.key===" "||Q.key==="Enter")&&(Q.preventDefault(),Qe(!pe))},children:[s.jsx(bs,{checked:pe,onChange:Qe,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":W,onClick:()=>ze(!W),onKeyDown:Q=>{(Q.key===" "||Q.key==="Enter")&&(Q.preventDefault(),ze(!W))},children:[s.jsx(bs,{checked:W,onChange:ze,ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editTools")})]})]}),ot("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:dI.map(Q=>{const ht=pI(h)===Q.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ht,onClick:()=>Xe(Q.id),onKeyDown:vt=>{(vt.key===" "||vt.key==="Enter")&&(vt.preventDefault(),Xe(Q.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ai,{checked:ht,onChange:()=>Xe(Q.id),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:o(Q.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ht?"text-foreground":"text-foreground/50"),children:o(Q.labelKey)})]},Q.id)})})]}),ot("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:cI.map(Q=>{const ht=f===Q.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ht,onClick:()=>_e(Q.id),onKeyDown:vt=>{(vt.key===" "||vt.key==="Enter")&&(vt.preventDefault(),_e(Q.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ai,{checked:ht,onChange:()=>_e(Q.id),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:o(Q.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ht?"text-foreground":"text-foreground/50"),children:o(Q.labelKey)})]},Q.id)})})]}),ot("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:oI.map(Q=>{const ht=B===Q.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ht,onClick:()=>re(Q.id),onKeyDown:vt=>{(vt.key===" "||vt.key==="Enter")&&(vt.preventDefault(),re(Q.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ai,{checked:ht,onChange:()=>re(Q.id),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:o(Q.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ht?"text-foreground":"text-foreground/50"),children:o(Q.labelKey)})]},Q.id)})})]}),ot("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:lI.map(Q=>{const ht=oe===Q.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ht,onClick:()=>ee(Q.id),onKeyDown:vt=>{(vt.key===" "||vt.key==="Enter")&&(vt.preventDefault(),ee(Q.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ai,{checked:ht,onChange:()=>ee(Q.id),ariaLabel:i("settings.openchamber.visual.field.diffViewModeAria",{option:o(Q.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ht?"text-foreground":"text-foreground/50"),children:o(Q.labelKey)})]},Q.id)})})]})]}),(ot("stickyUserHeader")||ot("wideChatLayout")||ot("splitAssistantMessageActions")||ot("mobileStatusBar")&&c||ot("dotfiles")||ot("queueMode")||ot("persistDraft")||ot("showToolFileIcons")||!c&&ot("inputSpellcheck")||ot("reasoning"))&&s.jsxs("section",{className:"p-2 space-y-0.5",children:[ot("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:Q=>{(Q.key===" "||Q.key==="Enter")&&(Q.preventDefault(),u(!m))},children:[s.jsx(bs,{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")})]}),ot("stickyUserHeader")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":x,onClick:()=>dt(!x),onKeyDown:Q=>{(Q.key===" "||Q.key==="Enter")&&(Q.preventDefault(),dt(!x))},children:[s.jsx(bs,{checked:x,onChange:dt,ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.stickyUserHeader")})]}),ot("wideChatLayout")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>et(!w),onKeyDown:Q=>{(Q.key===" "||Q.key==="Enter")&&(Q.preventDefault(),et(!w))},children:[s.jsx(bs,{checked:w,onChange:et,ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.wideChatLayout")})]}),ot("splitAssistantMessageActions")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Ne,onClick:()=>ct(!Ne),onKeyDown:Q=>{(Q.key===" "||Q.key==="Enter")&&(Q.preventDefault(),ct(!Ne))},children:[s.jsx(bs,{checked:Ne,onChange:ct,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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")})]})]})]}),ot("showToolFileIcons")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ce,onClick:()=>tt(!ce),onKeyDown:Q=>{(Q.key===" "||Q.key==="Enter")&&(Q.preventDefault(),tt(!ce))},children:[s.jsx(bs,{checked:ce,onChange:tt,ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showToolFileIcons")})]}),ot("mobileStatusBar")&&c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":he,onClick:()=>je(!he),onKeyDown:Q=>{(Q.key===" "||Q.key==="Enter")&&(Q.preventDefault(),je(!he))},children:[s.jsx(bs,{checked:he,onChange:je,ariaLabel:i("settings.openchamber.visual.field.showMobileStatusBarAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showMobileStatusBar")})]}),ot("dotfiles")&&!jn()&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>Cl(!p),onKeyDown:Q=>{(Q.key===" "||Q.key==="Enter")&&(Q.preventDefault(),Cl(!p))},children:[s.jsx(bs,{checked:p,onChange:Cl,ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showDotfiles")})]}),ot("queueMode")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ne,onClick:()=>E(!ne),onKeyDown:Q=>{(Q.key===" "||Q.key==="Enter")&&(Q.preventDefault(),E(!ne))},children:[s.jsx(bs,{checked:ne,onChange:E,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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.queueMessagesByDefaultTooltip",{modifier:Jl()})})]})]})]}),ot("persistDraft")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":z,onClick:()=>J(!z),onKeyDown:Q=>{(Q.key===" "||Q.key==="Enter")&&(Q.preventDefault(),J(!z))},children:[s.jsx(bs,{checked:z,onChange:J,ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.persistDraftMessages")})]}),!c&&ot("inputSpellcheck")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":H,onClick:()=>at(!H),onKeyDown:Q=>{(Q.key===" "||Q.key==="Enter")&&(Q.preventDefault(),at(!H))},children:[s.jsx(bs,{checked:H,onChange:at,ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs")})]})]})]}),ot("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(bs,{checked:Ve,onChange:Ke,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":Ve,onClick:()=>Ke(!Ve),onKeyDown:Q=>{(Q.key===" "||Q.key==="Enter")&&(Q.preventDefault(),Ke(!Ve))},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 hI(){if(typeof window>"u")return"unknown";try{const{deviceType:t}=A1();return t}catch{return"unknown"}}function fI(){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 gI(){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 xI(t){const e=De.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",hI()),n.set("arch",fI()),n.set("platform",gI()),t==="desktop"?(n.set("appType",I1()?"desktop-electron":"desktop-tauri"),n.set("instanceMode",ca()?"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 gd(t,e){try{const n=xI(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 bI(){return ri()?ca()?"desktop":"web":jn()?"vscode":Sa()?"web":null}const Th={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},Ya=Nr()((t,e)=>({...Th,checkForUpdates:async()=>{const n=bI();if(!n)return null;t({checking:!0,error:null,runtimeType:n});try{let r=null,a=null;if(n==="desktop"){let i=await zc();t({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null});const o=await gd("desktop",i?.currentVersion);if(a=o?.nextSuggestedCheckInSec??null,o?.available&&!i?.available){const c=await zc();c&&(i=c)}if(o){const c={...i??{available:!1,currentVersion:o.currentVersion??"unknown"},...o,currentVersion:i?.currentVersion??o.currentVersion??"unknown",available:o.available};t({available:c.available,info:c,nextCheckInSec:a})}else t({nextCheckInSec:a});return a}else n==="web"?(r=await gd("web"),a=r?.nextSuggestedCheckInSec??null):n==="vscode"&&(a=(await gd("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 zc();if(!a?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(t(o=>({info:o.info?{...o.info,...a,body:o.info.body||a.body,available:o.info.available}:a})),!await C1(o=>{t({progress:o})}))throw new Error("Desktop update only works on Local instance");t({downloading:!1,downloaded:!0})}catch(a){t({downloading:!1,error:a instanceof Error?a.message:"Failed to download update"})}}},restartToUpdate:async()=>{const{downloaded:n,runtimeType:r}=e();if(!(r!=="desktop"||!n))try{if(!await k1())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(Th)}})),Mh="https://github.com/btriapitsyn/openchamber/releases";function yI(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 vI(t){return t.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Rh(t){return t.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function wI(t,e){const n=t.split(".").map(a=>Number.parseInt(a,10)),r=e.split(".").map(a=>Number.parseInt(a,10));for(let a=0;a<3;a+=1){const i=Number.isFinite(n[a])?n[a]:0,o=Number.isFinite(r[a])?r[a]:0;if(i!==o)return o-i}return 0}function jI(t){const e=/^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2})\s*$/gm,n=[];let r;for(;(r=e.exec(t))!==null;)n.push({version:r[1]??"",date:r[2]??"",start:r.index});return n.length===0?[]:n.map((a,i)=>{const o=n[i+1]?.start??t.length,c=t.slice(a.start,o).trim();return{version:a.version,date:a.date,start:a.start,end:o,raw:c}})}const Eh=2e3,NI=600*1e3;async function SI(){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 kI(){try{return(await fetch("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function CI(t,e=Math.ceil(NI/Eh),n=Eh){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 kI())return!0}catch{}await new Promise(a=>setTimeout(a,n))}return!1}const cu=({open:t,onOpenChange:e,info:n,downloading:r,downloaded:a,progress:i,error:o,onDownload:c,onRestart:d,runtimeType:p="desktop"})=>{const{t:m}=ut(),[u,f]=Oe.useState(!1),[y,h]=Oe.useState("idle"),[b,x]=Oe.useState(null),g=n?.version?`${Mh}/tag/v${n.version}`:Mh,w=i?.total?Math.round(i.downloaded/i.total*100):0,v=p==="web",S=n?.updateCommand||"openchamber update";Oe.useEffect(()=>{t||(h("idle"),x(null))},[t]);const P=async()=>{(await Wn(S)).ok&&(f(!0),setTimeout(()=>f(!1),2e3))},j=Oe.useCallback(async k=>{await mr(k)},[]),C=Oe.useCallback(async()=>{h("updating"),x(null);const k=await SI();if(!k.success){h("error"),x(k.error||m("updateDialog.error.updateFailed"));return}k.autoRestart&&(h("restarting"),await new Promise(N=>setTimeout(N,2e3))),h("reconnecting"),await CI(n?.currentVersion)?window.location.reload():(h("error"),x(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),I=y!=="idle"&&y!=="error",R=Oe.useMemo(()=>{if(!n?.body)return null;const k=n.body.trim();if(!k)return null;const A=jI(k);if(A.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:Rh(k)};const N=[...A].sort((D,T)=>wI(D.version,T.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:N.map(D=>({version:D.version,dateLabel:yI(D.date),content:Rh(vI(D.raw)||k)}))}},[n?.body,m]);return s.jsx(ws,{open:t,onOpenChange:I?void 0:e,children:s.jsxs(vs,{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(js,{className:"flex items-center gap-2.5",children:[s.jsx(My,{className:"h-5 w-5 text-[var(--primary-base)]"}),s.jsx("span",{className:"text-lg font-semibold text-foreground",children:m(y==="restarting"||y==="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(Sl,{className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),s.jsxs("div",{className:"typography-ui-label text-foreground",children:[y==="updating"&&m("updateDialog.status.installingUpdate"),y==="restarting"&&m("updateDialog.status.serverRestarting"),y==="reconnecting"&&m("updateDialog.status.waitingForServer")]})]}),s.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:m("updateDialog.status.autoReloadHint")})]}),R&&!I&&s.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:s.jsx(Ps,{className:"max-h-[400px] p-0",fillContainer:!1,children:R.kind==="raw"?s.jsx("div",{className:"p-4 typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline hover:[&_a]:!underline",onClickCapture:k=>{const N=k.target.closest("a");N&&N.href&&(k.preventDefault(),k.stopPropagation(),j(N.href))},children:s.jsx(ai,{content:R.content,disableLinkSafety:!0})}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:R.sections.map(k=>s.jsxs("div",{className:"p-4 hover:bg-background/40 transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[s.jsxs("span",{className:"typography-ui-label font-mono text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:["v",k.version]}),s.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:k.dateLabel})]}),s.jsx("div",{className:"typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline hover:[&_a]:!underline",onClickCapture:A=>{const D=A.target.closest("a");D&&D.href&&(A.preventDefault(),A.stopPropagation(),j(D.href))},children:s.jsx(ai,{content:k.content,disableLinkSafety:!0})})]},k.version))})})}),v&&y==="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(tg,{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:S}),s.jsx("button",{onClick:P,className:me("flex items-center justify-center p-2 rounded","text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]","transition-colors",u&&"text-[var(--status-success)]"),title:m(u?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:u?s.jsx(Zs,{className:"h-4 w-4"}):s.jsx(ni,{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:[w,"%"]})]}),s.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${w}%`}})})]}),(o||b)&&s.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:s.jsx("p",{className:"text-sm text-[var(--status-error)]",children:o||b})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[s.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0",children:[s.jsx(Pr,{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(Xr,{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(Sl,{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(Fn,{className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),v&&!I&&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(Xr,{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(Sl,{className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},Fh="https://github.com/btriapitsyn/openchamber",II=800,AI=()=>{const t=nt.c(103),{t:e}=ut(),[n,r]=l.useState(!1),[a,i]=l.useState(!1),o=Ya(Sr(PI)),{isMobile:c}=dn(),d=o.info?.currentVersion||"unknown",p=l.useRef(!1);let m,u;t[0]!==a||t[1]!==e||t[2]!==o.available||t[3]!==o.checking||t[4]!==o.error?(m=()=>{if(o.checking)i(!0),p.current=!0;else if(a){const _=setTimeout(()=>{i(!1),p.current&&!o.available&&!o.error&&(q.success(e("settings.openchamber.about.toast.latestVersion")),p.current=!1)},II);return()=>clearTimeout(_)}},u=[e,o.checking,a,o.available,o.error],t[0]=a,t[1]=e,t[2]=o.available,t[3]=o.checking,t[4]=o.error,t[5]=m,t[6]=u):(m=t[5],u=t[6]),l.useEffect(m,u);const f=o.checking||a;if(c){let _;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]!==f||t[10]!==e||t[11]!==o?(O=!o.available&&!o.error&&s.jsx("button",{onClick:()=>o.checkForUpdates(),disabled:f,className:me("typography-meta text-muted-foreground/60 hover:text-muted-foreground disabled:cursor-default",f&&"animate-pulse [animation-duration:1s]"),children:e("settings.openchamber.about.actions.checkUpdates")}),t[9]=f,t[10]=e,t[11]=o,t[12]=O):O=t[12];let L;t[13]!==f||t[14]!==e||t[15]!==o.available?(L=!f&&o.available&&s.jsxs("button",{onClick:()=>r(!0),className:"flex items-center gap-1 typography-meta text-[var(--primary-base)] hover:underline",children:[s.jsx(Xr,{className:"h-3.5 w-3.5"}),e("settings.openchamber.about.actions.update")]}),t[13]=f,t[14]=e,t[15]=o.available,t[16]=L):L=t[16];let K;t[17]!==_||t[18]!==O||t[19]!==L?(K=s.jsxs("div",{className:"flex items-center justify-between",children:[_,O,L]}),t[17]=_,t[18]=O,t[19]=L,t[20]=K):K=t[20];let B;t[21]!==o.error?(B=o.error&&s.jsx("p",{className:"typography-micro text-[var(--status-error)] truncate",children:o.error}),t[21]=o.error,t[22]=B):B=t[22];let re;t[23]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsxs("a",{href:Fh,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(Na,{className:"h-3.5 w-3.5"}),s.jsx("span",{children:"GitHub"})]}),t[23]=re):re=t[23];let oe;t[24]===Symbol.for("react.memo_cache_sentinel")?(oe=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(sg,{className:"h-3.5 w-3.5"}),s.jsx("span",{children:"Discord"})]}),t[24]=oe):oe=t[24];let ee;t[25]===Symbol.for("react.memo_cache_sentinel")?(ee=s.jsxs("div",{className:"flex items-center gap-3",children:[re,oe,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(Od,{className:"h-3.5 w-3.5"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[25]=ee):ee=t[25];let ae;t[26]!==n||t[27]!==o.downloadUpdate||t[28]!==o.downloaded||t[29]!==o.downloading||t[30]!==o.error||t[31]!==o.info||t[32]!==o.progress||t[33]!==o.restartToUpdate||t[34]!==o.runtimeType?(ae=s.jsx(cu,{open:n,onOpenChange:r,info:o.info,downloading:o.downloading,downloaded:o.downloaded,progress:o.progress,error:o.error,onDownload:o.downloadUpdate,onRestart:o.restartToUpdate,runtimeType:o.runtimeType}),t[26]=n,t[27]=o.downloadUpdate,t[28]=o.downloaded,t[29]=o.downloading,t[30]=o.error,t[31]=o.info,t[32]=o.progress,t[33]=o.restartToUpdate,t[34]=o.runtimeType,t[35]=ae):ae=t[35];let ge;return t[36]!==ae||t[37]!==K||t[38]!==B?(ge=s.jsxs("div",{className:"w-full space-y-2",children:[K,B,ee,ae]}),t[36]=ae,t[37]=K,t[38]=B,t[39]=ge):ge=t[39],ge}let y;t[40]!==e?(y=e("settings.openchamber.about.title"),t[40]=e,t[41]=y):y=t[41];let h;t[42]!==y?(h=s.jsx("div",{className:"mb-3 px-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:y})}),t[42]=y,t[43]=h):h=t[43];let b;t[44]!==e?(b=e("settings.openchamber.about.field.version"),t[44]=e,t[45]=b):b=t[45];let x;t[46]!==b?(x=s.jsx("span",{className:"typography-ui-label text-foreground",children:b}),t[46]=b,t[47]=x):x=t[47];let g;t[48]!==d?(g=s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:d}),t[48]=d,t[49]=g):g=t[49];let w;t[50]!==x||t[51]!==g?(w=s.jsxs("div",{className:"flex min-w-0 flex-col",children:[x,g]}),t[50]=x,t[51]=g,t[52]=w):w=t[52];let v;t[53]!==e||t[54]!==o.checking?(v=o.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(Sl,{className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),t[53]=e,t[54]=o.checking,t[55]=v):v=t[55];let S;t[56]!==e||t[57]!==o.available||t[58]!==o.checking||t[59]!==o.info?.version?(S=!o.checking&&o.available&&s.jsxs(ve,{size:"sm",variant:"default",onClick:()=>r(!0),children:[s.jsx(Xr,{className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:o.info?.version||""})]}),t[56]=e,t[57]=o.available,t[58]=o.checking,t[59]=o.info?.version,t[60]=S):S=t[60];let P;t[61]!==e||t[62]!==o.available||t[63]!==o.checking||t[64]!==o.error?(P=!o.checking&&!o.available&&!o.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),t[61]=e,t[62]=o.available,t[63]=o.checking,t[64]=o.error,t[65]=P):P=t[65];let j;t[66]!==o?(j=()=>o.checkForUpdates(),t[66]=o,t[67]=j):j=t[67];const C=o.checking;let I;t[68]!==e?(I=e("settings.openchamber.about.actions.checkForUpdates"),t[68]=e,t[69]=I):I=t[69];let R;t[70]!==j||t[71]!==I||t[72]!==o.checking?(R=s.jsx(ve,{size:"sm",variant:"outline",onClick:j,disabled:C,children:I}),t[70]=j,t[71]=I,t[72]=o.checking,t[73]=R):R=t[73];let k;t[74]!==P||t[75]!==R||t[76]!==v||t[77]!==S?(k=s.jsxs("div",{className:"flex items-center gap-3",children:[v,S,P,R]}),t[74]=P,t[75]=R,t[76]=v,t[77]=S,t[78]=k):k=t[78];let A;t[79]!==k||t[80]!==w?(A=s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-4 py-3 border-b border-[var(--surface-subtle)]",children:[w,k]}),t[79]=k,t[80]=w,t[81]=A):A=t[81];let N;t[82]!==o.error?(N=o.error&&s.jsx("div",{className:"px-3 py-2 border-b border-[var(--surface-subtle)]",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:o.error})}),t[82]=o.error,t[83]=N):N=t[83];let D;t[84]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsxs("a",{href:Fh,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(Na,{className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),t[84]=D):D=t[84];let T;t[85]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[D,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(Od,{className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[85]=T):T=t[85];let M;t[86]!==A||t[87]!==N?(M=s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[A,N,T]}),t[86]=A,t[87]=N,t[88]=M):M=t[88];let $;t[89]!==n||t[90]!==o.downloadUpdate||t[91]!==o.downloaded||t[92]!==o.downloading||t[93]!==o.error||t[94]!==o.info||t[95]!==o.progress||t[96]!==o.restartToUpdate||t[97]!==o.runtimeType?($=s.jsx(cu,{open:n,onOpenChange:r,info:o.info,downloading:o.downloading,downloaded:o.downloaded,progress:o.progress,error:o.error,onDownload:o.downloadUpdate,onRestart:o.restartToUpdate,runtimeType:o.runtimeType}),t[89]=n,t[90]=o.downloadUpdate,t[91]=o.downloaded,t[92]=o.downloading,t[93]=o.error,t[94]=o.info,t[95]=o.progress,t[96]=o.restartToUpdate,t[97]=o.runtimeType,t[98]=$):$=t[98];let F;return t[99]!==M||t[100]!==$||t[101]!==h?(F=s.jsxs("div",{className:"mb-8",children:[h,M,$]}),t[99]=M,t[100]=$,t[101]=h,t[102]=F):F=t[102],F};function PI(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 DI=1,TI=365,Oh=30,MI=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Ux=()=>{const t=nt.c(113),{t:e}=ut(),n=De(RI),r=De(EI),a=De(FI),i=De(OI),o=De(LI),c=De($I);let d;t[0]===Symbol.for("react.memo_cache_sentinel")?(d={autoRun:!1},t[0]=d):d=t[0];const{candidates:p,isRunning:m,runCleanup:u,action:f}=P1(d),y=p.length;let h;t[1]!==u||t[2]!==e?(h=async()=>{const Z=await u({force:!0});if(Z.completedIds.length===0&&Z.failedIds.length===0){q.message(Z.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}Z.completedIds.length>0&&q.success(Z.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:Z.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:Z.completedIds.length})),Z.failedIds.length>0&&q.error(Z.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:Z.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:Z.failedIds.length}))},t[1]=u,t[2]=e,t[3]=h):h=t[3];const b=h;let x;t[4]!==e?(x=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=x):x=t[5];let g;t[6]!==x?(g=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:x}),t[6]=x,t[7]=g):g=t[7];let w;t[8]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[8]=w):w=t[8];let v;t[9]!==e?(v=e("settings.openchamber.sessionRetention.tooltip"),t[9]=e,t[10]=v):v=t[10];let S;t[11]!==v?(S=s.jsxs(St,{children:[w,s.jsx(It,{sideOffset:8,className:"max-w-xs",children:v})]}),t[11]=v,t[12]=S):S=t[12];let P;t[13]!==g||t[14]!==S?(P=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[g,S]})}),t[13]=g,t[14]=S,t[15]=P):P=t[15];let j,C;t[16]!==n||t[17]!==i?(j=()=>i(!n),C=Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),i(!n))},t[16]=n,t[17]=i,t[18]=j,t[19]=C):(j=t[18],C=t[19]);let I;t[20]!==e?(I=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[20]=e,t[21]=I):I=t[21];let R;t[22]!==n||t[23]!==i||t[24]!==I?(R=s.jsx(bs,{checked:n,onChange:i,ariaLabel:I}),t[22]=n,t[23]=i,t[24]=I,t[25]=R):R=t[25];let k;t[26]!==e?(k=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[26]=e,t[27]=k):k=t[27];let A;t[28]!==k?(A=s.jsx("span",{className:"typography-ui-label text-foreground",children:k}),t[28]=k,t[29]=A):A=t[29];let N;t[30]!==n||t[31]!==R||t[32]!==A||t[33]!==j||t[34]!==C?(N=s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":n,onClick:j,onKeyDown:C,children:[R,A]}),t[30]=n,t[31]=R,t[32]=A,t[33]=j,t[34]=C,t[35]=N):N=t[35];let D;t[36]!==e?(D=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[36]=e,t[37]=D):D=t[37];let T;t[38]!==D?(T=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:D})}),t[38]=D,t[39]=T):T=t[39];let M;t[40]!==e?(M=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[40]=e,t[41]=M):M=t[41];let $;t[42]!==r||t[43]!==o||t[44]!==M?($=s.jsx(Cn,{value:r,onValueChange:o,min:DI,max:TI,step:1,"aria-label":M,className:"w-20 tabular-nums"}),t[42]=r,t[43]=o,t[44]=M,t[45]=$):$=t[45];let F;t[46]!==e?(F=e("settings.openchamber.sessionRetention.field.days"),t[46]=e,t[47]=F):F=t[47];let _;t[48]!==F?(_=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:F}),t[48]=F,t[49]=_):_=t[49];let O;t[50]!==o?(O=()=>o(Oh),t[50]=o,t[51]=O):O=t[51];const L=r===Oh;let K;t[52]!==e?(K=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[52]=e,t[53]=K):K=t[53];let B;t[54]!==e?(B=e("settings.common.actions.reset"),t[54]=e,t[55]=B):B=t[55];let re;t[56]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx(Fn,{className:"h-3.5 w-3.5"}),t[56]=re):re=t[56];let oe;t[57]!==O||t[58]!==L||t[59]!==K||t[60]!==B?(oe=s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:O,disabled:L,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":K,title:B,children:re}),t[57]=O,t[58]=L,t[59]=K,t[60]=B,t[61]=oe):oe=t[61];let ee;t[62]!==$||t[63]!==_||t[64]!==oe?(ee=s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[$,_,oe]}),t[62]=$,t[63]=_,t[64]=oe,t[65]=ee):ee=t[65];let ae;t[66]!==T||t[67]!==ee?(ae=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[T,ee]}),t[66]=T,t[67]=ee,t[68]=ae):ae=t[68];let ge;t[69]!==e?(ge=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[69]=e,t[70]=ge):ge=t[70];let ne;t[71]!==ge?(ne=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:ge})}),t[71]=ge,t[72]=ne):ne=t[72];let E;t[73]!==a||t[74]!==c||t[75]!==e?(E=MI.map(Z=>s.jsx(ve,{type:"button",variant:"chip",size:"xs","aria-pressed":a===Z.value,className:"!font-normal",onClick:()=>c(Z.value),children:e(Z.labelKey)},Z.value)),t[73]=a,t[74]=c,t[75]=e,t[76]=E):E=t[76];let z;t[77]!==E?(z=s.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:E}),t[77]=E,t[78]=z):z=t[78];let J;t[79]!==ne||t[80]!==z?(J=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[ne,z]}),t[79]=ne,t[80]=z,t[81]=J):J=t[81];let H;t[82]!==N||t[83]!==ae||t[84]!==J?(H=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[N,ae,J]}),t[82]=N,t[83]=ae,t[84]=J,t[85]=H):H=t[85];let te;t[86]!==e?(te=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[86]=e,t[87]=te):te=t[87];let ce;t[88]!==te?(ce=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:te})}),t[88]=te,t[89]=ce):ce=t[89];let Se;t[90]!==m||t[91]!==e?(Se=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[90]=m,t[91]=e,t[92]=Se):Se=t[92];let pe;t[93]!==b||t[94]!==m||t[95]!==Se?(pe=s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsx(ve,{type:"button",variant:"outline",size:"xs",onClick:b,disabled:m,className:"!font-normal",children:Se})}),t[93]=b,t[94]=m,t[95]=Se,t[96]=pe):pe=t[96];let we;t[97]!==ce||t[98]!==pe?(we=s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[ce,pe]}),t[97]=ce,t[98]=pe,t[99]=we):we=t[99];let W;t[100]!==f||t[101]!==y||t[102]!==e?(W=f==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:y}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:y}),t[100]=f,t[101]=y,t[102]=e,t[103]=W):W=t[103];let ue;t[104]!==W?(ue=s.jsx("p",{className:"typography-meta text-muted-foreground",children:W}),t[104]=W,t[105]=ue):ue=t[105];let Y;t[106]!==we||t[107]!==ue?(Y=s.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[we,ue]}),t[106]=we,t[107]=ue,t[108]=Y):Y=t[108];let le;return t[109]!==H||t[110]!==Y||t[111]!==P?(le=s.jsxs("div",{className:"mb-8",children:[P,H,Y]}),t[109]=H,t[110]=Y,t[111]=P,t[112]=le):le=t[112],le};function RI(t){return t.autoDeleteEnabled}function EI(t){return t.autoDeleteAfterDays}function FI(t){return t.sessionRetentionAction}function OI(t){return t.setAutoDeleteEnabled}function LI(t){return t.setAutoDeleteAfterDays}function $I(t){return t.setSessionRetentionAction}const Lh=(t,e)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(t),Wx=()=>{const{t}=ut(),[e,n]=l.useState(!1),[r,a]=l.useState(!0),[i,o]=l.useState(!1),[c,d]=l.useState(null),[p,m]=l.useState(!1),[u,f]=l.useState([]),[y,h]=l.useState(D1),[b,x]=l.useState(""),g=l.useMemo(()=>T1(),[]),w=l.useCallback(async()=>{a(!0),x("");try{const j=await M1();f(j)}catch(j){const C=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.loadFailed");x(C)}finally{a(!1)}},[t]);l.useEffect(()=>{let j=!1;return(async()=>{try{if(!g.supported){j||(n(!1),a(!1));return}j||n(!0)}catch{j||n(!1)}if(!j){const C=await Uc();if(h(C),!C.enabled){f([]),a(!1);return}await w()}})(),()=>{j=!0,Fm()}},[w,g.supported]);const v=l.useCallback(async()=>{if(!y.enabled){const j=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");x(j),q.message(j);return}if(!e){x(g.reason),q.message(g.reason);return}if(i){Fm(),o(!1);return}x(""),o(!0);try{await R1(),h(await Uc()),await w(),q.success(t("settings.openchamber.passkeys.toast.added"))}catch(j){if(E1(j)){q.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const C=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.addFailed");x(C),q.error(C)}finally{o(!1)}},[i,w,y.enabled,g.reason,e,t]),S=l.useCallback(async j=>{d(j),x("");try{await F1(j),h(await Uc()),await w(),q.success(t("settings.openchamber.passkeys.toast.removed"))}catch(C){const I=C instanceof Error?C.message:t("settings.openchamber.passkeys.toast.removeFailed");x(I),q.error(I)}finally{d(null)}},[w,t]),P=l.useCallback(async()=>{m(!0),x("");try{await O1(),window.location.reload()}catch(j){const C=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");x(C),q.error(C),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(ve,{type:"button",variant:i?"secondary":"outline",size:"xs",onClick:()=>{v()},disabled:r||p,className:"!font-normal",children:t(i?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(ve,{type:"button",variant:"ghost",size:"xs",onClick:()=>{P()},disabled:r||i||p,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(p?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]})]}),!y.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),y.enabled&&!e&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:g.reason}),r?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):u.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:u.map(j=>s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:j.label})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:j.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:Lh(j.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"))}):t("settings.openchamber.passkeys.item.added",{time:Lh(j.createdAt,t("settings.openchamber.passkeys.time.neverUsed"))})}),s.jsx(ve,{type:"button",variant:"ghost",size:"xs",onClick:()=>{S(j.id)},disabled:c===j.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===j.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]})]},j.id))})]}),b&&s.jsx("div",{className:"mt-1 px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:b})})]})},BI=t=>{const e=Ji(t);return e||{providerId:"",modelId:""}},Kx=()=>{const{t}=ut(),e=yt(T=>T.setProvider),n=yt(T=>T.setModel),r=yt(T=>T.setAgent),a=yt(T=>T.setCurrentVariant),i=yt(T=>T.setSettingsDefaultModel),o=yt(T=>T.setSettingsDefaultVariant),c=yt(T=>T.setSettingsDefaultAgent),d=yt(T=>T.setSettingsDefaultFileViewerPreview),p=yt(T=>T.settingsDefaultFileViewerPreview),m=De(T=>T.showDeletionDialog),u=De(T=>T.setShowDeletionDialog),f=yt(T=>T.providers),[y,h]=l.useState(),[b,x]=l.useState(),[g,w]=l.useState(),[v,S]=l.useState(!0),P=l.useMemo(()=>BI(y),[y]);l.useEffect(()=>{(async()=>{try{let M=null;if(!M){const $=yr()?.settings;if($)try{const _=(await $.load())?.settings;_&&(M={defaultModel:typeof _.defaultModel=="string"?_.defaultModel:void 0,defaultVariant:typeof _.defaultVariant=="string"?_.defaultVariant:void 0,defaultAgent:typeof _.defaultAgent=="string"?_.defaultAgent:void 0})}catch{}}if(!M){const $=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});$.ok&&(M=await $.json())}if(M){const $=typeof M.defaultModel=="string"&&M.defaultModel.trim().length>0?M.defaultModel.trim():void 0,F=typeof M.defaultVariant=="string"&&M.defaultVariant.trim().length>0?M.defaultVariant.trim():void 0,_=typeof M.defaultAgent=="string"&&M.defaultAgent.trim().length>0?M.defaultAgent.trim():void 0;$!==void 0&&h($),F!==void 0&&x(F),_!==void 0&&w(_)}}catch(M){console.warn("Failed to load defaults settings:",M)}finally{S(!1)}})()},[]);const j=l.useCallback(async(T,M)=>{const $=T&&M?`${T}/${M}`:void 0;h($),x(void 0),o(void 0),a(void 0),i($),T&&M&&f.find(_=>_.id===T)&&(e(T),n(M));try{await As({defaultModel:$??"",defaultVariant:""});const F=await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:$})});F.ok||console.warn("Failed to save default model to server:",F.status,F.statusText)}catch(F){console.warn("Failed to save default model:",F)}},[f,a,n,e,i,o]),C="__default__",I=l.useCallback(T=>T===C?t("settings.openchamber.defaults.option.default"):T.charAt(0).toUpperCase()+T.slice(1),[t]),R=l.useCallback(async T=>{const M=T===C?void 0:T||void 0;x(M),o(M),a(M);try{await As({defaultVariant:M??""})}catch($){console.warn("Failed to save default variant:",$)}},[a,o]),k=l.useCallback(async T=>{const M=T||void 0;w(M),c(M),T&&r(T);try{await As({defaultAgent:M??""})}catch($){console.warn("Failed to save default agent:",$)}},[r,c]),A=l.useCallback(()=>{const T=!p;d(T),As({defaultFileViewerPreview:T}).catch(console.warn)},[p,d]),N=l.useMemo(()=>{if(!P.providerId||!P.modelId)return[];const $=f.find(F=>F.id===P.providerId)?.models.find(F=>F.id===P.modelId)?.variants;return $?Object.keys($):[]},[P.modelId,P.providerId,f]),D=N.length>0;return l.useEffect(()=>{!D&&b&&(x(void 0),o(void 0),a(void 0),As({defaultVariant:""}).catch(()=>{}))},[b,a,o,D]),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")," ",P.providerId?s.jsxs("span",{className:"text-foreground",children:[P.providerId,"/",P.modelId,D?` (${b??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),g&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:g})]})]}),s.jsxs("div",{className:me("flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(qo,{providerId:P.providerId,modelId:P.modelId,onChange:j})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultThinking")})}),s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsxs(ps,{value:b??C,onValueChange:R,disabled:!D,children:[s.jsx(hs,{className:"w-fit min-w-[120px]",children:s.jsx(ys,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:I(b??C)})}),s.jsxs(fs,{children:[s.jsx(Rt,{value:C,children:t("settings.openchamber.defaults.option.default")}),N.map(T=>s.jsx(Rt,{value:T,children:I(T)},T))]})]})})]}),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(Sc,{agentName:g||"",onChange:k})})]}),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:T=>{(T.key===" "||T.key==="Enter")&&(T.preventDefault(),u(!m))},children:[s.jsx(bs,{checked:m,onChange:u,ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.showDeletionDialog")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":p,onClick:A,onKeyDown:T=>{(T.key===" "||T.key==="Enter")&&(T.preventDefault(),A())},children:[s.jsx(bs,{checked:p,onChange:d,ariaLabel:t("settings.openchamber.defaults.field.openFilesPreviewAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.openFilesPreview")})]})]})]})},$h={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"}},_I={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"},Bh="big-pickle",xd="__not_selected__",_h=200,Vh=100,zh=250,VI=()=>{const{t}=ut(),{isMobile:e}=dn(),n=l.useMemo(()=>Pn(),[]),r=l.useMemo(()=>jn(),[]),a=!n&&!r,i=De(W=>W.nativeNotificationsEnabled),o=De(W=>W.setNativeNotificationsEnabled),c=De(W=>W.notificationMode),d=De(W=>W.setNotificationMode),p=De(W=>W.notifyOnSubtasks),m=De(W=>W.setNotifyOnSubtasks),u=De(W=>W.notifyOnCompletion),f=De(W=>W.setNotifyOnCompletion),y=De(W=>W.notifyOnError),h=De(W=>W.setNotifyOnError),b=De(W=>W.notifyOnQuestion),x=De(W=>W.setNotifyOnQuestion),g=De(W=>W.notificationTemplates),w=De(W=>W.setNotificationTemplates),v=De(W=>W.summarizeLastMessage),S=De(W=>W.setSummarizeLastMessage),P=De(W=>W.summaryThreshold),j=De(W=>W.setSummaryThreshold),C=De(W=>W.summaryLength),I=De(W=>W.setSummaryLength),R=De(W=>W.maxLastMessageLength),k=De(W=>W.setMaxLastMessageLength),A=yt(W=>W.settingsZenModel),N=yt(W=>W.setSettingsZenModel),[D,T]=l.useState("default"),[M,$]=l.useState(!1),[F,_]=l.useState(!1),[O,L]=l.useState(!1),[K,B]=l.useState([]);l.useEffect(()=>{const W=new AbortController;return fetch("/api/zen/models",{method:"GET",headers:{Accept:"application/json"},signal:W.signal}).then(async ue=>{if(!ue.ok)return[];const Y=await ue.json().catch(()=>({}));return(Array.isArray(Y?.models)?Y.models:[]).map(Z=>{const Ie=typeof Z?.id=="string"?Z.id.trim():"";return Ie?{id:Ie,name:Ie}:null}).filter(Z=>Z!==null)}).then(ue=>{B(ue)}).catch(ue=>{ue?.name!=="AbortError"&&console.warn("Failed to load zen utility models:",ue)}),()=>{W.abort()}},[]);const re=l.useMemo(()=>K,[K]),oe=l.useMemo(()=>A&&re.some(W=>W.id===A)?A:re.some(W=>W.id===Bh)?Bh:re[0]?.id??"",[A,re]),ee=l.useCallback(async W=>{const ue=W===xd?void 0:W;N(ue);try{await As({zenModel:ue??"",gitProviderId:"",gitModelId:""})}catch(Y){console.warn("Failed to save utility model setting:",Y)}},[N]);l.useEffect(()=>{if(!a){$(!1),_(!1);return}typeof Notification<"u"&&T(Notification.permission);const W=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;$(W),(async()=>{if(!W){_(!1);return}try{const Y=await navigator.serviceWorker.getRegistration();if(!Y){_(!1);return}const le=await Y.pushManager.getSubscription();_(!!le)}catch{_(!1)}})()},[a]);const ae=async W=>{if(n){o(W);return}if(!a){o(W);return}if(W&&typeof Notification<"u"&&Notification.permission==="default")try{const ue=await Notification.requestPermission();T(ue),ue==="granted"?o(!0):q.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(ue){console.error("Failed to request notification permission:",ue),q.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else o(!!(W&&D==="granted"))},ge=n||r||a&&typeof Notification<"u"&&Notification.permission==="granted",ne=(W,ue,Y)=>{w({...g,[W]:{...g[W],[ue]:Y}})},E=W=>{const ue="=".repeat((4-W.length%4)%4),Y=(W+ue).replace(/-/g,"+").replace(/_/g,"/"),le=atob(Y),Z=new Uint8Array(le.length);for(let Ie=0;Ie<le.length;Ie+=1)Z[Ie]=le.charCodeAt(Ie);return Z},z=async(W,ue,Y)=>{let le=null;const Z=new Promise((Ie,Ne)=>{le=setTimeout(()=>{Ne(new Error(Y))},ue)});try{return await Promise.race([W,Z])}finally{le&&clearTimeout(le)}},J=async W=>{if(W.active)return;const ue=W.installing||W.waiting;ue&&ue.state!=="activated"&&await z(new Promise(Y=>{const le=()=>{ue.state==="activated"&&(ue.removeEventListener("statechange",le),Y())};ue.addEventListener("statechange",le),le()}),15e3,"Service worker activation timed out")},H=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const W=[{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 ue=null;for(const Y of W)try{const le=Y.opts?navigator.serviceWorker.register("/sw.js",Y.opts):navigator.serviceWorker.register("/sw.js");return await z(le,1e4,`Service worker registration timed out (${Y.label})`)}catch(le){ue=le}throw ue instanceof Error?ue:new Error("Service worker registration failed")},te=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const W=await navigator.serviceWorker.getRegistration();if(W)return W;const ue=await H();try{await ue.update()}catch{}return await J(ue),ue},ce=W=>{const ue=W,Y=[`type=${typeof W}`,`toString=${String(W)}`,`name=${String(ue?.name??"")}`,`message=${String(ue?.message??"")}`];let le="";try{le=JSON.stringify(W)}catch{}return{summary:Y.filter(Boolean).join(" | "),json:le,stack:typeof ue?.stack=="string"?ue.stack:""}},Se=async()=>{const W=yr();if(!W?.notifications){q.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await W.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?q.success(t("settings.notifications.page.toast.testNotificationSent")):q.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(ue){console.error("Test notification failed:",ue),q.error(t("settings.notifications.page.toast.testNotificationFailed"))}},pe=async()=>{if(!M){q.error(t("settings.notifications.page.toast.pushUnsupported"));return}const W=yr();if(!W?.push){q.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}L(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const he=await Notification.requestPermission();if(T(he),he!=="granted"){q.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){q.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const ue=await W.push.getVapidPublicKey();if(!ue?.publicKey){q.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const Y=await te();await J(Y);const le=await Y.pushManager.getSubscription();if(!("pushManager"in Y)||!Y.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const Ie=(le??await z(Y.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:E(ue.publicKey)}),15e3,"Push subscription timed out")).toJSON(),Ne=Ie.keys;if(!Ie.endpoint||!Ne?.p256dh||!Ne.auth)throw new Error("Push subscription missing keys");if(!(await z(W.push.subscribe({endpoint:Ie.endpoint,keys:{p256dh:Ne.p256dh,auth:Ne.auth},origin:typeof window<"u"?window.location.origin:void 0}),15e3,"Push subscribe request timed out"))?.ok){q.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}_(!0),q.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(ue){console.error("[Push] Enable failed:",ue);const Y=ce(ue);q.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:Y.summary})}finally{L(!1)}},we=async()=>{if(!M){_(!1);return}const W=yr();if(!W?.push){q.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}L(!0);try{const Y=await(await te()).pushManager.getSubscription();if(!Y){_(!1);return}const le=Y.endpoint;await Y.unsubscribe(),await W.push.unsubscribe({endpoint:le}),_(!1),q.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{L(!1)}};return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.delivery.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":i&&ge,onClick:()=>{ae(!(i&&ge))},onKeyDown:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),ae(!(i&&ge)))},children:[s.jsx(bs,{checked:i&&ge,onChange:W=>{ae(W)},ariaLabel:t("settings.notifications.page.delivery.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.enableLabel")})]}),i&&ge&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":c==="always",onClick:()=>d(c==="always"?"hidden-only":"always"),onKeyDown:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),d(c==="always"?"hidden-only":"always"))},children:[s.jsx(bs,{checked:c==="always",onChange:W=>d(W?"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(ve,{type:"button",variant:"outline",size:"sm",onClick:()=>{Se()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),a&&s.jsxs("div",{className:"mt-1 px-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.browserPermissionHint")}),D==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),D==="granted"&&!i&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]}),r&&s.jsx("div",{className:"mt-1 px-2",children:s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.vscodeHint")})})]}),i&&ge&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.events.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":u,onClick:()=>f(!u),onKeyDown:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),f(!u))},children:[s.jsx(bs,{checked:u,onChange:f,ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.completionLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>m(!p),onKeyDown:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),m(!p))},children:[s.jsx(bs,{checked:p,onChange:m,ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.subtaskLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":y,onClick:()=>h(!y),onKeyDown:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),h(!y))},children:[s.jsx(bs,{checked:y,onChange:h,ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.errorLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":b,onClick:()=>x(!b),onKeyDown:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),x(!b))},children:[s.jsx(bs,{checked:b,onChange:x,ariaLabel:t("settings.notifications.page.events.questionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.questionLabel")})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.template.title")}),s.jsxs("p",{className:"typography-meta text-muted-foreground mt-0.5",children:[t("settings.notifications.page.template.variablesLabel")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]})]}),s.jsx("div",{className:"grid grid-cols-1 gap-2 md:grid-cols-2 md:gap-3",children:["completion","subtask","error","question"].map(W=>s.jsxs("section",{className:"p-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground font-normal capitalize block",children:t(_I[W])}),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(Bt,{value:g[W].title,onChange:ue=>ne(W,"title",ue.target.value),className:"h-7",placeholder:t($h[W].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(Bt,{value:g[W].message,onChange:ue=>ne(W,"message",ue.target.value),className:"h-7",placeholder:t($h[W].messageKey)})]})]})]},W))})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.summary.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":v,onClick:()=>S(!v),onKeyDown:W=>{(W.key===" "||W.key==="Enter")&&(W.preventDefault(),S(!v))},children:[s.jsx(bs,{checked:v,onChange:S,ariaLabel:t("settings.notifications.page.summary.toggleAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.toggleLabel")})]}),s.jsx("div",{className:"pl-6 pb-1",children:s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.notifications.page.summary.requiresTemplateVariable")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"}),"."]})}),s.jsxs("div",{className:me("flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.modelLabel")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:t("settings.notifications.page.summary.modelTooltip")})]})]})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsxs(ps,{value:oe||xd,onValueChange:ee,children:[s.jsx(hs,{className:"w-fit min-w-[220px]",children:s.jsx(ys,{placeholder:t("settings.notifications.page.summary.notSelected")})}),s.jsxs(fs,{children:[s.jsx(Rt,{value:xd,children:t("settings.notifications.page.summary.notSelected")}),re.map(W=>s.jsx(Rt,{value:W.id,children:W.name},W.id))]})]})})]}),v?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-8 py-1.5 mt-1 border-t border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.thresholdLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.notifications.page.summary.thresholdHint")})]}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsx(Cn,{value:P,onValueChange:j,min:50,max:2e3,step:50,className:"w-20 tabular-nums"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(_h),disabled:P===_h,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.notifications.page.summary.resetThresholdAria"),title:t("settings.common.actions.reset"),children:s.jsx(Fn,{className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.lengthLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.notifications.page.summary.lengthHint")})]}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsx(Cn,{value:C,onValueChange:I,min:20,max:500,step:10,className:"w-20 tabular-nums"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>I(Vh),disabled:C===Vh,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.notifications.page.summary.resetLengthAria"),title:t("settings.common.actions.reset"),children:s.jsx(Fn,{className:"h-3.5 w-3.5"})})]})]})]}):s.jsxs("div",{className:me("py-1.5 mt-1 border-t border-[var(--surface-subtle)]",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:me("flex min-w-0 flex-col",e?"w-full":"w-56 shrink-0"),children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.maxLengthLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.notifications.page.summary.maxLengthHint")})]}),s.jsxs("div",{className:me("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(Cn,{value:R,onValueChange:k,min:50,max:1e3,step:10,className:"w-20 tabular-nums"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>k(zh),disabled:R===zh,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.notifications.page.summary.resetMaxLengthAria"),title:t("settings.common.actions.reset"),children:s.jsx(Fn,{className:"h-3.5 w-3.5"})})]})]})]})]})]}),a&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.push.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[s.jsx(bs,{checked:M?F:!1,disabled:!M||O,onChange:W=>{W?pe():we()},ariaLabel:t("settings.notifications.page.push.enableAria")}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:me("typography-ui-label",M?"text-foreground":"text-muted-foreground"),children:t("settings.notifications.page.push.enableLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t(M?"settings.notifications.page.push.supportedHint":"settings.notifications.page.push.unsupportedHint")})]}),O&&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")})})]})})]})]})},zI=[{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=[{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"}],WI=()=>{const{t}=ut(),{isMobile:e}=dn(),{isSupported:n,language:r,setLanguage:a}=L1(),i=yt(U=>U.voiceProvider),o=yt(U=>U.setVoiceProvider),c=yt(U=>U.speechRate),d=yt(U=>U.setSpeechRate),p=yt(U=>U.speechPitch),m=yt(U=>U.setSpeechPitch),u=yt(U=>U.speechVolume),f=yt(U=>U.setSpeechVolume),y=yt(U=>U.sayVoice),h=yt(U=>U.setSayVoice),b=yt(U=>U.browserVoice),x=yt(U=>U.setBrowserVoice),g=yt(U=>U.openaiVoice),w=yt(U=>U.setOpenaiVoice),v=yt(U=>U.openaiApiKey),S=yt(U=>U.setOpenaiApiKey),P=yt(U=>U.openaiCompatibleUrl),j=yt(U=>U.setOpenaiCompatibleUrl),C=yt(U=>U.openaiCompatibleVoice),I=yt(U=>U.setOpenaiCompatibleVoice),R=yt(U=>U.openaiCompatibleTtsModel),k=yt(U=>U.setOpenaiCompatibleTtsModel),A=yt(U=>U.showMessageTTSButtons),N=yt(U=>U.sttProvider),D=yt(U=>U.setSttProvider),T=yt(U=>U.sttServerUrl),M=yt(U=>U.setSttServerUrl),$=yt(U=>U.sttModel),F=yt(U=>U.setSttModel),_=yt(U=>U.sttLanguage),O=yt(U=>U.setSttLanguage),L=yt(U=>U.sttSilenceThresholdDb),K=yt(U=>U.setSttSilenceThresholdDb),B=yt(U=>U.sttSilenceHoldMs),re=yt(U=>U.setSttSilenceHoldMs),oe=yt(U=>U.setShowMessageTTSButtons),ee=yt(U=>U.voiceModeEnabled),ae=yt(U=>U.setVoiceModeEnabled),ge=yt(U=>U.summarizeMessageTTS),ne=yt(U=>U.setSummarizeMessageTTS),E=yt(U=>U.summarizeVoiceConversation),z=yt(U=>U.setSummarizeVoiceConversation),J=yt(U=>U.summarizeCharacterThreshold),H=yt(U=>U.setSummarizeCharacterThreshold),te=yt(U=>U.summarizeMaxLength),ce=yt(U=>U.setSummarizeMaxLength),[Se,pe]=Oe.useState(!1),[we,W]=Oe.useState([]),[ue,Y]=Oe.useState(!1),[le,Z]=Oe.useState(null),[Ie,Ne]=Oe.useState(!1),[X,he]=Oe.useState(!1),[je,be]=Oe.useState(null),[fe,Pe]=Oe.useState(!1),[Be,G]=Oe.useState(null),[ke,Ee]=Oe.useState([]),[Ae,xe]=Oe.useState(!1);Oe.useEffect(()=>((async()=>{const Ve=await Wc.waitForVoices();Ee(Ve)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Ee(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const V=Oe.useMemo(()=>ke.filter(U=>U.lang).sort((U,Ve)=>{const He=U.lang.startsWith("en"),Ke=Ve.lang.startsWith("en");if(He&&!Ke)return-1;if(!He&&Ke)return 1;const Ze=U.lang.localeCompare(Ve.lang);return Ze!==0?Ze:U.name.localeCompare(Ve.name)}),[ke]),de=Oe.useCallback(()=>{if(Ae){Wc.cancelSpeech(),xe(!1);return}const U=ke.find(Ze=>Ze.name===b),Ve=U?.name??t("settings.voice.page.preview.browserVoiceFallback"),He=t("settings.voice.page.preview.voiceLine",{voiceName:Ve});xe(!0);const Ke=new SpeechSynthesisUtterance(He);Ke.rate=c,Ke.pitch=p,Ke.volume=u,U&&(Ke.voice=U,Ke.lang=U.lang),Ke.onend=()=>xe(!1),Ke.onerror=()=>xe(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(Ke)},[b,ke,c,p,u,Ae,t]);Oe.useEffect(()=>()=>{Ae&&Wc.cancelSpeech()},[Ae]),Oe.useEffect(()=>{if(!ee||i!=="openai"&&i!=="openai-compatible"){Ne(v.trim().length>0);return}(async()=>{try{const Ke=(await(await fetch("/api/tts/status")).json()).available,Ze=v.trim().length>0;Ne(Ke||Ze)}catch{Ne(v.trim().length>0)}})()},[v,ee,i]),Oe.useEffect(()=>{if(!ee){pe(!1),W([]);return}fetch("/api/tts/say/status").then(U=>U.json()).then(U=>{if(pe(U.available),U.voices){const Ve=U.voices.filter((He,Ke,Ze)=>Ze.findIndex(Xe=>Xe.name===He.name)===Ke).sort((He,Ke)=>He.name.localeCompare(Ke.name));W(Ve)}}).catch(()=>{pe(!1)})},[ee]);const Me=Oe.useCallback(async()=>{if(le){le.pause(),le.currentTime=0,Z(null),Y(!1);return}Y(!0);try{const U=await fetch("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:y}),voice:y,rate:Math.round(100+(c-.5)*200)})});if(!U.ok)throw new Error("Preview failed");const Ve=await U.blob(),He=URL.createObjectURL(Ve),Ke=new Audio(He);Ke.onended=()=>{URL.revokeObjectURL(He),Z(null),Y(!1)},Ke.onerror=()=>{URL.revokeObjectURL(He),Z(null),Y(!1)},Z(Ke),await Ke.play()}catch{Y(!1)}},[y,c,le,t]);Oe.useEffect(()=>()=>{le&&le.pause()},[le]);const Le=Oe.useCallback(async()=>{if(je){je.pause(),je.currentTime=0,be(null),he(!1);return}he(!0);try{const U=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:g}),voice:g,speed:c,apiKey:v||void 0})});if(!U.ok){const Ze=await U.json().catch(()=>({error:"Unknown error"}));throw new Error(Ze.error||`HTTP ${U.status}`)}const Ve=await U.blob(),He=URL.createObjectURL(Ve),Ke=new Audio(He);Ke.onended=()=>{URL.revokeObjectURL(He),be(null),he(!1)},Ke.onerror=()=>{URL.revokeObjectURL(He),be(null),he(!1)},be(Ke),await Ke.play()}catch{he(!1)}},[g,c,je,v,t]);Oe.useEffect(()=>()=>{je&&je.pause()},[je]);const se=Oe.useCallback(async()=>{if(Be){Be.pause(),Be.currentTime=0,G(null),Pe(!1);return}if(P.trim()){Pe(!0);try{const U=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:C,model:R||void 0,speed:c,baseURL:P})});if(!U.ok){const Ze=await U.json().catch(()=>({error:"Unknown error"}));throw new Error(Ze.error||`HTTP ${U.status}`)}const Ve=await U.blob(),He=URL.createObjectURL(Ve),Ke=new Audio(He);Ke.onended=()=>{URL.revokeObjectURL(He),G(null),Pe(!1)},Ke.onerror=()=>{URL.revokeObjectURL(He),G(null),Pe(!1)},G(Ke),await Ke.play()}catch{Pe(!1)}}},[P,C,R,c,Be,t]);Oe.useEffect(()=>()=>{Be&&Be.pause()},[Be]);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":ee,onClick:()=>ae(!ee),onKeyDown:U=>{(U.key===" "||U.key==="Enter")&&(U.preventDefault(),ae(!ee))},children:[s.jsx(bs,{checked:ee,onChange:ae,ariaLabel:t("settings.voice.page.field.enableVoiceModeAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.enableVoiceMode")})]}),ee&&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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{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(ve,{variant:"chip",size:"xs","aria-pressed":i==="browser",onClick:()=>o("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":i==="openai",onClick:()=>o("openai"),className:"!font-normal",children:"OpenAI"}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":i==="openai-compatible",onClick:()=>o("openai-compatible"),className:"!font-normal",children:t("settings.voice.page.provider.custom")}),Se&&s.jsxs(ve,{variant:"chip",size:"xs","aria-pressed":i==="say",onClick:()=>o("say"),className:"!font-normal",children:[s.jsx(Ry,{className:"w-3.5 h-3.5 mr-0.5"}),t("settings.voice.page.provider.say")]})]})]})}),i==="openai"&&s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:me("typography-ui-label text-foreground",!Ie&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:me("typography-meta ml-2",Ie?"text-muted-foreground":"text-[var(--status-error)]/80"),children:t(Ie&&!v?"settings.voice.page.field.apiKeyHintUsingConfig":Ie?"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:U=>S(U.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:()=>S(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(Is,{className:"w-3.5 h-3.5"})})]})]}),i==="openai-compatible"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:me("typography-ui-label text-foreground",!P.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:P,onChange:U=>j(U.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"}),P&&s.jsx("button",{type:"button",onClick:()=>j(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(Is,{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:R,onChange:U=>k(U.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:C,onChange:U=>I(U.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(ve,{size:"xs",variant:"ghost",onClick:se,title:t("settings.voice.page.actions.preview"),disabled:!P.trim(),children:fe?s.jsx(qr,{className:"w-3.5 h-3.5"}):s.jsx(Gr,{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"&&Ie&&s.jsxs(s.Fragment,{children:[s.jsxs(ps,{value:g,onValueChange:w,children:[s.jsx(hs,{className:"w-fit",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(fs,{children:UI.map(U=>s.jsx(Rt,{value:U.value,children:U.label},U.value))})]}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:Le,title:t("settings.voice.page.actions.preview"),children:X?s.jsx(qr,{className:"w-3.5 h-3.5"}):s.jsx(Gr,{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"&&Se&&we.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(ps,{value:y,onValueChange:h,children:[s.jsx(hs,{className:"w-fit",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(fs,{children:we.map(U=>s.jsx(Rt,{value:U.name,children:U.name},U.name))})]}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:Me,title:t("settings.voice.page.actions.preview"),children:ue?s.jsx(qr,{className:"w-3.5 h-3.5"}):s.jsx(Gr,{className:"w-3.5 h-3.5"})})]}),i==="browser"&&V.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(ps,{value:b||"__auto__",onValueChange:U=>x(U==="__auto__"?"":U),children:[s.jsx(hs,{className:"w-fit max-w-[200px]",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(fs,{children:[s.jsx(Rt,{value:"__auto__",children:t("settings.voice.page.field.auto")}),V.map(U=>s.jsxs(Rt,{value:U.name,children:[U.name," (",U.lang,")"]},U.name))]})]}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:de,title:t("settings.voice.page.actions.preview"),children:Ae?s.jsx(qr,{className:"w-3.5 h-3.5"}):s.jsx(Gr,{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:U=>d(Number(U.target.value)),disabled:!n,className:ie}),s.jsx(Cn,{value:c,onValueChange:d,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.speechPitch")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:p,onChange:U=>m(Number(U.target.value)),disabled:!n,className:ie}),s.jsx(Cn,{value:p,onValueChange:m,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.speechVolume")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:u,onChange:U=>f(Number(U.target.value)),disabled:!n,className:ie}),e?s.jsx(Cn,{value:Math.round(u*100),onValueChange:U=>f(U/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(ps,{value:r,onValueChange:a,disabled:!n,children:[s.jsx(hs,{className:"w-fit",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.selectLanguagePlaceholder")})}),s.jsx(fs,{children:zI.map(U=>s.jsx(Rt,{value:U.value,children:U.label},U.value))})]})})]})]})]})]}),ee&&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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{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(ve,{variant:"chip",size:"xs","aria-pressed":N==="browser",onClick:()=>D("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":N==="server",onClick:()=>D("server"),className:"!font-normal",children:t("settings.voice.page.provider.server")})]})]})}),N==="server"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[!$1.isSupported()&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:t("settings.voice.page.field.sttBrowserSupportError")}),s.jsxs("div",{children:[s.jsx("span",{className:me("typography-ui-label text-foreground",!T.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:T,onChange:U=>M(U.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"}),T&&s.jsx("button",{type:"button",onClick:()=>M(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(Is,{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:$,onChange:U=>F(U.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.language")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.sttLanguageHint")}),s.jsx("div",{className:"relative mt-1.5 max-w-[8rem]",children:s.jsx("input",{type:"text",value:_,onChange:U=>O(U.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:L,onChange:U=>K(Number(U.target.value)),className:ie}),s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3.5rem] text-right",children:[L," 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:B,onChange:U=>re(Number(U.target.value)),className:ie}),s.jsx(Cn,{value:B,onValueChange:re,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")})]})]})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.playbackAndSummary")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":A,onClick:()=>oe(!A),onKeyDown:U=>{(U.key===" "||U.key==="Enter")&&(U.preventDefault(),oe(!A))},children:[s.jsx(bs,{checked:A,onChange:oe,ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.messageReadAloudButton")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ge,onClick:()=>ne(!ge),onKeyDown:U=>{(U.key===" "||U.key==="Enter")&&(U.preventDefault(),ne(!ge))},children:[s.jsx(bs,{checked:ge,onChange:ne,ariaLabel:t("settings.voice.page.field.summarizeBeforePlaybackAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.summarizeBeforePlayback")})]}),ee&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":E,onClick:()=>z(!E),onKeyDown:U=>{(U.key===" "||U.key==="Enter")&&(U.preventDefault(),z(!E))},children:[s.jsx(bs,{checked:E,onChange:z,ariaLabel:t("settings.voice.page.field.summarizeVoiceModeResponsesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.summarizeVoiceModeResponses")})]}),(ge||E)&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.summarizationThreshold")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:50,max:2e3,step:50,value:J,onChange:U=>H(Number(U.target.value)),className:ie}),s.jsx(Cn,{value:J,onValueChange:H,min:50,max:2e3,step:50,className:"w-16 tabular-nums"})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.summaryMaxLength")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:50,max:2e3,step:50,value:te,onChange:U=>ce(Number(U.target.value)),className:ie}),s.jsx(Cn,{value:te,onValueChange:ce,min:50,max:2e3,step:50,className:"w-16 tabular-nums"})]})]})]})]}),ee&&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")]})})]})]})},bd=[{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}],yd=[{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}],KI="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",HI="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Uh=[{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"}],GI=[".yml",".yaml",".json"],qI="settings.openchamber.tunnel.error.invalidConfigExtension",po=t=>{const e=t.trim().toLowerCase();return GI.some(n=>e.endsWith(n))},Hx=t=>t==="cloudflare"?"Cloudflare":t,Wh=t=>{const e=nt.c(11),{provider:n}=t;let r;e[0]!==n?(r=Hx(n),e[0]=n,e[1]=r):r=e[1];const a=r,o=n==="cloudflare"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==o?(c=me("size-4 shrink-0",o),e[2]=o,e[3]=c):c=e[3];let d;e[4]!==c?(d=s.jsx(ng,{className:c}),e[4]=c,e[5]=d):d=e[5];let p;e[6]!==a?(p=s.jsx("span",{children:a}),e[6]=a,e[7]=p):p=e[7];let m;return e[8]!==d||e[9]!==p?(m=s.jsxs("span",{className:"flex items-center gap-2",children:[d,p]}),e[8]=d,e[9]=p,e[10]=m):m=e[10],m},La=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",Kh=(t,e,n)=>t.find(a=>a.ms===e)?.value||n,Hh=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`},QI=t=>new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),Fl=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()}},JI=t=>{if(!Array.isArray(t))return[];const e=new Set,n=new Set,r=[];for(const a of t){if(!a||typeof a!="object")continue;const i=a,o=typeof i.id=="string"?i.id.trim():"",c=typeof i.name=="string"?i.name.trim():"",d=Fl(typeof i.hostname=="string"?i.hostname:"");!o||!c||!d||e.has(o)||n.has(d)||(e.add(o),n.add(d),r.push({id:o,name:c,hostname:d}))}return r},YI=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,XI=()=>{const{t}=ut(),e=l.useCallback(ye=>t(ye),[t]),[n,r]=l.useState("checking"),[a,i]=l.useState(null),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(null),[f,y]=l.useState(null),[h,b]=l.useState(!1),[x,g]=l.useState(!1),[w,v]=l.useState(!1),[S,P]=l.useState("cloudflare"),[j,C]=l.useState([]),[I,R]=l.useState("quick"),[k,A]=l.useState(null),[N,D]=l.useState([]),[T,M]=l.useState({}),[$,F]=l.useState(""),[_,O]=l.useState({}),[L,K]=l.useState(new Set),[B,re]=l.useState(!1),[oe,ee]=l.useState(""),[ae,ge]=l.useState(""),[ne,E]=l.useState(""),[z,J]=l.useState(1800*1e3),[H,te]=l.useState(480*60*1e3),[ce,Se]=l.useState(""),[pe,we]=l.useState([]),[W,ue]=l.useState(()=>Date.now()),[Y,le]=l.useState(null),Z=t(qI),Ie=l.useRef(null),Ne=l.useMemo(()=>k?!po(k):!1,[k]),X=l.useMemo(()=>N.find(ye=>ye.id===$)||N[0]||null,[N,$]),he=l.useMemo(()=>pe.map(ye=>{const Ge=ye.expiresAt<=W,$e=ye.status==="active"&&!Ge,_e=$e?Hh(ye.expiresAt-W):ye.inactiveReason==="expired"||Ge?"expired":"inactive",tt=_e==="expired"?t("settings.openchamber.tunnel.state.expired"):ye.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),Qe=La(ye.mode);return{...ye,isActive:$e,mode:Qe,remainingTextForSession:_e,inactiveLabel:tt}}),[W,pe,t]),je=l.useMemo(()=>a?.connectUrl?a.bootstrapExpiresAt===null?!0:a.bootstrapExpiresAt>W:!1,[W,a?.bootstrapExpiresAt,a?.connectUrl]),be=l.useMemo(()=>!a||n!=="active"&&n!=="stopping"?!1:o===I,[o,n,a,I]),fe=l.useMemo(()=>!a||n!=="active"||!o?!1:o!==I,[o,n,a,I]),Pe=l.useMemo(()=>{if(typeof Y=="number"&&Number.isFinite(Y)&&Y>0)return Y;if(typeof window>"u")return null;const ye=Number(window.location.port);return Number.isFinite(ye)&&ye>0?ye:null},[Y]),Be=l.useCallback(async ye=>{await mr(ye)},[]),G=l.useCallback(async ye=>{try{const[Ge,$e,_e,tt]=await Promise.all([fetch("/api/openchamber/tunnel/check",{signal:ye}),fetch("/api/openchamber/tunnel/status",{signal:ye}),fetch("/api/config/settings",{signal:ye,headers:{Accept:"application/json"}}),fetch("/api/openchamber/tunnel/providers",{signal:ye})]),Qe=await Ge.json(),ze=await $e.json(),gt=_e.ok?await _e.json():{},Vt=tt.ok?await tt.json():{},Kt=ze.ttlConfig?.bootstrapTtlMs??(gt?.tunnelBootstrapTtlMs===null?null:typeof gt?.tunnelBootstrapTtlMs=="number"?gt.tunnelBootstrapTtlMs:1800*1e3),Jt=typeof ze.ttlConfig?.sessionTtlMs=="number"?ze.ttlConfig.sessionTtlMs:typeof gt?.tunnelSessionTtlMs=="number"?gt.tunnelSessionTtlMs:480*60*1e3,At=La(ze.mode??gt?.tunnelMode),jt=typeof gt?.tunnelProvider=="string"&>.tunnelProvider.trim().length>0?gt.tunnelProvider.trim().toLowerCase():"cloudflare",ns=typeof gt?.managedLocalTunnelConfigPath=="string"&>.managedLocalTunnelConfigPath.trim()||null,ot=JI(ze?.managedRemoteTunnelPresets),Zt=typeof ze.managedRemoteTunnelHostname=="string"?ze.managedRemoteTunnelHostname:"",Yt=ot.length>0?ot:Zt?[{id:`legacy-${Fl(Zt)}`,name:Zt,hostname:Fl(Zt)}]:[],es=Yt[0]?.id||"";if(J(Kt),te(Jt),P(jt),C(Array.isArray(Vt?.providers)?Vt.providers:[]),R(At),A(ns),D(Yt),F(es),we(Array.isArray(ze.activeSessions)?ze.activeSessions:[]),c(ze.activeTunnelMode?La(ze.activeTunnelMode):ze.active&&ze.mode?La(ze.mode):null),K(new Set(Array.isArray(ze.managedRemoteTunnelTokenPresetIds)?ze.managedRemoteTunnelTokenPresetIds:[])),le(typeof ze.localPort=="number"?ze.localPort:null),ze.active&&ze.url){i({url:ze.url,connectUrl:null,bootstrapExpiresAt:typeof ze.bootstrapExpiresAt=="number"?ze.bootstrapExpiresAt:null}),r("active");return}r(Qe.available?"idle":"not-available")}catch{ye.aborted||(r("error"),u(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[t]);l.useEffect(()=>{const ye=new AbortController;return G(ye.signal),()=>ye.abort()},[G]),l.useEffect(()=>{if(!a?.connectUrl){p(null);return}let ye=!1;return Ey.toDataURL(a.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(Ge=>{ye||p(Ge)}).catch(()=>{ye||p(null)}),()=>{ye=!0}},[a?.connectUrl]),l.useEffect(()=>{if(!a?.bootstrapExpiresAt){Se(t("settings.openchamber.tunnel.state.noExpiry"));return}let ye=null,Ge=Date.now();const $e=()=>{const Qe=a.bootstrapExpiresAt?a.bootstrapExpiresAt-Date.now():0;Qe<=0?Se(t("settings.openchamber.tunnel.state.expired")):Se(Hh(Qe))},_e=()=>{const Qe=Date.now();Qe-Ge>=1e3&&($e(),Ge=Qe),ye=requestAnimationFrame(_e)};$e(),(typeof document>"u"||document.visibilityState==="visible")&&(ye=requestAnimationFrame(_e));const tt=()=>{document.visibilityState==="visible"&&ye===null?ye=requestAnimationFrame(_e):document.visibilityState!=="visible"&&ye!==null&&(cancelAnimationFrame(ye),ye=null)};return document.addEventListener("visibilitychange",tt),()=>{document.removeEventListener("visibilitychange",tt),ye!==null&&cancelAnimationFrame(ye)}},[t,a?.bootstrapExpiresAt]),l.useEffect(()=>{let ye=null,Ge=Date.now();const $e=()=>{const tt=Date.now();tt-Ge>=1e3&&(ue(tt),Ge=tt),ye=requestAnimationFrame($e)};(typeof document>"u"||document.visibilityState==="visible")&&(ye=requestAnimationFrame($e));const _e=()=>{document.visibilityState==="visible"&&ye===null?ye=requestAnimationFrame($e):document.visibilityState!=="visible"&&ye!==null&&(cancelAnimationFrame(ye),ye=null)};return document.addEventListener("visibilitychange",_e),()=>{document.removeEventListener("visibilitychange",_e),ye!==null&&cancelAnimationFrame(ye)}},[]),l.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let ye=!1;const Ge=async()=>{try{const _e=await fetch("/api/openchamber/tunnel/status");if(!_e.ok||ye)return;const tt=await _e.json();if(ye)return;we(Array.isArray(tt.activeSessions)?tt.activeSessions:[]),K(new Set(Array.isArray(tt.managedRemoteTunnelTokenPresetIds)?tt.managedRemoteTunnelTokenPresetIds:[])),le(typeof tt.localPort=="number"?tt.localPort:null)}catch{}},$e=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Ge()},5e3);return()=>{ye=!0,window.clearInterval($e)}},[n]);const ke=l.useCallback(async ye=>{v(!0);try{await As(ye),Object.prototype.hasOwnProperty.call(ye,"tunnelMode")&&ye.tunnelMode&&R(ye.tunnelMode),Object.prototype.hasOwnProperty.call(ye,"tunnelProvider")&&typeof ye.tunnelProvider=="string"&&P(ye.tunnelProvider),Object.prototype.hasOwnProperty.call(ye,"managedLocalTunnelConfigPath")&&A(ye.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(ye,"managedRemoteTunnelPresets")&&ye.managedRemoteTunnelPresets&&D(ye.managedRemoteTunnelPresets)}catch{q.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{v(!1)}},[t]),Ee=l.useCallback(async(ye,Ge)=>{g(!0);try{await As({tunnelBootstrapTtlMs:ye,tunnelSessionTtlMs:Ge})}catch{q.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{g(!1)}},[t]),Ae=l.useCallback(async ye=>{const Ge=ye.token.trim();if(Ge)try{const $e={..._,[ye.presetId]:Ge};await As({managedRemoteTunnelPresetTokens:$e}),K(_e=>{const tt=new Set(_e);return tt.add(ye.presetId),tt})}catch{q.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[_,t]),xe=l.useCallback(async ye=>{y(null),u(null),await ke({tunnelProvider:ye})},[ke]),V=l.useCallback(async()=>{const ye=await B1({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(ye.success&&typeof ye.path=="string"&&ye.path.trim().length>0){const Ge=ye.path.trim();if(!po(Ge)){q.error(Z);return}A(Ge),await ke({managedLocalTunnelConfigPath:Ge});return}Ie.current?.click()},[Z,ke]),de=l.useCallback(ye=>{const Ge=ye.trim();A(Ge.length>0?Ge:null)},[]),Me=l.useCallback(async()=>{if(k&&!po(k)){q.error(Z);return}await ke({managedLocalTunnelConfigPath:k})},[Z,k,ke]),Le=l.useCallback(async()=>{A(null),await ke({managedLocalTunnelConfigPath:null})},[ke]),se=l.useCallback(async ye=>{const Ge=ye.target.files?.[0];if(!Ge)return;const $e=Ge.name.trim();if($e.length!==0){if(!po($e)){q.error(Z);return}A($e),await ke({managedLocalTunnelConfigPath:$e}),ye.target.value=""}},[Z,ke]),ie=l.useCallback(async()=>{if(u(null),y(null),I==="managed-local"&&k&&!po(k)){u(Z),q.error(Z);return}r("starting");try{let ye="",Ge="";if(I==="managed-remote"){if(!X){r("idle"),y(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),q.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}ye=X.hostname,Ge=(_[X.id]||"").trim(),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:N})}const $e=await fetch("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:S,mode:I,...I==="managed-remote"&&X?{managedRemoteTunnelPresetId:X.id,managedRemoteTunnelPresetName:X.name}:{},...I==="managed-remote"&&ye?{managedRemoteTunnelHostname:ye}:{},...I==="managed-remote"&&Ge?{managedRemoteTunnelToken:Ge}:{},...I==="managed-local"&&k?{configPath:k}:{}})}),_e=await $e.json();if(!$e.ok||!_e.ok){if(I==="managed-remote"&&typeof _e.error=="string"&&_e.error.includes("Managed remote tunnel token is required")){r("idle"),y(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),q.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),u(_e.error||t("settings.openchamber.tunnel.toast.startFailed")),q.error(_e.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const tt=typeof _e.url=="string"?_e.url:"";if(!tt){r("error"),u(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),q.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(i({url:tt,connectUrl:typeof _e.connectUrl=="string"?_e.connectUrl:null,bootstrapExpiresAt:typeof _e.bootstrapExpiresAt=="number"?_e.bootstrapExpiresAt:null}),c(_e.activeTunnelMode?La(_e.activeTunnelMode):_e.mode?La(_e.mode):I),we(Array.isArray(_e.activeSessions)?_e.activeSessions:[]),Array.isArray(_e.managedRemoteTunnelTokenPresetIds)&&K(new Set(_e.managedRemoteTunnelTokenPresetIds)),typeof _e.localPort=="number"&&le(_e.localPort),typeof _e.mode=="string"&&R(La(_e.mode)),r("active"),_e.replacedTunnel){const Qe=typeof _e.revokedBootstrapCount=="number"?_e.revokedBootstrapCount:0,ze=typeof _e.invalidatedSessionCount=="number"?_e.invalidatedSessionCount:0;Qe===1&&ze===1?q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):Qe===1?q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:ze})):ze===1?q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:Qe})):q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:Qe,invalidatedSessionCount:ze}))}else q.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.startFailed")),q.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[Z,N,ke,X,_,t,S,I,k]),U=l.useCallback(async()=>{r("stopping");try{await fetch("/api/openchamber/tunnel/stop",{method:"POST"});const ye=await fetch("/api/openchamber/tunnel/status");if(ye.ok){const Ge=await ye.json();we(Array.isArray(Ge.activeSessions)?Ge.activeSessions:[]),K(new Set(Array.isArray(Ge.managedRemoteTunnelTokenPresetIds)?Ge.managedRemoteTunnelTokenPresetIds:[])),le(typeof Ge.localPort=="number"?Ge.localPort:null)}i(null),c(null),p(null),r("idle"),q.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.stopFailed")),q.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),Ve=l.useCallback(async()=>{if(a?.connectUrl)try{await navigator.clipboard.writeText(a.connectUrl),b(!0),q.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>b(!1),2e3)}catch{q.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,a?.connectUrl]),He=l.useCallback(async ye=>{const Ge=bd.find($e=>$e.value===ye);Ge&&(J(Ge.ms),await Ee(Ge.ms,H))},[Ee,H]),Ke=l.useCallback(async ye=>{const Ge=yd.find($e=>$e.value===ye);!Ge||Ge.ms===null||(te(Ge.ms),await Ee(z,Ge.ms))},[z,Ee]),Ze=l.useCallback(async ye=>{y(null),u(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await ke({tunnelMode:ye,managedRemoteTunnelPresets:N})},[N,ke,n]),Xe=l.useCallback(async(ye,Ge)=>{try{await As({managedRemoteTunnelPresets:Ge})}catch{q.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),dt=l.useCallback(ye=>{const Ge=N.find($e=>$e.id===ye);Ge&&(F(Ge.id),y(null),Xe(Ge,N))},[N,Xe]),et=l.useCallback(async()=>{const ye=oe.trim(),Ge=Fl(ae),$e=ne.trim();if(!ye){q.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!Ge){q.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!$e){q.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(N.some(Qe=>Qe.hostname===Ge)){q.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const _e={id:YI(),name:ye,hostname:Ge},tt=[...N,_e];D(tt),F(_e.id),M(Qe=>({...Qe,[_e.id]:!0})),O(Qe=>({...Qe,[_e.id]:$e})),y(null),re(!1),ee(""),ge(""),E(""),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:tt,managedRemoteTunnelPresetTokens:{..._,[_e.id]:$e}}),await Ae({presetId:_e.id,presetName:_e.name,hostname:_e.hostname,token:$e}),q.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[N,ae,oe,ne,Ae,ke,_,t]),ct=l.useCallback(async ye=>{const Ge=N.find(ze=>ze.id===ye);if(!Ge)return;const $e=N.filter(ze=>ze.id!==Ge.id),_e=$e[0]?.id||"",tt=$===Ge.id?_e:$,Qe=Object.fromEntries(Object.entries(_).filter(([ze,gt])=>ze!==Ge.id&>.trim().length>0));D($e),F(tt),M(ze=>{const gt={...ze};return delete gt[Ge.id],gt}),O(ze=>{const gt={...ze};return delete gt[Ge.id],gt}),K(ze=>{const gt=new Set(ze);return gt.delete(Ge.id),gt}),y(null),await ke({managedRemoteTunnelPresets:$e,managedRemoteTunnelPresetTokens:Qe}),q.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[N,ke,$,_,t]),at="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")})]}),he.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(Us,{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:he.map(ye=>{const Ge=ye.mode==="quick",$e=ye.mode==="managed-remote",_e=Ge?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":$e?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",tt=ye.isActive?Ge?"text-[var(--status-warning)]":$e?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",Qe=t(Ge?"settings.openchamber.tunnel.badge.quick":$e?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(Fy,{className:me("size-2.5 shrink-0",tt)}),s.jsx("span",{className:me("typography-micro rounded border px-1.5 py-0.5 uppercase",_e),children:Qe}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:QI(ye.createdAt)})}),s.jsx("span",{className:"typography-meta text-foreground",children:ye.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:ye.remainingTextForSession}):ye.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:ye.inactiveLabel})})]},ye.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(Qr,{className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.notAvailable.cloudflaredNotFound")}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:"brew install cloudflared"})]})]})}),n!=="not-available"&&s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(ps,{value:S,onValueChange:ye=>{xe(ye)},disabled:w||n==="starting"||n==="stopping",children:[s.jsx(hs,{className:"max-w-[16rem]",children:s.jsx(ys,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:Hx(S)})}),s.jsxs(fs,{children:[j.length>0?j.map(ye=>s.jsx(Rt,{value:ye.provider,children:s.jsx(Wh,{provider:ye.provider})},ye.provider)):s.jsx(Rt,{value:"cloudflare",children:s.jsx(Wh,{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:Uh.map(ye=>s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":I===ye.value,className:"!font-normal",onClick:()=>{Ze(ye.value)},disabled:w||n==="starting"||n==="stopping",children:e(ye.labelKey)})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:e(ye.tooltipKey)})]},ye.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(ps,{value:Kh(bd,z,"1800000"),onValueChange:ye=>{He(ye)},disabled:x||w||n==="starting"||n==="stopping",children:[s.jsx(hs,{className:"max-w-[11rem] min-w-0",children:s.jsx(ys,{className:"truncate"})}),s.jsx(fs,{children:bd.map(ye=>s.jsx(Rt,{value:ye.value,children:ye.label},ye.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(ps,{value:Kh(yd,H,"28800000"),onValueChange:ye=>{Ke(ye)},disabled:x||w||n==="starting"||n==="stopping",children:[s.jsx(hs,{className:"max-w-[11rem] min-w-0",children:s.jsx(ys,{className:"truncate"})}),s.jsx(fs,{children:yd.map(ye=>s.jsx(Rt,{value:ye.value,children:ye.label},ye.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(Qr,{className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.option.mode.quick.tooltip")}),s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),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 Pe=="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:",Pe]})]})}),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(ve,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>re(ye=>!ye),disabled:n==="starting"||n==="stopping"||w,children:[s.jsx(zs,{className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),N.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:N.map((ye,Ge)=>{const $e=_[ye.id]||"",_e=L.has(ye.id),tt=T[ye.id]??!1;return s.jsx("div",{className:me(Ge<N.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(wr,{open:tt,onOpenChange:Qe=>{M(ze=>({...ze,[ye.id]:Qe})),Qe&&dt(ye.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Rr,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||w,children:[tt?s.jsx(ks,{className:"h-4 w-4 text-muted-foreground"}):s.jsx($n,{className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:ye.name})]}),s.jsx(ve,{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:ye.name}),onClick:()=>{ct(ye.id)},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(an,{className:"h-3.5 w-3.5"})})]}),s.jsx(jr,{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:ye.hostname})]}),s.jsx(Bt,{type:"password",value:$e,onChange:Qe=>{const ze=Qe.target.value;y(null),O(gt=>({...gt,[ye.id]:ze}))},onBlur:Qe=>{const ze=Qe.currentTarget.value.trim();ze&&Ae({presetId:ye.id,presetName:ye.name,hostname:ye.hostname,token:ze})},placeholder:t(_e?"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(ve,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||$e.trim().length===0,onClick:()=>{Ae({presetId:ye.id,presetName:ye.name,hostname:ye.hostname,token:$e})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},ye.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),B&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Bt,{value:oe,onChange:ye=>ee(ye.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Bt,{value:ae,onChange:ye=>ge(ye.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Bt,{type:"password",value:ne,onChange:ye=>E(ye.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),typeof Pe=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Pe]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{et()},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{re(!1),ee(""),ge(""),E("")},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsxs(St,{children:[s.jsx(kt,{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(Us,{className:"h-3.5 w-3.5"})})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]})]}),!X&&f&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:f})]}),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:Ie,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:ye=>{se(ye)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bt,{value:k||"",onChange:ye=>{de(ye.target.value)},onBlur:()=>{Me()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||w}),s.jsx(ve,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{V()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(Un,{className:"size-3.5"})}),k&&s.jsx(ve,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{Le()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(Is,{className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(k?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),Ne&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Z})]})}),!be&&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(Us,{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:()=>{Be(KI)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(Pr,{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:()=>{Be(HI)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(Pr,{className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.startModeAndGenerateLink",{mode:e(Uh.find(ye=>ye.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(ps,{value:$||(N[0]?.id??""),onValueChange:ye=>{dt(ye)},disabled:w||n==="starting"||n==="stopping"||N.length<=1,children:[s.jsx(hs,{children:s.jsx(ys,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:X?.name})}),s.jsx(fs,{fitContent:!0,children:N.map(ye=>s.jsx(Rt,{value:ye.id,children:ye.name},ye.id))})]})]}),fe&&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(Qr,{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(ve,{size:"sm",variant:"outline",onClick:ie,disabled:n==="starting"||w||I==="managed-remote"&&!X||I==="managed-local"&&Ne,className:me(at,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(ts,{className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),be&&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})]}),je&&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(ve,{size:"sm",variant:"ghost",onClick:Ve,className:"shrink-0 gap-1.5",children:[h?s.jsx(Zs,{className:"size-3.5 text-[var(--status-success)]"}):s.jsx(vr,{className:"size-3.5"}),t(h?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.expires"),": ",a.bootstrapExpiresAt?ce: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(ve,{size:"sm",variant:"outline",onClick:ie,disabled:n==="stopping"||w||I==="managed-local"&&Ne,className:at,children:[s.jsx(Fn,{className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(ve,{size:"sm",variant:"ghost",onClick:U,disabled:n==="stopping"||w,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(ts,{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(ve,{size:"sm",variant:"ghost",onClick:ie,children:t("settings.openchamber.tunnel.actions.retry")})]})]})},Gx=()=>{const{t}=ut(),[e,n]=Oe.useState(""),[r,a]=Oe.useState(!0),[i,o]=Oe.useState(!1);Oe.useEffect(()=>{let p=!1;return(async()=>{try{const m=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!m.ok)return;const u=await m.json().catch(()=>null);if(p||!u)return;const f=typeof u.opencodeBinary=="string"?u.opencodeBinary.trim():"";n(f)}catch{}finally{p||a(!1)}})(),()=>{p=!0}},[]);const c=Oe.useCallback(async()=>{if(typeof window>"u"||!Pn()||!ri())return;const p=window.__TAURI__;if(p?.dialog?.open)try{const m=await p.dialog.open({title:t("settings.openchamber.opencodeCli.dialog.selectBinaryTitle"),multiple:!1,directory:!1});typeof m=="string"&&m.trim().length>0&&n(m.trim())}catch{}},[t]),d=Oe.useCallback(async()=>{o(!0);try{await As({opencodeBinary:e.trim()}),await ko({message:t("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}finally{o(!1)}},[t,e]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.opencodeCli.title")}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(It,{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(Bt,{value:e,onChange:p=>n(p.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(ve,{type:"button",variant:"outline",size:"xs",onClick:c,disabled:r||i||!Pn()||!ri(),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(Un,{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.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(ve,{type:"button",size:"xs",onClick:d,disabled:r||i,className:"shrink-0 !font-normal",children:t(i?"settings.common.actions.saving":"settings.openchamber.opencodeCli.actions.saveAndReload")})})]})]})},qx=()=>{const{t}=ut(),e=Pn()&&ca(),[n,r]=Oe.useState(!1),[a,i]=Oe.useState(!1),[o,c]=Oe.useState(!0),[d,p]=Oe.useState(!1),[m,u]=Oe.useState(null),[f,y]=Oe.useState(null);Oe.useEffect(()=>{if(!e){c(!1);return}let v=!1;return(async()=>{try{const S=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!S.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const P=await S.json().catch(()=>null);if(v)return;const j=P?.desktopLanAccessEnabled===!0;r(j),i(j),u(null)}catch(S){v||u(S instanceof Error?S.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{v||c(!1)}})(),()=>{v=!0}},[e,t]),Oe.useEffect(()=>{if(!e||!a){y(null);return}let v=!1;return(async()=>{const S=await _1();v||y(S)})(),()=>{v=!0}},[a,e]);const h=a!==n,b=Oe.useMemo(()=>{if(typeof window>"u")return null;const v=Number(window.location.port);return Number.isFinite(v)&&v>0?v:null},[]),x=a&&f&&b?`http://${f}:${b}`:null,g=Oe.useCallback(()=>{i(v=>!v)},[]),w=Oe.useCallback(async()=>{if(h){p(!0),u(null);try{if(!(await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:a})})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(r(a),!await Cg())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(v){u(v instanceof Error?v.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),p(!1)}}},[a,h,t]);return e?s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.desktopNetwork.title")})}),s.jsxs("section",{className:"space-y-2 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:g,onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),g())},children:[s.jsx(bs,{checked:a,onChange:g,ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria"),disabled:o||d}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.desktopNetwork.field.allowLanAccess")}),s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription")}),s.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.warning")})]})]}),m?s.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:m}):null,x?s.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[t(h&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:x})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(ve,{type:"button",size:"xs",onClick:w,disabled:o||d||!h,className:"shrink-0 !font-normal",children:t(d?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})]}):null},ZI=new Set(["shift","control","alt","meta"]),eA=t=>{if(ZI.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=z1(t.key);return n?(e.push(n),Pi(e.join("+"))):null},tA=()=>{const t=nt.c(58),{t:e}=ut();let n;t[0]!==e?(n=ne=>e(ne),t[0]=e,t[1]=n):n=t[1];const r=n,a=De(sA),i=De(nA),o=De(rA),c=De(aA);let d;t[2]===Symbol.for("react.memo_cache_sentinel")?(d=V1(),t[2]=d):d=t[2];const p=d;let m;t[3]!==r?(m=(ne,E)=>{const z=`settings.openchamber.keyboardShortcuts.action.${ne}.label`,J=r(z);return J===z?E:J},t[3]=r,t[4]=m):m=t[4];const u=m,[f,y]=l.useState(null);let h;t[5]===Symbol.for("react.memo_cache_sentinel")?(h={},t[5]=h):h=t[5];const[b,x]=l.useState(h),[g,w]=l.useState(""),[v,S]=l.useState(""),[P,j]=l.useState(null);let C;t[6]!==a?(C=(ne,E)=>{const z=Pi(E);for(const J of p){if(J.id===ne)continue;const H=ia(J.id,a);if(Pi(H)===z)return J.id}return null},t[6]=a,t[7]=C):C=t[7];const I=C;let R;t[8]!==I||t[9]!==i||t[10]!==e?(R=(ne,E)=>{const z=Pi(E),J=I(ne,z);if(J){j({actionId:ne,combo:z,conflictActionId:J}),w("");return}i(ne,z),j(null),w(""),S(Om(z)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(H=>{const te={...H};return delete te[ne],te})},t[8]=I,t[9]=i,t[10]=e,t[11]=R):R=t[11];const k=R;let A;t[12]!==P||t[13]!==i||t[14]!==e?(A=()=>{P&&(i(P.conflictActionId,U1),i(P.actionId,P.combo),j(null),w(""),S(Om(P.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(ne=>{const E={...ne};return delete E[P.actionId],E}))},t[12]=P,t[13]=i,t[14]=e,t[15]=A):A=t[15];const N=A;let D;t[16]!==o?(D=ne=>{o(ne),x(E=>{const z={...E};return delete z[ne],z}),j(null),w(""),S("")},t[16]=o,t[17]=D):D=t[17];const T=D;let M;t[18]!==e?(M=e("settings.openchamber.keyboardShortcuts.title"),t[18]=e,t[19]=M):M=t[19];let $;t[20]!==M?($=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:M}),t[20]=M,t[21]=$):$=t[21];let F;t[22]!==c?(F=()=>{c(),x({}),j(null),w(""),S("")},t[22]=c,t[23]=F):F=t[23];let _;t[24]!==e?(_=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),t[24]=e,t[25]=_):_=t[25];let O;t[26]!==F||t[27]!==_?(O=s.jsx(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:F,children:_}),t[26]=F,t[27]=_,t[28]=O):O=t[28];let L;t[29]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(kt,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[29]=L):L=t[29];let K;t[30]!==e?(K=e("settings.openchamber.keyboardShortcuts.tooltip"),t[30]=e,t[31]=K):K=t[31];let B;t[32]!==K?(B=s.jsxs(St,{children:[L,s.jsx(It,{sideOffset:8,className:"max-w-xs",children:K})]}),t[32]=K,t[33]=B):B=t[33];let re;t[34]!==O||t[35]!==B||t[36]!==$?(re=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[$,O,B]})}),t[34]=O,t[35]=B,t[36]=$,t[37]=re):re=t[37];let oe;t[38]!==N||t[39]!==g||t[40]!==P||t[41]!==e||t[42]!==v?(oe=(g||v||P)&&s.jsxs("div",{className:"mb-2 space-y-2 px-1",children:[P&&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(ve,{type:"button",size:"xs",className:"!font-normal",onClick:N,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),s.jsx(ve,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>j(null),children:e("settings.common.actions.cancel")})]})]}),g&&s.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:g}),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]=N,t[39]=g,t[40]=P,t[41]=e,t[42]=v,t[43]=oe):oe=t[43];let ee;t[44]!==u||t[45]!==f||t[46]!==b||t[47]!==T||t[48]!==k||t[49]!==a||t[50]!==e?(ee=p.map((ne,E)=>{const z=ia(ne.id,a),J=b[ne.id],H=J??z,te=typeof J=="string"&&Pi(J)!==Pi(z);return s.jsxs("div",{className:me("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",E>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(ne.id,ne.label)})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx(Bt,{readOnly:!0,value:f===ne.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):gc(H),onFocus:()=>{y(ne.id),w("")},onBlur:()=>{f===ne.id&&y(null)},onKeyDown:ce=>{if(ce.preventDefault(),ce.stopPropagation(),ce.key==="Escape"){y(null);return}const Se=eA(ce);Se&&(x(pe=>({...pe,[ne.id]:Se})),y(null),j(null),w(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),s.jsx(ve,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const ce=b[ne.id];if(!ce){w(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}k(ne.id,ce)},disabled:!te,children:e("settings.common.actions.saveChanges")}),s.jsx(ve,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>T(ne.id),children:e("settings.common.actions.reset")})]})]},ne.id)}),t[44]=u,t[45]=f,t[46]=b,t[47]=T,t[48]=k,t[49]=a,t[50]=e,t[51]=ee):ee=t[51];let ae;t[52]!==ee?(ae=s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:ee}),t[52]=ee,t[53]=ae):ae=t[53];let ge;return t[54]!==re||t[55]!==oe||t[56]!==ae?(ge=s.jsxs("div",{className:"mb-8",children:[re,oe,ae]}),t[54]=re,t[55]=oe,t[56]=ae,t[57]=ge):ge=t[57],ge};function sA(t){return t.shortcutOverrides}function nA(t){return t.setShortcutOverride}function rA(t){return t.clearShortcutOverride}function aA(t){return t.resetAllShortcutOverrides}const iA=t=>{const e=nt.c(20),{section:n}=t,{isMobile:r}=dn();let a;e[0]!==r?(a=r&&Sa(),e[0]=r,e[1]=a):a=e[1];const i=a;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=jn(),e[2]=o):o=e[2];const c=o;let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=Pn()&&ca(),e[3]=d):d=e[3];const p=d;if(!n){let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(sm,{}),e[4]=h):h=e[4];let b,x,g;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Kx,{})}),x=!c&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Gx,{})}),g=p&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(qx,{})}),e[5]=b,e[6]=x,e[7]=g):(b=e[5],x=e[6],g=e[7]);let w;e[8]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ux,{})}),e[8]=w):w=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(Wx,{})}),e[9]=v):v=e[9];let S;e[10]!==i?(S=i&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(AI,{})}),e[10]=i,e[11]=S):S=e[11];let P;return e[12]!==S?(P=s.jsx(Ps,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-3 p-3 sm:space-y-6 sm:p-6 sm:pt-8",children:[h,b,x,g,w,v,S]})}),e[12]=S,e[13]=P):P=e[13],P}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return s.jsx(lA,{});case"chat":return s.jsx(cA,{});case"sessions":return s.jsx(dA,{});case"shortcuts":return s.jsx(oA,{});case"git":return s.jsx(uA,{});case"github":return s.jsx(mA,{});case"notifications":return s.jsx(pA,{});case"voice":return s.jsx(hA,{});case"tunnel":return s.jsx(fA,{});default:return null}},e[14]=n,e[15]=m):m=e[15];const u=m;let f;e[16]!==u?(f=u(),e[16]=u,e[17]=f):f=e[17];let y;return e[18]!==f?(y=s.jsx(Ps,{outerClassName:"h-full",className:"w-full",children:s.jsx("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",children:f})}),e[18]=f,e[19]=y):y=e[19],y},oA=()=>{const t=nt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(tA,{}),t[0]=e):e=t[0],e},lA=()=>{const t=nt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=jn(),t[0]=e):e=t[0];const n=e;let r;return t[1]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(sm,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat","weekStart","fontSize","terminalFontSize","spacing","inputBarOffset",...n?[]:["terminalQuickKeys"],"reportUsage"]}),t[1]=r):r=t[1],r},cA=()=>{const t=nt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(sm,{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},dA=()=>{const t=nt.c(7);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=jn(),t[0]=e):e=t[0];const n=e;let r;t[1]===Symbol.for("react.memo_cache_sentinel")?(r=Pn()&&ca(),t[1]=r):r=t[1];const a=r;let i,o,c;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Kx,{}),o=!n&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Gx,{})}),c=a&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(qx,{})}),t[2]=i,t[3]=o,t[4]=c):(i=t[2],o=t[3],c=t[4]);let d;t[5]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ux,{})}),t[5]=d):d=t[5];let p;return t[6]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsxs("div",{className:"space-y-6",children:[i,o,c,d,s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Wx,{})})]}),t[6]=p):p=t[6],p},uA=()=>{const t=nt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"space-y-6",children:s.jsx(Bx,{})}),t[0]=e):e=t[0],e},mA=()=>{const t=nt.c(1);if(jn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(_x,{}),t[0]=e):e=t[0],e},pA=()=>{const t=nt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(VI,{}),t[0]=e):e=t[0],e},hA=()=>{const t=nt.c(1);if(jn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(WI,{}),t[0]=e):e=t[0],e},fA=()=>{const t=nt.c(1);if(jn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(XI,{}),t[0]=e):e=t[0],e},du=176,uu=280,Gh=8;function vd(t){return Math.min(uu,Math.max(du,t))}const gA=["appearance","chat","notifications","sessions","shortcuts","git","magic-prompts","projects","remote-instances","agents","behavior","commands","mcp","providers","usage","skills.installed","skills.catalog","voice","tunnel"];function xA(t){const e=jn(),n=!t&&Sa();return{isVSCode:e,isWeb:n,isDesktop:t}}function qh(t,e){return t.isAvailable?t.isAvailable(e):!0}function nm(t){switch(t){case"projects":return Uy;case"remote-instances":return ei;case"appearance":return ag;case"chat":return rg;case"magic-prompts":return Ga;case"notifications":return zy;case"shortcuts":return Vo;case"sessions":return Vy;case"providers":return ng;case"agents":return Eu;case"behavior":return _y;case"commands":return By;case"mcp":return Hg;case"skills.installed":return Fu;case"skills.catalog":return $y;case"git":return Qs;case"usage":return Ly;case"voice":return Oy;case"tunnel":return ti;case"home":return null;default:return Jr}}const wd=t=>{const e=nt.c(95),{onOpen:n}=t,{t:r}=ut();let a;e[0]!==r?(a=r("settings.view.home.title"),e[0]=r,e[1]=a):a=e[1];let i;e[2]!==a?(i=s.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:a}),e[2]=a,e[3]=i):i=e[3];let o;e[4]!==r?(o=r("settings.view.home.description"),e[4]=r,e[5]=o):o=e[5];let c;e[6]!==o?(c=s.jsx("p",{className:"typography-ui text-muted-foreground",children:o}),e[6]=o,e[7]=c):c=e[7];let d;e[8]!==i||e[9]!==c?(d=s.jsxs("div",{className:"space-y-1",children:[i,c]}),e[8]=i,e[9]=c,e[10]=d):d=e[10];let p;e[11]!==n?(p=()=>n("providers"),e[11]=n,e[12]=p):p=e[12];let m;e[13]===Symbol.for("react.memo_cache_sentinel")?(m=me("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[13]=m):m=e[13];let u;e[14]!==r?(u=r("settings.view.home.cards.providers.title"),e[14]=r,e[15]=u):u=e[15];let f;e[16]!==u?(f=s.jsx("div",{className:"typography-ui-label text-foreground",children:u}),e[16]=u,e[17]=f):f=e[17];let y;e[18]!==r?(y=r("settings.view.home.cards.providers.description"),e[18]=r,e[19]=y):y=e[19];let h;e[20]!==y?(h=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:y}),e[20]=y,e[21]=h):h=e[21];let b;e[22]!==h||e[23]!==p||e[24]!==f?(b=s.jsxs("button",{type:"button",onClick:p,className:m,children:[f,h]}),e[22]=h,e[23]=p,e[24]=f,e[25]=b):b=e[25];let x;e[26]!==n?(x=()=>n("agents"),e[26]=n,e[27]=x):x=e[27];let g;e[28]===Symbol.for("react.memo_cache_sentinel")?(g=me("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[28]=g):g=e[28];let w;e[29]!==r?(w=r("settings.view.home.cards.agents.title"),e[29]=r,e[30]=w):w=e[30];let v;e[31]!==w?(v=s.jsx("div",{className:"typography-ui-label text-foreground",children:w}),e[31]=w,e[32]=v):v=e[32];let S;e[33]!==r?(S=r("settings.view.home.cards.agents.description"),e[33]=r,e[34]=S):S=e[34];let P;e[35]!==S?(P=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:S}),e[35]=S,e[36]=P):P=e[36];let j;e[37]!==x||e[38]!==v||e[39]!==P?(j=s.jsxs("button",{type:"button",onClick:x,className:g,children:[v,P]}),e[37]=x,e[38]=v,e[39]=P,e[40]=j):j=e[40];let C;e[41]!==n?(C=()=>n("skills.catalog"),e[41]=n,e[42]=C):C=e[42];let I;e[43]===Symbol.for("react.memo_cache_sentinel")?(I=me("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 R;e[44]!==r?(R=r("settings.view.home.cards.skillsCatalog.title"),e[44]=r,e[45]=R):R=e[45];let k;e[46]!==R?(k=s.jsx("div",{className:"typography-ui-label text-foreground",children:R}),e[46]=R,e[47]=k):k=e[47];let A;e[48]!==r?(A=r("settings.view.home.cards.skillsCatalog.description"),e[48]=r,e[49]=A):A=e[49];let N;e[50]!==A?(N=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:A}),e[50]=A,e[51]=N):N=e[51];let D;e[52]!==C||e[53]!==k||e[54]!==N?(D=s.jsxs("button",{type:"button",onClick:C,className:I,children:[k,N]}),e[52]=C,e[53]=k,e[54]=N,e[55]=D):D=e[55];let T;e[56]!==n?(T=()=>n("mcp"),e[56]=n,e[57]=T):T=e[57];let M;e[58]===Symbol.for("react.memo_cache_sentinel")?(M=me("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[58]=M):M=e[58];let $;e[59]!==r?($=r("settings.view.home.cards.mcp.title"),e[59]=r,e[60]=$):$=e[60];let F;e[61]!==$?(F=s.jsx("div",{className:"typography-ui-label text-foreground",children:$}),e[61]=$,e[62]=F):F=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 L;e[67]!==T||e[68]!==F||e[69]!==O?(L=s.jsxs("button",{type:"button",onClick:T,className:M,children:[F,O]}),e[67]=T,e[68]=F,e[69]=O,e[70]=L):L=e[70];let K;e[71]!==n?(K=()=>n("usage"),e[71]=n,e[72]=K):K=e[72];let B;e[73]===Symbol.for("react.memo_cache_sentinel")?(B=me("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[73]=B):B=e[73];let re;e[74]!==r?(re=r("settings.view.home.cards.usage.title"),e[74]=r,e[75]=re):re=e[75];let oe;e[76]!==re?(oe=s.jsx("div",{className:"typography-ui-label text-foreground",children:re}),e[76]=re,e[77]=oe):oe=e[77];let ee;e[78]!==r?(ee=r("settings.view.home.cards.usage.description"),e[78]=r,e[79]=ee):ee=e[79];let ae;e[80]!==ee?(ae=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:ee}),e[80]=ee,e[81]=ae):ae=e[81];let ge;e[82]!==K||e[83]!==oe||e[84]!==ae?(ge=s.jsxs("button",{type:"button",onClick:K,className:B,children:[oe,ae]}),e[82]=K,e[83]=oe,e[84]=ae,e[85]=ge):ge=e[85];let ne;e[86]!==b||e[87]!==j||e[88]!==D||e[89]!==L||e[90]!==ge?(ne=s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[b,j,D,L,ge]}),e[86]=b,e[87]=j,e[88]=D,e[89]=L,e[90]=ge,e[91]=ne):ne=e[91];let E;return e[92]!==ne||e[93]!==d?(E=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,ne]})}),e[92]=ne,e[93]=d,e[94]=E):E=e[94],E},bA=t=>{const e=nt.c(102),{onClose:n,forceMobile:r,isWindowed:a}=t,{t:i}=ut(),o=dn(),c=r??o.isMobile,d=De(yA),p=De(vA),m=De(wA);let u;e[0]!==d?(u=Px(d),e[0]=d,e[1]=u):u=e[1];const f=u,[y,h]=l.useState("nav"),b=l.useRef(null),[x,g]=l.useState(216),[w,v]=l.useState(!1),[S,P]=l.useState(!1),j=l.useRef(0),C=l.useRef(x),I=l.useRef(null);let R;e[2]===Symbol.for("react.memo_cache_sentinel")?(R=Pn(),e[2]=R):R=e[2];const k=R;let A;e[3]===Symbol.for("react.memo_cache_sentinel")?(A=xA(k),e[3]=A):A=e[3];const N=A;let D;if(e[4]!==c){let Ae;e[6]===Symbol.for("react.memo_cache_sentinel")?(Ae=V=>qh(V,N),e[6]=Ae):Ae=e[6];let xe;e[7]===Symbol.for("react.memo_cache_sentinel")?(xe=V=>!(N.isVSCode&&V.slug==="projects"),e[7]=xe):xe=e[7],D=Zu.filter(jA).filter(Ae).filter(xe).filter(V=>!(c&&V.slug==="shortcuts")),e[4]=c,e[5]=D}else D=e[5];const T=D;let M;e[8]===Symbol.for("react.memo_cache_sentinel")?(M=new Map(gA.map(NA)),e[8]=M):M=e[8];const $=M;let F;if(e[9]!==T){let Ae;e[11]===Symbol.for("react.memo_cache_sentinel")?(Ae=(xe,V)=>($.get(xe.slug)??999)-($.get(V.slug)??999),e[11]=Ae):Ae=e[11],F=T.slice().sort(Ae),e[9]=T,e[10]=F}else F=e[10];const _=F,O=Es(SA);let L,K;e[12]!==w?(L=()=>{if(typeof window>"u")return;const Ae=()=>{if(!w){const xe=vd(Math.floor(window.innerWidth*.12));g(xe)}};return window.addEventListener("resize",Ae),()=>window.removeEventListener("resize",Ae)},K=[w],e[12]=w,e[13]=L,e[14]=K):(L=e[13],K=e[14]),l.useEffect(L,K);let B,re;e[15]!==S?(re=()=>{if(!S)return;const Ae=V=>{const de=V.clientX-j.current,Me=vd(C.current+de);g(Me),v(!0)},xe=()=>P(!1);return window.addEventListener("pointermove",Ae),window.addEventListener("pointerup",xe,{once:!0}),()=>{window.removeEventListener("pointermove",Ae),window.removeEventListener("pointerup",xe)}},B=[S],e[15]=S,e[16]=B,e[17]=re):(B=e[16],re=e[17]),l.useEffect(re,B);let oe;e[18]!==x?(oe=Ae=>{P(!0),j.current=Ae.clientX,C.current=x,Ae.preventDefault()},e[18]=x,e[19]=oe):oe=e[19];const ee=oe;let ae;e[20]!==x?(ae=Ae=>{const xe=Ae.shiftKey?Gh*4:Gh;let V;e:switch(Ae.key){case"ArrowLeft":{V=x-xe;break e}case"ArrowRight":{V=x+xe;break e}case"Home":{V=du;break e}case"End":{V=uu;break e}default:return}Ae.preventDefault(),g(vd(V)),v(!0)},e[20]=x,e[21]=ae):ae=e[21];const ge=ae;let ne;e[22]!==p||e[23]!==f?(ne=()=>{if(!(!p&&!N.isVSCode)){if(f==="agents"){Ki.getState().loadAgents();return}if(f==="commands"){Uu.getState().loadCommands();return}if(f==="mcp"){Lo.getState().loadMcpConfigs();return}(f==="skills.installed"||f==="skills.catalog")&&(wa.getState().loadSkills(),Qa.getState().loadCatalog())}},e[22]=p,e[23]=f,e[24]=ne):ne=e[24];let E;e[25]!==O||e[26]!==p||e[27]!==f?(E=[O,p,N.isVSCode,f],e[25]=O,e[26]=p,e[27]=f,e[28]=E):E=e[28],l.useEffect(ne,E);let z;e[29]!==c||e[30]!==m?(z=Ae=>{if(m(Ae),b.current=Ae,!c)return;const xe=bo(Ae);if(!xe||xe.slug==="home"){h("nav");return}h(xe.kind==="split"?"page-sidebar":"page-content")},e[29]=c,e[30]=m,e[31]=z):z=e[31];const J=z;let H;e[32]!==f?(H=bo(f),e[32]=f,e[33]=H):H=e[33];const te=H;let ce;e[34]===Symbol.for("react.memo_cache_sentinel")?(ce={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[34]=ce):ce=e[34];const Se=ce;let pe;e[35]!==i?(pe=Ae=>{switch(Ae){case"projects":return i("settings.page.projects.title");case"remote-instances":return i("settings.page.remoteInstances.title");case"providers":return i("settings.page.providers.title");case"usage":return i("settings.page.usage.title");case"agents":return i("settings.page.agents.title");case"behavior":return i("settings.page.behavior.title");case"commands":return i("settings.page.commands.title");case"mcp":return i("settings.page.mcp.title");case"skills.installed":return i("settings.page.skills.title");case"skills.catalog":return i("settings.page.skillsCatalog.title");case"git":return i("settings.page.git.title");case"appearance":return i("settings.page.appearance.title");case"chat":return i("settings.page.chat.title");case"shortcuts":return i("settings.page.shortcuts.title");case"sessions":return i("settings.page.sessions.title");case"magic-prompts":return i("settings.page.magicPrompts.title");case"notifications":return i("settings.page.notifications.title");case"voice":return i("settings.page.voice.title");case"tunnel":return i("settings.page.tunnel.title");default:return i("settings.view.home.title")}},e[35]=i,e[36]=pe):pe=e[36];const we=pe;let W;e[37]!==i?(W=()=>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[37]=i,e[38]=W):W=e[38];const ue=W,Y=kA;let le;e[39]!==J||e[40]!==ue?(le=Ae=>{const xe=bo(Ae);if(xe&&!qh(xe,N))return ue();switch(Ae){case"home":return s.jsx(wd,{onOpen:J});case"projects":return s.jsx(GC,{});case"remote-instances":return s.jsx(y4,{});case"agents":return s.jsx(y5,{});case"behavior":return s.jsx(S5,{});case"commands":return s.jsx(R5,{});case"mcp":return s.jsx(oC,{});case"skills.installed":return s.jsx(fh,{view:"installed"});case"skills.catalog":return s.jsx(fh,{view:"catalog"});case"providers":return s.jsx(I4,{});case"usage":return s.jsx(K4,{});case"magic-prompts":return s.jsx(J4,{});case"git":return s.jsx(tI,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const V=Se[Ae]??"visual";return s.jsx(iA,{section:V})}default:return s.jsx(wd,{onOpen:J})}},e[39]=J,e[40]=ue,e[41]=le):le=e[41];const Z=le;let Ie,Ne;e[42]!==c||e[43]!==y||e[44]!==f?(Ie=()=>{if(!c||y!=="nav"||f==="home"||b.current===f)return;const Ae=bo(f);!Ae||Ae.slug==="home"||(b.current=f,h(Ae.kind==="split"?"page-sidebar":"page-content"))},Ne=[c,y,f],e[42]=c,e[43]=y,e[44]=f,e[45]=Ie,e[46]=Ne):(Ie=e[45],Ne=e[46]),l.useEffect(Ie,Ne);const X=c&&y!=="nav";let he,je,be,fe,Pe,Be,G;if(e[47]!==te||e[48]!==we||e[49]!==c||e[50]!==a||e[51]!==y||e[52]!==n||e[53]!==J||e[54]!==Z||e[55]!==f||e[56]!==X||e[57]!==_||e[58]!==i){const Ae=Jl();let xe;e[66]===Symbol.for("react.memo_cache_sentinel")?(xe=()=>{h("nav")},e[66]=xe):xe=e[66];const V=xe;let de;e[67]===Symbol.for("react.memo_cache_sentinel")?(de=()=>{h("page-sidebar")},e[67]=de):de=e[67];const Me=de;let Le;e[68]!==we||e[69]!==J||e[70]!==f||e[71]!==_||e[72]!==i?(Le=()=>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(U=>{const Ve=f===U.slug,He=nm(U.slug);return He?s.jsx(St,{children:s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>J(U.slug),"aria-current":Ve?"page":void 0,className:me("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",Ve?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[s.jsx(He,{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:we(U.slug)}),(U.slug==="voice"||U.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")})]})]})})},U.slug):null})})}),s.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:s.jsx("div",{className:"border-t border-border bg-sidebar px-2 py-1 space-y-0.5",children:!N.isVSCode&&s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",className:me("flex h-7 w-full items-center gap-2 rounded-md px-2 overflow-hidden whitespace-nowrap","text-sm font-semibold text-sidebar-foreground/90","hover:text-sidebar-foreground hover:bg-interactive-hover"),onClick:CA,children:[s.jsx(Fn,{className:"h-4 w-4 shrink-0"}),s.jsx("span",{children:i("settings.view.actions.reloadOpenCode")})]})}),s.jsx(It,{children:i("settings.view.actions.reloadOpenCodeTooltip")})]})})})]}),e[68]=we,e[69]=J,e[70]=f,e[71]=_,e[72]=i,e[73]=Le):Le=e[73],be=Le;let se;e[74]!==te||e[75]!==y||e[76]!==Z||e[77]!==be||e[78]!==f?(se=()=>{if(y==="nav")return s.jsx("div",{className:me("flex-1 min-h-0 overflow-hidden",N.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(on,{children:be()})})});if(!te)return s.jsx("div",{className:"flex-1 bg-background"});if(y==="page-sidebar"){if(te.kind!=="split"){const Ve=Z(f);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(on,{children:Ve})})}return s.jsx("div",{className:me("flex-1 min-h-0 overflow-hidden",N.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx(on,{children:Y(f,{onItemSelect:()=>h("page-content")})})})}const U=Z(f);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(on,{children:U})})},e[74]=te,e[75]=y,e[76]=Z,e[77]=be,e[78]=f,e[79]=se):se=e[79],je=se;let ie;e[80]!==te||e[81]!==J||e[82]!==Z||e[83]!==f?(ie=()=>!te||f==="home"?s.jsx(wd,{onOpen:J}):te.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:me("w-[264px] min-w-[264px] border-r",N.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:s.jsx(on,{children:Y(f,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(on,{children:Z(f)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:s.jsx(on,{children:Z(f)})}),e[80]=te,e[81]=J,e[82]=Z,e[83]=f,e[84]=ie):ie=e[84],he=ie,fe=I,Pe="true",e[85]===Symbol.for("react.memo_cache_sentinel")?(Be=me("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[85]=Be):Be=e[85],G=c?s.jsxs("div",{className:me("flex items-center gap-2 px-3 py-2 border-b","bg-background"),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("button",{type:"button",onClick:X?V:n,"aria-label":i(X?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(Wi,{className:"h-5 w-5"})}),s.jsx("div",{className:"min-w-0 flex-1 typography-ui-label font-medium text-foreground truncate",children:y==="nav"?i("settings.view.home.title"):te?we(te.slug):i("settings.view.home.title")}),y==="page-content"&&te?.kind==="split"&&s.jsx("button",{type:"button",onClick:Me,"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(Wy,{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:Ae}),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(Is,{className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[X&&s.jsx("div",{className:me("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:V,"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(Wi,{className:"h-5 w-5"})})}),n&&s.jsx("div",{className:me("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:n,"aria-label":i("settings.view.actions.closeSettings"),title:i("settings.view.actions.closeSettingsWithShortcut",{shortcut:Ae}),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(Is,{className:"h-5 w-5"})})})]}),e[47]=te,e[48]=we,e[49]=c,e[50]=a,e[51]=y,e[52]=n,e[53]=J,e[54]=Z,e[55]=f,e[56]=X,e[57]=_,e[58]=i,e[59]=he,e[60]=je,e[61]=be,e[62]=fe,e[63]=Pe,e[64]=Be,e[65]=G}else he=e[59],je=e[60],be=e[61],fe=e[62],Pe=e[63],Be=e[64],G=e[65];let ke;e[86]!==ee||e[87]!==ge||e[88]!==c||e[89]!==S||e[90]!==x||e[91]!==he||e[92]!==je||e[93]!==be||e[94]!==i?(ke=s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?je():s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:me("relative flex h-full min-h-0 flex-col overflow-hidden border-r",k?"bg-sidebar":N.isVSCode?"bg-background":"bg-sidebar",S?"":"transition-[width,min-width] duration-200 ease-[cubic-bezier(0.25,0.1,0.25,1)]"),style:{width:`${x}px`,minWidth:`${x}px`,borderColor:"var(--interactive-border)"},children:[s.jsx("div",{className:me("absolute right-0 top-0 z-20 h-full w-[6px] -mr-[3px] cursor-col-resize","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",S?"bg-primary/30":"bg-transparent hover:bg-primary/20"),tabIndex:0,onPointerDown:ee,onKeyDown:ge,role:"separator","aria-orientation":"vertical","aria-valuemin":du,"aria-valuemax":uu,"aria-valuenow":x,"aria-label":i("settings.view.actions.resizeNavigation")}),s.jsx(on,{children:be()})]}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:he()})]})}),e[86]=ee,e[87]=ge,e[88]=c,e[89]=S,e[90]=x,e[91]=he,e[92]=je,e[93]=be,e[94]=i,e[95]=ke):ke=e[95];let Ee;return e[96]!==fe||e[97]!==Pe||e[98]!==Be||e[99]!==G||e[100]!==ke?(Ee=s.jsxs("div",{ref:fe,"data-settings-view":Pe,className:Be,children:[G,ke]}),e[96]=fe,e[97]=Pe,e[98]=Be,e[99]=G,e[100]=ke,e[101]=Ee):Ee=e[101],Ee};function yA(t){return t.settingsPage}function vA(t){return t.isSettingsDialogOpen}function wA(t){return t.setSettingsPage}function jA(t){return t.slug!=="home"}function NA(t,e){return[t,e]}function SA(t){return t.activeProjectId}function kA(t,e){switch(t){case"projects":return s.jsx($C,{onItemSelect:e.onItemSelect});case"remote-instances":return s.jsx(i4,{onItemSelect:e.onItemSelect});case"agents":return s.jsx(m5,{onItemSelect:e.onItemSelect});case"commands":return s.jsx(k5,{onItemSelect:e.onItemSelect});case"mcp":return s.jsx(E5,{onItemSelect:e.onItemSelect});case"skills.installed":return s.jsx(lC,{onItemSelect:e.onItemSelect});case"providers":return s.jsx(j4,{onItemSelect:e.onItemSelect});case"usage":return s.jsx(P4,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(G4,{onItemSelect:e.onItemSelect});default:return null}}function CA(){ko({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]})}const IA=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:bA,getSettingsNavIcon:nm},Symbol.toStringTag,{value:"Module"})),mu=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},AA=()=>{const t=nt.c(162),{t:e}=ut(),n=De(PA),r=De(DA),a=De(TA),i=De(MA),o=De(RA),c=De(EA),d=De(FA),p=De(OA),m=De(LA),u=De($A),f=De(BA),y=De(_A),h=Ht(VA),b=Ht(zA),x=So(UA),g=qs(WA),w=Es(KA),v=ta(),S=Vu(HA),{files:P,git:j}=Yn(),C=pn(GA),{isMobile:I}=dn();let R;t[0]!==v?(R=v?mu(v):null,t[0]=v,t[1]=R):R=t[1];const k=R,[A,N]=l.useState(""),D=vc(A,200);let T;t[2]!==D?(T=D.trim(),t[2]=D,t[3]=T):T=t[3];const M=T;let $;t[4]!==A?($=A.trim(),t[4]=A,t[5]=$):$=t[5];const F=$;let _,O;t[6]!==n?(_=()=>{n&&N("")},O=[n],t[6]=n,t[7]=_,t[8]=O):(_=t[7],O=t[8]),l.useEffect(_,O);let L,K;t[9]!==x||t[10]!==C||t[11]!==j||t[12]!==n?(L=()=>{if(!n||!j)return;const Qe=setTimeout(()=>{const ze=new Set;for(const gt of x){const Vt=Il(gt);!Vt||ze.has(Vt)||(ze.add(Vt),C(Vt,j))}},0);return()=>clearTimeout(Qe)},K=[n,x,j,C],t[9]=x,t[10]=C,t[11]=j,t[12]=n,t[13]=L,t[14]=K):(L=t[13],K=t[14]),l.useEffect(L,K);let B;t[15]!==r?(B=()=>r(!1),t[15]=r,t[16]=B):B=t[16];const re=B;let oe;t[17]!==re?(oe=Qe=>()=>{re(),Qe()},t[17]=re,t[18]=oe):oe=t[18];const ee=oe;let ae;t[19]!==w?.id||t[20]!==w?.path||t[21]!==g||t[22]!==I||t[23]!==u||t[24]!==h||t[25]!==ee||t[26]!==a||t[27]!==c||t[28]!==i||t[29]!==e||t[30]!==m||t[31]!==p||t[32]!==d?(ae=()=>{const Qe=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(zs,{className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:ee(()=>{a("chat"),c(!1),h()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(Qs,{className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:ee(qA)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(Aa,{className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:ee(QA)},{id:"toggle-sidebar",title:e(I?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(si,{className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(I?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:ee(()=>{if(I){const{isSessionSwitcherOpen:ze}=De.getState();c(!ze)}else d()})},{id:"toggle-right-sidebar",title:e("commandPalette.item.toggleRightSidebar"),icon:s.jsx(Ei,{className:"mr-2 h-4 w-4"}),shortcutId:"toggle_right_sidebar",searchText:e("commandPalette.item.toggleRightSidebar"),onSelect:ee(()=>p())},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(Za,{className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:ee(()=>m())},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(Ky,{className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:ee(()=>{g&&u(g)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(Ui,{className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:ee(()=>i(!0))}];return Ou()&&Qe.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(jo,{className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:ee(()=>{Gl("desktop_open_draft_mini_chat_window",{directory:mu(g||w?.path||""),projectId:w?.id??null}).catch(JA)})}),Qe},t[19]=w?.id,t[20]=w?.path,t[21]=g,t[22]=I,t[23]=u,t[24]=h,t[25]=ee,t[26]=a,t[27]=c,t[28]=i,t[29]=e,t[30]=m,t[31]=p,t[32]=d,t[33]=ae):ae=t[33],w?.id,w?.path;let ge;t[34]!==ae?(ge=ae(),t[34]=ae,t[35]=ge):ge=t[35];const ne=ge;let E;t[36]===Symbol.for("react.memo_cache_sentinel")?(E=Pn(),t[36]=E):E=t[36];const z=E;let J;t[37]===Symbol.for("react.memo_cache_sentinel")?(J={isVSCode:jn(),isWeb:!z&&Sa(),isDesktop:z},t[37]=J):J=t[37];const H=J;let te;if(t[38]!==ee||t[39]!==i||t[40]!==o){let Qe;t[42]===Symbol.for("react.memo_cache_sentinel")?(Qe=ze=>ze.isAvailable?ze.isAvailable(H):!0,t[42]=Qe):Qe=t[42],te=Zu.filter(YA).filter(Qe).map(ze=>{const gt=nm(ze.slug)??Ui,Vt=(ze.keywords??[]).join(" ");return{id:`settings:${ze.slug}`,title:ze.title,icon:s.jsx(gt,{className:"mr-2 h-4 w-4"}),searchText:`${ze.title} ${ze.group} ${Vt}`,onSelect:ee(()=>{o(ze.slug),i(!0)})}}),t[38]=ee,t[39]=i,t[40]=o,t[41]=te}else te=t[41];const ce=te,Se=XA;let pe;if(t[43]!==x){let Qe;t[45]===Symbol.for("react.memo_cache_sentinel")?(Qe=(ze,gt)=>Se(gt)-Se(ze),t[45]=Qe):Qe=t[45],pe=[...x].sort(Qe),t[43]=x,t[44]=pe}else pe=t[44];const we=pe,W=Ig(),ue=Ht(ZA);let Y;t[46]!==W||t[47]!==ue?(Y=(Qe,ze)=>{const gt=ue.get(Qe);return gt?.branch?gt.branch.trim()||null:ze&&W.get(ze)?.trim()||null},t[46]=W,t[47]=ue,t[48]=Y):Y=t[48];const le=Y;let Z;t[49]===Symbol.for("react.memo_cache_sentinel")?(Z=[],t[49]=Z):Z=t[49];const[Ie,Ne]=l.useState(Z),[X,he]=l.useState(!1);let je,be;t[50]!==k||t[51]!==n||t[52]!==S||t[53]!==M?(je=()=>{if(!n){Ne([]),he(!1);return}if(!k||M.length===0){Ne([]),he(!1);return}let Qe=!1;return he(!0),S(k,M,10,{type:"file"}).then(ze=>{Qe||Ne(ze.map(e6))}).catch(()=>{Qe||Ne([])}).finally(()=>{Qe||he(!1)}),()=>{Qe=!0}},be=[n,k,M,S],t[50]=k,t[51]=n,t[52]=S,t[53]=M,t[54]=je,t[55]=be):(je=t[54],be=t[55]),l.useEffect(je,be);const fe=F.length>0;let Pe;e:{if(!fe){let ze;t[56]!==ne?(ze=ne.map(t6),t[56]=ne,t[57]=ze):ze=t[57],Pe=ze;break e}let Qe;t[58]!==ne||t[59]!==F?(Qe=nl(ne,F,s6,{limit:7,noFuzzy:!0}),t[58]=ne,t[59]=F,t[60]=Qe):Qe=t[60],Pe=Qe}const Be=Pe;let G;e:{if(!fe){let ze;t[61]===Symbol.for("react.memo_cache_sentinel")?(ze=[],t[61]=ze):ze=t[61],G=ze;break e}let Qe;t[62]!==F||t[63]!==ce?(Qe=nl(ce,F,n6,{limit:7,noFuzzy:!0}),t[62]=F,t[63]=ce,t[64]=Qe):Qe=t[64],G=Qe}const ke=G;let Ee;e:{if(!fe){let ze;t[65]!==we?(ze=we.slice(0,5).map(r6),t[65]=we,t[66]=ze):ze=t[66],Ee=ze;break e}let Qe;t[67]!==F||t[68]!==we?(Qe=nl(we,F,a6,{limit:7,threshold:.2}),t[67]=F,t[68]=we,t[69]=Qe):Qe=t[69],Ee=Qe}const Ae=Ee;let xe;e:{if(!fe||Ie.length===0){let ze;t[70]===Symbol.for("react.memo_cache_sentinel")?(ze=[],t[70]=ze):ze=t[70],xe=ze;break e}let Qe;t[71]!==Ie||t[72]!==F?(Qe=nl(Ie,F,i6,{limit:10,threshold:.4}),t[71]=Ie,t[72]=F,t[73]=Qe):Qe=t[73],xe=Qe}const V=xe;let de,Me,Le,se,ie,U,Ve,He,Ke,Ze,Xe,dt,et,ct,at;if(t[74]!==le||t[75]!==re||t[76]!==k||t[77]!==P||t[78]!==fe||t[79]!==n||t[80]!==f||t[81]!==A||t[82]!==Be||t[83]!==V||t[84]!==Ae||t[85]!==ke||t[86]!==r||t[87]!==b||t[88]!==y||t[89]!==e){const Qe=Be.map(o6),ze=ke.map(l6),gt=Ae.map(c6);at=fe?V.map(d6):[];let Vt;e:{if(!fe){Vt=["commands","sessions"];break e}const Ct=u6,Ue=[{key:"commands",score:Ct(Be)},{key:"settings",score:Ct(ke)},{key:"sessions",score:Ct(Ae)},{key:"files",score:Ct(V)}];Ue.sort(m6),Vt=Ue.map(p6)}const Kt=Vt;let Jt;t[105]!==re||t[106]!==b?(Jt=Ct=>{re(),b(Ct.id,Il(Ct))},t[105]=re,t[106]=b,t[107]=Jt):Jt=t[107];const At=Jt;let jt;t[108]!==re||t[109]!==k||t[110]!==P||t[111]!==f?(jt=async Ct=>{if(!k)return;const Ue=await Ju(P,Ct);if(!Ue.ok){q.error(Yu(Ue.reason));return}f(k,Ct),re()},t[108]=re,t[109]=k,t[110]=P,t[111]=f,t[112]=jt):jt=t[112];const ns=jt;let ot;t[113]!==y?(ot=Ct=>gc(ia(Ct,y)),t[113]=y,t[114]=ot):ot=t[114];const Zt=ot;se=ws,dt=n,et=r;let Yt;t[115]!==e?(Yt=e("commandPalette.title"),t[115]=e,t[116]=Yt):Yt=t[116];let es;t[117]!==Yt?(es=s.jsx(js,{children:Yt}),t[117]=Yt,t[118]=es):es=t[118];let ls;t[119]!==e?(ls=e("commandPalette.description"),t[119]=e,t[120]=ls):ls=t[120];let ds;t[121]!==ls?(ds=s.jsx(Fs,{children:ls}),t[121]=ls,t[122]=ds):ds=t[122],t[123]!==es||t[124]!==ds?(ct=s.jsxs(Cs,{className:"sr-only",children:[es,ds]}),t[123]=es,t[124]=ds,t[125]=ct):ct=t[125],Le=vs,Ze="overflow-hidden p-0",Xe=!0,Me=oi,Ve=!1,He="[&_[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 gs;t[126]!==e?(gs=e("commandPalette.input.placeholder"),t[126]=e,t[127]=gs):gs=t[127],t[128]!==A||t[129]!==gs?(Ke=s.jsx(Ia,{value:A,onValueChange:N,placeholder:gs}),t[128]=A,t[129]=gs,t[130]=Ke):Ke=t[130],de=li;let us;t[131]!==e?(us=e("commandPalette.empty.noResults"),t[131]=e,t[132]=us):us=t[132],t[133]!==us?(ie=s.jsx(ci,{children:us}),t[133]=us,t[134]=ie):ie=t[134],U=Kt.map(Ct=>Ct==="commands"&&Qe.length>0?s.jsx(Qn,{children:Qe.map(Ue=>s.jsxs(On,{value:Ue.id,onSelect:Ue.onSelect,children:[Ue.icon,s.jsx("span",{children:Ue.title}),Ue.shortcutId?s.jsx(oN,{children:Zt(Ue.shortcutId)}):null]},Ue.id))},"commands"):Ct==="settings"&&ze.length>0?s.jsx(Qn,{children:ze.map(h6)},"settings"):Ct==="sessions"&>.length>0?s.jsx(Qn,{children:gt.map(Ue=>{const Dt=Ue.title||e("commandPalette.session.untitled"),Tt=Il(Ue),wt=le(Ue.id,Tt);return s.jsxs(On,{value:`session:${Ue.id}`,onSelect:()=>At(Ue),children:[s.jsx(rg,{className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:Dt}),wt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(Qs,{className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:wt})]}):null]},Ue.id)})},"sessions"):Ct==="files"&&at.length>0?s.jsx(Qn,{children:at.map(Ue=>{const Dt=W1(Ue.relativePath||Ue.name,{maxLength:80});return s.jsxs(On,{value:`file:${Ue.path}`,onSelect:()=>{ns(Ue.path)},children:[s.jsx(Dr,{filePath:Ue.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":Ue.relativePath,children:Dt})]},`file:${Ue.path}`)})},"files"):null),t[74]=le,t[75]=re,t[76]=k,t[77]=P,t[78]=fe,t[79]=n,t[80]=f,t[81]=A,t[82]=Be,t[83]=V,t[84]=Ae,t[85]=ke,t[86]=r,t[87]=b,t[88]=y,t[89]=e,t[90]=de,t[91]=Me,t[92]=Le,t[93]=se,t[94]=ie,t[95]=U,t[96]=Ve,t[97]=He,t[98]=Ke,t[99]=Ze,t[100]=Xe,t[101]=dt,t[102]=et,t[103]=ct,t[104]=at}else de=t[90],Me=t[91],Le=t[92],se=t[93],ie=t[94],U=t[95],Ve=t[96],He=t[97],Ke=t[98],Ze=t[99],Xe=t[100],dt=t[101],et=t[102],ct=t[103],at=t[104];let ye;t[135]!==fe||t[136]!==X||t[137]!==e||t[138]!==at?(ye=fe&&X&&at.length===0?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[135]=fe,t[136]=X,t[137]=e,t[138]=at,t[139]=ye):ye=t[139];let Ge;t[140]!==de||t[141]!==ie||t[142]!==U||t[143]!==ye?(Ge=s.jsxs(de,{children:[ie,U,ye]}),t[140]=de,t[141]=ie,t[142]=U,t[143]=ye,t[144]=Ge):Ge=t[144];let $e;t[145]!==Me||t[146]!==Ve||t[147]!==He||t[148]!==Ke||t[149]!==Ge?($e=s.jsxs(Me,{shouldFilter:Ve,className:He,children:[Ke,Ge]}),t[145]=Me,t[146]=Ve,t[147]=He,t[148]=Ke,t[149]=Ge,t[150]=$e):$e=t[150];let _e;t[151]!==Le||t[152]!==Ze||t[153]!==Xe||t[154]!==$e?(_e=s.jsx(Le,{className:Ze,showCloseButton:Xe,children:$e}),t[151]=Le,t[152]=Ze,t[153]=Xe,t[154]=$e,t[155]=_e):_e=t[155];let tt;return t[156]!==se||t[157]!==dt||t[158]!==et||t[159]!==ct||t[160]!==_e?(tt=s.jsxs(se,{open:dt,onOpenChange:et,children:[ct,_e]}),t[156]=se,t[157]=dt,t[158]=et,t[159]=ct,t[160]=_e,t[161]=tt):tt=t[161],tt};function PA(t){return t.isCommandPaletteOpen}function DA(t){return t.setCommandPaletteOpen}function TA(t){return t.setActiveMainTab}function MA(t){return t.setSettingsDialogOpen}function RA(t){return t.setSettingsPage}function EA(t){return t.setSessionSwitcherOpen}function FA(t){return t.toggleSidebar}function OA(t){return t.toggleRightSidebar}function LA(t){return t.toggleBottomTerminal}function $A(t){return t.openContextOverview}function BA(t){return t.openContextFile}function _A(t){return t.shortcutOverrides}function VA(t){return t.openNewSessionDraft}function zA(t){return t.setCurrentSession}function UA(t){return t.activeSessions}function WA(t){return t.currentDirectory}function KA(t){return t.getActiveProject()}function HA(t){return t.searchFiles}function GA(t){return t.ensureStatus}function qA(){Ag()}function QA(){Tr.requestDirectoryDialog()}function JA(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function YA(t){return t.slug!=="home"}function XA(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function ZA(t){return t.worktreeMetadata}function e6(t){return{path:mu(t.path),name:t.name,relativePath:t.relativePath}}function t6(t){return{item:t,score:0}}function s6(t){return t.searchText}function n6(t){return t.searchText}function r6(t){return{item:t,score:0}}function a6(t){return t.title||""}function i6(t){return t.name}function o6(t){return t.item}function l6(t){return t.item}function c6(t){return t.item}function d6(t){return t.item}function u6(t){return t.length?t[0].score:1/0}function m6(t,e){return t.score-e.score}function p6(t){return t.key}function h6(t){return s.jsxs(On,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const Qh=(t,e,n)=>H1(t)?gc(ia(t,n)):e,f6=()=>{const t=nt.c(68),{t:e}=ut(),n=De(g6),r=De(x6),a=De(b6);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=K1(),t[0]=i):i=t[0];const o=i;let c,d,p,m,u,f,y,h,b;if(t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==e){const M=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:Vo,keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:Ld,keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:si,keys:""},{keys:["Tab"],descriptionKey:"helpDialog.item.cycleAgent",icon:Eu},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:Ga,keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:Ga},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:Do},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:Do,keys:""},{keys:[`Shift + Alt + ${o} + N`],descriptionKey:"helpDialog.item.newWindow",icon:jo}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:zs,keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:Qs,keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:Hy,keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:Gy,keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_right_sidebar",descriptionKey:"helpDialog.item.toggleRightSidebar",icon:Ei,keys:""},{id:"open_right_sidebar_git",descriptionKey:"helpDialog.item.openRightSidebarGitTab",icon:Qs,keys:""},{id:"open_right_sidebar_files",descriptionKey:"helpDialog.item.openRightSidebarFilesTab",icon:Ei,keys:""},{id:"cycle_right_sidebar_tab",descriptionKey:"helpDialog.item.cycleRightSidebarTab",icon:Ei,keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:jo,keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:jo,keys:""},{id:"toggle_context_plan",descriptionKey:"helpDialog.item.togglePlanContextPanel",icon:Nu,keys:""}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:ag,keys:""},{keys:[`${o} + 1...9`],descriptionKey:"helpDialog.item.switchProject",icon:si},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:Ca,keys:""},{id:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:Ca,keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:Ui,keys:""}]}];d=ws,h=n,b=r,c=vs,f="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(Ui,{className:"h-5 w-5"}),t[14]=$):$=t[14];let F;t[15]!==e?(F=e("helpDialog.title"),t[15]=e,t[16]=F):F=t[16];let _;t[17]!==F?(_=s.jsxs(js,{className:"flex items-center gap-2",children:[$,F]}),t[17]=F,t[18]=_):_=t[18];let O;t[19]!==e?(O=e("helpDialog.description"),t[19]=e,t[20]=O):O=t[20];let L;t[21]!==O?(L=s.jsx(Fs,{children:O}),t[21]=O,t[22]=L):L=t[22],t[23]!==_||t[24]!==L?(y=s.jsxs(Cs,{children:[_,L]}),t[23]=_,t[24]=L,t[25]=y):y=t[25],u="flex-1 overflow-y-auto mt-3 pr-1",p="space-y-4",m=M.map(K=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(K.categoryKey)}),s.jsx("div",{className:"space-y-1",children:K.items.map(B=>{const re=B.id?Qh(B.id,Array.isArray(B.keys)?B.keys[0]:B.keys,a):Array.isArray(B.keys)?B.keys:B.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:[B.icon&&s.jsx(B.icon,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(B.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(re)?re:[re]).map((oe,ee)=>s.jsxs(l.Fragment,{children:[ee>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:oe})]},`${oe}-${ee}`))})]},B.id||B.descriptionKey)})})]},K.categoryKey)),t[1]=n,t[2]=r,t[3]=a,t[4]=e,t[5]=c,t[6]=d,t[7]=p,t[8]=m,t[9]=u,t[10]=f,t[11]=y,t[12]=h,t[13]=b}else c=t[5],d=t[6],p=t[7],m=t[8],u=t[9],f=t[10],y=t[11],h=t[12],b=t[13];let x;t[26]!==p||t[27]!==m?(x=s.jsx("div",{className:p,children:m}),t[26]=p,t[27]=m,t[28]=x):x=t[28];let g;t[29]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(Ld,{className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[29]=g):g=t[29];let w;t[30]!==e?(w=e("helpDialog.proTips.title"),t[30]=e,t[31]=w):w=t[31];let v;t[32]!==w?(v=s.jsx("p",{className:"font-medium mb-1",children:w}),t[32]=w,t[33]=v):v=t[33];let S;t[34]!==a||t[35]!==e?(S=e("helpDialog.proTips.commandPalette",{shortcut:Qh("open_command_palette",`${o} P`,a)}),t[34]=a,t[35]=e,t[36]=S):S=t[36];let P;t[37]!==S?(P=s.jsxs("li",{children:["• ",S]}),t[37]=S,t[38]=P):P=t[38];let j;t[39]!==e?(j=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=j):j=t[40];let C;t[41]!==j?(C=s.jsxs("li",{children:["• ",j]}),t[41]=j,t[42]=C):C=t[42];let I;t[43]!==e?(I=e("helpDialog.proTips.themeCycling"),t[43]=e,t[44]=I):I=t[44];let R;t[45]!==I?(R=s.jsxs("li",{children:["• ",I]}),t[45]=I,t[46]=R):R=t[46];let k;t[47]!==P||t[48]!==C||t[49]!==R?(k=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[P,C,R]}),t[47]=P,t[48]=C,t[49]=R,t[50]=k):k=t[50];let A;t[51]!==v||t[52]!==k?(A=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[g,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[v,k]})]})}),t[51]=v,t[52]=k,t[53]=A):A=t[53];let N;t[54]!==A||t[55]!==u||t[56]!==x?(N=s.jsxs("div",{className:u,children:[x,A]}),t[54]=A,t[55]=u,t[56]=x,t[57]=N):N=t[57];let D;t[58]!==c||t[59]!==N||t[60]!==f||t[61]!==y?(D=s.jsxs(c,{className:f,children:[y,N]}),t[58]=c,t[59]=N,t[60]=f,t[61]=y,t[62]=D):D=t[62];let T;return t[63]!==d||t[64]!==D||t[65]!==h||t[66]!==b?(T=s.jsx(d,{open:h,onOpenChange:b,children:D}),t[63]=d,t[64]=D,t[65]=h,t[66]=b,t[67]=T):T=t[67],T};function g6(t){return t.isHelpDialogOpen}function x6(t){return t.setHelpDialogOpen}function b6(t){return t.shortcutOverrides}const y6=()=>{const t=nt.c(32),{t:e}=ut(),n=De(v6),r=De(w6),a=De(j6);let i;t[0]!==a||t[1]!==e?(i=async()=>{if(!a)return;if((await Wn(a)).ok){q.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}q.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=a,t[1]=e,t[2]=i):i=t[2];const o=i;let c;t[3]!==e?(c=e("openCodeStatusDialog.title"),t[3]=e,t[4]=c):c=t[4];let d;t[5]!==c?(d=s.jsx(js,{children:c}),t[5]=c,t[6]=d):d=t[6];let p;t[7]!==e?(p=e("openCodeStatusDialog.description"),t[7]=e,t[8]=p):p=t[8];let m;t[9]!==p?(m=s.jsx(Fs,{children:p}),t[9]=p,t[10]=m):m=t[10];let u;t[11]!==d||t[12]!==m?(u=s.jsxs(Cs,{children:[d,m]}),t[11]=d,t[12]=m,t[13]=u):u=t[13];let f;t[14]!==e?(f=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=f):f=t[15];let y;t[16]!==o||t[17]!==f?(y=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:o,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:f})}),t[16]=o,t[17]=f,t[18]=y):y=t[18];let h;t[19]!==a||t[20]!==e?(h=a||e("openCodeStatusDialog.empty.noData"),t[19]=a,t[20]=e,t[21]=h):h=t[21];let b;t[22]!==h?(b=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:h}),t[22]=h,t[23]=b):b=t[23];let x;t[24]!==u||t[25]!==y||t[26]!==b?(x=s.jsxs(vs,{className:"max-w-2xl",children:[u,y,b]}),t[24]=u,t[25]=y,t[26]=b,t[27]=x):x=t[27];let g;return t[28]!==n||t[29]!==r||t[30]!==x?(g=s.jsx(ws,{open:n,onOpenChange:r,children:x}),t[28]=n,t[29]=r,t[30]=x,t[31]=g):g=t[31],g};function v6(t){return t.isOpenCodeStatusDialogOpen}function w6(t){return t.setOpenCodeStatusDialogOpen}function j6(t){return t.openCodeStatusText}const N6=180,Jh=600,S6=1,k6=6,C6=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],ensureSessionRenderable:r})=>{const a=l.useRef(new Map),i=l.useRef([]),o=l.useRef(new Set),c=l.useCallback(()=>{if(!(typeof window>"u"))for(;o.current.size<S6&&i.current.length>0;){const p=i.current.shift();if(!p)break;Ht.getState().currentSessionId!==p&&(Lm(p).renderable||(o.current.add(p),r(p).catch(()=>{}).finally(()=>{o.current.delete(p),c()})))}},[r]),d=l.useCallback(p=>{if(!p||p===t||typeof window>"u"||Lm(p).renderable||o.current.has(p)||i.current.includes(p))return;i.current.length>=k6&&i.current.shift();const m=a.current.get(p);m!==void 0&&window.clearTimeout(m);const u=window.setTimeout(()=>{a.current.delete(p),i.current.push(p),c()},N6);a.current.set(p,u)},[t,c]);l.useEffect(()=>{if(!t||e.length===0)return;const p=window.setTimeout(()=>{const m=e.findIndex(u=>u.id===t);m<0||(d(e[m-1]?.id),d(e[m+1]?.id))},Jh);return()=>window.clearTimeout(p)},[t,d,e]),l.useEffect(()=>{if(!t||n.length===0)return;const p=window.setTimeout(()=>{const m=n.indexOf(t);m<0||(d(n[m-1]),d(n[m+1]))},Jh);return()=>window.clearTimeout(p)},[t,n,d]),l.useEffect(()=>{const p=a.current;return()=>{p.forEach(m=>{clearTimeout(m)}),p.clear(),i.current=[]}},[])};function Yh(t){const{localBranches:e,remoteBranches:n,query:r}=t,a=r.trim();if(!a)return{matching:[],otherLocal:e,otherRemote:n};const i=$m(e,a,m=>m),o=$m(n,a,m=>m),c=[],d=i.other,p=o.other;for(const m of i.matching)c.push({label:m,value:m,source:"local"});for(const m of o.matching)c.push({label:m,value:`remotes/${m}`,source:"remote"});return c.sort((m,u)=>{const f=m.label.localeCompare(u.label,void 0,{sensitivity:"accent"});return f!==0?f:m.source!==u.source?m.source.localeCompare(u.source):m.value.localeCompare(u.value)}),{matching:c,otherLocal:d,otherRemote:p}}function I6({open:t,onOpenChange:e,onSelect:n}){const{t:r}=ut(),a=De(W=>W.isMobile),{github:i}=Yn(),o=sr(W=>W.status),c=sr(W=>W.hasChecked),d=De(W=>W.setSettingsDialogOpen),p=De(W=>W.setSettingsPage),m=Es(W=>W.getActiveProject()),u=m?.path??null,f=Oe.useMemo(()=>u&&m?{id:m.id,path:u}:null,[m,u]),[y,h]=Oe.useState("issues"),[b,x]=Oe.useState(""),[g,w]=Oe.useState([]),[v,S]=Oe.useState([]),[P,j]=Oe.useState(!1),[C,I]=Oe.useState(!1),[R,k]=Oe.useState(null),[A,N]=Oe.useState(null),[D,T]=Oe.useState(null),[M,$]=Oe.useState(!1),[F,_]=Oe.useState(new Map),[O,L]=Oe.useState(1),[K,B]=Oe.useState(!1),re=Oe.useCallback(async()=>{if(!(!u||!i)&&!(c&&o?.connected===!1)){j(!0),k(null),L(1),B(!1);try{if(y==="issues"&&i.issuesList){const W=await i.issuesList(u,{page:1});W.connected===!1?(k(r("session.githubIntegration.error.notConnected")),w([])):(w(W.issues??[]),L(W.page??1),B(!!W.hasMore))}else if(y==="prs"&&i.prsList){const W=await i.prsList(u,{page:1});W.connected===!1?(k(r("session.githubIntegration.error.notConnected")),S([])):(S(W.prs??[]),L(W.page??1),B(!!W.hasMore))}}catch(W){k(W instanceof Error?W.message:r("session.githubIntegration.error.loadDataFailed"))}finally{j(!1)}}},[u,i,c,o,y,r]),oe=Oe.useCallback(async()=>{if(!(!u||!i)&&!(P||C)&&K){I(!0);try{const W=O+1;if(y==="issues"&&i.issuesList){const ue=await i.issuesList(u,{page:W});ue.connected!==!1&&(w(Y=>[...Y,...ue.issues??[]]),L(ue.page??W),B(!!ue.hasMore))}else if(y==="prs"&&i.prsList){const ue=await i.prsList(u,{page:W});ue.connected!==!1&&(S(Y=>[...Y,...ue.prs??[]]),L(ue.page??W),B(!!ue.hasMore))}}catch{}finally{I(!1)}}},[u,i,y,O,K,P,C]);Oe.useEffect(()=>{if(!t){h("issues"),x(""),w([]),S([]),N(null),T(null),$(!1),k(null),_(new Map),L(1),B(!1);return}re()},[t,re]);const ee=Oe.useCallback(async W=>{if(!(!f||!W)&&!F.has(W))try{const Y=(await Pg(f,{mode:"new",branchName:W,worktreeName:W})).errors.find(le=>le.code==="branch_in_use");_(le=>new Map(le).set(W,{isValid:!Y,error:Y?r(Y.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{_(ue=>new Map(ue).set(W,{isValid:!1,error:r("session.githubIntegration.validation.failed")}))}},[f,F,r]);Oe.useEffect(()=>{!t||y!=="prs"||v.forEach(W=>{W.head&&ee(W.head)})},[t,y,v,ee]);const ae=Oe.useMemo(()=>{const W=b.trim().toLowerCase();return W?g.filter(ue=>String(ue.number)===W.replace(/^#/,"")?!0:ue.title.toLowerCase().includes(W)):g},[g,b]),ge=Oe.useMemo(()=>{const W=b.trim().toLowerCase();return W?v.filter(ue=>String(ue.number)===W.replace(/^#/,"")?!0:ue.title.toLowerCase().includes(W)):v},[v,b]),ne=c&&o?.connected===!0,E=()=>{p("github"),d(!0)},z=W=>{N(W),T(null)},J=W=>{T(W),N(null)},H=()=>{A?n({type:"issue",item:A}):D&&n({type:"pr",item:D,includeDiff:M}),e(!1)},te=()=>{N(null),T(null),$(!1)},ce=A||D&&F.get(D.head??"")?.isValid!==!1,Se=W=>W.head?F.get(W.head)?.isValid===!1:!0,pe=s.jsx(s.Fragment,{children:ne?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"relative mt-2",children:[s.jsx(Jn,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),s.jsx(Bt,{value:b,onChange:W=>x(W.target.value),placeholder:r(y==="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:[P&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx(ts,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),R&&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(Qr,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-small",children:R})]})}),!P&&!R&&y==="issues"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[ae.length>0?ae.map(W=>s.jsx("button",{onClick:()=>z(W),className:me("w-full text-left px-2 py-1.5 rounded transition-colors",A?.number===W.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:["#",W.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-2",children:W.title}),W.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:[W.sourceRepo.owner,"/",W.sourceRepo.repo]}):null]})]})},`${W.sourceRepo?.owner??""}-${W.sourceRepo?.repo??""}-${W.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")}),K&&!C&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>{oe()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),C&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(ts,{className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),!P&&!R&&y==="prs"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[ge.length>0?ge.map(W=>{const ue=Se(W),Y=W.head?F.get(W.head):void 0;return s.jsx("button",{onClick:()=>!ue&&J(W),disabled:ue,className:me("w-full text-left px-2 py-1.5 rounded transition-colors",D?.number===W.number?"bg-interactive-selection text-interactive-selection-foreground":ue?"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:["#",W.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-1",children:W.title}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[W.head," → ",W.base]}),W.sourceRepo?.source==="upstream"?s.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[W.sourceRepo.owner,"/",W.sourceRepo.repo]}):null,ue&&Y?.error&&s.jsx("span",{className:"typography-micro text-destructive",children:Y.error})]})]})]})},`${W.sourceRepo?.owner??""}-${W.sourceRepo?.repo??""}-${W.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")}),K&&!C&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>{oe()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),C&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(ts,{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(Mi,{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(ve,{onClick:E,size:"sm",children:r("session.githubIntegration.connect.action")})]})}),we=s.jsxs("div",{className:me("w-full",a?"flex flex-col gap-2":"flex flex-row items-center"),children:[s.jsxs("div",{className:me("flex items-center gap-4",a?"w-full justify-center order-1":"flex-1"),children:[!a&&(A||D)&&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(Zs,{className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate max-w-[150px]",children:A?r("session.githubIntegration.selected.issueNumber",{number:A.number}):r("session.githubIntegration.selected.prNumber",{number:D?.number??""})}),s.jsx("button",{onClick:te,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(Is,{className:"h-3.5 w-3.5"})})]}),y==="prs"&&D&&s.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[s.jsx(bs,{checked:M,onChange:W=>$(W),ariaLabel:r("session.githubIntegration.includeDiffAria")}),s.jsx("span",{className:"typography-small text-foreground",children:r("session.githubIntegration.includeDiff")})]})]}),s.jsxs("div",{className:me("flex gap-2",a?"w-full order-2":"justify-end"),children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>e(!1),className:me(a&&"flex-1"),children:r("session.githubIntegration.actions.cancel")}),s.jsx(ve,{size:"sm",onClick:H,disabled:!ce,className:me(a&&"flex-1"),children:r("session.githubIntegration.actions.select")})]})]});return s.jsx(s.Fragment,{children:a?s.jsx(Vr,{open:t,title:r("session.githubIntegration.title"),onClose:()=>e(!1),footer:ne?we:void 0,renderHeader:W=>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")}),W]}),s.jsx("div",{className:"w-full",children:s.jsx(zr,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(Qs,{className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(Wa,{className:"h-3.5 w-3.5"})}],activeId:y,onSelect:ue=>{h(ue),x("")},variant:"active-pill",layoutMode:"fit"})}),(A||D)&&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(Zs,{className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate flex-1",children:A?r("session.githubIntegration.selected.issueNumber",{number:A.number}):r("session.githubIntegration.selected.prNumber",{number:D?.number??""})}),s.jsx("button",{onClick:te,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(Is,{className:"h-3.5 w-3.5"})})]})]}),children:pe}):s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsx(Cs,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(js,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(Mi,{className:"h-5 w-5"}),r("session.githubIntegration.title")]}),s.jsx("div",{className:"w-[220px]",children:s.jsx(zr,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(Qs,{className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(Wa,{className:"h-3.5 w-3.5"})}],activeId:y,onSelect:W=>{h(W),x("")},variant:"active-pill",layoutMode:"fit"})})]})}),pe,s.jsx(Xs,{className:"mt-1",children:we})]})})})}const yo=t=>t.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),Gn=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),Xh="oc:lastWorktreeSourceBranch",A6=t=>String(t).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",Zh=(t,e,n)=>{const r=yo(t.head||"");if(!r)throw new Error("PR head branch is missing");if(e.includes(r))return{existingBranch:r,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:r};const a=n.find(p=>{const m=p.indexOf("/");return m<=0||m>=p.length-1?!1:p.slice(m+1)===r});if(a){const p=a.indexOf("/"),m=a.slice(0,p);return{existingBranch:`remotes/${a}`,setUpstream:!0,upstreamRemote:m,upstreamBranch:r,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${m}/${r}`}}const i=String(t.headLabel||"").split(":")[0]?.trim(),o=t.headRepo?.owner||i||"pr-head",c=`pr-${A6(o)}`,d=t.headRepo?.sshUrl||t.headRepo?.cloneUrl||"";if(!d)throw new Error("PR head repository URL is unavailable");return{existingBranch:`remotes/${c}/${r}`,setUpstream:!0,upstreamRemote:c,upstreamBranch:r,ensureRemoteName:c,ensureRemoteUrl:d,sourceLabel:`${c}/${r}`}},P6=t=>{const e={repo:t.repo??null,issue:t.issue,comments:t.comments};return`GitHub issue context (JSON)
|
|
87
|
+
${JSON.stringify(e,null,2)}`},D6=t=>`GitHub pull request context (JSON)
|
|
88
|
+
${JSON.stringify(t,null,2)}`;function T6({open:t,onOpenChange:e,onWorktreeCreated:n}){const{t:r}=ut(),{github:a,git:i}=Yn(),o=De(ie=>ie.isMobile),c=sr(ie=>ie.status),d=sr(ie=>ie.hasChecked),p=Es(ie=>ie.getActiveProject()),m=p?.path??null,u=Oe.useMemo(()=>m&&p?{id:p.id,path:m}:null,[p,m]),[f,y]=Oe.useState("new-branch"),[h,b]=Oe.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[x,g]=Oe.useState({selectedBranch:"",worktreeName:""}),w=Bu(m),v=Dg(m),S=pn(ie=>ie.fetchBranches),P=Oe.useMemo(()=>w?.all?w.all.filter(ie=>!ie.startsWith("remotes/")).sort():[],[w]),j=Oe.useMemo(()=>w?.all?w.all.filter(ie=>ie.startsWith("remotes/")).map(ie=>ie.replace(/^remotes\//,"")).sort():[],[w]),C=Ht(ie=>ie.availableWorktreesByProject),I=Oe.useMemo(()=>{if(!m)return new Set;const ie=C.get(m)??[];return new Set(ie.map(U=>U.name))},[C,m]),R=Oe.useCallback((ie=10)=>{for(let U=0;U<ie;U++){const Ve=Kc();if(!I.has(Ve))return Ve}return`${Kc()}-${Date.now().toString(36).slice(-4)}`},[I]),[k,A]=Oe.useState(!1),[N,D]=Oe.useState(!1),[T,M]=Oe.useState(!1),[$,F]=Oe.useState(!1),[_,O]=Oe.useState(!1),[L,K]=Oe.useState(""),[B,re]=Oe.useState(""),oe=Oe.useRef(null),ee=Oe.useRef(null),ae=Oe.useRef(null),ge=Oe.useRef(null),ne=Oe.useCallback(ie=>{let U=ie;for(;U&&U!==document.body;){const{overflowY:Ve}=window.getComputedStyle(U);if((Ve==="auto"||Ve==="scroll")&&U.scrollHeight>U.clientHeight)return U;U=U.parentElement}return null},[]),E=Oe.useCallback(ie=>{ie&&(ie.scrollTop=0)},[]),z=Oe.useCallback(ie=>{const U=ie.current?.querySelector('[data-slot="command-list"]')??null;E(U)},[E]),J=Oe.useCallback(ie=>{const U=ne(ie.current);E(U)},[ne,E]),H=Oe.useMemo(()=>Yh({localBranches:P,remoteBranches:j,query:L}),[P,j,L]),te=Oe.useMemo(()=>Yh({localBranches:P,remoteBranches:j,query:B}),[P,j,B]),ce=L.trim().length>0,Se=B.trim().length>0,pe=H.matching.length>0,we=te.matching.length>0,W=!!(m&&i),ue=Oe.useCallback(()=>{!m||!i||S(m,i)},[m,i,S]);Oe.useEffect(()=>{!N&&!$&&K("")},[N,$]),Oe.useEffect(()=>{!T&&!_&&re("")},[T,_]),Oe.useEffect(()=>{N&&z(oe),$&&J(ae)},[N,$,L,z,J]),Oe.useEffect(()=>{T&&z(ee),_&&J(ge)},[T,_,B,z,J]);const[Y,le]=Oe.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[Z,Ie]=Oe.useState(!1),[Ne,X]=Oe.useState(null),he=Oe.useCallback(()=>{const ie=yt.getState(),U=ie.getVisibleAgents();if(ie.settingsDefaultAgent){const Ve=U.find(He=>He.name===ie.settingsDefaultAgent);if(Ve)return Ve.name}return U.find(Ve=>Ve.name==="build")?.name||U[0]?.name},[]),je=Oe.useCallback(()=>{const ie=yt.getState(),U=ie.settingsDefaultModel;if(!U)return null;const Ve=Ji(U);if(!Ve)return null;const{providerId:He,modelId:Ke}=Ve;return ie.getModelMetadata(He,Ke)?{providerID:He,modelID:Ke}:null},[]),be=Oe.useCallback((ie,U)=>{const Ve=yt.getState(),He=Ve.settingsDefaultVariant;if(!He)return;const Xe=Ve.providers.find(dt=>dt.id===ie)?.models.find(dt=>dt.id===U)?.variants;if(Xe&&Object.prototype.hasOwnProperty.call(Xe,He))return He},[]),fe=Oe.useCallback(ie=>{const U=yt.getState();try{rl.getState().saveSessionModelSelection(ie.sessionId,ie.providerID,ie.modelID)}catch{}if(ie.agentName){try{U.setAgent(ie.agentName)}catch{}try{rl.getState().saveSessionAgentSelection(ie.sessionId,ie.agentName)}catch{}try{rl.getState().saveAgentModelForSession(ie.sessionId,ie.agentName,ie.providerID,ie.modelID)}catch{}if(ie.variant!==void 0){try{U.setCurrentVariant(ie.variant)}catch{}try{rl.getState().saveAgentModelVariantForSession(ie.sessionId,ie.agentName,ie.providerID,ie.modelID,ie.variant)}catch{}}}},[]),Pe=Oe.useCallback(async ie=>{if(!m||!a)return;const U=yt.getState(),Ve=xc.getState().lastUsedProvider,He=je(),Ke=He?.providerID||U.currentProviderId||Ve?.providerID,Ze=He?.modelID||U.currentModelId||Ve?.modelID,Xe=he()||U.currentAgentName||void 0;if(!Ke||!Ze){q.error(r("session.newWorktree.error.noModelSelected"));return}const dt=be(Ke,Ze);if(fe({sessionId:ie.sessionId,providerID:Ke,modelID:Ze,agentName:Xe,variant:dt}),ie.issue){if(!a.issueGet||!a.issueComments)return;const et=await a.issueGet(m,ie.issue.number);if(et.connected===!1||!et.repo||!et.issue)throw new Error("Failed to load issue context");const ct=await a.issueComments(m,ie.issue.number);if(ct.connected===!1)throw new Error("Failed to load issue comments");const at=await zn("github.issue.review.visible",{issue_number:String(ie.issue.number)}),ye=await zn("github.issue.review.instructions"),Ge=P6({repo:et.repo,issue:et.issue,comments:ct.comments??[]});await Mn.sendMessage({id:ie.sessionId,providerID:Ke,modelID:Ze,agent:Xe,variant:dt,text:at,additionalParts:[{text:ye,synthetic:!0},{text:Ge,synthetic:!0}]}),q.success(r("session.newWorktree.toast.sessionFromIssue"));return}if(ie.pr){if(!a.prContext)return;const et=await a.prContext(m,ie.pr.number,{includeDiff:ie.includeDiff,includeCheckDetails:!1});if(et.connected===!1||!et.repo||!et.pr)throw new Error("Failed to load PR context");const ct=await zn("github.pr.review.visible",{pr_number:String(ie.pr.number)}),at=await zn("github.pr.review.instructions"),ye=D6(et);await Mn.sendMessage({id:ie.sessionId,providerID:Ke,modelID:Ze,agent:Xe,variant:dt,text:ct,additionalParts:[{text:at,synthetic:!0},{text:ye,synthetic:!0}]}),q.success(r("session.newWorktree.toast.sessionFromPr"))}},[fe,a,m,he,je,be,r]),Be=f==="new-branch"?h:x;Oe.useEffect(()=>{if(!w?.all||!m||h.sourceBranch)return;(async()=>{try{const U=await Uo(m).catch(()=>null),Ve=localStorage.getItem(Xh),He=Ve&&w.all?.includes(Ve)?Ve:U&&w.all?.includes(U)?U:w.all?.includes("main")?"main":w.all?.includes("master")?"master":w.all?.[0]||"";He&&b(Ke=>({...Ke,sourceBranch:He}))}catch{}})()},[w,m,h.sourceBranch]),Oe.useEffect(()=>{if(!t)return;y("new-branch"),g({selectedBranch:"",worktreeName:""}),D(!1),M(!1),F(!1),O(!1),K(""),re(""),le({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const ie=R();b({branchName:ie,worktreeName:ie,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[t,R]),Oe.useEffect(()=>{if(f!=="new-branch"||!h.isSyncingWorktreeName)return;const ie=yo(h.branchName),U=Gn(ie);b(Ve=>({...Ve,worktreeName:U}))},[f,h.branchName,h.isSyncingWorktreeName]);const G=Oe.useCallback(async()=>{if(!u||!Y.touched||Z)return;Ne&&Ne.abort();const ie=new AbortController;X(ie),le(U=>({...U,isValidating:!0}));try{const U=f==="new-branch"?h.branchName:x.selectedBranch,Ve=Be.worktreeName,He=yo(U),Ke=Gn(Ve);let Ze=null,Xe=null;if(He||(Ze=r("session.newWorktree.error.branchNameRequired")),Ke||(Xe=r("session.newWorktree.error.worktreeDirectoryRequired")),He&&Ke){const dt=f==="new-branch"?h.linkedPr:null,et=dt?Zh(dt,P,j):null,ct=await Pg(u,{mode:f==="existing-branch"||et?"existing":"new",branchName:He,worktreeName:Ke,existingBranch:et?.existingBranch??(f==="existing-branch"?He:void 0),...et?.ensureRemoteName?{ensureRemoteName:et.ensureRemoteName}:{},...et?.ensureRemoteUrl?{ensureRemoteUrl:et.ensureRemoteUrl}:{}});if(ie.signal.aborted)return;ct.ok||ct.errors.forEach(at=>{if(at.code==="worktree_exists"){Xe=Xe??at.message;return}at.code.startsWith("branch_")&&(Ze=Ze??at.message)})}ie.signal.aborted||le(dt=>({...dt,isValidating:!1,branchError:Ze,worktreeError:Xe}))}catch{ie.signal.aborted||le(U=>({...U,isValidating:!1}))}},[u,f,h.branchName,h.linkedPr,x.selectedBranch,Be.worktreeName,P,j,Y.touched,Ne,Z,r]),ke=f==="new-branch"?h.branchName:x.selectedBranch;Oe.useEffect(()=>{if(!t||!u||!Y.touched||Z)return;const ie=setTimeout(()=>{G()},300);return()=>clearTimeout(ie)},[Be.worktreeName,ke,t,u,G,Y.touched,Z]);const Ee=async()=>{if(!u||!m){q.error(r("session.newWorktree.error.noActiveProject"));return}le(Ke=>({...Ke,touched:!0}));const ie=f==="new-branch"?h.branchName:x.selectedBranch,U=Be.worktreeName,Ve=yo(ie),He=Gn(U);if(!Ve){q.error(r("session.newWorktree.error.branchNameRequired"));return}if(!He){q.error(r("session.newWorktree.error.worktreeDirectoryRequired"));return}Ne&&(Ne.abort(),X(null)),le(Ke=>({...Ke,isValidating:!1,branchError:null,worktreeError:null})),Ie(!0);try{const Ke=await Wu(u),Ze=f==="new-branch"?h.linkedPr:null,Xe=h.sourceBranch;let dt="";const et=(()=>{if(Ze){const tt=Zh(Ze,P,j);return dt=tt.sourceLabel,{preferredName:Ve||He,mode:"existing",branchName:Ve,worktreeName:He,existingBranch:tt.existingBranch,setupCommands:Ke,setUpstream:tt.setUpstream,upstreamRemote:tt.upstreamRemote,upstreamBranch:tt.upstreamBranch,...tt.ensureRemoteName?{ensureRemoteName:tt.ensureRemoteName}:{},...tt.ensureRemoteUrl?{ensureRemoteUrl:tt.ensureRemoteUrl}:{}}}return dt=f==="new-branch"?Xe:"",{preferredName:Ve||He,mode:f==="existing-branch"?"existing":"new",branchName:f==="existing-branch"?void 0:Ve,worktreeName:He,existingBranch:f==="existing-branch"?Ve:void 0,setupCommands:Ke,...Xe&&f==="new-branch"?{startRef:Xe}:{}}})(),ct=await G1(m,et),at=await q1(u,ct),ye=f==="new-branch"?h.linkedIssue:null,Ge=f==="new-branch"?h.linkedPr:null,$e=f==="new-branch"?h.includePrDiff:!1;let _e=null;if(ye||Ge){const tt=ye?`#${ye.number} ${ye.title}`.trim():Ge?`#${Ge.number} ${Ge.title}`.trim():r("session.newWorktree.newSessionTitle"),Qe=await Q1(tt,at.path,null);if(!Qe?.id)throw new Error("Failed to create session");_e=Qe.id,J1(Qe.id,tt).catch(()=>{});try{Ht.getState().initializeNewOpenChamberSession(Qe.id,yt.getState().agents)}catch{}}h.sourceBranch&&f==="new-branch"&&!h.linkedPr&&localStorage.setItem(Xh,h.sourceBranch),q.success(r("session.newWorktree.toast.worktreeCreated"),{description:r("session.newWorktree.toast.worktreeCreatedDescription",{target:`${at.branch||at.name}${dt?` ${r("session.newWorktree.fromSource",{source:dt})}`:""}`})}),e(!1),_e?(n?.(at.path,{sessionId:_e}),Pe({sessionId:_e,issue:ye,pr:Ge,includeDiff:$e}).catch(tt=>{const Qe=tt instanceof Error?tt.message:r("session.newWorktree.error.sendGitHubContextFailed");q.error(r("session.newWorktree.error.sendGitHubContextFailed"),{description:Qe})})):n?.(at.path)}catch(Ke){const Ze=Ke instanceof Error?Ke.message:r("session.newWorktree.error.createWorktreeFailed");q.error(r("session.newWorktree.error.createWorktreeFailed"),{description:Ze})}finally{Ie(!1)}},Ae=ie=>{y(ie),le(U=>({...U,touched:!1,branchError:null,worktreeError:null}))},xe=ie=>{if(!ie){b(U=>({...U,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(ie.type==="issue"){const U=ie.item,Ve=`issue-${U.number}-${Kc()}`;b(He=>({...He,linkedIssue:U,linkedPr:null,includePrDiff:!1,branchName:Ve,worktreeName:Gn(Ve),isSyncingWorktreeName:!0}))}else if(ie.type==="pr"){const U=ie.item;b(Ve=>({...Ve,linkedPr:U,linkedIssue:null,includePrDiff:ie.includeDiff??!1,branchName:U.head,worktreeName:Gn(U.head),isSyncingWorktreeName:!0}))}},V=d&&c?.connected===!0,Me=(f==="existing-branch"?!!x.selectedBranch&&!!x.worktreeName&&!Y.branchError&&!Y.worktreeError:!!yo(h.branchName)&&!!h.worktreeName&&!Y.branchError&&!Y.worktreeError)&&!Z,Le=()=>{b(ie=>({...ie,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},se=s.jsxs("div",{className:me("flex gap-2",o?"flex-col w-full":"flex-row items-center"),children:[s.jsx("div",{className:me("flex items-center gap-1.5 text-destructive",o?"w-full justify-center order-first":"mr-auto"),children:Y.touched&&(Y.branchError||Y.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(Qr,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:Y.branchError||Y.worktreeError})]})}),s.jsxs("div",{className:me("flex gap-2",o&&"w-full"),children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Z,className:me(o&&"flex-1"),children:r("session.newWorktree.actions.cancel")}),s.jsxs(ve,{size:"sm",onClick:Ee,disabled:!Me||Z,className:me("gap-1.5",o&&"flex-1"),children:[Z&&s.jsx(ts,{className:"h-3.5 w-3.5 animate-spin"}),r(Z?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return s.jsxs(s.Fragment,{children:[o?s.jsxs(Vr,{open:t,title:r("session.newWorktree.title"),onClose:()=>e(!1),footer:se,children:[s.jsx("div",{className:"w-full mb-4",children:s.jsx(zr,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(Qs,{className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(Fd,{className:"h-3.5 w-3.5"})}],activeId:f,onSelect:ie=>Ae(ie),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),s.jsxs("div",{className:"space-y-6",children:[f==="existing-branch"?s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.selectBranch")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>F(!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(Qs,{className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(ve,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:ue,disabled:!W||v,title:r("session.newWorktree.fetchBranches"),children:v?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(In,{className:"size-4"})})]}),s.jsx(Vr,{open:$,title:r("session.newWorktree.selectBranch"),onClose:()=>F(!1),children:s.jsxs("div",{className:"space-y-4",ref:ae,children:[s.jsx(Bt,{value:L,onChange:ie=>K(ie.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")}):P.length===0&&j.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[ce&&pe&&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:H.matching.map(ie=>s.jsx("button",{onClick:()=>{g(U=>({...U,selectedBranch:ie.value,worktreeName:Gn(ie.label)})),le(U=>({...U,touched:!0})),F(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===ie.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ie.label})},`${ie.source}-${ie.value}`))})]}),ce&&!pe&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),H.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(ce?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:H.otherLocal.map(ie=>s.jsx("button",{onClick:()=>{g(U=>({...U,selectedBranch:ie,worktreeName:Gn(ie)})),le(U=>({...U,touched:!0})),F(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===ie?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ie})},ie))})]}),H.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(ce?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:H.otherRemote.map(ie=>s.jsx("button",{onClick:()=>{g(U=>({...U,selectedBranch:`remotes/${ie}`,worktreeName:Gn(ie)})),le(U=>({...U,touched:!0})),F(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===`remotes/${ie}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ie})},`remotes/${ie}`))})]})]})]})})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),f==="new-branch"&&V&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>A(!0),className:"gap-1.5 h-7",children:[s.jsx(Mi,{className:"size-4 text-status-success"}),h.linkedIssue||h.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Bt,{value:h.branchName,onChange:ie=>{b(U=>({...U,branchName:ie.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>le(ie=>({...ie,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!h.linkedPr,className:me("h-8",Y.touched&&Y.branchError&&"border-destructive",h.linkedPr&&"bg-muted text-muted-foreground")}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(Zs,{className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:h.linkedPr.head})})]}),h.linkedIssue&&!h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(Zs,{className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:h.linkedIssue.number,title:h.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),f!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const ie=Gn(f==="new-branch"?h.branchName:"");b(U=>({...U,worktreeName:ie,isSyncingWorktreeName:!0}))},disabled:!h.branchName||h.worktreeName===Gn(h.branchName),className:me("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",h.worktreeName===Gn(h.branchName)||!h.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(In,{className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Bt,{value:Be.worktreeName,onChange:ie=>{f==="new-branch"?b(U=>({...U,worktreeName:ie.target.value,isSyncingWorktreeName:!1})):g(U=>({...U,worktreeName:ie.target.value}))},onBlur:()=>le(ie=>({...ie,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:me("h-8",Y.touched&&Y.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!h.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>O(!0),className:"w-full justify-between h-9",children:[s.jsx("span",{className:h.sourceBranch?"text-foreground":"text-muted-foreground",children:h.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(Qs,{className:"h-4 w-4 text-muted-foreground"})]}),h.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:h.sourceBranch})}),s.jsx(Vr,{open:_,title:r("session.newWorktree.selectSourceBranch"),onClose:()=>O(!1),children:s.jsxs("div",{className:"space-y-4",ref:ge,children:[s.jsx(Bt,{value:B,onChange:ie=>re(ie.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")}):P.length===0&&j.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[Se&&we&&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:te.matching.map(ie=>s.jsx("button",{onClick:()=>{b(U=>({...U,sourceBranch:ie.value})),O(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===ie.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ie.label})},`${ie.source}-${ie.value}`))})]}),Se&&!we&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),te.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:te.otherLocal.map(ie=>s.jsx("button",{onClick:()=>{b(U=>({...U,sourceBranch:ie})),O(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===ie?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ie})},ie))})]}),te.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:te.otherRemote.map(ie=>s.jsx("button",{onClick:()=>{b(U=>({...U,sourceBranch:`remotes/${ie}`})),O(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===`remotes/${ie}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ie})},`remotes/${ie}`))})]})]})]})})]}),(h.linkedIssue||h.linkedPr)&&f==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Mi,{className:"h-3.5 w-3.5 text-status-success shrink-0"}),h.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:h.linkedIssue.number})}),h.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:h.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:h.linkedIssue?.title||h.linkedPr?.title}),s.jsx("a",{href:h.linkedIssue?.url||h.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:ie=>ie.stopPropagation(),children:s.jsx(Pr,{className:"h-3 w-3"})}),s.jsx("button",{onClick:Le,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(Is,{className:"h-3.5 w-3.5"})})]}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[h.linkedPr.head," → ",h.linkedPr.base]}),h.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]})]}):s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[s.jsx(Cs,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(js,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(Qs,{className:"h-5 w-5"}),r("session.newWorktree.title")]}),s.jsx("div",{className:"w-[280px] shrink-0",children:s.jsx(zr,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(Qs,{className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(Fd,{className:"h-3.5 w-3.5"})}],activeId:f,onSelect:ie=>Ae(ie),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),s.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[f==="existing-branch"?s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.selectBranch")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(_s,{open:N,onOpenChange:D,children:[s.jsx($s,{asChild:!0,children:s.jsxs(ve,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:me("truncate",x.selectedBranch?"text-foreground":"text-muted-foreground"),children:x.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(ks,{className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(Bs,{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:oe,children:s.jsxs(oi,{shouldFilter:!1,children:[s.jsx(Ia,{placeholder:r("session.newWorktree.searchBranches"),value:L,onValueChange:K}),s.jsx(li,{disableHorizontal:!0,children:v?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):P.length===0&&j.length===0?s.jsx(ci,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[ce&&pe&&s.jsx(Qn,{heading:r("session.newWorktree.matchingBranches"),children:H.matching.map(ie=>s.jsx(On,{value:ie.value,onSelect:()=>{g(U=>({...U,selectedBranch:ie.value,worktreeName:Gn(ie.label)})),le(U=>({...U,touched:!0})),D(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie.label})},`${ie.source}-${ie.value}`))}),ce&&!pe&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),H.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[ce&&s.jsx(Ka,{}),s.jsx(Qn,{heading:r(ce?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:H.otherLocal.map(ie=>s.jsx(On,{value:ie,onSelect:()=>{g(U=>({...U,selectedBranch:ie,worktreeName:Gn(ie)})),le(U=>({...U,touched:!0})),D(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie})},`local-${ie}`))})]}),H.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(H.otherLocal.length>0||ce)&&s.jsx(Ka,{}),s.jsx(Qn,{heading:r(ce?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:H.otherRemote.map(ie=>s.jsx(On,{value:`remotes/${ie}`,onSelect:()=>{g(U=>({...U,selectedBranch:`remotes/${ie}`,worktreeName:Gn(ie)})),le(U=>({...U,touched:!0})),D(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie})},`remote-${ie}`))})]})]})})]})})]}),s.jsx(ve,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:ue,disabled:!W||v,title:r("session.newWorktree.fetchBranches"),children:v?s.jsx(ts,{className:"size-4 animate-spin"}):s.jsx(In,{className:"size-4"})})]})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),f==="new-branch"&&V&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>A(!0),className:"gap-1.5 h-7",children:[s.jsx(Mi,{className:"size-4 text-status-success"}),h.linkedIssue||h.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Bt,{value:h.branchName,onChange:ie=>{b(U=>({...U,branchName:ie.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>le(ie=>({...ie,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!h.linkedPr,className:me("h-8",Y.touched&&Y.branchError&&"border-destructive",h.linkedPr&&"bg-muted text-muted-foreground")}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(Zs,{className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:h.linkedPr.head})})]}),h.linkedIssue&&!h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(Zs,{className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:h.linkedIssue.number,title:h.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),f!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const ie=Gn(f==="new-branch"?h.branchName:"");b(U=>({...U,worktreeName:ie,isSyncingWorktreeName:!0}))},disabled:!h.branchName||h.worktreeName===Gn(h.branchName),className:me("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",h.worktreeName===Gn(h.branchName)||!h.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(In,{className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Bt,{value:Be.worktreeName,onChange:ie=>{f==="new-branch"?b(U=>({...U,worktreeName:ie.target.value,isSyncingWorktreeName:!1})):g(U=>({...U,worktreeName:ie.target.value}))},onBlur:()=>le(ie=>({...ie,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:me("h-8",Y.touched&&Y.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!h.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(_s,{open:T,onOpenChange:M,children:[s.jsx($s,{asChild:!0,children:s.jsxs(ve,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:me("truncate",h.sourceBranch?"text-foreground":"text-muted-foreground"),children:h.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(ks,{className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(Bs,{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:ee,children:s.jsxs(oi,{shouldFilter:!1,children:[s.jsx(Ia,{placeholder:r("session.newWorktree.searchBranches"),value:B,onValueChange:re}),s.jsx(li,{disableHorizontal:!0,children:v?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):P.length===0&&j.length===0?s.jsx(ci,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[Se&&we&&s.jsx(Qn,{heading:r("session.newWorktree.matchingBranches"),children:te.matching.map(ie=>s.jsx(On,{value:ie.value,onSelect:()=>{b(U=>({...U,sourceBranch:ie.value})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie.label})},`${ie.source}-${ie.value}`))}),Se&&!we&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),te.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[Se&&s.jsx(Ka,{}),s.jsx(Qn,{heading:r(Se?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:te.otherLocal.map(ie=>s.jsx(On,{value:ie,onSelect:()=>{b(U=>({...U,sourceBranch:ie})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie})},`local-${ie}`))})]}),te.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(te.otherLocal.length>0||Se)&&s.jsx(Ka,{}),s.jsx(Qn,{heading:r(Se?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:te.otherRemote.map(ie=>s.jsx(On,{value:`remotes/${ie}`,onSelect:()=>{b(U=>({...U,sourceBranch:`remotes/${ie}`})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie})},`remote-${ie}`))})]})]})})]})})]}),h.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:h.sourceBranch})})]}),(h.linkedIssue||h.linkedPr)&&f==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Mi,{className:"h-3.5 w-3.5 text-status-success shrink-0"}),h.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:h.linkedIssue.number})}),h.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:h.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:h.linkedIssue?.title||h.linkedPr?.title}),s.jsx("a",{href:h.linkedIssue?.url||h.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:ie=>ie.stopPropagation(),children:s.jsx(Pr,{className:"h-3 w-3"})}),s.jsx("button",{onClick:Le,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(Is,{className:"h-3.5 w-3.5"})})]}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[h.linkedPr.head," → ",h.linkedPr.base]}),h.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]}),s.jsxs(Xs,{className:"mt-1 flex items-center justify-between",children:[s.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:Y.touched&&(Y.branchError||Y.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(Qr,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:Y.branchError||Y.worktreeError})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Z,children:r("session.newWorktree.actions.cancel")}),s.jsxs(ve,{size:"sm",onClick:Ee,disabled:!Me||Z,className:"gap-1.5",children:[Z&&s.jsx(ts,{className:"h-3.5 w-3.5 animate-spin"}),r(Z?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),s.jsx(I6,{open:k,onOpenChange:A,onSelect:xe})]})}let _i=null,Vi=null,Ol=null,oc=0;const Xa=new Set,M6=3e4,R6=45e3,Qx=()=>{Ol&&(clearTimeout(Ol),Ol=null)},Jx=()=>{if(Vi||Xa.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(oc,5)),M6);Vi=setTimeout(()=>{Vi=null,oc+=1,Yx()},t)},lc=()=>{Qx(),_i&&_i.close(),_i=null},ef=()=>{Qx(),Xa.size!==0&&(Ol=setTimeout(()=>{lc(),Jx()},R6))},E6=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}},F6=t=>{if(t.type==="openchamber:event-stream-ready"){oc=0;return}if(t.type==="openchamber:heartbeat"||t.type!=="openchamber:scheduled-task-ran")return;const e=t.properties&&typeof t.properties=="object"?t.properties:null,n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",a=typeof e?.ranAt=="number"?e.ranAt:Date.now(),i=e?.status,o=i==="running"||i==="error"?i:"success";if(!n||!r)return;const c={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:a,status:o,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of Xa)d(c)},Yx=()=>{if(typeof window>"u"||Xa.size===0||typeof EventSource!="function"||_i&&_i.readyState!==EventSource.CLOSED)return;lc();const t=new EventSource("/api/openchamber/events");t.onopen=()=>{ef()},t.onmessage=e=>{ef();const n=E6(e.data);n&&F6(n)},t.onerror=()=>{lc(),Jx()},_i=t},Xx=t=>(Xa.add(t),Yx(),()=>{Xa.delete(t),Xa.size===0&&(Vi&&(clearTimeout(Vi),Vi=null),oc=0,lc())}),Cc=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},eo=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},O6=async t=>{const e=eo(t),n=await fetch(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await Cc(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},tf=async(t,e)=>{const n=eo(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 Cc(r,"Failed to save scheduled task"));const a=await r.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},L6=async(t,e)=>{const n=eo(t),r=eo(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 Cc(a,"Failed to delete scheduled task"));const i=await a.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},$6=async(t,e)=>{const n=eo(t),r=eo(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 Cc(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}},Zx=[0,1,2,3,4,5,6],sf=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"],nf=()=>{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}`},Ll=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},rf=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},B6=(t,e,n)=>{const r=Ll(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},af=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),_6=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),o=(new Date(n,r,1).getDay()-e+7)%7,c=new Date(n,r+1,0).getDate(),d=new Date(n,r,0).getDate(),p=[];for(let m=0;m<42;m+=1){const u=m-o+1;if(u<=0){const f=d+u;p.push({date:new Date(n,r-1,f),inCurrentMonth:!1});continue}if(u>c){p.push({date:new Date(n,r+1,u-c),inCurrentMonth:!1});continue}p.push({date:new Date(n,r,u),inCurrentMonth:!0})}return p},V6=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}},$a=(t,e,n)=>{const r=Number(t),a=Number(e),i=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,o=Number.isFinite(a)?Math.min(59,Math.max(0,a)):0;let c=i%12;return n==="PM"&&(c+=12),`${String(c).padStart(2,"0")}:${String(o).padStart(2,"0")}`},no=(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"},of=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:no(t,{min:1,max:12}),bl=t=>/^[0-5][0-9]$/.test(t)?t:no(t,{max:59}),z6=(t,e)=>no(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),lf=(t,e)=>no(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),U6=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}},W6=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}},K6=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Zx.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},H6=(t,e)=>[...t.slice(e),...t.slice(0,e)],Ir=t=>{const e=nt.c(6),{htmlFor:n,required:r,children:a}=t;let i;e[0]!==r?(i=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=i):i=e[1];let o;return e[2]!==a||e[3]!==n||e[4]!==i?(o=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,i]})}),e[2]=a,e[3]=n,e[4]=i,e[5]=o):o=e[5],o},cf=t=>{const e=nt.c(84),{value:n,onChange:r,use24Hour:a,hourAriaLabel:i,minuteAriaLabel:o,periodAriaLabel:c,amLabel:d,pmLabel:p}=t;let m;e[0]!==n?(m=V6(n),e[0]=n,e[1]=m):m=e[1];const u=m,f=Oe.useRef(null),y=Oe.useRef(null),[h,b]=Oe.useState(null),[x,g]=Oe.useState(null),w=Oe.useRef(null),v=Oe.useRef(null);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=Z=>{w.current=Z,b(Z)},e[2]=S):S=e[2];const P=S;let j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=Z=>{v.current=Z,g(Z)},e[3]=j):j=e[3];const C=j,I=X6,R=Z6,k=eP;let A;e[4]!==r||e[5]!==u.meridiem||e[6]!==u.minute||e[7]!==a?(A=Z=>{const Ie=Z.replace(/\D/g,"").slice(0,2);P(Ie),Ie.length===2&&(r(a?k(I(Ie),u.minute):$a(of(Ie),u.minute,u.meridiem)),P(null),y.current?.focus())},e[4]=r,e[5]=u.meridiem,e[6]=u.minute,e[7]=a,e[8]=A):A=e[8];const N=A;let D;e[9]!==r||e[10]!==u.meridiem||e[11]!==u.minute||e[12]!==a?(D=()=>{const Z=w.current;if(Z!==null&&(P(null),Z.length!==0)){if(a){r(k(I(Z.padStart(2,"0")),u.minute));return}r($a(of(Z.padStart(2,"0")),u.minute,u.meridiem))}},e[9]=r,e[10]=u.meridiem,e[11]=u.minute,e[12]=a,e[13]=D):D=e[13];const T=D;let M;e[14]!==r||e[15]!==u.hour12||e[16]!==u.hour24||e[17]!==u.meridiem||e[18]!==a?(M=Z=>{const Ie=Z.replace(/\D/g,"").slice(0,2);C(Ie),Ie.length===2&&(r(a?k(u.hour24,bl(Ie)):$a(u.hour12,bl(Ie),u.meridiem)),C(null))},e[14]=r,e[15]=u.hour12,e[16]=u.hour24,e[17]=u.meridiem,e[18]=a,e[19]=M):M=e[19];const $=M;let F;e[20]!==r||e[21]!==u.hour12||e[22]!==u.hour24||e[23]!==u.meridiem||e[24]!==a?(F=()=>{const Z=v.current;Z!==null&&(C(null),Z.length!==0&&r(a?k(u.hour24,bl(Z.padStart(2,"0"))):$a(u.hour12,bl(Z.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]=F):F=e[25];const _=F;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=Z=>r(a?k(R(u.hour24,Z),u.minute):$a(z6(u.hour12,Z),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 L=O;let K;e[33]!==r||e[34]!==u.hour12||e[35]!==u.hour24||e[36]!==u.meridiem||e[37]!==u.minute||e[38]!==a?(K=Z=>r(a?k(u.hour24,lf(u.minute,Z)):$a(u.hour12,lf(u.minute,Z),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]=K):K=e[39];const B=K;let re;e[40]!==r||e[41]!==u.hour12||e[42]!==u.meridiem||e[43]!==u.minute?(re=Z=>{Z!==u.meridiem&&r($a(u.hour12,u.minute,Z))},e[40]=r,e[41]=u.hour12,e[42]=u.meridiem,e[43]=u.minute,e[44]=re):re=e[44];const oe=re;let ee;e[45]!==T||e[46]!==L?(ee=Z=>{if(Z.key==="ArrowRight"){Z.preventDefault(),T(),y.current?.focus();return}(Z.key==="ArrowUp"||Z.key==="ArrowDown")&&(Z.preventDefault(),P(null),L(Z.key==="ArrowUp"?1:-1))},e[45]=T,e[46]=L,e[47]=ee):ee=e[47];const ae=ee;let ge;e[48]!==_||e[49]!==B?(ge=Z=>{if(Z.key==="ArrowLeft"&&(Z.currentTarget.selectionStart??0)===0){Z.preventDefault(),_(),f.current?.focus();return}(Z.key==="ArrowUp"||Z.key==="ArrowDown")&&(Z.preventDefault(),C(null),B(Z.key==="ArrowUp"?1:-1))},e[48]=_,e[49]=B,e[50]=ge):ge=e[50];const ne=ge,E=a?"px-2":"pl-2 pr-1";let z;e[51]!==E?(z=me("inline-flex h-9 w-fit items-center gap-1 rounded-md border border-border bg-background focus-within:ring-1 focus-within:ring-interactive-focusRing focus-within:border-interactive-focusRing",E),e[51]=E,e[52]=z):z=e[52];const J=h??(a?u.hour24:u.hour12);let H;e[53]!==N?(H=Z=>N(Z.target.value),e[53]=N,e[54]=H):H=e[54];let te;e[55]===Symbol.for("react.memo_cache_sentinel")?(te=()=>P(""),e[55]=te):te=e[55];let ce;e[56]!==T||e[57]!==i||e[58]!==ae||e[59]!==J||e[60]!==H?(ce=s.jsx("input",{ref:f,inputMode:"numeric",value:J,onChange:H,onKeyDown:ae,onFocus:te,onBlur:T,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]=T,e[57]=i,e[58]=ae,e[59]=J,e[60]=H,e[61]=ce):ce=e[61];let Se;e[62]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=Se):Se=e[62];const pe=x??u.minute;let we;e[63]!==$?(we=Z=>$(Z.target.value),e[63]=$,e[64]=we):we=e[64];let W;e[65]===Symbol.for("react.memo_cache_sentinel")?(W=()=>C(""),e[65]=W):W=e[65];let ue;e[66]!==_||e[67]!==o||e[68]!==ne||e[69]!==pe||e[70]!==we?(ue=s.jsx("input",{ref:y,inputMode:"numeric",value:pe,onChange:we,onKeyDown:ne,onFocus:W,onBlur:_,maxLength:2,"aria-label":o,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=_,e[67]=o,e[68]=ne,e[69]=pe,e[70]=we,e[71]=ue):ue=e[71];let Y;e[72]!==d||e[73]!==u.meridiem||e[74]!==c||e[75]!==p||e[76]!==oe||e[77]!==a?(Y=a?null:s.jsxs(ps,{value:u.meridiem,onValueChange:Z=>oe(Z),children:[s.jsx(hs,{"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(ys,{})}),s.jsxs(fs,{children:[s.jsx(Rt,{value:"AM",children:d}),s.jsx(Rt,{value:"PM",children:p})]})]}),e[72]=d,e[73]=u.meridiem,e[74]=c,e[75]=p,e[76]=oe,e[77]=a,e[78]=Y):Y=e[78];let le;return e[79]!==z||e[80]!==ce||e[81]!==ue||e[82]!==Y?(le=s.jsxs("div",{className:z,children:[ce,Se,ue,Y]}),e[79]=z,e[80]=ce,e[81]=ue,e[82]=Y,e[83]=le):le=e[83],le},df=t=>new Date(t.getFullYear(),t.getMonth(),1),G6=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},uf=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),q6=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"]},mf=(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:q6(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:nf(),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:nf(),onceTime:"09:00",weekdays:[1],timezone:n},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent}}},Q6=(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")},J6=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 Y6(t){const{open:e,task:n,onOpenChange:r,onSave:a}=t,{t:i,locale:o}=ut(),c=yt(G=>G.loadProviders),d=yt(G=>G.loadAgents),p=yt(G=>G.providers),m=yt(G=>G.currentProviderId),u=yt(G=>G.currentModelId),f=yt(G=>G.currentVariant||""),y=yt(G=>G.currentAgentName||""),h=De(G=>G.timeFormatPreference),b=De(G=>G.weekStartPreference),x=De(G=>G.isMobile),[g,w]=Oe.useState(()=>mf(n,{providerID:m,modelID:u,variant:f,agent:y})),[v,S]=Oe.useState(!1),[P,j]=Oe.useState(!1),[C,I]=Oe.useState(!1),[R,k]=Oe.useState(""),[A,N]=Oe.useState(!1),[D,T]=Oe.useState(""),[M,$]=Oe.useState(()=>{const G=Ll(n?.schedule?.date||"")||new Date;return new Date(G.getFullYear(),G.getMonth(),1)}),F=Oe.useRef(null),_=Oe.useRef(null),O=Oe.useRef(null),L=Oe.useRef(null),K=Oe.useMemo(()=>W6(o),[o]),B=Oe.useMemo(()=>U6(o),[o]),re=Oe.useMemo(()=>h==="24h"?!0:h==="12h"?!1:K,[h,K]),oe=Oe.useMemo(()=>b==="sunday"?0:b==="monday"?1:B,[b,B]),ee=Oe.useMemo(()=>{const G=K6(o);return H6(Zx.map(ke=>({value:ke,label:G[ke]||""})),oe)},[o,oe]);Oe.useEffect(()=>{e&&(c(),d())},[e,c,d]),Oe.useEffect(()=>{if(!e)return;w(mf(n,{providerID:m,modelID:u,variant:f,agent:y}));const G=Ll(n?.schedule?.date||"")||new Date;$(new Date(G.getFullYear(),G.getMonth(),1)),j(!1),N(!1),I(!1),T(""),k("")},[e,n,m,u,f,y]),Oe.useEffect(()=>{if(!P)return;const G=ke=>{F.current&&!F.current.contains(ke.target)&&j(!1)};return document.addEventListener("mousedown",G),()=>{document.removeEventListener("mousedown",G)}},[P]);const ae=Oe.useMemo(()=>{const ke=p.find(Ee=>Ee.id===g.execution.providerID)?.models?.find(Ee=>Ee.id===g.execution.modelID);return ke?.variants?Object.keys(ke.variants):[]},[p,g.execution.providerID,g.execution.modelID]),ge=ae.length>0,ne=Oe.useMemo(()=>!ge||!g.execution.variant?"__default":ae.includes(g.execution.variant)?g.execution.variant:"__default",[g.execution.variant,ge,ae]);Oe.useEffect(()=>{ge||!g.execution.variant||w(G=>({...G,execution:{...G.execution,variant:""}}))},[ge,g.execution.variant]);const E=Oe.useCallback((G,ke)=>{w(Ee=>{const Ae=new Set(Ee.schedule.weekdays);return ke?Ae.add(G):Ae.delete(G),{...Ee,schedule:{...Ee.schedule,weekdays:Array.from(Ae).sort((xe,V)=>xe-V)}}})},[]),z=Oe.useCallback((G,ke)=>{w(Ee=>{const Ae=Ee.schedule.times.slice();return Ae[G]=ke,{...Ee,schedule:{...Ee.schedule,times:Ae}}})},[]),J=Oe.useCallback(G=>{w(ke=>{const Ee=ke.schedule.times.filter((Ae,xe)=>xe!==G);return{...ke,schedule:{...ke.schedule,times:Ee.length>0?Ee:["09:00"]}}})},[]),H=Oe.useCallback(()=>{w(G=>({...G,schedule:{...G.schedule,times:[...G.schedule.times,"12:00"]}}))},[]),te=Oe.useMemo(()=>G6(),[]),ce=Oe.useMemo(()=>df(te),[te]),Se=Oe.useMemo(()=>{const G=Ll(g.schedule.onceDate);return G?uf(G,te)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(o,{weekday:"short"}).format(G):null},[g.schedule.onceDate,o,i,te]),pe=Oe.useMemo(()=>df(M).getTime()<=ce.getTime(),[M,ce]),we=Oe.useMemo(()=>ee.map(G=>G.label),[ee]),W=Oe.useCallback(G=>{w(ke=>({...ke,schedule:{...ke.schedule,onceDate:G}}))},[]),ue=Oe.useCallback((G,ke)=>{if(G.startsWith("/")){const xe=G.indexOf(" "),V=G.indexOf(`
|
|
89
|
+
`),de=Math.min(xe===-1?G.length:xe,V===-1?G.length:V);if(ke<=de&&xe===-1){T(G.substring(1,de)),N(!0),I(!1);return}}N(!1);const Ee=G.substring(0,ke),Ae=Ee.lastIndexOf("@");if(Ae!==-1){const xe=Ae>0?Ee[Ae-1]:null,V=Ee.substring(Ae+1);(!xe||/\s/.test(xe))&&!V.includes(" ")&&!V.includes(`
|
|
90
|
+
`)?(k(V),I(!0)):I(!1);return}I(!1)},[]),Y=Oe.useCallback(G=>{w(ke=>({...ke,execution:{...ke.execution,prompt:G}}))},[]),le=Oe.useCallback(G=>{const ke=g.execution.prompt,Ae=_.current?.selectionStart??ke.length,V=ke.substring(0,Ae).lastIndexOf("@"),de=G.relativePath&&G.relativePath.trim().length>0?G.relativePath.trim():G.path||G.name,Me=V!==-1?V:Ae,Le=`${ke.substring(0,Me)}@${de} ${ke.substring(Ae)}`,se=Me+de.length+2;Y(Le),I(!1),k(""),requestAnimationFrame(()=>{const ie=_.current;ie&&(ie.selectionStart=se,ie.selectionEnd=se,ie.focus()),ue(Le,se)})},[g.execution.prompt,Y,ue]),Z=Oe.useCallback(G=>{const ke=g.execution.prompt,Ae=_.current?.selectionStart??ke.length,V=ke.substring(0,Ae).lastIndexOf("@"),de=V!==-1?V:Ae,Me=`${ke.substring(0,de)}@${G} ${ke.substring(Ae)}`,Le=de+G.length+2;Y(Me),I(!1),k(""),requestAnimationFrame(()=>{const se=_.current;se&&(se.selectionStart=Le,se.selectionEnd=Le,se.focus()),ue(Me,Le)})},[g.execution.prompt,Y,ue]),Ie=Oe.useCallback(G=>{const ke=`/${G.name} `;Y(ke),N(!1),T(""),requestAnimationFrame(()=>{const Ee=_.current;Ee&&(Ee.focus(),Ee.selectionStart=Ee.value.length,Ee.selectionEnd=Ee.value.length),ue(ke,ke.length)})},[Y,ue]),Ne=Oe.useCallback(G=>{if(A&&L.current&&(G.key==="Enter"||G.key==="ArrowUp"||G.key==="ArrowDown"||G.key==="Escape"||G.key==="Tab")){G.preventDefault(),L.current.handleKeyDown(G.key);return}C&&O.current&&(G.key==="Enter"||G.key==="ArrowUp"||G.key==="ArrowDown"||G.key==="Escape"||G.key==="Tab")&&(G.preventDefault(),O.current.handleKeyDown(G.key))},[A,C]),X=Oe.useCallback(async()=>{const G=Q6(g,i);if(G){q.error(G);return}const ke=J6(g.schedule.times),Ee={...g.id?{id:g.id}:{},name:g.name.trim(),enabled:g.enabled,schedule:{kind:g.schedule.kind,timezone:g.schedule.timezone.trim(),...g.schedule.kind==="once"?{date:g.schedule.onceDate,time:g.schedule.onceTime}:{times:ke,...g.schedule.kind==="weekly"?{weekdays:g.schedule.weekdays}:{}}},execution:{prompt:g.execution.prompt,providerID:g.execution.providerID,modelID:g.execution.modelID,...g.execution.variant.trim()?{variant:g.execution.variant.trim()}:{},...g.execution.agent.trim()?{agent:g.execution.agent.trim()}:{}},...g.state?{state:g.state}:{}};S(!0);try{await a(Ee),r(!1)}catch(Ae){q.error(Ae instanceof Error?Ae.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{S(!1)}},[g,r,a,i]),he=Oe.useId(),je=Oe.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),be=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),fe=i("sessions.scheduledTasks.editor.description"),Pe=s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ir,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(Bt,{id:"sched-name",value:g.name,onChange:G=>w(ke=>({...ke,name:G.target.value})),placeholder:i("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ir,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(ps,{value:g.schedule.kind,onValueChange:G=>{w(ke=>({...ke,schedule:{...ke.schedule,kind:G}}))},children:[s.jsx(hs,{className:"w-fit max-w-full",children:s.jsx(ys,{children:G=>i(G==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":G==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(fs,{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")})]})]})]})]}),g.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:F,children:[s.jsx(Ir,{children:i("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:"inline-flex h-9 w-fit max-w-full items-center justify-between gap-2 rounded-md border border-border bg-background px-3 text-left hover:bg-interactive-hover",onClick:()=>j(G=>!G),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(qy,{className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:B6(g.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),o)})]}),s.jsx(ks,{className:"h-4 w-4 text-muted-foreground"})]}),P?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:()=>$(G=>af(G,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:pe,children:s.jsx(Wi,{className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(o,{month:"long",year:"numeric"}).format(M)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>$(G=>af(G,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx($n,{className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:we.map((G,ke)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:G},`${G}-${ke}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:_6(M,oe).map(({date:G,inCurrentMonth:ke})=>{const Ee=rf(G),Ae=Ee===g.schedule.onceDate,xe=uf(G,te),V=G.getTime()<te.getTime(),de=Ae?"bg-interactive-selection text-interactive-selection-foreground":V?"text-muted-foreground/40":ke?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{V||(W(Ee),j(!1))},disabled:V,className:["h-8 rounded-md typography-ui-label",de,xe&&!Ae?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",V?"cursor-not-allowed opacity-45":""].join(" "),children:G.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:Se||""}),s.jsx(ve,{type:"button",size:"xs",variant:"ghost",onClick:()=>{W(rf(te)),$(new Date(te.getFullYear(),te.getMonth(),1))},children:i("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Ir,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(cf,{value:g.schedule.onceTime,use24Hour:re,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:G=>w(ke=>({...ke,schedule:{...ke.schedule,onceTime:G}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(Ir,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(ps,{value:g.schedule.timezone,onValueChange:G=>{w(ke=>({...ke,schedule:{...ke.schedule,timezone:G}}))},children:[s.jsx(hs,{className:"w-fit max-w-full",children:s.jsx(ys,{})}),s.jsx(fs,{children:sf.map(G=>s.jsx(Rt,{value:G,children:G},G))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[g.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(Ir,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:ee.map(G=>{const ke=g.schedule.weekdays.includes(G.value);return s.jsxs("button",{type:"button",onClick:()=>E(G.value,!ke),className:["inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",ke?"text-foreground":"text-muted-foreground","hover:text-foreground"].join(" "),children:[s.jsx(bs,{checked:ke,onChange:Ee=>E(G.value,Ee),ariaLabel:G.label}),s.jsx("span",{children:G.label})]},G.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(Ir,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:g.schedule.times.map((G,ke)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(cf,{value:G,use24Hour:re,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=>z(ke,Ee)}),g.schedule.times.length>1?s.jsx(ve,{type:"button",size:"icon",variant:"ghost",onClick:()=>J(ke),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(Is,{className:"h-4 w-4"})}):null]},ke))}),s.jsx("div",{children:s.jsxs(ve,{type:"button",size:"sm",variant:"outline",onClick:H,children:[s.jsx(zs,{className:"mr-1 h-4 w-4"})," ",i("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ir,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(ps,{value:g.schedule.timezone,onValueChange:G=>{w(ke=>({...ke,schedule:{...ke.schedule,timezone:G}}))},children:[s.jsx(hs,{className:"w-fit max-w-full",children:s.jsx(ys,{})}),s.jsx(fs,{children:sf.map(G=>s.jsx(Rt,{value:G,children:G},G))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Ir,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(qo,{providerId:g.execution.providerID,modelId:g.execution.modelID,onChange:(G,ke)=>{w(Ee=>({...Ee,execution:{...Ee.execution,providerID:G,modelID:ke,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Ir,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(ps,{value:ne,disabled:!ge,onValueChange:G=>{w(ke=>({...ke,execution:{...ke.execution,variant:G==="__default"?"":G}}))},children:[s.jsx(hs,{className:"w-fit max-w-full",children:s.jsx(ys,{children:G=>G==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):G})}),s.jsxs(fs,{children:[s.jsx(Rt,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),ae.map(G=>s.jsx(Rt,{value:G,children:G},G))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Ir,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Sc,{agentName:g.execution.agent,filter:G=>fg(G.mode),onChange:G=>w(ke=>({...ke,execution:{...ke.execution,agent:G}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ir,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(An,{id:"sched-prompt",ref:_,value:g.execution.prompt,onChange:G=>{const ke=G.target.value;Y(ke);const Ee=G.target.selectionStart??ke.length;ue(ke,Ee)},onKeyDown:Ne,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),A?s.jsx(Tg,{ref:L,searchQuery:D,onCommandSelect:Ie,onClose:()=>N(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,C?s.jsx(Mg,{ref:O,searchQuery:R,onFileSelect:le,onAgentSelect:Z,onClose:()=>I(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),Be=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(bs,{checked:g.enabled,onChange:G=>w(ke=>({...ke,enabled:G})),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(ve,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:v,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(ve,{type:"button",size:"sm",onClick:X,disabled:v,children:i(v?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return x?s.jsx(Vr,{open:e,title:be,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:G=>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:be}),G]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:fe})]}),footer:Be,children:Pe}):s.jsx(ws,{open:e,onOpenChange:G=>{!G&&je()||r(G)},children:s.jsxs(vs,{"aria-describedby":he,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Fs,{id:he,className:"sr-only",children:fe}),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(js,{className:"typography-ui-label font-medium text-foreground",children:be}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:fe})]})}),s.jsx(zo,{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:Pe})}),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:Be})})]})})}function X6(t){return no(t,{min:0,max:23})}function Z6(t,e){return no(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function eP(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 tP=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))},sP=(t,e)=>{const n=tP(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||""})},nP=t=>!t||!Number.isFinite(t)?"":new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),pf=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),a=6e4,i=60*a,o=24*i,c=n>=0;if(r<a)return e(c?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<i){const u=Math.round(r/a);return c?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:u}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:u})}if(r<o){const u=Math.floor(r/i),f=Math.round(r%i/a),y=f>0?`${u}h ${f}m`:`${u}h`;return c?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:y}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:y})}const d=Math.floor(r/o),p=Math.round(r%o/i),m=p>0?`${d}d ${p}h`:`${d}d`;return c?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:m}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:m})},rP={success:{tone:"success",Icon:wu},error:{tone:"error",Icon:Qr},running:{tone:"warning",Icon:ts,spin:!0},idle:{tone:"muted",Icon:ig}},aP=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function iP(){const{t}=ut(),e=De(T=>T.isScheduledTasksDialogOpen),n=De(T=>T.setScheduledTasksDialogOpen),r=De(T=>T.isMobile),a=Es(T=>T.projects),i=Es(T=>T.getActiveProject()),o=qs(T=>T.homeDirectory),{currentTheme:c}=Er(),[d,p]=Oe.useState(""),[m,u]=Oe.useState([]),[f,y]=Oe.useState(!0),[h,b]=Oe.useState(!1),[x,g]=Oe.useState(null),[w,v]=Oe.useState(null),S=Oe.useMemo(()=>a.find(T=>T.id===d)||null,[a,d]),P=Oe.useCallback(T=>{const M=T.label?.trim()||ii(T.path,o||void 0),$=Ho({id:T.id,iconImage:T.iconImage??null},{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),F=T.icon?jc[T.icon]:null,_=T.color?Go[T.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:T.iconBackground?{backgroundColor:T.iconBackground}:void 0,children:s.jsx("img",{src:$,alt:"",className:"h-full w-full object-contain",draggable:!1})}):F?s.jsx(F,{className:"h-3.5 w-3.5 shrink-0",style:_?{color:_}:void 0}):s.jsx(Un,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:_?{color:_}:void 0}),s.jsx("span",{className:"truncate",children:M})]})},[o,c.metadata.variant,c.colors.surface.foreground]),j=Oe.useCallback(async(T,M)=>{if(!T){u([]);return}M?.silent||y(!0);try{const $=await O6(T);$.sort((F,_)=>{if(F.enabled!==_.enabled)return F.enabled?-1:1;const O=F.name.localeCompare(_.name);return O!==0?O:(F.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(_.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),u($)}catch($){q.error($ instanceof Error?$.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),M?.silent||u([])}finally{M?.silent||y(!1)}},[t]);Oe.useEffect(()=>{if(!e)return;const T=i?.id||a[0]?.id||"";p(T),T?j(T):(u([]),y(!1))},[e,i,a,j]),Oe.useEffect(()=>{if(!e)return;let T=null;const M=Xx($=>{$.type==="scheduled-task-ran"&&$.projectId===d&&(T&&clearTimeout(T),T=setTimeout(()=>{j(d,{silent:!0})},400))});return()=>{T&&clearTimeout(T),M()}},[e,d,j]);const C=Oe.useCallback(async T=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await tf(d,T),await j(d),q.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,j,t]),I=Oe.useCallback(async(T,M)=>{if(d){v(T.id),u($=>$.map(F=>F.id===T.id?{...F,enabled:M}:F));try{await tf(d,{...T,enabled:M}),await j(d,{silent:!0})}catch($){q.error($ instanceof Error?$.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await j(d,{silent:!0})}finally{v(null)}}},[d,j,t]),R=Oe.useCallback(async T=>{if(!(!d||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:T.name})))){v(T.id);try{await L6(d,T.id),await j(d,{silent:!0}),q.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch($){q.error($ instanceof Error?$.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{v(null)}}},[d,j,t]),k=Oe.useCallback(async T=>{if(d){v(T.id);try{await $6(d,T.id),await Promise.all([j(d,{silent:!0}),Vd()]),q.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(M){q.error(M instanceof Error?M.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{v(null)}}},[d,j,t]),A=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(ps,{value:d||"__none",onValueChange:T=>{const M=T==="__none"?"":T;p(M),M?j(M):u([])},children:[s.jsx(hs,{className:r?"w-full":void 0,children:S?s.jsx(ys,{children:P(S)}):s.jsx(ys,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(fs,{children:[a.length===0?s.jsx(Rt,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,a.map(T=>s.jsx(Rt,{value:T.id,children:P(T)},T.id))]})]})]}),N=()=>{g(null),b(!0)},D=s.jsxs("div",{className:"space-y-4",children:[r?A:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[A,s.jsxs(ve,{onClick:N,disabled:!d,children:[s.jsx(zs,{className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})]}),s.jsx("div",{className:"min-h-[280px]",children:f?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(ts,{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(T=>{const M=w===T.id,$=T.state?.lastStatus||"idle",F=rP[$],_=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=T.state?.nextRunAt,L=T.state?.lastRunAt;return s.jsxs("div",{className:me("rounded-lg border border-border p-4 transition-opacity",!T.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:T.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:sP(T,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(Dd,{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:pf(O,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:nP(O)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx($f,{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(ts,{className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):L?s.jsxs(s.Fragment,{children:[F.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${F.tone})`},children:[s.jsx(F.Icon,{className:"h-3.5 w-3.5"}),_]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:pf(L,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),T.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:aP("error"),children:[s.jsx(Qr,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:T.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:me("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",T.enabled?"text-foreground":"text-muted-foreground",M&&"cursor-not-allowed opacity-50"),children:[s.jsx(bs,{checked:T.enabled,onChange:K=>{I(T,K)},ariaLabel:T.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:T.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:T.name}),disabled:M}),T.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(ve,{variant:"outline",size:"sm",onClick:()=>{k(T)},disabled:M,children:[s.jsx(Gr,{className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>{g(T),b(!0)},disabled:M,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:T.name}),children:[s.jsx(Qy,{className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(ve,{variant:"destructive",size:"sm",onClick:()=>{R(T)},disabled:M,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:T.name}),children:s.jsx(an,{className:"h-4 w-4"})})]})]})]},T.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Vr,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:T=>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")}),T]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(ve,{className:"w-full",onClick:N,disabled:!d,children:[s.jsx(zs,{className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:D}):s.jsx(ws,{open:e,onOpenChange:n,children:s.jsxs(vs,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(Fs,{children:t("sessions.scheduledTasks.dialog.description")})]}),D]})}),s.jsx(Y6,{open:h,task:x,onOpenChange:b,onSave:C})]})}const oP=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(c=>Ns(c.path)??c.path).filter(c=>!!c)]),i=(c=>c.filter(d=>Eo(d,t.normalizedPath,r)))(e.archivedSessions),o=e.sessions.filter(c=>c.time?.archived||Ns(c.directory??null)?!1:Eo(c,t.normalizedPath,r));return Yi([...i,...o])},lP=t=>{const e=nt.c(12),{normalizedProjects:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:o,isSessionsLoading:c,foldersMap:d,createFolder:p,addSessionToFolder:m,cleanupSessions:u}=t;let f,y;e[0]!==m||e[1]!==a||e[2]!==i||e[3]!==u||e[4]!==p||e[5]!==d||e[6]!==c||e[7]!==o||e[8]!==n||e[9]!==r?(f=()=>{c||n.forEach(h=>{const b=Ku(h.normalizedPath),x=oP(h,{sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:o}),g=new Set(x.map(cP)),w=d[b]??[],v=new Map(w.map(dP));x.forEach(S=>{const P=Y1(S,h.normalizedPath),j=P.toLowerCase();let C=v.get(j);C||(C=p(b,P),v.set(j,C)),C.sessionIds.includes(S.id)||m(b,C.id,S.id)}),u(b,g)})},y=[n,r,a,i,o,c,d,p,m,u],e[0]=m,e[1]=a,e[2]=i,e[3]=u,e[4]=p,e[5]=d,e[6]=c,e[7]=o,e[8]=n,e[9]=r,e[10]=f,e[11]=y):(f=e[10],y=e[11]),l.useEffect(f,y)};function cP(t){return t.id}function dP(t){return[t.name.toLowerCase(),t]}const uP=t=>{const e=nt.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:a,availableWorktreesByProject:i,projectRepoStatus:o,projectRootBranches:c,lastRepoStatus:d,buildGroupedSessions:p,hasSessionSearchQuery:m,normalizedSessionSearchQuery:u,filterSessionNodesForSearch:f,buildGroupSearchText:y,foldersMap:h}=t;let b;if(e[0]!==i||e[1]!==p||e[2]!==a||e[3]!==r||e[4]!==d||e[5]!==n||e[6]!==o||e[7]!==c){let k;e[9]!==i||e[10]!==p||e[11]!==a||e[12]!==r||e[13]!==d||e[14]!==o||e[15]!==c?(k=A=>{const N=Yi([...r(A),...a(A)]),D=i.get(A.normalizedPath)??[],T=o.has(A.id)?!!o.get(A.id):d,M=p(N,A.normalizedPath,D,c.get(A.id)??null,T);return{project:A,groups:M}},e[9]=i,e[10]=p,e[11]=a,e[12]=r,e[13]=d,e[14]=o,e[15]=c,e[16]=k):k=e[16],b=n.map(k),e[0]=i,e[1]=p,e[2]=a,e[3]=r,e[4]=d,e[5]=n,e[6]=o,e[7]=c,e[8]=b}else b=e[8];const x=b,g=x;let w;if(e[17]!==y||e[18]!==f||e[19]!==h||e[20]!==m||e[21]!==u||e[22]!==g){e:{const k=new WeakMap;if(!m){w=k;break e}const A=N=>N.reduce((D,T)=>D+1+A(T.children),0);g.forEach(N=>{N.groups.forEach(D=>{const T=f(D.sessions,u),M=A(T),$=y(D).includes(u),F=Ns(D.directory??null),O=(F?h[F]??[]:[]).filter(L=>L.name.toLowerCase().includes(u)).length;k.set(D,{filteredNodes:T,matchedSessionCount:M,folderNameMatchCount:O,groupMatches:$,hasMatch:$||M>0||O>0})})}),w=k}e[17]=y,e[18]=f,e[19]=h,e[20]=m,e[21]=u,e[22]=g,e[23]=w}else w=e[23];const v=w;let S;e:{if(!m){S=g;break e}let k;if(e[24]!==v||e[25]!==g){let A;e[27]!==v?(A=N=>({...N,groups:N.groups.filter(D=>v.get(D)?.hasMatch===!0)}),e[27]=v,e[28]=A):A=e[28],k=g.map(A).filter(mP),e[24]=v,e[25]=g,e[26]=k}else k=e[26];S=k}const P=S,j=m?P:g;let C;e:{if(!m){C=0;break e}let k;if(e[29]!==v||e[30]!==j){let A;e[32]!==v?(A=(N,D)=>N+D.groups.reduce((T,M)=>{const $=v.get(M);if(!$)return T;const F=$.folderNameMatchCount+($.groupMatches?1:0);return T+$.matchedSessionCount+F},0),e[32]=v,e[33]=A):A=e[33],k=j.reduce(A,0),e[29]=v,e[30]=j,e[31]=k}else k=e[31];C=k}const I=C;let R;return e[34]!==v||e[35]!==x||e[36]!==I||e[37]!==P||e[38]!==j||e[39]!==g?(R={projectSections:x,visibleProjectSections:g,groupSearchDataByGroup:v,searchableProjectSections:P,sectionsForRender:j,searchMatchCount:I},e[34]=v,e[35]=x,e[36]=I,e[37]=P,e[38]=j,e[39]=g,e[40]=R):R=e[40],R};function mP(t){return t.groups.length>0}const pP=t=>{const e=nt.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:a,setActiveSessionByProject:i,currentSessionId:o,handleSessionSelect:c,newSessionDraftOpen:d,mobileVariant:p,openNewSessionDraft:m,setActiveMainTab:u,setSessionSwitcherOpen:f,sessions:y,worktreeMetadata:h}=t;let b,x;if(e[0]!==n){x=new Map,b=new Map;const A=(N,D,T,M)=>{x.has(N)||x.set(N,new Map);const $=x.get(N);M.forEach(F=>{const _=Ns(F.worktree?.path??F.session.directory??T??D);$.set(F.session.id,{directory:_}),b.has(N)||b.set(N,{id:F.session.id,directory:_}),F.children.length>0&&A(N,D,_,F.children)})};n.forEach(N=>{N.groups.forEach(D=>{A(N.project.id,N.project.normalizedPath,D.directory,D.sessions)})}),e[0]=n,e[1]=b,e[2]=x}else b=e[1],x=e[2];let g;e[3]!==b||e[4]!==x?(g={metaByProject:x,firstSessionByProject:b},e[3]=b,e[4]=x,e[5]=g):g=e[5];const w=g,v=l.useRef(null);let S,P;e[6]!==r||e[7]!==a||e[8]!==o||e[9]!==c||e[10]!==p||e[11]!==d||e[12]!==m||e[13]!==n||e[14]!==w||e[15]!==u||e[16]!==i||e[17]!==f?(S=()=>{if(!r||d||v.current===r)return;const A=n.find(_=>_.project.id===r);if(!A)return;v.current=r;const N=w.metaByProject.get(r);if(o&&N&&N.has(o)){i(_=>{if(_.get(r)===o)return _;const O=new Map(_);return O.set(r,o),O});return}if(!N||N.size===0){u("chat"),p&&f(!1),m({directoryOverride:A.project.normalizedPath});return}const D=a.get(r),T=D&&N.has(D)?D:null,M=w.firstSessionByProject.get(r)?.id??null,$=T??M;if(!$||$===o)return;const F=N.get($)?.directory??null;c($,F,!1,r)},P=[r,a,o,c,d,p,m,n,w,u,f,i],e[6]=r,e[7]=a,e[8]=o,e[9]=c,e[10]=p,e[11]=d,e[12]=m,e[13]=n,e[14]=w,e[15]=u,e[16]=i,e[17]=f,e[18]=S,e[19]=P):(S=e[18],P=e[19]),l.useLayoutEffect(S,P);let j,C;e[20]!==r||e[21]!==o||e[22]!==w||e[23]!==i?(j=()=>{if(!r||!o)return;const A=w.metaByProject.get(r);!A||!A.has(o)||i(N=>{if(N.get(r)===o)return N;const D=new Map(N);return D.set(r,o),D})},C=[r,o,w,i],e[20]=r,e[21]=o,e[22]=w,e[23]=i,e[24]=j,e[25]=C):(j=e[24],C=e[25]),l.useEffect(j,C);let I;if(e[26]!==o||e[27]!==y||e[28]!==h){e:{if(!o){I=null;break e}const A=h.get(o)?.path;if(A){I=Ns(A)??A;break e}let N;e[30]!==o?(N=T=>T.id===o,e[30]=o,e[31]=N):N=e[31];const D=y.find(N);if(!D){I=null;break e}I=Ns(D.directory??null)}e[26]=o,e[27]=y,e[28]=h,e[29]=I}else I=e[29];const R=I;let k;return e[32]!==R?(k={currentSessionDirectory:R},e[32]=R,e[33]=k):k=e[33],k},hP=t=>{const e=nt.c(4);let n;e[0]!==t?(n=(i,o)=>{const c=t.get(i);if(!c||c.length===0)return o;const d=new Map(o.map(fP)),p=[];return c.forEach(m=>{const u=d.get(m);u&&(p.push(u),d.delete(m))}),o.forEach(m=>{d.has(m.id)&&p.push(m)}),p},e[0]=t,e[1]=n):n=e[1];const r=n;let a;return e[2]!==r?(a={getOrderedGroups:r},e[2]=r,e[3]=a):a=e[3],a};function fP(t){return[t.id,t]}const yl=t=>!!t.time?.archived,gP=t=>{const{t:e}=ut(),n=l.useCallback(o=>[o.label,o.branch??"",o.description??"",o.directory??""].join(" ").toLowerCase(),[]),r=l.useCallback(o=>{const c=Ns(o.directory??null)??"";return`${(o.title||e("sessions.sidebar.session.untitled")).trim()} ${c}`.toLowerCase()},[e]),a=l.useCallback((o,c)=>c?o.flatMap(d=>{if(r(d.session).includes(c))return[d];const m=a(d.children,c);return m.length===0?[]:[{...d,children:m}]}):o,[r]),i=l.useCallback((o,c,d,p,m)=>{const u=Ns(c??null),f=Yi(o).sort((A,N)=>Bi(A,N,t.pinnedSessionIds)),y=new Map(f.map(A=>[A.id,A])),h=new Map;f.forEach(A=>{const N=A.parentID;if(!N)return;const D=y.get(N);if(!D||yl(D)!==yl(A))return;const T=h.get(N)??[];T.push(A),h.set(N,T)}),h.forEach(A=>A.sort((N,D)=>Bi(N,D,t.pinnedSessionIds)));const b=new Map;d.forEach(A=>{if(A.path){const N=Ns(A.path)??A.path;b.set(N,A)}});const x=A=>{const N=Ns(A.directory??null),D=t.worktreeMetadata.get(A.id)??null;if(D)return D;if(N){const T=b.get(N)??null;if(T&&N!==u)return T}return null},g=A=>{const N=h.get(A.id)??[];return{session:A,children:N.map(D=>g(D)),worktree:x(A)}},w=f.filter(A=>{const N=A.parentID;if(!N)return!0;const D=y.get(N);return D?yl(D)!==yl(A):!0}),v=new Map,S="__archived__",P=A=>{if(A.time?.archived)return S;const N=Ns(t.worktreeMetadata.get(A.id)?.path??null),D=Ns(A.directory??null);if(!N&&!D)return S;const T=Ns(A.project?.worktree??null),M=N??D??T;return M?M!==u&&b.has(M)?M:M===u?u??"__project_root__":S:S};w.forEach(A=>{const N=g(A),D=P(A);v.has(D)||v.set(D,[]),v.get(D)?.push(N)});const j=u??"__project_root__",C=[{id:"root",label:m&&p&&p!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:p}):e("sessions.sidebar.grouping.projectRoot"),branch:p??null,description:u?Ro(u,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:u,folderScopeKey:u,sessions:v.get(j)??[]}],I=new Map;d.forEach(A=>{const N=Ns(A.path)??A.path,D=v.get(N)??[],T=D.length>0,M=D.reduce(($,F)=>{const _=Number(F.session.time?.updated??F.session.time?.created??0);return Number.isFinite(_)?Math.max($,_):$},0);I.set(N,{hasActiveSession:T,lastUpdatedAt:M})}),[...d].sort((A,N)=>{const D=Ns(A.path)??A.path,T=Ns(N.path)??N.path,M=I.get(D)??{hasActiveSession:!1,lastUpdatedAt:0},$=I.get(T)??{hasActiveSession:!1,lastUpdatedAt:0};if(M.hasActiveSession!==$.hasActiveSession)return M.hasActiveSession?-1:1;if(M.hasActiveSession&&$.hasActiveSession)return $.lastUpdatedAt-M.lastUpdatedAt;const F=(A.label||A.branch||A.name||A.path||"").toLowerCase(),_=(N.label||N.branch||N.name||N.path||"").toLowerCase();return F.localeCompare(_)}).forEach(A=>{const N=Ns(A.path)??A.path,D=t.gitBranches.get(N)?.trim()||null,T=A.branch?.trim()||null,$=!!(D&&T&&A.label&&Bm(A.label)===Bm(T))?D:A.label||A.name||ii(N,t.homeDirectory)||N;C.push({id:`worktree:${N}`,label:$,branch:D||T,description:Ro(N,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:A,directory:N,folderScopeKey:N,sessions:v.get(N)??[]})});const k=v.get(S)??[];return k.length>0&&C.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?Ku(u):null,sessions:k}),C},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:a,buildGroupedSessions:i}},xP=t=>{const e=nt.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:a,sessionSearchContainerRef:i}=t;let o,c;e[0]!==n||e[1]!==a?(o=()=>{if(!n||typeof window>"u")return;const m=window.requestAnimationFrame(()=>{a.current?.focus(),a.current?.select()});return()=>window.cancelAnimationFrame(m)},c=[n,a],e[0]=n,e[1]=a,e[2]=o,e[3]=c):(o=e[2],c=e[3]),l.useEffect(o,c);let d,p;e[4]!==n||e[5]!==i||e[6]!==r?(d=()=>{if(!n||typeof document>"u")return;const m=u=>{i.current&&(i.current.contains(u.target)||r(!1))};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},p=[n,r,i],e[4]=n,e[5]=i,e[6]=r,e[7]=d,e[8]=p):(d=e[7],p=e[8]),l.useEffect(d,p)},bP=t=>{const e=nt.c(42),{t:n}=ut(),[r,a]=l.useState(null),i=l.useRef(null);let o,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>()=>{i.current&&clearTimeout(i.current)},c=[],e[0]=o,e[1]=c):(o=e[0],c=e[1]),l.useEffect(o,c);let d;e[2]!==t?(d=(M,$,F,_)=>{if(F)return;const O=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(_&&_!==t.activeProjectId&&t.setActiveProjectIdOnly(_),$&&$!==t.currentDirectory&&t.setDirectory($,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),M===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(M),O();return}t.setCurrentSession(M,$??null),t.onSessionSelected?.(M),O()},e[2]=t,e[3]=d):d=e[3];const p=d;let m;e[4]!==t?(m=()=>{t.setActiveMainTab("chat")},e[4]=t,e[5]=m):m=e[5];const u=m;let f;e[6]!==t?(f=async()=>{t.editingId&&t.editTitle.trim()&&(await t.updateSessionTitle(t.editingId,t.editTitle.trim()),t.setEditingId(null),t.setEditTitle(""))},e[6]=t,e[7]=f):f=e[7];const y=f;let h;e[8]!==t?(h=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=h):h=e[9];const b=h;let x;e[10]!==t||e[11]!==n?(x=async M=>{const $=await t.shareSession(M.id);$&&$.share?.url?q.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):q.error(n("sessions.sidebar.session.share.error"))},e[10]=t,e[11]=n,e[12]=x):x=e[12];const g=x;let w;e[13]!==n?(w=(M,$)=>{Wn(M).then(F=>{if(!F.ok){q.error(n("sessions.sidebar.session.share.copyUrlError"));return}a($),i.current&&clearTimeout(i.current),i.current=window.setTimeout(()=>{a(null),i.current=null},2e3)}).catch(()=>{q.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=w):w=e[14];const v=w;let S;e[15]!==t||e[16]!==n?(S=async M=>{await t.unshareSession(M)?q.success(n("sessions.sidebar.session.unshare.success")):q.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=S):S=e[17];const P=S;let j;e[18]!==t.childrenMap?(j=M=>{const $=[],F=_=>{(t.childrenMap.get(_)??[]).forEach(L=>{$.push(L),F(L.id)})};return F(M),$},e[18]=t.childrenMap,e[19]=j):j=e[19];const C=j;let I;e[20]!==t||e[21]!==C||e[22]!==n?(I=async(M,$)=>{const F=C(M.id),_=$?.archivedBucket===!0;if(F.length===0){(_?await t.deleteSession(M.id):await t.archiveSession(M.id))?q.success(n(_?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):q.error(n(_?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const O=[M.id,...F.map(yP)];if(_){const{deletedIds:B,failedIds:re}=await t.deleteSessions(O);B.length>0&&q.success(B.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:B.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:B.length})),re.length>0&&q.error(re.length===1?n("sessions.sidebar.bulkActions.failedDeleteSingle",{count:re.length}):n("sessions.sidebar.bulkActions.failedDeletePlural",{count:re.length}));return}const{archivedIds:L,failedIds:K}=await t.archiveSessions(O);L.length>0&&q.success(L.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:L.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:L.length})),K.length>0&&q.error(K.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:K.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:K.length}))},e[20]=t,e[21]=C,e[22]=n,e[23]=I):I=e[23];const R=I;let k;e[24]!==t||e[25]!==C||e[26]!==R?(k=(M,$)=>{const F=C(M.id);if(!t.showDeletionDialog){R(M,$);return}t.setDeleteSessionConfirm({session:M,descendantCount:F.length,archivedBucket:$?.archivedBucket===!0})},e[24]=t,e[25]=C,e[26]=R,e[27]=k):k=e[27];const A=k;let N;e[28]!==t||e[29]!==R?(N=async()=>{if(!t.deleteSessionConfirm)return;const{session:M,archivedBucket:$}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await R(M,{archivedBucket:$})},e[28]=t,e[29]=R,e[30]=N):N=e[30];const D=N;let T;return e[31]!==D||e[32]!==r||e[33]!==b||e[34]!==v||e[35]!==A||e[36]!==y||e[37]!==u||e[38]!==p||e[39]!==g||e[40]!==P?(T={copiedSessionId:r,handleSessionSelect:p,handleSessionDoubleClick:u,handleSaveEdit:y,handleCancelEdit:b,handleShareSession:g,handleCopyShareUrl:v,handleUnshareSession:P,handleDeleteSession:A,confirmDeleteSession:D},e[31]=D,e[32]=r,e[33]=b,e[34]=v,e[35]=A,e[36]=y,e[37]=u,e[38]=p,e[39]=g,e[40]=P,e[41]=T):T=e[41],T};function yP(t){return t.id}const vP=t=>{const e=nt.c(41),{isVSCode:n,hasLoadedGlobalSessions:r,safeStorage:a,keys:i,sessions:o,pinnedSessionIds:c,setPinnedSessionIds:d,groupOrderByProject:p,activeSessionByProject:m,collapsedGroups:u,setExpandedParents:f,setCollapsedProjects:y}=t,h=l.useRef(null),b=l.useRef(null);let x;e[0]!==n?(x=()=>{if(n)return;const O=b.current;if(b.current=null,h.current=null,!O)return;const{projects:L}=Es.getState(),K=L.map(B=>({...B,sidebarCollapsed:O.has(B.id)}));As({projects:K}).catch(wP)},e[0]=n,e[1]=x):x=e[1];const g=x;let w;e[2]!==g||e[3]!==n?(w=O=>{typeof window>"u"||n||(b.current=O,h.current!==null&&window.clearTimeout(h.current),h.current=window.setTimeout(()=>{g()},700))},e[2]=g,e[3]=n,e[4]=w):w=e[4];const v=w;let S,P;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=()=>()=>{typeof window<"u"&&h.current!==null&&window.clearTimeout(h.current),h.current=null,b.current=null},P=[],e[5]=S,e[6]=P):(S=e[5],P=e[6]),l.useEffect(S,P);let j,C;e[7]!==i.projectCollapse||e[8]!==i.sessionExpanded||e[9]!==a||e[10]!==y||e[11]!==f?(j=()=>{try{const O=a.getItem(i.sessionExpanded);if(O){const K=JSON.parse(O);Array.isArray(K)&&f(new Set(K.filter(jP)))}const L=a.getItem(i.projectCollapse);if(L){const K=JSON.parse(L);Array.isArray(K)&&y(new Set(K.filter(NP)))}}catch{}},C=[i.projectCollapse,i.sessionExpanded,a,y,f],e[7]=i.projectCollapse,e[8]=i.sessionExpanded,e[9]=a,e[10]=y,e[11]=f,e[12]=j,e[13]=C):(j=e[12],C=e[13]),l.useEffect(j,C);let I,R;e[14]!==r||e[15]!==o||e[16]!==d?(I=()=>{if(!r)return;const O=new Set(o.map(SP));d(L=>{let K=!1;const B=new Set;return L.forEach(re=>{O.has(re)?B.add(re):K=!0}),K?B:L})},R=[r,o,d],e[14]=r,e[15]=o,e[16]=d,e[17]=I,e[18]=R):(I=e[17],R=e[18]),l.useEffect(I,R);let k,A;e[19]!==i.sessionPinned||e[20]!==c||e[21]!==a?(k=()=>{try{a.setItem(i.sessionPinned,JSON.stringify(Array.from(c)))}catch{}},A=[i.sessionPinned,c,a],e[19]=i.sessionPinned,e[20]=c,e[21]=a,e[22]=k,e[23]=A):(k=e[22],A=e[23]),l.useEffect(k,A);let N,D;e[24]!==p||e[25]!==i.groupOrder||e[26]!==a?(N=()=>{try{const O=Object.fromEntries(p.entries());a.setItem(i.groupOrder,JSON.stringify(O))}catch{}},D=[p,i.groupOrder,a],e[24]=p,e[25]=i.groupOrder,e[26]=a,e[27]=N,e[28]=D):(N=e[27],D=e[28]),l.useEffect(N,D);let T,M;e[29]!==m||e[30]!==i.projectActiveSession||e[31]!==a?(T=()=>{try{const O=Object.fromEntries(m.entries());a.setItem(i.projectActiveSession,JSON.stringify(O))}catch{}},M=[m,i.projectActiveSession,a],e[29]=m,e[30]=i.projectActiveSession,e[31]=a,e[32]=T,e[33]=M):(T=e[32],M=e[33]),l.useEffect(T,M);let $,F;e[34]!==u||e[35]!==i.groupCollapse||e[36]!==a?($=()=>{try{a.setItem(i.groupCollapse,JSON.stringify(Array.from(u)))}catch{}},F=[u,i.groupCollapse,a],e[34]=u,e[35]=i.groupCollapse,e[36]=a,e[37]=$,e[38]=F):($=e[37],F=e[38]),l.useEffect($,F);let _;return e[39]!==v?(_={scheduleCollapsedProjectsPersist:v},e[39]=v,e[40]=_):_=e[40],_};function wP(){}function jP(t){return typeof t=="string"}function NP(t){return typeof t=="string"}function SP(t){return t.id}const kP=async(t,e,n)=>{if(t.length===0)return[];const r=Math.max(1,Math.min(e,t.length)),a=new Array(t.length);let i=0;const o=async()=>{for(;;){const c=i;if(i+=1,c>=t.length)return;a[c]=await n(t[c])}};return await Promise.all(Array.from({length:r},()=>o())),a},CP=t=>{const e=nt.c(23),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:a,setProjectRootBranches:i}=t,{git:o}=Yn(),c=pn(IP);let d,p;e[0]!==c||e[1]!==o||e[2]!==n||e[3]!==a?(d=()=>{if(!o||n.length===0){a(new Map);return}n.forEach(x=>{c(x.normalizedPath,o)})},p=[n,o,c,a],e[0]=c,e[1]=o,e[2]=n,e[3]=a,e[4]=d,e[5]=p):(d=e[4],p=e[5]),l.useEffect(d,p);let m,u;e[6]!==r||e[7]!==n||e[8]!==a?(m=()=>{const x=new Map;n.forEach(g=>{x.set(g.id,r.get(g.normalizedPath)?.isGitRepo??null)}),a(x)},u=[n,r,a],e[6]=r,e[7]=n,e[8]=a,e[9]=m,e[10]=u):(m=e[9],u=e[10]),l.useEffect(m,u);let f;if(e[11]!==r||e[12]!==n){let x;e[14]!==r?(x=g=>{const w=r.get(g.normalizedPath)?.branch??"";return`${g.id}:${w}`},e[14]=r,e[15]=x):x=e[15],f=n.map(x).join("|"),e[11]=r,e[12]=n,e[13]=f}else f=e[13];const y=f;let h;e[16]!==n||e[17]!==i?(h=()=>{let x=!1;return(async()=>{const w=await kP(n,2,PP);x||i(v=>{const S=new Map(v);return w.forEach(P=>{const{id:j,branch:C}=P;C&&S.set(j,C)}),S})})(),()=>{x=!0}},e[16]=n,e[17]=i,e[18]=h):h=e[18];let b;e[19]!==n||e[20]!==y||e[21]!==i?(b=[n,y,i],e[19]=n,e[20]=y,e[21]=i,e[22]=b):b=e[22],l.useEffect(h,b)};function IP(t){return t.ensureStatus}function AP(){return null}async function PP(t){const e=await Uo(t.normalizedPath).catch(AP);return{id:t.id,branch:e}}const DP=t=>{const e=nt.c(14),{isVSCode:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i}=t;let o;e[0]!==r?(o=new Map,r.forEach(y=>{const h=Ns(y.directory??null)??Ns(y.project?.worktree??null);if(!h)return;const b=o.get(h)??[];b.push(y),o.set(h,b)}),e[0]=r,e[1]=o):o=e[1];const c=o;let d;e[2]!==i||e[3]!==n||e[4]!==c?(d=y=>{const h=n?[]:i.get(y.normalizedPath)??[],b=[y.normalizedPath,...h.map(TP).filter(MP)],x=new Set,g=[];return b.forEach(w=>{(c.get(w)??[]).forEach(S=>{x.has(S.id)||(x.add(S.id),g.push(S))})}),g},e[2]=i,e[3]=n,e[4]=c,e[5]=d):d=e[5];const p=d;let m;e[6]!==a||e[7]!==i||e[8]!==n||e[9]!==r?(m=y=>{if(n){const v=a.filter(P=>{const j=Ns(P.directory??null),C=Ns(P.project?.worktree??null);return j?j===y.normalizedPath:C===y.normalizedPath}),S=r.filter(P=>P.time?.archived||Ns(P.directory??null)?!1:Ns(P.project?.worktree??null)===y.normalizedPath);return Yi([...v,...S])}const h=n?[]:i.get(y.normalizedPath)??[],b=new Set([y.normalizedPath,...h.map(RP).filter(EP)]),g=(v=>v.filter(S=>Eo(S,y.normalizedPath,b)))(a),w=r.filter(v=>{if(v.time?.archived||Ns(v.directory??null))return!1;const P=Ns(v.project?.worktree??null);return P?P===y.normalizedPath||P.startsWith(`${y.normalizedPath}/`):!1});return Yi([...g,...w])},e[6]=a,e[7]=i,e[8]=n,e[9]=r,e[10]=m):m=e[10];const u=m;let f;return e[11]!==u||e[12]!==p?(f={getSessionsForProject:p,getArchivedSessionsForProject:u},e[11]=u,e[12]=p,e[13]=f):f=e[13],f};function TP(t){return Ns(t.path)??t.path}function MP(t){return!!t}function RP(t){return Ns(t.path)??t.path}function EP(t){return!!t}const FP=t=>{const e=nt.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:a,normalizedProjects:i,isVSCode:o,availableWorktreesByProject:c,cleanupSessions:d}=t;let p,m;e[0]!==a||e[1]!==c||e[2]!==d||e[3]!==n||e[4]!==o||e[5]!==i||e[6]!==r?(p=()=>{if(n)return;const u=new Map;r.forEach(h=>{const b=Ns(h.directory??null);if(!b)return;const x=u.get(b);if(x){x.add(h.id);return}u.set(b,new Set([h.id]))}),i.forEach(h=>{const b=Ku(h.normalizedPath),x=o?[]:c.get(h.normalizedPath)??[],g=new Set([h.normalizedPath,...x.map(OP).filter(LP)]),w=Yi([...a,...r.filter(v=>v.time?.archived||Ns(v.directory??null)?!1:Eo(v,h.normalizedPath,g))]).filter(v=>Eo(v,h.normalizedPath,g));u.set(b,new Set(w.map($P)))});const f=rr.getState().foldersMap;new Set([...Object.keys(f),...u.keys()]).forEach(h=>{d(h,u.get(h)??new Set)})},m=[a,c,d,n,o,i,r],e[0]=a,e[1]=c,e[2]=d,e[3]=n,e[4]=o,e[5]=i,e[6]=r,e[7]=p,e[8]=m):(p=e[7],m=e[8]),l.useEffect(p,m)};function OP(t){return Ns(t.path)??t.path}function LP(t){return!!t}function $P(t){return t.id}const BP=t=>{const e=nt.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:a}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[o,c]=l.useState(i);let d;e[1]!==n||e[2]!==a?(d=()=>{if(!n)return;const m=new IntersectionObserver(u=>{u.forEach(f=>{const y=f.target.dataset.projectId;y&&c(h=>{const b=new Set(h);return f.isIntersecting?b.delete(y):b.add(y),b})})},{threshold:0});return a.current.forEach(u=>{u&&m.observe(u)}),()=>m.disconnect()},e[1]=n,e[2]=a,e[3]=d):d=e[3];let p;return e[4]!==n||e[5]!==a||e[6]!==r?(p=[n,a,r],e[4]=n,e[5]=a,e[6]=r,e[7]=p):p=e[7],l.useEffect(d,p),o},_P=t=>{const e=nt.c(85),{folder:n,sessions:r,subFolderItems:a,isCollapsed:i,onToggle:o,onRename:c,onDelete:d,renderSessionNode:p,groupDirectory:m,projectId:u,mobileVariant:f,alwaysShowActions:y,isRenaming:h,renameDraft:b,onRenameDraftChange:x,onRenameSave:g,onRenameCancel:w,droppableRef:v,isDropTarget:S,onNewSession:P,onNewSubFolder:j,depth:C,hideActions:I,archivedBucket:R}=t,A=y===void 0?f===void 0?!1:f:y,N=h===void 0?!1:h,D=b===void 0?"":b,T=S===void 0?!1:S,M=C===void 0?0:C,$=I===void 0?!1:I,F=R===void 0?!1:R,{t:_}=ut(),[O,L]=l.useState(!1),[K,B]=l.useState(""),re=l.useRef(null),oe=N||O,ee=N?D:K;let ae;e[0]!==n.name?(ae=()=>{B(n.name),L(!0)},e[0]=n.name,e[1]=ae):ae=e[1];const ge=ae;let ne;e[2]!==ee||e[3]!==n.name||e[4]!==N||e[5]!==c||e[6]!==g?(ne=()=>{const de=ee.trim();de&&de!==n.name&&c(de),N&&g&&g(),L(!1),B("")},e[2]=ee,e[3]=n.name,e[4]=N,e[5]=c,e[6]=g,e[7]=ne):ne=e[7];const E=ne;let z;e[8]!==N||e[9]!==w?(z=()=>{N&&w&&w(),L(!1),B("")},e[8]=N,e[9]=w,e[10]=z):z=e[10];const J=z;let H;e[11]!==N||e[12]!==x?(H=de=>{N&&x?x(de):B(de)},e[11]=N,e[12]=x,e[13]=H):H=e[13];const te=H;let ce,Se;e[14]!==N?(ce=()=>{if(!N)return;const de=()=>{const se=re.current;se&&(se.focus(),se.select())},Me=requestAnimationFrame(de),Le=window.setTimeout(de,0);return()=>{cancelAnimationFrame(Me),window.clearTimeout(Le)}},Se=[N],e[14]=N,e[15]=ce,e[16]=Se):(ce=e[15],Se=e[16]),l.useEffect(ce,Se);const pe=i?Un:Jy,W=M>0&&"ml-3";let ue;e[17]!==W?(ue=me("oc-folder",W),e[17]=W,e[18]=ue):ue=e[18];const Y=T&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let le;e[19]!==Y?(le=me("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",Y),e[19]=Y,e[20]=le):le=e[20];const Z=oe?void 0:o,Ie=oe?void 0:"button",Ne=oe?void 0:0;let X;e[21]!==o||e[22]!==oe?(X=oe?void 0:de=>{(de.key==="Enter"||de.key===" ")&&(de.preventDefault(),o())},e[21]=o,e[22]=oe,e[23]=X):X=e[23];let he;e[24]!==n.name||e[25]!==i||e[26]!==_?(he=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]=he):he=e[27];const je=F?A?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let be;e[28]!==je?(be=me("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",je),e[28]=je,e[29]=be):be=e[29];const fe=T?"text-primary":"text-muted-foreground";let Pe;e[30]!==fe?(Pe=me("h-3.5 w-3.5 flex-shrink-0",fe),e[30]=fe,e[31]=Pe):Pe=e[31];let Be;e[32]!==pe||e[33]!==Pe?(Be=s.jsx(pe,{className:Pe}),e[32]=pe,e[33]=Pe,e[34]=Be):Be=e[34];let G;e[35]!==ee||e[36]!==n.name||e[37]!==J||e[38]!==te||e[39]!==E||e[40]!==i||e[41]!==T||e[42]!==oe||e[43]!==r||e[44]!==_?(G=oe?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:zP,onMouseDown:UP,onSubmit:de=>{de.preventDefault(),E()},children:[s.jsx("input",{ref:re,value:ee,onChange:de=>te(de.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:WP,onPointerDown:KP,onMouseDown:HP,onKeyDown:de=>{if(de.key==="Escape"){de.stopPropagation(),J();return}(de.key===" "||de.key==="Enter")&&de.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:GP,onPointerDown:qP,onMouseDown:QP,children:s.jsx(Zs,{className:"size-4"})}),s.jsx("button",{type:"button",onClick:de=>{de.stopPropagation(),J()},onPointerDown:JP,onMouseDown:YP,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(Is,{className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsx("span",{className:me("typography-ui-label font-semibold truncate",T?"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($n,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(ks,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=ee,e[36]=n.name,e[37]=J,e[38]=te,e[39]=E,e[40]=i,e[41]=T,e[42]=oe,e[43]=r,e[44]=_,e[45]=G):G=e[45];let ke;e[46]!==be||e[47]!==Be||e[48]!==G?(ke=s.jsxs("div",{className:be,children:[Be,G]}),e[46]=be,e[47]=Be,e[48]=G,e[49]=ke):ke=e[49];let Ee;e[50]!==A||e[51]!==F||e[52]!==M||e[53]!==n.name||e[54]!==ge||e[55]!==$||e[56]!==d||e[57]!==P||e[58]!==j||e[59]!==oe||e[60]!==_?(Ee=!oe&&(!$||F)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:me("flex items-center gap-0.5 transition-opacity",A?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",F&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!F&&P?s.jsx("button",{type:"button",onClick:de=>{de.stopPropagation(),P()},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(zs,{className:"h-3.5 w-3.5"})}):null,!F&&j&&M===0?s.jsx("button",{type:"button",onClick:de=>{de.stopPropagation(),j()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":_("sessions.sidebar.folderItem.newSubfolderAria",{folderName:n.name}),title:_("sessions.sidebar.folderItem.newSubfolder"),children:s.jsx(Aa,{className:"h-3.5 w-3.5"})}):null,F?null:s.jsx("button",{type:"button",onClick:de=>{de.stopPropagation(),ge()},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(Fi,{className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:de=>{de.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":F?_("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):_("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(an,{className:"h-3.5 w-3.5"})})]})}):null,e[50]=A,e[51]=F,e[52]=M,e[53]=n.name,e[54]=ge,e[55]=$,e[56]=d,e[57]=P,e[58]=j,e[59]=oe,e[60]=_,e[61]=Ee):Ee=e[61];let Ae;e[62]!==v||e[63]!==le||e[64]!==Z||e[65]!==Ie||e[66]!==Ne||e[67]!==X||e[68]!==he||e[69]!==ke||e[70]!==Ee?(Ae=s.jsxs("div",{ref:v,className:le,onClick:Z,role:Ie,tabIndex:Ne,onKeyDown:X,"aria-label":he,children:[ke,Ee]}),e[62]=v,e[63]=le,e[64]=Z,e[65]=Ie,e[66]=Ne,e[67]=X,e[68]=he,e[69]=ke,e[70]=Ee,e[71]=Ae):Ae=e[71];let xe;e[72]!==F||e[73]!==m||e[74]!==i||e[75]!==u||e[76]!==p||e[77]!==r||e[78]!==a||e[79]!==_?(xe=i?null:s.jsxs("div",{className:"pb-1 pl-2",children:[a,r.length>0?r.map(de=>p(de,0,m??null,u??null,F)):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]=F,e[73]=m,e[74]=i,e[75]=u,e[76]=p,e[77]=r,e[78]=a,e[79]=_,e[80]=xe):xe=e[80];let V;return e[81]!==ue||e[82]!==Ae||e[83]!==xe?(V=s.jsxs("div",{className:ue,children:[Ae,xe]}),e[81]=ue,e[82]=Ae,e[83]=xe,e[84]=V):V=e[84],V},VP=l.memo(_P);function zP(t){return t.stopPropagation()}function UP(t){return t.stopPropagation()}function WP(t){return t.stopPropagation()}function KP(t){return t.stopPropagation()}function HP(t){return t.stopPropagation()}function GP(t){return t.stopPropagation()}function qP(t){return t.stopPropagation()}function QP(t){return t.stopPropagation()}function JP(t){return t.stopPropagation()}function YP(t){return t.stopPropagation()}const XP=t=>{const e=nt.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:a,children:i}=t,o=`session-drag:${n}`;let c;e[0]!==r||e[1]!==n||e[2]!==a?(c={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:a},e[0]=r,e[1]=n,e[2]=a,e[3]=c):c=e[3];let d;e[4]!==o||e[5]!==c?(d={id:o,data:c},e[4]=o,e[5]=c,e[6]=d):d=e[6];const{attributes:p,listeners:m,setNodeRef:u,isDragging:f}=Yy(d);let y;e[7]!==m?(y=g=>{g.stopPropagation(),m?.onPointerDown&&m.onPointerDown(g)},e[7]=m,e[8]=y):y=e[8];const h=y,b=f?"opacity-30":void 0;let x;return e[9]!==p||e[10]!==i||e[11]!==h||e[12]!==u||e[13]!==b?(x=s.jsx("div",{ref:u,...p,onPointerDown:h,className:b,children:i}),e[9]=p,e[10]=i,e[11]=h,e[12]=u,e[13]=b,e[14]=x):x=e[14],x},ZP=t=>{const e=nt.c(11),{folderId:n,children:r}=t,a=`folder-drop:${n}`;let i;e[0]!==n?(i={type:"folder",folderId:n},e[0]=n,e[1]=i):i=e[1];let o;e[2]!==a||e[3]!==i?(o={id:a,data:i},e[2]=a,e[3]=i,e[4]=o):o=e[4];const{setNodeRef:c,isOver:d}=Xy(o);let p;e[5]!==r||e[6]!==d||e[7]!==c?(p=r(c,d),e[5]=r,e[6]=d,e[7]=c,e[8]=p):p=e[8];let m;return e[9]!==p?(m=s.jsx(s.Fragment,{children:p}),e[9]=p,e[10]=m):m=e[10],m},eD=t=>{const e=nt.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:a,children:i}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={activationConstraint:{distance:8}},e[0]=o):o=e[0];const c=$l(vo(Bl,o)),[d,p]=l.useState(null),[m,u]=l.useState("Session"),[f,y]=l.useState(null),[h,b]=l.useState(null);if(!n){let C;return e[1]!==i?(C=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=C):C=e[2],C}let x;e[3]!==a?(x=C=>{p(null),y(null),b(null);const{active:I,over:R}=C;if(!R)return;const k=I.data.current,A=R.data.current;k?.type==="session"&&k.sessionId&&A?.type==="folder"&&A.folderId&&a(k.sessionId,A.folderId)},e[3]=a,e[4]=x):x=e[4];const g=x;let w,v;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=C=>{const I=C.active.data.current;if(I?.type==="session"&&I.sessionId){p(I.sessionId),u(I.sessionTitle??"Session");const R=C.active.rect.current.initial?.width,k=C.active.rect.current.initial?.height;y(typeof R=="number"?R:null),b(typeof k=="number"?k:null)}},v=()=>{p(null),y(null),b(null)},e[5]=w,e[6]=v):(w=e[5],v=e[6]);let S;e[7]!==h||e[8]!==d||e[9]!==m||e[10]!==f||e[11]!==r?(S=d&&r?s.jsxs("div",{style:{width:f?`${f}px`:"auto",height:h?`${h}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(Zy,{className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:m})]}):null,e[7]=h,e[8]=d,e[9]=m,e[10]=f,e[11]=r,e[12]=S):S=e[12];let P;e[13]!==S?(P=s.jsx(_l,{children:S}),e[13]=S,e[14]=P):P=e[14];let j;return e[15]!==i||e[16]!==g||e[17]!==c||e[18]!==P?(j=s.jsxs(Vl,{sensors:c,collisionDetection:zl,onDragStart:w,onDragCancel:v,onDragEnd:g,children:[i,P]}),e[15]=i,e[16]=g,e[17]=c,e[18]=P,e[19]=j):j=e[19],j},Ha=Nr()(_o(t=>({displayMode:"default",showRecentSection:!0,setDisplayMode:e=>t({displayMode:e}),setShowRecentSection:e=>t({showRecentSection:e}),toggleRecentSection:()=>t(e=>({showRecentSection:!e.showRecentSection}))}),{name:"session-display-mode"}));function tD(t){const e=nt.c(289),{t:n}=ut(),{group:r,groupKey:a,projectId:i,hideGroupLabel:o,hasSessionSearchQuery:c,normalizedSessionSearchQuery:d,groupSearchDataByGroup:p,expandedSessionGroups:m,collapsedGroups:u,hideDirectoryControls:f,collapsedFolderIds:y,toggleFolderCollapse:h,renameFolder:b,deleteFolder:x,showDeletionDialog:g,setDeleteFolderConfirm:w,renderSessionNode:v,projectRepoStatus:S,lastRepoStatus:P,toggleGroupSessionLimit:j,mobileVariant:C,alwaysShowActions:I,activeProjectId:R,setActiveProjectIdOnly:k,setActiveMainTab:A,setSessionSwitcherOpen:N,openNewSessionDraft:D,addSessionToFolder:T,createFolderAndStartRename:M,renamingFolderId:$,renameFolderDraft:F,setRenameFolderDraft:_,setRenamingFolderId:O,pinnedSessionIds:L,sessionOrderIndex:K,prVisualStateByDirectoryBranch:B,onToggleCollapsedGroup:re,dragHandleProps:oe,compactBodyPadding:ee}=t,ae=ee===void 0?!1:ee;let ge;e[0]!==L||e[1]!==K?(ge=(st,Et)=>{const os=K.get(st.session.id),rs=K.get(Et.session.id);if(os!==void 0||rs!==void 0){if(os===void 0)return 1;if(rs===void 0)return-1;if(os!==rs)return os-rs}return Bi(st.session,Et.session,L)},e[0]=L,e[1]=K,e[2]=ge):ge=e[2];const ne=ge;let E;e[3]!==r||e[4]!==p||e[5]!==c?(E=c?p.get(r):null,e[3]=r,e[4]=p,e[5]=c,e[6]=E):E=e[6];const z=E,J=Ha(dD),H=rr(cD),te=J==="minimal";let ce;e[7]!==m||e[8]!==a?(ce=m.has(a),e[7]=m,e[8]=a,e[9]=ce):ce=e[9];const Se=ce;let pe;e[10]!==u||e[11]!==a||e[12]!==c?(pe=c?!1:u.has(a),e[10]=u,e[11]=a,e[12]=c,e[13]=pe):pe=e[13];const we=pe,W=f?10:5,ue=c?z?.groupMatches===!0:!1,Y=c;z?.filteredNodes;let le;e[14]!==ne||e[15]!==r.sessions||e[16]!==z?.filteredNodes||e[17]!==Y?(le=[...Y?z?.filteredNodes??[]:r.sessions].sort(ne),e[14]=ne,e[15]=r.sessions,e[16]=z?.filteredNodes,e[17]=Y,e[18]=le):le=e[18];const Z=le;let Ie;e[19]!==r.directory||e[20]!==r.folderScopeKey?(Ie=r.folderScopeKey??Ns(r.directory??null),e[19]=r.directory,e[20]=r.folderScopeKey,e[21]=Ie):Ie=e[21];const Ne=Ie;let X;e[22]!==Ne||e[23]!==H?(X=Ne?H[Ne]??[]:[],e[22]=Ne,e[23]=H,e[24]=X):X=e[24];const he=X;let je;if(e[25]!==Z){je=new Map;const st=Et=>{Et.forEach(os=>{je.set(os.session.id,os),os.children.length>0&&st(os.children)})};st(Z),e[25]=Z,e[26]=je}else je=e[26];const be=je;let fe;if(e[27]!==ne||e[28]!==be||e[29]!==he){let st;e[31]!==ne||e[32]!==be?(st=Et=>{const os=Et.sessionIds.map(rs=>be.get(rs)).filter(lD).sort(ne);return{folder:Et,nodes:os}},e[31]=ne,e[32]=be,e[33]=st):st=e[33],fe=he.map(st),e[27]=ne,e[28]=be,e[29]=he,e[30]=fe}else fe=e[30];const Pe=fe;let Be;if(e[34]!==Pe||e[35]!==r.isArchivedBucket||e[36]!==c||e[37]!==d){const st=new Map(Pe.map(oD)),Et=new Map;for(const{folder:$t}of Pe){if(!$t.parentId)continue;const xs=Et.get($t.parentId);xs?xs.push($t.id):Et.set($t.parentId,[$t.id])}const os=new Map,rs=$t=>{const xs=os.get($t);if(xs!==void 0)return xs;const bn=st.get($t);if(!bn)return os.set($t,!1),!1;const en=Et.get($t)??[];if(r.isArchivedBucket&&bn.nodes.length===0){const un=en.some(fn=>rs(fn));return os.set($t,un),un}if(!c||bn.folder.name.toLowerCase().includes(d)||bn.nodes.length>0)return os.set($t,!0),!0;const hn=en.some(un=>rs(un));return os.set($t,hn),hn};Be=Pe.filter($t=>{const{folder:xs}=$t;return rs(xs.id)}),e[34]=Pe,e[35]=r.isArchivedBucket,e[36]=c,e[37]=d,e[38]=Be}else Be=e[38];const G=Be;let ke;e[39]!==G?(ke=new Set(G.flatMap(iD)),e[39]=G,e[40]=ke):ke=e[40];const Ee=ke;let Ae;if(e[41]!==Ee||e[42]!==Z){let st;e[44]!==Ee?(st=Et=>!Ee.has(Et.session.id),e[44]=Ee,e[45]=st):st=e[45],Ae=Z.filter(st),e[41]=Ee,e[42]=Z,e[43]=Ae}else Ae=e[43];const xe=Ae;let V;e[46]!==G?(V=G.filter(aD),e[46]=G,e[47]=V):V=e[47];const de=V;if(c&&!ue&&de.length===0&&xe.length===0)return null;const Me=xe.length;let Le;e[48]!==r.isArchivedBucket||e[49]!==c||e[50]!==Se||e[51]!==W||e[52]!==xe?(Le=r.isArchivedBucket||c||Se?xe:xe.slice(0,W),e[48]=r.isArchivedBucket,e[49]=c,e[50]=Se,e[51]=W,e[52]=xe,e[53]=Le):Le=e[53];const se=Le,ie=Me-se.length,U=rD;let Ve;e[54]!==Z?(Ve=U(Z),e[54]=Z,e[55]=Ve):Ve=e[55];const He=Ve;let Ke;e[56]!==P||e[57]!==i||e[58]!==S?(Ke=i&&S.has(i)?!!S.get(i):P,e[56]=P,e[57]=i,e[58]=S,e[59]=Ke):Ke=e[59];const Ze=Ke,Xe=r.directory??null;let dt;e[60]!==Xe?(dt=Ns(Xe),e[60]=Xe,e[61]=dt):dt=e[61];const et=dt;let ct;e[62]!==r.branch?(ct=r.branch?.trim()??null,e[62]=r.branch,e[63]=ct):ct=e[63];const at=ct;let ye,Ge,$e,_e,tt,Qe,ze,gt;e[64]!==r.branch||e[65]!==r.isMain||e[66]!==at||e[67]!==et||e[68]!==B||e[69]!==n?(_e=et&&at?B.get(`${et}::${at}`)??null:null,ze=!!(_e&&r.branch),Qe=!_e&&!r.isMain&&!!r.branch,tt=_e?.visualState??null,ye=_e&&_e.state==="open"&&_e.checks?n("sessions.sidebar.group.pr.checksPassed",{success:_e.checks.success,total:_e.checks.total}):null,Ge=_e&&_e.state==="open"&&_e.checks?[_e.checks.failure>0?n("sessions.sidebar.group.pr.failingCount",{count:_e.checks.failure}):null,_e.checks.pending>0?n("sessions.sidebar.group.pr.pendingCount",{count:_e.checks.pending}):null].filter(nD).join(", "):null,$e=_e&&_e.state==="open"?_e.mergeableState==="blocked"||_e.mergeableState==="dirty"?n("sessions.sidebar.group.pr.conflictsOrBlocked"):_e.mergeableState==="clean"||_e.canMerge===!0?n("sessions.sidebar.group.pr.mergeable"):null:null,gt=_e&&_e.state==="open"&&_e.mergeableState?n("sessions.sidebar.group.pr.mergeState",{state:_e.mergeableState}):null,e[64]=r.branch,e[65]=r.isMain,e[66]=at,e[67]=et,e[68]=B,e[69]=n,e[70]=ye,e[71]=Ge,e[72]=$e,e[73]=_e,e[74]=tt,e[75]=Qe,e[76]=ze,e[77]=gt):(ye=e[70],Ge=e[71],$e=e[72],_e=e[73],tt=e[74],Qe=e[75],ze=e[76],gt=e[77]);const Vt=gt,Kt=_e?.base??null,Jt=_e?.head??null;let At;e:{if(!_e){let st;e[78]!==r.branch||e[79]!==r.label?(st=r.branch&&X1(r.branch,r.label)?{label:r.branch,color:null}:null,e[78]=r.branch,e[79]=r.label,e[80]=st):st=e[80],At=st;break e}switch(_e.visualState){case"merged":{let st;e[81]!==n?(st=n("sessions.sidebar.group.pr.status.merged"),e[81]=n,e[82]=st):st=e[82];let Et;e[83]!==st?(Et={label:st,color:"var(--pr-merged)"},e[83]=st,e[84]=Et):Et=e[84],At=Et;break e}case"open":{let st;e[85]!==_e.canMerge||e[86]!==_e.checks?.state||e[87]!==_e.mergeableState||e[88]!==n?(st=_e.canMerge===!0||_e.mergeableState==="clean"||_e.checks?.state==="success"?{label:n("sessions.sidebar.group.pr.status.readyToMerge"),color:"var(--pr-open)"}:{label:n("sessions.sidebar.group.pr.status.open"),color:"var(--pr-open)"},e[85]=_e.canMerge,e[86]=_e.checks?.state,e[87]=_e.mergeableState,e[88]=n,e[89]=st):st=e[89],At=st;break e}case"blocked":{let st;e[90]!==_e.mergeableState||e[91]!==n?(st=_e.mergeableState==="dirty"?n("sessions.sidebar.group.pr.status.mergeConflicts"):n("sessions.sidebar.group.pr.status.mergeBlocked"),e[90]=_e.mergeableState,e[91]=n,e[92]=st):st=e[92];let Et;e[93]!==st?(Et={label:st,color:"var(--pr-blocked)"},e[93]=st,e[94]=Et):Et=e[94],At=Et;break e}case"draft":{let st;e[95]!==n?(st=n("sessions.sidebar.group.pr.status.draft"),e[95]=n,e[96]=st):st=e[96];let Et;e[97]!==st?(Et={label:st,color:"var(--pr-draft)"},e[97]=st,e[98]=Et):Et=e[98],At=Et;break e}case"closed":{let st;e[99]!==n?(st=n("sessions.sidebar.group.pr.status.closed"),e[99]=n,e[100]=st):st=e[100];let Et;e[101]!==st?(Et={label:st,color:"var(--pr-closed)"},e[101]=st,e[102]=Et):Et=e[102],At=Et;break e}default:At=null}}const jt=At,ns=jt?.color??(tt?`var(--pr-${tt})`:void 0);let ot;e[103]!==_e?.url?(ot=st=>{st.preventDefault(),st.stopPropagation();const Et=_e?.url;Et&&mr(Et)},e[103]=_e?.url,e[104]=ot):ot=e[104];const Zt=ot;let Yt,es,ls,ds,gs,us;if(e[105]!==R||e[106]!==T||e[107]!==G||e[108]!==I||e[109]!==y||e[110]!==M||e[111]!==x||e[112]!==Ne||e[113]!==r.directory||e[114]!==r.isArchivedBucket||e[115]!==r.isMain||e[116]!==r.worktree||e[117]!==c||e[118]!==te||e[119]!==C||e[120]!==D||e[121]!==i||e[122]!==b||e[123]!==F||e[124]!==$||e[125]!==v||e[126]!==de||e[127]!==A||e[128]!==k||e[129]!==w||e[130]!==_||e[131]!==O||e[132]!==N||e[133]!==g||e[134]!==h){const st=(rs,$t,xs)=>{const bn=G.filter(un=>{const{folder:fn}=un;return fn.parentId===rs.id}),en=bn.length>0?s.jsx(s.Fragment,{children:bn.map(un=>{const{folder:fn,nodes:gn}=un;return st(fn,gn,xs+1)})}):void 0,Ws=un=>{const fn=G.find(yn=>{const{folder:mn}=yn;return mn.id===un})?.nodes??[],gn=G.filter(yn=>{const{folder:mn}=yn;return mn.parentId===un});return[...U(fn),...gn.flatMap(yn=>{const{folder:mn}=yn;return Ws(mn.id)})]},hn=r.isArchivedBucket?Ws(rs.id):[];return s.jsx(ZP,{folderId:rs.id,children:(un,fn)=>s.jsx(VP,{folder:rs,sessions:$t,subFolderItems:en,isCollapsed:c?!1:y.has(rs.id),onToggle:()=>h(rs.id),onRename:gn=>{Ne&&b(Ne,rs.id,gn)},onDelete:()=>{if(r.isArchivedBucket){Tr.requestDelete({sessions:hn,mode:"session"});return}if(!Ne)return;if(!g){x(Ne,rs.id);return}const gn=G.filter(mn=>{const{folder:Rn}=mn;return Rn.parentId===rs.id}).length,yn=$t.length;w({scopeKey:Ne,folderId:rs.id,folderName:rs.name,subFolderCount:gn,sessionCount:yn})},renderSessionNode:v,groupDirectory:r.directory,projectId:i,mobileVariant:C,alwaysShowActions:I,isRenaming:$===rs.id,renameDraft:$===rs.id?F:void 0,onRenameDraftChange:gn=>_(gn),onRenameSave:()=>{const gn=F.trim();gn&&Ne&&b(Ne,rs.id,gn),O(null),_("")},onRenameCancel:()=>{O(null),_("")},droppableRef:un,isDropTarget:fn,depth:xs,onNewSession:()=>{i&&i!==R&&k(i),A("chat"),C&&N(!1),D({directoryOverride:r.directory,targetFolderId:rs.id})},onNewSubFolder:xs===0?()=>{Ne&&M(Ne,rs.id)}:void 0,hideActions:!1,archivedBucket:r.isArchivedBucket===!0})},rs.id)},Et=()=>de.map(rs=>{const{folder:$t,nodes:xs}=rs;return st($t,xs,0)}),os=!!(!r.isMain&&r.worktree);es=I?os?"pr-14":"pr-7":te?os?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":os?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",Yt=eD,ls=Ne,ds=G.length>0,e[141]!==T||e[142]!==Ne?(gs=(rs,$t)=>{Ne&&T(Ne,$t,rs)},e[141]=T,e[142]=Ne,e[143]=gs):gs=e[143],us=Et(),e[105]=R,e[106]=T,e[107]=G,e[108]=I,e[109]=y,e[110]=M,e[111]=x,e[112]=Ne,e[113]=r.directory,e[114]=r.isArchivedBucket,e[115]=r.isMain,e[116]=r.worktree,e[117]=c,e[118]=te,e[119]=C,e[120]=D,e[121]=i,e[122]=b,e[123]=F,e[124]=$,e[125]=v,e[126]=de,e[127]=A,e[128]=k,e[129]=w,e[130]=_,e[131]=O,e[132]=N,e[133]=g,e[134]=h,e[135]=Yt,e[136]=es,e[137]=ls,e[138]=ds,e[139]=gs,e[140]=us}else Yt=e[135],es=e[136],ls=e[137],ds=e[138],gs=e[139],us=e[140];let Ct;if(e[144]!==r.directory||e[145]!==r.isArchivedBucket||e[146]!==i||e[147]!==v||e[148]!==se){let st;e[150]!==r.directory||e[151]!==r.isArchivedBucket||e[152]!==i||e[153]!==v?(st=Et=>v(Et,0,r.directory,i,r.isArchivedBucket===!0),e[150]=r.directory,e[151]=r.isArchivedBucket,e[152]=i,e[153]=v,e[154]=st):st=e[154],Ct=se.map(st),e[144]=r.directory,e[145]=r.isArchivedBucket,e[146]=i,e[147]=v,e[148]=se,e[149]=Ct}else Ct=e[149];let Ue;e[155]!==G.length||e[156]!==r.isArchivedBucket||e[157]!==n||e[158]!==Me?(Ue=Me===0&&G.length===0?s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:r.isArchivedBucket?n("sessions.sidebar.group.empty.noArchivedSessions"):n("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,e[155]=G.length,e[156]=r.isArchivedBucket,e[157]=n,e[158]=Me,e[159]=Ue):Ue=e[159];let Dt;e[160]!==a||e[161]!==Se||e[162]!==ie||e[163]!==n||e[164]!==j?(Dt=ie>0&&!Se?s.jsx("button",{type:"button",onClick:()=>j(a),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:ie===1?n("sessions.sidebar.group.showMoreSingle",{count:ie}):n("sessions.sidebar.group.showMorePlural",{count:ie})}):null,e[160]=a,e[161]=Se,e[162]=ie,e[163]=n,e[164]=j,e[165]=Dt):Dt=e[165];let Tt;e[166]!==a||e[167]!==Se||e[168]!==W||e[169]!==n||e[170]!==j||e[171]!==Me?(Tt=Se&&Me>W?s.jsx("button",{type:"button",onClick:()=>j(a),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:n("sessions.sidebar.group.showFewer")}):null,e[166]=a,e[167]=Se,e[168]=W,e[169]=n,e[170]=j,e[171]=Me,e[172]=Tt):Tt=e[172];let wt;e[173]!==Yt||e[174]!==ls||e[175]!==ds||e[176]!==gs||e[177]!==us||e[178]!==Ct||e[179]!==Ue||e[180]!==Dt||e[181]!==Tt?(wt=s.jsxs(Yt,{scopeKey:ls,hasFolders:ds,onSessionDroppedOnFolder:gs,children:[us,Ct,Ue,Dt,Tt]}),e[173]=Yt,e[174]=ls,e[175]=ds,e[176]=gs,e[177]=us,e[178]=Ct,e[179]=Ue,e[180]=Dt,e[181]=Tt,e[182]=wt):wt=e[182];const Wt=wt,_t=ae?"pb-2 pl-1":"pb-3 pl-4";if(o){let st;e[183]!==_t?(st=me("oc-group-body",_t),e[183]=_t,e[184]=st):st=e[184];let Et;return e[185]!==Wt||e[186]!==st?(Et=s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:st,children:Wt})}),e[185]=Wt,e[186]=st,e[187]=Et):Et=e[187],Et}let Vs;e[188]===Symbol.for("react.memo_cache_sentinel")?(Vs=me("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),e[188]=Vs):Vs=e[188];let mt;e[189]!==a||e[190]!==re?(mt=()=>re(a),e[189]=a,e[190]=re,e[191]=mt):mt=e[191];let cs;e[192]!==a||e[193]!==re?(cs=st=>{(st.key==="Enter"||st.key===" ")&&(st.preventDefault(),re(a))},e[192]=a,e[193]=re,e[194]=cs):cs=e[194];let qt;e[195]!==r.label||e[196]!==we||e[197]!==n?(qt=we?n("sessions.sidebar.group.expandAria",{label:r.label}):n("sessions.sidebar.group.collapseAria",{label:r.label}),e[195]=r.label,e[196]=we,e[197]=n,e[198]=qt):qt=e[198];const Ds=!we,Os=oe?.setActivatorNodeRef;let Q;e[199]!==es?(Q=me("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",es),e[199]=es,e[200]=Q):Q=e[200];let ht;e[201]!==oe?.listeners?(ht=oe?.listeners??{},e[201]=oe?.listeners,e[202]=ht):ht=e[202];let vt;e[203]!==I||e[204]!==Kt||e[205]!==ns||e[206]!==ye||e[207]!==Ge||e[208]!==r.branch||e[209]!==r.isArchivedBucket||e[210]!==r.isMain||e[211]!==r.label||e[212]!==r.worktree||e[213]!==Zt||e[214]!==Jt||e[215]!==we||e[216]!==Vt||e[217]!==$e||e[218]!==d||e[219]!==_e||e[220]!==ze?(vt=ze&&_e?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(St,{children:[s.jsx(kt,{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(Qs,{className:me("h-3.5 w-3.5 shrink-0",I?"hidden":"group-hover/gh:hidden"),style:ns?{color:ns}:void 0}),s.jsx("span",{className:me("text-muted-foreground h-3.5 w-3.5 items-center justify-center",I?"inline-flex":"hidden group-hover/gh:inline-flex"),children:we?s.jsx($n,{className:"h-3.5 w-3.5"}):s.jsx(ks,{className:"h-3.5 w-3.5"})})]}),_e.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:sD,onClick:Zt,children:["#",_e.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",_e.number]})]})}),s.jsx(It,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Kt||Jt?s.jsx("div",{className:"text-muted-foreground truncate",children:Kt&&Jt?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Kt}),s.jsx(hm,{className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:Jt})]}):s.jsx("span",{children:Kt??Jt??""})}):null,Vt?s.jsx("div",{className:"text-muted-foreground truncate",children:Vt}):null,$e||ye?s.jsxs("div",{className:"text-muted-foreground truncate",children:[$e??"",$e&&ye?" • ":"",ye??"",Ge?` (${Ge})`:""]}):null]})})]}),s.jsx("span",{className:"ml-1 min-w-0 flex-1 truncate leading-none align-middle",children:r.branch})]}):r.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx($d,{className:me("h-3.5 w-3.5 shrink-0 text-muted-foreground",I?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:me("text-muted-foreground h-3.5 w-3.5 items-center justify-center",I?"inline-flex":"hidden group-hover/gh:inline-flex"),children:we?s.jsx($n,{className:"h-3.5 w-3.5"}):s.jsx(ks,{className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Co(r.label,d)})]}):!r.isMain||r.worktree?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(Qs,{className:me("h-3.5 w-3.5 shrink-0 text-muted-foreground",I?"hidden":"group-hover/gh:hidden"),style:ns?{color:ns}:void 0}),s.jsx("span",{className:me("text-muted-foreground h-3.5 w-3.5 items-center justify-center",I?"inline-flex":"hidden group-hover/gh:inline-flex"),children:we?s.jsx($n,{className:"h-3.5 w-3.5"}):s.jsx(ks,{className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Co(r.label,d)})]}):Co(r.label,d),e[203]=I,e[204]=Kt,e[205]=ns,e[206]=ye,e[207]=Ge,e[208]=r.branch,e[209]=r.isArchivedBucket,e[210]=r.isMain,e[211]=r.label,e[212]=r.worktree,e[213]=Zt,e[214]=Jt,e[215]=we,e[216]=Vt,e[217]=$e,e[218]=d,e[219]=_e,e[220]=ze,e[221]=vt):vt=e[221];let zt;e[222]!==vt?(zt=s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:vt}),e[222]=vt,e[223]=zt):zt=e[223];let ss;e[224]!==Kt||e[225]!==ns||e[226]!==ye||e[227]!==Ge||e[228]!==r.isArchivedBucket||e[229]!==r.isMain||e[230]!==Jt||e[231]!==Ze||e[232]!==Vt||e[233]!==$e||e[234]!==_e||e[235]!==Qe||e[236]!==ze||e[237]!==jt?(ss=Qe&&jt?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[r.isArchivedBucket?s.jsx($d,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!r.isMain||Ze?ze&&_e?s.jsxs(St,{children:[s.jsx(kt,{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(Qs,{className:"h-3.5 w-3.5 text-muted-foreground",style:ns?{color:ns}:void 0})})}),s.jsx(It,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Kt||Jt?s.jsx("div",{className:"text-muted-foreground truncate",children:Kt&&Jt?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Kt}),s.jsx(hm,{className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:Jt})]}):s.jsx("span",{children:Kt??Jt??""})}):null,Vt?s.jsx("div",{className:"text-muted-foreground truncate",children:Vt}):null,$e||ye?s.jsxs("div",{className:"text-muted-foreground truncate",children:[$e??"",$e&&ye?" • ":"",ye??"",Ge?` (${Ge})`:""]}):null]})})]}):s.jsx(Qs,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:ns?{color:ns}:void 0}):null,s.jsx("span",{className:me("min-w-0 truncate text-[11px] font-medium",!jt.color&&"text-muted-foreground/80"),style:jt.color?{color:jt.color}:void 0,children:jt.label})]}):null,e[224]=Kt,e[225]=ns,e[226]=ye,e[227]=Ge,e[228]=r.isArchivedBucket,e[229]=r.isMain,e[230]=Jt,e[231]=Ze,e[232]=Vt,e[233]=$e,e[234]=_e,e[235]=Qe,e[236]=ze,e[237]=jt,e[238]=ss):ss=e[238];let is;e[239]!==zt||e[240]!==ss?(is=s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[zt,ss]}),e[239]=zt,e[240]=ss,e[241]=is):is=e[241];let Ss;e[242]!==Os||e[243]!==Q||e[244]!==ht||e[245]!==is?(Ss=s.jsx("div",{ref:Os,className:Q,...ht,children:is}),e[242]=Os,e[243]=Q,e[244]=ht,e[245]=is,e[246]=Ss):Ss=e[246];let Ms;e[247]!==He||e[248]!==I||e[249]!==r.isArchivedBucket||e[250]!==r.label||e[251]!==n?(Ms=r.isArchivedBucket&&He.length>0?s.jsx("div",{className:me("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",I?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:st=>{st.stopPropagation(),Tr.requestDelete({sessions:He,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:r.label}),children:s.jsx(an,{className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,e[247]=He,e[248]=I,e[249]=r.isArchivedBucket,e[250]=r.label,e[251]=n,e[252]=Ms):Ms=e[252];let We;e[253]!==He||e[254]!==I||e[255]!==r.directory||e[256]!==r.isMain||e[257]!==r.label||e[258]!==r.worktree||e[259]!==n?(We=r.directory&&!r.isMain&&r.worktree?s.jsx("div",{className:me("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",I?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:st=>{st.stopPropagation(),Tr.requestDelete({sessions:He,mode:"worktree",worktree:r.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.group.actions.deleteGroupAria",{label:r.label}),children:s.jsx(an,{className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,e[253]=He,e[254]=I,e[255]=r.directory,e[256]=r.isMain,e[257]=r.label,e[258]=r.worktree,e[259]=n,e[260]=We):We=e[260];let xt;e[261]!==R||e[262]!==I||e[263]!==r.directory||e[264]!==r.label||e[265]!==C||e[266]!==D||e[267]!==i||e[268]!==A||e[269]!==k||e[270]!==N||e[271]!==n?(xt=r.directory?s.jsx("div",{className:me("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",I?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:st=>{st.stopPropagation(),i&&i!==R&&k(i),A("chat"),C&&N(!1),D({directoryOverride:r.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.group.actions.newDraftInGroupAria",{label:r.label}),children:s.jsx(zs,{className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.project.actions.newDraftSession")})})]})}):null,e[261]=R,e[262]=I,e[263]=r.directory,e[264]=r.label,e[265]=C,e[266]=D,e[267]=i,e[268]=A,e[269]=k,e[270]=N,e[271]=n,e[272]=xt):xt=e[272];let Pt;e[273]!==mt||e[274]!==cs||e[275]!==qt||e[276]!==Ds||e[277]!==Ss||e[278]!==Ms||e[279]!==We||e[280]!==xt?(Pt=s.jsxs("div",{className:Vs,onClick:mt,role:"button",tabIndex:0,onKeyDown:cs,"aria-label":qt,"aria-expanded":Ds,children:[Ss,Ms,We,xt]}),e[273]=mt,e[274]=cs,e[275]=qt,e[276]=Ds,e[277]=Ss,e[278]=Ms,e[279]=We,e[280]=xt,e[281]=Pt):Pt=e[281];let Mt;e[282]!==Wt||e[283]!==_t||e[284]!==we?(Mt=we?null:s.jsx("div",{className:me("oc-group-body",_t),children:Wt}),e[282]=Wt,e[283]=_t,e[284]=we,e[285]=Mt):Mt=e[285];let as;return e[286]!==Pt||e[287]!==Mt?(as=s.jsxs("div",{className:"oc-group",children:[Pt,Mt]}),e[286]=Pt,e[287]=Mt,e[288]=as):as=e[288],as}function sD(t){return t.stopPropagation()}function nD(t){return!!t}function rD(t){const e=[],n=r=>{r.forEach(a=>{e.push(a.session),a.children.length>0&&n(a.children)})};return n(t),e}function aD(t){const{folder:e}=t;return!e.parentId}function iD(t){return t.folder.sessionIds}function oD(t){return[t.folder.id,t]}function lD(t){return!!t}function cD(t){return t.foldersMap}function dD(t){return t.displayMode}function uD(t){const e=nt.c(37),{t:n}=ut(),{hideDirectoryControls:r,handleOpenDirectoryDialog:a,handleNewSession:i,canOpenMultiRun:o,openMultiRunLauncher:c,headerActionIconClass:d,reserveHeaderActionsSpace:p,headerActionButtonClass:m,isSessionSearchOpen:u,setIsSessionSearchOpen:f,sessionSearchInputRef:y,sessionSearchQuery:h,setSessionSearchQuery:b,hasSessionSearchQuery:x,searchMatchCount:g,collapseAllProjects:w,expandAllProjects:v,openScheduledTasksDialog:S,selectionModeEnabled:P,onToggleSelectionMode:j,showSidebarToggle:C,onToggleSidebar:I,avoidWindowControlsOverlay:R}=t,k=C===void 0?!1:C,A=R===void 0?!1:R,N=Ha(gD),D=Ha(fD),T=Ha(hD),M=Ha(pD);if(r)return null;const $=k?A?"pl-[5.5rem] pr-3":"pl-3 pr-3":"px-2.5 py-1";let F;e[0]!==$?(F=me("select-none flex-shrink-0",$),e[0]=$,e[1]=F):F=e[1];let _;e[2]!==A||e[3]!==k?(_=k&&A?{paddingTop:"var(--oc-safe-area-top, 0px)"}:void 0,e[2]=A,e[3]=k,e[4]=_):_=e[4];let O;e[5]!==A||e[6]!==o||e[7]!==w||e[8]!==N||e[9]!==v||e[10]!==i||e[11]!==a||e[12]!==x||e[13]!==m||e[14]!==d||e[15]!==u||e[16]!==j||e[17]!==I||e[18]!==c||e[19]!==S||e[20]!==p||e[21]!==g||e[22]!==P||e[23]!==y||e[24]!==h||e[25]!==T||e[26]!==f||e[27]!==b||e[28]!==D||e[29]!==k||e[30]!==n||e[31]!==M?(O=p?s.jsxs("div",{className:me("flex h-auto flex-col gap-1",k?A?"min-h-[calc(var(--oc-header-height,56px)-var(--oc-safe-area-top,0px))] justify-center":"min-h-[var(--oc-header-height,56px)] justify-center":"min-h-8"),children:[s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[k&&I?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:I,className:"inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50","aria-label":n("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(si,{className:"h-[18px] w-[18px]"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.closeSessions")})})]}):null,s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:m,"aria-label":n("sessions.sidebar.header.actions.addProject"),children:s.jsx(Aa,{className:d})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.addProject")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:m,"aria-label":n("sessions.sidebar.header.actions.newSession"),children:s.jsx(Of,{className:d})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newSession")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:m,"aria-label":n("sessions.sidebar.header.actions.newMultiRun"),disabled:!o,children:s.jsx(Z1,{className:d})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newMultiRun")})})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:S,className:m,"aria-label":n("sessions.sidebar.header.actions.scheduledTasks"),children:s.jsx(ev,{className:d})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.scheduledTasks")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>f(mD),className:m,"aria-label":n("sessions.sidebar.header.actions.searchSessions"),"aria-expanded":u,children:s.jsx(Jn,{className:d})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.searchSessions")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,className:me(m,P&&"bg-interactive-hover text-primary"),"aria-label":n(P?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),"aria-pressed":P,children:s.jsx(tv,{className:d})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n(P?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions")})})]}),s.jsxs(_s,{children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx($s,{asChild:!0,children:s.jsx("button",{type:"button",className:m,"aria-label":n("sessions.sidebar.header.actions.sessionDisplayMode"),children:s.jsx(sv,{className:d})})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.displayMode.label")})})]}),s.jsxs(Bs,{align:"end",className:"min-w-[160px]",children:[s.jsxs(Lt,{onClick:()=>T("default"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.default")}),N==="default"?s.jsx(Zs,{className:"h-4 w-4 text-primary"}):null]}),s.jsxs(Lt,{onClick:()=>T("minimal"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.minimal")}),N==="minimal"?s.jsx(Zs,{className:"h-4 w-4 text-primary"}):null]}),s.jsx(Ln,{}),s.jsxs(Lt,{onClick:M,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),D?s.jsx(Zs,{className:"h-4 w-4 text-primary"}):null]}),s.jsx(Ln,{}),s.jsxs(Lt,{onClick:w,className:"flex items-center gap-2",children:[s.jsx(nv,{className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.collapseAll")})]}),s.jsxs(Lt,{onClick:v,className:"flex items-center gap-2",children:[s.jsx(rv,{className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.expandAll")})]})]})]})]})]}),u?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[x?s.jsx("span",{children:g===1?n("sessions.sidebar.header.search.matchCountSingle",{count:g}):n("sessions.sidebar.header.search.matchCountPlural",{count:g})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(Jn,{className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:y,value:h,onChange:K=>b(K.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:K=>{K.key==="Escape"&&(K.stopPropagation(),x?b(""):f(!1))}}),h.length>0?s.jsx("button",{type:"button",onClick:()=>b(""),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(Is,{className:"h-3.5 w-3.5"})}):null]})]}):null]}):null,e[5]=A,e[6]=o,e[7]=w,e[8]=N,e[9]=v,e[10]=i,e[11]=a,e[12]=x,e[13]=m,e[14]=d,e[15]=u,e[16]=j,e[17]=I,e[18]=c,e[19]=S,e[20]=p,e[21]=g,e[22]=P,e[23]=y,e[24]=h,e[25]=T,e[26]=f,e[27]=b,e[28]=D,e[29]=k,e[30]=n,e[31]=M,e[32]=O):O=e[32];let L;return e[33]!==F||e[34]!==_||e[35]!==O?(L=s.jsx("div",{className:F,style:_,children:O}),e[33]=F,e[34]=_,e[35]=O,e[36]=L):L=e[36],L}function mD(t){return!t}function pD(t){return t.toggleRecentSection}function hD(t){return t.setDisplayMode}function fD(t){return t.showRecentSection}function gD(t){return t.displayMode}const hf=7;function xD(t){const e=nt.c(20),{sections:n,renderSessionNode:r}=t,{t:a}=ut();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[o,c]=l.useState(i);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[1]=d):d=e[1];const[p,m]=l.useState(d);let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=v=>{c(S=>{const P=new Set(S);return P.has(v)?P.delete(v):P.add(v),P})},e[2]=u):u=e[2];const f=u;let y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=v=>{m(S=>{const P=new Set(S);return P.has(v)?P.delete(v):P.add(v),P})},e[3]=y):y=e[3];const h=y;let b,x,g;if(e[4]!==o||e[5]!==p||e[6]!==r||e[7]!==n||e[8]!==a){g=Symbol.for("react.early_return_sentinel");e:{const v=n.filter(bD);if(v.length===0){g=null;break e}b="space-y-2 pb-2 pt-1";let S;e[12]!==o||e[13]!==p||e[14]!==r||e[15]!==a?(S=P=>{const j=o.has(P.key),C=p.has(P.key),I=C?P.items:P.items.slice(0,hf),R=P.items.length-I.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>f(P.key),className:"group flex w-full items-center gap-1 rounded-md px-0.5 py-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!j,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:j?s.jsx($n,{className:"h-3.5 w-3.5"}):s.jsx(ks,{className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:P.title})]}),j?null:s.jsxs("div",{className:me("space-y-0.5 pl-7"),children:[I.map(k=>r(k.node,0,k.groupDirectory,k.projectId,!1,k.secondaryMeta,"recent")),R>0&&!C?s.jsx("button",{type:"button",onClick:()=>h(P.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:R===1?a("sessions.sidebar.group.showMoreSingle",{count:R}):a("sessions.sidebar.group.showMorePlural",{count:R})}):null,C&&P.items.length>hf?s.jsx("button",{type:"button",onClick:()=>h(P.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]})]},P.key)},e[12]=o,e[13]=p,e[14]=r,e[15]=a,e[16]=S):S=e[16],x=v.map(S)}e[4]=o,e[5]=p,e[6]=r,e[7]=n,e[8]=a,e[9]=b,e[10]=x,e[11]=g}else b=e[9],x=e[10],g=e[11];if(g!==Symbol.for("react.early_return_sentinel"))return g;let w;return e[17]!==b||e[18]!==x?(w=s.jsx("div",{className:b,children:x}),e[17]=b,e[18]=x,e[19]=w):w=e[19],w}function bD(t){return t.items.length>0}const jd="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 yD(t){const e=nt.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:a,onOpenUpdate:i,showRuntimeButtons:o,showUpdateButton:c}=t,d=o===void 0?!0:o,p=c===void 0?!0:c,{t:m}=ut();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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:jd,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(Ui,{className:"h-4.5 w-4.5"})})}),s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:jd,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(Ld,{className:"h-4.5 w-4.5"})})}),s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:jd,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(Us,{className:"h-4.5 w-4.5"})})}),s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=a,e[1]=n,e[2]=r,e[3]=d,e[4]=m,e[5]=u):u=e[5];let f;e[6]!==i||e[7]!==p||e[8]!==m?(f=p?s.jsx(ve,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:i,children:m("sessions.sidebar.footer.actions.update")}):null,e[6]=i,e[7]=p,e[8]=m,e[9]=f):f=e[9];let y;return e[10]!==u||e[11]!==f?(y=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[u,f]}),e[10]=u,e[11]=f,e[12]=y):y=e[12],y}const vD=t=>{const e=nt.c(58),{id:n,projectLabel:r,projectDescription:a,projectIcon:i,projectColor:o,projectIconImage:c,projectIconBackground:d,isCollapsed:p,isActiveProject:m,isRepo:u,isDesktopShell:f,isStuck:y,hideDirectoryControls:h,alwaysShowActions:b,onToggle:x,onNewSession:g,onNewWorktreeSession:w,onRenameStart:v,onClose:S,sentinelRef:P,children:j,showCreateButtons:C,hideHeader:I,openSidebarMenuKey:R,setOpenSidebarMenuKey:k}=t,A=C===void 0?!0:C,N=I===void 0?!1:I,{t:D}=ut(),{currentTheme:T}=Er();let M;e[0]!==n?(M={id:n},e[0]=n,e[1]=M):M=e[1];const{attributes:$,listeners:F,setNodeRef:_,transform:O,transition:L,isDragging:K}=yu(M),[B,re]=l.useState(!1),oe=l.useRef(!1),ee=`project:${n}`,ae=R===ee;let ge;e[2]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>{re(!1)},e[2]=ge):ge=e[2];const ne=c?.updatedAt;let E;e[3]!==n||e[4]!==ne?(E=[n,ne],e[3]=n,e[4]=ne,e[5]=E):E=e[5],l.useEffect(ge,E);const z=i?jc[i]:null,J=o?Go[o]??null:null;let H;e[6]!==T||e[7]!==n||e[8]!==B||e[9]!==c?(H=B?null:Ho({id:n,iconImage:c},{themeVariant:T.metadata.variant,iconColor:T.colors.surface.foreground}),e[6]=T,e[7]=n,e[8]=B,e[9]=c,e[10]=H):H=e[10];const te=H;let ce;e[11]!==ee||e[12]!==k?(ce=fe=>{k(fe?ee:null)},e[11]=ee,e[12]=k,e[13]=ce):ce=e[13];const Se=ce,pe=ND,we=SD,W=kD;let ue;e[14]===Symbol.for("react.memo_cache_sentinel")?(ue=fe=>{(fe.button===2||fe.button===0&&fe.ctrlKey)&&(oe.current=!0)},e[14]=ue):ue=e[14];const Y=ue;let le;e[15]!==x?(le=()=>{if(oe.current){oe.current=!1;return}x()},e[15]=x,e[16]=le):le=e[16];const Z=le;let Ie;e[17]!==O?(Ie=vu.Transform.toString(O),e[17]=O,e[18]=Ie):Ie=e[18];let Ne;e[19]!==Ie||e[20]!==L?(Ne={transform:Ie,transition:L},e[19]=Ie,e[20]=L,e[21]=Ne):Ne=e[21];const X=K&&"opacity-30";let he;e[22]!==X?(he=me("relative",X),e[22]=X,e[23]=he):he=e[23];let je;e[24]!==z||e[25]!==b||e[26]!==$||e[27]!==Se||e[28]!==Z||e[29]!==h||e[30]!==N||e[31]!==J||e[32]!==n||e[33]!==te||e[34]!==m||e[35]!==p||e[36]!==f||e[37]!==ae||e[38]!==u||e[39]!==y||e[40]!==F||e[41]!==S||e[42]!==g||e[43]!==w||e[44]!==v||e[45]!==a||e[46]!==d||e[47]!==r||e[48]!==P||e[49]!==A||e[50]!==D?(je=N?null:s.jsxs(s.Fragment,{children:[f&&s.jsx("div",{ref:P,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:me("w-full text-left group/project select-none"),style:{backgroundColor:f&&y?"transparent":void 0},children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",...$,children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:Y,onClick:Z,...F,className:me("flex-1 min-w-0 flex items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing transition-[padding]",u&&!h?b?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":b?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[s.jsx("span",{className:me("h-3.5 w-3.5 items-center justify-center text-muted-foreground",b?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:p?s.jsx($n,{className:"h-3.5 w-3.5"}):s.jsx(ks,{className:"h-3.5 w-3.5"})}),te?s.jsx("span",{className:me("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",b?"hidden":"inline-flex group-hover/project:hidden group-focus-within/project:hidden"),style:d?{backgroundColor:d}:void 0,children:s.jsx("img",{src:te,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>re(!0)})}):z?s.jsx(z,{className:me("h-3.5 w-3.5",b?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:J?{color:J}:void 0}):s.jsx(Un,{className:me("h-3.5 w-3.5 text-muted-foreground/80",b?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:J?{color:J}:void 0})]}),s.jsx("span",{className:me("text-[14px] font-normal truncate lowercase",m?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(It,{side:"right",sideOffset:8,children:a})]}),s.jsxs("div",{className:me("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",A?"right-7":"right-0.5"),children:[A&&u&&!h&&w?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:fe=>{fe.stopPropagation(),w()},className:me("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground transition-opacity",b?"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":D("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(qf,{className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:D("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(_s,{open:ae,onOpenChange:Se,children:[s.jsx($s,{asChild:!0,children:s.jsx("button",{type:"button",className:me("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground",ae?"opacity-100 pointer-events-auto":b?"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":D("sessions.sidebar.project.actions.projectMenu"),onPointerDown:we,onMouseDown:W,onClick:pe,children:s.jsx(la,{className:"h-3.5 w-3.5"})})}),s.jsxs(Bs,{align:"end",className:"min-w-[180px]",children:[A&&!u&&!h&&g&&s.jsxs(Lt,{onClick:g,children:[s.jsx(zs,{className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.newSession")]}),s.jsxs(Lt,{onClick:v,children:[s.jsx(Fi,{className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.session.menu.rename")]}),s.jsxs(Lt,{onClick:S,className:"text-destructive focus:text-destructive",children:[s.jsx(Is,{className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.closeProject")]})]})]})]}),A&&g?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:fe=>{fe.stopPropagation(),g()},className:me("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",b?"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":D(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(zs,{className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:D(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})})]}),e[24]=z,e[25]=b,e[26]=$,e[27]=Se,e[28]=Z,e[29]=h,e[30]=N,e[31]=J,e[32]=n,e[33]=te,e[34]=m,e[35]=p,e[36]=f,e[37]=ae,e[38]=u,e[39]=y,e[40]=F,e[41]=S,e[42]=g,e[43]=w,e[44]=v,e[45]=a,e[46]=d,e[47]=r,e[48]=P,e[49]=A,e[50]=D,e[51]=je):je=e[51];let be;return e[52]!==j||e[53]!==_||e[54]!==Ne||e[55]!==he||e[56]!==je?(be=s.jsxs("div",{ref:_,style:Ne,className:he,children:[je,j]}),e[52]=j,e[53]=_,e[54]=Ne,e[55]=he,e[56]=je,e[57]=be):be=e[57],be},wD=t=>{const e=nt.c(21),{id:n,disabled:r,children:a}=t,i=r===void 0?!1:r;let o;e[0]!==i||e[1]!==n?(o={id:n,disabled:i},e[0]=i,e[1]=n,e[2]=o):o=e[2];const{listeners:c,setNodeRef:d,setActivatorNodeRef:p,transform:m,transition:u,isDragging:f}=yu(o);let y;e[3]!==c||e[4]!==p?(y={listeners:c,setActivatorNodeRef:p},e[3]=c,e[4]=p,e[5]=y):y=e[5];const h=y;let b;e[6]!==m?(b=vu.Transform.toString(m),e[6]=m,e[7]=b):b=e[7];let x;e[8]!==b||e[9]!==u?(x={transform:b,transition:u},e[8]=b,e[9]=u,e[10]=x):x=e[10];const g=f&&"opacity-50";let w;e[11]!==g?(w=me("space-y-0.5 rounded-md",g),e[11]=g,e[12]=w):w=e[12];let v;e[13]!==a||e[14]!==h?(v=typeof a=="function"?a(h):a,e[13]=a,e[14]=h,e[15]=v):v=e[15];let S;return e[16]!==d||e[17]!==x||e[18]!==w||e[19]!==v?(S=s.jsx("div",{ref:d,style:x,className:w,children:v}),e[16]=d,e[17]=x,e[18]=w,e[19]=v,e[20]=S):S=e[20],S},jD=l.memo(wD);function ND(t){t.stopPropagation()}function SD(t){t.stopPropagation()}function kD(t){t.stopPropagation()}function CD(t){const e=nt.c(25),{t:n}=ut();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:ov},e[1]=a):a=e[1];const i=$l(vo(Bl,r),vo(av,a));let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o={activationConstraint:{distance:8}},e[2]=o):o=e[2];const c=$l(vo(Bl,o));if(t.projectSections.length===0){const f=(t.mobileVariant,"");let y;e[3]!==f?(y=me("space-y-1 pb-1 pl-2.5 pr-2",f),e[3]=f,e[4]=y):y=e[4];let h;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==y?(h=s.jsxs(Ps,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:y,children:[t.topContent,t.emptyState]}),e[5]=t.emptyState,e[6]=t.topContent,e[7]=y,e[8]=h):h=e[8],h}if(t.sectionsForRender.length===0){const f=(t.mobileVariant,"");let y;e[9]!==f?(y=me("space-y-1 pb-1 pl-2.5 pr-2",f),e[9]=f,e[10]=y):y=e[10];let h;return e[11]!==t.searchEmptyState||e[12]!==y?(h=s.jsx(Ps,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:y,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=y,e[13]=h):h=e[13],h}const d=(t.mobileVariant,"");let p;e[14]!==d?(p=me("space-y-1 pb-1 pl-2.5 pr-2",d),e[14]=d,e[15]=p):p=e[15];let m;e[16]!==c||e[17]!==i||e[18]!==t||e[19]!==n?(m=t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const f=t.sectionsForRender.find(x=>x.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!f)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const y=f.groups.find(ED)??f.groups.find(RD)??f.groups.find(MD)??f.groups[0];if(!y)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")});const h=f.groups.find(TD);return[y,...h&&h.id!==y.id?[h]:[]].map(x=>{const g=`${f.project.id}:${x.id}`,w=x.id===y.id;return s.jsx(l.Fragment,{children:t.renderGroupSessions(x,g,f.project.id,w,null,!0)},g)})})()}):s.jsx(s.Fragment,{children:s.jsxs(Vl,{sensors:i,collisionDetection:zl,onDragEnd:f=>{if(t.isInlineEditing)return;const{active:y,over:h}=f;if(!h||y.id===h.id)return;const b=t.sectionsForRender.findIndex(g=>g.project.id===y.id),x=t.sectionsForRender.findIndex(g=>g.project.id===h.id);b===-1||x===-1||b===x||t.reorderProjects(b,x)},children:[s.jsx(Pd,{items:t.sectionsForRender.map(DD),strategy:fm,children:t.sectionsForRender.map(f=>{const y=f.project,h=y.id,b=Rg(y.label?.trim()||ii(y.normalizedPath,t.homeDirectory)||y.normalizedPath),x=Ro(y.normalizedPath,t.homeDirectory),g=t.collapsedProjects.has(h),w=h===t.activeProjectId,v=t.projectRepoStatus.get(h),S=t.getOrderedGroups(h,f.groups),P=S.find(PD)??null,j=P?S.filter(C=>C.id!==P.id):S;return s.jsx(vD,{id:h,projectLabel:b,projectDescription:x,projectIcon:y.icon,projectColor:y.color,projectIconImage:y.iconImage,projectIconBackground:y.iconBackground,isCollapsed:g,isActiveProject:w,isRepo:!!v,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(h),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onToggle:()=>t.toggleProject(h),onNewSession:()=>{h!==t.activeProjectId&&t.setActiveProjectIdOnly(h),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:y.normalizedPath})},onNewWorktreeSession:()=>{h!==t.activeProjectId&&t.setActiveProjectIdOnly(h),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(h),onClose:()=>t.removeProject(h),sentinelRef:C=>{t.projectHeaderSentinelRefs.current.set(h,C)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:g?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:f.groups.length>0?s.jsxs(Vl,{sensors:c,collisionDetection:zl,onDragEnd:C=>{if(t.isInlineEditing)return;const{active:I,over:R}=C;if(!R||I.id===R.id)return;const k=j.findIndex(T=>T.id===I.id),A=j.findIndex(T=>T.id===R.id);if(k===-1||A===-1||k===A)return;const N=iv(j,k,A).map(AD),D=P?[P.id,...N]:N;t.setGroupOrderByProject(T=>{const M=new Map(T);return M.set(h,D),M})},children:[P?t.renderGroupSessions(P,`${h}:${P.id}`,h,!0):null,s.jsx(Pd,{items:j.map(ID),strategy:fm,children:j.map(C=>{const I=`${h}:${C.id}`;return s.jsx(jD,{id:C.id,disabled:t.isInlineEditing,children:R=>t.renderGroupSessions(C,I,h,!1,R)},C.id)})}),s.jsx(_l,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})},h)})}),s.jsx(_l,{dropAnimation:null})]})}),e[16]=c,e[17]=i,e[18]=t,e[19]=n,e[20]=m):m=e[20];let u;return e[21]!==t.topContent||e[22]!==p||e[23]!==m?(u=s.jsxs(Ps,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:p,children:[t.topContent,m]}),e[21]=t.topContent,e[22]=p,e[23]=m,e[24]=u):u=e[24],u}function ID(t){return t.id}function AD(t){return t.id}function PD(t){return t.isMain}function DD(t){return t.project.id}function TD(t){return t.isArchivedBucket}function MD(t){return t.isMain}function RD(t){return t.sessions.length>0}function ED(t){return t.isMain&&t.sessions.length>0}function FD(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(void 0,{month:"short"}),r=e.getDate(),a=e.getFullYear(),i=String(e.getHours()).padStart(2,"0"),o=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${a}, ${i}:${o}`}function OD(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 LD(t){const e=t.info.role==="user"?"User":"Assistant",n=FD(t.info.time?.created),r=OD(t),a=n&&r?`${n} (${r})`:n||r;return a?`**${e}**
|
|
91
|
+
|
|
92
|
+
*${a}*`:`**${e}**`}function $D(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function eb(t){const e=LD(t),n=$D(t.parts).trim();return n?`${e}
|
|
93
|
+
|
|
94
|
+
${n}`:""}function tb(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",a=`${n} Sub-agent: ${t.title}${r}
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
`,i=t.records.map(eb).filter(Boolean).join(`
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
`),o=[a+i];for(const c of t.children)o.push(tb(c,e+1));return o.join(`
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
`)}function BD(t,e,n){const r=e?.trim()||"Session",a=new Date().toISOString().split("T")[0],i=`# ${r}
|
|
107
|
+
|
|
108
|
+
*Exported on ${a}*
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
`,o=t.map(eb).filter(Boolean).join(`
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
`);let c=i+o;if(n&&n.length>0){const d=n.map(p=>tb(p,1)).join(`
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
`);c+=`
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
`+d}return c}function _D(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 VD(t,e){const n=await ew(e,t);if(n)return n;if(!jn())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 zD(t){const e=yr()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await tw(t)?!0:Hl(t)}function UD(){return zu()}function WD(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 KD=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const a of t){r.has(a)||(r.add(a),n.push(a));const i=e.get(a);if(i)for(const o of i)r.has(o)||(r.add(o),n.push(o))}return n},xr=Nr()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,a)=>{const i=e(),o=new Set(i.selectedIds);let c=i.scopeKey,d=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(o.clear(),c=r,d=null):c===null&&r!==null&&(c=r);const m=a&&a.length>0?[n,...a]:[n];if(o.has(n)){for(const f of m)o.delete(f);d===n&&(d=null)}else{for(const f of m)o.add(f);d=n}o.size===0?t({selectedIds:o,scopeKey:null,anchorId:null}):t({selectedIds:o,scopeKey:c,anchorId:d})},setRange:(n,r,a,i,o)=>{const c=e();if(a.length===0)return;const d=n&&a.includes(n)?n:a[0],p=a.indexOf(d),m=a.indexOf(r);if(p<0||m<0)return;const[u,f]=p<=m?[p,m]:[m,p],y=a.slice(u,f+1),h=KD(y,o),x=i!==null&&c.scopeKey!==null&&i!==c.scopeKey?new Set:new Set(c.selectedIds);for(const g of h)x.add(g);t({selectedIds:x,scopeKey:i??c.scopeKey,anchorId:d})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const a=new Set(r.selectedIds);for(const i of n)a.delete(i);a.size!==r.selectedIds.size&&(a.size===0?t({selectedIds:a,scopeKey:null,anchorId:null}):t({selectedIds:a}))}})),ff=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),Va=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(Va(n,e))return!0;return!1},pu=(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(pu(i,e,n,r))return!0;return!1},HD=(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||ff(t.node)!==ff(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=Va(t.node,t.currentSessionId),u=Va(e.node,e.currentSessionId);if(m||u)return!1}if(t.pinnedSessionIds.has(a)!==e.pinnedSessionIds.has(i)||t.expandedParents.has(a)!==e.expandedParents.has(i)||t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const m=Va(t.node,t.editingId),u=Va(e.node,e.editingId);if(m||u)return!1}if(t.editTitle!==e.editTitle){const m=Va(t.node,t.editingId),u=Va(e.node,e.editingId);if(m||u)return!1}if(t.copiedSessionId===a!=(e.copiedSessionId===i))return!1;const o=pu(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),c=pu(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(o!==c)return!1;const d=Ns(n.directory??null)??Ns(t.groupDirectory??null),p=Ns(r.directory??null)??Ns(e.groupDirectory??null);return!(d!==p||(d?t.directoryStatus.get(d):null)!==(p?e.directoryStatus.get(p):null)||(t.secondaryMeta?.projectLabel??null)!==(e.secondaryMeta?.projectLabel??null)||(t.secondaryMeta?.branchLabel??null)!==(e.secondaryMeta?.branchLabel??null)||t.mobileVariant!==e.mobileVariant||t.alwaysShowActions!==e.alwaysShowActions||(t.renderContext??"project")!==(e.renderContext??"project")||t.renamingFolderId!==e.renamingFolderId)};function GD(t){const{t:e}=ut(),{node:n,depth:r=0,groupDirectory:a,projectId:i,archivedBucket:o=!1,directoryStatus:c,currentSessionId:d,pinnedSessionIds:p,expandedParents:m,hasSessionSearchQuery:u,normalizedSessionSearchQuery:f,notifyOnSubtasks:y,editingId:h,setEditingId:b,editTitle:x,setEditTitle:g,handleSaveEdit:w,handleCancelEdit:v,toggleParent:S,handleSessionSelect:P,handleSessionDoubleClick:j,togglePinnedSession:C,handleShareSession:I,copiedSessionId:R,handleCopyShareUrl:k,handleUnshareSession:A,openSidebarMenuKey:N,setOpenSidebarMenuKey:D,renamingFolderId:T,getFoldersForScope:M,getSessionFolderId:$,removeSessionFromFolder:F,addSessionToFolder:_,createFolderAndStartRename:O,openContextPanelTab:L,handleDeleteSession:K,mobileVariant:B,alwaysShowActions:re,renderSessionNode:oe,secondaryMeta:ee,renderContext:ae="project"}=t,ge=!!ee?.projectLabel,ne=!!ee?.branchLabel,z=Ha(mt=>mt.displayMode)==="minimal",J=l.useMemo(()=>jn(),[]),H=l.useMemo(()=>Ou(),[]),te=J?"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",ce=J?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",Se=!o&&!B,pe=z?J?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":J?Se?"group-hover:pr-12":"group-hover:pr-5":Se?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",we=Se?"pr-13":"pr-7",W=l.useRef(!1),[ue,Y]=l.useState(!1),le=n.session,Ie=lg(le.id)??le,Ne=Ns(le.directory??null)??Ns(a??null),X=sw(Ne??void 0),he=Eg(),je=xr(mt=>mt.enabled),be=xr(l.useCallback(mt=>mt.selectedIds.has(le.id),[le.id])),fe=xr(mt=>mt.toggleSelected),Pe=xr(mt=>mt.setRange),Be=l.useCallback(mt=>{const cs=[],qt=Ds=>{Ds.children.forEach(Os=>{cs.push(Os.session.id),qt(Os)})};return qt(mt),cs},[]),[G,ke]=l.useState(!1),[Ee,Ae]=l.useState(!0),xe=`${ae}:${o?"archived":"active"}:${le.id}`,V=Fg(l.useCallback(mt=>!!mt.sessionMemoryState.get(le.id)?.isZombie,[le.id])),de=nw(le.id),Me=rw(le.id,Ne??void 0),se=(Ne?c.get(Ne):null)==="missing",ie=d===le.id,U=Ie.title||e("sessions.sidebar.session.untitled"),Ve=n.children.length>0,He=p.has(le.id),Ke=u?!0:m.has(le.id),Ze=!!Ie.parentID,dt=aw(le.id)>0&&(!Ze||y),et=Ie.summary,ct=ug(et),at=Ie.time?.updated||Ie.time?.created||Date.now(),ye=iw(at),Ge=dw(at),$e=N===xe,_e=l.useMemo(()=>Be(n).length,[Be,n]),tt=l.useCallback(async mt=>{const cs=[];let qt=0;for(const Ds of mt)try{await he.ensureSessionRenderable(Ds.session.id);const Os=_m(X.getState(),Ds.session.id).list,Q=Ds.session.title||e("sessions.sidebar.session.export.untitledSubagent"),ht=Ds.session.agent,vt=await tt(Ds.children);qt+=vt.skipped,cs.push({title:Q,agent:ht,records:Os,children:vt.children})}catch{qt+=Be(Ds).length+1}return{children:cs,skipped:qt}},[Be,X,he,e]),Qe=l.useCallback(mt=>{mt<=0||q.warning(mt===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:mt}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:mt}))},[e]),ze=l.useCallback(async mt=>{if(!Ne){q.error(e("sessions.sidebar.session.export.nothingToExport"));return}await he.ensureSessionRenderable(le.id);const cs=_m(X.getState(),le.id).list;if(cs.length===0){q.error(e("sessions.sidebar.session.export.nothingToExport"));return}let qt,Ds=0;if(mt&&n.children.length>0){const vt=await tt(n.children);qt=vt.children,Ds=vt.skipped}const Os=BD(cs,Ie.title??null,qt),Q=WD(Ie.title??null),ht=await VD(Os,Q);if(ht){q.success(e("sessions.sidebar.session.export.success"),{action:{label:e(UD()),onClick:()=>{zD(ht).then(vt=>{vt||q.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),Qe(Ds);return}_D(Os,Q),q.success(e("sessions.sidebar.session.export.success")),Qe(Ds)},[tt,X,n.children,Ie.title,le.id,Ne,Qe,he,e]),gt=l.useCallback(async()=>{if(n.children.length>0){Ae(!0),ke(!0);return}await ze(!1)},[ze,n.children.length]),Vt=l.useCallback(()=>{Ne&&Gl("desktop_open_session_mini_chat_window",{sessionId:le.id,directory:Ne}).catch(mt=>{console.warn("[session-sidebar] failed to open mini chat window",mt)})},[le.id,Ne]);if(h===le.id)return s.jsx("div",{className:me("group relative flex items-center rounded-sm px-1.5 py-1",r>0&&"pl-[20px]"),children:s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:[s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:mt=>{mt.preventDefault(),w()},children:[s.jsx("input",{value:x,onChange:mt=>g(mt.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:mt=>{if(mt.key==="Escape"){mt.stopPropagation(),v();return}(mt.key===" "||mt.key==="Enter")&&mt.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(Zs,{className:"size-4"})}),s.jsx("button",{type:"button",onClick:v,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(Is,{className:"size-4"})})]}),z?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:[Ve?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:Ke?s.jsx(ks,{className:"h-3 w-3"}):s.jsx($n,{className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:ye}),ct?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:["+",ct.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",ct.deletions]})]}):null,ge?s.jsx("span",{className:"truncate",children:ee?.projectLabel}):null,ne?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(Qs,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ee?.branchLabel})]}):null]})})]})},le.id);const Kt=de?.type??"idle",Jt=Kt==="busy"||Kt==="retry",At=Me.length,ns=Jt||!Jt&&dt&&!ie,ot=Jt?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")}),Zt=ns||He?s.jsxs("span",{className:me("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",z?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",ns&&He?"left-[-18px] w-6":"left-[-10px] w-3.5",Ve&&!re?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[ns?ot:null,He?s.jsx(gm,{className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,Yt=Ve?s.jsx("span",{role:"button",tabIndex:0,onClick:mt=>{mt.stopPropagation(),S(le.id)},onKeyDown:mt=>{(mt.key==="Enter"||mt.key===" ")&&(mt.preventDefault(),mt.stopPropagation(),S(le.id))},className:me("absolute left-[-10px] inline-flex h-3.5 w-3.5 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",z?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",z&&ns&&!re?"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(Ke?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Ke?s.jsx(ks,{className:"h-3 w-3"}):s.jsx($n,{className:"h-3 w-3"})}):null,es=V?s.jsx(Qr,{className:"h-4 w-4 text-status-warning"}):null,ls=mt=>{D(mt?xe:null)},ds=mt=>{mt.preventDefault(),mt.stopPropagation(),D($e?null:xe)},gs=mt=>{mt.preventDefault(),mt.stopPropagation()},us=mt=>{mt.preventDefault(),mt.stopPropagation()},Ct=mt=>{mt.preventDefault(),mt.stopPropagation()},Ue=mt=>{mt.preventDefault(),mt.stopPropagation()},Dt=mt=>{mt.preventDefault(),mt.stopPropagation(),D(null),K(le,{archivedBucket:o})},Tt=mt=>{if(W.current){W.current=!1;return}if(je){if(mt?.preventDefault(),mt?.stopPropagation(),mt?.shiftKey){const qt=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(Q=>Q.getAttribute("data-session-row")).filter(Q=>typeof Q=="string"&&Q.length>0),Ds=xr.getState().anchorId,Os=new Map;Os.set(le.id,Be(n)),Pe(Ds,le.id,qt,Ne??null,Os);return}fe(le.id,Ne??null,Be(n));return}P(le.id,Ne,se,i)},wt=mt=>{(mt.button===2||mt.button===0&&mt.ctrlKey&&!je)&&(W.current=!0)},Wt=mt=>{B&&mt.pointerType==="touch"&&Y(!0)},_t=mt=>{B&&mt.pointerType==="touch"&&Y(!1)},Vs=s.jsxs(Bs,{align:"end",className:"min-w-[180px]",onCloseAutoFocus:mt=>{T&&mt.preventDefault()},children:[s.jsxs(Lt,{onClick:()=>{b(le.id),g(U)},className:"[&>svg]:mr-1",children:[s.jsx(Fi,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(Lt,{onClick:()=>C(le.id),className:"[&>svg]:mr-1",children:[He?s.jsx(lv,{className:"mr-1 h-4 w-4"}):s.jsx(gm,{className:"mr-1 h-4 w-4"}),e(He?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),Ie.share?s.jsxs(s.Fragment,{children:[s.jsx(Lt,{onClick:()=>{Ie.share?.url&&k(Ie.share.url,le.id)},className:"[&>svg]:mr-1",children:R===le.id?s.jsxs(s.Fragment,{children:[s.jsx(Zs,{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(vr,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(Lt,{onClick:()=>A(le.id),className:"[&>svg]:mr-1",children:[s.jsx(dv,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Lt,{onClick:()=>I(Ie),className:"[&>svg]:mr-1",children:[s.jsx(cv,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(Lt,{onClick:()=>{gt()},className:"[&>svg]:mr-1",children:[s.jsx(Xr,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),Ne&&!o?(()=>{const mt=M(Ne),cs=$(Ne,le.id);return s.jsxs(s.Fragment,{children:[s.jsx(Ln,{}),s.jsxs(ow,{children:[s.jsxs(lw,{className:"[&>svg]:mr-1",children:[s.jsx(Un,{className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(cw,{className:"min-w-[180px]",children:[mt.length===0?s.jsx(Lt,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):mt.map(qt=>s.jsxs(Lt,{onClick:()=>{cs===qt.id?F(Ne,le.id):_(Ne,qt.id,le.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:qt.name}),cs===qt.id?s.jsx(Zs,{className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},qt.id)),s.jsx(Ln,{}),s.jsxs(Lt,{onClick:()=>{const qt=O(Ne);qt&&_(Ne,qt.id,le.id)},children:[s.jsx(zs,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),cs?s.jsxs(Lt,{onClick:()=>{F(Ne,le.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(Is,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,J?null:s.jsxs(Lt,{disabled:!Ne,onClick:()=>{Ne&&L(Ne,{mode:"chat",dedupeKey:`session:${le.id}`,label:U})},className:"[&>svg]:mr-1",children:[s.jsx(mc,{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")})]}),H?s.jsxs(Lt,{disabled:!Ne,onClick:Vt,className:"[&>svg]:mr-1",children:[s.jsx(jo,{className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Ln,{}),s.jsxs(Lt,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>K(le,{archivedBucket:o}),children:[s.jsx(an,{className:"mr-1 h-4 w-4"}),e(o?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(l.Fragment,{children:[s.jsx(XP,{sessionId:le.id,sessionDirectory:Ne??null,sessionTitle:U,children:s.jsxs("div",{"data-session-row":le.id,"data-session-scope":Ne??"","data-session-archived":o?"1":"0",className:me("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",se?"opacity-75":"",r>0&&"pl-[20px]",be&&"bg-primary/15"),children:[Zt,Yt,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:z?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",disabled:se,onPointerDown:Wt,onPointerUp:_t,onPointerCancel:_t,onMouseDown:wt,onClick:mt=>Tt(mt),onDoubleClick:mt=>{mt.stopPropagation(),j()},className:me("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ue&&"bg-interactive-hover/70",re?J?pe:we:pe),children:s.jsxs("div",{className:me("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:me("block min-w-0 flex-1 truncate typography-ui-label font-normal",ie?"text-primary":"text-foreground"),children:Co(U,f)}),re?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Ge}):null,re?null:s.jsx("div",{className:"relative ml-1 flex h-4 min-w-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:me("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",$e?"opacity-0":ce),children:Ge})}),At>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(xm,{className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:At})]}):null]})})}),s.jsx(It,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex flex-col gap-1 text-left text-xs",children:[s.jsxs("div",{className:me("flex items-center gap-3 text-left text-muted-foreground",ee?.projectLabel?"justify-between":"justify-start"),children:[ee?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:ee.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:ye})]}),ee?.branchLabel||ct?s.jsxs("div",{className:me("flex items-center gap-3 text-left text-muted-foreground",ee?.branchLabel?"justify-between":"justify-start"),children:[ee?.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(Qs,{className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ee.branchLabel})]})}):null,ct?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",ct.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",ct.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:se,onPointerDown:Wt,onPointerUp:_t,onPointerCancel:_t,onMouseDown:wt,onClick:mt=>Tt(mt),onDoubleClick:mt=>{mt.stopPropagation(),j()},className:me("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ue&&"bg-interactive-hover/70",re?J?pe:we:pe),children:[s.jsxs("div",{className:me("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:me("block min-w-0 flex-1 truncate typography-ui-label font-normal",ie?"text-primary":"text-foreground"),children:Co(U,f)}),At>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(xm,{className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:At})]}):null]}),z?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:ye}),ct?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:["+",ct.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",ct.deletions]})]}):null,ge?s.jsx("span",{className:"truncate",children:ee?.projectLabel}):null,ne?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(Qs,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ee?.branchLabel})]}):null]})})]})}),es&&!B?s.jsx("div",{className:me("absolute top-1/2 -translate-y-1/2 z-10",z?"right-0":"right-[30px]"),children:es}):null,s.jsxs("div",{className:me("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",$e||re&&!J?"opacity-100":me("opacity-0",te)),children:[Se?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",className:me("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",z&&!re?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:Ct,onMouseDown:Ue,onClick:Dt,onKeyDown:mt=>mt.stopPropagation(),children:s.jsx($d,{className:me(z&&!re?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(It,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,s.jsxs(_s,{open:$e,onOpenChange:ls,children:[s.jsx($s,{asChild:!0,children:s.jsx("button",{type:"button",className:me("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",z&&!re?$e?"h-4 w-4 opacity-100":me("h-4 w-4 opacity-0",te):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:gs,onMouseDown:us,onClick:ds,onKeyDown:mt=>mt.stopPropagation(),children:s.jsx(la,{className:me(z&&!re?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),Vs]})]})]})}),Ve&&Ke?n.children.map(mt=>oe(mt,r+1,Ne??a,i,o,void 0,ae)):null,s.jsx(ws,{open:G,onOpenChange:ke,children:s.jsxs(vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Fs,{children:_e===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:_e}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:_e})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:Ee,onChange:mt=>Ae(mt.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(Xs,{children:[s.jsx(ve,{type:"button",onClick:()=>ke(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{type:"button",onClick:()=>{ke(!1),ze(Ee)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})})]},le.id)}const qD=l.memo(GD,HD);function QD(t){const e=nt.c(71),{t:n}=ut(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:o,onConfirm:c}=t;let d,p,m,u,f,y,h,b,x,g;if(e[0]!==a||e[1]!==n||e[2]!==r){const O=n("sessions.sidebar.session.untitled");u=ws,x=!!r,e[13]!==a?(g=K=>{K||a(null)},e[13]=a,e[14]=g):g=e[14],m=vs,h=!1,b="max-w-sm gap-5",p=Cs;let L;e[15]!==n||e[16]!==r?.archivedBucket?(L=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=L):L=e[17],e[18]!==L?(y=s.jsx(js,{children:L}),e[18]=L,e[19]=y):y=e[19],d=Fs,f=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]=p,e[5]=m,e[6]=u,e[7]=f,e[8]=y,e[9]=h,e[10]=b,e[11]=x,e[12]=g}else d=e[3],p=e[4],m=e[5],u=e[6],f=e[7],y=e[8],h=e[9],b=e[10],x=e[11],g=e[12];let w;e[20]!==d||e[21]!==f?(w=s.jsx(d,{children:f}),e[20]=d,e[21]=f,e[22]=w):w=e[22];let v;e[23]!==p||e[24]!==y||e[25]!==w?(v=s.jsxs(p,{children:[y,w]}),e[23]=p,e[24]=y,e[25]=w,e[26]=v):v=e[26];let S;e[27]!==o||e[28]!==i?(S=()=>o(!i),e[27]=o,e[28]=i,e[29]=S):S=e[29];const P=!i;let j;e[30]!==i?(j=i?s.jsx(Li,{className:"h-4 w-4"}):s.jsx(Oi,{className:"h-4 w-4 text-primary"}),e[30]=i,e[31]=j):j=e[31];let C;e[32]!==n?(C=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=C):C=e[33];let I;e[34]!==j||e[35]!==C||e[36]!==S||e[37]!==P?(I=s.jsxs("button",{type:"button",onClick:S,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":P,children:[j,C]}),e[34]=j,e[35]=C,e[36]=S,e[37]=P,e[38]=I):I=e[38];let R;e[39]!==a?(R=()=>a(null),e[39]=a,e[40]=R):R=e[40];let k;e[41]!==n?(k=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=k):k=e[42];let A;e[43]!==R||e[44]!==k?(A=s.jsx("button",{type:"button",onClick:R,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:k}),e[43]=R,e[44]=k,e[45]=A):A=e[45];let N;e[46]!==c?(N=()=>{c()},e[46]=c,e[47]=N):N=e[47];let D;e[48]!==n||e[49]!==r?.archivedBucket?(D=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=D):D=e[50];let T;e[51]!==N||e[52]!==D?(T=s.jsx("button",{type:"button",onClick:N,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:D}),e[51]=N,e[52]=D,e[53]=T):T=e[53];let M;e[54]!==A||e[55]!==T?(M=s.jsxs("div",{className:"flex items-center gap-2",children:[A,T]}),e[54]=A,e[55]=T,e[56]=M):M=e[56];let $;e[57]!==I||e[58]!==M?($=s.jsxs(Xs,{className:"w-full sm:items-center sm:justify-between",children:[I,M]}),e[57]=I,e[58]=M,e[59]=$):$=e[59];let F;e[60]!==m||e[61]!==h||e[62]!==$||e[63]!==b||e[64]!==v?(F=s.jsxs(m,{showCloseButton:h,className:b,children:[v,$]}),e[60]=m,e[61]=h,e[62]=$,e[63]=b,e[64]=v,e[65]=F):F=e[65];let _;return e[66]!==u||e[67]!==F||e[68]!==x||e[69]!==g?(_=s.jsx(u,{open:x,onOpenChange:g,children:F}),e[66]=u,e[67]=F,e[68]=x,e[69]=g,e[70]=_):_=e[70],_}function JD(t){const e=nt.c(57),{t:n}=ut(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:o,onConfirm:c}=t,d=r?.archivedBucket===!0,p=r?.sessionCount??0;let m;e[0]!==d||e[1]!==p||e[2]!==n?(m=n(d?p===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":p===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=p,e[2]=n,e[3]=m):m=e[3];const u=m;let f;e[4]!==d||e[5]!==p||e[6]!==n?(f=d?p===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:p}):p===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:p}),e[4]=d,e[5]=p,e[6]=n,e[7]=f):f=e[7];const y=f,h=!!r;let b;e[8]!==a?(b=_=>{_||a(null)},e[8]=a,e[9]=b):b=e[9];let x;e[10]!==u?(x=s.jsx(js,{children:u}),e[10]=u,e[11]=x):x=e[11];let g;e[12]!==y?(g=s.jsx(Fs,{children:y}),e[12]=y,e[13]=g):g=e[13];let w;e[14]!==x||e[15]!==g?(w=s.jsxs(Cs,{children:[x,g]}),e[14]=x,e[15]=g,e[16]=w):w=e[16];let v;e[17]!==o||e[18]!==i?(v=()=>o(!i),e[17]=o,e[18]=i,e[19]=v):v=e[19];const S=!i;let P;e[20]!==i?(P=i?s.jsx(Li,{className:"h-4 w-4"}):s.jsx(Oi,{className:"h-4 w-4 text-primary"}),e[20]=i,e[21]=P):P=e[21];let j;e[22]!==n?(j=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=j):j=e[23];let C;e[24]!==j||e[25]!==v||e[26]!==S||e[27]!==P?(C=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":S,children:[P,j]}),e[24]=j,e[25]=v,e[26]=S,e[27]=P,e[28]=C):C=e[28];let I;e[29]!==a?(I=()=>a(null),e[29]=a,e[30]=I):I=e[30];let R;e[31]!==n?(R=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=R):R=e[32];let k;e[33]!==I||e[34]!==R?(k=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:R}),e[33]=I,e[34]=R,e[35]=k):k=e[35];let A;e[36]!==c?(A=()=>{c()},e[36]=c,e[37]=A):A=e[37];let N;e[38]!==d||e[39]!==n?(N=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=N):N=e[40];let D;e[41]!==A||e[42]!==N?(D=s.jsx("button",{type:"button",onClick:A,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:N}),e[41]=A,e[42]=N,e[43]=D):D=e[43];let T;e[44]!==k||e[45]!==D?(T=s.jsxs("div",{className:"flex items-center gap-2",children:[k,D]}),e[44]=k,e[45]=D,e[46]=T):T=e[46];let M;e[47]!==C||e[48]!==T?(M=s.jsxs(Xs,{className:"w-full sm:items-center sm:justify-between",children:[C,T]}),e[47]=C,e[48]=T,e[49]=M):M=e[49];let $;e[50]!==M||e[51]!==w?($=s.jsxs(vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[w,M]}),e[50]=M,e[51]=w,e[52]=$):$=e[52];let F;return e[53]!==h||e[54]!==$||e[55]!==b?(F=s.jsx(ws,{open:h,onOpenChange:b,children:$}),e[53]=h,e[54]=$,e[55]=b,e[56]=F):F=e[56],F}function YD(t){const e=nt.c(36),{t:n}=ut(),{value:r,setValue:a,onConfirm:i}=t,o=!!r;let c;e[0]!==a?(c=P=>{P||a(null)},e[0]=a,e[1]=c):c=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let p;e[4]!==d?(p=s.jsx(js,{children:d}),e[4]=d,e[5]=p):p=e[5];let m;e[6]!==n||e[7]!==r?(m=r&&(r.subFolderCount>0||r.sessionCount>0)?r.subFolderCount>0?r.subFolderCount===1?n("sessions.sidebar.dialogs.deleteFolder.withOneSubfolder",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withManySubfolders",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withContentsNoSubfolders",{folderName:r.folderName}):n("sessions.sidebar.dialogs.deleteFolder.single",{folderName:r?.folderName??""}),e[6]=n,e[7]=r,e[8]=m):m=e[8];let u;e[9]!==m?(u=s.jsx(Fs,{children:m}),e[9]=m,e[10]=u):u=e[10];let f;e[11]!==p||e[12]!==u?(f=s.jsxs(Cs,{children:[p,u]}),e[11]=p,e[12]=u,e[13]=f):f=e[13];let y;e[14]!==a?(y=()=>a(null),e[14]=a,e[15]=y):y=e[15];let h;e[16]!==n?(h=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=h):h=e[17];let b;e[18]!==y||e[19]!==h?(b=s.jsx("button",{type:"button",onClick:y,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:h}),e[18]=y,e[19]=h,e[20]=b):b=e[20];let x;e[21]!==n?(x=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=x):x=e[22];let g;e[23]!==i||e[24]!==x?(g=s.jsx("button",{type:"button",onClick:i,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:x}),e[23]=i,e[24]=x,e[25]=g):g=e[25];let w;e[26]!==g||e[27]!==b?(w=s.jsxs(Xs,{children:[b,g]}),e[26]=g,e[27]=b,e[28]=w):w=e[28];let v;e[29]!==w||e[30]!==f?(v=s.jsxs(vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[f,w]}),e[29]=w,e[30]=f,e[31]=v):v=e[31];let S;return e[32]!==o||e[33]!==c||e[34]!==v?(S=s.jsx(ws,{open:o,onOpenChange:c,children:v}),e[32]=o,e[33]=c,e[34]=v,e[35]=S):S=e[35],S}const XD=t=>{const e=nt.c(46),{selectedCount:n,scopeKey:r,scopeFolders:a,archivedBucket:i,onMoveToFolder:o,onCreateFolderAndMove:c,onRemoveFromFolder:d,canRemoveFromFolder:p,onDelete:m,onDone:u}=t,{t:f}=ut(),y=!!r&&!i;let h;e[0]!==i||e[1]!==f?(h=f(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=f,e[2]=h):h=e[2];const b=h;let x;e[3]!==n||e[4]!==f?(x=f("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=f,e[5]=x):x=e[5];let g;e[6]!==x?(g=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:x}),e[6]=x,e[7]=g):g=e[7];let w;e[8]!==y||e[9]!==p||e[10]!==c||e[11]!==o||e[12]!==d||e[13]!==a||e[14]!==f?(w=y?s.jsxs(_s,{children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx($s,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":f("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(Un,{className:"h-4 w-4"})})})}),s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:f("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Bs,{align:"end",className:"min-w-[180px]",children:[a.length===0?s.jsx(Lt,{disabled:!0,className:"text-muted-foreground",children:f("sessions.sidebar.folders.none")}):a.map($=>s.jsx(Lt,{onClick:()=>o($.id),children:s.jsx("span",{className:"flex-1 truncate",children:$.name})},$.id)),s.jsx(Ln,{}),s.jsxs(Lt,{onClick:c,children:[s.jsx(zs,{className:"mr-1 h-4 w-4"}),f("sessions.sidebar.folders.newFolderEllipsis")]}),p?s.jsxs(Lt,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(Is,{className:"mr-1 h-4 w-4"}),f("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=y,e[9]=p,e[10]=c,e[11]=o,e[12]=d,e[13]=a,e[14]=f,e[15]=w):w=e[15];let v;e[16]===Symbol.for("react.memo_cache_sentinel")?(v=me("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[16]=v):v=e[16];let S;e[17]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(an,{className:"h-4 w-4"}),e[17]=S):S=e[17];let P;e[18]!==b||e[19]!==m?(P=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:v,"aria-label":b,children:S})}),e[18]=b,e[19]=m,e[20]=P):P=e[20];let j;e[21]!==b?(j=s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:b})}),e[21]=b,e[22]=j):j=e[22];let C;e[23]!==P||e[24]!==j?(C=s.jsxs(St,{children:[P,j]}),e[23]=P,e[24]=j,e[25]=C):C=e[25];let I;e[26]!==f?(I=f("sessions.sidebar.header.actions.exitSelection"),e[26]=f,e[27]=I):I=e[27];let R;e[28]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(Is,{className:"h-4 w-4"}),e[28]=R):R=e[28];let k;e[29]!==u||e[30]!==I?(k=s.jsx(kt,{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:R})}),e[29]=u,e[30]=I,e[31]=k):k=e[31];let A;e[32]!==f?(A=f("sessions.sidebar.header.actions.exitSelection"),e[32]=f,e[33]=A):A=e[33];let N;e[34]!==A?(N=s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:A})}),e[34]=A,e[35]=N):N=e[35];let D;e[36]!==k||e[37]!==N?(D=s.jsxs(St,{children:[k,N]}),e[36]=k,e[37]=N,e[38]=D):D=e[38];let T;e[39]!==D||e[40]!==w||e[41]!==C?(T=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[w,C,D]}),e[39]=D,e[40]=w,e[41]=C,e[42]=T):T=e[42];let M;return e[43]!==T||e[44]!==g?(M=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[g,T]}),e[43]=T,e[44]=g,e[45]=M):M=e[45],M},sb="oc.sessions.activeNow",ZD=2160*60*1e3,nb=t=>!!t.parentID,rm=t=>!!t.time?.archived,hu=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},eT=t=>{try{const e=t.getItem(sb);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,a=[];return n.forEach(i=>{const o=typeof i=="string"?i:i&&typeof i=="object"&&"sessionId"in i&&typeof i.sessionId=="string"?i.sessionId:null;!o||r.has(o)||(r.add(o),a.push({sessionId:o}))}),a}catch{return[]}},gf=(t,e)=>{try{t.setItem(sb,JSON.stringify(e))}catch{}},tT=(t,e,n=Date.now())=>{const r=n-ZD;return t.filter(a=>{const i=e.get(a.sessionId);return i?rm(i)?!1:hu(i)>=r:!0})},sT=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],rb=t=>[...t].sort((e,n)=>hu(n)-hu(e)),nT=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!rm(r)).filter(r=>!nb(r));return rb(n)},rT=(t,e)=>{const n=t.filter(r=>{if(rm(r)||nb(r))return!1;const a=e[r.id];return a?.type==="busy"||a?.type==="retry"});return rb(n)},vl="oc.sessions.projectCollapse",xf="oc.sessions.groupOrder",bf="oc.sessions.groupCollapse",yf="oc.sessions.activeSessionByProject",Nd="oc.sessions.expandedParents",vf="oc.sessions.pinned",aT=(t,e)=>{const n=new Set;for(const r of t){const a=Ns(r.path)?.toLowerCase();a&&n.add(a)}for(const r of e.values())for(const a of r){const i=Ns(a.path)?.toLowerCase();i&&n.add(i)}return n},iT=(t,e)=>{if(t.time?.archived)return!0;const n=Ns(Il(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},oT=5*6e4,wf=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:a=!1})=>{const{t:i}=ut(),[o,c]=l.useState(!1),[d,p]=l.useState(""),m=l.useRef(null),u=l.useRef(null),f=l.useRef(new Set),[y,h]=l.useState(null),[b,x]=l.useState(""),[g,w]=l.useState(null),[v,S]=l.useState(new Set),[P]=l.useState(()=>new Map),j=l.useMemo(()=>va(),[]),[C,I]=l.useState(()=>eT(j)),[R,k]=l.useState(new Set),[A,N]=l.useState(new Map),[D,T]=l.useState(new Set),[M,$]=l.useState(!1),[F,_]=l.useState(!1),[O,L]=l.useState(null),[K,B]=l.useState(null),[re,oe]=l.useState(""),[ee,ae]=l.useState(null),[ge,ne]=l.useState(null),[E,z]=l.useState(null),[J,H]=l.useState(()=>{try{const Te=va().getItem(vf);if(!Te)return new Set;const bt=JSON.parse(Te);return new Set(Array.isArray(bt)?bt.filter(lt=>typeof lt=="string"):[])}catch{return new Set}}),[te,ce]=l.useState(()=>{try{const Te=va().getItem(bf);if(!Te)return new Set;const bt=JSON.parse(Te);return new Set(Array.isArray(bt)?bt.filter(lt=>typeof lt=="string"):[])}catch{return new Set}}),[Se,pe]=l.useState(()=>{try{const Te=va().getItem(xf);if(!Te)return new Map;const bt=JSON.parse(Te),lt=new Map;return Object.entries(bt).forEach(([Qt,Ts])=>{Array.isArray(Ts)&<.set(Qt,Ts.filter(Ce=>typeof Ce=="string"))}),lt}catch{return new Map}}),[we,W]=l.useState(()=>{try{const Te=va().getItem(yf);if(!Te)return new Map;const bt=JSON.parse(Te),lt=new Map;return Object.entries(bt).forEach(([Qt,Ts])=>{typeof Ts=="string"&&Ts.length>0&<.set(Qt,Ts)}),lt}catch{return new Map}}),[ue,Y]=l.useState(new Map),le=l.useRef(new Map),Z=l.useRef(0),Ie=qs(Te=>Te.homeDirectory),Ne=qs(Te=>Te.currentDirectory),X=qs(Te=>Te.setDirectory),he=Es(Te=>Te.projects),je=Es(Te=>Te.activeProjectId),be=Es(Te=>Te.removeProject),fe=Es(Te=>Te.setActiveProjectIdOnly),Pe=Es(Te=>Te.updateProjectMeta),Be=Es(Te=>Te.reorderProjects),G=De(Te=>Te.setActiveMainTab),ke=De(Te=>Te.openContextPanelTab),Ee=De(Te=>Te.setSettingsDialogOpen),Ae=De(Te=>Te.toggleHelpDialog),xe=De(Te=>Te.setAboutDialogOpen),V=De(Te=>Te.setSessionSwitcherOpen),de=De(Te=>Te.setScheduledTasksDialogOpen),Me=De(Te=>Te.toggleSidebar),Le=De(Te=>Te.openMultiRunLauncher),se=De(Te=>Te.notifyOnSubtasks),ie=De(Te=>Te.showDeletionDialog),U=De(Te=>Te.setShowDeletionDialog),Ve=vc(d,120),He=l.useMemo(()=>Ve.trim().toLowerCase(),[Ve]),Ke=He.length>0,Ze=rr(Te=>Te.collapsedFolderIds),Xe=rr(Te=>Te.foldersMap),dt=rr(Te=>Te.getFoldersForScope),et=rr(Te=>Te.createFolder),ct=rr(Te=>Te.renameFolder),at=rr(Te=>Te.deleteFolder),ye=rr(Te=>Te.addSessionToFolder),Ge=rr(Te=>Te.addSessionsToFolder),$e=rr(Te=>Te.removeSessionFromFolder),_e=rr(Te=>Te.removeSessionsFromFolders),tt=rr(Te=>Te.toggleFolderCollapse),Qe=rr(Te=>Te.cleanupSessions),ze=rr(Te=>Te.getSessionFolderId);xP({isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchContainerRef:m});const gt=Ig(),Vt=Eg(),Kt=cg(),Jt=uw(),At=So(Te=>Te.hasLoaded),jt=So(Te=>Te.activeSessions),ns=So(Te=>Te.archivedSessions),ot=Ht(Te=>Te.currentSessionId),Zt=Ht(Te=>!!Te.newSessionDraft?.open),Yt=Ht(Te=>Te.setCurrentSession),es=Ht(Te=>Te.updateSessionTitle),ls=Ht(Te=>Te.shareSession),ds=Ht(Te=>Te.unshareSession),gs=Ht(Te=>Te.worktreeMetadata),us=Ht(Te=>Te.availableWorktreesByProject),Ct=Ht(Te=>Te.openNewSessionDraft),Ue=Ya(Sr(Te=>({checkForUpdates:Te.checkForUpdates,available:Te.available,runtimeType:Te.runtimeType,info:Te.info,downloading:Te.downloading,downloaded:Te.downloaded,progress:Te.progress,error:Te.error,downloadUpdate:Te.downloadUpdate,restartToUpdate:Te.restartToUpdate}))),Dt=l.useMemo(()=>aT(he,us),[us,he]),Tt=l.useMemo(()=>{const Te=new Map(Kt.map(Qt=>[Qt.id,Qt])),bt=jt.map(Qt=>Te.get(Qt.id)??Qt),lt=new Set(bt.map(Qt=>Qt.id));return Kt.forEach(Qt=>{lt.has(Qt.id)||bt.push(Qt)}),bt.filter(Qt=>iT(Qt,Dt))},[jt,Dt,Kt]),wt=l.useMemo(()=>Kt.map(Te=>{const bt=Ns(Te.directory??null)??"";return`${Te.id}:${Te.title??""}:${Te.time?.archived?1:0}:${bt}`}).join("|"),[Kt]),Wt=l.useRef(Kt);l.useEffect(()=>{Wt.current=Kt},[wt,Kt]),l.useEffect(()=>{let Te=!1;const bt=async()=>{const lt=Es.getState().projects;if(lt.length===0)return;const Qt=new Map,Ts=[];await Promise.all(lt.map(async Ce=>{const qe=Ns(Ce.path);if(qe)try{if(!(pn.getState().directories.get(qe)?.isGitRepo??await Mr(()=>import("./modelPrefsAutoSave-DlTpduDU.js").then(Gt=>Gt.eS),__vite__mapDeps([2,0,1,3,4])).then(Gt=>Gt.checkIsGitRepository(qe))))return;const Ot=await _d({id:Ce.id,path:qe});if(Te||Ot.length===0)return;Qt.set(qe,Ot),Ts.push(...Ot)}catch{}})),!Te&&Ht.setState({availableWorktrees:Ts,availableWorktreesByProject:Qt})};return Vd(Wt.current),bt(),()=>{Te=!0}},[Ne,wt,he]),l.useEffect(()=>{let Te=null;const bt=Xx(lt=>{lt.type==="scheduled-task-ran"&&(Te&&clearTimeout(Te),Te=setTimeout(()=>{Vd(Wt.current)},500))});return()=>{Te&&clearTimeout(Te),bt()}},[]);const _t=l.useMemo(()=>Pn(),[]),Vs=fc(),[mt,cs]=l.useState(!1),qt=l.useMemo(()=>jn(),[]),{isTablet:Ds}=dn(),Os=t||Ds,Q=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),ht=!t&&!qt&&!_t,vt=!t&&!qt&&!ht,zt=_t&&Q&&!mt||Vs?"pl-[5.5rem]":"pl-3",ss="app-region-no-drag inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50";l.useEffect(()=>{if(!_t||!Q){cs(!1);return}let Te=!1,bt=null;const lt=async()=>{try{const Ts=await hw();Te||cs(Ts)}catch{Te||cs(!1)}},Qt=async()=>{try{bt=fw(()=>{lt()})}catch{}};return lt(),Qt(),()=>{Te=!0,bt&&bt()}},[_t,Q]);const is=l.useCallback(async Te=>{const bt=Te.target;bt.closest(".app-region-no-drag")||bt.closest("button, a, input, select, textarea")||Te.button===0&&_t&&await Og()},[_t]),{buildGroupSearchText:Ss,filterSessionNodesForSearch:Ms,buildGroupedSessions:We}=gP({homeDirectory:Ie,worktreeMetadata:gs,pinnedSessionIds:J,gitBranches:gt,isVSCode:qt}),{scheduleCollapsedProjectsPersist:xt}=vP({isVSCode:qt,hasLoadedGlobalSessions:At,safeStorage:j,keys:{sessionExpanded:Nd,projectCollapse:vl,sessionPinned:vf,groupOrder:xf,projectActiveSession:yf,groupCollapse:bf},sessions:Tt,pinnedSessionIds:J,setPinnedSessionIds:H,groupOrderByProject:Se,activeSessionByProject:we,collapsedGroups:te,setExpandedParents:S,setCollapsedProjects:k}),Pt=l.useCallback(Te=>{H(bt=>{const lt=new Set(bt);return lt.has(Te)?lt.delete(Te):lt.add(Te),lt})},[]),Mt=l.useMemo(()=>[...Tt].sort((Te,bt)=>Bi(Te,bt,J)),[Tt,J]),as=l.useMemo(()=>new Map(Mt.map((Te,bt)=>[Te.id,bt])),[Mt]),st=l.useMemo(()=>{const Te=new Map;return Mt.forEach(bt=>{const lt=bt.parentID;if(!lt)return;const Qt=Te.get(lt)??[];Qt.push(bt),Te.set(lt,Qt)}),Te.forEach(bt=>bt.sort((lt,Qt)=>Bi(lt,Qt,J))),Te},[Mt,J]),Et=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")})]}),os=l.useMemo(()=>he.find(Te=>Te.id===g)??null,[he,g]),rs=l.useCallback(Te=>{g&&(Pe(g,Te),w(null))},[g,Pe]),$t=l.useCallback(()=>{$(!0)},[]),xs=l.useCallback(()=>{const Te=Ya.getState();if(Te.available&&Te.info){_(!0);return}Ue.checkForUpdates().then(()=>{const{available:bt,error:lt}=Ya.getState();if(lt){q.error(i("sessions.sidebar.updateCheck.errorTitle"),{description:lt});return}if(!bt){q.success(i("sessions.sidebar.updateCheck.latestVersion"));return}_(!0)})},[i,Ue]),bn=l.useCallback(()=>{t&&V(!1),Ee(!0)},[t,V,Ee]),en=Ue.available&&(Ue.runtimeType==="desktop"||Ue.runtimeType==="web"),Ws=Ht(Te=>Te.deleteSession),hn=Ht(Te=>Te.deleteSessions),un=Ht(Te=>Te.archiveSession),fn=Ht(Te=>Te.archiveSessions),{copiedSessionId:gn,handleSessionSelect:yn,handleSessionDoubleClick:mn,handleSaveEdit:Rn,handleCancelEdit:Fr,handleShareSession:Kn,handleCopyShareUrl:Fe,handleUnshareSession:Nt,handleDeleteSession:Xt,confirmDeleteSession:ms}=bP({activeProjectId:je,currentDirectory:Ne,currentSessionId:ot,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:o,sessionSearchQuery:d,setSessionSearchQuery:p,setIsSessionSearchOpen:c,setActiveProjectIdOnly:fe,setDirectory:X,setActiveMainTab:G,setSessionSwitcherOpen:V,setCurrentSession:Yt,updateSessionTitle:es,shareSession:ls,unshareSession:ds,deleteSession:Ws,deleteSessions:hn,archiveSession:un,archiveSessions:fn,childrenMap:st,showDeletionDialog:ie,setDeleteSessionConfirm:ae,deleteSessionConfirm:ee,setEditingId:h,setEditTitle:x,editingId:y,editTitle:b}),tn=l.useCallback(()=>{if(!ge)return;const{scopeKey:Te,folderId:bt}=ge;ne(null),at(Te,bt)},[ge,at]),sn=l.useCallback(()=>{Tr.requestDirectoryDialog()},[]);l.useEffect(()=>{if(!ot)return;const bt=Tt.find(lt=>lt.id===ot)?.parentID;bt&&S(lt=>{if(lt.has(bt))return lt;const Qt=new Set(lt);Qt.add(bt);try{j.setItem(Nd,JSON.stringify(Array.from(Qt)))}catch{}return Qt})},[ot,Tt,j]);const Hs=l.useCallback(Te=>{S(bt=>{const lt=new Set(bt);lt.has(Te)?lt.delete(Te):lt.add(Te);try{j.setItem(Nd,JSON.stringify(Array.from(lt)))}catch{}return lt})},[j]),Gs=l.useCallback((Te,bt)=>{if(!Te)return null;bt&&Ze.has(bt)&&tt(bt);const lt=et(Te,i("sessions.sidebar.folder.newFolderName"),bt);return B(lt.id),oe(lt.name),lt},[Ze,tt,et,i]),nn=l.useCallback(Te=>{T(bt=>{const lt=new Set(bt);return lt.has(Te)?lt.delete(Te):lt.add(Te),lt})},[]),pr=l.useCallback(()=>{Z.current=Date.now()+150,k(()=>{const Te=new Set(he.map(bt=>bt.id));try{j.setItem(vl,JSON.stringify(Array.from(Te)))}catch{}return qt||xt(Te),Te})},[he,qt,j,xt]),lr=l.useCallback(()=>{Z.current=Date.now()+150,k(()=>{const Te=new Set;try{j.setItem(vl,JSON.stringify([]))}catch{}return qt||xt(Te),Te})},[qt,j,xt]),ma=l.useCallback(Te=>{Z.current=Date.now()+150,k(bt=>{const lt=new Set(bt);lt.has(Te)?lt.delete(Te):lt.add(Te);try{j.setItem(vl,JSON.stringify(Array.from(lt)))}catch{}return qt||xt(lt),lt})},[qt,j,xt]),Bn=l.useMemo(()=>he.map(Te=>({...Te,normalizedPath:Ns(Te.path)})).filter(Te=>!!Te.normalizedPath),[he]),Or=l.useMemo(()=>Bn.map(Te=>Te.normalizedPath),[Bn]),{github:_n}=Yn(),nr=sr(Te=>Te.status),vn=sr(Te=>Te.hasChecked),cr=mw(Or),En=br(Te=>Te.ensureEntry),Ur=br(Te=>Te.setParams),Wr=br(Te=>Te.refreshTargets);CP({normalizedProjects:Bn,gitRepoStatus:cr,setProjectRepoStatus:N,setProjectRootBranches:Y});const Pa=Ht(Te=>Te.isLoading);FP({isSessionsLoading:Pa,sessions:Tt,archivedSessions:ns,normalizedProjects:Bn,isVSCode:qt,availableWorktreesByProject:us,cleanupSessions:Qe});const{getSessionsForProject:sa,getArchivedSessionsForProject:Hn}=DP({isVSCode:qt,sessions:Tt,archivedSessions:ns,availableWorktreesByProject:us});lP({normalizedProjects:Bn,sessions:Tt,archivedSessions:ns,availableWorktreesByProject:us,isVSCode:qt,isSessionsLoading:Pa,foldersMap:Xe,createFolder:et,addSessionToFolder:ye,cleanupSessions:Qe});const Nn=l.useRef(!1);je&&A.has(je)&&(Nn.current=!!A.get(je));const{projectSections:ln,groupSearchDataByGroup:kr,sectionsForRender:Kr,searchMatchCount:mi}=uP({normalizedProjects:Bn,getSessionsForProject:sa,getArchivedSessionsForProject:Hn,availableWorktreesByProject:us,projectRepoStatus:A,projectRootBranches:ue,lastRepoStatus:Nn.current,buildGroupedSessions:We,hasSessionSearchQuery:Ke,normalizedSessionSearchQuery:He,filterSessionNodesForSearch:Ms,buildGroupSearchText:Ss,foldersMap:Xe}),pa=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")})]}),pi=!0,{currentSessionDirectory:Dn}=pP({projectSections:ln,activeProjectId:je,activeSessionByProject:we,setActiveSessionByProject:W,currentSessionId:ot,handleSessionSelect:yn,newSessionDraftOpen:Zt,mobileVariant:t,openNewSessionDraft:Ct,setActiveMainTab:G,setSessionSwitcherOpen:V,sessions:Tt,worktreeMetadata:gs}),{getOrderedGroups:hi}=hP(Se),fi=l.useRef(!1);l.useEffect(()=>{if(fi.current||ln.length===0)return;const Te=ln.flatMap(bt=>bt.groups.filter(lt=>lt.isArchivedBucket).map(lt=>`${bt.project.id}:${lt.id}`));Te.length>0&&ce(bt=>new Set([...bt,...Te])),fi.current=!0},[ln]);const gi=l.useMemo(()=>{const Te=new Map,bt=new Map;return ln.forEach(lt=>{const Qt=Rg(lt.project.label?.trim()||ii(lt.project.normalizedPath,Ie)||lt.project.normalizedPath);lt.groups.forEach(Ts=>{const Ce=Ts.branch&&Ts.branch!==Qt?{projectLabel:Qt,branchLabel:Ts.branch}:{projectLabel:Qt,branchLabel:null},qe=pt=>{pt.forEach(ft=>{const Ot=lt.project.normalizedPath.length,Gt=bt.get(ft.session.id)??-1;Ot<Gt||(Te.set(ft.session.id,{node:ft,projectId:lt.project.id,groupDirectory:Ts.directory,secondaryMeta:Ce}),bt.set(ft.session.id,Ot),ft.children.length>0&&qe(ft.children))})};qe(Ts.sessions)})}),Te},[ln,Ie]),Xn=Ha(Te=>Te.showRecentSection),Re=l.useMemo(()=>Xn?nT(C,new Map(Tt.map(Te=>[Te.id,Te]))).sort((Te,bt)=>Bi(Te,bt,J)):[],[C,J,Tt,Xn]),Je=l.useMemo(()=>Xn?rT(Tt,Jt):[],[Jt,Tt,Xn]);l.useEffect(()=>{!Xn||Je.length===0||I(Te=>{const bt=Je.reduce((lt,Qt)=>sT(lt,Qt.id),Te);return bt===Te?Te:(gf(j,bt),bt)})},[Je,j,Xn]),l.useEffect(()=>{if(!Xn)return;const Te=new Map;[...Tt,...ns].forEach(lt=>{Te.set(lt.id,lt)});const bt=tT(C,Te);bt.length===C.length&&bt.every((lt,Qt)=>lt.sessionId===C[Qt]?.sessionId)||(I(bt),gf(j,bt))},[C,ns,j,Tt,Xn]);const Ye=l.useMemo(()=>{if(!Xn)return[];const Te=bt=>{const lt=gi.get(bt.id),Qt=Ns(bt.directory??null);return{node:lt?.node??{session:bt,children:[],worktree:null},projectId:lt?.projectId??null,groupDirectory:lt?.groupDirectory??Qt,secondaryMeta:lt?.secondaryMeta??null}};return[{key:"active-now",title:i("sessions.sidebar.activity.recentTitle"),items:Re.map(Te)}]},[Re,gi,Xn,i]),it=l.useMemo(()=>new Set(Re.map(Te=>Te.id)),[Re]),Ft=l.useMemo(()=>[...it],[it]);C6({currentSessionId:ot,sortedSessions:Mt,recentSessionIds:Ft,ensureSessionRenderable:Vt.ensureSessionRenderable});const Ut=l.useMemo(()=>{if(!qt||Ke||it.size===0)return Kr;const Te=bt=>bt.reduce((lt,Qt)=>{if(it.has(Qt.session.id))return lt;const Ts=Te(Qt.children);return Ts.length===Qt.children.length?(lt.push(Qt),lt):(lt.push({...Qt,children:Ts}),lt)},[]);return Kr.map(bt=>({...bt,groups:bt.groups.map(lt=>({...lt,sessions:Te(lt.sessions)}))}))},[qt,Ke,it,Kr]),Ks=l.useMemo(()=>{const Te=new Set;return Ut.forEach(bt=>{bt.groups.forEach(lt=>{const Qt=Ns(lt.directory??null),Ts=lt.branch?.trim()||gt.get(Qt||"")?.trim();!Qt||!Ts||Te.add(Ao(Qt,Ts))})}),[...Te]},[gt,Ut]),wn=x2(Ks);l.useEffect(()=>{if(!vn||!nr?.connected||!_n)return;const Te=[],bt=Date.now();if(Ut.forEach(Qt=>{R.has(Qt.project.id)||Qt.groups.forEach(Ts=>{const Ce=Ns(Ts.directory??null),qe=Ts.branch?.trim()||gt.get(Ce||"")?.trim();if(!Ce||!qe)return;const pt=Ao(Ce,qe),ft=br.getState().entries[pt],Ot=!!ft?.status?.pr,Gt=`${Ce}::${qe}`,Rs=Math.max(ft?.lastRefreshAt??0,ft?.lastDiscoveryPollAt??0),Ys=!!(ft?.isInitialStatusResolved&&!Ot&&(!f.current.has(Gt)||bt-Rs>=oT));(!ft||!ft.isInitialStatusResolved||Ys)&&(Ys&&f.current.add(Gt),Te.push({directory:Ce,branch:qe}))})}),Te.length===0)return;const lt=new Map;Te.forEach(Qt=>{const Ts=Ao(Qt.directory,Qt.branch,Qt.remoteName??null);lt.has(Ts)||lt.set(Ts,Qt)}),lt.forEach((Qt,Ts)=>{En(Ts),Ur(Ts,{directory:Qt.directory,branch:Qt.branch,remoteName:Qt.remoteName??null,canShow:!0,github:_n,githubAuthChecked:vn,githubConnected:nr.connected})}),Wr([...lt.values()],{force:!0,silent:!0,markInitialResolved:!0})},[R,En,_n,vn,nr?.connected,gt,Wr,Ut,Ur]);const Jo=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",bi="h-4.5 w-4.5",ur=BP({isDesktopShellRuntime:_t,projectSections:ln,projectHeaderSentinelRefs:le}),Hr=l.useCallback((Te,bt=0,lt,Qt,Ts=!1,Ce,qe="project")=>s.jsx(qD,{node:Te,depth:bt,groupDirectory:lt,projectId:Qt,archivedBucket:Ts,directoryStatus:P,currentSessionId:ot,pinnedSessionIds:J,expandedParents:v,hasSessionSearchQuery:Ke,normalizedSessionSearchQuery:He,notifyOnSubtasks:se,editingId:y,setEditingId:h,editTitle:b,setEditTitle:x,handleSaveEdit:Rn,handleCancelEdit:Fr,toggleParent:Hs,handleSessionSelect:yn,handleSessionDoubleClick:mn,togglePinnedSession:Pt,handleShareSession:Kn,copiedSessionId:gn,handleCopyShareUrl:Fe,handleUnshareSession:Nt,openSidebarMenuKey:O,setOpenSidebarMenuKey:L,renamingFolderId:K,getFoldersForScope:dt,getSessionFolderId:ze,removeSessionFromFolder:$e,addSessionToFolder:ye,createFolderAndStartRename:Gs,openContextPanelTab:ke,handleDeleteSession:Xt,mobileVariant:t,alwaysShowActions:Os,renderSessionNode:Hr,secondaryMeta:Ce,renderContext:qe}),[P,ot,J,v,Ke,He,se,y,h,b,x,Rn,Fr,Hs,yn,mn,Pt,Kn,gn,Fe,Nt,O,L,K,dt,ze,$e,ye,Gs,ke,Xt,t,Os]),yi=l.useCallback(Te=>{ce(bt=>{const lt=new Set(bt);return lt.has(Te)?lt.delete(Te):lt.add(Te),lt})},[]),vi=l.useMemo(()=>{const Te=new Map;for(const[bt,lt]of wn)Te.set(bt,{visualState:lt.visualState,number:lt.number,url:lt.url,state:lt.prState,draft:lt.draft,title:lt.title,base:lt.base,head:lt.head,checks:lt.checks,canMerge:lt.canMerge,mergeableState:lt.mergeableState,repo:lt.repo});return Te},[wn]),om=l.useCallback((Te,bt,lt,Qt,Ts,Ce)=>s.jsx(tD,{group:Te,groupKey:bt,projectId:lt,hideGroupLabel:Qt,compactBodyPadding:Ce,hasSessionSearchQuery:Ke,normalizedSessionSearchQuery:He,groupSearchDataByGroup:kr,expandedSessionGroups:D,collapsedGroups:te,hideDirectoryControls:r,collapsedFolderIds:Ze,toggleFolderCollapse:tt,renameFolder:ct,deleteFolder:at,showDeletionDialog:ie,setDeleteFolderConfirm:ne,renderSessionNode:Hr,currentSessionDirectory:Dn,projectRepoStatus:A,lastRepoStatus:Nn.current,toggleGroupSessionLimit:nn,mobileVariant:t,alwaysShowActions:Os,activeProjectId:je,setActiveProjectIdOnly:fe,setActiveMainTab:G,setSessionSwitcherOpen:V,openNewSessionDraft:Ct,addSessionToFolder:ye,createFolderAndStartRename:Gs,renamingFolderId:K,renameFolderDraft:re,setRenameFolderDraft:oe,setRenamingFolderId:B,pinnedSessionIds:J,sessionOrderIndex:as,prVisualStateByDirectoryBranch:vi,onToggleCollapsedGroup:yi,dragHandleProps:Ts}),[Ke,He,kr,D,te,r,Ze,tt,ct,at,ie,Hr,Dn,A,nn,t,Os,je,fe,G,V,Ct,ye,Gs,K,re,J,as,vi,yi]),ro=Xn&&!Ke?s.jsx(xD,{sections:Ye,renderSessionNode:Hr}):null,ha=!!(K||y||g),Da=xr(Te=>Te.enabled),cn=xr(Te=>Te.selectedIds),wi=xr(Te=>Te.scopeKey),ji=xr,Yo=l.useCallback(()=>{xr.getState().toggleMode()},[]),Ic=l.useCallback(()=>{xr.getState().disable()},[]),Ta=l.useMemo(()=>{if(cn.size===0||typeof document>"u")return!1;let Te=!1,bt=!1;for(const lt of cn){const Qt=document.querySelectorAll(`[data-session-row="${CSS.escape(lt)}"]`);for(const Ts of Qt)Ts.getAttribute("data-session-archived")==="1"?bt=!0:Te=!0}return bt&&!Te},[cn]),Sn=l.useMemo(()=>{if(wi)return wi;if(cn.size===0||typeof document>"u")return null;for(const Te of cn){const lt=document.querySelector(`[data-session-row="${CSS.escape(Te)}"]`)?.getAttribute("data-session-scope");if(lt&<.length>0)return lt}return null},[cn,wi]),Ac=l.useMemo(()=>Sn?Xe[Sn]??[]:[],[Xe,Sn]),Pc=l.useMemo(()=>{if(!Sn||cn.size===0)return!1;const Te=Xe[Sn]??[];for(const bt of Te)for(const lt of bt.sessionIds)if(cn.has(lt))return!0;return!1},[Xe,Sn,cn]),Xo=l.useCallback(Te=>{!Sn||cn.size===0||Ge(Sn,Te,Array.from(cn))},[Ge,cn,Sn]),fa=l.useCallback(()=>{if(!Sn||cn.size===0)return;const Te=Gs(Sn);Te&&Ge(Sn,Te.id,Array.from(cn))},[Ge,Gs,cn,Sn]),Zo=l.useCallback(()=>{!Sn||cn.size===0||_e(Sn,Array.from(cn))},[_e,cn,Sn]),Ma=l.useCallback(async()=>{const Te=Array.from(cn);if(Te.length!==0){if(Ta){const{deletedIds:bt,failedIds:lt}=await hn(Te);bt.length>0&&q.success(bt.length===1?i("sessions.sidebar.bulkActions.deletedSingle",{count:bt.length}):i("sessions.sidebar.bulkActions.deletedPlural",{count:bt.length})),lt.length>0&&q.error(lt.length===1?i("sessions.sidebar.bulkActions.failedDeleteSingle",{count:lt.length}):i("sessions.sidebar.bulkActions.failedDeletePlural",{count:lt.length}))}else{const{archivedIds:bt,failedIds:lt}=await fn(Te);bt.length>0&&q.success(bt.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:bt.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:bt.length})),lt.length>0&&q.error(lt.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:lt.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:lt.length}))}xr.getState().clear()}},[fn,Ta,hn,cn,i]),Ni=l.useCallback(()=>{const Te=cn.size;if(Te!==0){if(!ie){Ma();return}z({sessionCount:Te,archivedBucket:Ta})}},[Ta,Ma,cn,ie]),Dc=l.useCallback(async()=>{z(null),await Ma()},[Ma]);l.useEffect(()=>{if(!Da)return;const Te=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),bt=lt=>{if(ha)return;const Qt=lt.target;if(Qt&&(Qt.tagName==="INPUT"||Qt.tagName==="TEXTAREA"||Qt.isContentEditable))return;const Ts=Te?lt.metaKey:lt.ctrlKey;if(lt.key==="Escape"){lt.preventDefault(),xr.getState().disable();return}if(Ts&<.key==="Backspace"){lt.preventDefault(),Ni();return}if(Ts&&(lt.key==="a"||lt.key==="A")){const Ce=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Ce.length===0)return;lt.preventDefault();const pt=ji.getState().scopeKey??Ce[0]?.getAttribute("data-session-scope")??null,ft=Gt=>pt?Gt.getAttribute("data-session-scope")===pt:!0,Ot=Ce.filter(ft).map(Gt=>Gt.getAttribute("data-session-row")).filter(Gt=>typeof Gt=="string"&&Gt.length>0);if(Ot.length===0)return;ji.getState().replaceAll(Ot,pt||null)}};return window.addEventListener("keydown",bt),()=>window.removeEventListener("keydown",bt)},[Ni,ha,ji,Da]);const Tc=l.useCallback(()=>{G("chat"),t&&V(!1),Ct()},[t,Ct,G,V]),el=l.useCallback(()=>{G("chat"),t&&V(!1),Le()},[t,Le,G,V]);return s.jsxs("div",{ref:m,className:me("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[vt?s.jsx("div",{onMouseDown:is,className:me("app-region-drag flex h-[var(--oc-header-height,56px)] flex-shrink-0 items-center pr-3",zt),children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Me,className:ss,"aria-label":i("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(si,{className:"h-[18px] w-[18px]"})})}),s.jsx(It,{children:s.jsx("p",{children:i("sessions.sidebar.header.actions.closeSessions")})})]})}):null,s.jsx(uD,{hideDirectoryControls:r,handleOpenDirectoryDialog:sn,handleNewSession:Tc,canOpenMultiRun:he.length>0,openMultiRunLauncher:el,headerActionIconClass:bi,reserveHeaderActionsSpace:pi,headerActionButtonClass:Jo,isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchQuery:d,setSessionSearchQuery:p,hasSessionSearchQuery:Ke,searchMatchCount:mi,collapseAllProjects:pr,expandAllProjects:lr,openScheduledTasksDialog:()=>de(!0),selectionModeEnabled:Da,onToggleSelectionMode:Yo,showSidebarToggle:ht,onToggleSidebar:Me,avoidWindowControlsOverlay:Vs}),s.jsx(CD,{topContent:ro,sectionsForRender:Ut,projectSections:ln,activeProjectId:je,showOnlyMainWorkspace:a,hasSessionSearchQuery:Ke,emptyState:Et,searchEmptyState:pa,renderGroupSessions:om,homeDirectory:Ie,collapsedProjects:R,hideDirectoryControls:r,projectRepoStatus:A,isDesktopShellRuntime:_t,stuckProjectHeaders:ur,mobileVariant:t,alwaysShowActions:Os,toggleProject:ma,setActiveProjectIdOnly:fe,setActiveMainTab:G,setSessionSwitcherOpen:V,openNewSessionDraft:Ct,openNewWorktreeDialog:$t,openProjectEditDialog:w,removeProject:be,projectHeaderSentinelRefs:le,reorderProjects:Be,getOrderedGroups:hi,setGroupOrderByProject:pe,openSidebarMenuKey:O,setOpenSidebarMenuKey:L,isInlineEditing:ha}),Da&&cn.size>0?s.jsx(XD,{selectedCount:cn.size,scopeKey:Sn,scopeFolders:Ac,archivedBucket:Ta,onMoveToFolder:Xo,onCreateFolderAndMove:fa,onRemoveFromFolder:Zo,canRemoveFromFolder:Pc,onDelete:Ni,onDone:Ic}):null,s.jsx(yD,{onOpenSettings:bn,onOpenShortcuts:Ae,onOpenAbout:()=>xe(!0),onOpenUpdate:xs,showRuntimeButtons:!qt,showUpdateButton:en}),s.jsx(cu,{open:F,onOpenChange:_,info:Ue.info,downloading:Ue.downloading,downloaded:Ue.downloaded,progress:Ue.progress,error:Ue.error,onDownload:Ue.downloadUpdate,onRestart:Ue.restartToUpdate,runtimeType:Ue.runtimeType}),os?s.jsx(pw,{open:!!os,onOpenChange:Te=>{Te||w(null)},projectId:os.id,projectName:os.label||ii(os.path,Ie),projectPath:os.path,initialIcon:os.icon,initialColor:os.color,initialIconBackground:os.iconBackground,onSave:rs}):null,s.jsx(T6,{open:M,onOpenChange:$,onWorktreeCreated:(Te,bt)=>{if(G("chat"),t&&V(!1),bt?.sessionId){Yt(bt.sessionId);return}Ct({directoryOverride:Te})}}),s.jsx(iP,{}),s.jsx(QD,{value:ee,setValue:ae,showDeletionDialog:ie,setShowDeletionDialog:U,onConfirm:ms}),s.jsx(YD,{value:ge,setValue:ne,onConfirm:tn}),s.jsx(JD,{value:E,setValue:z,showDeletionDialog:ie,setShowDeletionDialog:U,onConfirm:Dc})]})},lT=()=>{const t=nt.c(13),[e,n]=Oe.useState(!1);let r,a;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(Pn())},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),Oe.useEffect(r,a);let i;t[2]!==e?(i=async f=>e?await gw(f):{success:!0,path:f},t[2]=e,t[3]=i):i=t[3];const o=i;let c;t[4]!==e?(c=async f=>e?await xw():{success:!0},t[4]=e,t[5]=c):c=t[5];const d=c;let p;t[6]!==e?(p=async f=>e?await bw():{success:!0},t[6]=e,t[7]=p):p=t[7];const m=p;let u;return t[8]!==e||t[9]!==o||t[10]!==d||t[11]!==m?(u={isDesktop:e,requestAccess:o,startAccessing:d,stopAccessing:m},t[8]=e,t[9]=o,t[10]=d,t[11]=m,t[12]=u):u=t[12],u},cT=t=>t==="/",cc=t=>t.replace(/\\/g,"/"),am=t=>{if(!t||cT(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},zi=t=>t.endsWith("/"),dT=t=>{const e=t.trim();return!e||zi(e)?e:`${e}/`},im=t=>t.lastIndexOf("/"),ab=t=>{if(zi(t))return t;const e=im(t);return e<0?t:t.slice(0,e+1)},uT=t=>{const e=im(t);return t.slice(e+1)},ib=t=>{const e=am(t.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=im(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},mT=t=>zi(t)&&ib(t)!==null,pT=(t,e)=>`${ab(t)}${e}/`,Ci=t=>{if(!t)return null;const e=am(cc(t.trim()));return e?e.toLowerCase():null},jf=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},hT=t=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?t.metaKey&&!t.ctrlKey:t.ctrlKey&&!t.metaKey,Sd=t=>{if(!t)return;t.focus({preventScroll:!0});const e=t.value.length;t.setSelectionRange(e,e),t.scrollLeft=t.scrollWidth},fT=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 cc(e.home.trim())}}catch{}return Mn.getFilesystemHome().catch(()=>null)},gT=({open:t,onOpenChange:e})=>{const{t:n}=ut(),r=qs(se=>se.homeDirectory),a=Es(se=>se.projects),i=Es(se=>se.addProject),o=ar(se=>se.profiles),c=ar(se=>se.globalIdentity),d=ar(se=>se.defaultGitIdentityId),p=ar(se=>se.loadProfiles),m=ar(se=>se.loadGlobalIdentity),u=ar(se=>se.loadDefaultGitIdentityId),f=yc(),{isDesktop:y,requestAccess:h,startAccessing:b}=lT(),{isMobile:x}=dn(),g=l.useRef(null),w=l.useRef(null),v=l.useRef(new Map),[S,P]=l.useState(""),[j,C]=l.useState("~/"),[I,R]=l.useState([]),[k,A]=l.useState(!1),[N,D]=l.useState(!1),[T,M]=l.useState(0),[$,F]=l.useState(!1),[_,O]=l.useState(!1),[L,K]=l.useState(0),[B,re]=l.useState(!1),[oe,ee]=l.useState(""),[ae,ge]=l.useState(null),ne=S||r,E=l.useMemo(()=>new Set(a.map(se=>Ci(se.path)).filter(se=>!!se)),[a]);l.useEffect(()=>{if(!t)return;C("~/"),R([]),M(0),F(!1),O(!1),re(!1),ee(""),ge(null),requestAnimationFrame(()=>Sd(g.current));let se=!1;return(async()=>{const U=await fT();se||(P(U||r||""),requestAnimationFrame(()=>Sd(g.current)))})(),()=>{se=!0}},[r,t]),l.useEffect(()=>{t&&(p(),m(),u())},[u,p,m,t]);const z=l.useMemo(()=>{const se=new Map;c&&se.set(c.id,c);for(const ie of o)se.set(ie.id,ie);return Array.from(se.values())},[o,c]);l.useEffect(()=>{if(!t||!B||ae!==null)return;const se=typeof d=="string"?d.trim():"";if(se&&z.some(U=>U.id===se)){ge(se);return}const ie=z.find(U=>U.authType==="ssh"||U.sshKey);ie&&ge(ie.id)},[z,d,B,t,ae]);const J=l.useMemo(()=>z.find(se=>se.id===ae)??null,[z,ae]),H=l.useMemo(()=>ab(j),[j]),te=l.useMemo(()=>zi(j)?"":uT(j),[j]),ce=l.useMemo(()=>ne?jf(H,ne):"",[H,ne]);l.useEffect(()=>{if(!t||!ce){R([]);return}let se=!1;return A(!0),D(!1),Mn.listLocalDirectory(ce).then(ie=>{if(se)return;D(!1);const U=ie.filter(Ve=>Ve.isDirectory).map(Ve=>({name:Ve.name,path:cc(Ve.path)})).sort((Ve,He)=>Ve.name.localeCompare(He.name));R(U)}).catch(()=>{se||(R([]),D(!0))}).finally(()=>{se||A(!1)}),()=>{se=!0}},[ce,t]);const Se=l.useMemo(()=>{const se=te.toLowerCase(),ie=f||te.startsWith(".");return I.filter(U=>U.name.toLowerCase().startsWith(se)&&(ie||!U.name.startsWith(".")))},[te,I,f]),pe=l.useMemo(()=>{const se=[];mT(j)&&se.push({type:"up",value:"browse:up",name:"..",path:ib(j)});for(const ie of Se){const U=Ci(ie.path);se.push({type:"directory",value:`browse:${ie.path}`,name:ie.name,path:ie.path,disabled:!!(U&&E.has(U))})}return se},[E,Se,j]);l.useEffect(()=>{M(0)},[j,pe.length]);const we=l.useMemo(()=>ne?am(jf(j,ne)):"",[ne,j]),W=Ci(we),ue=!!(W&&E.has(W)),Y=l.useMemo(()=>te?Se.find(se=>se.name===te)??null:null,[te,Se]),le=!!(we&&!ue&&(zi(j)&&N||!zi(j)&&te.trim().length>0&&Y===null)),Z=!$&&!_&&!ue&&!!we,Ie=Z&&oe.trim().length>0,Ne=pe[T]??null,X=!!(Ne&&(Ne.type==="up"||Ne.type==="directory"&&!Ne.disabled)),he=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",je=n(ue?"directoryExplorerDialog.actions.alreadyAdded":B?$?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":$?"directoryExplorerDialog.actions.adding":le?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");l.useLayoutEffect(()=>{const se=w.current;if(!se)return;const ie=()=>K(Math.ceil(se.getBoundingClientRect().width));if(ie(),typeof ResizeObserver>"u")return;const U=new ResizeObserver(ie);return U.observe(se),()=>U.disconnect()},[je]),l.useLayoutEffect(()=>{const se=g.current;se&&(se.scrollLeft=se.scrollWidth)},[L,j]),l.useLayoutEffect(()=>{t&&Sd(g.current)},[t]),l.useLayoutEffect(()=>{const se=pe[T];se&&v.current.get(se.value)?.scrollIntoView({block:"nearest"})},[T,pe]);const be=l.useCallback(()=>{e(!1)},[e]),fe=l.useCallback(async se=>{if(!se||$)return;const ie=Ci(se);if(ie&&E.has(ie))return;let U=se;F(!0);try{const Ve=!B&&le&&Ci(se)===Ci(we);if(B){const Ke=oe.trim();if(!Ke){q.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}U=(await Mn.cloneRepository({remoteUrl:Ke,destinationPath:se,gitIdentityId:J?.id??null})).path}else Ve&&await Mn.createDirectory(se,{allowOutsideWorkspace:!0});if(!i(U)){q.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}be()}catch(Ve){q.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Ve instanceof Error?Ve.message:n("directoryExplorerDialog.toast.unknownError")})}finally{F(!1)}},[i,E,oe,be,B,$,J?.id,le,we,n]),Pe=l.useCallback(se=>{C(dT(se))},[]),Be=l.useCallback(se=>{C(pT(j,se.name))},[j]),G=l.useCallback(se=>{if(se){if(se.type==="up"){se.path&&Pe(se.path);return}se.disabled||Be(se)}},[Pe,Be]),ke=l.useCallback(async()=>{if(!(!y||_)){O(!0);try{const se=await h(we);if(!se.success||!se.path){se.error&&se.error!=="Directory selection cancelled"&&q.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:se.error});return}const ie=await b(se.path);if(!ie.success){q.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:ie.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await fe(se.path)}catch(se){q.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:se instanceof Error?se.message:n("directoryExplorerDialog.toast.unknownError")})}finally{O(!1)}}},[fe,y,_,h,b,n,we]),Ee=l.useCallback(se=>{if(se.key==="ArrowDown"){se.preventDefault(),M(ie=>Math.min(pe.length-1,ie+1));return}if(se.key==="ArrowUp"){se.preventDefault(),M(ie=>Math.max(0,ie-1));return}if(se.key==="Enter"){if(se.preventDefault(),hT(se)){fe(we);return}X&&G(Ne);return}se.key==="Backspace"&&j===""&&(se.preventDefault(),be())},[G,fe,be,X,Ne,j,pe.length,we]),Ae=s.jsxs("button",{type:"button",onClick:()=>Cl(!f),className:"flex flex-shrink-0 items-center gap-2 rounded-lg px-2 py-1 typography-meta text-muted-foreground transition-colors hover:bg-interactive-hover/40",children:[f?s.jsx(Oi,{className:"h-4 w-4 text-primary"}):s.jsx(Li,{className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),xe=s.jsxs("div",{className:"px-2.5 py-1.5",children:[B?s.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[s.jsx(Bt,{value:oe,onChange:se=>ee(se.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(ax,{activeProfile:J,identities:z,onSelect:se=>ge(se.id),isApplying:$,iconOnly:!0})]}):null,s.jsxs("div",{className:"relative",children:[s.jsx(Aa,{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(Bt,{ref:g,value:j,onChange:se=>C(cc(se.target.value)),onKeyDown:Ee,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&&L>0?{paddingRight:`${L+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),x?null:s.jsx(ve,{ref:w,variant:"outline",size:"xs",tabIndex:-1,className:"absolute right-1.5 top-1/2 h-7 -translate-y-1/2 gap-1 px-2 typography-meta",disabled:B?!Ie:!Z,onMouseDown:se=>se.preventDefault(),onClick:()=>{fe(we)},title:je,children:je})]})]}),V=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")}),k?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):pe.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:pe.map((se,ie)=>{const U=ie===T;return s.jsxs("button",{ref:Ve=>{Ve?v.current.set(se.value,Ve):v.current.delete(se.value)},type:"button",disabled:se.type==="directory"&&se.disabled,onMouseEnter:()=>M(ie),onMouseDown:Ve=>Ve.preventDefault(),onClick:()=>G(se),className:me("flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",U&&"bg-interactive-selection text-interactive-selection-foreground",!U&&"hover:bg-interactive-hover/50",se.type==="directory"&&se.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[se.type==="up"?s.jsx(Wi,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(Ff,{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:se.name})}),se.type==="directory"&&se.disabled?s.jsx("span",{className:"rounded-full border border-border/60 px-2 py-0.5 typography-meta text-muted-foreground",children:n("directoryExplorerDialog.browse.addedBadge")}):null]},se.value)})})]})}),de=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[xe,V]}),Me=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(Du,{className:"h-3.5 w-3.5"}),s.jsx(ks,{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(bm,{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:he}),s.jsx(bm,{className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),Le=()=>s.jsxs(s.Fragment,{children:[x?null:Me,s.jsxs("div",{className:me("flex w-full flex-row justify-end gap-2 sm:w-auto",x&&"justify-stretch"),children:[y?s.jsx(ve,{variant:"ghost",size:"xs",onClick:ke,disabled:$||_||B,children:n(_?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(ve,{variant:"ghost",size:"xs",onClick:()=>re(se=>!se),disabled:$||_,className:me(x&&"flex-1"),children:n(B?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),x?s.jsx(ve,{size:"xs",onClick:()=>{fe(we)},disabled:B?!Ie:!Z,className:"flex-1",children:je}):null]})]});return x?s.jsx(Vr,{open:t,onClose:be,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:Le()}),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[s.jsx("div",{className:"flex justify-end",children:Ae}),de]})}):s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",onOpenAutoFocus:se=>se.preventDefault(),children:[s.jsx(Cs,{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(js,{children:n("directoryExplorerDialog.title")}),s.jsx(Fs,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),Ae]})}),s.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:de}),s.jsx(Xs,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:Le()})]})})},Ba=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,$r=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},xT=()=>{const{t}=ut(),[e,n]=l.useState(!1),[r,a]=l.useState(!1),[i,o]=l.useState(null),[c,d]=l.useState([]),[p,m]=l.useState(!1),[u,f]=l.useState(!1),[y,h]=l.useState(!1),[b,x]=l.useState(!1),[g,w]=l.useState(new Set),v=Ht(Z=>Z.getWorktreeMetadata),S=Ht(Z=>Z.newSessionDraft),P=Ht(Z=>Z.setNewSessionDraftTarget),j=Ht(Z=>Z.setDraftBootstrapPendingDirectory),C=yw,I=jw,R=Ht(Z=>Z.deleteSessions),k=Ht(Z=>Z.archiveSessions),A=De(Z=>Z.showDeletionDialog),N=De(Z=>Z.setShowDeletionDialog),D=qs(Z=>Z.currentDirectory),T=qs(Z=>Z.homeDirectory),M=qs(Z=>Z.isHomeReady),$=Es(Z=>Z.projects),F=Es(Z=>Z.activeProjectId),{isMobile:_,isTablet:O,hasTouchInput:L}=dn(),K=_||O||L,B=l.useMemo(()=>{const Ie=(F?$.find(Ne=>Ne.id===F)??null:null)?.path??D;return $r(Ie)},[F,D,$]),re=l.useCallback(Z=>{const Ne=$r(Z.projectDirectory)||B;return{id:($.find(he=>$r(he.path)===Ne)??null)?.id??`path:${Ne}`,path:Ne}},[B,$]),oe=b&&g.size>0,ee=l.useMemo(()=>{const Z=i?.worktree;return Z&&typeof Z.branch=="string"&&Z.branch.trim().length>0?!0:c.length>0&&c.every(({metadata:Ie})=>typeof Ie.branch=="string"&&Ie.branch.trim().length>0)},[i?.worktree,c]),ae=i?.mode==="worktree",ge=ae,ne=y||!ae||!ee,E=y||!ae;l.useEffect(()=>{r||!M||$.length>0||(a(!0),n(!0))},[r,M,$.length]);const z=l.useCallback(Z=>{o({sessions:Z.sessions,dateLabel:Z.dateLabel,mode:Z.mode??"session",worktree:Z.worktree??null})},[]),J=l.useCallback(()=>{o(null),d([]),m(!1),f(!1),h(!1),x(!1),w(new Set)},[]),H=l.useCallback(async Z=>{if(Z.sessions.length===0)return;if(Z.sessions.length===1){const he=Z.sessions[0];await C(he.id)?q.success(t("sessions.sidebar.session.delete.success")):q.error(t("sessions.sidebar.session.delete.error"));return}const Ie=Z.sessions.map(he=>he.id),{deletedIds:Ne,failedIds:X}=await R(Ie);if(Ne.length>0){const he=X.length>0?X.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:X.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:X.length}):Z.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:Z.dateLabel}):void 0;q.success(Ne.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Ne.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Ne.length}),{description:Ba(he)})}X.length>0&&q.error(X.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:X.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:X.length}),{description:Ba(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[C,R,t]);l.useEffect(()=>Tr.onDeleteRequest(Z=>{if(!A&&(Z.mode??"session")==="session"){H(Z);return}z(Z)}),[z,A,H]),l.useEffect(()=>Tr.onDirectoryRequest(()=>{n(!0)}),[]),l.useEffect(()=>{if(!i){d([]),m(!1),f(!1),x(!1),w(new Set);return}const Z=i.sessions.map(X=>{const he=v(X.id);return he?{session:X,metadata:he}:null}).filter(X=>!!X);d(Z),m(!1),x(!1),w(new Set);const Ie=new Map;if(i.worktree?.path&&Ie.set($r(i.worktree.path),i.worktree),Z.forEach(({metadata:X})=>{X.path&&Ie.set($r(X.path),X)}),Ie.size===0){x(!0);return}let Ne=!1;return(async()=>{const X=new Map,he=new Set;await Promise.all(Array.from(Ie.entries()).map(async([je,be])=>{try{const fe=await vw(be.path);X.set(je,fe),fe?.isDirty&&he.add(je)}catch{be.status&&(X.set(je,be.status),be.status.isDirty&&he.add(je))}})).catch(je=>{console.warn("Failed to inspect worktree status before deletion:",je)}),!Ne&&(w(he),x(!0),o(je=>{if(!je?.worktree?.path)return je;const be=$r(je.worktree.path),fe=X.get(be);if(!fe)return je;const Pe=je.worktree.status;return Pe?.isDirty===fe.isDirty&&Pe?.ahead===fe.ahead&&Pe?.behind===fe.behind&&Pe?.upstream===fe.upstream?je:{...je,worktree:{...je.worktree,status:fe}}}),d(je=>je.map(be=>{const fe=$r(be.metadata.path),Pe=X.get(fe);return Pe?{session:be.session,metadata:{...be.metadata,status:Pe}}:be})))})(),()=>{Ne=!0}},[i,v]),l.useEffect(()=>{ee||m(!1)},[ee]);const te=l.useCallback(async(Z,Ie)=>{const Ne=p&&ee,X=re(Z),he=$r(Z.path),je=$r(X.path);try{await ww(X,Z,{deleteRemoteBranch:Ne,deleteLocalBranch:Ie});const be=$r(S?.directoryOverride);return S?.open&&he&&be===he&&je&&(j(null),P({projectId:X.id,directoryOverride:je},{force:!0})),$r(D)===he&&je&&qs.getState().setDirectory(je,{showOverlay:!1}),!0}catch(be){return q.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Ba(be instanceof Error?be.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[ee,D,p,re,S?.directoryOverride,S?.open,j,P,t]),ce=l.useCallback(async()=>{if(i){h(!0);try{const Z=ge,Ie=Z&&p,Ne=Z&&u;if(i.sessions.length===0&&ae&&i.worktree){if(!await te(i.worktree,Ne)){J();return}const je=t(p&&ee?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");q.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Ba(je)}),J();return}if(i.sessions.length===1){const X=i.sessions[0];if(!(ae?await I(X.id):await C(X.id,{archiveWorktree:!1,deleteRemoteBranch:Ie,deleteLocalBranch:Ne}))){q.error(t(ae?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),h(!1);return}const je=!ae&&Z?t(Ie?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;q.success(t(ae?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Ba(je),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const X=i.sessions.map(be=>be.id);let he=[],je=[];if(ae){const be=await k(X);he=be.archivedIds,je=be.failedIds}else{const be=await R(X,{archiveWorktree:!1,deleteRemoteBranch:Ie,deleteLocalBranch:Ne});he=be.deletedIds,je=be.failedIds}if(ae&&i.worktree&&je.length===0&&await te(i.worktree,Ne),he.length>0){const be=!ae&&Z?t(Ie?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Pe=[je.length>0?ae?je.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:je.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:je.length}):je.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:je.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:je.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,be].filter(Boolean).join(" ");q.success(ae?he.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:he.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:he.length}):he.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:he.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:he.length}),{description:Ba(Pe||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(je.length>0&&(q.error(ae?je.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:je.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:je.length}):je.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:je.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:je.length}),{description:Ba(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),he.length===0)){h(!1);return}}ae&&i.sessions.length===1&&i.worktree&&await te(i.worktree,Ne),J()}finally{h(!1)}}},[i,p,u,C,R,I,k,J,ge,ae,ee,te,t]),Se=i?.worktree??c[0]?.metadata??null,pe=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}):"",we=i?s.jsxs("div",{className:me(ae?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:me(ae?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[ae&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:i.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:i.sessions.length})]}),s.jsxs("ul",{className:me(ae?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(Z=>s.jsxs("li",{className:me(ae?"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-muted-foreground":"typography-micro text-muted-foreground/80"),children:[s.jsx("span",{className:me(!ae&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:Z.title||t("sessions.sidebar.session.untitled")})]},Z.id)),i.sessions.length>5&&s.jsx("li",{className:me(ae?"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})})]})]}),ae?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(Qs,{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")}),Se?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:Se.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:Se?Ro(Se.path,T):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),oe&&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,W=ae?ee?s.jsxs("button",{type:"button",onClick:()=>{ne||m(Z=>!Z)},disabled:ne,className:me("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",ne?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[p?s.jsx(Oi,{className:"size-4 text-primary"}):s.jsx(Li,{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,ue=ae?s.jsxs("button",{type:"button",onClick:()=>{E||f(Z=>!Z)},disabled:E,className:me("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",E?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(Oi,{className:"size-4 text-primary"}):s.jsx(Li,{className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,Y=ae?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:[ue,W]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"ghost",onClick:J,disabled:y,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{variant:"destructive",onClick:ce,disabled:y,children:t(y?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>N(!A),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":!A,children:[A?s.jsx(Li,{className:"size-4"}):s.jsx(Oi,{className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"ghost",onClick:J,disabled:y,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{variant:"destructive",onClick:ce,disabled:y,children:y?t("sessions.sidebar.sessionDialogs.actions.deleting"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),le=ae?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:[K?s.jsx(Vr,{open:!!i,onClose:()=>{y||J()},title:le,footer:s.jsx("div",{className:"flex justify-end gap-2",children:Y}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[pe&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:pe}),we]})}):s.jsx(ws,{open:!!i,onOpenChange:Z=>{if(!Z){if(y)return;J()}},children:s.jsxs(vs,{className:me(ae?"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(Cs,{children:[s.jsxs(js,{className:me(ae&&"flex items-center gap-2"),children:[ae&&s.jsx(an,{className:"h-5 w-5"}),le]}),pe&&s.jsx(Fs,{children:pe})]}),s.jsx("div",{className:me(ae&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:we}),s.jsx(Xs,{className:"mt-2 gap-2 pt-1 pb-1",children:Y})]})}),s.jsx(gT,{open:e,onOpenChange:n})]})},fu=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),bT=(t,e)=>{const n=fu(t),r=fu(e);return`${n}-${r}`.substring(0,60)},Nf=(t,e)=>`${t}/${e}`,yT=()=>{const t=Es.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=qs.getState().currentDirectory??null;if(r&&r.trim().length>0){const a=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${a}`,path:a}}return null},kd=Nr()(to(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),r=e.prompt.trim(),{models:a,agent:i,files:o,setupCommands:c}=e;if(!n)return t({error:"Group name is required"}),null;if(!r)return t({error:"Prompt is required"}),null;if(a.length<1)return t({error:"Select at least 1 model"}),null;if(a.length>5)return t({error:"Maximum 5 models allowed"}),null;t({isLoading:!0,error:null});try{const d=yT();if(!d)return t({error:"Select a project",isLoading:!1}),null;const p=d.path;if(!await Sg(p))return t({error:"Not in a git repository",isLoading:!1}),null;const u=fu(n),f=await Uo(p),y=await Nw(p),h=[],b=c?.filter(j=>j.trim().length>0)??[],x=new Map;for(const j of a){const C=`${j.providerID}:${j.modelID}`;x.set(C,(x.get(C)||0)+1)}const g=new Map;for(const j of a){const C=`${j.providerID}:${j.modelID}`,I=x.get(C)||1,R=(g.get(C)||0)+1;g.set(C,R);const k=bT(j.providerID,j.modelID),A=I>1?Nf(u,`${k}/${R}`):Nf(u,k);try{const N=await Sw(d,{preferredName:A,mode:"new",branchName:A,worktreeName:A,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:b},{resolvedRootTrackingRemote:y}),D={...N,createdFromBranch:f,kind:"standard"},T=I>1?`${u}/${j.providerID}/${j.modelID}/${R}`:`${u}/${j.providerID}/${j.modelID}`,M=await Mn.withDirectory(N.path,()=>Mn.createSession({title:T}));Ht.getState().setWorktreeMetadata(M.id,D),h.push({sessionId:M.id,worktreePath:N.path,providerID:j.providerID,modelID:j.modelID,variant:j.variant})}catch(N){console.warn("[MultiRun] Failed to create session:",N)}}const w=c?.filter(j=>j.trim().length>0)??[];w.length>0&&kg(d,w).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const v=h.map(j=>j.sessionId),S=h[0]?.sessionId??null;if(v.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const P=o?.map(j=>({type:"file",mime:j.mime,filename:j.filename,url:j.url}));return(async()=>{try{await Promise.allSettled(h.map(async j=>{try{await Mn.withDirectory(j.worktreePath,()=>Mn.sendMessage({id:j.sessionId,providerID:j.providerID,modelID:j.modelID,variant:j.variant,text:r,agent:i,files:P}))}catch(C){console.warn("[MultiRun] Failed to start run:",C)}}))}catch(j){console.warn("[MultiRun] Failed to start runs:",j)}})(),t({isLoading:!1}),{groupSlug:u,sessionIds:v,firstSessionId:S}}catch(d){return t({error:d instanceof Error?d.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"})),ob="h-7",gu=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,vT=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),wT=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=vT.format(t);return e.endsWith(".0")?e.slice(0,-2):e},jT=t=>{const e=nt.c(12),{model:n,instanceIndex:r,totalSameModel:a,onRemove:i}=t,o=n.displayName||`${n.providerID}/${n.modelID}`,c=a>1?`${o} (${r})`:o;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=me("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",ob),e[0]=d):d=e[0];let p;e[1]!==n.providerID?(p=s.jsx(Vn,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=p):p=e[2];let m;e[3]!==c?(m=s.jsx("span",{className:"typography-meta font-medium truncate max-w-[140px]",children:c}),e[3]=c,e[4]=m):m=e[4];let u;e[5]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(Is,{className:"h-3.5 w-3.5"}),e[5]=u):u=e[5];let f;e[6]!==i?(f=s.jsx("button",{type:"button",onClick:i,className:"text-muted-foreground hover:text-foreground ml-0.5",children:u}),e[6]=i,e[7]=f):f=e[7];let y;return e[8]!==p||e[9]!==m||e[10]!==f?(y=s.jsxs("div",{className:d,children:[p,m,f]}),e[8]=p,e[9]=m,e[10]=f,e[11]=y):y=e[11],y},NT=({selectedModels:t,onAdd:e,onRemove:n,onUpdate:r,minModels:a,addButtonLabel:i,showChips:o=!0,maxModels:c,addButtonClassName:d})=>{const{t:p}=ut(),m=yt(K=>K.providers),u=yt(K=>K.modelsMetadata),{favoriteModelsList:f,recentModelsList:y}=hg(),[h,b]=l.useState(!1),[x,g]=l.useState(""),[w,v]=l.useState(0),[S,P]=l.useState(null),j=l.useRef(null),C=l.useRef(null),I=l.useRef(null),R=l.useRef([]),k=c===void 0||t.length<c,A=l.useMemo(()=>{const K=new Map;for(const B of t){const re=`${B.providerID}:${B.modelID}`;K.set(re,(K.get(re)||0)+1)}return K},[t]),N=l.useCallback(K=>t.filter(re=>re.providerID===K.providerID&&re.modelID===K.modelID).findIndex(re=>re.instanceId===K.instanceId)+1,[t]),D=(K,B)=>{const re=`${K}/${B}`;return u.get(re)},T=K=>{const B=K?.name||K?.id||"",re=String(B);return re.length>40?re.substring(0,37)+"...":re},M=l.useCallback((K,B)=>{if(!x.trim())return!0;const re=x.toLowerCase();return K.toLowerCase().includes(re)||B.toLowerCase().includes(re)},[x]),$=l.useMemo(()=>f.filter(({model:K,providerID:B})=>{const oe=m.find(ae=>ae.id===B)?.name||B,ee=T(K);return M(ee,oe)}),[f,m,M]),F=l.useMemo(()=>y.filter(({model:K,providerID:B})=>{const oe=m.find(ae=>ae.id===B)?.name||B,ee=T(K);return M(ee,oe)}),[y,m,M]),_=l.useMemo(()=>m.map(K=>{const re=(Array.isArray(K.models)?K.models:[]).filter(oe=>{const ee=T(oe);return M(ee,K.name||K.id||"")});return{...K,models:re}}).filter(K=>K.models.length>0),[m,M]),O=$.length>0||F.length>0||_.length>0;l.useEffect(()=>{if(!h||!I.current)return;const K=I.current.getBoundingClientRect();let B=I.current.parentElement;for(;B&&!(B.getAttribute("role")==="dialog"||B.hasAttribute("data-scroll-shadow"));){const ee=getComputedStyle(B);if(ee.overflow==="auto"||ee.overflow==="hidden"||ee.overflowY==="auto"||ee.overflowY==="hidden")break;B=B.parentElement}const re=B?B.getBoundingClientRect().top:0,oe=K.top-re-16;P(Math.max(150,Math.min(300,oe)))},[h]),l.useEffect(()=>{h&&j.current&&j.current.focus()},[h]),l.useEffect(()=>{!k&&h&&(b(!1),g(""),v(0))},[k,h]),l.useEffect(()=>{if(!h)return;const K=B=>{C.current&&!C.current.contains(B.target)&&(b(!1),g(""),v(0))};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[h]),l.useEffect(()=>{v(0)},[x]);const L=(K,B,re,oe,ee,ae)=>{const ge=`${B}:${re}`,ne=A.get(ge)||0,E=D(B,re),z=wT(E?.limit?.context),J=oe==="fav"||oe==="recent";return s.jsxs("button",{ref:H=>{R.current[ee]=H},type:"button",disabled:!k,onClick:()=>{e({providerID:B,modelID:re,displayName:K.name||re,instanceId:gu()})},onMouseEnter:()=>v(ee),className:me("w-full text-left px-2 py-1.5 rounded-md typography-meta transition-colors flex items-center gap-2",k&&(ae?"bg-interactive-selection":"hover:bg-interactive-hover/50"),!k&&"cursor-not-allowed opacity-60"),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[J&&s.jsx(Vn,{providerId:B,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:T(K)}),z&&s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:z})]}),ne>0&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:["×",ne]})]},`${oe}-${ge}`)};return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[s.jsxs("div",{className:"relative",ref:C,children:[s.jsxs(ve,{ref:I,type:"button",variant:"outline",size:"sm",className:me(ob,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",d),disabled:!k,onClick:()=>{b(!h)},children:[s.jsx(zs,{className:"h-3.5 w-3.5 mr-1"}),i??p("multirun.modelMultiSelect.actions.addModel")]}),h&&(()=>{const K=[];$.forEach(({model:ee,providerID:ae,modelID:ge})=>{K.push({model:ee,providerID:ae,modelID:ge,section:"fav"})}),F.forEach(({model:ee,providerID:ae,modelID:ge})=>{K.push({model:ee,providerID:ae,modelID:ge,section:"recent"})}),_.forEach(ee=>{ee.models.forEach(ae=>{K.push({model:ae,providerID:ee.id,modelID:ae.id,section:"provider"})})});const B=K.length,re=ee=>{if(!kw(ee))if(ee.key==="ArrowDown"){ee.preventDefault(),ee.stopPropagation();const ae=(w+1)%Math.max(1,B);v(ae),setTimeout(()=>{R.current[ae]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(ee.key==="ArrowUp"){ee.preventDefault(),ee.stopPropagation();const ae=(w-1+Math.max(1,B))%Math.max(1,B);v(ae),setTimeout(()=>{R.current[ae]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(ee.key==="Enter"){ee.preventDefault(),ee.stopPropagation();const ae=K[w];ae&&k&&e({providerID:ae.providerID,modelID:ae.modelID,displayName:ae.model.name||ae.modelID,instanceId:gu()})}else ee.key==="Escape"&&(ee.preventDefault(),ee.stopPropagation(),b(!1),g(""),v(0))};let oe=0;return s.jsxs("div",{className:"absolute bottom-full left-0 mb-1 z-50 w-[min(380px,calc(100vw-2rem))] max-w-[calc(100vw-2rem)] flex flex-col overflow-hidden rounded-xl border border-border/50 shadow-lg",style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:[s.jsx("div",{className:"p-2 border-b border-border/40",children:s.jsxs("div",{className:"relative",children:[s.jsx(Jn,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Bt,{ref:j,type:"text",placeholder:p("multirun.modelMultiSelect.search.placeholder"),value:x,onChange:ee=>g(ee.target.value),onKeyDown:re,className:"h-8 pl-8 typography-meta"})]})}),s.jsx(Ps,{outerClassName:"flex-1",style:{maxHeight:S?`${S}px`:"300px"},children:s.jsxs("div",{className:"p-1",children:[!O&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:p("multirun.modelMultiSelect.search.noResults")}),$.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(ho,{className:"h-4 w-4 text-primary"}),p("multirun.modelMultiSelect.sections.favorites")]}),$.map(({model:ee,providerID:ae,modelID:ge})=>{const ne=oe++;return L(ee,ae,ge,"fav",ne,w===ne)})]}),F.length>0&&s.jsxs(s.Fragment,{children:[$.length>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(Nu,{className:"h-4 w-4"}),p("multirun.modelMultiSelect.sections.recent")]}),F.map(({model:ee,providerID:ae,modelID:ge})=>{const ne=oe++;return L(ee,ae,ge,"recent",ne,w===ne)})]}),($.length>0||F.length>0)&&_.length>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),_.map((ee,ae)=>s.jsxs(l.Fragment,{children:[ae>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(Vn,{providerId:ee.id,className:"h-4 w-4 flex-shrink-0"}),ee.name]}),ee.models.map(ge=>{const ne=oe++;return L(ge,ee.id,ge.id,"provider",ne,w===ne)})]},ee.id))]})}),s.jsx("div",{className:"px-3 pt-1 pb-1.5 border-t border-border/40 typography-micro text-muted-foreground",children:p("multirun.modelMultiSelect.keyboard.hint")})]})})()]}),o&&t.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:t.map((K,B)=>{const re=`${K.providerID}:${K.modelID}`,oe=A.get(re)||1,ee=N(K),ge=m.find(H=>H.id===K.providerID)?.models.find(H=>H.id===K.modelID),ne=ge?.variants?Object.keys(ge.variants):[],E=ne.length>0,z="__default__",J=K.variant??z;return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(jT,{model:K,instanceIndex:ee,totalSameModel:oe,onRemove:()=>n(B)}),E&&s.jsxs(ps,{value:J,onValueChange:H=>{if(!r)return;r(B,{...K,variant:H===z?void 0:H})},children:[s.jsxs(hs,{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(Do,{className:me("h-3.5 w-3.5 flex-shrink-0",J===z?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(ys,{placeholder:p("multirun.modelMultiSelect.variant.placeholder")})]}),s.jsxs(fs,{fitContent:!0,children:[s.jsx(Rt,{value:z,className:"pr-2 [&>span:first-child]:hidden",children:p("multirun.modelMultiSelect.variant.default")}),ne.map(H=>s.jsx(Rt,{value:H,className:"pr-2 [&>span:first-child]:hidden",children:H},H))]})]})]},K.instanceId)})})]}),a!==void 0&&t.length<a&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:c!==void 0?p("multirun.modelMultiSelect.validation.minToMax",{min:a,max:c}):p("multirun.modelMultiSelect.validation.minOnly",{min:a})})]})},ST="oc:lastWorktreeSourceBranch";function lb(t){const e=nt.c(21),{git:n}=Yn(),r=Bu(t),a=Dg(t),i=pn(AT);let o;e[0]!==r?.all||e[1]!==t||e[2]!==i||e[3]!==n?(o=()=>{!t||!n||r?.all||i(t,n)},e[0]=r?.all,e[1]=t,e[2]=i,e[3]=n,e[4]=o):o=e[4];const c=r?.all;let d;e[5]!==t||e[6]!==i||e[7]!==n||e[8]!==c?(d=[t,n,c,i],e[5]=t,e[6]=i,e[7]=n,e[8]=c,e[9]=d):d=e[9],l.useEffect(o,d);let p;e:{if(!r?.all){let g;e[10]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[10]=g):g=e[10],p=g;break e}let x;e[11]!==r.all?(x=r.all.filter(IT).sort(),e[11]=r.all,e[12]=x):x=e[12],p=x}const m=p;let u;e:{if(!r?.all){let g;e[13]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[13]=g):g=e[13],u=g;break e}let x;e[14]!==r.all?(x=r.all.filter(CT).map(kT).sort(),e[14]=r.all,e[15]=x):x=e[15],u=x}const f=u;let y;e:{if(!t){y=null;break e}if(a){y=null;break e}if(!r){y=null;break e}y=!!r.all}const h=y;let b;return e[16]!==h||e[17]!==a||e[18]!==m||e[19]!==f?(b={localBranches:m,remoteBranches:f,isLoading:a,isGitRepository:h},e[16]=h,e[17]=a,e[18]=m,e[19]=f,e[20]=b):b=e[20],b}function kT(t){return t.replace(/^remotes\//,"")}function CT(t){return t.startsWith("remotes/")}function IT(t){return!t.startsWith("remotes/")}function AT(t){return t.fetchBranches}const PT=({directory:t,value:e,onChange:n,className:r,disabled:a,id:i})=>{const{t:o}=ut(),{localBranches:c,remoteBranches:d,isLoading:p,isGitRepository:m}=lb(t),u=l.useMemo(()=>[...c,...d.map(y=>`remotes/${y}`)],[c,d]);l.useEffect(()=>{if(a||p||u.length===0||e&&u.includes(e))return;(async()=>{try{const h=t?await Uo(t).catch(()=>null):null,b=localStorage.getItem(ST);b&&u.includes(b)?n(b):h&&u.includes(h)?n(h):u.includes("main")?n("main"):u.includes("master")?n("master"):u[0]&&n(u[0])}catch{}})()},[u,t,a,p,n,e]);const f=a||!m||p;return s.jsxs("div",{children:[s.jsxs(ps,{value:e,onValueChange:n,disabled:f,children:[s.jsx(hs,{id:i,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(ys,{placeholder:o(p?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(fs,{className:"max-h-[280px] max-w-[320px]",children:p?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:o("multiRun.branchSelector.status.loadingBranches")}):c.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:o("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[c.length>0&&s.jsxs(zd,{children:[s.jsx(Vm,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.localBranches")}),c.map(y=>s.jsx(Rt,{value:y,className:"whitespace-normal break-all",children:y},y))]}),c.length>0&&d.length>0&&s.jsx(Cw,{}),d.length>0&&s.jsxs(zd,{children:[s.jsx(Vm,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.remoteBranches")}),d.map(y=>s.jsx(Rt,{value:`remotes/${y}`,className:"whitespace-normal break-all",children:y},`remotes/${y}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:o("multiRun.branchSelector.status.notInGitRepository")})]})},DT=t=>{const e=nt.c(34),{value:n,onChange:r,className:a,disabled:i,id:o}=t,{t:c}=ut(),d=yt(TT),p=yt(MT),m=yt(RT);let u;e[0]!==d?(u=d(),e[0]=d,e[1]=u):u=e[1];const f=u;let y;e[2]!==f?(y=f.filter(ET),e[2]=f,e[3]=y):y=e[3];const h=y;let b,x;e[4]!==p?(b=()=>{p()},x=[p],e[4]=p,e[5]=b,e[6]=x):(b=e[5],x=e[6]),l.useEffect(b,x);let g,w;e[7]!==m||e[8]!==i||e[9]!==r||e[10]!==h||e[11]!==n?(g=()=>{if(i)return;const A=n.trim();if(A.length>0&&h.some(T=>T.name===A))return;const N=typeof m=="string"&&m.trim().length>0?m.trim():null;if(N&&h.some(T=>T.name===N)){r(N);return}const D=h[0]?.name;D&&r(D)},w=[m,i,r,h,n],e[7]=m,e[8]=i,e[9]=r,e[10]=h,e[11]=n,e[12]=g,e[13]=w):(g=e[12],w=e[13]),l.useEffect(g,w);const v=n.trim().length>0?n:void 0;let S;e[14]!==a?(S=me("max-w-full typography-meta text-foreground !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 data-[popup-open]:!bg-[var(--interactive-active)]/70",a),e[14]=a,e[15]=S):S=e[15];let P;e[16]!==c?(P=c("multirun.agentSelector.placeholder"),e[16]=c,e[17]=P):P=e[17];let j;e[18]!==P?(j=s.jsx(ys,{placeholder:P}),e[18]=P,e[19]=j):j=e[19];let C;e[20]!==o||e[21]!==S||e[22]!==j?(C=s.jsx(hs,{id:o,size:"lg",className:S,children:j}),e[20]=o,e[21]=S,e[22]=j,e[23]=C):C=e[23];let I;e[24]!==h?(I=h.length>0&&s.jsx(zd,{children:h.map(FT)}),e[24]=h,e[25]=I):I=e[25];let R;e[26]!==I?(R=s.jsx(fs,{fitContent:!0,children:I}),e[26]=I,e[27]=R):R=e[27];let k;return e[28]!==i||e[29]!==r||e[30]!==v||e[31]!==C||e[32]!==R?(k=s.jsxs(ps,{value:v,onValueChange:r,disabled:i,children:[C,R]}),e[28]=i,e[29]=r,e[30]=v,e[31]=C,e[32]=R,e[33]=k):k=e[33],k};function TT(t){return t.getVisibleAgents}function MT(t){return t.loadAgents}function RT(t){return t.currentAgentName}function ET(t){return t.mode!=="subagent"}function FT(t){return s.jsx(Rt,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const OT=10*1024*1024,Cd=5,wl=t=>{const e=nt.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(kt,{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(Us,{className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let a;return e[1]!==n?(a=s.jsxs(St,{children:[r,s.jsx(It,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=a):a=e[2],a},Ii=t=>{const e=nt.c(9),{htmlFor:n,required:r,children:a,info:i}=t;let o;e[0]!==r?(o=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=o):o=e[1];let c;e[2]!==a||e[3]!==n||e[4]!==o?(c=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,o]}),e[2]=a,e[3]=n,e[4]=o,e[5]=c):c=e[5];const d=i&&i;let p;return e[6]!==c||e[7]!==d?(p=s.jsxs("div",{className:"flex items-center gap-1.5",children:[c,d]}),e[6]=c,e[7]=d,e[8]=p):p=e[8],p},LT=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:a}=ut(),[i,o]=l.useState(""),[c,d]=l.useState(()=>t??""),[p,m]=l.useState([]),[u,f]=l.useState(""),[y,h]=l.useState([]),[b,x]=l.useState(!1),[g,w]=l.useState([]),[v,S]=l.useState(!1),[P,j]=l.useState(!1),[C,I]=l.useState(!1),[R,k]=l.useState(""),[A,N]=l.useState(!1),[D,T]=l.useState(""),M=l.useRef(null),$=l.useRef(null),F=l.useRef(null),_=l.useRef(null),O=qs(se=>se.currentDirectory??null),L=qs(se=>se.homeDirectory??null),K=l.useMemo(()=>{if(typeof window>"u")return null;const se=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof se=="string"&&se.trim().length>0?se.trim():null},[]),B=Es(se=>se.activeProjectId),re=Es(se=>se.setActiveProjectIdOnly),oe=Es(se=>se.projects),[ee,ae]=l.useState(()=>B??null);l.useEffect(()=>{if(B){ae(B);return}!ee&&oe.length>0&&ae(oe[0].id)},[B,oe,ee]);const ge=l.useMemo(()=>ee?oe.find(se=>se.id===ee)??null:null,[oe,ee]),ne=ge?.path??O,E=l.useCallback(se=>{ae(se),se!==B&&re(se)},[B,re]),{currentTheme:z}=Er(),J=l.useCallback(se=>{const ie=se.label?.trim()||ii(se.path,L),U=Ho({id:se.id,iconImage:se.iconImage??null},{themeVariant:z.metadata.variant,iconColor:z.colors.surface.foreground}),Ve=se.icon?jc[se.icon]:null,He=se.color?Go[se.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[U?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:se.iconBackground?{backgroundColor:se.iconBackground}:void 0,children:s.jsx("img",{src:U,alt:"",className:"h-full w-full object-contain",draggable:!1})}):Ve?s.jsx(Ve,{className:"h-3.5 w-3.5 shrink-0",style:He?{color:He}:void 0}):s.jsx(Un,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:He?{color:He}:void 0}),s.jsx("span",{className:"truncate",children:ie})]})},[L,z.metadata.variant,z.colors.surface.foreground]),H=l.useMemo(()=>{if(ge?.path)return{id:ge.id,path:ge.path};const se=O??K;return se?{id:`path:${se}`,path:se}:null},[ge,O,K]),[te,ce]=l.useState(()=>typeof window>"u"?!1:Pn()),Se=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),pe=fc();l.useEffect(()=>{typeof window>"u"||ce(Pn())},[]);const we=l.useMemo(()=>{if(typeof window>"u")return null;const se=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof se=="number"&&Number.isFinite(se)&&se>0)return se;if(typeof navigator>"u")return null;const ie=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!ie)return null;const U=Number.parseInt(ie[1],10),Ve=Number.parseInt(ie[2],10);return Number.isNaN(U)?null:U===10?Ve:U},[]),W=l.useMemo(()=>te&&Se||pe?"pl-[5.5rem]":"pl-3",[te,Se,pe]),ue=l.useMemo(()=>!te||!Se||we===null?"":we>=26?"h-12":we<=15?"h-14":"",[te,Se,we]),Y=l.useCallback(async se=>{se.target.closest("button, a, input, select, textarea")||se.button===0&&te&&await Og()},[te]);l.useEffect(()=>{if(!n)return;const se=ie=>{ie.key==="Escape"&&(ie.preventDefault(),ie.stopPropagation(),n())};return window.addEventListener("keydown",se,!0),()=>window.removeEventListener("keydown",se,!0)},[n]);const[le,Z]=l.useState(""),{isLoading:Ie,isGitRepository:Ne}=lb(ne),X=kd(se=>se.createMultiRun),he=kd(se=>se.error),je=kd(se=>se.clearError);l.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(se=>se.trim().length>0?se:t)},[t]),l.useEffect(()=>{if(!H)return;let se=!1;return j(!0),(async()=>{try{const ie=await Wu(H);se||w(ie)}catch{}finally{se||j(!1)}})(),()=>{se=!0}},[H]);const be=se=>{p.length>=Cd||(m(ie=>[...ie,se]),je())},fe=se=>{m(ie=>ie.filter((U,Ve)=>Ve!==se)),je()},Pe=l.useCallback((se,ie)=>{m(U=>U.map((Ve,He)=>He===se?ie:Ve))},[]),Be=async se=>{const ie=se.target.files;if(!ie)return;let U=0;for(let Ve=0;Ve<ie.length;Ve++){const He=ie[Ve];if(He.size>OT){q.error(a("multirun.launcher.toast.fileTooLarge",{fileName:He.name}));continue}try{const Ke=await new Promise((Xe,dt)=>{const et=new FileReader;et.onload=()=>Xe(et.result),et.onerror=dt,et.readAsDataURL(He)}),Ze={id:gu(),filename:He.name,mimeType:He.type||"application/octet-stream",size:He.size,dataUrl:Ke};h(Xe=>[...Xe,Ze]),U++}catch(Ke){console.error("File attach failed",Ke),q.error(a("multirun.launcher.toast.attachFailed",{fileName:He.name}))}}U>0&&q.success(U===1?a("multirun.launcher.toast.attachedSingle",{count:U}):a("multirun.launcher.toast.attachedPlural",{count:U})),M.current&&(M.current.value="")},G=se=>{h(ie=>ie.filter(U=>U.id!==se))},ke=l.useCallback((se,ie)=>{if(se.startsWith("/")){const He=se.indexOf(" "),Ke=se.indexOf(`
|
|
125
|
+
`),Ze=Math.min(He===-1?se.length:He,Ke===-1?se.length:Ke);if(ie<=Ze&&He===-1){T(se.substring(1,Ze)),N(!0),I(!1);return}}N(!1);const U=se.substring(0,ie),Ve=U.lastIndexOf("@");if(Ve!==-1){const He=Ve>0?U[Ve-1]:null,Ke=U.substring(Ve+1);(!He||/\s/.test(He))&&!Ke.includes(" ")&&!Ke.includes(`
|
|
126
|
+
`)?(k(Ke),I(!0)):I(!1);return}I(!1)},[]),Ee=l.useCallback(se=>{if(A&&_.current&&(se.key==="Enter"||se.key==="ArrowUp"||se.key==="ArrowDown"||se.key==="Escape"||se.key==="Tab")){se.preventDefault(),_.current.handleKeyDown(se.key);return}C&&F.current&&(se.key==="Enter"||se.key==="ArrowUp"||se.key==="ArrowDown"||se.key==="Escape"||se.key==="Tab")&&(se.preventDefault(),F.current.handleKeyDown(se.key))},[A,C]),Ae=l.useCallback(se=>{const U=$.current?.selectionStart??c.length,He=c.substring(0,U).lastIndexOf("@"),Ke=se.relativePath&&se.relativePath.trim().length>0?se.relativePath.trim():se.path||se.name,Ze=He!==-1?He:U,Xe=`${c.substring(0,Ze)}@${Ke} ${c.substring(U)}`,dt=Ze+Ke.length+2;d(Xe),I(!1),k(""),requestAnimationFrame(()=>{const et=$.current;et&&(et.selectionStart=dt,et.selectionEnd=dt,et.focus()),ke(Xe,dt)})},[c,ke]),xe=l.useCallback(se=>{const U=$.current?.selectionStart??c.length,He=c.substring(0,U).lastIndexOf("@"),Ke=He!==-1?He:U,Ze=`${c.substring(0,Ke)}@${se} ${c.substring(U)}`,Xe=Ke+se.length+2;d(Ze),I(!1),k(""),requestAnimationFrame(()=>{const dt=$.current;dt&&(dt.selectionStart=Xe,dt.selectionEnd=Xe,dt.focus()),ke(Ze,Xe)})},[c,ke]),V=l.useCallback(se=>{const ie=`/${se.name} `;d(ie),N(!1),T(""),requestAnimationFrame(()=>{const U=$.current;U&&(U.focus(),U.selectionStart=U.value.length,U.selectionEnd=U.value.length),ke(ie,ie.length)})},[ke]),de=async se=>{if(se.preventDefault(),!!c.trim()&&!(p.length<2)){x(!0),je();try{ee&&ee!==B&&re(ee);const ie=p.map(({instanceId:Ze,...Xe})=>Xe),U=y.map(Ze=>({mime:Ze.mimeType,filename:Ze.filename,url:Ze.dataUrl})),Ve=g.filter(Ze=>Ze.trim().length>0),He={name:i.trim(),prompt:c.trim(),models:ie,agent:u||void 0,worktreeBaseBranch:le,files:U.length>0?U:void 0,setupCommands:Ve.length>0?Ve:void 0},Ke=await X(He);Ke&&(Ke.firstSessionId&&Ht.getState().setCurrentSession(Ke.firstSessionId),e?.())}finally{x(!1)}}},Me=!!(i.trim()&&c.trim()&&p.length>=2&&le&&Ne&&!Ie),Le=g.filter(se=>se.trim()).length;return s.jsxs("form",{onSubmit:de,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:Y,className:me("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",W,ue),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(St,{children:[s.jsx(kt,{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(Is,{className:"h-5 w-5"})})}),s.jsx(It,{children:s.jsx("p",{children:a("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(zo,{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(Ii,{htmlFor:"multirun-project",required:!0,children:a("multirun.launcher.project.label")}),oe.length>0?s.jsxs(ps,{value:ee??void 0,onValueChange:E,children:[s.jsx(hs,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:ge?s.jsx(ys,{children:J(ge)}):s.jsx(ys,{placeholder:a("multirun.launcher.project.placeholder")})}),s.jsx(fs,{fitContent:!0,children:oe.map(se=>s.jsx(Rt,{value:se.id,className:"max-w-[24rem]",children:J(se)},se.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(Ii,{htmlFor:"group-name",required:!0,info:s.jsx(wl,{children:a("multirun.launcher.groupName.info")}),children:a("multirun.launcher.groupName.label")}),s.jsx(Bt,{id:"group-name",value:i,onChange:se=>o(se.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(Ii,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(wl,{children:a("multirun.launcher.baseBranch.info")}),children:a("multirun.launcher.baseBranch.label")}),s.jsx(PT,{directory:ne,value:le,onChange:Z,id:"multirun-worktree-base-branch"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ii,{htmlFor:"multirun-agent",info:s.jsx(wl,{children:a("multirun.launcher.agent.info")}),children:a("multirun.launcher.agent.label")}),s.jsx(DT,{value:u,onChange:f,id:"multirun-agent"})]})]}),s.jsxs(wr,{open:v,onOpenChange:S,children:[s.jsxs(Rr,{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(tg,{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")}),Le>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:Le}),s.jsx(ks,{className:me("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",v&&"rotate-180")})]}),s.jsx(jr,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:P?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:a("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[g.map((se,ie)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Bt,{value:se,onChange:U=>{const Ve=[...g];Ve[ie]=U.target.value,w(Ve)},placeholder:a("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{const U=g.filter((Ve,He)=>He!==ie);w(U)},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(Is,{className:"h-3.5 w-3.5"})})]},`${se}-${ie}`)),s.jsxs("button",{type:"button",onClick:()=>w([...g,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(zs,{className:"h-3 w-3"}),a("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Ii,{htmlFor:"prompt",required:!0,children:a("multirun.launcher.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(An,{id:"prompt",ref:$,value:c,onChange:se=>{const ie=se.target.value;d(ie);const U=se.target.selectionStart??ie.length;ke(ie,U)},onKeyDown:Ee,placeholder:a("multirun.launcher.prompt.placeholder"),className:"typography-meta min-h-[100px] max-h-[300px] resize-none overflow-y-auto field-sizing-content",required:!0}),A?s.jsx(Tg,{ref:_,searchQuery:D,onCommandSelect:V,onClose:()=>N(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,C?s.jsx(Mg,{ref:F,searchQuery:R,onFileSelect:Ae,onAgentSelect:xe,onClose:()=>I(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:M,type:"file",multiple:!0,className:"hidden",onChange:Be,accept:"*/*"}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>M.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(uv,{className:"h-3 w-3"}),a("multirun.launcher.attachments.attach")]})}),s.jsx(It,{children:a("multirun.launcher.attachments.tooltip")})]}),y.map(se=>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:[se.mimeType.startsWith("image/")?s.jsx(eg,{className:"h-3 w-3 text-muted-foreground"}):s.jsx(Xf,{className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:se.filename,children:se.filename}),s.jsx("button",{type:"button",onClick:()=>G(se.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(Is,{className:"h-3 w-3"})})]},se.id))]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Ii,{required:!0,info:s.jsx(wl,{children:a("multirun.launcher.models.info",{max:Cd})}),children:a("multirun.launcher.models.label")}),s.jsx(NT,{selectedModels:p,onAdd:be,onRemove:fe,onUpdate:Pe,minModels:2,maxModels:Cd})]}),he&&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:he})]})})}),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:[s.jsx(ve,{type:"button",variant:"ghost",size:"sm",onClick:n,children:a("multirun.launcher.actions.cancel")}),s.jsx(ve,{type:"submit",size:"sm",disabled:!Me||b,children:b?a("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:a("multirun.launcher.actions.startWithModelCount",{count:p.length})})})]})})]})};class $T extends l.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?s.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:s.jsxs(Lg,{className:"w-full max-w-md",children:[s.jsx(Iw,{className:"text-center",children:s.jsxs(Aw,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(mv,{className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(Pw,{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(ve,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(Fn,{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=nt.c(22),{t:n}=ut();let r;e[0]!==n?(r=n("chat.errorBoundary.title"),e[0]=n,e[1]=r):r=e[1];let a;e[2]!==n?(a=n("chat.errorBoundary.description"),e[2]=n,e[3]=a):a=e[3];let i;e[4]!==n?(i=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=i):i=e[5];let o;e[6]!==n?(o=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=o):o=e[7];let c;e[8]!==n?(c=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=c):c=e[9];let d;e[10]!==n?(d=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=d):d=e[11];let p;e[12]!==r||e[13]!==a||e[14]!==i||e[15]!==o||e[16]!==c||e[17]!==d?(p={title:r,description:a,sessionLabel:i,detailsSummary:o,resetAction:c,persistentHint:d},e[12]=r,e[13]=a,e[14]=i,e[15]=o,e[16]=c,e[17]=d,e[18]=p):p=e[18];let m;return e[19]!==t||e[20]!==p?(m=s.jsx($T,{...t,texts:p}),e[19]=t,e[20]=p,e[21]=m):m=e[21],m}const xu=()=>{const t=nt.c(3),n=Ht(_T)||void 0;let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Dw,{}),t[0]=r):r=t[0];let a;return t[1]!==n?(a=s.jsx(BT,{sessionId:n,children:r}),t[1]=n,t[2]=a):a=t[2],a};function _T(t){return t.currentSessionId}const VT=ua(()=>Mr(()=>Promise.resolve().then(()=>x3),void 0).then(t=>({default:t.PlanView}))),Sf=ua(()=>Mr(()=>Promise.resolve().then(()=>Y2),void 0).then(t=>({default:t.GitView}))),zT=ua(()=>Mr(()=>Promise.resolve().then(()=>Bk),void 0).then(t=>({default:t.DiffView}))),kf=ua(()=>Mr(()=>import("./TerminalView-DiV5PHoV.js"),__vite__mapDeps([5,0,1,2,3,4,6])).then(t=>({default:t.TerminalView}))),UT=ua(()=>Mr(()=>Promise.resolve().then(()=>u3),void 0).then(t=>({default:t.FilesView}))),WT=ua(()=>Mr(()=>Promise.resolve().then(()=>IA),void 0).then(t=>({default:t.SettingsView}))),KT=ua(()=>Mr(()=>import("./SettingsWindow-DfL6vlAG.js"),__vite__mapDeps([7,0,1,2,3,4,6])).then(t=>({default:t.SettingsWindow}))),HT=ua(()=>Mr(()=>import("./MultiRunWindow-BQtAxwtT.js"),__vite__mapDeps([8,0,1,2,3,4,6])).then(t=>({default:t.MultiRunWindow}))),jl=85,GT=250,qT=500,QT=400,JT=860,YT=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},XT=()=>{const{t}=ut(),e=1140,n=1220,r=640,a=700,i=De(ne=>ne.isSidebarOpen),o=De(ne=>ne.isRightSidebarOpen),c=De(ne=>ne.isBottomTerminalOpen),d=De(ne=>ne.setRightSidebarOpen),p=De(ne=>ne.setBottomTerminalOpen),m=De(ne=>ne.activeMainTab),u=De(ne=>ne.setIsMobile),f=De(ne=>ne.isSessionSwitcherOpen),y=De(ne=>ne.isSettingsDialogOpen),h=De(ne=>ne.setSettingsDialogOpen),b=De(ne=>ne.isMultiRunLauncherOpen),x=De(ne=>ne.setMultiRunLauncherOpen),g=De(ne=>ne.multiRunLauncherPrefillPrompt),{isMobile:w,isTablet:v}=dn(),S=l.useMemo(()=>Pn(),[]),P=De(ne=>ne.sidebarWidth),j=De(ne=>ne.rightSidebarWidth),[C,I]=l.useState(null),R=ta()??"",k=l.useMemo(()=>YT(R),[R]),A=De(ne=>{if(!k)return!1;const E=ne.contextPanelByDirectory[k],z=E?.tabs??[],J=z.find(H=>H.id===E?.activeTabId)??z[z.length-1];return!!(E?.isOpen&&J)}),N=De(ne=>ne.setSidebarOpen),D=l.useRef(!1),T=l.useRef(!1),M=l.useRef(!1),[$,F]=l.useState(!1),_=l.useRef(!1),O=ym(0),L=Oe.useRef(0),K=ym(0),B=Oe.useRef(0);Oe.useEffect(()=>{w&&(L.current=window.innerWidth*(jl/100),B.current=window.innerWidth*(jl/100))},[w]),Oe.useEffect(()=>{if(!w)return;const ne=$?0:-L.current;vm(O,ne,{type:"spring",stiffness:400,damping:35,mass:.8})},[$,w,O]),Oe.useEffect(()=>{if(!w)return;_.current=o;const ne=o?0:B.current;vm(K,ne,{type:"spring",stiffness:400,damping:35,mass:.8})},[w,o,K]),Oe.useEffect(()=>{w&&F(f)},[f,w]),Oe.useEffect(()=>{!w||!y||(F(!1),f&&De.getState().setSessionSwitcherOpen(!1),o&&d(!1))},[w,y,f,o,d]),Oe.useEffect(()=>{w&&(_.current=o)},[o,w]);const re=Ya(ne=>ne.checkForUpdates);l.useEffect(()=>{let H=!1,te=null;const ce=pe=>{const we=Math.round(pe*1e3);return Math.max(3e5,Math.min(864e5,we))},Se=pe=>{H||(te=window.setTimeout(async()=>{const we=await re(),W=typeof we=="number"&&Number.isFinite(we)?ce(we):36e5;Se(W)},pe))};return Se(3e3),()=>{H=!0,te!==null&&window.clearTimeout(te)}},[re]),l.useEffect(()=>{De.getState().isMobile!==w&&u(w)},[w,u]),l.useEffect(()=>{if(typeof window>"u")return;let ne;const E=()=>{ne!==void 0&&window.clearTimeout(ne),ne=window.setTimeout(()=>{De.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",E),()=>{window.removeEventListener("resize",E),ne!==void 0&&window.clearTimeout(ne)}},[]),l.useEffect(()=>{if(A){De.getState().isSidebarOpen&&(N(!1),M.current=!0);return}M.current&&(N(!0),M.current=!1)},[A,N]),l.useEffect(()=>{if(typeof window>"u")return;let ne;const E=()=>{const J=De.getState(),H=window.innerWidth,te=window.innerHeight,ce=H<e,Se=H>=n;if(ce?J.isRightSidebarOpen&&(d(!1),D.current=!0):Se&&D.current&&(d(!0),D.current=!1),!w&&!v){const pe=te<r,we=te>=a;pe?J.isBottomTerminalOpen&&(p(!1),T.current=!0):we&&T.current&&(p(!0),T.current=!1)}},z=()=>{ne!==void 0&&window.clearTimeout(ne),ne=window.setTimeout(()=>{E()},100)};return E(),window.addEventListener("resize",z),()=>{window.removeEventListener("resize",z),ne!==void 0&&window.clearTimeout(ne)}},[w,v,p,d]),l.useEffect(()=>{if(typeof window>"u")return;const ne=De.subscribe((E,z)=>{const J=window.innerWidth,H=window.innerHeight,te=J>=n,ce=H>=a;E.isRightSidebarOpen!==z.isRightSidebarOpen&&te&&(D.current=!1),E.isBottomTerminalOpen!==z.isBottomTerminalOpen&&ce&&(T.current=!1)});return()=>{ne()}},[w,v,p,d]);const oe=l.useMemo(()=>{switch(m){case"plan":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(VT,{})});case"git":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(Sf,{})});case"diff":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(zT,{})});case"terminal":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(kf,{})});case"files":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(UT,{})});default:return null}},[m]),ee=m==="chat",ae=l.useMemo(()=>Math.min(qT,Math.max(GT,P||qd)),[P]),ge=l.useMemo(()=>Math.min(JT,Math.max(QT,j||Zg)),[j]);return s.jsx(ik,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:me("main-content-safe-area h-[100dvh]",w?"flex flex-col":"flex","bg-background"),children:[s.jsx(AA,{}),s.jsx(f6,{}),s.jsx(y6,{}),s.jsx(xT,{}),w?s.jsxs(Tw,{value:{leftDrawerOpen:$,rightDrawerOpen:o,toggleLeftDrawer:()=>{o&&d(!1),F(!$)},toggleRightDrawer:()=>{$&&F(!1),d(!o)},leftDrawerX:O,rightDrawerX:K,leftDrawerWidth:L,rightDrawerWidth:B,setMobileLeftDrawerOpen:F,setRightSidebarOpen:d},children:[!y&&s.jsx(cp,{onToggleLeftDrawer:()=>{o&&d(!1),F(!$)},onToggleRightDrawer:()=>{$&&F(!1),d(!o)},leftDrawerOpen:$,rightDrawerOpen:o}),s.jsx(Fc.button,{type:"button",initial:!1,animate:{opacity:$||o?1:0,pointerEvents:$||o?"auto":"none"},className:"fixed left-0 right-0 bottom-0 top-[var(--oc-header-height,56px)] z-40 bg-black/50 cursor-default",onClick:()=>{F(!1),d(!1)},"aria-label":t("mainLayout.mobile.closeDrawerAria")}),s.jsx(Fc.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:-(L.current||window.innerWidth*.85),right:0},style:{width:`${jl}%`,x:O},onDragEnd:(ne,E)=>{const z=L.current||window.innerWidth*.85,J=z*.3,H=500,te=O.get(),ce=E.offset.x<-J||E.velocity.x<-H,Se=E.offset.x>J||E.velocity.x>H;ce?(O.set(-z),F(!1)):Se?(O.set(0),F(!0)):te>-z/2?O.set(0):O.set(-z)},className:me("fixed left-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!$,children:s.jsx("div",{"data-page-scroll-lock":"true",className:"h-full overflow-hidden flex bg-[var(--surface-background)] shadow-none drawer-safe-area",style:{backgroundImage:"linear-gradient(var(--surface-muted), var(--surface-muted))"},children:s.jsx("div",{className:"flex-1 min-w-0 overflow-hidden flex flex-col","data-page-scroll-lock":"true",children:s.jsx(on,{children:s.jsx(wf,{mobileVariant:!0})})})})}),s.jsx(Fc.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:0,right:B.current||window.innerWidth*.85},style:{width:`${jl}%`,x:K},onDragEnd:(ne,E)=>{const z=B.current||window.innerWidth*.85,J=z*.3,H=500,te=K.get(),ce=E.offset.x>J||E.velocity.x>H,Se=E.offset.x<-J||E.velocity.x<-H;ce?(K.set(z),d(!1)):Se?(K.set(0),d(!0)):te<z/2?K.set(0):K.set(z)},className:me("fixed right-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!o,children:s.jsx("div",{className:"h-full overflow-hidden flex flex-col bg-background shadow-none drawer-safe-area","data-page-scroll-lock":"true",children:s.jsx(on,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(Sf,{})})})})}),s.jsx("div",{"data-page-scroll-lock":"true",className:me("flex flex-1 overflow-hidden relative",y&&"hidden"),children:s.jsxs("main",{className:"w-full h-full overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:me("absolute inset-0",!ee&&"invisible"),children:s.jsx(on,{children:s.jsx(xu,{})})}),oe&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(on,{children:oe})}),b&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(on,{children:s.jsx(LT,{initialPrompt:g,onCreated:()=>x(!1),onCancel:()=>x(!1)})})})]})}),y&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(on,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(WT,{onClose:()=>h(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-1 overflow-hidden relative",children:s.jsxs("div",{className:me("absolute inset-0 flex overflow-hidden","bg-sidebar"),"data-page-scroll-lock":"true",children:[i?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:me("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{left:`${ae}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:me("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{left:`${ae}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)"}})]}):null,o?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:me("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{right:`${ge}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:me("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{right:`${ge}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)"}})]}):null,s.jsx(P0,{isOpen:i,isMobile:w,className:"border-0",children:s.jsx(wf,{})}),s.jsxs("div",{className:me("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-sidebar",i&&"border-l border-border/50 rounded-tl-[10px] rounded-bl-[10px]",o&&"border-r border-border/50 rounded-tr-[10px] rounded-br-[10px]"),"data-page-scroll-lock":"true",children:[s.jsx(cp,{desktopRightSidebarActionsHost:C}),s.jsx("div",{className:me("flex flex-1 min-h-0 overflow-hidden",i||ee?"":"border-l border-border/50",o?"":"border-r border-border/50"),"data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:me("absolute inset-0",!ee&&"invisible"),children:s.jsx(on,{children:s.jsx(xu,{})})}),oe&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(on,{children:oe})})]}),s.jsx(t5,{})]})}),s.jsx(S0,{isOpen:c,isMobile:w,children:c?s.jsx(on,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(kf,{})})}):null})]}),s.jsx(D0,{isOpen:o,className:"border-0",onTopActionsHostChange:I,children:s.jsx(on,{children:s.jsx(TS,{})})})]})}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(KT,{open:y,onOpenChange:h})}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(HT,{open:b,onOpenChange:x,initialPrompt:g})})]})]})})},ZT=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`},gr=t=>{const e=nt.c(8),{label:n,value:r}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=a):a=e[0];let i;e[1]!==n?(i=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=i):i=e[2];let o;e[3]!==r?(o=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=o):o=e[4];let c;return e[5]!==i||e[6]!==o?(c=s.jsxs("div",{className:"rounded-md p-2",style:a,children:[i,o]}),e[5]=i,e[6]=o,e[7]=c):c=e[7],c},Cf=t=>{const e=nt.c(43),{title:n,snapshot:r,emptyLabel:a}=t,{t:i}=ut();let o;if(e[0]!==a||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==i||e[6]!==n){const c=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(sM,0),e[8]=r.entries,e[9]=d):d=e[9];const p=d;let m;e[10]!==n?(m=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=m):m=e[11];let u;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==i?(u=r.startedAt?ZT(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=u):u=e[15];let f;e[16]!==u?(f=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:u}),e[16]=u,e[17]=f):f=e[17];let y;e[18]!==m||e[19]!==f?(y=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,f]}),e[18]=m,e[19]=f,e[20]=y):y=e[20];let h;e[21]!==i?(h=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=h):h=e[22];let b;e[23]!==r.entries.length||e[24]!==h?(b=s.jsx(gr,{label:h,value:r.entries.length}),e[23]=r.entries.length,e[24]=h,e[25]=b):b=e[25];let x;e[26]!==i?(x=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=x):x=e[27];let g;e[28]!==x||e[29]!==p?(g=s.jsx(gr,{label:x,value:p}),e[28]=x,e[29]=p,e[30]=g):g=e[30];let w;e[31]!==i?(w=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=w):w=e[32];let 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 S;e[36]!==w||e[37]!==v?(S=s.jsx(gr,{label:w,value:v}),e[36]=w,e[37]=v,e[38]=S):S=e[38];let P;e[39]!==g||e[40]!==S||e[41]!==b?(P=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[b,g,S]}),e[39]=g,e[40]=S,e[41]=b,e[42]=P):P=e[42],o=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[y,P,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(Ps,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:c.map(j=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:j.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:i("memoryDebugPanel.metric.countValue",{value:j.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:j.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:j.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:j.total})})]})]},j.metric))})})]}),e[0]=a,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=i,e[6]=n,e[7]=o}else o=e[7];return o},eM=t=>{const e=nt.c(101),{onClose:n}=t,{t:r}=ut(),[a,i]=l.useState("memory"),[o,c]=l.useState("idle"),d=Ht(nM),p=Fg(rM),m=Wo(),u=jg(aM),f=br(iM),[y,h]=l.useState(oM),[b,x]=l.useState(lM);let g;e[0]!==y.entries?(g=new Map,y.entries.forEach(Ne=>{g.set(Ne.metric,Ne.count)}),e[0]=y.entries,e[1]=g):g=e[1];let w;e[2]!==g?(w=g.get("ui.message_list.render")??0,e[2]=g,e[3]=w):w=e[3];let v;e[4]!==g?(v=g.get("ui.message_list.render.streaming")??0,e[4]=g,e[5]=v):v=e[5];let S;e[6]!==g?(S=g.get("ui.chat_message.render")??0,e[6]=g,e[7]=S):S=e[7];let P;e[8]!==g?(P=g.get("ui.chat_message.render.streaming")??0,e[8]=g,e[9]=P):P=e[9];let j;e[10]!==g?(j=g.get("ui.chat_message.render.static_during_stream")??0,e[10]=g,e[11]=j):j=e[11];let C;e[12]!==g?(C=g.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=g,e[13]=C):C=e[13];let I;e[14]!==w||e[15]!==v||e[16]!==S||e[17]!==P||e[18]!==j||e[19]!==C?(I={messageListRender:w,messageListRenderStreaming:v,chatMessageRender:S,chatMessageRenderStreaming:P,chatMessageRenderStaticDuringStream:j,chatMessageRenderStaticOutsideActiveTurnDuringStream:C},e[14]=w,e[15]=v,e[16]=S,e[17]=P,e[18]=j,e[19]=C,e[20]=I):I=e[20];const R=I;let k,A;e[21]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{const Ne=()=>{h(Al()),x(Pl())};Ne();const X=window.setInterval(Ne,500);return()=>window.clearInterval(X)},A=[],e[21]=k,e[22]=A):(k=e[21],A=e[22]),l.useEffect(k,A);let N,D;e[23]!==o?(N=()=>{if(o==="idle")return;const Ne=window.setTimeout(()=>{c("idle")},1500);return()=>window.clearTimeout(Ne)},D=[o],e[23]=o,e[24]=N,e[25]=D):(N=e[24],D=e[25]),l.useEffect(N,D);let T=0,M;if(e[26]!==u?(M=Object.keys(u),e[26]=u,e[27]=M):M=e[27],e[28]!==u||e[29]!==M||e[30]!==T){for(const Ne of M)T=T+(u[Ne]?.length??0);e[28]=u,e[29]=M,e[30]=T,e[31]=T}else T=e[31];const $=T;let F;if(e[32]!==d||e[33]!==u||e[34]!==p||e[35]!==m||e[36]!==r){let Ne;e[38]!==d||e[39]!==u||e[40]!==p||e[41]!==r?(Ne=X=>{const he=u[X.id]?.length||0,je=p.get(X.id);return{id:X.id,title:X.title||r("memoryDebugPanel.common.untitled"),messageCount:he,isStreaming:je?.isStreaming||!1,isZombie:je?.isZombie||!1,backgroundCount:je?.backgroundMessageCount||0,lastAccessed:je?.lastAccessedAt||0,isCurrent:X.id===d}},e[38]=d,e[39]=u,e[40]=p,e[41]=r,e[42]=Ne):Ne=e[42],F=m.map(Ne).sort(cM),e[32]=d,e[33]=u,e[34]=p,e[35]=m,e[36]=r,e[37]=F}else F=e[37];const _=F;let O;e[43]!==u?(O=Object.keys(u),e[43]=u,e[44]=O):O=e[44];const L=O.length;let K;e[45]===Symbol.for("react.memo_cache_sentinel")?(K=async()=>{try{const Ne={generatedAt:new Date().toISOString(),ui:Al(),vscode:Pl()};await navigator.clipboard.writeText(JSON.stringify(Ne,null,2)),c("copied")}catch{c("error")}},e[45]=K):K=e[45];const B=K;let re;e[46]===Symbol.for("react.memo_cache_sentinel")?(re={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=re):re=e[46];let oe;e[47]!==a?(oe=a==="memory"?s.jsx(pv,{className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(hv,{className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=a,e[48]=oe):oe=e[48];let ee;e[49]!==r?(ee=r("memoryDebugPanel.title"),e[49]=r,e[50]=ee):ee=e[50];let ae;e[51]!==ee?(ae=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:ee}),e[51]=ee,e[52]=ae):ae=e[52];let ge;e[53]!==oe||e[54]!==ae?(ge=s.jsxs("div",{className:"flex items-center gap-2",children:[oe,ae]}),e[53]=oe,e[54]=ae,e[55]=ge):ge=e[55];let ne;e[56]!==a?(ne=a==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(ve,{size:"xs",variant:"ghost",onClick:B,children:s.jsx(vr,{className:"h-3.5 w-3.5"})}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:()=>{Rw(),h(Al()),x(Pl())},children:s.jsx(In,{className:"h-3.5 w-3.5"})})]}):null,e[56]=a,e[57]=ne):ne=e[57];let E;e[58]!==n?(E=n?s.jsx(ve,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(Is,{className:"h-4 w-4"})}):null,e[58]=n,e[59]=E):E=e[59];let z;e[60]!==ne||e[61]!==E?(z=s.jsxs("div",{className:"flex items-center gap-1",children:[ne,E]}),e[60]=ne,e[61]=E,e[62]=z):z=e[62];let J;e[63]!==ge||e[64]!==z?(J=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[ge,z]}),e[63]=ge,e[64]=z,e[65]=J):J=e[65];let H;e[66]===Symbol.for("react.memo_cache_sentinel")?(H={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=H):H=e[66];const te=a==="memory"?"secondary":"ghost";let ce;e[67]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>i("memory"),e[67]=ce):ce=e[67];let Se;e[68]!==r?(Se=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=Se):Se=e[69];let pe;e[70]!==te||e[71]!==Se?(pe=s.jsx(ve,{size:"sm",variant:te,className:"flex-1",onClick:ce,children:Se}),e[70]=te,e[71]=Se,e[72]=pe):pe=e[72];const we=a==="streaming"?"secondary":"ghost";let W;e[73]===Symbol.for("react.memo_cache_sentinel")?(W=()=>i("streaming"),e[73]=W):W=e[73];let ue;e[74]!==r?(ue=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=ue):ue=e[75];let Y;e[76]!==we||e[77]!==ue?(Y=s.jsx(ve,{size:"sm",variant:we,className:"flex-1",onClick:W,children:ue}),e[76]=we,e[77]=ue,e[78]=Y):Y=e[78];let le;e[79]!==pe||e[80]!==Y?(le=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:H,children:[pe,Y]}),e[79]=pe,e[80]=Y,e[81]=le):le=e[81];let Z;e[82]!==a||e[83]!==L||e[84]!==o||e[85]!==d||e[86]!==u||e[87]!==p||e[88]!==_||e[89]!==m||e[90]!==R||e[91]!==y||e[92]!==r||e[93]!==f||e[94]!==$||e[95]!==b?(Z=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(gr,{label:r("memoryDebugPanel.metric.totalMessages"),value:$}),s.jsx(gr,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${L} / ${zm.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:Mw()})})]}),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:zm.ZOMBIE_TIMEOUT/1e3/60})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.githubTotalRequests")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:f})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx(Ps,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:_.map(Ne=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Ne.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:Ne.title}),Ne.isStreaming?s.jsx(ig,{className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Ne.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:Ne.messageCount})}),Ne.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Ne.backgroundCount]}):null]})]},Ne.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(ve,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(dM),currentSessionId:d,cachedSessions:Object.keys(u),memoryStates:Object.fromEntries(p)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(It,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(o==="copied"?"memoryDebugPanel.streaming.copy.copied":o==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(ve,{size:"xs",variant:"outline",onClick:B,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(gr,{label:r("memoryDebugPanel.metric.uiMetrics"),value:y.entries.length}),s.jsx(gr,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:b.entries.length}),s.jsx(gr,{label:r("memoryDebugPanel.metric.messageListRenders"),value:R.messageListRender}),s.jsx(gr,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:R.messageListRenderStreaming}),s.jsx(gr,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:R.chatMessageRender}),s.jsx(gr,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:R.chatMessageRenderStreaming}),s.jsx(gr,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:R.chatMessageRenderStaticDuringStream}),s.jsx(gr,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:R.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(Cf,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:y,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),b.entries.length>0?s.jsx(Cf,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:b,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=a,e[83]=L,e[84]=o,e[85]=d,e[86]=u,e[87]=p,e[88]=_,e[89]=m,e[90]=R,e[91]=y,e[92]=r,e[93]=f,e[94]=$,e[95]=b,e[96]=Z):Z=e[96];let Ie;return e[97]!==J||e[98]!==le||e[99]!==Z?(Ie=s.jsxs(Lg,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:re,children:[J,le,Z]}),e[97]=J,e[98]=le,e[99]=Z,e[100]=Ie):Ie=e[100],Ie},tM=eM;function sM(t,e){return t+e.count}function nM(t){return t.currentSessionId}function rM(t){return t.sessionMemoryState}function aM(t){return t.message}function iM(t){return t.totalRequestCount}function oM(){return Al()}function lM(){return Pl()}function cM(t,e){return e.lastAccessed-t.lastAccessed}function dM(t){return{id:t.id,title:t.title}}const uM=()=>{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()??"":""},mM=async()=>{const t=uM()||window.getSelection()?.toString()||"";if(!t.trim())return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(t),!0}catch{}return document.execCommand("copy")},If="openchamber:menu-action",Id="openchamber:check-for-updates",pM=t=>{const e=Ht(x=>x.openNewSessionDraft),n=De(x=>x.toggleCommandPalette),r=De(x=>x.setCommandPaletteOpen),a=De(x=>x.toggleHelpDialog),i=De(x=>x.toggleSidebar),o=De(x=>x.setSessionSwitcherOpen),c=De(x=>x.setActiveMainTab),d=De(x=>x.setSettingsDialogOpen),p=De(x=>x.setAboutDialogOpen),m=Ya(x=>x.checkForUpdates),{setThemeMode:u}=Er(),f=l.useRef(!1),y=l.useCallback(()=>{f.current||(f.current=!0,m().then(()=>{const{available:x,error:g}=Ya.getState();if(g){q.error("Failed to check for updates",{description:g});return}x||q.success("You are on the latest version")}).finally(()=>{f.current=!1}))},[m]),h=l.useCallback(()=>{Tr.requestDirectoryDialog()},[]),b=l.useCallback(x=>{switch(x){case"about":p(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":c("chat"),o(!1),e();break;case"new-worktree-session":c("chat"),o(!1),Ag();break;case"change-workspace":h();break;case"open-git-tab":{const{activeMainTab:g}=De.getState();c(g==="git"?"chat":"git");break}case"open-diff-tab":{const{activeMainTab:g}=De.getState();c(g==="diff"?"chat":"diff");break}case"open-files-tab":{const{activeMainTab:g}=De.getState();c(g==="files"?"chat":"files");break}case"open-terminal-tab":{const{activeMainTab:g}=De.getState();c(g==="terminal"?"chat":"terminal");break}case"copy":{const g=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(g)||mM();break}case"theme-light":u("light");break;case"theme-dark":u("dark");break;case"theme-system":u("system");break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"help-dialog":a();break;case"download-logs":{Ew().catch(()=>{q.error("Failed to collect OpenCode status")});break}}},[h,t,e,p,c,o,r,d,u,n,a,i]);l.useEffect(()=>{const x=w=>{const v=w.detail;v&&b(v)},g=()=>{y()};return window.addEventListener(If,x),window.addEventListener(Id,g),()=>{window.removeEventListener(If,x),window.removeEventListener(Id,g)}},[b,y]),l.useEffect(()=>{if(typeof window>"u")return;const g=window.__TAURI__?.event?.listen;if(typeof g!="function")return;let w=null,v=null;return g("openchamber:menu-action",S=>{const P=S?.payload;typeof P=="string"&&b(P)}).then(S=>{w=S}).catch(()=>{}),g("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(Id))}).then(S=>{v=S}).catch(()=>{}),()=>{(async()=>{try{const P=w?.();P instanceof Promise&&await P}catch{}try{const P=v?.();P instanceof Promise&&await P}catch{}})()}},[b])},hM=["chat","git","diff","terminal","files"],fM=["settings","agents","commands","skills","providers","usage","git-identities"],Ar={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Af(t){const e=gM();return{sessionId:xM(e),tab:bM(e),settingsPath:yM(e),diffFile:vM(e)}}function gM(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function xM(t){const e=t.get(Ar.SESSION);return!e||e.trim().length===0?null:e.trim()}function bM(t){const e=t.get(Ar.TAB);if(!e)return null;const n=e.toLowerCase().trim();return hM.includes(n)?n:null}function yM(t){const e=t.get(Ar.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(fM.includes(n),n)}function vM(t){const e=t.get(Ar.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function Pf(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(Ar.SESSION)||t.has(Ar.TAB)||t.has(Ar.SETTINGS)||t.has(Ar.FILE)}catch{return!1}}const wM="chat";function cb(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(Ar.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(Ar.SETTINGS,n),e}return t.tab!==wM&&e.set(Ar.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(Ar.FILE,t.diffFile),e}function jM(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function NM(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=cb(t),r=[...e.entries()].sort((i,o)=>i[0].localeCompare(o[0])),a=[...n.entries()].sort((i,o)=>i[0].localeCompare(o[0]));if(r.length!==a.length)return!1;for(let i=0;i<r.length;i++)if(r[i][0]!==a[i][0]||r[i][1]!==a[i][1])return!1;return!0}catch{return!0}}function SM(t,e={}){if(!(typeof window>"u")&&!kM()&&!(!e.force&&NM(t)))try{const n=cb(t),r=jM(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function kM(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function CM(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function IM(){const t=l.useMemo(()=>CM(),[]),e=l.useRef(!1),n=l.useRef(!1),r=Ht(u=>u.setCurrentSession),a=De(u=>u.setActiveMainTab),i=De(u=>u.setSettingsDialogOpen),o=De(u=>u.setSettingsPage),c=De(u=>u.navigateToDiff),d=l.useCallback(async u=>{if(!n.current){n.current=!0;try{if(u.sessionId){const f=Ht.getState().currentSessionId;u.sessionId!==f&&await r(u.sessionId)}if(u.settingsPath){o(Px(u.settingsPath)),i(!0);return}De.getState().isSettingsDialogOpen&&i(!1),u.tab&&a(u.tab),u.diffFile&&(u.tab==="diff"||!u.tab)&&c(u.diffFile)}finally{n.current=!1}}},[r,a,i,o,c]),p=l.useCallback(()=>{const u=Ht.getState(),f=De.getState();return{sessionId:u.currentSessionId,tab:f.activeMainTab,isSettingsOpen:f.isSettingsDialogOpen,settingsPath:f.settingsPage,diffFile:f.pendingDiffFile}},[]),m=l.useCallback((u={})=>{if(t||n.current)return;const f=p();SM(f,u)},[t,p]);l.useEffect(()=>{if(e.current||(e.current=!0,!Pf()))return;const u=Af();(async()=>(await d(u),t||m({replace:!0})))()},[d,t,m]),l.useEffect(()=>{if(t)return;let u=Ht.getState().currentSessionId;return Ht.subscribe(y=>{const h=y.currentSessionId;h===u||n.current||(u=h,m())})},[t,m]),l.useEffect(()=>{if(t)return;let u=De.getState().activeMainTab,f=De.getState().isSettingsDialogOpen,y=De.getState().settingsPage,h=De.getState().pendingDiffFile;return De.subscribe(x=>{if(n.current)return;const g=x.activeMainTab!==u,w=x.isSettingsDialogOpen!==f,v=x.settingsPage!==y,S=x.pendingDiffFile!==h&&x.activeMainTab==="diff";u=x.activeMainTab,f=x.isSettingsDialogOpen,y=x.settingsPage,h=x.pendingDiffFile,(g||w||v||S)&&m()})},[t,m]),l.useEffect(()=>{if(typeof window>"u"||t)return;const u=()=>{const f=Af();if(Pf())d(f);else{const y=De.getState();y.isSettingsDialogOpen&&i(!1),y.activeMainTab!=="chat"&&a("chat")}};return window.addEventListener("popstate",u),()=>{window.removeEventListener("popstate",u)}},[d,t,a,i])}const Df="pwa-install-toast-shown",AM=()=>{const t=nt.c(6),{browserTab:e}=zx(),{t:n}=ut(),r=l.useRef(n);let a,i;t[0]!==n?(a=()=>{r.current=n},i=[n],t[0]=n,t[1]=a,t[2]=i):(a=t[1],i=t[2]),l.useEffect(a,i);let o,c;t[3]!==e?(o=()=>{if(typeof window>"u"||!Sa()||!e)return;let d=null,p=null;const m=()=>{p!==null&&(q.dismiss(p),p=null)},u=async()=>{if(!d)return;const h=d;d=null,m(),await h.prompt();const{outcome:b}=await h.userChoice;b==="accepted"&&q.success(r.current("pwa.installPrompt.started"))},f=h=>{const b=h;if(typeof b.prompt!="function")return;b.preventDefault(),d=b;const x=og();x.getItem(Df)!=="true"&&p===null&&(x.setItem(Df,"true"),p=q.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{u()}}}))},y=()=>{d=null,m(),q.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",f),window.addEventListener("appinstalled",y),()=>{m(),window.removeEventListener("beforeinstallprompt",f),window.removeEventListener("appinstalled",y)}},c=[e],t[3]=e,t[4]=o,t[5]=c):(o=t[4],c=t[5]),l.useEffect(o,c)},PM=["local","remote",null],DM=["ok","not-configured","unreachable","wrong-service","missing"];function db(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!PM.includes(n)))return{valid:!1};if(typeof r!="string"||!DM.includes(r))return{valid:!1};if(n==="remote"||n==="local"){if(r==="ok"&&n==="local")return{valid:!0,outcome:{target:"local",status:"ok"}};if(r==="ok"&&n==="remote")return typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"ok",hostId:e.hostId,url:e.url}};if(r==="unreachable")return n==="local"?{valid:!0,outcome:{target:"local",status:"unreachable"}}:typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"unreachable",hostId:e.hostId,url:e.url}};if(r==="wrong-service")return n!=="remote"?{valid:!1}:typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"wrong-service",hostId:e.hostId,url:e.url}};if(r==="missing")return n!=="remote"?{valid:!1}:typeof e.hostId!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"missing",hostId:e.hostId}}}if(n===null){if(r==="not-configured")return{valid:!0,outcome:{target:null,status:"not-configured"}};if(r==="missing")return{valid:!1}}return{valid:!1}}function Tf(t){if(!t.isDesktopShell)return null;const e=t.bootOutcome;if(!e)return null;if(e.status==="ok"){if(e.target==="local")return{screen:"main"};if(e.target==="remote")return{screen:"main",hostId:e.hostId,url:e.url}}if(e.target===null&&e.status==="not-configured")return{screen:"chooser"};if(e.target==="local"&&e.status==="unreachable")return{screen:"recovery",variant:"local-unavailable"};if(e.target==="remote"){if(e.status==="unreachable")return{screen:"recovery",variant:"remote-unreachable",hostId:e.hostId,url:e.url};if(e.status==="wrong-service")return{screen:"recovery",variant:"remote-wrong-service",hostId:e.hostId,url:e.url};if(e.status==="missing")return{screen:"recovery",variant:"remote-missing",hostId:e.hostId}}return null}function TM(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function MM(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function Mf(){if(bu()!=="valid")return null;const e=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__,n=db(e);return n.valid?n.outcome:null}function bu(){if(typeof window>"u")return"not-injected";const t=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":db(t).valid?"valid":"malformed"}const RM=()=>{const t=nt.c(5),[e,n]=l.useState(EM),{isUpdating:r,message:a}=e;let i,o;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>Ow(n),o=[],t[0]=i,t[1]=o):(i=t[0],o=t[1]),l.useEffect(i,o),!r)return null;let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx($g,{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 EM(){return Fw()}const FM=({open:t,onOpenChange:e})=>{const{t:n}=ut(),[r,a]=l.useState(null),[i,o]=l.useState(!1),[c,d]=l.useState(!1),[p,m]=l.useState(null),[u,f]=l.useState(!1),y=l.useCallback(async()=>{if(!i){o(!0),d(!1);try{if(!p){q.error(n("aboutDialog.toast.copyFailed"),{description:n("aboutDialog.toast.diagnosticsNotReady")});return}const b=await Um.copyTextToClipboard(p);b.ok?(d(!0),q.success(n("aboutDialog.toast.diagnosticsCopied"))):q.error(n("aboutDialog.toast.copyFailed"),{description:b.error})}catch(b){q.error(n("aboutDialog.toast.copyFailed")),console.error("Failed to copy diagnostics:",b)}finally{o(!1)}}},[p,i,n]);l.useEffect(()=>{if(!t)return;(async()=>{try{const x=await fetch("/api/system/info");if(x.ok){const g=await x.json();if(typeof g.openchamberVersion=="string"&&g.openchamberVersion.trim()){a(g.openchamberVersion);return}}}catch{}a(await Lw())})()},[t]),l.useEffect(()=>{if(!t){m(null),f(!1);return}let b=!1;return f(!0),Um.buildDiagnosticsReport().then(x=>{b||m(x)}).catch(x=>{b||(console.error("Failed to prepare diagnostics:",x),m(null))}).finally(()=>{b||f(!1)}),()=>{b=!0}},[t]);const h=r;return s.jsx(ws,{open:t,onOpenChange:e,children:s.jsx(vs,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx($g,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"OpenChamber"}),h&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:n("aboutDialog.versionLabel",{version:h})})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("button",{onClick:y,disabled:i||u||!p,className:me("typography-meta text-muted-foreground hover:text-foreground","underline-offset-2 hover:underline","disabled:opacity-50 disabled:cursor-not-allowed"),children:n(c?"aboutDialog.actions.diagnosticsCopied":u?"aboutDialog.actions.preparingDiagnostics":"aboutDialog.actions.copyDiagnostics")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:n("aboutDialog.diagnosticsDescription")})]}),s.jsxs("div",{className:"flex items-center gap-4 pt-2",children:[s.jsxs("a",{href:"https://github.com/btriapitsyn/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(Na,{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(sg,{className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]}),s.jsxs("a",{href:"https://x.com/btriapitsyn",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(Od,{className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},Ad=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},OM=(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},LM=()=>{const t=Tn(i=>i.completeAuth),[e,n]=l.useState("working"),[r,a]=l.useState("Completing MCP authorization...");return l.useEffect(()=>{if(typeof window>"u"){n("error"),a("Browser context unavailable.");return}const i=new URLSearchParams(window.location.search),o=Ad(i,"code"),c=Ex(i),d=em(i),p=Ad(i,"error"),m=Ad(i,"error_description");if(p){d&&fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(m??p);return}(async()=>{try{if(!o)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let u=c;if(!u&&d){const f=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(f.ok){const y=await f.json().catch(()=>null);y?.name?.trim()&&(u={name:y.name.trim(),directory:typeof y.directory=="string"&&y.directory.trim()?y.directory.trim():null})}}if(!u?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");await t(u.name,o,u.directory),d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),a("Authorization completed. You can close this tab and return to OpenChamber.")}catch(u){d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(OM(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(ve,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},Rf=ua(()=>Mr(()=>import("./OnboardingScreen-Bm0_2bRQ.js"),__vite__mapDeps([9,0,1,2,3,4])).then(t=>({default:t.OnboardingScreen}))),$M=()=>{const t=nt.c(3),e=De(WM),n=De(KM);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(FM,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},BM=t=>{const e=nt.c(21),{onRetry:n,isRetrying:r}=t,{t:a}=ut();let i;e[0]!==a?(i=a("startup.initRecovery.title"),e[0]=a,e[1]=i):i=e[1];let o;e[2]!==i?(o=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=o):o=e[3];let c;e[4]!==a?(c=a("startup.initRecovery.description"),e[4]=a,e[5]=c):c=e[5];let d;e[6]!==c?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:c}),e[6]=c,e[7]=d):d=e[7];let p;e[8]!==o||e[9]!==d?(p=s.jsxs("div",{className:"flex flex-col gap-2",children:[o,d]}),e[8]=o,e[9]=d,e[10]=p):p=e[10];let m;e[11]!==r||e[12]!==a?(m=a(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=a,e[13]=m):m=e[13];let u;e[14]!==r||e[15]!==n||e[16]!==m?(u=s.jsx(ve,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=u):u=e[17];let f;return e[18]!==p||e[19]!==u?(f=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[p,u]})}),e[18]=p,e[19]=u,e[20]=f):f=e[20],f},_M=()=>{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}},VM=()=>typeof window>"u"?!1:window.location.pathname===Rx,zM=t=>{const e=nt.c(7),{embeddedSessionChat:n,isVSCodeRuntime:r}=t,a=Wo(),i=Ht(HM),o=Ht(GM);let c,d;return e[0]!==i||e[1]!==n||e[2]!==r||e[3]!==a||e[4]!==o?(c=()=>{!n||r||i!==n.sessionId&&a.some(p=>p.id===n.sessionId)&&o(n.sessionId)},d=[i,n,r,a,o],e[0]=i,e[1]=n,e[2]=r,e[3]=a,e[4]=o,e[5]=c,e[6]=d):(c=e[5],d=e[6]),l.useEffect(c,d),null};function UM({apis:t}){const e=yt(E=>E.initializeApp),n=yt(E=>E.isInitialized),r=yt(E=>E.isConnected),a=yt(E=>E.providers.length),i=yt(E=>E.agents.length),o=yt(E=>E.loadProviders),c=yt(E=>E.loadAgents),d=Ht(E=>E.error),p=Ht(E=>E.clearError),m=qs(E=>E.currentDirectory),u=qs(E=>E.setDirectory),f=qs(E=>E.isSwitchingDirectory),[y,h]=l.useState(!1),b=sr(E=>E.refreshStatus),[x,g]=l.useState(()=>t.runtime.isVSCode),[w,v]=l.useState(!0),[S,P]=l.useState(!1),[j,C]=l.useState(0),[I,R]=l.useState(!1),k=De(E=>E.wideChatLayoutEnabled),A=De(E=>E.mobileKeyboardMode),N=l.useMemo(()=>Pn(),[]),D=Lu(E=>E.setPlanModeEnabled),[T,M]=l.useState(()=>bu()),[$,F]=l.useState(()=>{const E=Mf();return E!==null?Tf({isDesktopShell:!0,bootOutcome:E}):null}),_=l.useRef(!1),O=l.useMemo(()=>_M(),[]),L=!O||w,K=l.useMemo(()=>VM(),[]);l.useEffect(()=>(Wm(y),()=>{Wm(!1)}),[y]),l.useEffect(()=>{$w(A)},[A]),l.useEffect(()=>{g(t.runtime.isVSCode)},[t.runtime.isVSCode]),l.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",k),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[k]),l.useEffect(()=>(Km(t),()=>Km(null)),[t]),l.useEffect(()=>{O||b(t.github,{force:!0})},[t.github,O,b]),Bw();const B=T==="valid",re=$?.screen==="main";l.useEffect(()=>{if(!TM({isDesktopShell:N,isInitialized:n,bootOutcomeKnown:B,bootViewIsMain:re}))return;const E=setTimeout(()=>{const z=document.getElementById("initial-loading");z&&(z.classList.add("fade-out"),setTimeout(()=>{z.remove()},300))},150);return()=>clearTimeout(E)},[N,n,B,re]),l.useEffect(()=>{if(!N||T!=="malformed")return;const E=document.getElementById("initial-loading");E&&(E.textContent="Desktop startup failed — please restart the app.")},[N,T]),l.useEffect(()=>{if(N)return;const E=setTimeout(()=>{const z=document.getElementById("initial-loading");z&&!n&&(z.classList.add("fade-out"),setTimeout(()=>{z.remove()},300))},5e3);return()=>clearTimeout(E)},[N,n]),l.useEffect(()=>{let E=!1;return(async()=>{const J=await fetch("/health",{method:"GET"}).catch(()=>null);if(!J||!J.ok||E)return;const H=await J.json().catch(()=>null);if(!H||E)return;const te=H.planModeExperimentalEnabled;D(te===!0||te===1||te==="1"||te==="true")})(),()=>{E=!0}},[D]),l.useEffect(()=>{x||e()},[e,x]),l.useEffect(()=>{if(x||n)return;let E=!0,z,J=0;const H=10,te=1e3,ce=async()=>{if(!E)return;if(J>=H){P(!0);return}const Se=yt.getState();if(Se.isInitialized){P(!1);return}J+=1,await Se.initializeApp();const pe=yt.getState();if(!E)return;if(pe.isInitialized){P(!1);return}if(J>=H){P(!0);return}const we=Math.min(te*Math.pow(2,J-1),16e3);z=setTimeout(ce,we)};return z=setTimeout(ce,te),()=>{E=!1,z&&clearTimeout(z)}},[j,n,x]),l.useEffect(()=>{n&&P(!1)},[n]),l.useEffect(()=>{if(!S)return;const E=document.getElementById("initial-loading");E&&(E.classList.add("fade-out"),setTimeout(()=>{E.remove()},300))},[S]),l.useEffect(()=>{if(x||!r||a>0&&i>0)return;let E=!0,z=0;const J=15,H=async()=>{const ce=yt.getState();if(!(ce.providers.length>0&&ce.agents.length>0))try{ce.providers.length===0&&await o(),yt.getState().agents.length===0&&await c()}catch{}};H();const te=setInterval(()=>{if(E){if(++z>=J){clearInterval(te);return}H()}},2e3);return()=>{E=!1,clearInterval(te)}},[r,x,c,o,a,i]),l.useEffect(()=>{f||x||r&&Mn.setDirectory(m)},[m,f,r,x]),l.useEffect(()=>{if(!O||typeof window>"u")return;const E=H=>{const te=H?.visible===!0;v(te)},z=H=>{if(H.origin!==window.location.origin)return;const te=H.data;te?.type==="openchamber:embedded-visibility"&&E(te.payload)},J=window;return J.__openchamberSetEmbeddedVisibility=E,window.addEventListener("message",z),()=>{window.removeEventListener("message",z),J.__openchamberSetEmbeddedVisibility===E&&delete J.__openchamberSetEmbeddedVisibility}},[O]),l.useEffect(()=>{!O?.directory||x||m!==O.directory&&u(O.directory,{showOverlay:!1})},[m,O,x,u]),l.useEffect(()=>{if(!O||typeof window>"u")return;const E=z=>{z.storageArea===window.localStorage&&z.key==="ui-store"&&De.persist.rehydrate()};return window.addEventListener("storage",E),()=>{window.removeEventListener("storage",E)}},[O]),l.useEffect(()=>{if(typeof window>"u")return;const E=z=>{const J=z.detail,H=typeof J?.sessionId=="string"?J.sessionId.trim():"";if(!H)return;const te=typeof J?.directory=="string"&&J.directory.trim().length>0?J.directory.trim():null;De.getState().setActiveMainTab("chat"),Ht.getState().setCurrentSession(H,te)};return window.addEventListener("openchamber:open-session",E),()=>window.removeEventListener("openchamber:open-session",E)},[]),l.useEffect(()=>{if(typeof window>"u")return;const E=z=>{const J=z.detail,H=typeof J?.directory=="string"&&J.directory.trim().length>0?J.directory.trim():null,te=typeof J?.projectId=="string"&&J.projectId.trim().length>0?J.projectId.trim():null;De.getState().setActiveMainTab("chat"),De.getState().setSessionSwitcherOpen(!1),Ht.getState().openNewSessionDraft({selectedProjectId:te,directoryOverride:H,preserveDirectoryOverride:!!H})};return window.addEventListener("openchamber:open-draft-session",E),()=>window.removeEventListener("openchamber:open-draft-session",E)},[]),l.useEffect(()=>{if(typeof window>"u")return;const E=z=>{const J=z.detail,H=typeof J?.projectPath=="string"?J.projectPath.trim():"";if(!H)return;const te=Es.getState(),ce=te.projects.find(Se=>Se.path===H);ce?te.setActiveProject(ce.id):te.addProject(H)};return window.addEventListener("openchamber:open-project",E),()=>window.removeEventListener("openchamber:open-project",E)},[]),l.useEffect(()=>{typeof window>"u"||!n||f||_.current||(_.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,f]),_w({enabled:L}),AM(),Vw(),IM();const oe=l.useCallback(()=>{h(E=>!E)},[]);pM(oe),l.useEffect(()=>{if(O)return;const E=z=>{$u(z)&&z.shiftKey&&!z.altKey&&(z.code==="KeyD"||z.key.toLowerCase()==="d")&&(z.preventDefault(),h(H=>!H))};return window.addEventListener("keydown",E,!0),()=>window.removeEventListener("keydown",E,!0)},[O]),l.useEffect(()=>{O||d&&setTimeout(()=>p(),5e3)},[p,O,d]),l.useEffect(()=>{if(!N||T!=="not-injected")return;let E=!1,z=0;const J=200,H=2e3,te=50,ce=()=>{if(E)return;z++;const Se=bu();if(Se!=="not-injected"){if(E=!0,M(Se),Se==="valid"){const we=Mf();we&&F(Tf({isDesktopShell:!0,bootOutcome:we}))}return}const pe=Math.min(J*Math.pow(1.1,z),H);if(z>=te){const we=document.getElementById("initial-loading");we&&!we.textContent?.includes("taking longer")&&(we.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(ce,pe)};return window.setTimeout(ce,J),()=>{E=!0}},[N,T]);const ee=l.useCallback(async()=>{if(MM({isTauriShell:ri(),isDesktopLocalOriginActive:ca()})){await Cg();return}window.location.reload()},[]),ae=l.useCallback(async()=>{if(!I){P(!1),R(!0);try{await yt.getState().initializeApp()}finally{R(!1)}yt.getState().isInitialized||C(E=>E+1)}},[I]),ge=E=>{if(E.screen==="recovery")return E.variant};if(N&&$&&$.screen!=="main"){if($.screen==="chooser")return s.jsx(on,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(l.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Rf,{mode:"first-launch",onCliAvailable:ee,onChooseRemote:()=>{}})})})});const E=ge($),z=$.screen==="recovery"&&"url"in $?$.url:void 0;return s.jsx(on,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(l.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Rf,{mode:"recovery",recoveryVariant:E,recoveryHostUrl:z,recoveryHostLabel:void 0,onCliAvailable:ee})})})})}if(O)return s.jsx(on,{children:s.jsx(Hm,{sdk:Mn.getSdkClient(),directory:m||"",children:s.jsx(Gm,{apis:t,children:s.jsx(qm,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:"h-full text-foreground bg-background",children:[s.jsx(zM,{embeddedSessionChat:O,isVSCodeRuntime:x}),s.jsx(Qm,{embeddedBackgroundWorkEnabled:L}),s.jsx(xu,{}),s.jsx(Jm,{})]})})})})});if(K)return s.jsx(on,{children:s.jsx(LM,{})});if(S&&!n&&!x&&!O)return s.jsx(on,{children:s.jsx(BM,{onRetry:()=>{ae()},isRetrying:I})});const ne=!n&&!N;return s.jsx(on,{children:s.jsx(Hm,{sdk:Mn.getSdkClient(),directory:m||"",children:s.jsx(Gm,{apis:t,children:s.jsx(aN,{children:s.jsx(zw,{children:s.jsx(qm,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:N?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(Qm,{embeddedBackgroundWorkEnabled:L}),s.jsx(XT,{}),s.jsx(Jm,{}),!ne&&s.jsxs(s.Fragment,{children:[s.jsx(RM,{}),s.jsx($M,{}),y&&s.jsx(tM,{onClose:()=>h(!1)})]})]})})})})})})})}function WM(t){return t.isAboutDialogOpen}function KM(t){return t.setAboutDialogOpen}function HM(t){return t.currentSessionId}function GM(t){return t.setCurrentSession}const qM=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();Uw();Ww().then(()=>{Promise.all([Kw(),Hw()]).catch(t=>{console.error("[main] settings init failed:",t)}),Gw(),qw(),Qw()}).catch(t=>{console.error("[main] appearance init failed:",t)});const ub=document.getElementById("root");if(!ub)throw new Error("Root element not found");fv.createRoot(ub).render(s.jsx(Oe.StrictMode,{children:s.jsx(Jw,{children:s.jsx(Yw,{children:s.jsx(Xw,{children:s.jsx(Zw,{children:s.jsx(UM,{apis:qM})})})})})}));const n8=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{LT as M,Dl as P,zr as S,bA as a,n8 as m,xn as u};
|