@openchamber/web 1.11.6 → 1.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/bin/cli.js +443 -2
- package/dist/assets/{MarkdownRendererImpl-COdbjw73.js → MarkdownRendererImpl-DaF15QNC.js} +3 -3
- package/dist/assets/{MultiRunWindow-BKSHxjMq.js → MultiRunWindow-Cl7wS_CB.js} +1 -1
- package/dist/assets/{OnboardingScreen-Chjg337p.js → OnboardingScreen-DTv6YJI1.js} +2 -2
- package/dist/assets/{SettingsWindow-C0lRRW8M.js → SettingsWindow-_c3TTL2z.js} +1 -1
- package/dist/assets/{TerminalView-Bvil3j1u.js → TerminalView-CuXkDROt.js} +3 -3
- package/dist/assets/es-CYoUf2D-.js +15 -0
- package/dist/assets/{index-B9LvUHdG.js → index-3WXrN3AX.js} +1 -1
- package/dist/assets/index-BREIbhcb.css +1 -0
- package/dist/assets/ko-2tM0fIna.js +15 -0
- package/dist/assets/main-BF3kWAJ9.js +239 -0
- package/dist/assets/{main-Blhx9Fp5.js → main-o8ZERrmU.js} +2 -2
- package/dist/assets/miniChat-BZQjpK23.js +2 -0
- package/dist/assets/{modelPrefsAutoSave-DRJSYigo.js → modelPrefsAutoSave-wwnbqBk7.js} +110 -108
- package/dist/assets/pl-Dq8uAotM.js +15 -0
- package/dist/assets/pt-BR-nh9s9DFT.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-BxZRI73j.js → renderElectronMiniChatApp-C-Ezew9P.js} +2 -2
- package/dist/assets/uk-BZtz0wUV.js +15 -0
- package/dist/assets/{vendor-.bun-Bum-iBXX.js → vendor-.bun-CV3tusA8.js} +1 -1
- package/dist/assets/zh-CN-j_nYMchE.js +15 -0
- package/dist/assets/zh-TW-B11UpkDJ.js +15 -0
- package/dist/index.html +11 -28
- package/dist/mini-chat.html +4 -4
- package/package.json +1 -1
- package/server/lib/fs/routes.js +5 -0
- package/server/lib/fs/routes.test.js +61 -1
- package/server/lib/git/DOCUMENTATION.md +1 -0
- package/server/lib/git/routes.js +82 -1
- package/server/lib/git/service.js +338 -19
- package/server/lib/git/service.test.js +414 -8
- package/server/lib/opencode/env-runtime.js +52 -4
- package/server/lib/opencode/env-runtime.test.js +82 -6
- package/server/lib/opencode/openchamber-routes.js +9 -7
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-runtime.js +39 -1
- package/server/lib/opencode/settings-runtime.test.js +39 -0
- package/server/lib/skills-catalog/source.js +1 -1
- package/dist/assets/es-BZIAUghG.js +0 -15
- package/dist/assets/index-UcCH2KN9.css +0 -1
- package/dist/assets/ko-DU9l-zox.js +0 -15
- package/dist/assets/main-d2-dY4er.js +0 -232
- package/dist/assets/miniChat-CJ7-rZFl.js +0 -2
- package/dist/assets/pl-CdqzokG-.js +0 -15
- package/dist/assets/pt-BR-Bknbr_Y3.js +0 -15
- package/dist/assets/uk-Be4E8ZNO.js +0 -15
- package/dist/assets/zh-CN-qpPiaZMg.js +0 -15
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-Bum-iBXX.js","assets/vendor--V65Sl9C2.css","assets/modelPrefsAutoSave-DRJSYigo.js","assets/index-B9LvUHdG.js","assets/index-UcCH2KN9.css","assets/TerminalView-Bvil3j1u.js","assets/SettingsWindow-C0lRRW8M.js","assets/MultiRunWindow-BKSHxjMq.js","assets/OnboardingScreen-Chjg337p.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as ot,R as l,u as io,a as hi,j as s,b as ql,C as Jl,P as oo,S as Sl,d as xx,D as kl,e as lo,f as co,g as ar,i as Xa,r as _e,k as bx,l as yx,p as Ei,m as wo,n as vx,o as wx,q as jx,_ as Tr,s as ah,v as dd,t as Za,w as ih,x as sl,W as Nx,y as Sx,V as kx,F as Cx,z as Ix,A as Gn,E as Px,B as Ln,G as Ax,H as Mi,I as Au,J as Dx,K as Tx,L as mc,M as Ex,N as Mx,O as Rx,Q as Du,T as Cl,U as Tu,X as Fx,Y as oh,Z as lh,$ as Ox,a0 as Eu,a1 as Lx,a2 as $x,a3 as _x,a4 as Bx,a5 as Vx,a6 as Mu,a7 as gt,a8 as To,a9 as zx,aa as Ux,ab as Wx,ac as Kx,ad as Hx,ae as Gx,af as qx,ag as Jx,ah as Yx,ai as Qx,aj as Xx,ak as Zx,al as Ru,am as Fu,an as Ou,ao as eb}from"./vendor-.bun-Bum-iBXX.js";import{a as tb,b as sb,f as nb}from"./index-B9LvUHdG.js";import{u as ft,a as Fe,b as ln,c as ye,I as A,d as ks,i as fn,g as or,e as br,s as nl,r as rl,f as al,h as Cs,o as on,j as Ws,T as kt,k as Ct,l as It,m as Ka,n as ta,p as Lu,D as _t,q as rb,t as Il,v as En,w as H,x as Is,y as nr,z as Ps,A as As,B as ch,C as $u,E as ab,F as ib,G as _u,H as ob,J as lb,K as cb,L as db,M as _n,N as jn,O as rr,P as ud,Q as yr,R as dh,S as ub,U as wt,V as $t,W as mb,X as uh,Y as xa,Z as Gd,_ as Hn,$ as qd,a0 as mh,a1 as pb,a2 as Bu,a3 as fb,a4 as hb,a5 as ph,a6 as gb,a7 as xb,a8 as fh,a9 as Jd,aa as Pl,ab as bb,ac as Yl,ad as Xr,ae as Yd,af as il,ag as yb,ah as vb,ai as en,aj as hh,ak as gh,al as xh,am as zr,an as ji,ao as wb,ap as bh,aq as hs,ar as ms,as as be,at as ds,au as us,av as Ha,aw as jb,ax as Nb,ay as Eo,az as wn,aA as yh,aB as vh,aC as Ql,aD as Sb,aE as wh,aF as Vu,aG as zu,aH as un,aI as Lt,aJ as vs,aK as kb,aL as Cb,aM as Ib,aN as Pb,aO as Ab,aP as Db,aQ as Tb,aR as Ss,aS as Hs,aT as Eb,aU as Mb,aV as Ns,aW as Rb,aX as Fb,aY as Ob,aZ as Lb,a_ as Ar,a$ as jo,b0 as $b,b1 as _s,b2 as Xl,b3 as pi,b4 as Ni,b5 as Si,b6 as Uu,b7 as ki,b8 as _b,b9 as as,ba as is,bb as fs,bc as os,bd as Mt,be as Bb,bf as ya,bg as Vb,bh as na,bi as Qd,bj as Zl,bk as zb,bl as Xd,bm as Ub,bn as Wb,bo as Zd,bp as Kb,bq as Ys,br as No,bs as Dr,bt as Hb,bu as Gb,bv as pc,bw as ec,bx as eu,by as tu,bz as tc,bA as Fn,bB as su,bC as Ga,bD as Al,bE as Dl,bF as Ci,bG as jh,bH as qb,bI as jr,bJ as Jb,bK as Tl,bL as Yb,bM as Wu,bN as Qb,bO as Zi,bP as sc,bQ as Nh,bR as Xb,bS as Zb,bT as So,bU as ey,bV as nu,bW as ty,bX as fi,bY as uo,bZ as Sh,b_ as Ii,b$ as kh,c0 as sy,c1 as ny,c2 as ru,c3 as ha,c4 as gi,c5 as Fa,c6 as Va,c7 as nc,c8 as ko,c9 as Co,ca as md,cb as Ch,cc as au,cd as Ih,ce as mo,cf as ry,cg as ay,ch as iy,ci as oy,cj as ly,ck as xi,cl as fc,cm as Ku,cn as cy,co as dy,cp as uy,cq as my,cr as rc,cs as hc,ct as py,cu as Hu,cv as ea,cw as fy,cx as Gu,cy as qu,cz as Ju,cA as Yu,cB as ol,cC as Qu,cD as hy,cE as gc,cF as gy,cG as xy,cH as by,cI as yy,cJ as vy,cK as wy,cL as jy,cM as xc,cN as Xu,cO as Ny,cP as Sy,cQ as ky,cR as Cy,cS as Iy,cT as bc,cU as Py,cV as Zu,cW as Ji,cX as Ay,cY as Ph,cZ as Dy,c_ as di,c$ as Ty,d0 as em,d1 as Ey,d2 as Ah,d3 as Mo,d4 as eo,d5 as My,d6 as Dh,d7 as Ry,d8 as Fy,d9 as tm,da as sm,db as Th,dc as Eh,dd as yc,de as Ro,df as Oy,dg as Ly,dh as $y,di as _y,dj as Mh,dk as Rh,dl as Fh,dm as pd,dn as iu,dp as By,dq as bs,dr as po,ds as Pi,dt as bi,du as nm,dv as er,dw as Vy,dx as to,dy as zy,dz as Oh,dA as Uy,dB as Wy,dC as fd,dD as Ky,dE as rm,dF as Hy,dG as Gy,dH as qy,dI as ou,dJ as Lh,dK as Jy,dL as Yy,dM as Qy,dN as Xy,dO as am,dP as Zy,dQ as ev,dR as tv,dS as sv,dT as vc,dU as nv,dV as rv,dW as av,dX as iv,dY as ov,dZ as lv,d_ as cv,d$ as dv,e0 as uv,e1 as mv,e2 as pv,e3 as fv,e4 as hv,e5 as gv,e6 as xv,e7 as im,e8 as bv,e9 as yv,ea as $h,eb as vv,ec as wv,ed as jv,ee as Nv,ef as ra,eg as Sv,eh as om,ei as kv,ej as ll,ek as cl,el as Cv,em as Iv,en as Pv,eo as Av,ep as Dv,eq as lm,er as Tv,es as cm,et as Ev,eu as Mv,ev as Rv,ew as dm,ex as um,ey as mm,ez as Fv,eA as _h,eB as Bh,eC as Ov,eD as Lv,eE as $v,eF as _v,eG as Bv,eH as Vv,eI as zv,eJ as Uv,eK as Wv,eL as Kv,eM as Hv}from"./modelPrefsAutoSave-DRJSYigo.js";const Gv=({transform:t})=>({...t,y:0}),qv=t=>{const e=ot.c(18),{id:n,children:r,className:a}=t;let i;e[0]!==n?(i={id:n},e[0]=n,e[1]=i):i=e[1];const{attributes:o,listeners:c,setNodeRef:d,transform:p,transition:m,isDragging:u}=ql(i);let f;e[2]!==p?(f=Jl.Transform.toString(p),e[2]=p,e[3]=f):f=e[3];let b;e[4]!==f||e[5]!==m?(b={transform:f,transition:m},e[4]=f,e[5]=m,e[6]=b):b=e[6];const x=u&&"opacity-50";let y;e[7]!==a||e[8]!==x?(y=ye("h-full rounded-md",a,x),e[7]=a,e[8]=x,e[9]=y):y=e[9];let g;return e[10]!==o||e[11]!==r||e[12]!==n||e[13]!==c||e[14]!==d||e[15]!==b||e[16]!==y?(g=s.jsx("div",{ref:d,"data-sortable-tab-id":n,style:b,className:y,...o,...c,children:r}),e[10]=o,e[11]=r,e[12]=n,e[13]=c,e[14]=d,e[15]=b,e[16]=y,e[17]=g):g=e[17],g},Jv=t=>{const e=ot.c(6),{id:n,children:r,className:a}=t;let i;e[0]!==a?(i=ye("h-full",a),e[0]=a,e[1]=i):i=e[1];let o;return e[2]!==r||e[3]!==n||e[4]!==i?(o=s.jsx("div",{className:i,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=i,e[5]=o):o=e[5],o},Er=t=>{const e=ot.c(121),{items:n,activeId:r,onSelect:a,onClose:i,onReorder:o,layoutMode:c,variant:d,activePillInsetClassName:p,activePillButtonClassName:m,inactiveTabsIconOnly:u,iconOnlyActiveTab:f,animateActivePill:b,activePillLowercase:x,className:y}=t,g=c===void 0?"scrollable":c,h=d===void 0?"default":d,j=u===void 0?!1:u,v=f===void 0?!1:f,C=x===void 0?!0:x,{t:k}=ft(),w=Fe(Yv),{isTablet:N}=ln(),I=w||N,T=l.useRef(null);let P;e[0]===Symbol.for("react.memo_cache_sentinel")?(P={left:!1,right:!1},e[0]=P):P=e[0];const[D,S]=l.useState(P);let M;e[1]!==n?(M=n.map(Qv),e[1]=n,e[2]=M):M=e[2];const E=M,R=g==="scrollable",V=h==="default",B=h==="active-pill",$=h==="animated",O=B||$,_=V,q=O||_,L=B&&R,J=O,Z=b??$,ie=typeof o=="function",ne=ie?qv:Jv;let me;e[3]===Symbol.for("react.memo_cache_sentinel")?(me=new Map,e[3]=me):me=e[3];const pe=l.useRef(me),[G,K]=l.useState(null);let Q;e[4]===Symbol.for("react.memo_cache_sentinel")?(Q={activationConstraint:{distance:8}},e[4]=Q):Q=e[4];const W=io(hi(oo,Q)),de=Xv;let ge;e[5]===Symbol.for("react.memo_cache_sentinel")?(ge=(Je,Be)=>{if(Be){pe.current.set(Je,Be);return}pe.current.delete(Je)},e[5]=ge):ge=e[5];const ve=ge;let te;e[6]!==r||e[7]!==q?(te=()=>{if(!q||!r){K(Zv);return}const Je=T.current,Be=pe.current.get(r);if(!Je||!Be){K(e1);return}let nt=0,Ge=0,at=Be;for(;at&&at!==Je;)nt=nt+at.offsetLeft,Ge=Ge+at.offsetTop,at=at.offsetParent;const Ae={left:nt,top:Ge,width:Be.offsetWidth,height:Be.offsetHeight};K(Le=>de(Le,Ae)?Le:Ae)},e[6]=r,e[7]=q,e[8]=te):te=e[8];const he=te;let ce;e[9]!==R?(ce=()=>{if(!R){S({left:!1,right:!1});return}const Je=T.current;if(!Je){S({left:!1,right:!1});return}S({left:Je.scrollLeft>2,right:Je.scrollLeft+Je.clientWidth<Je.scrollWidth-2})},e[9]=R,e[10]=ce):ce=e[10];const xe=ce;let se;e[11]!==R||e[12]!==xe?(se=()=>{if(!R){S({left:!1,right:!1});return}const Je=T.current;if(!Je)return;xe(),Je.addEventListener("scroll",xe,{passive:!0});const Be=new ResizeObserver(xe);return Be.observe(Je),()=>{Je.removeEventListener("scroll",xe),Be.disconnect()}},e[11]=R,e[12]=xe,e[13]=se):se=e[13];let ue;e[14]!==R||e[15]!==n.length||e[16]!==xe?(ue=[R,n.length,xe],e[14]=R,e[15]=n.length,e[16]=xe,e[17]=ue):ue=e[17],l.useEffect(se,ue);let Y;e[18]!==r||e[19]!==he||e[20]!==q?(Y=()=>{if(!q){K(null);return}he();const Je=T.current;if(!Je)return;const Be=new ResizeObserver(he);if(Be.observe(Je),r){const nt=pe.current.get(r);nt&&Be.observe(nt)}return()=>{Be.disconnect()}},e[18]=r,e[19]=he,e[20]=q,e[21]=Y):Y=e[21];let Se;e[22]!==r||e[23]!==n.length||e[24]!==he||e[25]!==q?(Se=[r,n.length,he,q],e[22]=r,e[23]=n.length,e[24]=he,e[25]=q,e[26]=Se):Se=e[26],l.useEffect(Y,Se);let fe;e[27]!==he?(fe=()=>{he()},e[27]=he,e[28]=fe):fe=e[28],l.useLayoutEffect(fe);let Ce;e[29]!==r||e[30]!==R||e[31]!==xe?(Ce=()=>{if(!R||!r)return;const Je=T.current;if(!Je)return;const Be=window.requestAnimationFrame(()=>{const nt=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),Ge=Je.querySelector(`[data-sortable-tab-id="${nt}"]`);Ge&&(Ge.scrollIntoView({block:"nearest",inline:"nearest"}),xe())});return()=>{window.cancelAnimationFrame(Be)}},e[29]=r,e[30]=R,e[31]=xe,e[32]=Ce):Ce=e[32];let Ie;e[33]!==r||e[34]!==R||e[35]!==n.length||e[36]!==xe?(Ie=[r,R,n.length,xe],e[33]=r,e[34]=R,e[35]=n.length,e[36]=xe,e[37]=Ie):Ie=e[37],l.useEffect(Ce,Ie);let ke;e[38]!==o?(ke=Je=>{if(!o)return;const{active:Be,over:nt}=Je;!nt||Be.id===nt.id||o(String(Be.id),String(nt.id))},e[38]=o,e[39]=ke):ke=e[39];const X=ke;let ae;e[40]!==y?(ae=ye("relative flex h-full min-w-0 flex-1",y),e[40]=y,e[41]=ae):ae=e[41];let je;e[42]!==R||e[43]!==D||e[44]!==O?(je=R&&D.left?s.jsx("div",{className:ye("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]=R,e[43]=D,e[44]=O,e[45]=je):je=e[45];let le;e[46]!==R||e[47]!==D||e[48]!==O?(le=R&&D.right?s.jsx("div",{className:ye("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]=R,e[47]=D,e[48]=O,e[49]=le):le=e[49];const Ne=O?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Me=O&&"@container/pill-tabs",Ve=O&&"pill-tabs__track",we=O&&(p??"gap-0.5 py-0.5"),ee=_&&"items-center overflow-y-hidden",F=J&&"rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[color-mix(in_srgb,var(--foreground)_2%,transparent)] p-0.5 gap-0.5",U=R?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let oe;e[50]!==Ne||e[51]!==Me||e[52]!==Ve||e[53]!==we||e[54]!==ee||e[55]!==F||e[56]!==U?(oe=ye("relative flex h-full min-w-0 flex-1",Ne,Me,Ve,we,ee,F,U),e[50]=Ne,e[51]=Me,e[52]=Ve,e[53]=we,e[54]=ee,e[55]=F,e[56]=U,e[57]=oe):oe=e[57];let Te;e[58]!==R?(Te=R?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=R,e[59]=Te):Te=e[59];let Oe;e[60]!==k?(Oe=k("sortableTabsStrip.aria.tabs"),e[60]=k,e[61]=Oe):Oe=e[61];let Pe;e[62]!==G||e[63]!==Z||e[64]!==O?(Pe=O&&G?s.jsx("div",{className:ye("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(${G.left}px, ${G.top}px, 0)`,width:`${G.width}px`,height:`${G.height}px`,transition:Z?"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]=G,e[63]=Z,e[64]=O,e[65]=Pe):Pe=e[65];let z;e[66]!==G||e[67]!==_?(z=_&&G?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(${G.left}px, 0, 0)`,width:`${G.width}px`},"aria-hidden":!0}):null,e[66]=G,e[67]=_,e[68]=z):z=e[68];let De;if(e[69]!==ne||e[70]!==r||e[71]!==m||e[72]!==C||e[73]!==I||e[74]!==v||e[75]!==j||e[76]!==B||e[77]!==w||e[78]!==R||e[79]!==n||e[80]!==i||e[81]!==a||e[82]!==L||e[83]!==O){let Je;e[85]!==ne||e[86]!==r||e[87]!==m||e[88]!==C||e[89]!==I||e[90]!==v||e[91]!==j||e[92]!==B||e[93]!==w||e[94]!==R||e[95]!==i||e[96]!==a||e[97]!==L||e[98]!==O?(Je=Be=>{const nt=Be.id===r,Ge=j&&O&&!nt&&!!Be.icon,at=!Ge,Ae=!!Be.icon&&(!v||nt),Le=j&&O&&nt&&!R&&!L,ze=Be.closable!==!1&&!!i,Ke=ze&&!!Be.icon,lt=R||L?void 0:O?Le?"flex-none basis-auto":w?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",xt=ze?ut=>{ut.button===1&&(ut.preventDefault(),ut.stopPropagation(),i?.(Be.id))}:void 0,dt=ze?t1:void 0;return s.jsx(ne,{id:Be.id,className:lt,children:s.jsxs("div",{ref:ut=>ve(Be.id,ut),onAuxClick:xt,onMouseDown:dt,className:ye("group flex h-full min-w-0 flex-nowrap items-center",R||L?"shrink-0":O?"w-full":"w-full min-w-0",O?"relative z-10 bg-transparent":nt?"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":nt,"aria-label":Ge?Be.title??Be.label:void 0,onClick:()=>a(Be.id),className:ye(O?"animated-tabs__button pill-tabs__button relative z-10 flex flex-1 min-w-0 flex-nowrap items-center justify-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] text-sm font-medium transition-colors duration-150 !min-h-0":"flex h-full min-w-0 flex-nowrap items-center typography-micro",O&&C?"lowercase":null,O&&(Ge?"gap-0":"gap-1.5"),O?L?"shrink-0 whitespace-nowrap px-3 text-center":R?"max-w-56 shrink-0 px-3 text-center":Ge?"px-2 !min-w-0 text-center":Le?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":R?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",O?m??(B?w?"h-[38px]":"h-[31px]":"h-7"):null,O?nt?"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:Be.title??Be.label,children:O?s.jsxs(s.Fragment,{children:[Ae?s.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[s.jsx("span",{className:ye("flex items-center justify-center transition-opacity",Ke&&(I?"opacity-0":"group-hover:opacity-0")),children:Be.icon}),Ke?s.jsx("span",{role:"button",tabIndex:-1,className:ye("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:s1,onClick:ut=>{ut.stopPropagation(),i?.(Be.id)},"aria-label":Be.closeLabel??`Close ${Be.label} tab`,title:Be.closeLabel??`Close ${Be.label} tab`,children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,at?s.jsx("span",{className:"animated-tabs__label truncate",children:Be.label}):null]}):s.jsxs("span",{className:ye("flex min-w-0 flex-nowrap items-center gap-1.5",!R&&"justify-center"),children:[Ae?s.jsxs("span",{className:ye("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",nt?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:ye("flex items-center justify-center transition-opacity",Ke&&(I?"opacity-0":"group-hover:opacity-0")),children:Be.icon}),Ke?s.jsx("span",{role:"button",tabIndex:-1,className:ye("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",I?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:n1,onClick:ut=>{ut.stopPropagation(),i?.(Be.id)},"aria-label":Be.closeLabel??`Close ${Be.label} tab`,title:Be.closeLabel??`Close ${Be.label} tab`,children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:Be.label})]})}),ze&&!Ke?s.jsx("button",{type:"button",onPointerDown:r1,onClick:ut=>{ut.stopPropagation(),i?.(Be.id)},className:ye("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?nt?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":nt?"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":Be.closeLabel??`Close ${Be.label} tab`,title:Be.closeLabel??`Close ${Be.label} tab`,children:s.jsx(A,{name:"close",className:"h-3 w-3"})}):null]})},Be.id)},e[85]=ne,e[86]=r,e[87]=m,e[88]=C,e[89]=I,e[90]=v,e[91]=j,e[92]=B,e[93]=w,e[94]=R,e[95]=i,e[96]=a,e[97]=L,e[98]=O,e[99]=Je):Je=e[99],De=n.map(Je),e[69]=ne,e[70]=r,e[71]=m,e[72]=C,e[73]=I,e[74]=v,e[75]=j,e[76]=B,e[77]=w,e[78]=R,e[79]=n,e[80]=i,e[81]=a,e[82]=L,e[83]=O,e[84]=De}else De=e[84];let Qe;e[100]!==oe||e[101]!==Te||e[102]!==Oe||e[103]!==Pe||e[104]!==z||e[105]!==De?(Qe=s.jsxs("div",{ref:T,className:oe,style:Te,role:"tablist","aria-label":Oe,children:[Pe,z,De]}),e[100]=oe,e[101]=Te,e[102]=Oe,e[103]=Pe,e[104]=z,e[105]=De,e[106]=Qe):Qe=e[106];let et;e[107]!==ae||e[108]!==je||e[109]!==le||e[110]!==Qe?(et=s.jsxs("div",{className:ae,children:[je,le,Qe]}),e[107]=ae,e[108]=je,e[109]=le,e[110]=Qe,e[111]=et):et=e[111];const Ze=et;if(!ie)return Ze;let We;e[112]===Symbol.for("react.memo_cache_sentinel")?(We=[Gv],e[112]=We):We=e[112];let it;e[113]!==E||e[114]!==Ze?(it=s.jsx(Sl,{items:E,strategy:xx,children:Ze}),e[113]=E,e[114]=Ze,e[115]=it):it=e[115];let qe;e[116]===Symbol.for("react.memo_cache_sentinel")?(qe=s.jsx(kl,{dropAnimation:null}),e[116]=qe):qe=e[116];let st;return e[117]!==X||e[118]!==W||e[119]!==it?(st=s.jsxs(lo,{sensors:W,collisionDetection:co,onDragEnd:X,modifiers:We,children:[it,qe]}),e[117]=X,e[118]=W,e[119]=it,e[120]=st):st=e[120],st};function Yv(t){return t.isMobile}function Qv(t){return t.id}function Xv(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 Zv(t){return t===null?t:null}function e1(t){return t===null?t:null}function t1(t){t.button===1&&t.preventDefault()}function s1(t){t.stopPropagation()}function n1(t){t.stopPropagation()}function r1(t){t.stopPropagation()}function pm(t){const e=ot.c(14);let n,r,a,i;e[0]!==t?({size:a,className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);const 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 Kr=[{id:"claude",name:"Claude"},{id:"codex",name:"Codex"},{id:"github-copilot",name:"GitHub Copilot"},{id:"google",name:"Google"},{id:"kimi-for-coding",name:"Kimi for Coding"},{id:"nano-gpt",name:"NanoGPT"},{id:"openrouter",name:"OpenRouter"},{id:"zai-coding-plan",name:"z.ai"},{id:"zhipuai-coding-plan",name:"Zhipu AI Coding Plan"},{id:"minimax-cn-coding-plan",name:"MiniMax Coding Plan (minimaxi.com)"},{id:"minimax-coding-plan",name:"MiniMax Coding Plan (minimax.io)"},{id:"ollama-cloud",name:"Ollama Cloud"},{id:"wafer",name:"Wafer.ai"}];Kr.reduce((t,e)=>(t[e.id]=e,t),{});const a1=t=>typeof t!="number"||!Number.isFinite(t)?null:Math.max(0,Math.min(100,Math.round(t))),i1=t=>typeof t!="number"||!Number.isFinite(t)?"-":`${Math.round(t)}%`,fo=(t,e)=>t??i1(e),lu=(t,e)=>{if(!t)return e??"";try{const n=new Date(t);if(!Number.isFinite(n.getTime()))return e??"";const r=new Date;return n.toDateString()===r.toDateString()?n.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}):n.toLocaleString(void 0,{month:"short",day:"numeric",weekday:"short",hour:"numeric",minute:"2-digit"})}catch{return e??""}},Vh=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",cu=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,o1=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},ho=(t,e,n,r)=>{let a=n;if(a===null&&r&&(a=o1(r)),t===null||e===null||a===null||a<=0)return null;const i=Date.now(),o=Math.max(0,(e-i)/1e3),c=Math.max(0,Math.min(a,a-o)),d=Math.max(0,Math.min(1,c/a)),p=t/100,m=t>=100&&o>0;let u;d>.01?u=Math.min(999,p/d*100):u=t;let f;m?f="exhausted":p<=d?f="on-track":u<=130?f="slightly-fast":f="too-fast";const b=a>=120*3600,x=b?86400:3600,y=b?"d":"h",g=a/x,h=Math.max(c/x,g*.01),j=t/h,v=Number.isFinite(j)?`${Math.min(999.9,Math.max(0,j)).toFixed(1)}%/${y}`:"-",C=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`;let k=null;const w=a/86400;return w>=7&&(k=100/w),{elapsedRatio:d,usageRatio:p,predictedFinalPercent:u,remainingSeconds:o,isExhausted:m,elapsedSeconds:c,totalSeconds:a,status:f,paceRateText:v,predictText:C,dailyAllocationPercent:k}},l1=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)"}},fm=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`},Zr=t=>Math.min(100,Math.max(0,t*100));function El(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 c1=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],zh={google:c1};function Uh(t,e){const n=zh[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function Wh(t){return zh[t]??[]}function Kh(t){return[...t].sort((e,n)=>e.order-n.order)}function d1(t,e){const n=new Map;for(const r of Object.keys(t)){const i=Uh(r,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(r)}return n}function u1(t,e,n){const r=new Map;for(const a of t){const i=e(a),c=Uh(i,n)?.id??null;r.has(c)||r.set(c,[]),r.get(c).push(a)}return r}function m1(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 du=6e4,hm=t=>{const e=Kr.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))):du,a=t?.usageDisplayMode==="remaining"?"remaining":"usage",i=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,o=i?i.filter(u=>typeof u=="string"&&e.includes(u)):e,c={},d=t?.usageSelectedModels;if(d&&typeof d=="object")for(const[u,f]of Object.entries(d))Array.isArray(f)&&(c[u]=f.filter(b=>typeof b=="string"));const p={},m=t?.usageExpandedFamilies;if(m&&typeof m=="object")for(const[u,f]of Object.entries(m))Array.isArray(f)&&(p[u]=f.filter(b=>typeof b=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:a,dropdownProviderIds:o,selectedModels:c,expandedFamilies:p}},p1=async()=>{const t=or()?.settings;if(t)try{const n=(await t.load())?.settings;return hm(n??null)}catch{}if(!fn()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return hm(n)}}return{autoRefresh:!1,refreshIntervalMs:du,displayMode:"usage",dropdownProviderIds:Kr.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Rs=ar()(Xa((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:du,displayMode:"usage",dropdownProviderIds:Kr.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await p1();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Kr.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}})),ks({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}}}),ks({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=m1(n,r);i.length!==0&&(t(o=>({selectedModels:{...o.selectedModels,[n]:i}})),ks({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Hh=()=>{const t=ot.c(5),e=Rs(f1),n=Rs(h1),r=Rs(g1);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 f1(t){return t.autoRefresh}function h1(t){return t.refreshIntervalMs}function g1(t){return t.fetchAllQuotas}const Ml=_e.forwardRef((t,e)=>{const n=ot.c(11);let r,a;n[0]!==t?({className:r,...a}=t,n[0]=t,n[1]=r,n[2]=a):(r=n[1],a=n[2]);let i;n[3]!==r?(i=ye("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(bx,{className:ye("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(yx,{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});Ml.displayName="Switch";const Fo=()=>{try{const e=Cs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=on.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[McpConfigStore] Error resolving config directory:",t)}return null},gm=t=>t?Object.entries(t).map(([e,n])=>({key:e,value:n})):[],xm=t=>{const e=t.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},Oo=t=>typeof t!="string"?void 0:t.trim()||void 0,wc=800,x1=5e3,b1="__default__",hd=new Map,jc=new Map,Gh=t=>t?.trim()||b1,Nc=t=>{hd.delete(Gh(t))},go=ar()(Xa(Ei((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=Fo(),a=Gh(r),i=Date.now(),o=hd.get(a)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&i-o<x1)return!0;const d=jc.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}),hd.set(a,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();jc.set(a,p);try{return await p}finally{jc.delete(a)}},createMcp:async n=>{nl("Creating MCP server configuration…");let r=!1;try{const a=bm(n),i=Fo(),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 Nc(i),d?.requiresReload?(r=!0,await rl({message:d.message,delayMs:d.reloadDelayMs??wc,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||al()}},updateMcp:async(n,r)=>{nl("Updating MCP server configuration…");let a=!1;try{const i=bm(r),o=Fo(),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 Nc(o),p?.requiresReload?(a=!0,await rl({message:p.message,delayMs:p.reloadDelayMs??wc,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||al()}},deleteMcp:async n=>{nl("Deleting MCP server configuration…");let r=!1;try{const a=Fo(),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 Nc(a),c?.requiresReload&&(r=!0,await rl({message:c.message,delayMs:c.reloadDelayMs??wc,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||al()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:wo(()=>br()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function bm(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=xm(t.environment)??{}),t.headers!==void 0&&(e.headers=xm(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:Oo(t.oauthClientId),clientSecret:Oo(t.oauthClientSecret),scope:Oo(t.oauthScope),redirectUri:Oo(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 y1={},v1={},Qr=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},oi=t=>Qr(t)??"__global__",Pa=t=>{const e=Qr(t);return e?on.getScopedApiClient(e):on.getApiClient()},vn=ar()(Xa((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=oi(n??Ws.getState().currentDirectory);return e().byDirectory[r]??y1},getDiagnosticForDirectory:n=>{const r=oi(n??Ws.getState().currentDirectory);return e().diagnosticsByDirectory[r]??v1},getErrorForDirectory:n=>{const r=oi(n??Ws.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=Qr(n?.directory??Ws.getState().currentDirectory),a=oi(r);n?.silent||t(i=>({loadingKeys:{...i.loadingKeys,[a]:!0},lastErrorKeys:{...i.lastErrorKeys,[a]:null}}));try{const c=(await Pa(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=Qr(r??Ws.getState().currentDirectory),i=oi(a),o=Pa(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=Qr(r??Ws.getState().currentDirectory);await Pa(a).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},startAuth:async(n,r)=>{const a=Qr(r??Ws.getState().currentDirectory),c=(await Pa(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=Qr(a??Ws.getState().currentDirectory);await Pa(i).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,r)=>{const a=Qr(r??Ws.getState().currentDirectory);await Pa(a).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},testConnection:async(n,r)=>{const a=Qr(r??Ws.getState().currentDirectory),i=oi(a),o=Pa(a),d=e().getStatusForDirectory(a)[n]?.status==="connected";let p,m;try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(b){p=b instanceof Error?b.message:"Connection failed",t(x=>({diagnosticsByDirectory:{...x.diagnosticsByDirectory,[i]:{...x.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:p??"Connection failed"}}}}))}await e().refresh({directory:a,silent:!0});const u=e().getStatusForDirectory(a)[n],f=u;if(!d&&u?.status==="connected"){try{await o.mcp.disconnect({name:n},{throwOnError:!0})}catch(b){m=`Connection test succeeded, but cleanup disconnect failed: ${b instanceof Error?b.message:"Disconnect failed"}`}await e().refresh({directory:a,silent:!0})}return{status:f??e().getStatusForDirectory(a)[n],error:p,warning:m}}}))),w1=(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}},j1=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},qh=({active:t,className:e})=>{const{t:n}=ft(),a=Ws(h=>h.currentDirectory)??null,i=vn(h=>h.getStatusForDirectory(a)),o=vn(h=>h.refresh),c=vn(h=>h.connect),d=vn(h=>h.disconnect),p=go(h=>h.mcpServers),m=go(h=>h.loadMcpConfigs),[u,f]=l.useState(!1),[b,x]=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 y=l.useMemo(()=>{const h=new Set(Object.keys(i));for(const j of p)j?.name&&h.add(j.name);return Array.from(h).sort((j,v)=>j.localeCompare(v))},[p,i]),g=l.useCallback(h=>{if(h?.preventDefault(),u)return;f(!0);const j=new Promise(v=>setTimeout(v,500));Promise.all([o({directory:a}),j]).finally(()=>{f(!1)})},[u,o,a]);return s.jsxs("div",{className:ye("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:g,"aria-label":n("mcpDropdown.actions.refreshAria"),children:s.jsx(A,{name:"refresh",className:ye("h-4 w-4",u&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[y.map(h=>{const j=i[h],v=j1(j),C=j?.status==="connected",k=b===h,w=w1(j,n);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:ye("h-2 w-2 rounded-full flex-shrink-0",v==="success"&&"bg-status-success",v==="error"&&"bg-status-error",v==="warning"&&"bg-status-warning",v==="default"&&"bg-muted-foreground/40"),"aria-label":w})}),s.jsx(It,{side:"left",children:s.jsx("p",{children:w})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:h})]})}),s.jsx(Ml,{checked:C,disabled:k,className:"data-[checked]:bg-status-info",onCheckedChange:async N=>{x(h);try{N?await c(h,a):await d(h,a)}finally{x(null)}}})]},h)}),y.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},xo=t=>{const e=ot.c(20),{percent:n,tonePercent:r,className:a,expectedMarkerPercent:i}=t;let o;e[0]!==n?(o=a1(n)??0,e[0]=n,e[1]=o):o=e[1];const c=o,d=r??n;let p;e[2]!==d?(p=Vh(d),e[2]=d,e[3]=p):p=e[3];const m=p,u=i!=null?Math.max(0,Math.min(100,i)):null;let f;e[4]!==m?(f=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=f):f=e[5];const b=f;let x;e[6]!==a?(x=ye("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",a),e[6]=a,e[7]=x):x=e[7];const y=`${c}%`;let g;e[8]!==b||e[9]!==y?(g={...b,width:y},e[8]=b,e[9]=y,e[10]=g):g=e[10];let h;e[11]!==c||e[12]!==g?(h=s.jsx("div",{className:"h-full transition-all duration-300",style:g,role:"progressbar","aria-valuenow":c,"aria-valuemin":0,"aria-valuemax":100}),e[11]=c,e[12]=g,e[13]=h):h=e[13];let j;e[14]!==u?(j=u!=null&&u>0&&u<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${u}%`},title:`Expected usage if spread evenly: ${Math.round(u)}% of quota`,"aria-hidden":"true"}),e[14]=u,e[15]=j):j=e[15];let v;return e[16]!==x||e[17]!==h||e[18]!==j?(v=s.jsxs("div",{className:x,children:[h,j]}),e[16]=x,e[17]=h,e[18]=j,e[19]=v):v=e[19],v},bo=t=>{const e=ot.c(67),{paceInfo:n,className:r,compact:a}=t,i=a===void 0?!1:a,{t:o}=ft();let c;e[0]!==n.status?(c=l1(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 N;e[2]!==o?(N=o("settings.usage.pace.status.onTrack"),e[2]=o,e[3]=N):N=e[3],p=N;break e}case"slightly-fast":{let N;e[4]!==o?(N=o("settings.usage.pace.status.slightlyFast"),e[4]=o,e[5]=N):N=e[5],p=N;break e}case"too-fast":{let N;e[6]!==o?(N=o("settings.usage.pace.status.tooFast"),e[6]=o,e[7]=N):N=e[7],p=N;break e}case"exhausted":{let N;e[8]!==o?(N=o("settings.usage.pace.status.usedUp"),e[8]=o,e[9]=N):N=e[9],p=N;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 N;e[13]!==r?(N=ye("flex items-center gap-1.5",r),e[13]=r,e[14]=N):N=e[14];let I;e[15]!==d?(I={backgroundColor:d},e[15]=d,e[16]=I):I=e[16];let T;e[17]!==m||e[18]!==I?(T=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]=T):T=e[19];let P;e[20]!==d?(P={color:d},e[20]=d,e[21]=P):P=e[21];const D=n.isExhausted?void 0:f;let S;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==o?(S=n.isExhausted?s.jsx(s.Fragment,{children:o("settings.usage.pace.wait",{duration:fm(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]=S):S=e[26];let M;e[27]!==S||e[28]!==P||e[29]!==D?(M=s.jsx("span",{className:"typography-micro tabular-nums",style:P,title:D,children:S}),e[27]=S,e[28]=P,e[29]=D,e[30]=M):M=e[30];let E;return e[31]!==M||e[32]!==N||e[33]!==T?(E=s.jsxs("div",{className:N,children:[T,M]}),e[31]=M,e[32]=N,e[33]=T,e[34]=E):E=e[34],E}let b;e[35]!==r?(b=ye("flex items-center justify-between gap-2",r),e[35]=r,e[36]=b):b=e[36];let x;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==o?(x=!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]=x):x=e[40];let y;e[41]!==x?(y=s.jsx("div",{className:"flex items-center gap-1.5",children:x}),e[41]=x,e[42]=y):y=e[42];let g;e[43]!==d?(g={color:d},e[43]=d,e[44]=g):g=e[44];let h;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==f||e[49]!==m||e[50]!==o?(h=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:fm(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]=h):h=e[51];let j;e[52]!==g||e[53]!==h?(j=s.jsx("span",{className:"typography-micro tabular-nums",style:g,children:h}),e[52]=g,e[53]=h,e[54]=j):j=e[54];let v;e[55]!==d?(v={backgroundColor:d},e[55]=d,e[56]=v):v=e[56];let C;e[57]!==m||e[58]!==v?(C=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:v,title:m}),e[57]=m,e[58]=v,e[59]=C):C=e[59];let k;e[60]!==j||e[61]!==C?(k=s.jsxs("div",{className:"flex items-center gap-1.5",children:[j,C]}),e[60]=j,e[61]=C,e[62]=k):k=e[62];let w;return e[63]!==k||e[64]!==b||e[65]!==y?(w=s.jsxs("div",{className:b,children:[y,k]}),e[63]=k,e[64]=b,e[65]=y,e[66]=w):w=e[66],w},vr=vx,Mr=t=>{const e=ot.c(14);let n,r,a,i;e[0]!==t?({className:a,asChild:n,children:r,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);let o;e[5]!==n||e[6]!==r?(o=n&&_e.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=ye("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(wx,{className:d,...i,...c}),e[10]=i,e[11]=c,e[12]=d,e[13]=p):p=e[13],p},wr=t=>{const e=ot.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=ye("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(jx,{className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i},ga=[{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"}],gd="finder",xd=new Set(["finder","terminal"]),bd=t=>t?ga.find(e=>e.id===t)??null:null,Sc=()=>ga.filter(t=>xd.has(t.id)).map(t=>({...t})),N1=()=>{if(typeof window>"u")return gd;const t=window.localStorage.getItem("openInAppId");return t&&bd(t)?t:gd};let kc=!1,li=!1,ca=!1,da=0,so=null;const ym=()=>{so&&(clearTimeout(so),so=null)},Br=ar()((t,e)=>({selectedAppId:N1(),availableApps:Sc(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(kc||typeof window>"u")return;kc=!0;const n=(d,p=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:Sc(),hasLoadedApps:p});return}const m=new Set(d.map(x=>x.name)),u=new Map(d.map(x=>[x.name,x.iconDataUrl??void 0])),b=ga.filter(x=>m.has(x.appName)||xd.has(x.id)).map(x=>({...x,iconDataUrl:u.get(x.appName)}));t({availableApps:b,hasLoadedApps:!0})},r=async d=>{if(!Ka()||!ta()||li||e().hasLoadedApps&&!d)return;const m=ga.map(u=>u.appName);ym(),li=!0,ca=!1,t({isScanning:!0});try{const{apps:u,success:f,hasCache:b,isCacheStale:x}=await Lu(m,d),y=f&&!b&&u.length===0&&da<3;if(t({isCacheStale:b?x:!1}),n(u,f?!y:!1),f){if(y){const h=[800,1600,3200][da]??3200;da+=1,ca=!0,so=setTimeout(()=>{r()},h);return}da=0,ca=!1;return}if(da<3){const h=[1e3,3e3,7e3][da]??7e3;da+=1,ca=!0,so=setTimeout(()=>{r()},h)}}finally{li=!1,ca||t({isScanning:!1})}};r();const a=d=>{const p=d.detail,m=p&&typeof p.openInAppId=="string"&&p.openInAppId.length>0&&bd(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)&&(da=3,ca=!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(kc||e().initialize(),!Ka()||!ta()||li||e().hasLoadedApps&&!n)return;const a=ga.map(i=>i.appName);ym(),n&&t({hasLoadedApps:!1}),li=!0,ca=!1,t({isScanning:!0});try{const{apps:i,hasCache:o,isCacheStale:c}=await Lu(a,n),d=new Set(i.map(f=>f.name)),p=new Map(i.map(f=>[f.name,f.iconDataUrl??void 0])),u=ga.filter(f=>d.has(f.appName)||xd.has(f.id)).map(f=>({...f,iconDataUrl:p.get(f.appName)}));t({availableApps:u.length>0?u:Sc(),hasLoadedApps:u.length>0,isCacheStale:o?c:!1})}finally{li=!1,ca||t({isScanning:!1})}},selectApp:async n=>{bd(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await ks({openInAppId:n}))}})),S1="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAXaSURBVFgJ7VddbBRVFP5mdme6dOnu2tZawOAPjfxU+bGQYCRAsvw8qNGEQPTRJ0I0amL0wfjgA/HBR8KLD8YgDxJEUkVFxSYYTSRii6DQQCMGIQqlW7p0u+zMzo/fuTuzO9Nt0Td94CRn7pl7z5zznZ977y5wh/7jDGiz+T979qD5Ujbfd90xlll+stOF1uI40B1+4HhkjnZk9CgLQ9iXp2/BdcbgVc/h0sAgduywudJEMwLY9Of4ugtW5p3CpL7W1jTN88VmjdQYvnDKF1mczkYuNZLeCVg3X8fa9u+nqzUB2HRpdN2pSseRQknPoUL1Jo2ICTrPGcCzdwPdHENcAnicKRqcAk7cpL5J1r0JlAtPYV1XDETM/FtH3m19r+f5by+XjNX/xnmCX3/cCzydi4CKiC7lw+PArhGgoPPFq/6E0+9vwM6d5VBNpuv03cLNfeNTRh9KnJIiV2/PvSngycC5RD+dE5zb3g7s6QESzAZc2l6wuY9SnWIAxv10r81uU85Vt1FvtpEtlc/SMFUkUofeZ2IBta0DWDmXgkfbyTRz1qAYAMczOz3p1elOxYPyEllj421hdELViPO6Kudk3ia3UGe5ABDbvtnJZ52SdYmCZ3stdeexBabFdeAbYopEowtagVUZqFapBrtAGqpiVaFrGgyjZlrmTD5yEqoEJj4iFMuA62i6L3WPZkAiuHgarZ/vbWSBkTzO2rfTR4XOJVJhjfX44MBn+OTocVWbcF5MalxXPeVL6zYonoGo44YOtDI7qHC1lkL5nHnOc+tJRi3K6iygLNGMjt1A1XVV6iUzOvVtAvMlS2I/yBYlRf8MgA6szmXQ1jDfKhSgjft6DRtrkgarAiAw5nI9v2WDSn+Zxfd9DawGxIlPPQUg0A2HGABfEIYlCDU4+q0d8O+jRzHCCFYy+nu4BaeYAoksBCDrPYsXQQ6iitgiSQaS1FHHtMzFil4DpxTl4UhORSn4WOaaiGsbu4iFRkMnYQlEV0oSJQGQ4FyYgSRDjpqPZcCR6EOOWonIEsBqArAIQOMLzw0VXRRERF2VoA6Atk1+MzsASekMJYgaFEeHR4Cr85lNGntYzgKCYd/NSNIDCXr0ZJ2jwTsjSvEMzFQCCVmKHBRahn2DNb4rDRx8pnbXOOIg0JELLMHOF1AUkaRj1V8c2TookkMS83WK9QCVpRwtf5wCykQWRKDyJ44Ytc452QUV6inmN9IDIv/6y2+YLDuqTywBEHxv8rsoxQC4Fpf4cZ2pbJ4/huxXr0EvFmoRCrAIVymLQ3Eid0GJYPsPfISBLwdwi79YQnCqBNS7LQDP5qYSAKEDypOrX4WVWYLsFy+i9cwh6CUmUKIJI2Gq5cSbnLLw849D2Ld3L4olC1u3P0c1ow5Ozgixa3puWChONG1D3eLZUQOglvng+Vp5dBfseesx5/yHyI4cBTL3wsssRGs2g6/ppHijiMLoNSSMNHofy6Nn6SPsAR02nUoTtrDTSrdoi8CTni55rlOsCf1ypaDxlFMNU1epCV5XL6Y6dmOq+BeS48NIlq7Anpjg5dOFbPdDWLQyj/aubnUKSkMKi3NhkUd4kieYtbRbYS0bFAOQKI8NO363z1RJHmamtnlwhGksxV2w/gl29WRtm8kWtWUnRShLnQvXgDOXmLg2HzlvbDiyHD8Y517YP2i4FtueFPbB9FFqKcyobk4A5y7zquUFa7IXojyHoeXmAFcY755vaI6A56Xsofm/7+cmblBTpOldQ5vs3PJDVS+RVSAaus2SpJTO80t4NTNSOQfCDrtFkBevA0ME6HGvPdDpFlekzm7rf3nFQNRQEwBZTL9warObWfx21Uv1+fx1ERqVNampGoOHpF1tsdp07RnoGMxK1vT97rbK4IP6+Tc+fWXVsahaYGL6VO09d//GXHXr7jVeqmuppqU6ff4x0RO6lqRxgxHJpWKSlcw5eWfjq5rq/CdhaL5l6JWxjDc6bP7w5sn+/uMs2B36H2bgb6v9raK0+o9IAAAAAElFTkSuQmCC",k1="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAQzSURBVFgJ7VZNbBNHFH67Xv9RxwnBDqlUoQglcZK6qSIEJIQWAYJQoVY9IE5RTzn20FMvqdpDesq9B24+NdwthAJCkZChJg1JSOXYQIwQKQIaBdtENbs73t2+N8miGWOcpFHUHniyd97OvJ9v3nv7ZgDe038cAeVd/jOZjC94sKdfU+Bj24G9igpexwYPyiu2bauKqqqirkOTqmrjnIOyFsoyUKDocSCj/7mU7ujoMER5l68JYOFZ4YSiwPjd9O0jjx7ch1KhAJZVAcdx0LxDv3XetYKjggr4I4bzHo8G4aYmONjZBYf6+2dUzfd9PNowJajUZmef/PX5zcWl0rmvvnbQHrra+f/M+S+dqYXs2t3Hz09Ve5UicCmZ3NPb1Zv66btv+65dSULA64WGxkbw+Xx8V9XK9d4pWowxeFUqgW6acHroC/j5l0sLD/PZY98MDf3t6mouQ+On3X1H7/2e7rtOztHpgbY2+CAUgperq+D3+7cNgtLSEA7D0+VluDF5FS7cSff2HT56DF1dd/3KhQTWJ/lclsc8jIrk9IfRURgZGQEvRqNSWa8D2t1W/liXXK8Ro0i0lF0ExaPEXec0SgAqhrm3VCzwdS9GQNd1GBsbg0AgAIlEAlpbW7EYLVF/U56AagieiGwbuhERlSQApmEE8c/XKXxU0fF4HNowFfPz81Aul7edBjLGbeHITANsZga4g42HVAM2Y74KM/kSIQ/izgcHB2FiYgJmZmZ4MZpYULRG5PF4+Bx/2cLDxuhhYUqFLwGoWCaQEBGhNjAa4+Pj/J3SQA6pHpqbm/kcNitIJpOgaZIZvlbrQbZNJvcjSZOZDKhwRKLic4l2Pjc3B8FgkE+trKxAVUN0RWuOZNtCHyJJACj/bgREIZcnA9PT029SQM63unuywSOwUWOuTQmAhfmnlluPxIjUk6u1RrbJh0jyV0Ap2OZnJhrbjOcRqEqBBMDCAtltAORDJAkAVj2mWS5CUXinPDUx+oxFkgBYjO0qANu2wKoqQgkAfgW7C4AiYMmfoQSgwpjj7GYRUh/Q66SAmdisNxql227FfP1bXrRlVExdtCNHwDRLdPkgwmi8OUREhe3y1NLJFpEfbWMNvBRtSI2o+KqYi+zbx4NQwptMCO8E1HjEHYjKm/HknG5FZIsCG4lEoLS2lhP1JAB3bt1KH//s+GJPd3dPJpvlN5kwXiYIhHukisr1eAItXsm6YzGItrTcn5+dvS3qSQBSqVQhFouNnj039CsaCC7mcqDjgbNT6op1AtrU8Wo3Ojk5KaVAOptdR8PDwxf3t7SMvXjxvJNOPP31a35Krt8CXKl3j2SUDip/IAjRaBRaP9z/cHW18GMikbhcrVUTAAm1t7d/NDAwcDIUCvVqmtqkyLe3ajtvvTtg4x3SLpbLa3+kUr9N5fP55beE3k/8HyLwDx2/HIx7q3WfAAAAAElFTkSuQmCC",Cc=t=>({...t,fallbackIconDataUrl:t.id==="finder"?S1:t.id==="terminal"?k1:void 0}),vm=t=>{const e=ot.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:a}=t,[i,o]=l.useState(!1);let c;e[0]!==n?(c=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=c):c=e[1];const d=c,p=r||a;if(p&&!i){let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f=()=>o(!0),e[2]=f):f=e[2];let b;return e[3]!==p?(b=s.jsx("img",{src:p,alt:"",className:"h-4 w-4 rounded-sm",onError:f}),e[3]=p,e[4]=b):b=e[4],b}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=ye("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},C1=t=>{const e=ot.c(75),{directory:n,className:r}=t,{t:a}=ft(),i=Br(I1),o=Br(P1),c=Br(A1),d=Br(D1),p=Br(T1),m=Br(E1),u=Br(M1);let f,b;e[0]!==p?(f=()=>{p()},b=[p],e[0]=p,e[1]=f,e[2]=b):(f=e[1],b=e[2]),l.useEffect(f,b);const x=Ka()&&ta();let y;e:{let G;e[3]!==o||e[4]!==i?(G=o.find(W=>W.id===i)??o.find(R1)??o[0]??ga[0],e[3]=o,e[4]=i,e[5]=G):G=e[5];const K=G;if(K){let W;e[6]!==K?(W=Cc(K),e[6]=K,e[7]=W):W=e[7],y=W;break e}let Q;e[8]===Symbol.for("react.memo_cache_sentinel")?(Q=Cc(ga[0]),e[8]=Q):Q=e[8],y=Q}const g=y;if(!x||!n||o.length===0)return null;let h;e[9]!==n?(h=async G=>{await rb(n,G.id,G.appName)||await Il(n,G.appName)},e[9]=n,e[10]=h):h=e[10];const j=h;let v;e[11]!==j||e[12]!==u?(v=async G=>{await u(G.id),await j(G)},e[11]=j,e[12]=u,e[13]=v):v=e[13];const C=v;let k;e[14]!==n||e[15]!==a?(k=async()=>{(await En(n)).ok&&H.success(a("openInApp.toast.pathCopied"))},e[14]=n,e[15]=a,e[16]=k):k=e[16];const w=k;let N;e[17]!==r?(N=ye("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=N):N=e[18];let I;e[19]!==j||e[20]!==g?(I=()=>{j(g)},e[19]=j,e[20]=g,e[21]=I):I=e[21];const T=d&&"animate-pulse";let P;e[22]!==T?(P=ye("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",T),e[22]=T,e[23]=P):P=e[23];let D;e[24]!==g.label||e[25]!==a?(D=a("openInApp.actions.openInAria",{app:g.label}),e[24]=g.label,e[25]=a,e[26]=D):D=e[26];let S;e[27]!==g.fallbackIconDataUrl||e[28]!==g.iconDataUrl||e[29]!==g.label?(S=s.jsx(vm,{label:g.label,iconDataUrl:g.iconDataUrl,fallbackIconDataUrl:g.fallbackIconDataUrl}),e[27]=g.fallbackIconDataUrl,e[28]=g.iconDataUrl,e[29]=g.label,e[30]=S):S=e[30];let M;e[31]!==P||e[32]!==D||e[33]!==S||e[34]!==I?(M=s.jsx("button",{type:"button",onClick:I,className:P,"aria-label":D,children:S}),e[31]=P,e[32]=D,e[33]=S,e[34]=I,e[35]=M):M=e[35];let E;e[36]===Symbol.for("react.memo_cache_sentinel")?(E=ye("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[36]=E):E=e[36];let R;e[37]!==a?(R=a("openInApp.actions.chooseAppAria"),e[37]=a,e[38]=R):R=e[38];let V;e[39]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=V):V=e[39];let B;e[40]!==R?(B=s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:E,"aria-label":R,children:V})}),e[40]=R,e[41]=B):B=e[41];let $;e[42]!==w?($=()=>{w()},e[42]=w,e[43]=$):$=e[43];let O;e[44]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(A,{name:"file-copy",className:"h-4 w-4"}),e[44]=O):O=e[44];let _;e[45]!==a?(_=a("openInApp.actions.copyPath"),e[45]=a,e[46]=_):_=e[46];let q;e[47]!==_?(q=s.jsx("span",{className:"typography-ui-label text-foreground",children:_}),e[47]=_,e[48]=q):q=e[48];let L;e[49]!==$||e[50]!==q?(L=s.jsxs(_t,{className:"flex items-center gap-2",onClick:$,children:[O,q]}),e[49]=$,e[50]=q,e[51]=L):L=e[51];let J;e[52]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(nr,{}),e[52]=J):J=e[52];let Z;if(e[53]!==o||e[54]!==C||e[55]!==g.id){let G;e[57]!==C||e[58]!==g.id?(G=K=>{const Q=Cc(K);return s.jsxs(_t,{className:"flex items-center gap-2",onClick:()=>{C(K)},children:[s.jsx(vm,{label:K.label,iconDataUrl:K.iconDataUrl,fallbackIconDataUrl:Q.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:K.label}),g.id===K.id?s.jsx(A,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},K.id)},e[57]=C,e[58]=g.id,e[59]=G):G=e[59],Z=o.map(G),e[53]=o,e[54]=C,e[55]=g.id,e[56]=Z}else Z=e[56];let ie;e[60]!==c||e[61]!==m||e[62]!==a?(ie=c?s.jsxs(_t,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(A,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("openInApp.actions.refreshApps")})]}):null,e[60]=c,e[61]=m,e[62]=a,e[63]=ie):ie=e[63];let ne;e[64]!==L||e[65]!==Z||e[66]!==ie?(ne=s.jsxs(Ps,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[L,J,Z,ie]}),e[64]=L,e[65]=Z,e[66]=ie,e[67]=ne):ne=e[67];let me;e[68]!==B||e[69]!==ne?(me=s.jsxs(As,{children:[B,ne]}),e[68]=B,e[69]=ne,e[70]=me):me=e[70];let pe;return e[71]!==M||e[72]!==me||e[73]!==N?(pe=s.jsxs("div",{className:N,children:[M,me]}),e[71]=M,e[72]=me,e[73]=N,e[74]=pe):pe=e[74],pe};function I1(t){return t.selectedAppId}function P1(t){return t.availableApps}function A1(t){return t.isCacheStale}function D1(t){return t.isScanning}function T1(t){return t.initialize}function E1(t){return t.loadInstalledApps}function M1(t){return t.selectApp}function R1(t){return t.id===gd}const F1=1e6,O1="terminal-store";let wm=!1;const Ic=t=>typeof t=="object"&&t!==null,L1=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function Wn(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const Pc=(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}),Ac=t=>({tabs:[t],activeTabId:t.id}),$r=(t,e)=>t.tabs.findIndex(n=>n.id===e),dn=ar()(Xa(Ei((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=Wn(n);r&&t(a=>{if(a.sessions.has(r))return a;const i=new Map(a.sessions),o=`tab-${a.nextTabId}`,c=Pc(o,"Terminal");return i.set(r,Ac(c)),{sessions:i,nextTabId:a.nextTabId+1}})},getDirectoryState:n=>{const r=Wn(n);return e().sessions.get(r)},getActiveTab:n=>{const r=Wn(n),a=e().sessions.get(r);if(!a)return;const i=a.activeTabId;return i?a.tabs.find(o=>o.id===i)??a.tabs[0]:a.tabs[0]},createTab:n=>{const r=Wn(n);if(!r)return"tab-invalid";const a=`tab-${e().nextTabId}`;return t(i=>{const o=new Map(i.sessions),c=o.get(r),d=i.nextTabId+1,m=`Terminal ${(c?.tabs.length??0)+1}`,u=Pc(a,m);return c?o.set(r,{...c,tabs:[...c.tabs,u]}):o.set(r,Ac(u)),{sessions:o,nextTabId:d}}),a},setActiveTab:(n,r)=>{const a=Wn(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);return!c||c.activeTabId===r||$r(c,r)<0?i:(o.set(a,{...c,activeTabId:r}),{sessions:o})})},setTabLabel:(n,r,a)=>{const i=Wn(n),o=a.trim();o&&t(c=>{const d=new Map(c.sessions),p=d.get(i);if(!p)return c;const m=$r(p,r);if(m<0||p.tabs[m]?.label===o)return c;const u=[...p.tabs];return u[m]={...u[m],label:o},d.set(i,{...p,tabs:u}),{sessions:d}})},setTabIconKey:(n,r,a)=>{const i=Wn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=$r(d,r);if(p<0)return o;const m=a?.trim()||null;if(d.tabs[p]?.iconKey===m)return o;const u=[...d.tabs];return u[p]={...u[p],iconKey:m},c.set(i,{...d,tabs:u}),{sessions:c}})},closeTab:async(n,r)=>{const a=Wn(n),c=e().sessions.get(a)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(c)try{await tb(c)}catch{}t(d=>{const p=new Map(d.sessions),m=p.get(a);if(!m)return d;const u=$r(m,r);if(u<0)return d;const f=m.tabs.filter(g=>g.id!==r),b=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,g])=>!(g.directory===a&&g.tabId===r))),x=Object.keys(b).length!==Object.keys(d.projectActionRuns).length;if(f.length===0){const g=`tab-${d.nextTabId}`,h=Pc(g,"Terminal");return p.set(a,Ac(h)),{sessions:p,nextTabId:d.nextTabId+1,...x?{projectActionRuns:b}:{}}}let y=m.activeTabId;return m.activeTabId===r&&(y=f[Math.min(u,f.length-1)]?.id??f[0]?.id??null),p.set(a,{...m,tabs:f,activeTabId:y}),{sessions:p,...x?{projectActionRuns:b}:{}}})},setTabSessionId:(n,r,a)=>{const i=Wn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=$r(d,r);if(p<0)return o;const m=d.tabs[p],u=a!==null&&m.terminalSessionId!==a,f=a?"running":m.terminalSessionId?"exited":m.lifecycle,b={...m,terminalSessionId:a,lifecycle:f,isConnecting:!1,...u?{bufferChunks:[],bufferLength:0}:{}},x=[...d.tabs];return x[p]=b,c.set(i,{...d,tabs:x}),{sessions:c}})},setTabLifecycle:(n,r,a)=>{const i=Wn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=$r(d,r);if(p<0)return o;const m=[...d.tabs];return m[p]={...m[p],lifecycle:a,isConnecting:!1},c.set(i,{...d,tabs:m}),{sessions:c}})},setConnecting:(n,r,a)=>{const i=Wn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=$r(d,r);if(p<0)return o;const m=[...d.tabs];return m[p]={...m[p],isConnecting:a},c.set(i,{...d,tabs:m}),{sessions:c}})},appendToBuffer:(n,r,a)=>{if(!a)return;const i=Wn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=$r(d,r);if(p<0)return o;const m=d.tabs[p],u=o.nextChunkId,f={id:u,data:a},b=[...m.bufferChunks,f];let x=m.bufferLength+a.length;for(;x>F1&&b.length>1;){const g=b.shift();if(!g)break;x-=g.data.length}const y=[...d.tabs];return y[p]={...m,bufferChunks:b,bufferLength:x},c.set(i,{...d,tabs:y}),{sessions:c,nextChunkId:u+1}})},setTabPreviewUrl:(n,r,a,i={})=>{const o=Wn(n);t(c=>{const d=new Map(c.sessions),p=d.get(o);if(!p)return c;const m=$r(p,r);if(m<0)return c;const u=p.tabs[m],f=i.autoOpened??u.previewAutoOpened,b=i.locked??u.previewUrlLocked;if(u.previewUrl===a&&u.previewAutoOpened===f&&u.previewUrlLocked===b)return c;const x=[...p.tabs];return x[m]={...u,previewUrl:a,previewAutoOpened:f,previewUrlLocked:b},d.set(o,{...p,tabs:x}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const a=Wn(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);if(!c)return i;const d=$r(c,r);if(d<0)return i;const p=c.tabs[d];if(!p.previewUrl||p.previewAutoOpened)return i;const m=[...c.tabs];return m[d]={...p,previewAutoOpened:!0},o.set(a,{...c,tabs:m}),{sessions:o}})},setProjectActionRun:n=>{t(r=>{const a=r.projectActionRuns[n.key];return a&&a.directory===n.directory&&a.actionId===n.actionId&&a.tabId===n.tabId&&a.sessionId===n.sessionId&&a.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(a=>{const i=a.projectActionRuns[n];return!i||i.status===r?a:{projectActionRuns:{...a.projectActionRuns,[n]:{...i,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const a={...r.projectActionRuns};return delete a[n],{projectActionRuns:a}})},clearBuffer:(n,r)=>{const a=Wn(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);if(!c)return i;const d=$r(c,r);if(d<0)return i;const p=[...c.tabs];return p[d]={...p[d],bufferChunks:[],bufferLength:0},o.set(a,{...c,tabs:p}),{sessions:o}})},removeDirectory:n=>{const r=Wn(n);t(a=>{const i=new Map(a.sessions);i.delete(r);const o=Object.fromEntries(Object.entries(a.projectActionRuns).filter(([,c])=>c.directory!==r));return{sessions:i,projectActionRuns:o}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:O1,storage:wo(()=>ch()),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(!Ic(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"||!Ic(p))continue;const m=Array.isArray(p.tabs)?p.tabs:[],u=[];for(const x of m){if(!Ic(x))continue;const y=typeof x.id=="string"?x.id:null;if(!y)continue;const g=L1(y);g!==null&&(a=Math.max(a,g));const h=typeof x.terminalSessionId=="string"||x.terminalSessionId===null?x.terminalSessionId:null,j=x.lifecycle,v=j==="idle"||j==="running"||j==="exited"?j:h?"running":"idle";u.push({id:y,label:typeof x.label=="string"?x.label:"Terminal",iconKey:typeof x.iconKey=="string"?x.iconKey:null,terminalSessionId:h,lifecycle:v,createdAt:typeof x.createdAt=="number"?x.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(u.length===0)continue;const f=typeof p.activeTabId=="string"?p.activeTabId:null,b=f?u.some(x=>x.id===f):!1;r.set(d,{tabs:u,activeTabId:b?f:u[0].id})}const i=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,o=Math.max(e.nextTabId,i,a+1);return{...e,sessions:r,nextChunkId:1,nextTabId:o,hasHydrated:!0}}})));if(typeof window<"u"&&!wm){wm=!0;const t=dn.persist,e=()=>{dn.getState().hasHydrated||dn.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const jm=(t,e)=>e.updatedAtMs-t.updatedAtMs,Zs=ar((t,e)=>({instances:[],statusesById:{},importCandidates:[],isLoading:!1,isSaving:!1,isImportsLoading:!1,initialized:!1,listenerReady:!1,error:null,load:async()=>{if(!e().isLoading){t({isLoading:!0,error:null});try{const[n,r]=await Promise.all([lb(),_u()]),a={};for(const i of r.sort(jm))a[i.id]=i;e().listenerReady||await cb(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 ob();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await _u(),r={};for(const a of n.sort(jm))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 ib({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=db(n,r);a&&a.trim()&&(i.nickname=a.trim()),await e().upsertInstance(i)},removeInstance:async n=>{await $u(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 ab(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 $u(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})})),Jh=[{key:"play",label:"Play",Icon:"play"},{key:"build",label:"Build",Icon:"hammer"},{key:"lint",label:"Lint",Icon:"checkbox-circle"},{key:"terminal",label:"Terminal",Icon:"terminal-box"},{key:"tools",label:"Tools",Icon:"tools"},{key:"bug",label:"Bug",Icon:"bug"},{key:"flask",label:"Flask",Icon:"flask"},{key:"rocket",label:"Rocket",Icon:"rocket"},{key:"code",label:"Code",Icon:"code"},{key:"server",label:"Server",Icon:"server"},{key:"branch",label:"Branch",Icon:"git-branch"},{key:"search",label:"Search",Icon:"search"},{key:"settings",label:"Settings",Icon:"settings-3"},{key:"brain",label:"Brain",Icon:"brain-ai-3"},{key:"stack",label:"Stack",Icon:"stack"},{key:"robot",label:"Robot",Icon:"robot-2"},{key:"command",label:"Command",Icon:"command"},{key:"file",label:"File",Icon:"file-text"}],dl=Object.fromEntries(Jh.map(t=>[t.key,t.Icon])),yd="openchamber:project-actions-updated",Yh=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},ua=(t,e)=>`${Yh(t)}::${e}`,$1=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Nm=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},_1=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=Nm(e.localPort),r=Nm(e.remotePort);if(!n||!r)return null;const a=$1(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}`}},Qh=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const a=_1(n,r);a&&e.push(a)}return e},B1=(t,e)=>{const n=(t||"").trim();return n&&Qh(e).find(i=>i.id===n)?.url||null},V1=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],z1=["dev","start","preview","serve"];async function U1(t,e,n){if(!t)return null;const r=H1(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const a=G1(n);if(a){const i=await q1(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 W1(t)){const a=await K1(),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 W1(t){const e=`${t}/index.html`,n=await Rl(e);return typeof n=="string"&&n.trim().length>0}async function K1(){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 H1(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(z1.some(a=>n.includes(a)))return e}return null}function G1(t){for(const{pattern:e}of V1)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function q1(t){const e=await Rl(`${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 Rl(`${t}/${r}`);if(typeof i=="string"&&i.trim().length>0)return a}return"npm"}async function Rl(t){const e=or()?.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 J1(t){try{const e=await Rl(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const Y1=t=>new Promise(e=>{window.setTimeout(e,t)}),Q1="\x1B",X1=new RegExp(`${Q1}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Z1=/https?:\/\/[^\s<>'"`]+/gi,mr="__openchamber_auto_discover_preview__",ew=15e3,tw=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},sw=t=>{const e=(t||"").trim();if(!e)return null;const n=/^https?:\/\//i.test(e)?e:`http://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?null:r.toString()}catch{return null}},nw=t=>{const n=t.replace(X1,"").match(Z1);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const a=[];for(const i of r)try{const o=new URL(i);o.port&&o.port.length>0&&a.push({raw:i,parsed:o})}catch{}if(a.length>0){const i=o=>{const{parsed:c}=o,d=c.hostname.toLowerCase(),p=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=c.pathname||"/",u=m.split("/").filter(Boolean).length,f=m==="/"||m==="",b=!!(c.search||c.hash);let x=0;return p&&(x+=50),f&&(x+=30),x-=Math.min(u*5,20),b&&(x-=10),x};return a.sort((o,c)=>i(c)-i(o)),a[0]?.parsed.origin??a[0]?.raw??null}return r[0]??null},Sm=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:a=!1})=>{const{t:i}=ft(),{terminal:o,runtime:c}=_n(),{isMobile:d}=ln(),p=l.useMemo(()=>jn(),[]),m=Zs(le=>le.instances),u=Zs(le=>le.load),f=Fe(le=>le.setBottomTerminalOpen),b=Fe(le=>le.setActiveMainTab),x=Fe(le=>le.setSettingsPage),y=Fe(le=>le.setSettingsDialogOpen),g=Fe(le=>le.setSettingsProjectsSelectedId),h=Fe(le=>le.openContextPreview),j=dn(le=>le.sessions),v=dn(le=>le.ensureDirectory),C=dn(le=>le.setTabLabel),k=dn(le=>le.setTabIconKey),w=dn(le=>le.setActiveTab),N=dn(le=>le.setConnecting),I=dn(le=>le.setTabSessionId),T=dn(le=>le.setTabPreviewUrl),P=dn(le=>le.projectActionRuns),D=dn(le=>le.setProjectActionRun),S=dn(le=>le.updateProjectActionRunStatus),M=dn(le=>le.removeProjectActionRun),[E,R]=l.useState([]),[V,B]=l.useState(null),[$,O]=l.useState(!1),_=l.useRef({}),q=l.useRef({}),L=l.useRef({}),J=l.useRef({}),Z=l.useRef(0),ie=t?.id??null,ne=t?.path??"",me=l.useMemo(()=>ie?{id:ie,path:ne}:null,[ie,ne]);l.useEffect(()=>{p&&u().catch(()=>{})},[p,u]);const pe=l.useCallback(async le=>{await rr(le)},[]),G=l.useCallback(async()=>{if(!me)return;const le=Z.current+1;Z.current=le,O(!0);try{const Ne=await ud(me);if(Z.current!==le)return;const Me=Ne.actions;R(Me),B(Ve=>Ve===mr||Ve&&Me.some(we=>we.id===Ve)?Ve:null)}catch{if(Z.current!==le)return}finally{Z.current===le&&O(!1)}},[me]),K=l.useMemo(()=>Yh(e||me?.path||""),[e,me?.path]),Q=l.useMemo(()=>V?E.find(le=>le.id===V)??null:null,[E,V]),W=l.useMemo(()=>({id:mr,name:i("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[i]),de=!d,ge=l.useMemo(()=>de?[W,...E]:E,[E,W,de]);l.useEffect(()=>{G()},[G]),l.useEffect(()=>{if(typeof window>"u")return;const le=Ne=>{const Me=Ne.detail;ie&&(Me?.projectId&&Me.projectId!==ie||G())};return window.addEventListener(yd,le),()=>{window.removeEventListener(yd,le)}},[G,ie]),l.useEffect(()=>{V&&(V===mr&&de||E.some(le=>le.id===V)||B(null))},[E,de,V]),l.useEffect(()=>{for(const[le,Ne]of Object.entries(P)){const Ve=j.get(Ne.directory)?.tabs.find(we=>we.id===Ne.tabId);(!Ve||Ve.terminalSessionId!==Ne.sessionId)&&M(le)}},[P,M,j]),l.useEffect(()=>{for(const[le,Ne]of Object.entries(P)){const Me=q.current[le]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};q.current[le]=Me;const Ve=ge.find(Pe=>Pe.id===Ne.actionId);if(!Ve)continue;const ee=j.get(Ne.directory)?.tabs.find(Pe=>Pe.id===Ne.tabId);if(!ee||!Array.isArray(ee.bufferChunks)||ee.bufferChunks.length===0)continue;const F=ee.bufferChunks.filter(Pe=>Me.lastSeenChunkId===null?!0:Pe.id>Me.lastSeenChunkId);if(F.length===0)continue;const U=F.map(Pe=>Pe.data).join(""),oe=`${Me.tail}${U}`,Te=!Me.openedUrl&&Ve.autoOpenUrl===!0?nw(oe):null,Oe=F[F.length-1]?.id??Me.lastSeenChunkId;if(Me.lastSeenChunkId=Oe,Me.tail=oe.slice(-512),Te)if(Me.openedUrl=!0,Me.openInPreview){const Pe=P[le];Pe&&(T(Pe.directory,Pe.tabId,Te,{locked:!1,autoOpened:!1}),Pe.status==="waiting-for-preview"&&S(le,"running"),window.clearTimeout(J.current[le]),delete J.current[le],h(Pe.directory,Te))}else pe(Te),H.success(i("projectActions.toast.openedUrlFromOutput"));q.current[le]=Me}for(const le of Object.keys(q.current))P[le]||(delete q.current[le],window.clearTimeout(J.current[le]),delete J.current[le])},[ge,h,pe,P,T,i,j,S]);const ve=l.useCallback(async(le,Ne={})=>{if(!K)throw new Error(i("projectActions.error.noActiveDirectory"));const Me=ua(K,le.id);v(K);const Ve=dn.getState(),we=Ve.getDirectoryState(K);let ee=_.current[Me]||null;const F=ee?!!we?.tabs.some(Te=>Te.id===ee):!1;(!ee||!F)&&(ee=Ve.createTab(K),_.current[Me]=ee),C(K,ee,`Action: ${le.name}`),k(K,ee,le.icon||"play"),Ne.revealTerminal!==!1&&(w(K,ee),f(!0),b("terminal"));const oe=dn.getState().getDirectoryState(K)?.tabs.find(Te=>Te.id===ee);return{key:Me,tabId:ee,sessionId:oe?.terminalSessionId??null}},[v,K,b,w,f,k,C,i]),te=l.useCallback(async le=>{if(c.isVSCode||!a&&d)return;if(!K){H.error(i("projectActions.error.noActiveDirectoryForAction"));return}const Ne=ua(K,le.id),Me=P[Ne];if(!(Me&&Me.status==="running"))try{const Ve=le.id===mr?await(async()=>{const[Qe,et]=await Promise.all([ud({id:me?.id??"",path:K}),J1(K)]),Ze=await U1(K,Qe.actions,et);if(!Ze)throw new Error(i("contextPanel.preview.noDevServer"));return{id:mr,name:i("projectActions.actions.autoDiscover"),command:Ze.command,icon:"search",autoOpenUrl:!0,openUrl:Ze.previewUrlHint||""}})():le,we=Ve.autoOpenUrl===!0&&(Ve.openUrl||"").trim().length>0,{key:ee,tabId:F,sessionId:U}=await ve(Ve,{revealTerminal:!we&&le.id!==mr});let oe=U,Te=!1;if(!oe){N(K,F,!0);try{oe=(await o.createSession({cwd:K})).sessionId,Te=!0,I(K,F,oe)}finally{N(K,F,!1)}}if(!oe)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));Te&&await Y1(350),Ve.id===mr&&(L.current[ee]?.(),N(K,F,!0),L.current[ee]=sb(oe,Qe=>{Qe.type==="data"&&typeof Qe.data=="string"&&Qe.data.length>0&&dn.getState().appendToBuffer(K,F,Qe.data),Qe.type==="exit"&&(dn.getState().setTabLifecycle(K,F,"exited"),dn.getState().setConnecting(K,F,!1),dn.getState().removeProjectActionRun(ee),delete q.current[ee],L.current[ee]?.(),delete L.current[ee],window.clearTimeout(J.current[ee]),delete J.current[ee])},()=>{dn.getState().setConnecting(K,F,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const Oe=Ve.autoOpenUrl===!0&&p&&(Ve.desktopOpenSshForward||"").trim().length>0,Pe=Ve.autoOpenUrl?sw(Ve.openUrl):null,z=Ve.autoOpenUrl&&p?B1(Ve.desktopOpenSshForward,m):null;D({key:ee,directory:K,actionId:Ve.id,tabId:F,sessionId:oe,status:Ve.id===mr&&!Pe?"waiting-for-preview":"running"}),window.clearTimeout(J.current[ee]),delete J.current[ee],Ve.id===mr&&!Pe&&(J.current[ee]=window.setTimeout(()=>{dn.getState().updateProjectActionRunStatus(ee,"running"),delete J.current[ee]},ew)),z?(T(K,F,null,{locked:!0}),pe(z),H.success(i("projectActions.toast.openedForwardedUrl"))):Pe?(T(K,F,Pe,{locked:!0,autoOpened:!0}),h(K,Pe),H.success(i("projectActions.toast.openedActionUrl"))):we?(T(K,F,null,{locked:!0}),H.error(i("projectActions.error.invalidCustomUrlFormat"))):Oe?(T(K,F,null,{locked:!0}),H.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):T(K,F,null,{locked:!1,autoOpened:!1}),q.current[ee]={lastSeenChunkId:null,openedUrl:!!z||!!Pe||we,tail:"",openInPreview:Ve.id===mr};const De=tw(Ve.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
-
`));await o.sendInput(oe,`${De}\r`)}catch(Ve){M(Ne),delete q.current[Ne],L.current[Ne]?.(),delete L.current[Ne],window.clearTimeout(J.current[Ne]),delete J.current[Ne],H.error(Ve instanceof Error?Ve.message:i("projectActions.error.failedToRunAction"))}},[m,ve,a,d,p,K,pe,h,P,c.isVSCode,M,N,D,T,I,me?.id,i,o]),he=l.useCallback(async le=>{const Ne=ua(K,le.id),Me=P[Ne];if(!Me)return;S(Ne,"stopping");try{await o.sendInput(Me.sessionId,"")}catch{}if(await new Promise(ee=>{window.setTimeout(ee,1e3)}),dn.getState().getDirectoryState(Me.directory)?.tabs.find(ee=>ee.id===Me.tabId)?.terminalSessionId===Me.sessionId){if(typeof o.forceKill=="function")try{await o.forceKill({sessionId:Me.sessionId})}catch{}else try{await o.close(Me.sessionId)}catch{}I(Me.directory,Me.tabId,null)}M(Ne),delete q.current[Ne],L.current[Ne]?.(),delete L.current[Ne],window.clearTimeout(J.current[Ne]),delete J.current[Ne]},[K,P,M,I,o,S]),ce=l.useCallback(()=>{const le=Q??ge[0];if(!le)return;const Ne=ua(K,le.id),Me=P[Ne];if(Me?.status!=="stopping"){if(Me){he(le);return}te(le)}},[ge,K,te,P,Q,he]),xe=l.useCallback((le,Ne=!1)=>{if(B(le.id),!Ne){te(le);return}const Me=ua(K,le.id),Ve=P[Me];if(Ve?.status!=="stopping"){if(Ve){he(le);return}te(le)}},[K,te,P,he]),se=l.useCallback(()=>{me?.id&&(g(me.id),x("projects"),y(!0))},[y,x,g,me?.id]);if(c.isVSCode||!a&&d||!me||!K)return null;const ue=Q??ge[0]??null;if(!ue)return null;const Y=ue.icon||"play",Se=ue.id===mr?"search":dl[Y]||"play",fe=ua(K,ue.id),Ce=P[fe],Ie=Ce?.status==="stopping",ke=Ce?.status==="waiting-for-preview",X=Ce?j.get(Ce.directory)?.tabs.find(le=>le.id===Ce.tabId)?.previewUrl??null:null,ae=!!(Ce&&X),je=()=>{!Ce||!X||h(Ce.directory,X)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:$||Ie,className:ye("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:ce,"aria-label":Ce?i("projectActions.actions.stopNamedAria",{name:ue.name}):i("projectActions.actions.runNamedAria",{name:ue.name}),children:Ie||ke?s.jsx(A,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):Ce?s.jsx(A,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(A,{name:Se,className:"h-5 w-5"})}),ae?s.jsxs(kt,{children:[s.jsx(Ct,{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:je,children:s.jsx(A,{name:"global",className:"h-4 w-4"})})}),s.jsx(It,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(As,{children:[s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(Ps,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(_t,{className:"flex items-center gap-2",onClick:se,children:[s.jsx(A,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(nr,{}),ge.map(le=>{const Ne=le.icon||"play",Me=le.id===mr?"search":dl[Ne]||"play",Ve=ua(K,le.id),we=P[Ve],ee=!!we,F=we?.status==="stopping";return s.jsxs(_t,{className:"flex items-center gap-2",onClick:()=>{xe(le,!0)},children:[s.jsx(A,{name:Me,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:le.name}),F||we?.status==="waiting-for-preview"?s.jsx(A,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):ee?s.jsx(A,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},le.id)})]})]})]}):s.jsxs("div",{className:ye("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[s.jsx("button",{type:"button",onClick:ce,disabled:$||Ie,className:ye("inline-flex h-full items-center justify-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 px-0":"px-2.5","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":Ce?i("projectActions.actions.stopNamedAria",{name:ue.name}):i("projectActions.actions.runNamedAria",{name:ue.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:Ie||ke?s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):Ce?s.jsx(A,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(A,{name:Se,className:"h-4 w-4"})})}),ae?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:je,className:ye(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.openPreview"),children:s.jsx(A,{name:"global",className:"h-4 w-4"})})}),s.jsx(It,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(As,{children:[s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:ye(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Ps,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(_t,{className:"flex items-center gap-2",onClick:se,children:[s.jsx(A,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(nr,{}),ge.map(le=>{const Ne=le.icon||"play",Me=le.id===mr?"search":dl[Ne]||"play",Ve=ua(K,le.id),we=P[Ve],ee=!!we,F=we?.status==="stopping";return s.jsxs(_t,{className:"flex items-center gap-2",onClick:()=>{xe(le,!0)},children:[s.jsx(A,{name:Me,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:le.name}),F||we?.status==="waiting-for-preview"?s.jsx(A,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):ee?s.jsx(A,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},le.id)})]})]})]})},ac="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",rw="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",$i=l.memo(function(e){const n=ot.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??ac,f=p??"h-[18px] w-[18px]";let b;n[0]!==d||n[1]!==f?(b=s.jsx(A,{name:d,className:f}),n[0]=d,n[1]=f,n[2]=b):b=n[2];let x;n[3]!==i||n[4]!==o||n[5]!==u||n[6]!==b?(x=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,"aria-label":i,className:u,children:b})}),n[3]=i,n[4]=o,n[5]=u,n[6]=b,n[7]=x):x=n[7];let y;n[8]!==a?(y=s.jsx(It,{children:s.jsx("p",{children:a})}),n[8]=a,n[9]=y):y=n[9];let g;return n[10]!==x||n[11]!==y?(g=s.jsxs(kt,{children:[x,y]}),n[10]=x,n[11]=y,n[12]=g):g=n[12],g}),aw=l.memo(function(e){const n=ot.c(42),{isMobile:r,githubAuthStatus:a,githubAccounts:i,githubAvatarUrl:o,githubLogin:c,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:p}=e,{t:m}=ft();if(!a?.connected||r)return null;if(i.length>1){let x;n[0]===Symbol.for("react.memo_cache_sentinel")?(x=ye(ac,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=x):x=n[0];let y;n[1]!==c||n[2]!==m?(y=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[1]=c,n[2]=m,n[3]=y):y=n[3];let g;n[4]!==o||n[5]!==c||n[6]!==m?(g=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(A,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=o,n[5]=c,n[6]=m,n[7]=g):g=n[7];let h;n[8]!==d||n[9]!==y||n[10]!==g?(h=s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:x,title:y,disabled:d,children:g})}),n[8]=d,n[9]=y,n[10]=g,n[11]=h):h=n[11];let j;n[12]!==m?(j=m("header.github.accountsTitle"),n[12]=m,n[13]=j):j=n[13];let v;n[14]!==j?(v=s.jsx(dh,{className:"typography-ui-header font-semibold text-foreground",children:j}),n[14]=j,n[15]=v):v=n[15];let C;n[16]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(nr,{}),n[16]=C):C=n[16];let k;if(n[17]!==i||n[18]!==p||n[19]!==d||n[20]!==m){let I;n[22]!==p||n[23]!==d||n[24]!==m?(I=T=>{const P=T.user,D=!!T.current;return s.jsxs(_t,{className:"gap-2",disabled:D||d,onSelect:()=>{D||p(T.id)},children:[P?.avatarUrl?s.jsx("img",{src:P.avatarUrl,alt:P.login?m("header.github.avatarWithLogin",{login:P.login}):m("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(A,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:P?.name?.trim()||P?.login||"GitHub"}),P?.login?s.jsx("span",{className:"truncate typography-micro font-mono text-muted-foreground",children:P.login}):null]}),D?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null]},T.id)},n[22]=p,n[23]=d,n[24]=m,n[25]=I):I=n[25],k=i.map(I),n[17]=i,n[18]=p,n[19]=d,n[20]=m,n[21]=k}else k=n[21];let w;n[26]!==v||n[27]!==k?(w=s.jsxs(Ps,{align:"end",className:"w-64",children:[v,C,k]}),n[26]=v,n[27]=k,n[28]=w):w=n[28];let N;return n[29]!==h||n[30]!==w?(N=s.jsxs(As,{children:[h,w]}),n[29]=h,n[30]=w,n[31]=N):N=n[31],N}let u;n[32]!==c||n[33]!==m?(u=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[32]=c,n[33]=m,n[34]=u):u=n[34];let 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(A,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=o,n[36]=c,n[37]=m,n[38]=f):f=n[38];let b;return n[39]!==u||n[40]!==f?(b=s.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:u,children:f}),n[39]=u,n[40]=f,n[41]=b):b=n[41],b}),iw=l.memo(function(e){const n=ot.c(76),{isDesktopApp:r,currentInstanceLabel:a,compactCurrentInstanceLabel:i,isDesktopServicesOpen:o,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,desktopServicesTab:p,setDesktopServicesTab:m,quotaResultsLength:u,fetchAllQuotas:f,servicesTabItems:b,quotaLastUpdated:x,quotaDisplayMode:y,quotaDisplayTabItems:g,handleDisplayModeChange:h,handleUsageRefresh:j,isQuotaLoading:v,isUsageRefreshSpinning:C,hasRateLimits:k,rateLimitGroups:w,expandedFamilies:N,toggleFamilyExpanded:I,shortcutLabel:T,showDevShutdown:P,isDevShutdownInFlight:D,onDevShutdown:S}=e,{t:M}=ft();let E;n[0]!==p||n[1]!==f||n[2]!==u||n[3]!==d||n[4]!==c?(E=W=>{c(W),W&&(d(),p==="usage"&&u===0&&f())},n[0]=p,n[1]=f,n[2]=u,n[3]=d,n[4]=c,n[5]=E):E=n[5];let R;n[6]!==a||n[7]!==r||n[8]!==M?(R=r?M("header.services.openWithCurrent",{current:a}):M("header.services.open"),n[6]=a,n[7]=r,n[8]=M,n[9]=R):R=n[9];const V=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let B;n[10]!==V?(B=ye(ac,V),n[10]=V,n[11]=B):B=n[11];let $;n[12]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(A,{name:"stack",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 _;n[16]!==R||n[17]!==B||n[18]!==O?(_=s.jsx(Ct,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":R,className:B,children:[$,O]})})}),n[16]=R,n[17]=B,n[18]=O,n[19]=_):_=n[19];let q;n[20]!==a||n[21]!==r||n[22]!==T||n[23]!==M?(q=r?M("header.services.tooltip.currentInstanceWithShortcuts",{current:a,toggle:T("toggle_services_menu"),nextTab:T("cycle_services_tab")}):M("header.services.tooltip.servicesWithShortcuts",{toggle:T("toggle_services_menu"),nextTab:T("cycle_services_tab")}),n[20]=a,n[21]=r,n[22]=T,n[23]=M,n[24]=q):q=n[24];let L;n[25]!==q?(L=s.jsx(It,{children:s.jsx("p",{children:q})}),n[25]=q,n[26]=L):L=n[26];let J;n[27]!==_||n[28]!==L?(J=s.jsxs(kt,{children:[_,L]}),n[27]=_,n[28]=L,n[29]=J):J=n[29];let Z;n[30]!==f||n[31]!==u||n[32]!==m?(Z=W=>{const de=W;m(de),de==="usage"&&u===0&&f()},n[30]=f,n[31]=u,n[32]=m,n[33]=Z):Z=n[33];let ie;n[34]!==p||n[35]!==b||n[36]!==Z?(ie=s.jsx("div",{className:"sticky top-0 z-20 px-2 pt-1.5 pb-px",children:s.jsx("div",{className:"h-9",children:s.jsx(Er,{items:b,activeId:p,onSelect:Z,layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),n[34]=p,n[35]=b,n[36]=Z,n[37]=ie):ie=n[37];let ne;n[38]!==p||n[39]!==r||n[40]!==o||n[41]!==c?(ne=r&&p==="instance"?s.jsx(ub,{embedded:!0,open:o&&p==="instance",onOpenChange:cw,onHostSwitched:()=>c(!1)}):null,n[38]=p,n[39]=r,n[40]=o,n[41]=c,n[42]=ne):ne=n[42];let me;n[43]!==p||n[44]!==o?(me=p==="mcp"?s.jsx(qh,{active:o&&p==="mcp"}):null,n[43]=p,n[44]=o,n[45]=me):me=n[45];let pe;n[46]!==p||n[47]!==N||n[48]!==h||n[49]!==j||n[50]!==k||n[51]!==v||n[52]!==C||n[53]!==y||n[54]!==g||n[55]!==x||n[56]!==w||n[57]!==M||n[58]!==I?(pe=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:M("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Xh(x)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(Er,{items:g,activeId:y,onSelect:W=>{h(W)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:ye("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:j,disabled:v||C,"aria-label":M("header.services.refreshRateLimitsAria"),children:s.jsx(A,{name:"refresh",className:ye("h-4 w-4",C&&"animate-spin")})})]})]}),k?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:M("header.services.noRateLimits")})}),s.jsx("div",{className:"py-2",children:w.map((W,de)=>{const ge=N[W.providerId]??[];return s.jsxs(l.Fragment,{children:[de>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(yr,{providerId:W.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:W.providerName})]}),W.entries.length===0&&(!W.modelFamilies||W.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:W.error??M("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[W.entries.map(ve=>{const[te,he]=ve,ce=y==="remaining"?he.remainingPercent:he.usedPercent,xe=ho(he.usedPercent,he.resetAt,he.windowSeconds,te),se=xe?.dailyAllocationPercent!=null?y==="remaining"?100-Zr(xe.elapsedRatio):Zr(xe.elapsedRatio):null,ue=fo(he.valueLabel,ce),Y=lu(he.resetAt,he.resetAfterFormatted??he.resetAtFormatted);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:cu(te)}),Y?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Y}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:ue==="-"?"":ue})]}),s.jsx(xo,{percent:ce,tonePercent:he.usedPercent,className:"h-1.5",expectedMarkerPercent:se}),xe?s.jsx(bo,{paceInfo:xe,compact:!0}):null]},`${W.providerId}-${te}`)}),W.modelFamilies&&W.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:W.modelFamilies.map(ve=>{const te=ve.familyId??"other",he=ge.includes(te);return s.jsxs(vr,{open:he,onOpenChange:()=>I(W.providerId,te),children:[s.jsxs(Mr,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:ve.familyLabel}),he?s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(wr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:ve.models.map(ce=>{const[xe,se]=ce,ue=y==="remaining"?se.remainingPercent:se.usedPercent,Y=ho(se.usedPercent,se.resetAt,se.windowSeconds),Se=Y?.dailyAllocationPercent!=null?y==="remaining"?100-Zr(Y.elapsedRatio):Zr(Y.elapsedRatio):null,fe=fo(se.valueLabel,ue);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:El(xe)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:fe==="-"?"":fe})]}),s.jsx(xo,{percent:ue,tonePercent:se.usedPercent,className:"h-1.5",expectedMarkerPercent:Se}),Y?s.jsx(bo,{paceInfo:Y,compact:!0}):null]},`${W.providerId}-${xe}`)})})})]},te)})}):null]})]},W.providerId)})})]}):null,n[46]=p,n[47]=N,n[48]=h,n[49]=j,n[50]=k,n[51]=v,n[52]=C,n[53]=y,n[54]=g,n[55]=x,n[56]=w,n[57]=M,n[58]=I,n[59]=pe):pe=n[59];let G;n[60]!==D||n[61]!==S||n[62]!==P||n[63]!==M?(G=P?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}),s.jsx("div",{className:"px-2 pb-2",children:s.jsx(_t,{disabled:D,onSelect:()=>{S()},children:M("header.services.shutdownDev")})})]}):null,n[60]=D,n[61]=S,n[62]=P,n[63]=M,n[64]=G):G=n[64];let K;n[65]!==ie||n[66]!==ne||n[67]!==me||n[68]!==pe||n[69]!==G?(K=s.jsxs(Ps,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[ie,ne,me,pe,G]}),n[65]=ie,n[66]=ne,n[67]=me,n[68]=pe,n[69]=G,n[70]=K):K=n[70];let Q;return n[71]!==o||n[72]!==E||n[73]!==J||n[74]!==K?(Q=s.jsxs(As,{open:o,onOpenChange:E,children:[J,K]}),n[71]=o,n[72]=E,n[73]=J,n[74]=K,n[75]=Q):Q=n[75],Q}),ow=(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??""),lw=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},Xh=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},pr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Lo=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,km=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r})=>{const{t:a}=ft(),i=Fe(Ue=>Ue.setSessionSwitcherOpen),o=Fe(Ue=>Ue.toggleSidebar),c=Fe(Ue=>Ue.toggleBottomTerminal),d=Fe(Ue=>Ue.toggleRightSidebar),p=Fe(Ue=>Ue.openContextOverview),m=Fe(Ue=>Ue.openContextPlan),u=Fe(Ue=>Ue.openContextBrowser),f=Fe(Ue=>Ue.closeContextPanel),b=Fe(Ue=>Ue.contextPanelByDirectory),x=Fe(Ue=>Ue.activeMainTab),y=Fe(Ue=>Ue.setActiveMainTab),g=Fe(Ue=>Ue.shortcutOverrides),h=wt(Ue=>Ue.getCurrentModel),j=_n(),[v,C]=l.useState(!1),k=$t(Ue=>Ue.getContextUsage),w=$t(Ue=>!!Ue.newSessionDraft?.open),N=$t(Ue=>Ue.currentSessionId),I=mb(N??""),T=uh(N??null),P=xa(Ue=>Ue.activeSessions),D=Gd(),S=Cs(Ue=>Ue.activeProjectId?Ue.projects.find(Pt=>Pt.id===Ue.activeProjectId)??null:null),M=l.useMemo(()=>{if(!S)return null;const Ue=S.label?.trim();if(Ue)return Ue;const Pt=S.path.split(/[\\/]/).filter(Boolean);return Pt[Pt.length-1]??null},[S]),E=Rs(Ue=>Ue.results),R=Rs(Ue=>Ue.fetchAllQuotas),V=Rs(Ue=>Ue.isLoading),B=Rs(Ue=>Ue.lastUpdated),$=Rs(Ue=>Ue.displayMode),O=Rs(Ue=>Ue.dropdownProviderIds),_=Rs(Ue=>Ue.loadSettings),q=Rs(Ue=>Ue.setDisplayMode),{isMobile:L}=ln(),J=Hn(Ue=>Ue.status),Z=Hn(Ue=>Ue.setStatus),ie=l.useRef(null),[ne,me]=l.useState(()=>typeof window>"u"?!1:jn()),pe=l.useMemo(()=>qd(),[]),G=mh(),[K,Q]=l.useState(!1),W=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),de=l.useMemo(()=>{if(typeof window>"u")return null;const Ue=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Ue=="number"&&Number.isFinite(Ue)&&Ue>0)return Ue;if(typeof navigator>"u")return null;const Pt=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Pt)return null;const Ht=Number.parseInt(Pt[1],10),ns=Number.parseInt(Pt[2],10);return Number.isNaN(Ht)?null:Ht===10?ns:Ht},[]);_e.useEffect(()=>{typeof window>"u"||me(jn())},[]);const ge=h(),ve=ge&&typeof ge.limit=="object"&&ge.limit!==null?ge.limit:null,te=ve&&typeof ve.context=="number"?ve.context:0,he=ve&&typeof ve.output=="number"?ve.output:0,ce=k(te,he),[xe,se]=l.useState(null),ue=!N||I;_e.useEffect(()=>{if(!N){se(Ue=>Ue===null?Ue:null);return}if(ce&&ce.totalTokens>0){se(Ue=>ow(Ue,ce)?Ue:ce);return}ue&&se(Ue=>Ue===null?Ue:null)},[ce,N,ue]);const Y=Fe(Ue=>Ue.isSessionSwitcherOpen),Se=J?.connected?J.user?.avatarUrl??null:null,fe=J?.connected?J.user?.login??null:null,Ce=J?.accounts??[],[Ie,ke]=l.useState(!1),[X,ae]=l.useState(!1),[je,le]=l.useState(!1),[Ne,Me]=l.useState(!1),[Ve,we]=l.useState("Local"),ee=l.useMemo(()=>lw(Ve),[Ve]),[F,U]=l.useState(ne?"instance":"usage"),[oe,Te]=l.useState("usage");_e.useEffect(()=>{!ne&&F==="instance"&&U("usage")},[F,ne]);const Oe=l.useMemo(()=>fn(),[]),Pe=!Oe&&x==="chat"&&!!xe&&xe.totalTokens>0,z=xe&&xe.contextLimit>0?Math.min(999,xe.totalTokens/xe.contextLimit*100):0,De=l.useCallback(async()=>{if(!(typeof window>"u"||!ne))try{const Ue=await pb(),Pt=window.location.href,Ht=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin;if(Bu(Pt,Ht)){we("Local");return}const ns=Ue.hosts.find(qs=>Bu(Pt,qs.url));if(ns?.label?.trim()){we(fb(ns.label.trim()));return}we("Instance")}catch{we("Local")}},[ne]);_e.useEffect(()=>{De()},[De]),Hh();const Qe=Rs(Ue=>Ue.selectedModels),et=Rs(Ue=>Ue.expandedFamilies),Ze=Rs(Ue=>Ue.toggleFamilyExpanded),We=l.useMemo(()=>{const Ue=[];for(const Pt of Kr){if(!O.includes(Pt.id))continue;const Ht=E.find(sn=>sn.providerId===Pt.id),ns=Ht?.usage?.windows??{},qs=Ht?.usage?.models,Gs=Object.entries(ns),Ls={providerId:Pt.id,providerName:Pt.name,entries:Gs,error:Ht&&!Ht.ok&&Ht.configured?Ht.error:void 0};if(qs&&Object.keys(qs).length>0){const sn=Qe[Pt.id]??[],nn=sn.length>0,qn=d1(qs,Pt.id),Jn=Wh(Pt.id),aa=Kh(Jn);Ls.modelFamilies=[];for(const cn of aa){const hn=qn.get(cn.id)??[];if(hn.length===0)continue;const Sn=nn?hn.filter(dr=>sn.includes(dr)):hn;if(Sn.length===0)continue;const cr=[];for(const dr of Sn){const an=qs[dr];if(an?.windows){const Fr=Object.entries(an.windows);Fr.length>0&&cr.push([dr,Fr[0][1]])}}cr.length>0&&Ls.modelFamilies.push({familyId:cn.id,familyLabel:cn.label,models:cr})}const Ur=qn.get(null)??[],Nn=nn?Ur.filter(cn=>sn.includes(cn)):Ur;if(Nn.length>0){const cn=[];for(const hn of Nn){const Sn=qs[hn];if(Sn?.windows){const cr=Object.entries(Sn.windows);cr.length>0&&cn.push([hn,cr[0][1]])}}cn.length>0&&Ls.modelFamilies.push({familyId:null,familyLabel:a("header.services.modelFamily.other"),models:cn})}}(Gs.length>0||Ls.modelFamilies&&Ls.modelFamilies.length>0||Ls.error)&&Ue.push(Ls)}return Ue},[O,E,Qe,a]),it=We.length>0;l.useEffect(()=>{_()},[_]);const qe=l.useCallback(async Ue=>{q(Ue);try{await ks({usageDisplayMode:Ue})}catch(Pt){console.warn("Failed to update usage display mode:",Pt)}},[q]),st=l.useCallback(()=>{if(Ne)return;Me(!0);const Ue=new Promise(Pt=>setTimeout(Pt,500));Promise.all([R(),Ue]).finally(()=>{Me(!1)})},[R,Ne]),Je=l.useMemo(()=>N?D.find(Ue=>Ue.id===N)??P.find(Ue=>Ue.id===N)??T??hb().find(Ue=>Ue.id===N)??null:null,[N,T,P,D]),Be=l.useRef(null),[nt,Ge]=l.useState(0);l.useEffect(()=>{if(!N){Be.current&&(Be.current=null,Ge(ns=>ns+1));return}if(Je){Be.current={sessionId:N,session:Je,expiresAt:Date.now()+2e3};return}const Ue=Be.current;if(!Ue||Ue.sessionId!==N)return;const Pt=Ue.expiresAt-Date.now();if(Pt<=0){Be.current=null,Ge(ns=>ns+1);return}const Ht=window.setTimeout(()=>{Be.current?.sessionId===N&&(Be.current=null),Ge(ns=>ns+1)},Pt);return()=>{window.clearTimeout(Ht)}},[N,Je]);const at=(()=>{if(Je)return Je;if(!N)return null;const Ue=Be.current;return Ue&&Ue.sessionId===N&&Ue.expiresAt>Date.now()?Ue.session:null})(),Ae=$t(Ue=>N?Ue.worktreeMetadata.get(N)?.path??"":""),Le=$t(Ue=>N?Ue.worktreeMetadata.get(N)?.branch?.trim()??null:null),ze=ph(Ue=>N?Ue.getAttachment(N):void 0),Ke=l.useMemo(()=>ze?gb(ze):null,[ze]),lt=l.useMemo(()=>ze?ze.legacy?"legacy":ze.degraded?"degraded":ze.worktreeStatus==="missing"?"missing":ze.worktreeStatus==="invalid"?"invalid":ze.attentionReason?"attention":null:null,[ze]),xt=l.useMemo(()=>pr(Ae||""),[Ae]),dt=l.useMemo(()=>{const Ue=typeof at?.directory=="string"?at.directory:"";return pr(Ue||"")},[at?.directory]),ut=$t(Ue=>Ue.newSessionDraft?.open?pr(Ue.newSessionDraft.bootstrapPendingDirectory??Ue.newSessionDraft.directoryOverride??""):""),Nt=l.useMemo(()=>xt||dt||ut,[ut,dt,xt]),ts=$t(Ue=>{const Pt=pr(xt||dt||"");if(!Pt)return null;for(const Ht of Ue.availableWorktreesByProject.values()){const qs=Ht.find(Gs=>pr(Gs.path)===Pt)?.branch?.trim();if(qs)return qs}return null}),Xt=xb(Nt||null)||Le||ts,ht=l.useMemo(()=>{if(!N)return M??"OpenChamber";const Ue=at?.title?.trim();return Ue&&Ue.length>0?Ue:"Untitled Session"},[M,at?.title,N]),Bt=l.useMemo(()=>fh(at?.summary),[at?.summary]),Zt=l.useMemo(()=>Bt||{additions:0,deletions:0},[Bt]),gs=Zt.additions>0||Zt.deletions>0,rs=l.useMemo(()=>pr(Nt||S?.path||""),[S?.path,Nt]),ps=l.useMemo(()=>S?{id:S.id,path:S.path}:null,[S]),Ut=l.useRef(null);l.useEffect(()=>{!ps||!rs||(Ut.current={projectRef:ps,directory:rs})},[rs,ps]);const Ye=l.useMemo(()=>ps&&rs?{projectRef:ps,directory:rs}:Ut.current,[rs,ps]),Tt=Jd(Ue=>Ue.planModeEnabled),Kt=$t(Ue=>Ue.isSessionPlanAvailable),St=Tt&&N?Kt(N):!1,es=St,ss=l.useRef("");l.useEffect(()=>{if(!Tt){Fe.getState().activeMainTab==="plan"&&Fe.getState().setActiveMainTab("chat");return}if(!N)return;const Ue=`${N||"none"}:${dt||"none"}:${at?.time?.created||0}:${at?.slug||"none"}`;ss.current!==Ue&&(ss.current=Ue),!St&&Fe.getState().activeMainTab==="plan"&&Fe.getState().setActiveMainTab("chat")},[Tt,St,at?.slug,at?.time?.created,N,dt]);const Ms=l.useCallback(async Ue=>{if(!(!Ue||Ie)){ke(!0);try{const Pt=j.github?await j.github.authActivate(Ue):await(async()=>{const Ht=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:Ue})}),ns=await Ht.json().catch(()=>null);if(!Ht.ok||!ns)throw new Error(ns?.error||Ht.statusText);return ns})();Z(Pt)}catch(Pt){console.error("Failed to switch GitHub account:",Pt)}finally{ke(!1)}}},[Ie,j.github,Z]),xs=l.useCallback(()=>{if(typeof document>"u")return;const Ue=document.activeElement;if(!Ue)return;const Pt=Ue.tagName;(Pt==="INPUT"||Pt==="TEXTAREA"||Pt==="SELECT"||Ue.isContentEditable)&&Ue.blur()},[]),Bs=l.useCallback(()=>{if(L){xs(),i(!Y);return}o()},[xs,L,Y,i,o]),ws=l.useCallback(()=>{Pl("desktop_open_draft_mini_chat_window",{directory:pr(Nt||S?.path||""),projectId:S?.id??null}).catch(Ue=>{console.warn("[header] failed to open draft mini chat window",Ue)})},[S?.id,S?.path,Nt]),xn=l.useCallback(()=>{if(w){ws();return}N&&Pl("desktop_open_session_mini_chat_window",{sessionId:N,directory:pr(Nt||S?.path||"")}).catch(Ue=>{console.warn("[header] failed to open session mini chat window",Ue)})},[S?.path,N,ws,w,Nt]),Qs=l.useCallback(()=>{const Ue=pr(Nt||"");if(!Ue)return;const Pt=b[Ue];if(Lo(Pt)==="context"){f(Ue);return}p(Ue)},[f,b,p,Nt]),Wt=l.useMemo(()=>{const Ue=pr(Nt||"");if(!Ue)return!1;const Pt=b[Ue];return Lo(Pt)==="context"},[b,Nt]),qt=l.useCallback(()=>{const Ue=pr(Nt||"");if(!Ue)return;const Pt=b[Ue];if(Lo(Pt)==="plan"){f(Ue);return}m(Ue)},[f,b,m,Nt]),re=l.useCallback(()=>{const Ue=pr(Nt||"");Ue&&u(Ue)},[u,Nt]),vt=l.useMemo(()=>{const Ue=pr(Nt||"");if(!Ue)return!1;const Pt=b[Ue];return Lo(Pt)==="plan"},[b,Nt]),Ft=ac,ct=rw,ls=l.useMemo(()=>X?"services":n?"sessions":r?"git":x,[x,X,n,r]),cs=l.useCallback(()=>{ae(!1),n&&t&&t(),r&&e&&e(),!t&&Y&&i(!1)},[Y,n,t,e,r,i]),He=l.useCallback(()=>{n||ae(!1),t?.()},[n,t]),yt=l.useCallback(()=>{r||ae(!1),e?.()},[e,r]),Et=l.useMemo(()=>ne&&W&&!K||G?"pl-[5.5rem]":"pl-3",[ne,K,W,G]);_e.useEffect(()=>{if(!ne||!W){Q(!1);return}let Ue=!1,Pt=null;const Ht=async()=>{try{const{getCurrentWindow:qs}=await Tr(async()=>{const{getCurrentWindow:sn}=await import("./vendor-.bun-Bum-iBXX.js").then(nn=>nn.bP);return{getCurrentWindow:sn}},__vite__mapDeps([0,1])),Ls=await qs().isFullscreen();Ue||Q(Ls)}catch{Ue||Q(!1)}},ns=async()=>{try{const{getCurrentWindow:qs}=await Tr(async()=>{const{getCurrentWindow:Ls}=await import("./vendor-.bun-Bum-iBXX.js").then(sn=>sn.bP);return{getCurrentWindow:Ls}},__vite__mapDeps([0,1]));Pt=await qs().onResized(()=>{Ht()})}catch{}};return Ht(),ns(),()=>{Ue=!0,Pt&&Pt()}},[ne,W]);const Rt=l.useMemo(()=>!ne||!W||de===null?"":de>=26?"h-12":de<=15?"h-14":"",[ne,W,de]),Yt=l.useMemo(()=>{if(!(ne||Oe))return{paddingLeft:G?"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))"}},[ne,G,Oe]),Ot=l.useCallback(()=>{if(typeof document>"u")return;const Ue=ie.current?.getBoundingClientRect().height;Ue&&document.documentElement.style.setProperty("--oc-header-height",`${Ue}px`)},[]);_e.useEffect(()=>{if(typeof window>"u")return;Ot();const Ue=ie.current;if(!Ue||typeof ResizeObserver>"u")return()=>{};let Pt=0;const Ht=()=>{Pt||(Pt=requestAnimationFrame(()=>{Pt=0,Ot()}))},ns=new ResizeObserver(Ht);return ns.observe(Ue),window.addEventListener("resize",Ht),window.addEventListener("orientationchange",Ht),()=>{Pt&&cancelAnimationFrame(Pt),ns.disconnect(),window.removeEventListener("resize",Ht),window.removeEventListener("orientationchange",Ht)}},[Ot]),_e.useEffect(()=>{Ot()},[Ot,L,Rt]);const Os=l.useCallback(async Ue=>{const Pt=Ue.target;Pt.closest(".app-region-no-drag")||Pt.closest("button, a, input, select, textarea")||Ue.button===0&&ne&&await bb()},[ne]),Ds=l.useMemo(()=>{if(L){const Ue=[{id:"chat",label:a("layout.mainTab.chat"),icon:"chat-4"}];return es&&Ue.push({id:"plan",label:a("layout.mainTab.plan"),icon:"file-text"}),Ue.push({id:"diff",label:a("layout.mainTab.diff"),icon:"diff"},{id:"files",label:a("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:a("layout.mainTab.terminal"),icon:"terminal-box"},{id:"context",label:a("layout.mainTab.context"),icon:"file-list-2"}),Ue}return[]},[L,es,a]),Ts=l.useCallback(Ue=>Yl(Xr(Ue,g)),[g]);_e.useEffect(()=>{!L&&(x==="git"||x==="terminal"||x==="diff"||x==="files"||x==="context")&&y("chat")},[x,L,y]);const Vs=l.useMemo(()=>{const Ue=[];return ne&&Ue.push({value:"instance",label:a("layout.services.instance"),icon:"server"}),Ue.push({value:"usage",label:a("layout.services.usage"),icon:"timer"},{value:"mcp",label:"MCP",icon:"plug-2"}),Ue},[ne,a]),js=l.useMemo(()=>Vs.map(Ue=>({id:Ue.value,label:Ue.label,icon:s.jsx(A,{name:Ue.icon,className:"h-3.5 w-3.5"})})),[Vs]),Bn=l.useMemo(()=>{if(typeof window>"u"||ne||Oe)return!1;const Ue=window.location.hostname;return Ue==="localhost"||Ue==="127.0.0.1"||Ue==="::1"},[ne,Oe]),bn=l.useCallback(async()=>{if(v)return;C(!0),le(!1);const Ue=[];let Pt=!1;try{try{for(const[,Ht]of dn.getState().sessions.entries())for(const ns of Ht.tabs)ns.previewUrl&&Ue.push(ns.previewUrl)}catch{}try{await nb({})}catch{}try{(await fetch("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:Ue})})).ok?Pt=!0:Pt=(await fetch("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{Pt||C(!1)}},[v,le]),mn=l.useMemo(()=>[{value:"usage",label:a("header.services.used")},{value:"remaining",label:a("header.services.remaining")}],[a]),lr=l.useMemo(()=>mn.map(Ue=>({id:Ue.value,label:Ue.label})),[mn]),Us=l.useMemo(()=>[{id:"usage",label:a("layout.services.usage"),icon:s.jsx(A,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(A,{name:"command",className:"h-3.5 w-3.5"})}],[a]);_e.useEffect(()=>{const Ue=Pt=>{if(Yd(Pt)&&!Pt.shiftKey&&!Pt.altKey){const Ht=parseInt(Pt.key,10);Ht>=1&&Ht<=Ds.length&&(Pt.preventDefault(),L&&(xs(),cs()),y(Ds[Ht-1].id))}};return window.addEventListener("keydown",Ue),()=>window.removeEventListener("keydown",Ue)},[xs,cs,L,y,Ds]),_e.useEffect(()=>{const Ue=Pt=>{const Ht=Xr("toggle_services_menu",g);if(il(Pt,Ht)){Pt.preventDefault(),je?le(!1):(le(!0),De(),F==="usage"&&E.length===0&&R());return}const ns=Xr("cycle_services_tab",g);if(il(Pt,ns)){Pt.preventDefault();const Gs=Vs.map(qn=>qn.value);if(Gs.length===0)return;const Ls=Gs.indexOf(F),sn=Ls===-1?0:(Ls+1)%Gs.length,nn=Gs[sn];U(nn),le(!0),De(),nn==="usage"&&E.length===0&&R();return}const qs=Xr("toggle_context_plan",g);il(Pt,qs)&&(Pt.preventDefault(),qt())};return window.addEventListener("keydown",Ue),()=>window.removeEventListener("keydown",Ue)},[g,je,F,Vs,E.length,R,De,qt]);const yn=Ue=>{const Pt=x===Ue.id,Ht=Ue.icon==="diff",ns=Ht?null:Ue.icon,qs=Ue.id==="chat",Gs=sn=>Ht?s.jsx(pm,{size:sn}):ns?s.jsx(A,{name:ns,className:`h-${sn/4} w-${sn/4}`}):null,Ls=s.jsxs("button",{type:"button",onClick:()=>y(Ue.id),className:ye("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",Pt?"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",qs&&!L&&"min-w-[100px] justify-center"),"aria-label":Ue.label,"aria-selected":Pt,role:"tab",children:[L?Gs(20):s.jsxs(s.Fragment,{children:[Gs(16),s.jsx("span",{className:"header-tab-label",children:Ue.label})]}),Ue.badge!==void 0&&Ue.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:Ue.badge})]});return s.jsx(l.Fragment,{children:Ls},Ue.id)},ir=s.jsxs(s.Fragment,{children:[es&&s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.actions.openPlanAria"),onClick:qt,className:ye(Ft,vt&&"bg-[var(--interactive-hover)]"),children:s.jsx(A,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(It,{children:s.jsx("p",{children:a("header.actions.planWithShortcut",{shortcut:Ts("toggle_context_plan")})})})]}),s.jsx(C1,{directory:rs,className:"mr-1"}),s.jsx(iw,{isDesktopApp:ne,currentInstanceLabel:Ve,compactCurrentInstanceLabel:ee,isDesktopServicesOpen:je,setIsDesktopServicesOpen:le,refreshCurrentInstanceLabel:De,desktopServicesTab:F,setDesktopServicesTab:U,quotaResultsLength:E.length,fetchAllQuotas:R,servicesTabItems:js,quotaLastUpdated:B,quotaDisplayMode:$,quotaDisplayTabItems:lr,handleDisplayModeChange:qe,handleUsageRefresh:st,isQuotaLoading:V,isUsageRefreshSpinning:Ne,hasRateLimits:it,rateLimitGroups:We,expandedFamilies:et,toggleFamilyExpanded:Ze,shortcutLabel:Ts,showDevShutdown:Bn,isDevShutdownInFlight:v,onDevShutdown:bn}),s.jsx($i,{title:a("header.actions.terminalPanelWithShortcut",{shortcut:Ts("toggle_terminal")}),ariaLabel:a("header.actions.toggleTerminalPanelAria"),onClick:c,Icon:"terminal-box"}),pe?s.jsx($i,{title:a("contextPanel.browser.open"),ariaLabel:a("contextPanel.browser.open"),onClick:re,Icon:"global"}):null,s.jsx($i,{title:a("header.actions.rightSidebarWithShortcut",{shortcut:Ts("toggle_right_sidebar")}),ariaLabel:a("header.actions.toggleRightSidebarAria"),onClick:d,Icon:"layout-right"}),s.jsx(aw,{isMobile:L,githubAuthStatus:J,githubAccounts:Ce,githubAvatarUrl:Se,githubLogin:fe,isSwitchingGitHubAccount:Ie,handleGitHubAccountSwitch:Ms})]}),Mn=pe&&(w||!!N),Rr=()=>s.jsxs("div",{onMouseDown:Os,className:ye("app-region-drag relative flex h-12 select-none items-center pr-3",Et,Rt),style:Yt,role:"tablist","aria-label":a("header.navigation.mainAria"),children:[s.jsx($i,{title:a("header.actions.openSessionsWithShortcut",{shortcut:Ts("toggle_sidebar")}),ariaLabel:a("header.actions.openSessionsAria"),onClick:Bs,className:`${Ft} shrink-0`,Icon:"layout-left"}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center pl-3",children:[Ye&&s.jsx(Sm,{projectRef:Ye.projectRef,directory:Ye.directory,className:"mr-2"}),s.jsx(yb,{children:s.jsxs("button",{type:"button","aria-label":a("sessions.switcher.openAria"),className:"app-region-no-drag mr-3 flex min-w-0 flex-col items-start rounded-md px-1 py-0.5 -my-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:w?a("sessions.switcher.draftTitle"):ht}),M||Xt||!w&&(gs||lt)?s.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[M?s.jsx("span",{className:"truncate",children:M}):null,Xt?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:Xt})]}):null,!w&&gs?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:["+",Zt.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Zt.deletions]})]}):null,!w&<?s.jsxs("span",{className:ye("inline-flex min-w-0 items-center gap-0.5",lt==="attention"||lt==="invalid"||lt==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(A,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Ke})]}):null]}):null]})}),Ds.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:Ds.map(Ue=>yn(Ue))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Pe&&xe?s.jsx(vb,{totalTokens:xe.totalTokens,percentage:z,colorPercentage:xe.percentage,contextLimit:xe.contextLimit,outputLimit:xe.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:Qs,pressed:Wt,className:Mn?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,s.jsx($i,{visible:Mn,title:a(w?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:a(w?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:xn,className:ye(Ft,Pe?"mr-3.5":"mr-1"),Icon:"picture-in-picture-2"}),ir]})]})]}),$s=()=>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:He,className:ye(ct,ls==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":a(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(A,{name:"layout-left",className:"h-5 w-5"})}):Y?s.jsx("button",{type:"button",onClick:()=>i(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":a("header.actions.backAria"),children:s.jsx(A,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:Bs,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":a("header.actions.openSessionsAria"),children:s.jsx(A,{name:"play-list-add",className:"h-5 w-5"})}),!t&&Y&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:a("header.sessions.title")})]}),(!Y||!!t)&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":a("header.navigation.mainAria"),children:Ds.map(Ue=>{const Pt=x===Ue.id,Ht=Ue.icon==="diff",ns=Ht?null:Ue.icon;return s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{L&&(xs(),cs()),y(Ue.id)},"aria-label":Ue.label,"aria-selected":Pt,role:"tab",className:ye(ct,"relative rounded-lg",ls===Ue.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[Ht?s.jsx(pm,{className:"h-5 w-5"}):ns?s.jsx(A,{name:ns,className:"h-5 w-5"}):null,Ue.badge!==void 0&&Ue.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:Ue.badge}),Ue.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":a("header.changes.availableAria")})]})}),s.jsx(It,{children:s.jsx("p",{children:Ue.label})})]},Ue.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[Ye&&s.jsx(Sm,{projectRef:Ye.projectRef,directory:Ye.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(As,{open:X,onOpenChange:Ue=>{Ue&&(n&&t&&t(),r&&e&&e()),ae(Ue),Ue&&E.length===0&&R()},children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.services.viewAria"),className:ye(ct,ls==="services"&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(A,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(It,{children:s.jsx("p",{children:a("header.services.title")})})]}),s.jsx(Ps,{align:"end",sideOffset:0,positionerClassName:"!fixed !bottom-0 !left-0 !right-0 !top-[var(--oc-header-height,56px)] !transform-none",className:"h-full w-screen max-h-none rounded-none border-0 p-0 pt-1 overflow-hidden",children:s.jsxs("div",{className:"flex h-full flex-col bg-[var(--surface-elevated)]",children:[s.jsx("div",{className:"sticky top-0 z-20 bg-[var(--surface-elevated)] px-2 py-px",children:s.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-0",children:[s.jsx("div",{className:"h-10 min-w-0 flex-1",children:s.jsx(Er,{items:Us,activeId:oe,onSelect:Ue=>{const Pt=Ue;Te(Pt),Pt==="usage"&&E.length===0&&R()},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:()=>ae(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":a("header.services.closeAria"),children:s.jsx(A,{name:"close",className:"h-5 w-5"})})]})}),oe==="mcp"&&s.jsx(qh,{active:X&&oe==="mcp"}),oe==="usage"&&s.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]",children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[s.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:a("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Xh(B)})]}),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:()=>qe("usage"),className:ye("typography-ui-label px-1 pb-0.5 transition-colors",$==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:a("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>qe("remaining"),className:ye("typography-ui-label px-1 pb-0.5 transition-colors",$==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:a("header.services.remaining")})]}),s.jsx("button",{type:"button",className:ye("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:st,disabled:V||Ne,"aria-label":a("header.services.refreshRateLimitsAria"),children:s.jsx(A,{name:"refresh",className:ye("h-4 w-4",Ne&&"animate-spin")})})]})]})}),!it&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:a("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:We.map((Ue,Pt)=>s.jsxs(l.Fragment,{children:[Pt>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(yr,{providerId:Ue.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Ue.providerName})]}),Ue.entries.length===0&&(!Ue.modelFamilies||Ue.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Ue.error??a("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Ue.entries.map(([Ht,ns])=>{const qs=$==="remaining"?ns.remainingPercent:ns.usedPercent,Gs=ho(ns.usedPercent,ns.resetAt,ns.windowSeconds,Ht),Ls=Gs?.dailyAllocationPercent!=null?$==="remaining"?100-Zr(Gs.elapsedRatio):Zr(Gs.elapsedRatio):null,sn=fo(ns.valueLabel,qs),nn=lu(ns.resetAt,ns.resetAfterFormatted??ns.resetAtFormatted);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:cu(Ht)}),nn?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:nn}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:sn==="-"?"":sn})]}),s.jsx(xo,{percent:qs,tonePercent:ns.usedPercent,className:"h-1.5",expectedMarkerPercent:Ls}),Gs?s.jsx(bo,{paceInfo:Gs,compact:!0}):null]},`${Ue.providerId}-${Ht}`)}),Ue.modelFamilies&&Ue.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:Ue.modelFamilies.map(Ht=>{const qs=(et[Ue.providerId]??[]).includes(Ht.familyId??"other");return s.jsxs(vr,{open:qs,onOpenChange:()=>Ze(Ue.providerId,Ht.familyId??"other"),children:[s.jsxs(Mr,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Ht.familyLabel}),qs?s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(wr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Ht.models.map(([Gs,Ls])=>{const sn=$==="remaining"?Ls.remainingPercent:Ls.usedPercent,nn=ho(Ls.usedPercent,Ls.resetAt,Ls.windowSeconds),qn=nn?.dailyAllocationPercent!=null?$==="remaining"?100-Zr(nn.elapsedRatio):Zr(nn.elapsedRatio):null,Jn=fo(Ls.valueLabel,sn);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:El(Gs)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Jn==="-"?"":Jn})]}),s.jsx(xo,{percent:sn,tonePercent:Ls.usedPercent,className:"h-1.5",expectedMarkerPercent:qn}),nn?s.jsx(bo,{paceInfo:nn,compact:!0}):null]},`${Ue.providerId}-${Gs}`)})})})]},Ht.familyId??"other")})})]})]},Ue.providerId))})]})]})})]}),e?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:yt,className:ye(ct,"relative",ls==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(A,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(It,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Ks=ye("header-safe-area relative z-10",L?"border-b border-border/50 bg-background":"bg-sidebar");return s.jsx("header",{ref:ie,className:Ks,style:{"--padding-scale":"1"},children:L?$s():Rr()})};function cw(){}const Cm=180,Im=640,dw=110,uw=t=>{const e=ot.c(44),{isOpen:n,isMobile:r,children:a}=t,{t:i}=ft(),o=Fe(mw),c=Fe(pw),d=Fe(fw),p=Fe(hw),[m,u]=l.useState(null),[f,b]=l.useState(!1),x=l.useRef(null),y=l.useRef(0),g=l.useRef(o||300),h=Math.min(Im,Math.max(Cm,o||300));let j,v;e[0]!==n?(j=()=>{n||(u(null),b(!1))},v=[n],e[0]=n,e[1]=j,e[2]=v):(j=e[1],v=e[2]),l.useEffect(j,v);let C,k;e[3]!==c||e[4]!==r||e[5]!==n?(C=()=>{if(r||!n||!c)return;const Z=()=>{const me=x.current?.parentElement?.getBoundingClientRect().height;if(!me||me<=0)return;const pe=Math.max(0,Math.round(me));u(G=>G===pe?G:pe)};Z();const ie=x.current?.parentElement;if(!ie)return;const ne=new ResizeObserver(Z);return ne.observe(ie),()=>{ne.disconnect()}},k=[c,r,n],e[3]=c,e[4]=r,e[5]=n,e[6]=C,e[7]=k):(C=e[6],k=e[7]),l.useEffect(C,k);let w,N;if(e[8]!==c||e[9]!==r||e[10]!==f||e[11]!==d||e[12]!==p?(w=()=>{if(r||!f||c)return;const Z=ne=>{const me=y.current-ne.clientY,pe=Math.min(Im,Math.max(Cm,g.current+me));d(pe)},ie=()=>{b(!1),Fe.getState().bottomTerminalHeight<=dw&&p(!1)};return window.addEventListener("pointermove",Z),window.addEventListener("pointerup",ie,{once:!0}),()=>{window.removeEventListener("pointermove",Z),window.removeEventListener("pointerup",ie)}},N=[c,r,f,d,p],e[8]=c,e[9]=r,e[10]=f,e[11]=d,e[12]=p,e[13]=w,e[14]=N):(w=e[13],N=e[14]),l.useEffect(w,N),r)return null;const I=n?c?Math.max(0,m??h):h:0,T=n&&c;let P;e[15]!==I||e[16]!==c||e[17]!==n?(P=Z=>{!n||c||(b(!0),y.current=Z.clientY,g.current=I,Z.preventDefault())},e[15]=I,e[16]=c,e[17]=n,e[18]=P):P=e[18];const D=P,S=T?"absolute inset-x-0 bottom-0 z-40":"relative",M=f?"transition-none":"transition-[height] duration-300 ease-in-out",E=(!n||T)&&"border-t-0";let R;e[19]!==E||e[20]!==S||e[21]!==M?(R=ye("flex overflow-hidden border-t border-border bg-sidebar",S,M,E),e[19]=E,e[20]=S,e[21]=M,e[22]=R):R=e[22];let V;e[23]!==I||e[24]!==T?(V=T?{top:0}:{height:`${I}px`,minHeight:`${I}px`,maxHeight:`${I}px`},e[23]=I,e[24]=T,e[25]=V):V=e[25];const B=!n||!c&&I===0;let $;e[26]!==D||e[27]!==c||e[28]!==n||e[29]!==f||e[30]!==i?($=n&&!c&&s.jsx("div",{className:ye("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:D,role:"separator","aria-orientation":"horizontal","aria-label":i("terminalView.bottomDock.resizeAria")}),e[26]=D,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 _;e[32]!==O?(_=ye("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]=_):_=e[33];const q=!n;let L;e[34]!==a||e[35]!==_||e[36]!==q?(L=s.jsx("div",{className:_,"aria-hidden":q,children:a}),e[34]=a,e[35]=_,e[36]=q,e[37]=L):L=e[37];let J;return e[38]!==R||e[39]!==V||e[40]!==B||e[41]!==$||e[42]!==L?(J=s.jsxs("section",{ref:x,className:R,style:V,"aria-hidden":B,children:[$,L]}),e[38]=R,e[39]=V,e[40]=B,e[41]=$,e[42]=L,e[43]=J):J=e[43],J};function mw(t){return t.bottomTerminalHeight}function pw(t){return t.isBottomTerminalExpanded}function fw(t){return t.setBottomTerminalHeight}function hw(t){return t.setBottomTerminalOpen}const vd=280,Pm=280,Am=500,gw=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:a}=ft(),i=Fe(w=>w.sidebarWidth),o=Fe(w=>w.setSidebarWidth),[c,d]=l.useState(!1),p=l.useRef(0),m=l.useRef(i||vd),u=l.useRef(null),f=l.useRef(null),b=l.useRef(null),x=l.useCallback(w=>Math.min(Am,Math.max(Pm,w)),[]),y=l.useCallback(w=>{const N=b.current;N&&(N.style.width=`${w}px`,N.style.minWidth=`${w}px`,N.style.maxWidth=`${w}px`,N.style.setProperty("--oc-left-sidebar-width",`${w}px`))},[]);if(l.useEffect(()=>{e&&c&&d(!1)},[e,c]),l.useEffect(()=>{c||(u.current=null,f.current=null)},[c]),e)return null;const g=Math.min(Am,Math.max(Pm,i||vd)),h=t?g:0,j=w=>{if(t){try{w.currentTarget.setPointerCapture(w.pointerId)}catch{}f.current=w.pointerId,d(!0),p.current=w.clientX,m.current=h,u.current=h,y(h),w.preventDefault()}},v=w=>{if(e||!c||f.current!==w.pointerId)return;const N=w.clientX-p.current,I=x(m.current+N);u.current!==I&&(u.current=I,y(I))},C=w=>{if(f.current!==w.pointerId||e)return;try{w.currentTarget.releasePointerCapture(w.pointerId)}catch{}const N=x(u.current??h);f.current=null,u.current=null,d(!1),o(N)},k=c?u.current??h:h;return s.jsxs("aside",{ref:b,className:ye("relative flex h-full overflow-hidden border-r border-border/40 will-change-[width] motion-reduce:transition-none","bg-sidebar",!t&&"border-r-0",r),style:{width:`${k}px`,minWidth:`${k}px`,maxWidth:`${k}px`,"--oc-left-sidebar-width":`${c?k:g}px`,overflowX:"clip",transitionProperty:c?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||h===0,children:[t&&s.jsx("div",{className:ye("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",c&&"bg-[var(--interactive-border)]"),onPointerDown:j,onPointerMove:v,onPointerUp:C,onPointerCancel:C,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.leftPanelAria")}),s.jsx("div",{className:ye("relative z-10 flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",c&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(en,{children:n})})})]})},wd=420,Dm=360,Tm=860,xw=({isOpen:t,children:e,className:n})=>{const{t:r}=ft(),a=Fe(k=>k.rightSidebarWidth),i=Fe(k=>k.setRightSidebarWidth),[o,c]=l.useState(!1),d=l.useRef(0),p=l.useRef(a||wd),m=l.useRef(null),u=l.useRef(null),f=l.useRef(null),b=l.useCallback(k=>Math.min(Tm,Math.max(Dm,k)),[]),x=l.useCallback(k=>{const w=f.current;w&&(w.style.width=`${k}px`,w.style.minWidth=`${k}px`,w.style.maxWidth=`${k}px`,w.style.setProperty("--oc-right-sidebar-width",`${k}px`))},[]),y=Math.min(Tm,Math.max(Dm,a||wd)),g=t?y:0,h=k=>{if(t){try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}u.current=k.pointerId,c(!0),d.current=k.clientX,p.current=g,m.current=g,x(g),k.preventDefault()}},j=k=>{if(!o||u.current!==k.pointerId)return;const w=d.current-k.clientX,N=b(p.current+w);m.current!==N&&(m.current=N,x(N))},v=k=>{if(u.current!==k.pointerId)return;try{k.currentTarget.releasePointerCapture(k.pointerId)}catch{}const w=b(m.current??g);u.current=null,m.current=null,c(!1),i(w)};l.useEffect(()=>{o||(m.current=null,u.current=null)},[o]);const C=o?m.current??g:g;return s.jsxs("aside",{ref:f,className:ye("relative flex h-full overflow-hidden border-l border-border/40 will-change-[width] motion-reduce:transition-none","bg-sidebar",!t&&"border-l-0",n),style:{width:`${C}px`,minWidth:`${C}px`,maxWidth:`${C}px`,"--oc-right-sidebar-width":`${o?C:y}px`,overflowX:"clip",transitionProperty:o?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||g===0,children:[t&&s.jsx("div",{className:ye("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",o&&"bg-[var(--interactive-border)]"),onPointerDown:h,onPointerMove:j,onPointerUp:v,onPointerCancel:v,role:"separator","aria-orientation":"vertical","aria-label":r("sidebar.resize.rightPanelAria")}),s.jsx("div",{className:ye("relative z-10 flex h-full min-h-0 shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",o&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-right-sidebar-width)"},"aria-hidden":!t,children:t?e:null})]})},Io=t=>{const e=ot.c(128),{providerId:n,modelId:r,onChange:a,className:i,allowedProviderIds:o,placeholder:c}=t,{t:d}=ft(),{isReady:p,isUnavailable:m}=hh(),u=wt(bw),f=wt(yw),b=Fe(vw),x=Fe(ww),y=Fe(jw),g=Fe(Nw),h=Fe(Sw),{favoriteModelsList:j,recentModelsList:v}=gh(),{isMobile:C}=ln(),k=b||C,[w,N]=l.useState(!1),[I,T]=l.useState(!1),[P,D]=l.useState("");let S;e[0]===Symbol.for("react.memo_cache_sentinel")?(S=()=>{N(!1),T(!1),D("")},e[0]=S):S=e[0];const M=S;let E;e[1]!==h||e[2]!==a?(E=Ne=>{a(Ne.providerID,Ne.modelID),h(Ne.providerID,Ne.modelID),M()},e[1]=h,e[2]=a,e[3]=E):E=e[3];const R=E;let V;e[4]!==a?(V=()=>{a("",""),M()},e[4]=a,e[5]=V):V=e[5];const B=V;let $;e[6]!==d?($=d("settings.agents.modelSelector.searchPlaceholder"),e[6]=d,e[7]=$):$=e[7];let O;e[8]!==d?(O=d("settings.agents.modelSelector.state.noModelsFound"),e[8]=d,e[9]=O):O=e[9];let _;e[10]!==d?(_=d("settings.agents.modelSelector.section.favorites"),e[10]=d,e[11]=_):_=e[11];let q;e[12]!==d?(q=d("settings.agents.modelSelector.section.recent"),e[12]=d,e[13]=q):q=e[13];let L;e[14]!==d?(L=d("settings.agents.modelSelector.keyboardHints"),e[14]=d,e[15]=L):L=e[15];let J;e[16]!==c||e[17]!==d?(J=c||d("settings.agents.modelSelector.notSelected"),e[16]=c,e[17]=d,e[18]=J):J=e[18];let Z;e[19]!==d?(Z=d("settings.agents.modelSelector.actions.favorite"),e[19]=d,e[20]=Z):Z=e[20];let ie;e[21]!==d?(ie=d("settings.agents.modelSelector.actions.unfavorite"),e[21]=d,e[22]=ie):ie=e[22];let ne;e[23]!==d?(ne=d("chat.modelControls.capabilities"),e[23]=d,e[24]=ne):ne=e[24];let me;e[25]!==d?(me=d("chat.modelControls.capability.toolCalling"),e[25]=d,e[26]=me):me=e[26];let pe;e[27]!==d?(pe=d("chat.modelControls.capability.reasoning"),e[27]=d,e[28]=pe):pe=e[28];let G;e[29]!==d?(G=d("chat.modelControls.input"),e[29]=d,e[30]=G):G=e[30];let K;e[31]!==d?(K=d("chat.modelControls.output"),e[31]=d,e[32]=K):K=e[32];let Q;e[33]!==d?(Q=d("chat.modelControls.costPerMillion"),e[33]=d,e[34]=Q):Q=e[34];let W;e[35]!==Z||e[36]!==ie||e[37]!==ne||e[38]!==me||e[39]!==pe||e[40]!==G||e[41]!==K||e[42]!==Q||e[43]!==$||e[44]!==O||e[45]!==_||e[46]!==q||e[47]!==L||e[48]!==J?(W={searchPlaceholder:$,noResults:O,favorites:_,recent:q,keyboardHint:L,notSelected:J,favorite:Z,unfavorite:ie,capabilities:ne,capabilityToolCalling:me,capabilityReasoning:pe,input:G,output:K,costPerMillion:Q},e[35]=Z,e[36]=ie,e[37]=ne,e[38]=me,e[39]=pe,e[40]=G,e[41]=K,e[42]=Q,e[43]=$,e[44]=O,e[45]=_,e[46]=q,e[47]=L,e[48]=J,e[49]=W):W=e[49];const de=W;let ge;e[50]!==r||e[51]!==n?(ge=n&&r?{providerID:n,modelID:r}:null,e[50]=r,e[51]=n,e[52]=ge):ge=e[52];const ve=ge;let te;e[53]!==r||e[54]!==c||e[55]!==n||e[56]!==d?(te=n&&r?`${n}/${r}`:c||d("settings.agents.modelSelector.notSelected"),e[53]=r,e[54]=c,e[55]=n,e[56]=d,e[57]=te):te=e[57];const he=te,ce=k?w:I;let xe;e[58]!==g?(xe=Ne=>g(Ne.providerID,Ne.modelID),e[58]=g,e[59]=xe):xe=e[59];let se;e[60]!==y?(se=Ne=>y(Ne.providerID,Ne.modelID),e[60]=y,e[61]=se):se=e[61];let ue;e[62]!==o||e[63]!==j||e[64]!==R||e[65]!==B||e[66]!==x||e[67]!==de||e[68]!==f||e[69]!==u||e[70]!==v||e[71]!==P||e[72]!==ve||e[73]!==ce||e[74]!==xe||e[75]!==se?(ue=s.jsx(xh,{providers:u,favoriteModels:j,recentModels:v,modelsMetadata:f,searchQuery:P,onSearchQueryChange:D,onSelect:R,labels:de,selectedModel:ve,hiddenModels:x,allowedProviderIds:o,includeNotSelected:!0,onSelectNone:B,onEscape:M,tooltipsEnabled:ce,isFavorite:xe,onToggleFavorite:se}),e[62]=o,e[63]=j,e[64]=R,e[65]=B,e[66]=x,e[67]=de,e[68]=f,e[69]=u,e[70]=v,e[71]=P,e[72]=ve,e[73]=ce,e[74]=xe,e[75]=se,e[76]=ue):ue=e[76];const Y=ue;if(k){let Ne;e[77]!==p?(Ne=p?()=>N(!0):void 0,e[77]=p,e[78]=Ne):Ne=e[78];const Me=!p,Ve=!p&&"opacity-60 cursor-not-allowed";let we;e[79]!==i||e[80]!==Ve?(we=ye("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",Ve,i),e[79]=i,e[80]=Ve,e[81]=we):we=e[81];let ee;e[82]!==p||e[83]!==m||e[84]!==n||e[85]!==d?(ee=p?n?s.jsx(yr,{providerId:n,className:"h-3.5 w-3.5 flex-shrink-0"}):s.jsx(A,{name:"pencil-ai",className:"h-3 w-3 text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:d(m?"common.unavailable":"common.loading")})]}),e[82]=p,e[83]=m,e[84]=n,e[85]=d,e[86]=ee):ee=e[86];let F;e[87]!==p||e[88]!==he?(F=p?s.jsx("span",{className:"typography-meta font-medium text-foreground truncate",children:he}):null,e[87]=p,e[88]=he,e[89]=F):F=e[89];let U;e[90]!==ee||e[91]!==F?(U=s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[ee,F]}),e[90]=ee,e[91]=F,e[92]=U):U=e[92];let oe;e[93]===Symbol.for("react.memo_cache_sentinel")?(oe=s.jsx(A,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),e[93]=oe):oe=e[93];let Te;e[94]!==Ne||e[95]!==Me||e[96]!==we||e[97]!==U?(Te=s.jsxs("button",{type:"button",onClick:Ne,disabled:Me,className:we,children:[U,oe]}),e[94]=Ne,e[95]=Me,e[96]=we,e[97]=U,e[98]=Te):Te=e[98];let Oe;e[99]!==d?(Oe=d("settings.agents.modelSelector.title"),e[99]=d,e[100]=Oe):Oe=e[100];let Pe;e[101]!==w||e[102]!==Y||e[103]!==Oe?(Pe=s.jsx(zr,{open:w,onClose:M,title:Oe,children:Y}),e[101]=w,e[102]=Y,e[103]=Oe,e[104]=Pe):Pe=e[104];let z;return e[105]!==Te||e[106]!==Pe?(z=s.jsxs(s.Fragment,{children:[Te,Pe]}),e[105]=Te,e[106]=Pe,e[107]=z):z=e[107],z}const Se=p&&I,fe=p?T:void 0,Ce=!p&&"opacity-60 cursor-not-allowed";let Ie;e[108]!==i||e[109]!==Ce?(Ie=ye("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",Ce,i),e[108]=i,e[109]=Ce,e[110]=Ie):Ie=e[110];let ke;e[111]!==p||e[112]!==m||e[113]!==n||e[114]!==d||e[115]!==he?(ke=p?s.jsxs(s.Fragment,{children:[n?s.jsx(yr,{providerId:n,className:"h-3.5 w-3.5 flex-shrink-0"}):s.jsx(A,{name:"pencil-ai",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-foreground",children:he})]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-muted-foreground",children:d(m?"common.unavailable":"common.loading")})]}),e[111]=p,e[112]=m,e[113]=n,e[114]=d,e[115]=he,e[116]=ke):ke=e[116];let X;e[117]===Symbol.for("react.memo_cache_sentinel")?(X=s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"}),e[117]=X):X=e[117];let ae;e[118]!==Ie||e[119]!==ke?(ae=s.jsx(Is,{asChild:!0,children:s.jsxs("div",{className:Ie,children:[ke,X]})}),e[118]=Ie,e[119]=ke,e[120]=ae):ae=e[120];let je;e[121]!==Y?(je=s.jsx(Ps,{className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",align:"start",children:Y}),e[121]=Y,e[122]=je):je=e[122];let le;return e[123]!==Se||e[124]!==fe||e[125]!==ae||e[126]!==je?(le=s.jsxs(As,{open:Se,onOpenChange:fe,children:[ae,je]}),e[123]=Se,e[124]=fe,e[125]=ae,e[126]=je,e[127]=le):le=e[127],le};function bw(t){return t.providers}function yw(t){return t.modelsMetadata}function vw(t){return t.isMobile}function ww(t){return t.hiddenModels}function jw(t){return t.toggleFavoriteModel}function Nw(t){return t.isFavoriteModel}function Sw(t){return t.addRecentModel}const ic=t=>{const e=ot.c(34),{agentName:n,onChange:r,className:a,filter:i}=t,{t:o}=ft(),{isReady:c,isUnavailable:d}=hh(),p=wt(kw),m=ji(Cw),u=ji(Iw),f=wt(Pw);let b;e:{if(Array.isArray(p)&&p.length>0){b=p;break e}let B;e[0]!==m?(B=Array.isArray(m)?m:[],e[0]=m,e[1]=B):B=e[1],b=B}const x=b;let y;if(e[2]!==i||e[3]!==x){const B=wb(x);y=i?B.filter(i):B,e[2]=i,e[3]=x,e[4]=y}else y=e[4];const g=y,h=Fe(Aw),{isMobile:j}=ln(),v=h||j,[C,k]=l.useState(!1);let w,N;e[5]!==u||e[6]!==f||e[7]!==x.length?(w=()=>{x.length>0||(f(),u())},N=[x.length,f,u],e[5]=u,e[6]=f,e[7]=x.length,e[8]=w,e[9]=N):(w=e[8],N=e[9]),l.useEffect(w,N);let I;e[10]===Symbol.for("react.memo_cache_sentinel")?(I=()=>k(!1),e[10]=I):I=e[10];const T=I;let P;e[11]!==r?(P=B=>{r(B)},e[11]=r,e[12]=P):P=e[12];const D=P;let S;e[13]!==n||e[14]!==g||e[15]!==D||e[16]!==v||e[17]!==C||e[18]!==o?(S=()=>v?s.jsx(zr,{open:C,onClose:T,title:o("settings.commands.agentSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",className:ye("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:()=>{D(""),T()},children:[s.jsx("span",{className:ye("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"})]}),g.map(B=>{const $=B.name===n;return s.jsxs("button",{type:"button",className:ye("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:()=>{D(B.name),T()},children:[s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-meta font-medium",children:B.name}),B.description&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:B.description})]}),$&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]},B.name)})]})}):null,e[13]=n,e[14]=g,e[15]=D,e[16]=v,e[17]=C,e[18]=o,e[19]=S):S=e[19];const M=S;let E;e[20]!==n||e[21]!==g||e[22]!==a||e[23]!==D||e[24]!==v||e[25]!==c||e[26]!==d||e[27]!==o?(E=v?s.jsxs("button",{type:"button",onClick:c?()=>k(!0):void 0,disabled:!c,className:ye("flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",!c&&"opacity-60 cursor-not-allowed",a),children:[s.jsx("div",{className:"flex items-center gap-2",children:c?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:n||o("settings.commands.agentSelector.selectAgentPlaceholder")})]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]})}),s.jsx(A,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):c?s.jsxs(As,{children:[s.jsx(Is,{asChild:!0,children:s.jsxs("div",{className:ye("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 cursor-pointer hover:bg-interactive-hover/30 h-6 w-fit",a),children:[s.jsx(A,{name:"robot-2",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap",children:n||o("settings.commands.agentSelector.notSelected")}),s.jsx(A,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsxs(Ps,{className:"max-w-[300px]",children:[s.jsx(_t,{className:"typography-meta",onSelect:()=>D(""),children:s.jsx("span",{className:"text-muted-foreground",children:o("settings.commands.agentSelector.notSelected")})}),g.map(B=>s.jsx(_t,{className:"typography-meta",onSelect:()=>D(B.name),children:s.jsx("span",{className:"font-medium",children:B.name})},B.name))]})]}):s.jsxs("div",{className:ye("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 h-6 w-fit opacity-60",a),children:[s.jsx(A,{name:"loader-4",className:"h-3 w-3 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap text-muted-foreground",children:o(d?"common.unavailable":"common.loading")})]}),e[20]=n,e[21]=g,e[22]=a,e[23]=D,e[24]=v,e[25]=c,e[26]=d,e[27]=o,e[28]=E):E=e[28];let R;e[29]!==M?(R=M(),e[29]=M,e[30]=R):R=e[30];let V;return e[31]!==E||e[32]!==R?(V=s.jsxs(s.Fragment,{children:[E,R]}),e[31]=E,e[32]=R,e[33]=V):V=e[33],V};function kw(t){return t.agents}function Cw(t){return t.agents}function Iw(t){return t.loadAgents}function Pw(t){return t.loadAgents}function Aw(t){return t.isMobile}const Em=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent}),Dw=t=>{const e=ot.c(38),{value:n,options:r,disabled:a,onChange:i}=t,{t:o}=ft();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=ye("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(A,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),e[7]=f):f=e[7];let b;e[8]!==m||e[9]!==u?(b=s.jsxs("div",{className:m,children:[u,f]}),e[8]=m,e[9]=u,e[10]=b):b=e[10];const x=b;if(a)return x;let y;e[11]!==x?(y=s.jsx(Is,{asChild:!0,children:x}),e[11]=x,e[12]=y):y=e[12];let g;e[13]!==i?(g=()=>i(""),e[13]=i,e[14]=g):g=e[14];const h=!n&&"text-primary";let j;e[15]!==h?(j=ye("font-medium",h),e[15]=h,e[16]=j):j=e[16];let v;e[17]!==o?(v=o("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[17]=o,e[18]=v):v=e[18];let C;e[19]!==j||e[20]!==v?(C=s.jsx("span",{className:j,children:v}),e[19]=j,e[20]=v,e[21]=C):C=e[21];let k;e[22]!==C||e[23]!==g?(k=s.jsx(_t,{className:"typography-meta",onSelect:g,children:C}),e[22]=C,e[23]=g,e[24]=k):k=e[24];let w;if(e[25]!==i||e[26]!==r||e[27]!==n){let T;e[29]!==i||e[30]!==n?(T=P=>s.jsx(_t,{className:"typography-meta",onSelect:()=>i(P),children:s.jsx("span",{className:ye("font-medium capitalize",n===P&&"text-primary"),children:P})},P),e[29]=i,e[30]=n,e[31]=T):T=e[31],w=r.map(T),e[25]=i,e[26]=r,e[27]=n,e[28]=w}else w=e[28];let N;e[32]!==k||e[33]!==w?(N=s.jsxs(Ps,{align:"start",className:"max-w-[220px]",children:[k,w]}),e[32]=k,e[33]=w,e[34]=N):N=e[34];let I;return e[35]!==N||e[36]!==y?(I=s.jsxs(As,{children:[y,N]}),e[35]=N,e[36]=y,e[37]=I):I=e[37],I};function Zh(t){const e=ot.c(99),{t:n}=ft(),{open:r,onOpenChange:a,target:i,projectDirectory:o,submitting:c,onConfirm:d}=t,p=c===void 0?!1:c,m=wt(Bw),u=wt(_w),f=ji($w),b=wt(Lw),x=wt(Ow),y=wt(Fw),g=wt(Rw),h=wt(Mw);let j;e[0]!==h||e[1]!==y||e[2]!==x||e[3]!==g?(j=()=>Em({providerID:x,modelID:y,variant:g,agent:h}),e[0]=h,e[1]=y,e[2]=x,e[3]=g,e[4]=j):j=e[4];const[v,C]=l.useState(j);let k,w;e[5]!==f||e[6]!==u||e[7]!==m||e[8]!==r||e[9]!==o?(k=()=>{r&&(m({directory:o}),u({directory:o}),f())},w=[r,m,u,f,o],e[5]=f,e[6]=u,e[7]=m,e[8]=r,e[9]=o,e[10]=k,e[11]=w):(k=e[10],w=e[11]),l.useEffect(k,w);let N,I;e[12]!==h||e[13]!==y||e[14]!==x||e[15]!==g||e[16]!==r?(N=()=>{r&&C(Em({providerID:x,modelID:y,variant:g,agent:h}))},I=[r,x,y,g,h],e[12]=h,e[13]=y,e[14]=x,e[15]=g,e[16]=r,e[17]=N,e[18]=I):(N=e[17],I=e[18]),l.useEffect(N,I);let T,P;e[19]!==v.modelID||e[20]!==v.providerID||e[21]!==r||e[22]!==b?(T=()=>{if(!r||b.length===0)return;const Ie=b.find(je=>je.id===v.providerID)??b[0],ke=Array.isArray(Ie?.models)?Ie.models:[],X=ke.some(je=>je.id===v.modelID),ae=ke[0]?.id??"";Ie?.id===v.providerID&&X||C(je=>({...je,providerID:Ie?.id??"",modelID:X?je.modelID:ae,variant:""}))},P=[r,b,v.providerID,v.modelID],e[19]=v.modelID,e[20]=v.providerID,e[21]=r,e[22]=b,e[23]=T,e[24]=P):(T=e[23],P=e[24]),l.useEffect(T,P);const D=Ew;let S;if(e[25]!==v.modelID||e[26]!==v.providerID||e[27]!==b){let Ie;e[29]!==v.providerID?(Ie=X=>X.id===v.providerID,e[29]=v.providerID,e[30]=Ie):Ie=e[30],S=b.find(Ie)?.models?.find(X=>X.id===v.modelID),e[25]=v.modelID,e[26]=v.providerID,e[27]=b,e[28]=S}else S=e[28];const M=S;let E;e[31]!==M?(E=M?.variants?Object.keys(M.variants):[],e[31]=M,e[32]=E):E=e[32];const R=E,V=R.length>0;let B,$;e[33]!==v.variant||e[34]!==V?(B=()=>{V||!v.variant||C(Tw)},$=[V,v.variant],e[33]=v.variant,e[34]=V,e[35]=B,e[36]=$):(B=e[35],$=e[36]),l.useEffect(B,$);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 _=O;let q;e[40]!==_||e[41]!==v||e[42]!==d||e[43]!==p?(q=()=>{!_||p||d(v)},e[40]=_,e[41]=v,e[42]=d,e[43]=p,e[44]=q):q=e[44];const L=q;let J,Z;e[45]!==L||e[46]!==r?(J=()=>{if(!r)return;const Ie=ke=>{(ke.metaKey||ke.ctrlKey)&&ke.key==="Enter"&&(ke.preventDefault(),L())};return window.addEventListener("keydown",Ie),()=>window.removeEventListener("keydown",Ie)},Z=[r,L],e[45]=L,e[46]=r,e[47]=J,e[48]=Z):(J=e[47],Z=e[48]),l.useEffect(J,Z);let ie;e[49]!==n||e[50]!==i?(ie=n(i==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=i,e[51]=ie):ie=e[51];const ne=ie;let me;e[52]!==a||e[53]!==p?(me=Ie=>{p||a(Ie)},e[52]=a,e[53]=p,e[54]=me):me=e[54];let pe;e[55]!==ne?(pe=s.jsx(hs,{children:s.jsx(ms,{children:ne})}),e[55]=ne,e[56]=pe):pe=e[56];let G;e[57]===Symbol.for("react.memo_cache_sentinel")?(G=(Ie,ke)=>{C(X=>({...X,providerID:Ie,modelID:ke,variant:""}))},e[57]=G):G=e[57];let K;e[58]!==v.modelID||e[59]!==v.providerID?(K=s.jsx(Io,{providerId:v.providerID,modelId:v.modelID,onChange:G}),e[58]=v.modelID,e[59]=v.providerID,e[60]=K):K=e[60];const Q=!V;let W;e[61]===Symbol.for("react.memo_cache_sentinel")?(W=Ie=>C(ke=>({...ke,variant:Ie})),e[61]=W):W=e[61];let de;e[62]!==v.variant||e[63]!==Q||e[64]!==R?(de=s.jsx(Dw,{value:v.variant,options:R,disabled:Q,onChange:W}),e[62]=v.variant,e[63]=Q,e[64]=R,e[65]=de):de=e[65];let ge;e[66]===Symbol.for("react.memo_cache_sentinel")?(ge=Ie=>C(ke=>({...ke,agent:Ie})),e[66]=ge):ge=e[66];let ve;e[67]!==v.agent?(ve=s.jsx(ic,{agentName:v.agent,filter:D,onChange:ge}),e[67]=v.agent,e[68]=ve):ve=e[68];let te;e[69]!==K||e[70]!==de||e[71]!==ve?(te=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[K,de,ve]}),e[69]=K,e[70]=de,e[71]=ve,e[72]=te):te=e[72];let he;e[73]!==a?(he=()=>a(!1),e[73]=a,e[74]=he):he=e[74];let ce;e[75]!==n?(ce=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[75]=n,e[76]=ce):ce=e[76];let xe;e[77]!==p||e[78]!==he||e[79]!==ce?(xe=s.jsx(be,{variant:"ghost",size:"sm",onClick:he,disabled:p,children:ce}),e[77]=p,e[78]=he,e[79]=ce,e[80]=xe):xe=e[80];const se=!_||p;let ue;e[81]!==p||e[82]!==n?(ue=n(p?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[81]=p,e[82]=n,e[83]=ue):ue=e[83];let Y;e[84]!==L||e[85]!==se||e[86]!==ue?(Y=s.jsx(be,{size:"sm",onClick:L,disabled:se,children:ue}),e[84]=L,e[85]=se,e[86]=ue,e[87]=Y):Y=e[87];let Se;e[88]!==xe||e[89]!==Y?(Se=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[xe,Y]}),e[88]=xe,e[89]=Y,e[90]=Se):Se=e[90];let fe;e[91]!==pe||e[92]!==te||e[93]!==Se?(fe=s.jsxs(ds,{className:"max-w-lg",children:[pe,te,Se]}),e[91]=pe,e[92]=te,e[93]=Se,e[94]=fe):fe=e[94];let Ce;return e[95]!==r||e[96]!==me||e[97]!==fe?(Ce=s.jsx(us,{open:r,onOpenChange:me,children:fe}),e[95]=r,e[96]=me,e[97]=fe,e[98]=Ce):Ce=e[98],Ce}function Tw(t){return{...t,variant:""}}function Ew(t){return bh(t.mode)}function Mw(t){return t.currentAgentName||""}function Rw(t){return t.currentVariant||""}function Fw(t){return t.currentModelId}function Ow(t){return t.currentProviderId}function Lw(t){return t.providers}function $w(t){return t.loadAgents}function _w(t){return t.loadAgents}function Bw(t){return t.loadProviders}const jd=5,eg=15,ul=t=>{const e=Math.sqrt(t/100),n=12*e,r=24*e;return Math.ceil(n+r+1)},Vw=(t,e)=>{const n=ul(e);return Math.max(n*jd,Math.min(n*eg,n*t))},zw=async(t,e)=>{const n=await kb(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},Uw=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,Ww=t=>{const e=ot.c(20),{id:n,children:r}=t;let a;e[0]!==n?(a={id:n},e[0]=n,e[1]=a):a=e[1];const{attributes:i,listeners:o,setNodeRef:c,setActivatorNodeRef:d,transform:p,transition:m,isDragging:u}=ql(a);let f;e[2]!==p?(f=Jl.Transform.toString(p),e[2]=p,e[3]=f):f=e[3];let b;e[4]!==f||e[5]!==m?(b={transform:f,transition:m},e[4]=f,e[5]=m,e[6]=b):b=e[6];const x=u&&"opacity-60";let y;e[7]!==x?(y=ye(x),e[7]=x,e[8]=y):y=e[8];let g;e[9]!==i||e[10]!==r||e[11]!==u||e[12]!==o||e[13]!==d?(g=r({attributes:i,listeners:o,setActivatorNodeRef:d,isDragging:u}),e[9]=i,e[10]=r,e[11]=u,e[12]=o,e[13]=d,e[14]=g):g=e[14];let h;return e[15]!==c||e[16]!==b||e[17]!==y||e[18]!==g?(h=s.jsx("li",{ref:c,style:b,className:y,children:g}),e[15]=c,e[16]=b,e[17]=y,e[18]=g,e[19]=h):h=e[19],h},Kw=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:a})=>{const{t:i}=ft(),[o,c]=l.useState(!1),[d,p]=l.useState(""),[m,u]=l.useState([]),[f,b]=l.useState(""),[x,y]=l.useState(null),[g,h]=l.useState(()=>new Set),[j,v]=l.useState([]),[C,k]=l.useState(null),[w,N]=l.useState(!1),[I,T]=l.useState(0),P=l.useRef(!1),D=l.useRef(""),S=Fe(F=>F.todoPanelHeight),M=Fe(F=>F.setTodoPanelHeight),E=Fe(F=>F.notesPanelHeight),R=Fe(F=>F.setNotesPanelHeight),[V,B]=l.useState(!1),$=l.useRef(0),O=l.useRef(S),_=$t(F=>F.currentSessionId),q=$t(F=>F.createSession),L=$t(F=>F.initializeNewOpenChamberSession),J=$t(F=>F.sendMessage),Z=$t(F=>F.setCurrentSession),ie=Ha(F=>F.setPendingInputText),ne=Ws(F=>F.currentDirectory),me=Fe(F=>F.openContextPanelTab),pe=Fe(F=>F.setActiveMainTab),G=Fe(F=>F.setSessionSwitcherOpen),K=Fe(F=>F.padding),Q=l.useCallback(async(F,U)=>{if(!t)return!1;const oe=await jb(t,{notes:F,todos:U});return oe||H.error(i("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),oe},[t,i]);l.useEffect(()=>{if(!t){p(""),u([]),v([]),b(""),h(new Set);return}let F=!1;return c(!0),(async()=>{try{const U=await Nb(t),oe=await Promise.all(U.plans.map(Te=>zw(Te,i("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(F)return;p(U.notes),u(U.todos),v(oe),D.current=U.notes,P.current=!0,b(""),h(new Set)}catch{F||(H.error(i("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),p(""),u([]),v([]),D.current="",P.current=!0)}finally{F||c(!1)}})(),()=>{F=!0}},[I,t,i]),l.useEffect(()=>{if(!t)return;const F=U=>{const oe=U.detail;oe?.projectId&&oe.projectId!==t.id||T(Te=>Te+1)};return window.addEventListener("openchamber:project-plan-saved",F),window.addEventListener("openchamber:project-notes-updated",F),()=>{window.removeEventListener("openchamber:project-plan-saved",F),window.removeEventListener("openchamber:project-notes-updated",F)}},[t]),l.useEffect(()=>{if(m.length<7)return;const F=Vw(m.length,K),U=ul(K)*jd;(S<U||S>F)&&M(F)},[m.length,K,S,M]),l.useEffect(()=>{if(!V)return;const F=oe=>{const Te=oe.clientY-$.current,Oe=Math.min(ul(K)*eg,Math.max(ul(K)*jd,O.current+Te));M(Oe)},U=()=>{B(!1)};return window.addEventListener("pointermove",F),window.addEventListener("pointerup",U,{once:!0}),window.addEventListener("pointercancel",U,{once:!0}),()=>{window.removeEventListener("pointermove",F),window.removeEventListener("pointerup",U),window.removeEventListener("pointercancel",U)}},[V,K,M]);const W=l.useCallback(F=>{B(!0),$.current=F.clientY,O.current=S,F.preventDefault()},[S]),de=l.useCallback(()=>{D.current=d,Q(d,m)},[d,Q,m]);l.useEffect(()=>{if(!t||!P.current||d===D.current)return;const F=window.setTimeout(()=>{D.current=d,Q(d,m)},400);return()=>{window.clearTimeout(F)}},[d,Q,t,m]);const ge=l.useCallback(()=>{const F=f.trim();if(!F)return;const U=[...m,{id:Uw(),text:F.slice(0,Eo),completed:!1,createdAt:Date.now()}];u(U),b(""),Q(d,U)},[f,d,Q,m]),ve=l.useCallback(F=>{h(U=>{const oe=new Set(U);return oe.has(F)?oe.delete(F):oe.add(F),oe})},[]),te=l.useCallback((F,U)=>{const oe=m.map(Te=>Te.id===F?{...Te,completed:U}:Te);u(oe),Q(d,oe)},[d,Q,m]),he=l.useCallback(F=>{const U=m.filter(oe=>oe.id!==F);u(U),Q(d,U)},[d,Q,m]),ce=l.useCallback(()=>{const F=m.filter(U=>!U.completed);F.length!==m.length&&(u(F),Q(d,F))},[d,Q,m]),xe=l.useCallback(F=>{const{active:U,over:oe}=F;if(!oe||U.id===oe.id)return;const Te=m.findIndex(z=>z.id===U.id),Oe=m.findIndex(z=>z.id===oe.id);if(Te===-1||Oe===-1)return;const Pe=ah(m,Te,Oe);u(Pe),Q(d,Pe)},[d,Q,m]),se=io(hi(oo,{activationConstraint:{distance:8}})),ue=f.slice(0,Eo),Y=m.reduce((F,U)=>F+(U.completed?1:0),0),Se=l.useCallback(()=>{pe("chat"),G(!1)},[pe,G]),fe=l.useCallback((F,U)=>{!t||x||k({kind:"session",todoId:F,todoText:U})},[t,x]),Ce=l.useCallback(F=>{if(!_){H.error(i("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}Se();const U=`\`\`\`md
|
|
4
|
-
${F}
|
|
5
|
-
\`\`\``;ie(U,"append"),H.success(i("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[_,r,Se,ie,i]),Ie=l.useCallback((F,U)=>{if(!(!t||x)){if(!n){H.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}k({kind:"worktree",todoId:F,todoText:U})}},[n,t,x,i]),ke=l.useCallback(async F=>{if(!t||!C)return;const U=await wn("plan.todo.visible",{todo_text:C.todoText}),Te=[{synthetic:!0,text:await wn("plan.todo.instructions",{todo_text:C.todoText})}];N(!0),y(C.todoId);try{Se();let Oe=null,Pe=t.path;if(C.kind==="worktree"){if(!n){H.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const De=await yh(t.path,vh());if(!De?.id)return;Oe=De.id,Pe=null}else{const De=await q(void 0,t.path,null);if(!De?.id){H.error(i("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}Oe=De.id,Pe=De.directory??t.path,L(De.id,wt.getState().agents??[])}if(!Oe)return;const z=Ql.getState();z.saveSessionModelSelection(Oe,F.providerID,F.modelID),F.agent.trim()&&(z.saveSessionAgentSelection(Oe,F.agent),z.saveAgentModelForSession(Oe,F.agent,F.providerID,F.modelID),z.saveAgentModelVariantForSession(Oe,F.agent,F.providerID,F.modelID,F.variant||void 0)),Z(Oe,Pe),await J(U,F.providerID,F.modelID,F.agent.trim()||void 0,void 0,void 0,Te,F.variant||void 0),H.success(C.kind==="worktree"?i("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):i("rightSidebar.contextNotesTodo.toast.sentToNewSession")),k(null),r?.()}catch(Oe){const Pe=Oe instanceof Error?Oe.message:void 0;H.error(i("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),Pe?{description:Pe}:void 0)}finally{N(!1),y(null)}},[n,q,L,r,C,t,Se,J,Z,i]),X=l.useRef(null),[ae,je]=l.useState(!1),[le,Ne]=l.useState(null),Me=l.useCallback(async F=>{if(!(!t||le)){Ne(F);try{if(!await Sb(t,F)){H.error(i("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}v(oe=>oe.filter(Te=>Te.id!==F)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}}))}finally{Ne(null)}}},[le,t,i]),Ve=l.useCallback(async()=>{if(!t||ae)return;const F=await wh({defaultPath:t.path,filters:[{name:"Plan files",extensions:["md","markdown","txt"]},{name:"All files",extensions:["*"]}]});if(F.success&&F.path){je(!0);try{const U=new URLSearchParams({path:F.path,allowOutsideWorkspace:"true"}),oe=await fetch(`/api/fs/read?${U.toString()}`,{cache:"no-store"});if(!oe.ok){H.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"));return}const Te=await oe.text();if(!Te.trim()){H.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const Oe=F.path.split("/").pop()?.replace(/\.(md|markdown|txt)$/i,"").trim()||"";if(!await Vu(t,Te,Oe)){H.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),H.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(U){const oe=U instanceof Error?U.message:void 0;H.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),oe?{description:oe}:void 0)}finally{je(!1)}}else F.error==="Native file picker not available"&&X.current?.click()},[ae,t,i]),we=l.useCallback(async F=>{if(!(!t||!F)){je(!0);try{const U=await F.text();if(!U.trim()){H.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const oe=F.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await Vu(t,U,oe)){H.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),H.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(U){const oe=U instanceof Error?U.message:void 0;H.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),oe?{description:oe}:void 0)}finally{je(!1)}}},[t,i]),ee=l.useCallback(F=>{const U=t?.path?.trim(),oe=ne?.trim()||U;oe&&me(oe,{mode:"plan",targetPath:F.path,dedupeKey:F.path,label:F.title})},[ne,me,t]);return t?s.jsxs("div",{className:ye("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,"/",zu]})]}),s.jsx(un,{value:d,onChange:F=>p(F.target.value.slice(0,zu)),onBlur:de,placeholder:i("rightSidebar.contextNotesTodo.notes.placeholder"),resizedHeight:E,onResizeHeightChange:R,useScrollShadow:!0,scrollShadowSize:56,disabled:o})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:m.length===1?i("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:m.length}):i("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:m.length})}),s.jsx("button",{type:"button",onClick:ce,disabled:o||Y===0,className:"typography-meta rounded-md px-1.5 py-0.5 text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",children:i("rightSidebar.contextNotesTodo.todo.clearCompleted")})]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[ue.length,"/",Eo]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Lt,{value:ue,onChange:F=>b(F.target.value.slice(0,Eo)),onKeyDown:F=>{F.key==="Enter"&&(F.preventDefault(),ge())},placeholder:i("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:o,className:"h-8"}),s.jsx("button",{type:"button",onClick:ge,disabled:o||ue.trim().length===0,className:"inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.addAria"),title:i("rightSidebar.contextNotesTodo.todo.addAria"),children:s.jsx(A,{name:"add",className:"h-4 w-4"})})]}),s.jsx("div",{className:ye("overflow-y-auto rounded-lg border border-border/60 bg-background/40",V&&"transition-none"),style:m.length<7?void 0:{height:`${S}px`,maxHeight:`${S}px`},children:m.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.todo.empty")}):s.jsx(lo,{sensors:se,collisionDetection:co,onDragEnd:xe,children:s.jsx(Sl,{items:m.map(F=>F.id),strategy:dd,children:s.jsx("ul",{className:"divide-y divide-border/50",children:m.map(F=>{const U=g.has(F.id);return s.jsx(Ww,{id:F.id,children:oe=>s.jsxs("div",{className:"flex items-start gap-1.5 px-2.5 py-1.5",children:[s.jsx("button",{type:"button",ref:oe.setActivatorNodeRef,...oe.attributes,...oe.listeners,onClick:Te=>{Te.preventDefault(),Te.stopPropagation()},className:"flex h-6 w-4 flex-shrink-0 touch-none items-center justify-center text-muted-foreground hover:text-foreground","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:F.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:F.text}),children:s.jsx(A,{name:"draggable",className:"h-3.5 w-3.5"})}),s.jsx("div",{className:"flex h-6 items-center",children:s.jsx(vs,{checked:F.completed,onChange:Te=>te(F.id,Te),ariaLabel:i("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:F.text})})}),s.jsx("button",{type:"button",onClick:()=>ve(F.id),className:ye("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-6 text-foreground",U?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",F.completed&&"text-muted-foreground line-through"),title:U?void 0:F.text,"aria-label":U?i("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:F.text}):i("rightSidebar.contextNotesTodo.todo.actions.expand",{text:F.text}),children:F.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>he(F.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:F.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:F.text}),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(As,{children:[s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",disabled:x===F.id,className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.actions.send",{text:F.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.send",{text:F.text}),children:s.jsx(A,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs(Ps,{align:"end",className:"w-56",children:[s.jsx(_t,{onClick:()=>Ce(F.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx(_t,{onClick:()=>fe(F.id,F.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx(_t,{onClick:()=>{Ie(F.id,F.text)},disabled:!n,children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]})},F.id)})})})})}),m.length>=7&&s.jsx("div",{className:ye("h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",V&&"bg-[var(--interactive-border)]"),onPointerDown:W,role:"separator","aria-orientation":"horizontal","aria-label":i("rightSidebar.contextNotesTodo.todo.resizeAria")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.plans.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:j.length===1?i("rightSidebar.contextNotesTodo.plans.filesSingle",{count:j.length}):i("rightSidebar.contextNotesTodo.plans.filesPlural",{count:j.length})})]}),s.jsx("input",{ref:X,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:F=>{const U=F.target.files?.[0]??null;we(U),F.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:Ve,disabled:!t||ae,className:"inline-flex h-6 w-6 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.plans.importFromFile"),title:i("rightSidebar.contextNotesTodo.plans.importFromFile"),children:s.jsx(A,{name:"add",className:"h-3.5 w-3.5"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:j.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.plans.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:j.map(F=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>ee(F),className:"flex min-w-0 flex-1 items-center justify-between gap-3 rounded-md px-1.5 py-1 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-foreground",children:F.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(F.createdAt).toLocaleDateString()})]}),s.jsx("button",{type:"button",onClick:()=>{Me(F.id)},disabled:le===F.id,className:"inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",title:i("rightSidebar.contextNotesTodo.plans.deletePlan"),"aria-label":i("rightSidebar.contextNotesTodo.plans.deletePlanWithTitle",{title:F.title}),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},F.id))})})]}),s.jsx(Zh,{open:C!==null,onOpenChange:F=>{!F&&!w&&k(null)},target:C?.kind??"session",projectDirectory:t?.path??null,submitting:w,onConfirm:ke})]}):s.jsx("div",{className:ye("w-full min-w-0 p-3",a),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.empty.selectProject")})})},tg=12,Hw=[{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"}],Gw=t=>{const e=ot.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?Hw:o,u=_e.useRef(!1);let f,b;e[0]!==n||e[1]!==c?(f=()=>{!n&&u.current&&c?.(),n&&(u.current=!0)},b=[n,c],e[0]=n,e[1]=c,e[2]=f,e[3]=b):(f=e[2],b=e[3]),_e.useEffect(f,b);let x;e[4]===Symbol.for("react.memo_cache_sentinel")?(x=Array.from({length:tg},qw),e[4]=x):x=e[4];const y=x;if(!n)return null;let g;e[5]!==a?(g=ye("fireworks-overlay pointer-events-none",a),e[5]=a,e[6]=g):g=e[6];let h;if(e[7]!==d||e[8]!==m||e[9]!==p){let v;e[11]!==d||e[12]!==p?(v=C=>{const k={"--burst-delay":`${C.delay}ms`,"--burst-x":`${C.x}%`,"--burst-y":`${C.y}%`,"--firework-color":`var(${C.colorVar})`,"--firework-duration":`${p}ms`};return s.jsx("div",{className:"firework-burst",style:k,children:y.map((w,N)=>{const I=w.x*C.radius,T=w.y*C.radius,P={"--translate-x":`${I}px`,"--translate-y":`${T}px`,"--particle-delay":`${w.delay}ms`,color:`var(${C.colorVar})`};return s.jsx("span",{className:"firework-particle",style:P},`${C.id}-${N}-${d}`)})},`${C.id}-${d}`)},e[11]=d,e[12]=p,e[13]=v):v=e[13],h=m.map(v),e[7]=d,e[8]=m,e[9]=p,e[10]=h}else h=e[10];let j;return e[14]!==d||e[15]!==g||e[16]!==h?(j=s.jsx("div",{className:g,"aria-hidden":"true","data-burst-key":d,children:h}),e[14]=d,e[15]=g,e[16]=h,e[17]=j):j=e[17],j};function qw(t,e){const n=Math.PI*2*e/tg;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const Jw=t=>{const e=ot.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,a=r===void 0?3400:r;let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={isActive:!1,cycle:0},e[2]=i):i=e[2];const[o,c]=_e.useState(i),d=_e.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(Yw)},e[4]=u):u=e[4];const f=u;let b;e[5]!==a?(b=()=>{m(),c(Qw),d.current=window.setTimeout(()=>{c(Xw),d.current=null},a)},e[5]=a,e[6]=b):b=e[6];const x=b;let y,g;e[7]===Symbol.for("react.memo_cache_sentinel")?(y=()=>()=>m(),g=[m],e[7]=y,e[8]=g):(y=e[7],g=e[8]),_e.useEffect(y,g);let h;return e[9]!==o.cycle||e[10]!==o.isActive||e[11]!==x?(h={isActive:o.isActive,burstKey:o.cycle,triggerFireworks:x,dismissFireworks:f},e[9]=o.cycle,e[10]=o.isActive,e[11]=x,e[12]=h):h=e[12],h};function Yw(t){return t.isActive?{...t,isActive:!1}:t}function Qw(t){return{isActive:!0,cycle:t.cycle+1}}function Xw(t){return t.isActive?{...t,isActive:!1}:t}const sg=l.createContext(void 0),Zw=t=>{const e=ot.c(10),{children:n}=t,{isActive:r,burstKey:a,triggerFireworks:i,dismissFireworks:o}=Jw();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(Gw,{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(sg.Provider,{value:d,children:[n,p]}),e[6]=n,e[7]=p,e[8]=d,e[9]=m):m=e[9],m},ej=()=>{const t=l.useContext(sg);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},tr=ar()(Xa(Ei((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 Tb();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 Db();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 Ab();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=or()?.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 ks({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 Pb(r),await e().loadProfiles(),!0}catch(r){return console.error("Failed to create git identity profile:",r),!1}},updateProfile:async(n,r)=>{try{const a=e().profiles.find(o=>o.id===n);if(!a)throw new Error("Profile not found");const i={...a,...r};return await Ib(n,i),await e().loadProfiles(),!0}catch(a){return console.error("Failed to update git identity profile:",a),!1}},deleteProfile:async n=>{try{return await Cb(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:wo(()=>br()),partialize:t=>({selectedProfileId:t.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=tr);function qa(t){const e=ot.c(12);let n,r,a;e[0]!==t?({className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a):(n=e[1],r=e[2],a=e[3]);let i;e[4]!==a?(i={color:"var(--surface-elevated-foreground)",...a},e[4]=a,e[5]=i):i=e[5];let o;e[6]!==n?(o=ye("flex h-full w-full flex-col overflow-hidden rounded-xl",n),e[6]=n,e[7]=o):o=e[7];let c;return e[8]!==r||e[9]!==i||e[10]!==o?(c=s.jsx(Za,{"data-slot":"command",style:i,className:o,...r}),e[8]=r,e[9]=i,e[10]=o,e[11]=c):c=e[11],c}const va=_e.forwardRef((t,e)=>{const n=ot.c(10);let r,a;n[0]!==t?({className:r,...a}=t,n[0]=t,n[1]=r,n[2]=a):(r=n[1],a=n[2]);let i;n[3]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(A,{name:"search",className:"size-4 shrink-0 opacity-50"}),n[3]=i):i=n[3];let o;n[4]!==r?(o=ye("placeholder:text-muted-foreground flex h-8 w-full rounded-lg bg-transparent py-2 typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",r),n[4]=r,n[5]=o):o=n[5];let c;return n[6]!==a||n[7]!==e||n[8]!==o?(c=s.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-8 items-center gap-2 border-b px-3",children:[i,s.jsx(Za.Input,{ref:e,"data-slot":"command-input",className:o,...a})]}),n[6]=a,n[7]=e,n[8]=o,n[9]=c):c=n[9],c});va.displayName="CommandInput";function Ja(t){const e=ot.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=ye("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(Ss,{as:Za.List,"data-slot":"command-list",outerClassName:"max-h-[min(600px,calc(100vh-10rem))] overflow-x-hidden p-0 w-full h-full min-h-0",className:c,scrollbarClassName:d,disableHorizontal:p,...i,children:n}),e[8]=n,e[9]=i,e[10]=c,e[11]=d,e[12]=p,e[13]=m):m=e[13],m}function Ya(t){const e=ot.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(Za.Empty,{"data-slot":"command-empty",className:"py-6 text-center typography-ui-label",...n}),e[2]=n,e[3]=r):r=e[3],r}function On(t){const e=ot.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=ye("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(Za.Group,{"data-slot":"command-group",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function _a(t){const e=ot.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=ye("bg-border -mx-1 h-px",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(Za.Separator,{"data-slot":"command-separator",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function Pn(t){const e=ot.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=ye("data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(Za.Item,{"data-slot":"command-item",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function tj(t){const e=ot.c(12);let n,r,a,i;if(e[0]!==t){const{className:c,...d}=t,p=nj,m=typeof d.children=="string"?d.children:"",u=m?m.split("+").map(sj).filter(Boolean):[];n="command-shortcut",e[5]!==c?(r=ye("text-muted-foreground ml-auto flex items-center gap-1 typography-meta",c),e[5]=c,e[6]=r):r=e[6],a=d,i=u.length>0?u.map((f,b)=>s.jsxs(_e.Fragment,{children:[b>0&&s.jsx("span",{className:"opacity-60 text-xs",children:"+"}),p(f)]},`${f}-${b}`)):d.children,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i}else n=e[1],r=e[2],a=e[3],i=e[4];let o;return e[7]!==n||e[8]!==r||e[9]!==a||e[10]!==i?(o=s.jsx("span",{"data-slot":n,className:r,...a,children:i}),e[7]=n,e[8]=r,e[9]=a,e[10]=i,e[11]=o):o=e[11],o}function sj(t){return t.trim()}function nj(t){const e=t.trim().toLowerCase();return e==="ctrl"||e==="control"?s.jsx("span",{className:"text-xs font-medium",children:"ctrl"}):e==="cmd"||e==="⌘"||e==="command"||e==="meta"?s.jsx(A,{name:"command",className:"size-3.5"}):e==="shift"||e==="⇧"?s.jsx(A,{name:"arrow-up",className:"size-3.5"}):s.jsx("span",{className:"text-xs font-medium",children:t})}const Nd=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},rj=t=>{const e=Nd(t);if(!e)return null;const r=e.indexOf("/.git/worktrees/");return r>0&&e.slice(0,r)||null};function aj(t,e,n){const r=ot.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([Hs("git rev-parse --absolute-git-dir",t),Hs("git rev-parse --show-toplevel",t)]);if(d||!p.success||!m.success)return;const u=Nd((p.stdout||"").trim()),f=rj(u);if(!f)return;const b=Nd((m.stdout||"").trim());if(!b||b===f)return;const x=n||"",y=b.split("/").filter(Boolean).pop()||b;i({source:"sdk",path:b,projectDirectory:f,branch:x,label:x||y,name:y,worktreeRoot:b,worktreeStatus:"ready",headState:x?"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 sr=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},Ai=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),sa=t=>!!t.success,oc=t=>(t.stdout||"").trim(),za=t=>(t.stderr||"").trim();async function ij(t){const n=((await Hs("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 oj(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),a=(await ij(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 Hs("git status --porcelain",o);oc(c)||i.push(o)}return i}async function ng(t,e){for(const n of e)await Hs("git reset --hard",n).catch(()=>{})}async function lj(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await Hs(`git show-ref --verify --quiet ${sr(`refs/heads/${n}`)}`,t);if(sa(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 Hs(`git branch --track ${sr(d)} ${sr(`${c}/${d}`)}`,t),d}const a=await Hs(`git show-ref --verify --quiet ${sr(`refs/remotes/origin/${n}`)}`,t);return sa(a)&&await Hs(`git branch --track ${sr(n)} ${sr(`origin/${n}`)}`,t),n}async function _i(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 lj(e,r),i=await Hs(`git cherry ${sr(a)} ${sr(n)}`,e),o=Ai(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 Hs(`git rev-list --reverse ${sr(`${a}..${n}`)}`,e),m=Ai(d.stdout).filter(u=>c.has(u));return{repoRoot:e,sourceBranch:n,targetBranch:a,commits:m}}async function cj(t,e){const n=await Hs('mkdir -p "$HOME/.config/openchamber/tmp"',t);if(!sa(n))throw new Error(za(n)||"Failed to create temp directory parent");const r=await Hs('mktemp -d "$HOME/.config/openchamber/tmp/oc-integrate-XXXXXX"',t),a=oc(r);if(!a)throw new Error(za(r)||"Failed to create temp directory");const i=await Hs(`git worktree add --force ${sr(a)} ${sr(e)}`,t);if(!sa(i))throw new Error(za(i)||"Failed to create temp worktree");return a}async function Fl(t,e){await Hs(`git worktree remove --force ${sr(e)}`,t).catch(()=>{}),await Hs("git worktree prune",t).catch(()=>{})}async function dj(t){const e=await Hs("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=oc(e);if(!n)return;await Hs("git fetch",t);const r=await Hs(`git merge --ff-only ${sr(n)}`,t);if(!sa(r))throw new Error(za(r)||"Fast-forward failed")}async function Ol(t){const e=await Hs("git status --porcelain",t),n=await Hs("git diff --name-only --diff-filter=U",t),r=await Hs("git diff",t),a=await Hs("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),i=await Hs("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:Ai(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:a.stdout||a.stderr||"",currentPatch:i.stdout||i.stderr||""}}async function uj(t){return Ol(t)}async function mj(t){const e=await Hs("git rev-parse --verify --quiet CHERRY_PICK_HEAD",t);return sa(e)}async function pj(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await cj(t.repoRoot,t.targetBranch);let n=[];try{await dj(e);const r=await Hs("git status --porcelain",e);if(oc(r))throw new Error("Target branch has local changes; abort integration and retry");const a=await oj({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const i=n[0],o=await Hs(`git cherry-pick ${sr(i)}`,e);if(sa(o)){n.shift();continue}const c=await Hs("git diff --name-only --diff-filter=U",e);if(Ai(c.stdout).length>0){const p=await Ol(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(za(o)||"Cherry-pick failed")}return await Fl(t.repoRoot,e),await ng(t.repoRoot,a).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await Fl(t.repoRoot,e).catch(()=>{}),r}}async function fj(t){await Hs("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await Fl(t.repoRoot,t.tempWorktreePath)}async function hj(t){const e=await Hs("git cherry-pick --continue",t.tempWorktreePath);if(!sa(e)){const i=await Hs("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(Ai(i.stdout).length>0){const c=await Ol(t.tempWorktreePath);return{kind:"conflict",state:t,details:c}}throw new Error(za(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 Hs(`git cherry-pick ${sr(i)}`,n);if(sa(o)){a.shift();continue}const c=await Hs("git diff --name-only --diff-filter=U",n);if(Ai(c.stdout).length>0){const p=await Ol(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(za(o)||"Cherry-pick failed")}return await Fl(t.repoRoot,t.tempWorktreePath),await ng(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:t.remainingCommits.length}}const gj=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:a,refreshKey:i,onRefresh:o})=>{const{t:c}=ft(),d=$t(O=>O.currentSessionId),p=Fe(O=>O.setActiveMainTab),[m,u]=_e.useState(!1),f=_e.useRef(null),[b,x]=_e.useState(a);_e.useEffect(()=>{x(a)},[a]),_e.useEffect(()=>{if(m){const O=setTimeout(()=>{f.current?.focus()},0);return()=>clearTimeout(O)}},[m]);const y=!!(t&&e&&b&&b!=="HEAD"&&e!==b),[g,h]=_e.useState({kind:"idle"}),[j,v]=_e.useState(!1),[C,k]=_e.useState([]),w=_e.useMemo(()=>d?`openchamber.integrate.conflict:${d}`:null,[d]);_e.useEffect(()=>{if(!w||typeof window>"u")return;const O=window.localStorage.getItem(w);if(!O)return;let _=!1;try{const q=JSON.parse(O);if(!q?.tempWorktreePath||q.repoRoot!==t){window.localStorage.removeItem(w);return}(async()=>{const L=await mj(q.tempWorktreePath).catch(()=>!1);if(_)return;if(!L){window.localStorage.removeItem(w);return}const J=await uj(q.tempWorktreePath).catch(()=>null);_||J&&h({kind:"conflict",state:q,details:J})})()}catch{window.localStorage.removeItem(w)}return()=>{_=!0}},[w,t]),_e.useEffect(()=>{if(!y){h({kind:"idle"});return}let O=!1;return h({kind:"loading"}),(async()=>{try{const _=await _i({repoRoot:t,sourceBranch:e,targetBranch:b});if(O)return;if(h({kind:"ready",plan:_}),_.commits.length>0){const J=_.commits.slice(-50).reverse().map(me=>JSON.stringify(me)).join(" "),ie=((await Hs(`git show -s --format=%H%x09%h%x09%s ${J}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),ne=[];for(const me of ie){const[pe,G,K]=me.split(" ");!pe||!G||ne.push({sha:pe,short:G,subject:K||""})}O||(k(ne),v(!1))}else O||(k([]),v(!1))}catch{O||h({kind:"idle"})}})(),()=>{O=!0}},[y,t,e,b,i]);const N=_e.useCallback(O=>{d&&$t.getState().setWorktreeMetadata(d,{...n,createdFromBranch:O})},[d,n]),I=$t(O=>O.openNewSessionDraft),T=_e.useCallback(async O=>{const _=await wn("git.integrate.cherrypick.resolve.visible",{current_commit:O.state.currentCommit,target_branch:O.state.targetBranch}),q=await wn("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}),L=`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:_,instructionsText:q,payloadText:L}},[]),P=Ha(O=>O.setPendingInputText),D=Ha(O=>O.setPendingSyntheticParts),S=_e.useCallback(async(O,_)=>{const q=await T(O);if(_){I({directoryOverride:O.state.tempWorktreePath,initialPrompt:q.visibleText,syntheticParts:[{text:q.instructionsText,synthetic:!0},{text:q.payloadText,synthetic:!0}]}),p("chat");return}if(!d){H.error(c("gitView.integrate.noActiveSession"),{description:c("gitView.integrate.noActiveSessionDescription")});return}P(q.visibleText,"replace"),D([{text:q.instructionsText,synthetic:!0},{text:q.payloadText,synthetic:!0}]),p("chat")},[d,p,T,I,P,D,c]),M=_e.useCallback(async()=>{if(g.kind==="ready"){if(g.plan.commits.length===0){H.message(c("gitView.integrate.noCommitsToMoveToast"));return}h({kind:"running",plan:g.plan});try{const O=await pj(g.plan);if(O.kind==="success"){H.success(c("gitView.integrate.commitsMovedToast"),{description:O.moved===1?c("gitView.integrate.commitsMovedDescriptionSingle",{count:O.moved,branch:g.plan.targetBranch}):c("gitView.integrate.commitsMovedDescriptionPlural",{count:O.moved,branch:g.plan.targetBranch})});const _=await _i(g.plan);h({kind:"ready",plan:_}),o?.();return}O.kind==="conflict"&&(H.error(c("gitView.integrate.cherryPickConflictToast"),{description:c("gitView.integrate.cherryPickConflictDescription")}),h({kind:"conflict",state:O.state,details:O.details}),w&&typeof window<"u"&&window.localStorage.setItem(w,JSON.stringify(O.state)))}catch(O){const _=O instanceof Error?O.message:String(O);H.error(c("gitView.integrate.failedToMoveToast"),{description:_});const q=await _i({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);h(q?{kind:"ready",plan:q}:{kind:"idle"})}}},[g,o,t,e,b,w,c]),E=_e.useCallback(async()=>{if(g.kind==="conflict")try{await fj(g.state),H.message(c("gitView.integrate.cherryPickAbortedToast")),w&&typeof window<"u"&&window.localStorage.removeItem(w)}finally{const O=await _i({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);h(O?{kind:"ready",plan:O}:{kind:"idle"})}},[g,t,e,b,w,c]),R=_e.useCallback(async()=>{if(g.kind==="conflict")try{const O=await hj(g.state);if(O.kind==="success"){H.success(c("gitView.integrate.cherryPickFinishedToast"));const _=await _i({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);h(_?{kind:"ready",plan:_}:{kind:"idle"}),w&&typeof window<"u"&&window.localStorage.removeItem(w),o?.();return}O.kind==="conflict"&&(h({kind:"conflict",state:O.state,details:O.details}),w&&typeof window<"u"&&window.localStorage.setItem(w,JSON.stringify(O.state)))}catch(O){const _=O instanceof Error?O.message:String(O);H.error(c("gitView.integrate.cherryPickContinueFailedToast"),{description:_})}},[g,t,e,b,o,w,c]);return!t||!e?null:s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(A,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:c("gitView.integrate.title")}),g.kind==="ready"&&g.plan.commits.length>0?s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:c("gitView.integrate.toMoveCount",{count:g.plan.commits.length})}):null]}),s.jsx("div",{className:"flex items-center gap-2",children:g.kind==="loading"||g.kind==="running"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:c("gitView.integrate.moveCommits")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",b]})]}),s.jsx("div",{className:"flex-1"}),s.jsxs(As,{open:m,onOpenChange:u,children:[s.jsx(Is,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"sm",className:"gap-1.5",children:[c("gitView.integrate.target"),s.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:b}),s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),s.jsx(Ps,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(qa,{className:"h-full min-h-0",children:[s.jsx(va,{ref:f,placeholder:c("gitView.branch.searchPlaceholder"),onKeyDown:O=>O.stopPropagation()}),s.jsxs(Ja,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(Ya,{children:c("gitView.branch.empty")}),s.jsx(On,{heading:c("gitView.branch.localBranches"),children:r.map(O=>s.jsx(Pn,{value:O,onSelect:()=>{x(O),N(O),u(!1)},children:O},O))})]})]})})]}),g.kind==="ready"?s.jsx(be,{size:"sm",onClick:()=>{M()},disabled:!y||g.plan.commits.length===0,children:c("gitView.integrate.move")}):g.kind==="loading"?s.jsx(be,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.checking")}):g.kind==="running"?s.jsx(be,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.moving")}):null]}),g.kind==="ready"&&g.plan.commits.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.noCommitsToMove")}),g.kind==="ready"&&g.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:[" (",g.plan.commits.length,")"]})]}),C.length>0&&g.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>v(O=>!O),className:"typography-micro text-muted-foreground hover:text-foreground",children:c(j?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),s.jsxs("div",{className:"space-y-1",children:[(j?C:C.slice(0,5)).map(O=>s.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[s.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:O.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:O.subject||O.sha})]},O.sha)),C.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.previewUnavailable")}),g.plan.commits.length>C.length&&s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c("gitView.integrate.showingFirstCommits",{count:C.length})})]})]}),g.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:g.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:g.state.currentCommit.slice(0,7)})]}),s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[g.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)),g.details.unmergedFiles.length>6&&s.jsx("span",{className:"text-xs text-muted-foreground",children:c("gitView.integrate.moreFiles",{count:g.details.unmergedFiles.length-6})})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(be,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{E()},children:c("gitView.operation.abort")}),s.jsxs(be,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!d,onClick:()=>{S({state:g.state,details:g.details},!1)},children:[s.jsx(A,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.currentSession")]}),s.jsxs(be,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{S({state:g.state,details:g.details},!0)},children:[s.jsx(A,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.newSession")]}),s.jsx(be,{size:"sm",className:"typography-meta",onClick:()=>{R()},children:c("gitView.operation.continue")})]})]})]})]})},xj=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),bj=({currentBranch:t,localBranches:e,remoteBranches:n,branchInfo:r,onCheckout:a,onCreate:i,remotes:o=[],disabled:c=!1})=>{const{t:d}=ft(),[p,m]=l.useState(!1),[u,f]=l.useState(""),[b,x]=l.useState(!1),[y,g]=l.useState(!1),[h,j]=l.useState(""),[v,C]=l.useState(!1),k=l.useRef(null),w=l.useCallback(B=>{B.stopPropagation()},[]),N=o.length>1,I=l.useMemo(()=>xj(h),[h]),T=l.useMemo(()=>{const B=u.toLowerCase();return B?e.filter($=>$.toLowerCase().includes(B)):e},[u,e]),P=l.useMemo(()=>{const B=u.toLowerCase();return B?n.filter($=>$.toLowerCase().includes(B)):n},[u,n]),D=B=>{if(B===t){m(!1);return}a(B),m(!1),f("")},S=()=>{x(!0),setTimeout(()=>k.current?.focus(),50)},M=async()=>{if(!(!I||v)){if(N){g(!0);return}C(!0);try{await i(I,o[0]),j(""),x(!1),m(!1)}finally{C(!1)}}},E=async B=>{if(!(!I||v)){C(!0);try{await i(I,B),j(""),x(!1),g(!1),m(!1)}finally{C(!1)}}},R=()=>{g(!1)},V=()=>{j(""),x(!1),g(!1)};return l.useEffect(()=>{p||(f(""),x(!1),g(!1),j(""))},[p]),s.jsxs(As,{open:p,onOpenChange:m,children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsxs(be,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1",disabled:c,children:[s.jsx(A,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("span",{className:"min-w-0 truncate font-medium text-left",children:t||d("gitView.branch.detachedHead")}),s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),s.jsx(It,{sideOffset:8,children:d("gitView.branch.currentBranchTooltip")})]}),s.jsx(Ps,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:s.jsxs(qa,{className:"h-full min-h-0",children:[s.jsx(va,{placeholder:d("gitView.branch.searchPlaceholder"),value:u,onValueChange:f,onKeyDown:w}),s.jsxs(Ja,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(Ya,{children:d("gitView.branch.empty")}),s.jsx(On,{children:y?s.jsxs("div",{className:"px-2 py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[s.jsx("button",{type:"button",onClick:R,disabled:v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(A,{name:"arrow-left",className:"size-4"})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d("gitView.branch.pushToPrefix")," ",s.jsx("span",{className:"text-foreground font-medium",children:I})," ",d("gitView.branch.pushToSuffix")]})]}),s.jsx("div",{className:"flex flex-col gap-1",children:o.map(B=>s.jsxs("button",{type:"button",onClick:()=>E(B),disabled:v,className:"flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50",children:[s.jsxs("span",{className:"typography-ui-label text-foreground",children:[v?s.jsx(A,{name:"loader-4",className:"inline size-3 mr-1.5 animate-spin"}):null,B.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:B.pushUrl})]},B.name))})]}):b?s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[s.jsx("input",{ref:k,placeholder:d("gitView.branch.newBranchPlaceholder"),value:h,onChange:B=>j(B.target.value),onClick:B=>B.stopPropagation(),onKeyDown:B=>{w(B),B.key==="Enter"?(B.preventDefault(),M()):B.key==="Escape"&&(B.preventDefault(),V())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"button",onClick:M,disabled:!I||v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:v?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"add",className:"size-4"})}),s.jsx("button",{type:"button",onClick:V,disabled:v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(A,{name:"close",className:"size-4"})})]}):s.jsxs(Pn,{onSelect:S,children:[s.jsx(A,{name:"add",className:"size-4"}),s.jsx("span",{children:d("gitView.branch.create")})]})}),s.jsx(_a,{}),s.jsxs(On,{heading:d("gitView.branch.localBranches"),children:[T.map(B=>s.jsxs(Pn,{onSelect:()=>D(B),children:[s.jsxs("span",{className:"flex flex-1 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:B}),(r?.[B]?.ahead||r?.[B]?.behind)&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[r[B].ahead||0," ahead ·"," ",r[B].behind||0," behind"]})]}),t===B&&s.jsx("span",{className:"typography-micro text-primary",children:d("gitView.branch.currentBadge")})]},`local-${B}`)),T.length===0&&s.jsx(Pn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noLocalBranches")})})]}),s.jsx(_a,{}),s.jsxs(On,{heading:d("gitView.branch.remoteBranches"),children:[P.map(B=>s.jsx(Pn,{onSelect:()=>D(B),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:B})},`remote-${B}`)),P.length===0&&s.jsx(Pn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noRemoteBranches")})})]})]})]})})]})},yj=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),vj=({currentBranch:t,onRename:e,showEditButton:n=!0})=>{const{t:r}=ft(),[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 y=yj(o);if(y===t){i(!1);return}p(!0);try{await e(t,y),i(!1),c("")}finally{p(!1)}},b=()=>{i(!1),c("")},x=y=>{y.key==="Enter"?(y.preventDefault(),f()):y.key==="Escape"&&(y.preventDefault(),b())};return a?s.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:y=>{y.preventDefault(),f()},children:[s.jsx(A,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("input",{ref:m,value:o,onChange:y=>c(y.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:r("gitView.branch.namePlaceholder"),onKeyDown:x,autoFocus:!0}),s.jsx("button",{type:"submit",disabled:d,"aria-label":r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),title:r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:d?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:b,disabled:d,"aria-label":r("gitView.branch.renameCancel"),title:r("gitView.branch.renameCancel"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(A,{name:"close",className:"size-4"})})]})}):s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1.5 px-2 py-1 h-8",children:[s.jsx(A,{name:"git-branch",className:"size-4 text-primary shrink-0"}),s.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:t||r("gitView.branch.detachedHead")}),n&&e&&t&&s.jsx(be,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:u,title:r("gitView.branch.renameTitle"),children:s.jsx(A,{name:"edit",className:"size-4"})})]})]})},wj=t=>{const e=ot.c(41),{syncAction:n,remotes:r,onFetch:a,onSync:i,onRemoveRemote:o,disabled:c,removingRemoteName:d,aheadCount:p,behindCount:m,trackingRemoteName:u,hasUncommittedChanges:f}=t,b=r===void 0?[]:r,x=d===void 0?null:d,y=p===void 0?0:p,g=m===void 0?0:m,h=f===void 0?!1:f,{t:j}=ft(),v=l.useRef(!1),C=!!x,k=b.find(ce=>ce.name===u)??b[0],w=g>0&&h,N=c||n!==null||C||!k||w,I=c||n!==null||C||b.length===0,T=y>0||g>0;let P;e[0]!==j?(P=j("gitView.sync.sync"),e[0]=j,e[1]=P):P=e[1];const D=g>0?`↓${g}`:null,S=y>0?`↑${y}`:null;let M;e[2]!==P||e[3]!==D||e[4]!==S?(M=[P,D,S].filter(Boolean),e[2]=P,e[3]=D,e[4]=S,e[5]=M):M=e[5];const E=M.join(" "),R=w?j("gitView.sync.commitOrStashTooltip"):k?T?j("gitView.sync.syncChangesTooltip",{ahead:y,behind:g}):j("gitView.sync.syncChanges"):j("gitView.sync.noRemoteTooltip"),V=()=>{k&&i(k)},B="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")?($=ye("inline-flex h-7 items-center gap-1.5 px-2 typography-ui-label font-medium text-foreground","transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[6]=$):$=e[6];let O;e[7]!==j?(O=j("gitView.sync.syncChanges"),e[7]=j,e[8]=O):O=e[8];let _;e[9]!==n?(_=n==="sync"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=_):_=e[10];let q;e[11]!==E?(q=s.jsx("span",{className:"whitespace-nowrap tabular-nums",children:E}),e[11]=E,e[12]=q):q=e[12];let L;e[13]!==V||e[14]!==N||e[15]!==O||e[16]!==_||e[17]!==q?(L=s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:V,disabled:N,className:$,"aria-label":O,children:[_,q]})}),e[13]=V,e[14]=N,e[15]=O,e[16]=_,e[17]=q,e[18]=L):L=e[18];let J;e[19]!==R?(J=s.jsx(It,{sideOffset:8,children:R}),e[19]=R,e[20]=J):J=e[20];let Z;e[21]!==L||e[22]!==J?(Z=s.jsxs(kt,{children:[L,J]}),e[21]=L,e[22]=J,e[23]=Z):Z=e[23];const ie=As;let ne;e[24]===Symbol.for("react.memo_cache_sentinel")?(ne=ye("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]=ne):ne=e[24];let me;e[25]!==j?(me=j("gitView.sync.moreActionsAria"),e[25]=j,e[26]=me):me=e[26];let pe;e[27]===Symbol.for("react.memo_cache_sentinel")?(pe=s.jsx(A,{name:"arrow-down-s",className:"size-4"}),e[27]=pe):pe=e[27];let G;e[28]!==I||e[29]!==me?(G=s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:ne,disabled:I,"aria-label":me,children:pe})}),e[28]=I,e[29]=me,e[30]=G):G=e[30];const K=Ps,Q="start",W=-40,de="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",ge=b.map(ce=>s.jsx(_t,{onSelect:xe=>{if(v.current){xe.preventDefault(),v.current=!1;return}a(ce)},children:s.jsxs("div",{className:"flex w-full items-center gap-2",children:[s.jsx(A,{name:"refresh",className:"size-4 text-muted-foreground"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:j("gitView.sync.fetchFromRemote",{name:ce.name})}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:ce.fetchUrl})]})}),o&&ce.name!==u?s.jsx(be,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||C,onPointerDown:xe=>{v.current=!0,xe.preventDefault(),xe.stopPropagation()},onClick:xe=>{v.current=!0,xe.preventDefault(),xe.stopPropagation(),o(ce)},"aria-label":j("gitView.header.removeRemoteAria",{name:ce.name}),title:j("gitView.header.removeRemoteTitle",{name:ce.name}),children:x===ce.name?s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(A,{name:"close",className:"size-3.5"})}):null]})},ce.name));let ve;e[31]!==K||e[32]!==ge?(ve=s.jsx(K,{align:Q,alignOffset:W,className:de,children:ge}),e[31]=K,e[32]=ge,e[33]=ve):ve=e[33];let te;e[34]!==ie||e[35]!==G||e[36]!==ve?(te=s.jsxs(ie,{children:[G,ve]}),e[34]=ie,e[35]=G,e[36]=ve,e[37]=te):te=e[37];let he;return e[38]!==Z||e[39]!==te?(he=s.jsxs("div",{className:B,children:[Z,te]}),e[38]=Z,e[39]=te,e[40]=he):he=e[40],he},jj={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},Nj={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 rg(t){return t&&Nj[t]||"var(--primary)"}const Mm=t=>{const e=ot.c(8),{icon:n,className:r,colorToken:a}=t,i=jj[n??"branch"]??"user-3";let o;e[0]!==a?(o=rg(a),e[0]=a,e[1]=o):o=e[1];let c;e[2]!==o?(c={color:o},e[2]=o,e[3]=c):c=e[3];let d;return e[4]!==r||e[5]!==i||e[6]!==c?(d=s.jsx(A,{name:i,className:r,style:c}),e[4]=r,e[5]=i,e[6]=c,e[7]=d):d=e[7],d},ag=t=>{const e=ot.c(35),{activeProfile:n,identities:r,onSelect:a,isApplying:i,iconOnly:o}=t,c=o===void 0?!1:o,{t:d}=ft(),p=i||r.length===0,m=n?.color;let u;e[0]!==m?(u=rg(m),e[0]=m,e[1]=u):u=e[1];let f;e[2]!==u?(f={color:u},e[2]=u,e[3]=f):f=e[3];let b;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==i?(b=i?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(Mm,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=i,e[7]=b):b=e[7];let x;e[8]!==n?.name||e[9]!==c||e[10]!==d?(x=!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]=x):x=e[11];let y;e[12]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=y):y=e[12];let g;e[13]!==p||e[14]!==f||e[15]!==b||e[16]!==x?(g=s.jsx(Ct,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsxs(be,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-[15rem] justify-start gap-1.5 px-2 py-1 typography-ui-label",style:f,disabled:p,children:[b,x,y]})})}),e[13]=p,e[14]=f,e[15]=b,e[16]=x,e[17]=g):g=e[17];let h;e[18]!==d?(h=d("gitView.header.identityTooltip"),e[18]=d,e[19]=h):h=e[19];let j;e[20]!==h?(j=s.jsx(It,{sideOffset:8,children:h}),e[20]=h,e[21]=j):j=e[21];let v;e[22]!==j||e[23]!==g?(v=s.jsxs(kt,{children:[g,j]}),e[22]=j,e[23]=g,e[24]=v):v=e[24];let C;e[25]!==n?.id||e[26]!==r||e[27]!==a||e[28]!==d?(C=r.length===0?s.jsx("div",{className:"px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:d("gitView.header.noProfiles")})}):r.map(N=>{const I=n?.id===N.id;return s.jsx(_t,{onSelect:()=>a(N),children:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(Mm,{icon:N.icon,colorToken:N.color,className:"size-4"}),s.jsxs("span",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:N.name}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:N.userEmail})]}),I?s.jsx(A,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},N.id)}),e[25]=n?.id,e[26]=r,e[27]=a,e[28]=d,e[29]=C):C=e[29];let k;e[30]!==C?(k=s.jsx(Ps,{align:"end",className:"w-64",children:C}),e[30]=C,e[31]=k):k=e[31];let w;return e[32]!==v||e[33]!==k?(w=s.jsxs(As,{children:[v,k]}),e[32]=v,e[33]=k,e[34]=w):w=e[34],w},Sj=t=>{const e=ot.c(49),{status:n,localBranches:r,remoteBranches:a,branchInfo:i,syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,onCheckoutBranch:f,onCreateBranch:b,onRenameBranch:x,activeIdentityProfile:y,availableIdentities:g,onSelectIdentity:h,isApplyingIdentity:j,isWorktreeMode:v,onOpenHistory:C,onOpenStashes:k,actionTabItems:w,activeActionTab:N,onSelectActionTab:I}=t,{t:T}=ft();if(!n)return null;let P;e[0]!==C||e[1]!==k||e[2]!==T?(P=C||k?s.jsxs(As,{children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0","aria-label":T("gitView.history.title"),children:s.jsx(A,{name:"git-repository",className:"size-4"})})})}),s.jsx(It,{sideOffset:8,children:T("gitView.history.title")})]}),s.jsxs(Ps,{align:"end",children:[C?s.jsxs(_t,{onSelect:C,children:[s.jsx(A,{name:"history",className:"size-4"}),T("gitView.history.title")]}):null,k?s.jsxs(_t,{onSelect:k,children:[s.jsx(A,{name:"archive-stack",className:"size-4"}),T("gitView.stashes.title")]}):null]})]}):null,e[0]=C,e[1]=k,e[2]=T,e[3]=P):P=e[3];let D;e[4]!==P?(D=s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:P}),e[4]=P,e[5]=D):D=e[5];const S=D,M=!n;let E;e[6]!==n.tracking?(E=n.tracking?.split("/")[0],e[6]=n.tracking,e[7]=E):E=e[7];const R=(n.files?.length??0)>0;let V;e[8]!==d||e[9]!==m||e[10]!==p||e[11]!==c||e[12]!==u||e[13]!==n.ahead||e[14]!==n.behind||e[15]!==o||e[16]!==M||e[17]!==E||e[18]!==R?(V=s.jsx(wj,{syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,disabled:M,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:E,hasUncommittedChanges:R}),e[8]=d,e[9]=m,e[10]=p,e[11]=c,e[12]=u,e[13]=n.ahead,e[14]=n.behind,e[15]=o,e[16]=M,e[17]=E,e[18]=R,e[19]=V):V=e[19];const B=V;let $;e[20]!==y||e[21]!==g||e[22]!==j||e[23]!==h?($=s.jsx(ag,{activeProfile:y,identities:g,onSelect:h,isApplying:j,iconOnly:!0}),e[20]=y,e[21]=g,e[22]=j,e[23]=h,e[24]=$):$=e[24];const O=$;let _;e[25]!==i||e[26]!==v||e[27]!==r||e[28]!==f||e[29]!==b||e[30]!==x||e[31]!==a||e[32]!==c||e[33]!==n.current?(_=s.jsx("div",{className:"min-w-0 flex-1",children:v?s.jsx(vj,{currentBranch:n.current,onRename:x}):s.jsx(bj,{currentBranch:n.current,localBranches:r,remoteBranches:a,branchInfo:i,onCheckout:f,onCreate:b,remotes:c})}),e[25]=i,e[26]=v,e[27]=r,e[28]=f,e[29]=b,e[30]=x,e[31]=a,e[32]=c,e[33]=n.current,e[34]=_):_=e[34];let q;e[35]!==O||e[36]!==S?(q=s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[S,O]}),e[35]=O,e[36]=S,e[37]=q):q=e[37];let L;e[38]!==_||e[39]!==q?(L=s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[_,q]}),e[38]=_,e[39]=q,e[40]=L):L=e[40];let J;e[41]!==w||e[42]!==N||e[43]!==I||e[44]!==B?(J=w&&N&&I?s.jsxs("div",{className:"mt-3 flex h-8 min-w-0 items-center gap-2",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx(Er,{items:w,activeId:N,onSelect:I,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),s.jsx("div",{className:"shrink-0",children:B})]}):null,e[41]=w,e[42]=N,e[43]=I,e[44]=B,e[45]=J):J=e[45];let Z;return e[46]!==L||e[47]!==J?(Z=s.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[L,J]}),e[46]=L,e[47]=J,e[48]=Z):Z=e[48],Z},kj=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,hasStagedChanges:a=!1,uncommittedFileCount:i,onChanged:o})=>{const{t:c}=ft(),[d,p]=l.useState([]),[m,u]=l.useState(!1),[f,b]=l.useState(""),[x,y]=l.useState(""),[g,h]=l.useState(null),[j,v]=l.useState({}),C=l.useCallback(async()=>{if(n){u(!0);try{const P=await Eb(n);p(P.stashes),v({})}catch(P){H.error(P instanceof Error?P.message:c("gitView.stashes.toast.loadFailed"))}finally{u(!1)}}},[n,c]);l.useEffect(()=>{t&&C()},[C,t]),l.useEffect(()=>{if(!t||!n||d.length===0)return;let P=!1;const D=d.map(S=>S.ref);return Mb(n,D).then(S=>{P||v(S.counts)}).catch(()=>{}),()=>{P=!0}},[n,t,d]);const k=l.useMemo(()=>{const P=f.trim().toLowerCase();return P?d.filter(D=>`${D.ref} ${D.message} ${D.relativeTime}`.toLowerCase().includes(P)):d},[f,d]),w=l.useCallback(async P=>{await C(),await o?.(P)},[C,o]),N=async()=>{if(!(!n||g)){h("create");try{const P=await Rb(n,{message:x.trim()||void 0});P.created?(H.success(c("gitView.stashes.toast.created")),y("")):H.info(c("gitView.stashes.toast.noChanges")),await w({affectsIndex:!!(P.created&&a)})}catch(P){H.error(P instanceof Error?P.message:c("gitView.stashes.toast.createFailed"))}finally{h(null)}}},I=async(P,D)=>{if(!(!n||g)&&!(D==="drop"&&!window.confirm(c("gitView.stashes.confirm.drop",{ref:P.ref})))){h(`${D}:${P.ref}`);try{D==="apply"&&await Fb(n,{ref:P.ref}),D==="pop"&&await Ob(n,{ref:P.ref}),D==="drop"&&await Lb(n,{ref:P.ref});const S=D==="apply"?"gitView.stashes.toast.applySuccess":D==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";H.success(c(S)),await w({affectsIndex:D!=="drop"})}catch(S){const M=D==="apply"?"gitView.stashes.toast.applyFailed":D==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";H.error(S instanceof Error?S.message:c(M)),await w({affectsIndex:D!=="drop"})}finally{h(null)}}},T=g!==null;return s.jsx(us,{open:t,onOpenChange:e,children:s.jsxs(ds,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(hs,{children:[s.jsxs(ms,{className:"flex items-center gap-2",children:[s.jsx(A,{name:"archive-stack",className:"h-5 w-5"}),c("gitView.stashes.title")]}),s.jsx(Ns,{children:c("gitView.stashes.description")})]}),s.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[s.jsx(Lt,{value:x,onChange:P=>y(P.target.value),placeholder:c("gitView.stashes.messagePlaceholder"),disabled:T||!r,className:"flex-1"}),s.jsxs(be,{onClick:N,disabled:!r||T||!n,children:[g==="create"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"inbox-archive",className:"size-4"}),c("gitView.stashes.actions.stashCurrentWithCount",{count:i})]})]}),s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:c("gitView.stashes.includeUntrackedHint")})]}),s.jsxs("div",{className:"relative mt-2",children:[s.jsx(A,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(Lt,{value:f,onChange:P=>b(P.target.value),placeholder:c("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:m?s.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:s.jsx(A,{name:"loader-4",className:"size-5 animate-spin"})}):k.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:c(f?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):k.map((P,D)=>s.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[s.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[s.jsx("p",{className:"typography-small truncate text-foreground",children:P.message||c("gitView.stashes.untitled")}),s.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{children:D===0&&!f.trim()?c("gitView.stashes.latestLabel"):c("gitView.stashes.itemNumber",{number:D+1})})}),s.jsx(It,{sideOffset:6,children:P.ref})]})," · ",P.relativeTime," · ",typeof j[P.ref]=="number"?c("gitView.stashes.fileCount",{count:j[P.ref]}):c("gitView.stashes.fileCountLoading")]})]}),s.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[s.jsx(Dc,{label:c("gitView.stashes.actions.apply"),loading:g===`apply:${P.ref}`,onClick:()=>I(P,"apply"),disabled:T,children:s.jsx(A,{name:"inbox-unarchive",className:"size-4"})}),s.jsx(Dc,{label:c("gitView.stashes.actions.pop"),loading:g===`pop:${P.ref}`,onClick:()=>I(P,"pop"),disabled:T,children:s.jsx(A,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx(Dc,{label:c("gitView.stashes.actions.drop"),loading:g===`drop:${P.ref}`,onClick:()=>I(P,"drop"),disabled:T,destructive:!0,children:s.jsx(A,{name:"delete-bin",className:"size-4"})})]})]},P.ref))})]})})},Dc=t=>{const e=ot.c(17),{label:n,loading:r,disabled:a,destructive:i,onClick:o,children:c}=t,d=r||void 0,p=i?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let m;e[0]!==p?(m=ye("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",p),e[0]=p,e[1]=m):m=e[1];let u;e[2]!==c||e[3]!==r?(u=r?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):c,e[2]=c,e[3]=r,e[4]=u):u=e[4];let f;e[5]!==a||e[6]!==n||e[7]!==o||e[8]!==d||e[9]!==m||e[10]!==u?(f=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":n,"aria-busy":d,className:m,onClick:o,disabled:a,children:u})}),e[5]=a,e[6]=n,e[7]=o,e[8]=d,e[9]=m,e[10]=u,e[11]=f):f=e[11];let b;e[12]!==n?(b=s.jsx(It,{sideOffset:6,children:n}),e[12]=n,e[13]=b):b=e[13];let x;return e[14]!==f||e[15]!==b?(x=s.jsxs(kt,{children:[f,b]}),e[14]=f,e[15]=b,e[16]=x):x=e[16],x},ig={"?":{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"}},Cj=ig.M;function Ij(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 Pj(t){const e=Ij(t);return ig[e]??Cj}const Aj=l.memo(function(e){const n=ot.c(58),{file:r,actionLabel:a,actionSymbol:i,onAction:o,onViewDiff:c,onRevert:d,isReverting:p,stats:m,rowPaddingClassName:u,indentPx:f,actionAtStart:b,showRevert:x}=e,y=f===void 0?0:f,g=b===void 0?!1:b,h=x===void 0?!0:x;let j;n[0]!==r?(j=Pj(r),n[0]=r,n[1]=j):j=n[1];const v=j,{t:C}=ft(),k=v.description,w=m?.insertions??0,N=m?.deletions??0;let I;n[2]!==o||n[3]!==c?(I=W=>{W.key===" "?(W.preventDefault(),o()):W.key==="Enter"&&(W.preventDefault(),c())},n[2]=o,n[3]=c,n[4]=I):I=n[4];const T=I;let P;n[5]!==o?(P=W=>{W.preventDefault(),W.stopPropagation(),o()},n[5]=o,n[6]=P):P=n[6];const D=P;let S;n[7]!==d?(S=W=>{W.preventDefault(),W.stopPropagation(),d()},n[7]=d,n[8]=S):S=n[8];const M=S;let E;n[9]!==a||n[10]!==i||n[11]!==D?(E=s.jsx("button",{type:"button",onClick:D,className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":a,title:a,children:i}),n[9]=a,n[10]=i,n[11]=D,n[12]=E):E=n[12];const R=E,V=`group flex items-center gap-2 py-1.5 hover:bg-sidebar/40 cursor-pointer ${u??"px-3"}`;let B;n[13]!==y?(B=y>0?{paddingLeft:`${y}px`}:void 0,n[13]=y,n[14]=B):B=n[14];const $=g?R:null;let O;n[15]!==v.color?(O={color:v.color},n[15]=v.color,n[16]=O):O=n[16];let _;n[17]!==v.code||n[18]!==k||n[19]!==O?(_=s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:O,title:k,"aria-label":k,children:v.code}),n[17]=v.code,n[18]=k,n[19]=O,n[20]=_):_=n[20];let q;n[21]!==r.path?(q=s.jsx(Ar,{filePath:r.path,className:"h-3.5 w-3.5 shrink-0"}),n[21]=r.path,n[22]=q):q=n[22];let L;if(n[23]!==r.path){e:{const W=r.path.lastIndexOf("/");if(W===-1){let xe;n[25]===Symbol.for("react.memo_cache_sentinel")?(xe={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[25]=xe):xe=n[25],L=s.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:xe,title:r.path,children:r.path});break e}const de=r.path.slice(0,W),ge=r.path.slice(W);let ve;n[26]===Symbol.for("react.memo_cache_sentinel")?(ve={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[26]=ve):ve=n[26];let te;n[27]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx("span",{className:"text-muted-foreground",children:"/"}),n[27]=te):te=n[27];const he=s.jsx("span",{className:"text-foreground",children:ge.slice(1)});let ce;n[28]!==he?(ce=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[te,he]}),n[28]=he,n[29]=ce):ce=n[29],L=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:ve,children:de}),ce]})}n[23]=r.path,n[24]=L}else L=n[24];let J;n[30]===Symbol.for("react.memo_cache_sentinel")?(J={color:"var(--status-success)"},n[30]=J):J=n[30];let Z;n[31]!==w?(Z=s.jsxs("span",{style:J,children:["+",w]}),n[31]=w,n[32]=Z):Z=n[32];let ie,ne;n[33]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),ne={color:"var(--status-error)"},n[33]=ie,n[34]=ne):(ie=n[33],ne=n[34]);let me;n[35]!==N?(me=s.jsxs("span",{style:ne,children:["-",N]}),n[35]=N,n[36]=me):me=n[36];let pe;n[37]!==Z||n[38]!==me?(pe=s.jsxs("span",{className:"shrink-0 typography-micro",children:[Z,ie,me]}),n[37]=Z,n[38]=me,n[39]=pe):pe=n[39];let G;n[40]!==r.path||n[41]!==M||n[42]!==p||n[43]!==h||n[44]!==C?(G=h?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:M,disabled:p,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":C("gitView.changes.revertFileAria",{path:r.path}),children:p?s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(A,{name:"arrow-go-back",className:"size-3.5"})})}),s.jsx(It,{sideOffset:8,children:C("gitView.changes.revertFileTooltip")})]}):null,n[40]=r.path,n[41]=M,n[42]=p,n[43]=h,n[44]=C,n[45]=G):G=n[45];const K=g?null:R;let Q;return n[46]!==T||n[47]!==c||n[48]!==B||n[49]!==$||n[50]!==_||n[51]!==q||n[52]!==L||n[53]!==pe||n[54]!==G||n[55]!==K||n[56]!==V?(Q=s.jsxs("div",{className:V,role:"button",tabIndex:0,onClick:c,onKeyDown:T,style:B,children:[$,_,q,L,pe,G,K]}),n[46]=T,n[47]=c,n[48]=B,n[49]=$,n[50]=_,n[51]=q,n[52]=L,n[53]=pe,n[54]=G,n[55]=K,n[56]=V,n[57]=Q):Q=n[57],Q}),Rm=14,og=t=>t.replace(/\\/g,"/").replace(/^\/+/,"").trim(),Fm=(t,e)=>({id:`dir:${t}`,path:t,name:e,children:new Map,directFiles:[],files:[]}),Dj=t=>{const e=Fm("","");for(const n of t){const r=og(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=Fm(c,d);m.files.push(n),o.children.set(d,m),o=m}}o.directFiles.push(n)}return e},Tj=(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:${og(d.path)}`,kind:"file",depth:i,file:d})};return r(t,0),n},Ej=1e3,Mj=34,Rj=30,$o="pl-0 pr-2",Tc=(t,e)=>`${t} ${e}`,Fj=({groups:t,diffStats:e,revertingPaths:n,isRevertingAll:r=!1,onVisiblePathsChange:a,onRevertAll:i})=>{const{t:o}=ft(),c=l.useRef(null),p=Fe($=>$.gitChangesViewMode)==="tree",m=l.useMemo(()=>t.filter($=>$.entries.length>0),[t]),[u,f]=l.useState(new Set),[b,x]=l.useState(new Set),[y,g]=l.useState(!1),h=l.useMemo(()=>m.map($=>Dj($.entries)),[m]),j=l.useMemo(()=>{const $=[];return m.forEach((O,_)=>{Array.from(h[_]?.children.values()??[]).forEach(q=>{$.push(Tc(O.id,q.path))})}),$},[h,m]);l.useEffect(()=>{p&&x($=>{const O=new Set,_=new Set(j);return $.forEach(q=>{(q.slice(q.indexOf(" ")+1).includes("/")||_.has(q))&&O.add(q)}),j.forEach(q=>O.add(q)),O})},[p,j]);const v=l.useMemo(()=>{const $=[];return m.forEach((O,_)=>{if($.push({type:"header",key:`header:${O.id}`,groupIndex:_}),!u.has(O.id)){if(p){const q=new Set;b.forEach(J=>{J.startsWith(`${O.id} `)&&q.add(J.slice(O.id.length+1))}),Tj(h[_],q).forEach(J=>{J.kind==="file"?$.push({type:"file",key:`${O.id}:${J.key}`,groupIndex:_,file:J.file,depth:J.depth}):$.push({type:"directory",key:`${O.id}:${J.key}`,groupIndex:_,directory:J.directory,depth:J.depth})});return}O.entries.forEach(q=>{$.push({type:"file",key:`${O.id}:file:${q.path}`,groupIndex:_,file:q,depth:0})})}}),i&&m.length>0&&$.push({type:"revert-all",key:"revert-all"}),$},[u,b,p,i,h,m]),C=v.length,k=C>=Ej,w=ih({count:C,getScrollElement:()=>c.current,estimateSize:()=>Mj,overscan:12,enabled:k});l.useEffect(()=>{if(!k)return;const $=c.current;if(!$)return;const O=new ResizeObserver(()=>w.measure());return O.observe($),()=>O.disconnect()},[k,w]);const N=w.getTotalSize(),I=l.useMemo(()=>k&&N>=0?w.getVirtualItems():[],[k,w,N]);l.useEffect(()=>{if(!a)return;const $=O=>O&&O.type==="file"?O.file.path:null;if(C===0){a([]);return}if(!k){const O=[];for(const _ of v)if(_.type==="file"&&(O.push(_.file.path),O.length>=Rj))break;a(O);return}a(I.map(O=>$(v[O.index])).filter(O=>!!O))},[a,C,v,k,I]);const T=l.useCallback($=>{f(O=>{const _=new Set(O);return _.has($)?_.delete($):_.add($),_})},[]),P=l.useCallback(($,O)=>{x(_=>{const q=new Set(_),L=Tc($,O);return q.has(L)?q.delete(L):q.add(L),q})},[]),D=l.useMemo(()=>{const $=new Set;return m.forEach(O=>O.entries.forEach(_=>$.add(_.path))),Array.from($)},[m]),S=D.length,M=l.useCallback(async()=>{!i||r||D.length===0||(await i(D),g(!1))},[D,r,i]),E=l.useCallback(($,O)=>{const _=u.has($.id),q=$.entries.length;return s.jsxs("div",{className:ye("sticky top-0 z-10 flex items-center gap-2 bg-sidebar py-2",$o,!O&&"mt-1 border-t border-border/40"),children:[s.jsx("button",{type:"button",onClick:()=>$.onActionAll($.entries.map(L=>L.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":$.actionAllLabel,title:$.actionAllLabel,children:$.actionSymbol}),s.jsxs("button",{type:"button",onClick:()=>T($.id),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-expanded":!_,children:[s.jsx("h3",{className:"truncate typography-ui-header font-semibold text-foreground",children:$.title}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:q}),s.jsx(A,{name:"arrow-down-s",className:ye("size-3.5 shrink-0 text-muted-foreground transition-transform",_&&"-rotate-90")})]})]})},[u,T]),R=l.useCallback(($,O,_)=>{const q=b.has(Tc($.id,O.path));return s.jsxs("div",{className:ye("group flex items-center gap-2 py-1.5 hover:bg-sidebar/40",$o),style:{paddingLeft:`${_*Rm}px`},children:[s.jsxs("button",{type:"button",onClick:()=>P($.id,O.path),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":q?o("gitView.changes.collapseDirectoryAria",{path:O.path}):o("gitView.changes.expandDirectoryAria",{path:O.path}),children:[q?s.jsx(A,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(A,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:O.path,children:O.name}),s.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:O.files.length})]}),s.jsx("button",{type:"button",onClick:()=>$.onActionAll(O.files.map(L=>L.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":o($.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:O.path}),title:o($.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:O.path}),children:$.actionSymbol})]})},[b,o,P]),V=l.useCallback(($,O)=>{if($.type==="revert-all")return s.jsx("div",{className:ye("flex justify-end py-2",$o),children:s.jsxs(be,{variant:"ghost",size:"sm",onClick:()=>g(!0),disabled:r,className:"gap-1.5 text-[var(--status-error)] hover:bg-[var(--status-error)]/10 hover:text-[var(--status-error)]",children:[s.jsx(A,{name:"arrow-go-back",className:"size-3.5"}),o("gitView.changes.revertAll")]})});const _=m[$.groupIndex];if(!_)return null;if($.type==="header")return E(_,O);if($.type==="directory")return R(_,$.directory,$.depth);const q=$.file;return s.jsx(Aj,{file:q,actionLabel:_.getActionLabel(q.path),actionSymbol:_.actionSymbol,onAction:()=>_.onActionFile(q.path),stats:e?.[q.path],onViewDiff:()=>_.onViewDiff(q.path),onRevert:()=>_.onRevertFile(q.path),isReverting:n.has(q.path)||r,rowPaddingClassName:$o,indentPx:$.depth*Rm,actionAtStart:!p,showRevert:_.showRevertActions!==!1})},[e,r,p,R,E,n,o,m]),B=l.useCallback($=>{const O=v[$],_=v[$-1];return!O||!_||O.type!=="file"&&O.type!=="directory"||_.type!=="file"&&_.type!=="directory"?!1:_.groupIndex===O.groupIndex},[v]);return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-col overflow-hidden",children:[s.jsx(jo,{ref:c,className:"overlay-scrollbar-target overlay-scrollbar-container min-h-0 w-full flex-1 overflow-x-hidden overflow-y-auto",children:k?s.jsx("div",{className:"relative w-full",style:{height:`${w.getTotalSize()}px`},children:I.map($=>{const O=v[$.index];return O?s.jsx("div",{ref:w.measureElement,"data-index":$.index,className:ye("absolute left-0 top-0 w-full",B($.index)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),style:{transform:`translateY(${$.start}px)`},children:V(O,$.index===0)},O.key):null})}):s.jsx("div",{role:"list","aria-label":o("gitView.changes.changedFilesAria"),children:v.map(($,O)=>s.jsx("div",{className:ye("relative",B(O)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:V($,O===0)},$.key))})}),s.jsx($b,{containerRef:c,disableHorizontal:!0})]}),s.jsx(us,{open:y,onOpenChange:$=>{!r&&!$&&g(!1)},children:s.jsxs(ds,{className:"max-w-md",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:o("gitView.changes.revertAllDialogTitle")}),s.jsx(Ns,{children:S===1?o("gitView.changes.revertAllDescriptionSingle",{count:S}):o("gitView.changes.revertAllDescriptionPlural",{count:S})})]}),s.jsxs(_s,{children:[s.jsx(be,{variant:"outline",size:"sm",onClick:()=>g(!1),disabled:r,children:o("gitView.common.cancel")}),s.jsx(be,{variant:"destructive",size:"sm",onClick:()=>{M()},disabled:r,children:o(r?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})})]})},Ec=38,_o=200,Oj=t=>{const e=ot.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}=ft(),f=l.useRef(null),b=Fe(Lj);let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const T=f.current;if(!T)return;const P=document.activeElement===T,D=()=>{T.style.height=`${Ec}px`;const M=T.scrollHeight,E=Math.min(Math.max(M,Ec),_o);T.style.height=`${E}px`,T.style.overflowY=M>_o?"auto":"hidden",M>_o&&!P&&(T.scrollTop=T.scrollHeight)};D();const S=window.requestAnimationFrame(D);return()=>{window.cancelAnimationFrame(S)}},e[0]=x):x=e[0];let y;e[1]!==n?(y=[n],e[1]=n,e[2]=y):y=e[2],l.useLayoutEffect(x,y);let g;e[3]!==r?(g=T=>r(T.target.value),e[3]=r,e[4]=g):g=e[4];let h;e[5]!==a||e[6]!==u?(h=a??u("gitView.commit.messagePlaceholder"),e[5]=a,e[6]=u,e[7]=h):h=e[7];const j=p?"on":"off",v=p?"sentences":"off",C=m||b,k=d&&"opacity-50";let w;e[8]!==k?(w=ye("w-full rounded-lg border border-border/60 bg-surface-elevated px-3 py-2 typography-ui-label text-foreground placeholder:text-muted-foreground","resize-none outline-none transition-[border-color,box-shadow] duration-150","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",k),e[8]=k,e[9]=w):w=e[9];let N;e[10]===Symbol.for("react.memo_cache_sentinel")?(N={minHeight:Ec,maxHeight:_o},e[10]=N):N=e[10];let I;return e[11]!==d||e[12]!==C||e[13]!==w||e[14]!==g||e[15]!==h||e[16]!==j||e[17]!==v||e[18]!==n?(I=s.jsx("textarea",{ref:f,value:n,onChange:g,placeholder:h,rows:1,disabled:d,autoCorrect:j,autoCapitalize:v,spellCheck:C,className:w,style:N}),e[11]=d,e[12]=C,e[13]=w,e[14]=g,e[15]=h,e[16]=j,e[17]=v,e[18]=n,e[19]=I):I=e[19],I};function Lj(t){return t.inputSpellcheckEnabled}const $j=t=>{const e=ot.c(30),{highlights:n,onInsert:r}=t,{t:a}=ft();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(A,{name:"arrow-down",className:"size-4"}),e[9]=m):m=e[9];let u;e[10]!==o||e[11]!==p?(u=s.jsx(Ct,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"icon",className:"size-6",onClick:o,"aria-label":p,children:m})}),e[10]=o,e[11]=p,e[12]=u):u=e[12];let f;e[13]!==a?(f=a("gitView.commit.aiHighlights.insertTooltip"),e[13]=a,e[14]=f):f=e[14];let b;e[15]!==f?(b=s.jsx(It,{sideOffset:8,children:f}),e[15]=f,e[16]=b):b=e[16];let x;e[17]!==u||e[18]!==b?(x=s.jsxs(kt,{children:[u,b]}),e[17]=u,e[18]=b,e[19]=x):x=e[19];let y;e[20]!==d||e[21]!==x?(y=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d,x]}),e[20]=d,e[21]=x,e[22]=y):y=e[22];let g;e[23]!==n?(g=n.map(_j),e[23]=n,e[24]=g):g=e[24];let h;e[25]!==g?(h=s.jsx("ul",{className:"space-y-1",children:g}),e[25]=g,e[26]=h):h=e[26];let j;return e[27]!==y||e[28]!==h?(j=s.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[y,h]}),e[27]=y,e[28]=h,e[29]=j):j=e[29],j};function _j(t,e){return s.jsx("li",{className:"typography-meta text-foreground",children:t},`${t}-${e}`)}const Bj=t=>{const e=ot.c(75),{stagedCount:n,commitMessage:r,onCommitMessageChange:a,generatedHighlights:i,onInsertHighlights:o,onGenerateMessage:c,isGeneratingMessage:d,onCommit:p,onCommitAndPush:m,commitAction:u,hasPendingIndexMutation:f,gitmojiEnabled:b,onOpenGitmojiPicker:x}=t,y=f===void 0?!1:f,{t:g}=ft(),h=n>0;let j;e[0]!==u||e[1]!==r||e[2]!==y||e[3]!==h?(j=r.trim()&&h&&u===null&&!y,e[0]=u,e[1]=r,e[2]=y,e[3]=h,e[4]=j):j=e[4];const v=j,{isMobile:C,hasTouchInput:k}=ln();let w;e[5]!==g?(w=g("gitView.commit.title"),e[5]=g,e[6]=w):w=e[6];let N;e[7]!==w?(N=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:w}),e[7]=w,e[8]=N):N=e[8];let I;e[9]!==h||e[10]!==g?(I=h?null:s.jsx("span",{className:"min-w-0 truncate typography-meta text-muted-foreground",children:g("gitView.commit.stageFilesHint")}),e[9]=h,e[10]=g,e[11]=I):I=e[11];let T;e[12]!==N||e[13]!==I?(T=s.jsxs("div",{className:"flex w-full items-baseline gap-2 px-0 pt-2 pb-1",children:[N,I]}),e[12]=N,e[13]=I,e[14]=T):T=e[14];let P;e[15]!==i||e[16]!==o?(P=s.jsx($j,{highlights:i,onInsert:o}),e[15]=i,e[16]=o,e[17]=P):P=e[17];let D;e[18]!==g?(D=g("gitView.commit.messagePlaceholder"),e[18]=g,e[19]=D):D=e[19];const S=u!==null;let M;e[20]!==r||e[21]!==k||e[22]!==C||e[23]!==a||e[24]!==D||e[25]!==S?(M=s.jsx(Oj,{value:r,onChange:a,placeholder:D,disabled:S,hasTouchInput:k,isMobile:C}),e[20]=r,e[21]=k,e[22]=C,e[23]=a,e[24]=D,e[25]=S,e[26]=M):M=e[26];let E;e[27]!==b||e[28]!==x||e[29]!==g?(E=b&&s.jsxs(be,{variant:"outline",size:"sm",onClick:x,className:"w-fit",type:"button",children:[s.jsx(A,{name:"emotion-happy",className:"size-4"}),g("gitView.commit.addGitmoji")]}),e[27]=b,e[28]=x,e[29]=g,e[30]=E):E=e[30];const R=d||u!==null||y||n===0;let V;e[31]!==g?(V=g("gitView.commit.generateAria"),e[31]=g,e[32]=V):V=e[32];let B;e[33]!==d?(B=d?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"ai-generate-2",className:"size-4 text-primary"}),e[33]=d,e[34]=B):B=e[34];let $;e[35]!==g?($=g("gitView.commit.generate"),e[35]=g,e[36]=$):$=e[36];let O;e[37]!==$?(O=s.jsx("span",{className:"commit-actions__label",children:$}),e[37]=$,e[38]=O):O=e[38];let _;e[39]!==c||e[40]!==R||e[41]!==V||e[42]!==B||e[43]!==O?(_=s.jsxs(be,{variant:"outline",size:"sm",onClick:c,disabled:R,type:"button","aria-label":V,className:"commit-actions__btn",children:[B,O]}),e[39]=c,e[40]=R,e[41]=V,e[42]=B,e[43]=O,e[44]=_):_=e[44];let q;e[45]===Symbol.for("react.memo_cache_sentinel")?(q=s.jsx("div",{className:"flex-1"}),e[45]=q):q=e[45];const L=!v||d;let J;e[46]!==g?(J=g("gitView.commit.commitAria"),e[46]=g,e[47]=J):J=e[47];let Z;e[48]!==u||e[49]!==g?(Z=u==="commit"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:g("gitView.commit.committing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"git-commit",className:"size-4"}),s.jsx("span",{className:"commit-actions__label",children:g("gitView.commit.commit")})]}),e[48]=u,e[49]=g,e[50]=Z):Z=e[50];let ie;e[51]!==p||e[52]!==L||e[53]!==J||e[54]!==Z?(ie=s.jsx(be,{size:"sm",variant:"outline",onClick:p,disabled:L,className:"commit-actions__btn whitespace-nowrap","aria-label":J,children:Z}),e[51]=p,e[52]=L,e[53]=J,e[54]=Z,e[55]=ie):ie=e[55];let ne;e[56]!==v||e[57]!==u||e[58]!==d||e[59]!==C||e[60]!==m||e[61]!==g?(ne=C?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(be,{variant:"default",size:"sm",onClick:()=>m(),disabled:!v||d,className:"h-7 w-7 p-0","aria-label":g("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"arrow-up",className:"size-3.5"})})}),s.jsx(It,{side:"top",children:s.jsx("p",{children:g("gitView.commit.push")})})]}):s.jsx(be,{size:"sm",variant:"default",onClick:()=>m(),disabled:!v||d,className:"commit-actions__btn","aria-label":g("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:g("gitView.commit.pushing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"arrow-up",className:"size-3.5"}),s.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:g("gitView.commit.push")})]})}),e[56]=v,e[57]=u,e[58]=d,e[59]=C,e[60]=m,e[61]=g,e[62]=ne):ne=e[62];let me;e[63]!==_||e[64]!==ie||e[65]!==ne?(me=s.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[_,q,ie,ne]}),e[63]=_,e[64]=ie,e[65]=ne,e[66]=me):me=e[66];let pe;e[67]!==M||e[68]!==E||e[69]!==me||e[70]!==P?(pe=s.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[P,M,E,me]}),e[67]=M,e[68]=E,e[69]=me,e[70]=P,e[71]=pe):pe=e[71];let G;return e[72]!==pe||e[73]!==T?(G=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[T,pe]}),e[72]=pe,e[73]=T,e[74]=G):G=e[74],G},Vj=t=>{const e=ot.c(16),{onOpenStashes:n}=t,{t:r}=ft();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(A,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=a):a=e[0];let i;e[1]!==r?(i=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=i):i=e[2];let o;e[3]!==i?(o=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:i}),e[3]=i,e[4]=o):o=e[4];let c;e[5]!==r?(c=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=c):c=e[6];let d;e[7]!==c?(d=s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:c}),e[7]=c,e[8]=d):d=e[8];let p;e[9]!==n||e[10]!==r?(p=n?s.jsxs(be,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(A,{name:"archive-stack",className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=p):p=e[11];let m;return e[12]!==o||e[13]!==d||e[14]!==p?(m=s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[a,o,d,p]}),e[12]=o,e[13]=d,e[14]=p,e[15]=m):m=e[15],m};function lg(t){const e=ot.c(63),{draft:n,onEdit:r,onDelete:a,className:i,maxWidth:o}=t,{t:c}=ft(),p=Xl()?.currentTheme,[m,u]=_e.useState(!1),f=typeof n.text=="string"?n.text:"";let b;e[0]!==f?(b=f.length>150||f.split(`
|
|
7
|
-
`).length>3,e[0]=f,e[1]=b):b=e[1];const x=b;let y;e[2]!==i?(y=ye("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden transition-all duration-200",i),e[2]=i,e[3]=y):y=e[3];const g=p?.colors?.surface?.elevated,h=p?.colors?.interactive?.border,j=o?`${Math.max(200,Math.floor(o))}px`:void 0;let v;e[4]!==g||e[5]!==h||e[6]!==j?(v={backgroundColor:g,borderColor:h,maxWidth:j},e[4]=g,e[5]=h,e[6]=j,e[7]=v):v=e[7];let C;e[8]!==n.fileLabel?(C=s.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),e[8]=n.fileLabel,e[9]=C):C=e[9];let k;e[10]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx("span",{children:"•"}),e[10]=k):k=e[10];let w;e[11]!==n.endLine||e[12]!==n.startLine||e[13]!==c?(w=c("inlineComment.range.lines",{start:n.startLine,end:n.endLine}),e[11]=n.endLine,e[12]=n.startLine,e[13]=c,e[14]=w):w=e[14];let N;e[15]!==w?(N=s.jsx("span",{children:w}),e[15]=w,e[16]=N):N=e[16];let I;e[17]!==n.side?(I=n.side&&s.jsxs("span",{children:["(",n.side,")"]}),e[17]=n.side,e[18]=I):I=e[18];let T;e[19]!==N||e[20]!==I||e[21]!==C?(T=s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[C,k,N,I]}),e[19]=N,e[20]=I,e[21]=C,e[22]=T):T=e[22];const P=m||!x,D=!m&&x&&"line-clamp-3";let S;e[23]!==D?(S=ye("text-sm whitespace-pre-wrap break-words leading-relaxed",D),e[23]=D,e[24]=S):S=e[24];let M;e[25]!==f||e[26]!==S?(M=s.jsx("div",{className:S,children:f}),e[25]=f,e[26]=S,e[27]=M):M=e[27];let E;e[28]!==x||e[29]!==m||e[30]!==c?(E=x&&s.jsx(Mr,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"h-6 px-0 mt-1 text-xs text-muted-foreground hover:text-foreground w-full justify-start",children:m?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"arrow-up-s",className:"size-3 mr-1"}),c("inlineComment.actions.showLess")]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"arrow-down-s",className:"size-3 mr-1"}),c("inlineComment.actions.showMore")]})})}),e[28]=x,e[29]=m,e[30]=c,e[31]=E):E=e[31];let R;e[32]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(wr,{}),e[32]=R):R=e[32];let V;e[33]!==P||e[34]!==M||e[35]!==E?(V=s.jsxs(vr,{open:P,onOpenChange:u,children:[M,E,R]}),e[33]=P,e[34]=M,e[35]=E,e[36]=V):V=e[36];let B;e[37]!==T||e[38]!==V?(B=s.jsxs("div",{className:"flex-1 min-w-0",children:[T,V]}),e[37]=T,e[38]=V,e[39]=B):B=e[39];let $;e[40]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(Is,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"more",className:"size-4"})})}),e[40]=$):$=e[40];let O;e[41]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(A,{name:"edit",className:"size-4 mr-2"}),e[41]=O):O=e[41];let _;e[42]!==c?(_=c("inlineComment.actions.editComment"),e[42]=c,e[43]=_):_=e[43];let q;e[44]!==r||e[45]!==_?(q=s.jsxs(_t,{onClick:r,children:[O,_]}),e[44]=r,e[45]=_,e[46]=q):q=e[46];let L;e[47]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(A,{name:"delete-bin",className:"size-4 mr-2"}),e[47]=L):L=e[47];let J;e[48]!==c?(J=c("inlineComment.actions.deleteComment"),e[48]=c,e[49]=J):J=e[49];let Z;e[50]!==a||e[51]!==J?(Z=s.jsxs(_t,{onClick:a,className:"text-destructive",children:[L,J]}),e[50]=a,e[51]=J,e[52]=Z):Z=e[52];let ie;e[53]!==q||e[54]!==Z?(ie=s.jsxs(As,{children:[$,s.jsxs(Ps,{align:"end",children:[q,Z]})]}),e[53]=q,e[54]=Z,e[55]=ie):ie=e[55];let ne;e[56]!==B||e[57]!==ie?(ne=s.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[B,ie]}),e[56]=B,e[57]=ie,e[58]=ne):ne=e[58];let me;return e[59]!==y||e[60]!==ne||e[61]!==v?(me=s.jsx("div",{className:y,style:v,"data-comment-card":"true",children:ne}),e[59]=y,e[60]=ne,e[61]=v,e[62]=me):me=e[62],me}function Ll(t){const e=ot.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}=ft(),x=Xl()?.currentTheme,{isMobile:y}=ln(),[g,h]=l.useState(m),j=_e.useRef(null),v=_e.useRef(o);let C,k;e[0]!==o?(C=()=>{o&&(v.current=o)},k=[o],e[0]=o,e[1]=C,e[2]=k):(C=e[1],k=e[2]),_e.useEffect(C,k);const w=qj,N=w(o);let I,T;e[3]!==y?(I=()=>{const xe=j.current;if(!xe)return;const se=xe.closest(".overlay-scrollbar-container"),ue=se?.scrollTop??window.scrollY,Y=se?.scrollLeft??window.scrollX;if(y){xe.scrollIntoView({behavior:"auto",block:"nearest"});try{xe.focus({preventScroll:!0})}catch{xe.focus()}return}try{xe.focus({preventScroll:!0})}catch{xe.focus()}const Se=xe.value.length;try{xe.setSelectionRange(Se,Se)}catch{}requestAnimationFrame(()=>{se?(se.scrollTop=ue,se.scrollLeft=Y):window.scrollTo({top:ue,left:Y})})},T=[y],e[3]=y,e[4]=I,e[5]=T):(I=e[4],T=e[5]),_e.useEffect(I,T);let P;e[6]!==a||e[7]!==r||e[8]!==g?(P=xe=>{(xe.metaKey||xe.ctrlKey)&&xe.key==="Enter"?(xe.preventDefault(),g.trim()&&r(g,w(v.current))):xe.key==="Escape"&&(xe.preventDefault(),a())},e[6]=a,e[7]=r,e[8]=g,e[9]=P):P=e[9];const D=P;let S;e[10]!==r||e[11]!==g?(S=xe=>{xe.stopPropagation(),g.trim()&&r(g,w(v.current))},e[10]=r,e[11]=g,e[12]=S):S=e[12];const M=S;let E;e[13]!==d?(E=ye("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]=E):E=e[14];const R=x?.colors?.surface?.elevated,V=x?.colors?.interactive?.border,B=p?`${Math.max(200,Math.floor(p))}px`:void 0;let $;e[15]!==R||e[16]!==V||e[17]!==B?($={backgroundColor:R,borderColor:V,maxWidth:B},e[15]=R,e[16]=V,e[17]=B,e[18]=$):$=e[18];const O="true",_=Gj,q=Hj,L="p-3",J=(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:"•"}),N&&s.jsx("span",{children:f("inlineComment.range.lines",{start:N.start,end:N.end})})]});let Z;e[19]===Symbol.for("react.memo_cache_sentinel")?(Z=xe=>h(xe.target.value),e[19]=Z):Z=e[19];let ie;e[20]!==f?(ie=f("inlineComment.input.placeholder"),e[20]=f,e[21]=ie):ie=e[21];let ne;e[22]!==D||e[23]!==ie||e[24]!==g?(ne=s.jsx(un,{simple:!0,ref:j,value:g,onChange:Z,onKeyDown:D,placeholder:ie,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]=D,e[23]=ie,e[24]=g,e[25]=ne):ne=e[25];let me;e[26]!==f?(me=f("inlineComment.actions.cancel"),e[26]=f,e[27]=me):me=e[27];let pe;e[28]!==a||e[29]!==me?(pe=s.jsx(be,{variant:"ghost",size:"sm",onClick:a,onPointerDown:Kj,onTouchStart:Wj,className:"h-8 text-muted-foreground hover:text-foreground",children:me}),e[28]=a,e[29]=me,e[30]=pe):pe=e[30];let G;e[31]!==g?(G=g.trim(),e[31]=g,e[32]=G):G=e[32];const K=!G,Q=x?.colors?.status?.success,W=x?.colors?.status?.successForeground;let de;e[33]!==Q||e[34]!==W?(de={backgroundColor:Q,color:W},e[33]=Q,e[34]=W,e[35]=de):de=e[35];let ge;e[36]!==u||e[37]!==f?(ge=f(u?"inlineComment.actions.save":"inlineComment.actions.comment"),e[36]=u,e[37]=f,e[38]=ge):ge=e[38];let ve;e[39]!==M||e[40]!==K||e[41]!==de||e[42]!==ge?(ve=s.jsx(be,{size:"sm",onClick:M,onPointerDown:Uj,onTouchStart:zj,disabled:K,className:"h-8 min-w-[80px]",style:de,children:ge}),e[39]=M,e[40]=K,e[41]=de,e[42]=ge,e[43]=ve):ve=e[43];let te;e[44]!==pe||e[45]!==ve?(te=s.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[pe,ve]}),e[44]=pe,e[45]=ve,e[46]=te):te=e[46];let he;e[47]!==J||e[48]!==ne||e[49]!==te?(he=s.jsxs("div",{className:L,children:[J,ne,te]}),e[47]=J,e[48]=ne,e[49]=te,e[50]=he):he=e[50];let ce;return e[51]!==$||e[52]!==_||e[53]!==q||e[54]!==he||e[55]!==E?(ce=s.jsx("div",{className:E,style:$,"data-comment-input":O,onPointerDown:_,onTouchStart:q,children:he}),e[51]=$,e[52]=_,e[53]=q,e[54]=he,e[55]=E,e[56]=ce):ce=e[56],ce}function zj(t){return t.stopPropagation()}function Uj(t){return t.stopPropagation()}function Wj(t){return t.stopPropagation()}function Kj(t){return t.stopPropagation()}function Hj(t){return t.stopPropagation()}function Gj(t){return t.stopPropagation()}function qj(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 Jj=t=>{const e=Math.min(t.startLine,t.endLine),n=Math.max(t.startLine,t.endLine);return{...t,startLine:e,endLine:n}},$l=t=>{const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}};function uu(t){const e=ot.c(40),{t:n}=ft(),{source:r,fileLabel:a,language:i,getCodeForRange:o,toStoreRange:c,fromDraftRange:d}=t,p=$t(t0),m=$t(e0),u=pi(Zj),f=pi(Xj),b=pi(Qj),x=pi(Yj),[y,g]=l.useState(null),[h,j]=l.useState(""),[v,C]=l.useState(null),k=p??(m?"draft":null);let w;e:{if(!k||!a){let L;e[0]===Symbol.for("react.memo_cache_sentinel")?(L=[],e[0]=L):L=e[0],w=L;break e}let O;e[1]!==x||e[2]!==k?(O=x[k]??[],e[1]=x,e[2]=k,e[3]=O):O=e[3];const _=O;let q;if(e[4]!==a||e[5]!==_||e[6]!==r){let L;e[8]!==a||e[9]!==r?(L=J=>J.source===r&&J.fileLabel===a,e[8]=a,e[9]=r,e[10]=L):L=e[10],q=_.filter(L),e[4]=a,e[5]=_,e[6]=r,e[7]=q}else q=e[7];w=q}const N=w;let I;e[11]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{g(null),j(""),C(null)},e[11]=I):I=e[11];const T=I;let P;e[12]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{T()},e[12]=P):P=e[12];const D=P;let S;e[13]!==d?(S=O=>{const _=$l(d(O));g(_),j(O.text),C(O.id)},e[13]=d,e[14]=S):S=e[14];const M=S;let E;e[15]!==v||e[16]!==b?(E=O=>{b(O.sessionKey,O.id),v===O.id&&T()},e[15]=v,e[16]=b,e[17]=E):E=e[17];const R=E;let V;e[18]!==u||e[19]!==v||e[20]!==a||e[21]!==o||e[22]!==i||e[23]!==y||e[24]!==k||e[25]!==r||e[26]!==n||e[27]!==c||e[28]!==f?(V=(O,_)=>{const q=_??y,L=O.trim();if(!q||!L||!a)return;if(!k){H.error(n("inlineComment.toast.selectSessionToSave"));return}const J=$l(q),Z=Jj(c(J)),ie=o(J);v?f(k,v,{fileLabel:a,startLine:Z.startLine,endLine:Z.endLine,side:Z.side,code:ie,language:i,text:L}):u({sessionKey:k,source:r,fileLabel:a,startLine:Z.startLine,endLine:Z.endLine,side:Z.side,code:ie,language:i,text:L}),T()},e[18]=u,e[19]=v,e[20]=a,e[21]=o,e[22]=i,e[23]=y,e[24]=k,e[25]=r,e[26]=n,e[27]=c,e[28]=f,e[29]=V):V=e[29];const B=V;let $;return e[30]!==h||e[31]!==R||e[32]!==N||e[33]!==v||e[34]!==d||e[35]!==B||e[36]!==y||e[37]!==k||e[38]!==M?($={sessionKey:k,drafts:N,selection:y,setSelection:g,commentText:h,setCommentText:j,editingDraftId:v,setEditingDraftId:C,reset:T,cancel:D,startEdit:M,deleteDraft:R,saveComment:B,fromDraftRange:d},e[30]=h,e[31]=R,e[32]=N,e[33]=v,e[34]=d,e[35]=B,e[36]=y,e[37]=k,e[38]=M,e[39]=$):$=e[39],$}function Yj(t){return t.drafts}function Qj(t){return t.removeDraft}function Xj(t){return t.updateDraft}function Zj(t){return t.addDraft}function e0(t){return t.newSessionDraft?.open}function t0(t){return t.currentSessionId}function cg(t){const{drafts:e,editingDraftId:n,commentText:r,selection:a,isDragging:i,fileLabel:o,newWidgetId:c,mapDraftToRange:d,onSave:p,onCancel:m,onEdit:u,onDelete:f}=t,b=[];for(const x of e){const y=d(x);if(x.id===n){b.push({afterLine:y.end,id:`edit-${x.id}`,content:s.jsx(Ll,{initialText:r,fileLabel:o,lineRange:y,isEditing:!0,onSave:p,onCancel:m},`edit-${x.id}`)});continue}b.push({afterLine:y.end,id:`card-${x.id}`,content:s.jsx(lg,{draft:x,onEdit:()=>u(x),onDelete:()=>f(x)},`card-${x.id}`)})}if(a&&!n&&!i){const x={...a,start:Math.min(a.start,a.end),end:Math.max(a.start,a.end)};b.push({afterLine:x.end,id:c,content:s.jsx(Ll,{initialText:r,fileLabel:o,lineRange:x,isEditing:!1,onSave:p,onCancel:m},c)})}return b}const ml=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}`},s0=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 n0(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 Om(t){if(!(!t||t<=0))return Math.max(200,Math.floor(t))}function r0(t){const{diffRootRef:e,drafts:n,selection:r,editingDraftId:a,commentText:i,fileLabel:o,onSave:c,onCancel:d,onEdit:p,onDelete:m}=t,[u,f]=l.useState(0),[b,x]=l.useState(null),y=l.useMemo(()=>!r||a?null:ml({type:"new",selection:r}),[a,r]),g=l.useMemo(()=>{const v=n.map(C=>ml({type:C.id===a?"edit":"saved",draft:C}));return y&&v.push(y),v},[n,a,y]),h=l.useCallback(v=>{const C=e.current;if(!C)return null;const k=C.querySelector("diffs-container");if(!(k instanceof HTMLElement))return null;const w=k.querySelector(`[data-annotation-id="${v}"]`);if(w instanceof HTMLElement)return w;const N=k.shadowRoot;return N?N.querySelector(`[data-annotation-id="${v}"]`):null},[e]);l.useEffect(()=>{if(g.length===0)return;let v=!1,C=0;const k=12,w=()=>{v||g.every(I=>!!h(I))||C>=k||(C+=1,requestAnimationFrame(()=>{v||(f(I=>I+1),w())}))};return w(),()=>{v=!0}},[g,h]),l.useEffect(()=>{const v=e.current;if(!v)return;const C=()=>{const w=getComputedStyle(v),N=n0(w.getPropertyValue("--oc-context-panel-width")),I=v.getBoundingClientRect(),T=N??I.width;x(T>0?T:null)};C();const k=new ResizeObserver(()=>{C()});return k.observe(v),window.addEventListener("resize",C),()=>{k.disconnect(),window.removeEventListener("resize",C)}},[e]);const j=l.useCallback(v=>{const k=e.current?.getBoundingClientRect(),w=v.closest("[data-annotation-content]"),N=w instanceof HTMLElement?w.getBoundingClientRect():v.getBoundingClientRect(),I=[N.width];k&&I.push(k.right-N.left);const T=I.filter(P=>Number.isFinite(P)&&P>0);return T.length>0?Om(Math.min(...T)):Om(b)},[e,b]);return s.jsxs(s.Fragment,{children:[n.map(v=>{const C=ml({type:v.id===a?"edit":"saved",draft:v}),k=h(C);if(!k)return null;const w=j(k);return v.id===a?sl.createPortal(s.jsx(Ll,{initialText:i,fileLabel:o,lineRange:{start:v.startLine,end:v.endLine,side:v.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:d,maxWidth:w}),k,`draft-edit-${v.id}`):sl.createPortal(s.jsx(lg,{draft:v,onEdit:()=>p(v),onDelete:()=>m(v),maxWidth:w}),k,`draft-card-${v.id}`)}),r&&!a&&y&&(()=>{const v=h(y);if(!v)return null;const C=j(v);return sl.createPortal(s.jsx(Ll,{initialText:i,fileLabel:o,lineRange:r,isEditing:!1,onSave:c,onCancel:d,maxWidth:C}),v,y)})()]})}function a0(){return new Worker(Nx,{type:"module"})}const i0=["typescript","javascript","tsx","jsx","json","markdown"],Sd={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let Lm,$m;const _m=t=>{const e=Sd[t],n=new Sx({workerFactory:a0,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:i0,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},o0=t=>{if(!(typeof window>"u"))return t==="split"?($m??=_m("split"),$m):(Lm??=_m("unified"),Lm)},l0=t=>{const e=ot.c(7),{children:n,renderTheme:r}=t,a=kd("unified"),i=kd("split");let o,c;e[0]!==r||e[1]!==i||e[2]!==a?(o=()=>{a&&a.setRenderOptions({theme:r,lineDiffType:Sd.unified.lineDiffType}),i&&i.setRenderOptions({theme:r,lineDiffType:Sd.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]),_e.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},c0=t=>{const e=ot.c(11),{children:n}=t,r=Xl();let a,i;if(e[0]!==r?.availableThemes||e[1]!==r?.darkThemeId||e[2]!==r?.lightThemeId){const p=Ni(!1),m=Ni(!0),u=r?.lightThemeId??p.metadata.id,f=r?.darkThemeId??m.metadata.id;i=r?.availableThemes.find(b=>b.metadata.id===u)??p,a=r?.availableThemes.find(b=>b.metadata.id===f)??m,Si(i),Si(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(l0,{renderTheme:c,children:n}),e[8]=n,e[9]=c,e[10]=d):d=e[10],d},kd=t=>{const e=ot.c(2),n=t===void 0?"unified":t;let r;return e[0]!==n?(r=o0(n),e[0]=n,e[1]=r):r=e[1],r},d0=5e5,u0=`
|
|
8
|
-
:host {
|
|
9
|
-
font-family: var(--font-mono);
|
|
10
|
-
font-size: var(--text-code);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
pre, [data-code] {
|
|
14
|
-
font-family: var(--font-mono);
|
|
15
|
-
font-size: var(--text-code);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/* Mobile touch selection support */
|
|
19
|
-
[data-line-number] {
|
|
20
|
-
touch-action: manipulation;
|
|
21
|
-
-webkit-tap-highlight-color: transparent;
|
|
22
|
-
cursor: pointer;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/* Ensure interactive line numbers work on touch */
|
|
26
|
-
pre[data-interactive-line-numbers] [data-line-number] {
|
|
27
|
-
touch-action: manipulation;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
[data-diff-header],
|
|
31
|
-
[data-diff] {
|
|
32
|
-
[data-separator] {
|
|
33
|
-
height: 24px !important;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
`;function m0(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 Bm(t){const e=t.length>400?`${t.slice(0,200)}${t.slice(-200)}`:t;return`${t.length}:${m0(e)}`}const p0=(t,e,n)=>{const i=(n.side==="deletions"?t:e).split(`
|
|
37
|
-
`),o=Math.min(n.start,n.end),c=Math.max(n.start,n.end),d=Math.max(1,o),p=Math.min(i.length,c);return d>p?"":i.slice(d-1,p).join(`
|
|
38
|
-
`)},f0=(t,e)=>t===e?!0:!t||!e?!1:t.start===e.start&&t.end===e.end&&t.side===e.side,Bo=new WeakMap,h0={lineHeight:24,hunkSeparatorHeight:24,fileGap:0};function g0(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 x0(t){if(typeof document>"u")return null;const e=g0(t);let n=Bo.get(e.key);if(!n){const a=new Ix;a.setup(e.root,e.content),n={virtualizer:a,refs:0},Bo.set(e.key,n)}n.refs+=1;let r=!1;return{virtualizer:n.virtualizer,release:()=>{if(r)return;r=!0;const a=Bo.get(e.key);a&&(a.refs-=1,!(a.refs>0)&&(a.virtualizer.cleanUp(),Bo.delete(e.key)))}}}const mu=({original:t,modified:e,language:n,fileName:r,renderSideBySide:a,wrapLines:i,layout:o="fill"})=>{const c=Xl(),d=c?.currentTheme.metadata.variant==="dark",p=c?.availableThemes.find(Q=>Q.metadata.id===c.lightThemeId)??Ni(!1),m=c?.availableThemes.find(Q=>Q.metadata.id===c.darkThemeId)??Ni(!0),{isMobile:u}=ln(),f=uu({source:"diff",fileLabel:r||"unknown",language:n,getCodeForRange:Q=>p0(t,e,Q),toStoreRange:Q=>({startLine:Q.start,endLine:Q.end,side:Q.side==="deletions"?"original":"modified"}),fromDraftRange:Q=>({start:Q.startLine,end:Q.endLine,side:Q.side==="original"?"deletions":"additions"})}),{drafts:b,selection:x,setSelection:y,commentText:g,setCommentText:h,editingDraftId:j,saveComment:v,cancel:C,startEdit:k,deleteDraft:w}=f,N=_e.useRef(null),I=_e.useRef(null),T=_e.useRef(!1),P=_e.useRef(null);_e.useEffect(()=>{N.current=x},[x]),_e.useEffect(()=>{I.current=j},[j]);const D=_e.useCallback(Q=>{if(T.current)return;const W=N.current;if(u&&W&&Q&&Q.side===W.side){const de=Math.min(W.start,Q.start),ge=Math.max(W.end,Q.end);y({...Q,start:de,end:ge})}else y(Q);Q&&(I.current||h(""))},[u,h,y]),S=_e.useCallback(()=>{C()},[C]),M=_e.useCallback(Q=>{const W=document.createElement("div");W.style.position="relative";const de=ml(Q.metadata);return W.dataset.annotationId=de,W.dataset.annotationSide=Q.side,W.dataset.annotationLine=String(Q.lineNumber),W},[]),E=_e.useCallback((Q,W)=>{v(Q,W??x??void 0)},[v,x]),R=_e.useCallback(Q=>{y(Q);const W=_.current;if(W)try{T.current=!0,W.setSelectedLines(Q),P.current=Q}catch{}finally{T.current=!1}},[y]),V=_e.useCallback(Q=>{const W=Q.closest("[data-line-type]")?.getAttribute("data-line-type")??Q.getAttribute("data-line-type");if(W==="change-deletion")return"deletions";if(W==="change-addition")return"additions";const de=Q.getAttribute("data-column-side")??Q.getAttribute("data-side")??Q.closest("[data-column-side]")?.getAttribute("data-column-side");if(de==="deletions"||de==="left"||de==="original")return"deletions";if(de==="additions"||de==="right"||de==="modified")return"additions";const ge=Q.closest("[data-line-type]");if(ge instanceof HTMLElement){const ve=ge.getBoundingClientRect(),te=Q.getBoundingClientRect(),he=ve.left+ve.width/2;return te.left+te.width/2<he?"deletions":"additions"}return"additions"},[]);Si(p),Si(m);const B=`${p.metadata.id}:${m.metadata.id}:${d?"dark":"light"}`,$=_e.useRef(null),O=_e.useRef(null),_=_e.useRef(null),q=_e.useRef(null),[,L]=l.useReducer(Q=>Q+1,0),J=kd(a?"split":"unified"),Z=_e.useMemo(()=>Uu(p),[p]),ie=_e.useMemo(()=>Uu(m),[m]);l.useLayoutEffect(()=>{const Q=$.current;if(!Q)return;const W=Q.querySelector("diffs-container");if(!W)return;const de=d?ie:Z,ge=(Ce,Ie)=>Ce.colors?.[Ie],ve=ge(Z,"terminal.ansiGreen"),te=ge(Z,"terminal.ansiRed"),he=ge(Z,"terminal.ansiBlue"),ce=ge(ie,"terminal.ansiGreen"),xe=ge(ie,"terminal.ansiRed"),se=ge(ie,"terminal.ansiBlue");W.style.setProperty("--shiki-light",Z.fg),W.style.setProperty("--shiki-light-bg",Z.bg),ve&&W.style.setProperty("--shiki-light-addition-color",ve),te&&W.style.setProperty("--shiki-light-deletion-color",te),he&&W.style.setProperty("--shiki-light-modified-color",he),W.style.setProperty("--shiki-dark",ie.fg),W.style.setProperty("--shiki-dark-bg",ie.bg),ce&&W.style.setProperty("--shiki-dark-addition-color",ce),xe&&W.style.setProperty("--shiki-dark-deletion-color",xe),se&&W.style.setProperty("--shiki-dark-modified-color",se),W.style.setProperty("--diffs-bg",de.bg),W.style.setProperty("--diffs-fg",de.fg);const ue=d?ce:ve,Y=d?xe:te,Se=d?se:he;ue&&W.style.setProperty("--diffs-addition-color-override",ue),Y&&W.style.setProperty("--diffs-deletion-color-override",Y),Se&&W.style.setProperty("--diffs-modified-color-override",Se);const fe=W.shadowRoot?.querySelector("pre");fe&&(fe.style.setProperty("--shiki-light",Z.fg),fe.style.setProperty("--shiki-light-bg",Z.bg),ve&&fe.style.setProperty("--shiki-light-addition-color",ve),te&&fe.style.setProperty("--shiki-light-deletion-color",te),he&&fe.style.setProperty("--shiki-light-modified-color",he),fe.style.setProperty("--shiki-dark",ie.fg),fe.style.setProperty("--shiki-dark-bg",ie.bg),ce&&fe.style.setProperty("--shiki-dark-addition-color",ce),xe&&fe.style.setProperty("--shiki-dark-deletion-color",xe),se&&fe.style.setProperty("--shiki-dark-modified-color",se),fe.style.setProperty("--diffs-bg",de.bg),fe.style.setProperty("--diffs-fg",de.fg),ue&&fe.style.setProperty("--diffs-addition-color-override",ue),Y&&fe.style.setProperty("--diffs-deletion-color-override",Y),Se&&fe.style.setProperty("--diffs-modified-color-override",Se))},[ie,B,d,Z]);const ne=_e.useMemo(()=>Math.max(t.length,e.length)>d0,[t.length,e.length]),me=_e.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:ne?0:1e3,maxLineLengthForHighlighting:ne?1:1e3,expansionLineCount:20,overflow:i?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:!0,enableHoverUtility:!1,onLineSelected:D,unsafeCSS:u0,renderAnnotation:M}),[m.metadata.id,d,ne,p.metadata.id,a,i,D,M]),pe=_e.useMemo(()=>s0({drafts:b,editingDraftId:j,selection:x}),[j,b,x]),G=_e.useRef(pe);if(_e.useEffect(()=>{G.current=pe},[pe]),_e.useEffect(()=>{if(typeof window>"u")return;const Q=O.current;if(!Q||!J)return;_.current?.cleanUp(),_.current=null,q.current?.release(),q.current=null,Q.innerHTML="";const W=x0(Q);q.current=W;const de=W?new kx(me,W.virtualizer,h0,J):new Cx(me,J);_.current=de,P.current=null;const ge={name:r||"",contents:t,lang:n,cacheKey:`old:${B}:${r}:${Bm(t)}`},ve={name:r||"",contents:e,lang:n,cacheKey:`new:${B}:${r}:${Bm(e)}`};return de.render({oldFile:ge,newFile:ve,lineAnnotations:G.current,containerWrapper:Q}),requestAnimationFrame(()=>{L()}),()=>{de.cleanUp(),_.current===de&&(_.current=null),W?.release(),W&&q.current===W&&(q.current=null),Q.innerHTML=""}},[B,r,n,e,me,t,J]),_e.useEffect(()=>{const Q=_.current;if(Q){try{Q.setLineAnnotations(pe)}catch(W){console.error("Failed to apply diff line annotations",W);try{Q.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(_.current===Q){try{Q.rerender()}catch{}L()}})}},[pe]),_e.useEffect(()=>{const Q=_.current;if(!Q||x!==null)return;const W=P.current;if(!f0(x,W))try{T.current=!0,Q.setSelectedLines(x),P.current=x}catch{}finally{T.current=!1}},[x]),_e.useEffect(()=>{const Q=O.current;if(!Q)return;let W=null,de=()=>{};const ge=()=>{const te=Q.querySelector("diffs-container")?.shadowRoot;if(!te){W=requestAnimationFrame(ge);return}const he=ce=>{if(!(ce instanceof MouseEvent)||ce.button!==0||!(ce.target instanceof Element))return;const xe=ce.target.closest("[data-column-number]");if(!(xe instanceof HTMLElement))return;const se=xe.getAttribute("data-column-number"),ue=se?parseInt(se,10):NaN;if(Number.isNaN(ue))return;const Y=V(xe);D({start:ue,end:ue,side:Y}),ce.preventDefault(),ce.stopPropagation()};te.addEventListener("click",he,!0),de=()=>{te.removeEventListener("click",he,!0)}};return ge(),()=>{W!==null&&cancelAnimationFrame(W),de()}},[B,r,D,V]),_e.useEffect(()=>{const Q=O.current;if(!Q)return;let W=null,de=null;const ve=setTimeout(()=>{const te=Q.querySelector("diffs-container");if(!(te instanceof HTMLElement))return;const he=te.shadowRoot;W=new MutationObserver(()=>{de&&cancelAnimationFrame(de),de=requestAnimationFrame(()=>{L(),de=null})}),W.observe(te,{childList:!0,subtree:!0}),he&&W.observe(he,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(ve),de&&cancelAnimationFrame(de),W?.disconnect()}},[B,r]),typeof window>"u")return null;const K=s.jsx(r0,{diffRootRef:$,drafts:b,selection:x,editingDraftId:j,commentText:g,fileLabel:r?.split("/").pop()??"",onSave:E,onCancel:S,onEdit:Q=>{R({start:Q.startLine,end:Q.endLine,side:Q.side==="original"?"deletions":"additions"}),k(Q)},onDelete:w});return o==="fill"?s.jsx("div",{className:ye("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(Ss,{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"})})}),K]})}):s.jsxs("div",{className:ye("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"})}),K]})},Vm=15e3,zm=500,Um=12,Wm=8*1024*1024,Km=t=>typeof t=="string"?0:(t.original?.length??0)+(t.modified?.length??0),Hm=t=>{if(t.size<=Um){let a=0;for(const i of t.values())a+=Km(i);if(a<=Wm)return t}const e=Array.from(t.entries()).reverse(),n=new Map;let r=0;for(const[a,i]of e){if(n.size>=Um)continue;const o=Km(i);r+o>Wm&&n.size>0||(n.set(a,i),r+=o)}return new Map(Array.from(n.entries()).reverse())};function Gm(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 b0(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 y0=l.memo(t=>{const e=ot.c(71),{entry:n,isExpanded:r,onToggle:a,files:i,isLoadingFiles:o,onCopyHash:c,directory:d}=t,{t:p}=ft();let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=new Set,e[0]=m):m=e[0];const[u,f]=l.useState(m);let b;e[1]===Symbol.for("react.memo_cache_sentinel")?(b=new Map,e[1]=b):b=e[1];const[x,y]=l.useState(b);let g;e[2]===Symbol.for("react.memo_cache_sentinel")?(g=new Set,e[2]=g):g=e[2];const[h,j]=l.useState(g);let v;e[3]!==d||e[4]!==n.hash?(v=async Q=>{const W=Q.path;if(!d){y(de=>new Map(de).set(W,"error"));return}y(de=>Hm(new Map(de).set(W,"loading")));try{const de=_b(d,n.hash,Q.path,!1),ge=new Promise(v0),ve=await Promise.race([de,ge]);y(te=>Hm(new Map(te).set(W,ve)))}catch{y(de=>new Map(de).set(W,"error"))}},e[3]=d,e[4]=n.hash,e[5]=v):v=e[5];const C=v;let k;e[6]!==x||e[7]!==h||e[8]!==C||e[9]!==u?(k=async Q=>{const W=Q.path;if(Q.changeType==="R"||Q.isBinary){f(te=>{const he=new Set(te);return he.has(W)?he.delete(W):he.add(W),he});return}const de=x.get(W);if(u.has(W)&&de&&de!=="error"){f(te=>{const he=new Set(te);return he.delete(W),he});return}f(te=>{const he=new Set(te);return he.add(W),he}),!(de&&de!=="error"||Q.insertions+Q.deletions>zm&&!h.has(W))&&await C(Q)},e[6]=x,e[7]=h,e[8]=C,e[9]=u,e[10]=k):k=e[10];const w=k,N=r?"bg-sidebar/90":"hover:bg-sidebar/40";let I;e[11]!==N?(I=ye("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",N),e[11]=N,e[12]=I):I=e[12];let T;e[13]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),e[13]=T):T=e[13];let P;e[14]!==n.message?(P=s.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:n.message}),e[14]=n.message,e[15]=P):P=e[15];let D;e[16]!==n.author_name?(D=s.jsx("span",{className:"truncate min-w-[3ch]",title:n.author_name,children:n.author_name}),e[16]=n.author_name,e[17]=D):D=e[17];let S;e[18]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx("span",{className:"shrink-0",children:"·"}),e[18]=S):S=e[18];let M;e[19]!==n.date?(M=Gm(n.date),e[19]=n.date,e[20]=M):M=e[20];let E;e[21]!==n.date?(E=Gm(n.date),e[21]=n.date,e[22]=E):E=e[22];let R;e[23]!==M||e[24]!==E?(R=s.jsx("span",{className:"truncate min-w-0",title:M,children:E}),e[23]=M,e[24]=E,e[25]=R):R=e[25];let V;e[26]!==D||e[27]!==R?(V=s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[D,S,R]}),e[26]=D,e[27]=R,e[28]=V):V=e[28];let B;e[29]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx("span",{className:"shrink-0",children:"·"}),e[29]=B):B=e[29];let $;e[30]!==n.hash?($=n.hash.slice(0,8),e[30]=n.hash,e[31]=$):$=e[31];let O;e[32]!==$?(O=s.jsx("code",{className:"shrink-0 font-mono",children:$}),e[32]=$,e[33]=O):O=e[33];let _;e[34]!==n.hash||e[35]!==c?(_=Q=>{Q.stopPropagation(),c(n.hash)},e[34]=n.hash,e[35]=c,e[36]=_):_=e[36];let q;e[37]===Symbol.for("react.memo_cache_sentinel")?(q=s.jsx(A,{name:"file-copy",className:"size-3"}),e[37]=q):q=e[37];let L;e[38]!==_?(L=s.jsx(Ct,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:_,children:q})}),e[38]=_,e[39]=L):L=e[39];let J;e[40]!==p?(J=p("gitView.history.copySha"),e[40]=p,e[41]=J):J=e[41];let Z;e[42]!==J?(Z=s.jsx(It,{sideOffset:8,children:J}),e[42]=J,e[43]=Z):Z=e[43];let ie;e[44]!==L||e[45]!==Z?(ie=s.jsxs(kt,{children:[L,Z]}),e[44]=L,e[45]=Z,e[46]=ie):ie=e[46];let ne;e[47]!==V||e[48]!==O||e[49]!==ie?(ne=s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[V,B,O,ie]}),e[47]=V,e[48]=O,e[49]=ie,e[50]=ne):ne=e[50];let me;e[51]!==ne||e[52]!==P?(me=s.jsxs("div",{className:"min-w-0 flex-1",children:[P,ne]}),e[51]=ne,e[52]=P,e[53]=me):me=e[53];let pe;e[54]!==a||e[55]!==me||e[56]!==I?(pe=s.jsxs("button",{type:"button",onClick:a,className:I,children:[T,me]}),e[54]=a,e[55]=me,e[56]=I,e[57]=pe):pe=e[57];let G;e[58]!==x||e[59]!==i||e[60]!==h||e[61]!==r||e[62]!==o||e[63]!==C||e[64]!==u||e[65]!==p||e[66]!==w?(G=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(A,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:p("gitView.history.loadingFiles")})]}):i.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:p("gitView.history.noFiles")}):s.jsx("ul",{className:"space-y-0.5 py-2",children:i.map(Q=>s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>w(Q),className:ye("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",u.has(Q.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[s.jsx("span",{className:ye("font-semibold w-3 text-center shrink-0",b0(Q.changeType)),children:Q.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:Q.path,children:Q.path}),!Q.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",Q.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",Q.deletions]})]}),Q.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:p("gitView.history.binary")}),s.jsx(A,{name:u.has(Q.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),u.has(Q.path)&&s.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:Q.changeType==="R"?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.renamedNoDiff")}):Q.isBinary?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.binaryNoDiff")}):(()=>{const W=Q.insertions+Q.deletions;if(!h.has(Q.path)&&W>zm)return s.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:p("gitView.history.largeDiffTitle",{count:W})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:p("gitView.history.largeDiffDescription")}),s.jsx(be,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{j(ge=>new Set(ge).add(Q.path)),C(Q)},children:p("gitView.history.renderDiffAnyway")})]});const de=x.get(Q.path);return de==="loading"||de===void 0?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.loadingDiff")}):de==="error"?s.jsx("button",{type:"button",onClick:()=>w(Q),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:p("gitView.history.diffError")}):s.jsx(mu,{original:de.original,modified:de.modified,language:ki(Q.path)||"",fileName:Q.path,renderSideBySide:!1,layout:"inline"})})()})]},Q.path))})}),e[58]=x,e[59]=i,e[60]=h,e[61]=r,e[62]=o,e[63]=C,e[64]=u,e[65]=p,e[66]=w,e[67]=G):G=e[67];let K;return e[68]!==pe||e[69]!==G?(K=s.jsxs("li",{children:[pe,G]}),e[68]=pe,e[69]=G,e[70]=K):K=e[70],K});function v0(t,e){setTimeout(()=>e(new Error(`Timed out after ${Vm}ms`)),Vm)}const w0=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],j0=t=>{const e=ot.c(56),{log:n,isLogLoading:r,logMaxCount:a,onLogMaxCountChange:i,expandedCommitHashes:o,onToggleCommit:c,commitFilesMap:d,loadingCommitHashes:p,onCopyHash:m,directory:u,showHeader:f,contentMaxHeightClassName:b,branchDivider:x}=t,y=f===void 0?!0:f,g=b===void 0?"max-h-[50vh]":b,h=x===void 0?null:x,{t:j}=ft(),[v,C]=l.useState(!0);if(!n)return null;const k=h!==null&&h.insertBeforeIndex>0&&h.insertBeforeIndex<n.all.length,w=h!==null&&h.insertBeforeIndex===n.all.length,N=k||w;let I;e[0]!==h||e[1]!==k||e[2]!==w||e[3]!==n.all?(I=k?n.all.slice(0,h.insertBeforeIndex):w?n.all:[],e[0]=h,e[1]=k,e[2]=w,e[3]=n.all,e[4]=I):I=e[4];const T=I;let P;if(e[5]!==h||e[6]!==d||e[7]!==g||e[8]!==u||e[9]!==o||e[10]!==k||e[11]!==N||e[12]!==p||e[13]!==n.all||e[14]!==m||e[15]!==c||e[16]!==j||e[17]!==T){const _=k?n.all.slice(h.insertBeforeIndex):[];let q;e[19]!==h?.direction?(q=h?.direction==="down"?s.jsx(A,{name:"arrow-down-s",className:"size-3.5"}):s.jsx(A,{name:"arrow-up",className:"size-3.5"}),e[19]=h?.direction,e[20]=q):q=e[20];const L=q;let J;e[21]!==d||e[22]!==u||e[23]!==o||e[24]!==p||e[25]!==m||e[26]!==c?(J=ie=>s.jsx("ul",{className:"divide-y divide-border/60",children:ie.map(ne=>s.jsx(y0,{entry:ne,isExpanded:o.has(ne.hash),onToggle:()=>c(ne.hash),files:d.get(ne.hash)??[],isLoadingFiles:p.has(ne.hash),onCopyHash:m,directory:u},ne.hash))}),e[21]=d,e[22]=u,e[23]=o,e[24]=p,e[25]=m,e[26]=c,e[27]=J):J=e[27];const Z=J;P=s.jsx(Ss,{outerClassName:`min-h-0 ${g}`,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:j("gitView.history.noCommits")})}):N&&h?s.jsxs("div",{className:"flex flex-col gap-0",children:[T.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:Z(T)}):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:h.branchName,children:h.branchName}),L]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),_.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:Z(_)}):null]}):Z(n.all)}),e[5]=h,e[6]=d,e[7]=g,e[8]=u,e[9]=o,e[10]=k,e[11]=N,e[12]=p,e[13]=n.all,e[14]=m,e[15]=c,e[16]=j,e[17]=T,e[18]=P}else P=e[18];const D=P;if(!y){if(N){let q;return e[28]!==D?(q=s.jsx("section",{className:"h-full min-h-0",children:D}),e[28]=D,e[29]=q):q=e[29],q}let _;return e[30]!==D?(_=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:D}),e[30]=D,e[31]=_):_=e[31],_}let S;e[32]!==j?(S=j("gitView.history.title"),e[32]=j,e[33]=S):S=e[33];let M;e[34]!==S?(M=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:S}),e[34]=S,e[35]=M):M=e[35];let E;e[36]!==r||e[37]!==v||e[38]!==a||e[39]!==i||e[40]!==j?(E=v&&s.jsx("div",{onClick:N0,onPointerDown:S0,children:s.jsxs(as,{value:String(a),onValueChange:_=>i(Number(_)),disabled:r,children:[s.jsx(is,{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(fs,{placeholder:j("gitView.history.commitsPlaceholder")})}),s.jsx(os,{children:w0.map(_=>s.jsx(Mt,{value:String(_.value),children:j(_.labelKey)},_.value))})]})}),e[36]=r,e[37]=v,e[38]=a,e[39]=i,e[40]=j,e[41]=E):E=e[41];let R;e[42]!==v?(R=v?s.jsx(A,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[42]=v,e[43]=R):R=e[43];let V;e[44]!==E||e[45]!==R?(V=s.jsxs("div",{className:"flex items-center gap-2",children:[E,R]}),e[44]=E,e[45]=R,e[46]=V):V=e[46];let B;e[47]!==V||e[48]!==M?(B=s.jsxs(Mr,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[M,V]}),e[47]=V,e[48]=M,e[49]=B):B=e[49];let $;e[50]!==D?($=s.jsx(wr,{children:D}),e[50]=D,e[51]=$):$=e[51];let O;return e[52]!==v||e[53]!==B||e[54]!==$?(O=s.jsxs(vr,{open:v,onOpenChange:C,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[B,$]}),e[52]=v,e[53]=B,e[54]=$,e[55]=O):O=e[55],O};function N0(t){return t.stopPropagation()}function S0(t){return t.stopPropagation()}const dg=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},k0=9e4,C0=15e3,I0=5*6e4,P0=[2e3,5e3],A0=6e4,D0=2*6e4,T0=5*6e4,E0=4,M0=720*6e4,R0="openchamber.github-pr-status",F0=t=>t==="closed"||t==="merged",O0=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},no=(t,e,n)=>`${t}::${e}`,Vo=new Map,zo=new Map,Bi=new Set,qm=new Map,Yi=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),_l=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,pu=t=>{const e=_l(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},ug=(t,e)=>Object.entries(t).filter(([,n])=>pu(n)===e).map(([n])=>n),L0=(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}}},Uo=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},$0=(t,e,n)=>{const r=ug(t,e),a=r.map(d=>Uo(t[d])).filter(d=>!!d);if(a.length===0)return null;const i=Uo(t[n]);if(i&&pu(t[n])===e)return i;const o=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&Uo(d)));if(o)return Uo(o);const c=a.find(d=>!!d.remoteName);return c||(a[0]??null)},_0=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:_l(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),B0=t=>({...Yi(),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}),xr=ar()(Ei((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:Yi()}})},setParams:(n,r)=>{t(a=>{const i=a.entries[n]??Yi();return{entries:{...a.entries,[n]:L0(i,r)}}})},startWatching:n=>{if(t(i=>{const o=i.entries[n]??Yi();return{entries:{...i.entries,[n]:{...o,watchers:o.watchers+1}}}}),Vo.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=zo.get(n)??[];c.push(o),zo.set(n,c)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),P0.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<I0)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(F0(i.status?.pr?.state))return;const c=Date.now()-i.lastRefreshAt,d=O0(i.status)?A0:i.status?.checks&&i.status.checks.state!=="pending"?T0:D0;c<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},C0);Vo.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=Vo.get(n);typeof a=="number"&&window.clearInterval(a),Vo.delete(n);const i=zo.get(n);i&&i.length>0&&i.forEach(o=>{window.clearTimeout(o)}),zo.delete(n)},refresh:async(n,r)=>{const a=e(),i=a.entries[n],o=pu(i);if(!i||!o)return;const c=ug(a.entries,o),d=c.some(u=>!!a.entries[u]?.status?.pr);if(r?.onlyExistingPr&&!d)return;const p=qm.get(o)??0;if(!r?.force&&Date.now()-p<k0||Bi.has(o))return;const m=$0(a.entries,o,n);if(m){if(Bi.add(o),qm.set(o,Date.now()),t(u=>{const f={...u.entries};return c.forEach(b=>{const x=f[b];x&&(f[b]={...x,lastRefreshAt:Date.now(),isLoading:r?.silent?x.isLoading:!0,error:null})}),{entries:f}}),m.githubAuthChecked&&m.githubConnected===!1){t(u=>{const f={...u.entries};return c.forEach(b=>{const x=f[b];x&&(f[b]={...x,status:{connected:!1},error:null,isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0})}),{entries:f}}),Bi.delete(o);return}if(!m.github?.prStatus){t(u=>{const f={...u.entries};return c.forEach(b=>{const x=f[b];x&&(f[b]={...x,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0})}),{entries:f}}),Bi.delete(o);return}try{t(f=>({...f,activeRequestCount:f.activeRequestCount+1,totalRequestCount:f.totalRequestCount+1}));const u=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0,{force:r?.force});t(f=>{const b={...f.entries};return c.forEach(x=>{const y=b[x];if(!y)return;const g=y.status?.pr,h=u.pr,v=!!(h&&g&&h.number===g.number&&(!h.body||!h.body.trim())&&typeof g.body=="string"&&g.body.trim().length>0)&&h&&g?.body?{...u,pr:{...h,body:g.body}}:u,C=v.resolvedRemoteName??y.resolvedRemoteName??m.remoteName??null,k=_l(y)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};b[x]={...y,status:v,error:null,isLoading:r?.silent?y.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?y.isInitialStatusResolved:!0,resolvedRemoteName:C,identity:{...k,remoteName:C??k.remoteName??null}}}),{entries:b}})}catch(u){const f=u instanceof Error?u.message:String(u);t(b=>{const x={...b.entries};return c.forEach(y=>{const g=x[y];g&&(x[y]={...g,error:f||"Failed to load PR status",isLoading:r?.silent?g.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?g.isInitialStatusResolved:!0})}),{entries:x}})}finally{Bi.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:no(o,c,i.remoteName??null)}).filter(i=>!!i)));await dg(a,E0,i=>e().refresh(i,r))},updateStatus:(n,r)=>{t(a=>{const i=a.entries[n]??Yi();return{entries:{...a.entries,[n]:{...i,status:r(i.status)}}}})}}),{name:R0,storage:wo(()=>br()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=_l(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<M0}).map(([e,n])=>[e,_0(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([a,i])=>[a,B0(i)]))}}})),V0=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"},z0=t=>{const e=V0(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}},U0=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 Mc=new Map,Jm=new Map;const W0=t=>{const e=ot.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=z0(c);if(!d)continue;const p=U0(d);a.set(o,p),i.set(o,d)}if(a.size===Mc.size){let o=!0;for(const[c,d]of a)if(Mc.get(c)!==d){o=!1;break}if(o)return Jm}return Mc=a,Jm=i,i},e[0]=t,e[1]=n):n=e[1],xr(n)},K0=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"}},H0=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"},G0=[2e3,5e3],Ym=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),fa=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):""},q0=(t,e)=>{const n=fa(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},J0=(t,e)=>`${t}::${e}`,fu=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},Rc=(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=fu(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)},Y0=t=>t.startsWith("pr-"),Q0=(t,e)=>{const n=fu(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=>!Y0(o.name)).forEach(o=>i(o)),t.forEach(o=>i(o)),a},Fc=new Map,Oc=rr;function X0(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 Z0=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:a=[],remoteBranches:i=[],onGeneratedDescription:o})=>{const{t:c}=ft(),{github:d}=_n(),p=Hn(He=>He.status),m=Hn(He=>He.hasChecked),u=Fe(He=>He.setSettingsDialogOpen),f=Fe(He=>He.setSettingsPage),b=Fe(He=>He.setActiveMainTab),x=$t(He=>He.currentSessionId),{isMobile:y,hasTouchInput:g}=ln(),h=l.useCallback(()=>{f("github"),u(!0)},[u,f]),j=l.useMemo(()=>J0(t,e),[t,e]),v=l.useMemo(()=>Fc.get(j)??null,[j]),C=xr(He=>He.ensureEntry),k=xr(He=>He.setParams),w=xr(He=>He.startWatching),N=xr(He=>He.stopWatching),I=xr(He=>He.refresh),T=xr(He=>He.updateStatus),[P,D]=l.useState(()=>v?.title??Ym(e)),[S,M]=l.useState(()=>v?.body??""),[E,R]=l.useState(()=>v?.draft??!1),[V,B]=l.useState(()=>v?.additionalContext??""),[$,O]=l.useState(()=>{const He=typeof v?.targetBaseBranch=="string"?fa(v.targetBaseBranch):"";return He||fa(n)}),[_,q]=l.useState("squash"),[L,J]=l.useState(!1),[Z,ie]=l.useState(!1),[ne,me]=l.useState(!1),[pe,G]=l.useState(!1),[K,Q]=l.useState(!1),[W,de]=l.useState(!1),[ge,ve]=l.useState(null),[te,he]=l.useState(""),[ce,xe]=l.useState(""),[se,ue]=l.useState(!1),[Y,Se]=l.useState(!1),[fe,Ce]=l.useState(()=>Rc(a,{selectedRemoteName:v?.selectedRemoteName,trackingBranch:r})),[Ie,ke]=l.useState(!1),{detectedUpstream:X,upstreamBranches:ae}=X0(t,d);l.useEffect(()=>{ke(!1)},[t]);const je=a.some(He=>He.name==="upstream"),Ne=!!(t&&e&&n&&(e!==n||(je||X!==null))),Me=l.useMemo(()=>no(t,e),[t,e]),Ve=xr(He=>He.entries[Me]),we=Ve?.isLoading??!1,ee=Ve?.status??null,F=Ve?.error??null,U=Ve?.isInitialStatusResolved??!1,oe=l.useMemo(()=>{const He=Ie?null:fe?.name?.trim()||null,yt=new Set;for(const Yt of i){const Ot=q0(Yt,He);!Ot||Ot==="HEAD"||yt.add(Ot)}if(Ie)for(const Yt of ae)Yt&&Yt!=="HEAD"&&yt.add(Yt);const Et=fa(n);Et&&Et!=="HEAD"&&yt.add(Et);const Rt=fa($);return Rt&&Rt!=="HEAD"&&yt.add(Rt),Array.from(yt).sort((Yt,Ot)=>Yt.localeCompare(Ot))},[n,i,fe?.name,$,ae,Ie]);l.useEffect(()=>{if(a.length===0){fe&&Ce(null);return}(!fe||!a.some(He=>He.name===fe.name))&&Ce(Rc(a,{selectedRemoteName:v?.selectedRemoteName,trackingBranch:r}))},[v?.selectedRemoteName,a,fe,r]),l.useEffect(()=>{const He=fa(n);if(!$&&He){O(He);return}if(oe.length!==0&&!oe.includes($)){const yt=oe.includes(He)?He:oe[0];yt&&O(yt)}},[oe,n,$]);const[Te,Oe]=l.useState(!1),[Pe,z]=l.useState(null),[De,Qe]=l.useState(!1),[et,Ze]=l.useState(new Set),[We,it]=l.useState(!1),[qe,st]=l.useState(null),[Je,Be]=l.useState(!1),nt=l.useRef(new Set),Ge=l.useRef(null),at=l.useRef(!1),Ae=l.useRef(new Set),Le=l.useRef([]);l.useEffect(()=>{X&&!je&&ke(!0)},[X,je]),l.useEffect(()=>{Ie&&X?.defaultBranch&&O(X.defaultBranch)},[Ie,X?.defaultBranch]);const ze=ee?.pr??null,Ke=ze?`${t}#${ze.number}`:null,lt=!!(Ke&&ge===Ke);l.useEffect(()=>{if(!d?.prContext||!ze||typeof ze.body=="string"&&ze.body.length>0)return;const He=`${t}#${ze.number}`;if(nt.current.has(He))return;nt.current.add(He),ve(He);let yt=!1;return d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1}).then(Et=>{if(yt)return;const Rt=Et?.pr;Rt&&T(Me,Yt=>!Yt?.pr||Yt.pr.number!==ze.number?Yt:{...Yt,pr:{...Yt.pr,body:Rt.body||""}})}).catch(()=>{}).finally(()=>{yt||ve(Et=>Et===He?null:Et)}),()=>{yt=!0}},[t,d,ze,Me,T]),l.useEffect(()=>{if(!ze){de(!1),he(""),xe(""),Ge.current=null;return}const He=Ge.current!==null&&Ge.current!==ze.number;He&&de(!1),(!W||He)&&(he(ze.title||""),xe(ze.body||"")),Ge.current=ze.number},[W,ze]);const xt=l.useCallback(async()=>{if(!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(ze){Oe(!0),Ze(new Set),Qe(!0);try{const He=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!0});z(He)}catch(He){const yt=He instanceof Error?He.message:String(He);H.error(c("gitView.pr.toast.loadCheckDetailsFailed"),{description:yt})}finally{Qe(!1)}}},[t,d,ze,c]),dt=l.useCallback(async()=>{if(!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(ze){it(!0),Be(!0);try{const He=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1});st(He)}catch(He){const yt=He instanceof Error?He.message:String(He);H.error(c("gitView.pr.toast.loadCommentsFailed"),{description:yt})}finally{Be(!1)}}},[t,d,ze,c]),ut=l.useCallback(He=>{if(!He)return"";const yt=Date.parse(He);return Number.isFinite(yt)?new Date(yt).toLocaleString():He},[]),Nt=l.useMemo(()=>{const He=p?.user?.login;return typeof He=="string"?He.trim():""},[p]),ts=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)]",[]),Vt=l.useCallback(He=>{const yt=Nt.toLowerCase(),Et=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return He.replace(Et,(Rt,Yt,Ot)=>{const Os=`@${Ot}`,Ds=Ot.toLowerCase();return`${Yt}[${Os}](https://github.com/${Ds}${yt&&Ds===yt?"?oc-self-mention=1":""})`})},[Nt]),Xt=l.useMemo(()=>{const He=(qe?.issueComments??[]).map(Rt=>({id:`issue-${Rt.id}`,body:Rt.body||"",authorName:Rt.author?.name||Rt.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Rt.author?.login||null,avatarUrl:Rt.author?.avatarUrl||null,createdAt:Rt.createdAt,context:c("gitView.pr.comments.generalContext"),path:null,line:null})),yt=(qe?.reviewComments??[]).map(Rt=>({id:`review-${Rt.id}`,body:Rt.body||"",authorName:Rt.author?.name||Rt.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Rt.author?.login||null,avatarUrl:Rt.author?.avatarUrl||null,createdAt:Rt.createdAt,context:c("gitView.pr.comments.reviewContext"),path:Rt.path||null,line:Rt.line??null})),Et=[...He,...yt];return Et.sort((Rt,Yt)=>{const Ot=Rt.createdAt?Date.parse(Rt.createdAt):0,Os=Yt.createdAt?Date.parse(Yt.createdAt):0,Ds=Number.isFinite(Ot)?Ot:0,Ts=Number.isFinite(Os)?Os:0;return Ds-Ts}),Et},[qe,c]),ht=l.useCallback(()=>{if(!x)return H.error(c("gitView.pr.toast.noActiveSession"),{description:c("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:He,currentModelId:yt,currentAgentName:Et,currentVariant:Rt}=wt.getState(),Yt=Ql.getState().lastUsedProvider,Ot=He||Yt?.providerID,Os=yt||Yt?.modelID;return!Ot||!Os?(H.error(c("gitView.pr.toast.noModelSelected")),null):{sessionId:x,providerID:Ot,modelID:Os,currentAgentName:Et??null,currentVariant:Rt??null}},[x,c]),Bt=l.useCallback((He,yt,Et,Rt)=>{$t.getState().sendMessage(yt,He.providerID,He.modelID,He.currentAgentName??void 0,void 0,void 0,[{text:Et,synthetic:!0},{text:Rt,synthetic:!0}],He.currentVariant??void 0).catch(Yt=>{const Ot=Yt instanceof Error?Yt.message:String(Yt);H.error(c("gitView.pr.toast.sendMessageFailed"),{description:Ot})})},[c]),Zt=l.useCallback(He=>{const yt=He.status||"unknown",Et=He.conclusion??void 0,Rt=Et?`${yt} / ${Et}`:yt,Yt=He.app?.name||He.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:He.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:Yt?`${Yt} · ${Rt}`:Rt})]}),He.detailsUrl?s.jsx(be,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:He.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(A,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),He.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:He.output.title}):null,He.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap",children:He.output.summary}):null,He.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:He.output.text}):null,Array.isArray(He.annotations)&&He.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",He.annotations.length>20?` (showing 20/${He.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:He.annotations.slice(0,20).map((Ot,Os)=>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:[Ot.title||Ot.level||"Issue",Ot.path?` · ${Ot.path}`:"",typeof Ot.startLine=="number"?`:${Ot.startLine}`:"",typeof Ot.endLine=="number"&&Ot.endLine!==Ot.startLine?`-${Ot.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:Ot.message}),Ot.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:Ot.rawDetails}):null]},`${Ot.path||"file"}:${Ot.startLine||Os}:${Os}`))})]}):null,He.job?.steps&&He.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:He.job.steps.map((Ot,Os)=>{const Ds=(Ot.conclusion||"").toLowerCase(),Ts=Ds&&!["success","neutral","skipped"].includes(Ds),Vs=`${He.id??"run"}:${He.job?.jobId??"job"}:${Ot.number??Os}:${Ot.name}`,js=et.has(Vs);return Ts?s.jsxs(vr,{open:js,children:[s.jsxs("button",{type:"button",onClick:()=>{Ze(Bn=>{const bn=new Set(Bn);return bn.has(Vs)?bn.delete(Vs):bn.add(Vs),bn})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(Ts?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[js?s.jsx(A,{name:"arrow-down-s",className:"size-4"}):s.jsx(A,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:Ot.name}),Ot.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Ot.conclusion}):null]}),s.jsx(wr,{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 Ot.number=="number"?s.jsxs("div",{children:[c("gitView.pr.checks.stepLabel"),": ",Ot.number]}):null,Ot.status?s.jsxs("div",{children:[c("gitView.pr.checks.statusLabel"),": ",Ot.status]}):null,Ot.conclusion?s.jsxs("div",{children:[c("gitView.pr.checks.conclusionLabel"),": ",Ot.conclusion]}):null,Ot.startedAt?s.jsxs("div",{children:[c("gitView.pr.checks.startedLabel"),": ",ut(Ot.startedAt)]}):null,Ot.completedAt?s.jsxs("div",{children:[c("gitView.pr.checks.completedLabel"),": ",ut(Ot.completedAt)]}):null]})})]},Vs):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:Ot.name}),Ot.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Ot.conclusion}):null]},Vs)})})]}):null]})},[et,ut,c]),gs=l.useCallback(async()=>{if(b("chat"),!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!ze)return;const He=ht();if(He)try{const yt=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!0}),Rt=(yt.checkRuns??[]).filter(Ts=>{const Vs=typeof Ts.conclusion=="string"?Ts.conclusion.toLowerCase():"";return Vs?!["success","neutral","skipped"].includes(Vs):!1});if(Rt.length===0){H.message(c("gitView.pr.toast.noFailedChecks"));return}const Yt=await wn("github.pr.checks.review.visible"),Ot=await wn("github.pr.checks.review.instructions"),Os=Rt.flatMap(Ts=>(Array.isArray(Ts.annotations)?Ts.annotations:[]).map(js=>({run:Ts.name,level:js.level,title:js.title,path:js.path,startLine:js.startLine,endLine:js.endLine,message:js.message,rawDetails:js.rawDetails}))),Ds=`GitHub PR failed checks (JSON)
|
|
39
|
-
${JSON.stringify({repo:yt.repo??null,pr:yt.pr??null,failedChecks:Rt,failedAnnotations:Os},null,2)}`;Bt(He,Yt,Ot,Ds)}catch(yt){const Et=yt instanceof Error?yt.message:String(yt);H.error(c("gitView.pr.toast.loadChecksFailed"),{description:Et})}},[t,Bt,d,ze,ht,b,c]),rs=l.useCallback(async()=>{if(b("chat"),!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!ze)return;const He=ht();if(He)try{const yt=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1}),Et=yt.issueComments??[],Rt=yt.reviewComments??[];if(Et.length+Rt.length===0){H.message(c("gitView.pr.toast.noPrComments"));return}const Ot=await wn("github.pr.comments.review.visible"),Os=await wn("github.pr.comments.review.instructions"),Ds=`GitHub PR comments (JSON)
|
|
40
|
-
${JSON.stringify({repo:yt.repo??null,pr:yt.pr??null,issueComments:Et,reviewComments:Rt},null,2)}`;Bt(He,Ot,Os,Ds)}catch(yt){const Et=yt instanceof Error?yt.message:String(yt);H.error(c("gitView.pr.toast.loadPrCommentsFailed"),{description:Et})}},[t,Bt,d,ze,ht,b,c]),ps=l.useCallback(async He=>{it(!1),b("chat");const yt=ht();if(!yt)return;const Et=await wn("github.pr.comment.single.visible"),Rt=await wn("github.pr.comment.single.instructions"),Yt=`GitHub PR comment (JSON)
|
|
41
|
-
${JSON.stringify({repo:qe?.repo??null,pr:qe?.pr??ze??null,comment:He},null,2)}`;Bt(yt,Et,Rt,Yt)},[qe,Bt,ze,ht,b]),Ut=l.useCallback(async He=>{await I(Me,He)},[Me,I]),Ye=l.useCallback(()=>{Le.current.forEach(He=>{window.clearTimeout(He)}),Le.current=G0.map(He=>window.setTimeout(()=>{Ut({force:!0,silent:!0,markInitialResolved:!0})},He))},[Ut]);l.useEffect(()=>{if(!d?.prStatus||!Ne||a.length<=1||at.current||ee?.pr)return;const He=`${j}::${fe?.name??""}`;if(Ae.current.has(He))return;Ae.current.add(He);const yt=Q0(a,r).filter(Yt=>Yt.name!==fe?.name);if(yt.length===0)return;let Et=!1;return(async()=>{for(const Yt of yt){if(Et)return;try{if(!(await d.prStatus(t,e,Yt.name))?.pr)continue;if(Et)return;Ce(Os=>Os?.name===Yt.name?Os:Yt);return}catch{}}})(),()=>{Et=!0}},[e,Ne,t,d,a,fe?.name,j,ee?.pr,r]),l.useEffect(()=>{C(Me),k(Me,{directory:t,branch:e,remoteName:fe?.name??null,canShow:Ne,github:d,githubAuthChecked:m,githubConnected:p?.connected??null})},[e,Ne,t,C,d,m,p?.connected,Me,fe?.name,k]),l.useEffect(()=>(w(Me),()=>{N(Me)}),[Me,w,N]),l.useEffect(()=>{const He=Fc.get(j)??null;D(He?.title??Ym(e)),M(He?.body??""),R(He?.draft??!1),O(He?.targetBaseBranch?fa(He.targetBaseBranch):fa(n));const yt=Rc(a,{selectedRemoteName:He?.selectedRemoteName,trackingBranch:r});Ce(Et=>Et?.name===yt?.name?Et:yt)},[n,e,a,j,r]),l.useEffect(()=>{Ut({markInitialResolved:!0})},[Me,Ut]),l.useEffect(()=>{!Ne||!fe?.name||Ut({force:!0,silent:!0,markInitialResolved:!0})},[Ne,Ut,fe?.name]),l.useEffect(()=>{const He=ee?.resolvedRemoteName?.trim();if(!He||at.current)return;const yt=a.find(Et=>Et.name===He);yt&&Ce(Et=>Et?.name===yt.name?Et:yt)},[a,ee?.resolvedRemoteName]),l.useEffect(()=>{const He=ee?.pr?.state==="closed"||ee?.pr?.state==="merged",yt=Ve?.lastRefreshAt??0,Et=Date.now()-yt>6e4,Rt=!He&&Et,Yt=()=>{Rt&&Ut({force:!0,silent:!0})},Ot=()=>{document.visibilityState==="visible"&&Rt&&Ut({force:!0,silent:!0})};return window.addEventListener("focus",Yt),document.addEventListener("visibilitychange",Ot),()=>{window.removeEventListener("focus",Yt),document.removeEventListener("visibilitychange",Ot)}},[Ut,ee?.pr?.state,Ve?.lastRefreshAt]),l.useEffect(()=>{m&&p?.connected===!1&&Ut({force:!0,silent:!0,markInitialResolved:!0})},[m,p,Ut]),l.useEffect(()=>{!t||!e||Fc.set(j,{title:P,body:S,draft:E,additionalContext:V,targetBaseBranch:$,selectedRemoteName:fe?.name})},[j,P,S,E,V,$,fe?.name,t,e]),l.useEffect(()=>{const He=Le.current;return()=>{He.forEach(yt=>{window.clearTimeout(yt)}),Le.current=[]}},[]);const Tt=l.useCallback(async()=>{if(!L&&t){J(!0);try{const yt={base:Ie&&X?.defaultBranchSha?X.defaultBranchSha:$,head:e};V&&(yt.context=V);const Et=await Bb(t,yt);Et.title?.trim()&&D(Et.title.trim()),Et.body?.trim()&&M(Et.body.trim()),o?.()}catch(He){const yt=He instanceof Error?He.message:String(He);H.error(c("gitView.pr.toast.generateDescriptionFailed"),{description:yt})}finally{J(!1)}}},[V,e,X?.defaultBranchSha,t,L,o,$,c,Ie]),Kt=l.useCallback(async()=>{if(!d?.prCreate){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}const He=P.trim();if(!He){H.error(c("gitView.pr.toast.titleRequired"));return}const yt=$.trim();if(!yt){H.error(c("gitView.pr.toast.baseBranchRequired"));return}if(!Ie&&yt===e){H.error(c("gitView.pr.toast.baseMustDifferFromHead"));return}ie(!0);try{const Et=fu(r),Rt=Ie&&X,Yt=await d.prCreate({directory:t,title:He,head:e,base:yt,...S.trim()?{body:S}:{},draft:E,...Rt?{targetRepo:{owner:X.owner,repo:X.repo},headRemote:"origin"}:{...fe?{remote:fe.name}:{},...Et&&Et!==fe?.name?{headRemote:Et}:{}}});H.success(c("gitView.pr.toast.prCreated")),T(Me,Ot=>Ot&&{...Ot,pr:Yt}),await Ut({force:!0}),Ye()}catch(Et){const Rt=Et instanceof Error?Et.message:String(Et);H.error(c("gitView.pr.toast.createPrFailed"),{description:Rt})}finally{ie(!1)}},[S,e,X,t,E,d,Me,Ut,Ye,fe,$,P,r,T,Ie,c]),St=l.useCallback(async He=>{if(!d?.prMerge){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}G(!0);try{const yt=await d.prMerge({directory:t,number:He.number,method:_});yt.merged?H.success(c("gitView.pr.toast.prMerged")):H.message(c("gitView.pr.toast.prNotMerged"),{description:yt.message||c("gitView.pr.notMergeable")}),await Ut({force:!0}),Ye()}catch(yt){const Et=yt instanceof Error?yt.message:String(yt);H.error(c("gitView.pr.toast.mergeFailed"),{description:Et}),He.url&&Oc(He.url)}finally{G(!1)}},[t,d,_,Ut,Ye,c]),es=l.useCallback(async He=>{if(!d?.prReady){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}Q(!0);try{await d.prReady({directory:t,number:He.number}),H.success(c("gitView.pr.toast.markedReady")),await Ut({force:!0}),Ye()}catch(yt){const Et=yt instanceof Error?yt.message:String(yt);H.error(c("gitView.pr.toast.markReadyFailed"),{description:Et}),He.url&&Oc(He.url)}finally{Q(!1)}},[t,d,Ut,Ye,c]),ss=l.useCallback(async He=>{if(!d?.prUpdate){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}const yt=te.trim();if(!yt){H.error(c("gitView.pr.toast.titleRequired"));return}me(!0);try{const Et=await d.prUpdate({directory:t,number:He.number,title:yt,body:ce});T(Me,Rt=>Rt&&{...Rt,pr:{...Rt.pr??He,...Et}}),de(!1),H.success(c("gitView.pr.toast.prUpdated")),await Ut({force:!0}),Ye()}catch(Et){const Rt=Et instanceof Error?Et.message:String(Et);H.error(c("gitView.pr.toast.updatePrFailed"),{description:Rt})}finally{me(!1)}},[t,ce,te,d,Me,Ut,Ye,T,c]);if(!Ne)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 Ms=ee?.repo?.url||null,xs=Ie&&X?.url?X.url:Ms,Bs=ee?.checks??null,ws=!!ee?.canMerge,xn=!!ee?.connected,Qs=m&&ee?.connected===!1,Wt=H0(ee),qt=Wt?`var(--pr-${Wt})`:"var(--status-info)",re=Wt==="draft"?"git-pr-draft":Wt==="merged"?"git-merge":Wt==="closed"?"git-close-pull-request":"git-pull-request",vt=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(" · "):"",Ft=Bs?Bs.total>0?`${Bs.success}/${Bs.total} ${c("gitView.pr.checks.label")}`:`${Bs.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(kt,{children:[s.jsx(Ct,{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:()=>{Oc(ze.url)},"aria-label":c("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(A,{name:re,className:"size-4 shrink-0",style:{color:qt}})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(A,{name:re,className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:c("gitView.pullRequest.title")}),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:[we?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(kt,{children:[s.jsx(Ct,{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:we,onClick:()=>{Ut({force:!0})},"aria-label":c("gitView.pr.actions.refreshAria"),children:s.jsx(A,{name:"refresh",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:qt},children:vt}),Bs?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${K0(Bs.state)}`}),Ft]}):null,r&&fe&&r.split("/")[0]!==fe.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",fe.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[Qs?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.githubNotConnected")}),s.jsx(be,{variant:"outline",size:"sm",onClick:h,className:"w-fit",children:c("gitView.pr.actions.openSettings")})]}):null,F?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:c("gitView.pr.statusUnavailable")}),s.jsx("div",{className:"typography-meta text-muted-foreground break-words",children:F}),xs?s.jsx(be,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:xs,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(A,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!ze&&!U&&!F&&!Qs?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),c("gitView.pr.checkingStatus")]}):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:[W?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Lt,{value:te,onChange:He=>he(He.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:g?"on":"off",autoCapitalize:g?"sentences":"off",spellCheck:g}),s.jsx(un,{value:ce,onChange:He=>xe(He.target.value),className:"min-h-[120px] bg-background/80",placeholder:c("gitView.pr.placeholder.description"),autoCorrect:g?"on":"off",autoCapitalize:g?"sentences":"off",spellCheck:g})]}):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(ya,{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(lt?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),ws&&ze.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.draftMustBeReady")}):null,ws?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"?W?s.jsxs(s.Fragment,{children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{de(!1),he(ze.title||""),xe(ze.body||"")},disabled:ne,"aria-label":c("gitView.pr.actions.cancelEditingAria"),children:s.jsx(A,{name:"close",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(be,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>ss(ze),disabled:ne||!te.trim(),"aria-label":c("gitView.pr.actions.savePrAria"),children:ne?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"check",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.savePr")})})]})]}):s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>de(!0),"aria-label":c("gitView.pr.actions.editPrAria"),children:s.jsx(A,{name:"edit",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.editPr")})})]}):null,Bs?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:xt,disabled:De,"aria-label":c("gitView.pr.actions.openChecksAria"),children:De?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"information",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.openChecks")})})]}):null,Bs?.failure?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:gs,"aria-label":c("gitView.pr.actions.resolveFailedChecksAria"),children:s.jsx(A,{name:"error-warning",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.resolveFailedChecks")})})]}):null,s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:dt,"aria-label":c("gitView.pr.actions.openCommentsAria"),children:s.jsx(A,{name:"chat-4",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.openComments")})})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:rs,"aria-label":c("gitView.pr.actions.shareCommentsAria"),children:s.jsx(A,{name:"ai-generate-2",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.shareComments")})})]}),ws&&ze.draft&&ze.state==="open"?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>es(ze),disabled:K||pe||ne||W,"aria-label":c("gitView.pr.actions.markReadyAria"),children:K?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"checkbox-circle",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:ws?s.jsxs(s.Fragment,{children:[s.jsxs(as,{value:_,onValueChange:He=>q(He),disabled:pe||ze.state!=="open",children:[s.jsx(is,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(fs,{})}),s.jsxs(os,{children:[s.jsx(Mt,{value:"squash",children:c("gitView.pr.mergeMethod.squash")}),s.jsx(Mt,{value:"merge",children:c("gitView.pr.mergeMethod.merge")}),s.jsx(Mt,{value:"rebase",children:c("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(be,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>St(ze),disabled:pe||K||ze.state!=="open"||ze.draft||ne||W,"aria-label":c("gitView.pr.actions.mergePrAria"),children:pe?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"git-merge",className:"size-4"})})}),s.jsx(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:["(",Ie&&X?"upstream":"remote",")"]})]})]}),xs?s.jsx(be,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:xs,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(A,{name:"external-link",className:"size-4"}),c("gitView.pr.actions.repo")]})}):null]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.title")}),s.jsx(Lt,{value:P,onChange:He=>D(He.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:g?"on":"off",autoCapitalize:g?"sentences":"off",spellCheck:g})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.baseBranch")}),oe.length>0?s.jsxs(as,{value:$,onValueChange:O,children:[s.jsx(is,{className:"h-9",children:s.jsx(fs,{placeholder:c("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(os,{children:oe.map(He=>s.jsx(Mt,{value:He,children:He},He))})]}):s.jsx(Lt,{value:$,onChange:He=>O(He.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(un,{value:S,onChange:He=>M(He.target.value),className:"min-h-[110px]",placeholder:c("gitView.pr.placeholder.whatChanged"),autoCorrect:g?"on":"off",autoCapitalize:g?"sentences":"off",spellCheck:g})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":E,onClick:()=>R(He=>!He),onKeyDown:He=>{(He.key===" "||He.key==="Enter")&&(He.preventDefault(),R(yt=>!yt))},children:[s.jsx(vs,{size:"sm",checked:E,onChange:He=>R(He),ariaLabel:c("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:c("gitView.pr.field.draft")})]}),y?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.optional")}),s.jsx(be,{variant:"outline",size:"sm",onClick:()=>Se(!0),children:V.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),V.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(vr,{open:se,onOpenChange:ue,children:[s.jsxs(Mr,{className:"flex w-full items-center justify-between rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-2 hover:bg-[var(--interactive-hover)]",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:se?c("gitView.pr.actions.hide"):V.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),s.jsx(wr,{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(un,{value:V,onChange:He=>B(He.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(zr,{open:Y,onClose:()=>Se(!1),title:c("gitView.pr.additionalContext.title"),footer:s.jsx(be,{size:"sm",onClick:()=>Se(!1),className:"w-full",children:c("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(un,{value:V,onChange:He=>B(He.target.value),className:"min-h-[200px] bg-transparent",placeholder:c("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(be,{variant:"outline",size:"sm",onClick:Tt,disabled:L||Z,children:[L?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"ai-generate-2",className:"size-4 text-primary"}),c("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(be,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Kt,disabled:Z||!xn||!$.trim()||!Ie&&$.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:Z?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:c("gitView.pr.actions.createPr")})]})]})]})]}),s.jsx(us,{open:Te,onOpenChange:Oe,children:s.jsxs(ds,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(hs,{children:[s.jsxs(ms,{className:"flex items-center gap-2",children:[s.jsx(A,{name:"git-pull-request",className:"h-5 w-5"}),c("gitView.pr.checkDetails.title")]}),s.jsx(Ns,{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:[De?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,De?null:s.jsx("div",{className:"space-y-3",children:Array.isArray(Pe?.checkRuns)&&Pe?.checkRuns.length>0?Pe.checkRuns.map((He,yt)=>{const Et=`${He.id??"run"}:${He.job?.jobId??"job"}:${He.name}:${yt}`;return s.jsx("div",{className:"p-1",children:Zt(He)},Et)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(us,{open:We,onOpenChange:it,children:s.jsxs(ds,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(hs,{children:s.jsxs(ms,{className:"flex items-center gap-2",children:[s.jsx(A,{name:"git-pull-request",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(jo,{className:"mt-2 max-h-[66vh] overflow-y-auto overlay-scrollbar-target overlay-scrollbar-container",children:[Je?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,Je?null:s.jsx("div",{className:"space-y-4",children:Xt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Xt.map((He,yt)=>{const Et=(He.authorName||"?").charAt(0).toUpperCase(),Rt=yt===Xt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[Rt?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:He.avatarUrl?s.jsx("img",{src:He.avatarUrl,alt:He.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:Et})}),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:[He.authorName,He.authorLogin&&He.authorLogin!==He.authorName?` · @${He.authorLogin}`:""]}),He.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:ut(He.createdAt)}):null,s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs(be,{variant:"ghost",size:"sm",className:"h-6 px-0 has-[>svg]:px-0 sm:px-2 sm:has-[>svg]:px-2.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)] justify-start",onClick:()=>{ps(He)},"aria-label":c("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(A,{name:"ai-generate-2",className:"size-3.5"}),c("gitView.pr.actions.sendToAgent")]})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[He.context,He.path?` · ${He.path}`:"",He.line?`:${He.line}`:""]}),s.jsx(ya,{content:Vt(He.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",ts].filter(Boolean).join(" ")})]})]},He.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.comments.empty")})})]})]})})]})},eN=t=>{const e=ot.c(150),{open:n,onOpenChange:r,conflictFiles:a,directory:i,operation: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}=ft(),f=$t(tN),b=$t(sN),x=Ha(nN),y=Ha(rN),g=Fe(aN),[h,j]=l.useState(!1),[v,C]=l.useState(null),[k,w]=l.useState(null);let N,I;e[2]!==i||e[3]!==n||e[4]!==u?(N=()=>{!n||!i||(j(!0),w(null),C(null),Vb(i).then(ke=>{C(ke)}).catch(ke=>{const X=ke instanceof Error?ke.message:u("gitView.conflict.loadFailed");w(X)}).finally(()=>{j(!1)}))},I=[n,i,u],e[2]=i,e[3]=n,e[4]=u,e[5]=N,e[6]=I):(N=e[5],I=e[6]),l.useEffect(N,I);let T;e[7]!==v||e[8]!==i||e[9]!==o?(T=async()=>{if(!v)return null;const ke=o==="merge"?"merge":"rebase",X=v.headInfo||(o==="merge"?"MERGE_HEAD":"REBASE_HEAD"),ae=o==="merge"?"git commit --no-edit":"git rebase --continue",je=await wn("git.conflict.resolve.visible",{operation_label:ke,head_ref:X}),le=await wn("git.conflict.resolve.instructions",{operation_label:ke,directory:i,operation:o,head_info:v.headInfo||"N/A",continue_cmd:ae}),Ne=`${ke} conflict context (JSON)
|
|
42
|
-
${JSON.stringify({directory:i,operation:v.operation,headInfo:v.headInfo,statusPorcelain:v.statusPorcelain,unmergedFiles:v.unmergedFiles,diff:v.diff},null,2)}`;return{visibleText:je,instructionsText:le,payloadText:Ne}},e[7]=v,e[8]=i,e[9]=o,e[10]=T):T=e[10];const P=T;let D;e[11]!==c||e[12]!==r?(D=()=>{c(),r(!1)},e[11]=c,e[12]=r,e[13]=D):D=e[13];const S=D;let M;e[14]!==d||e[15]!==r?(M=()=>{d?.(),r(!1)},e[14]=d,e[15]=r,e[16]=M):M=e[16];const E=M;let R;e[17]!==P||e[18]!==b||e[19]!==d||e[20]!==r||e[21]!==g||e[22]!==x||e[23]!==y||e[24]!==u?(R=async()=>{const ke=await P();if(!ke){H.error(u("gitView.conflict.noDetailsAvailable"));return}if(!b){H.error(u("gitView.conflict.noActiveSession"),{description:u("gitView.conflict.noActiveSessionDescription")});return}x(ke.visibleText,"replace"),y([{text:ke.instructionsText,synthetic:!0},{text:ke.payloadText,synthetic:!0}]),g("chat"),d?.(),r(!1)},e[17]=P,e[18]=b,e[19]=d,e[20]=r,e[21]=g,e[22]=x,e[23]=y,e[24]=u,e[25]=R):R=e[25];const V=R;let B;e[26]!==P||e[27]!==i||e[28]!==d||e[29]!==r||e[30]!==f||e[31]!==g||e[32]!==u?(B=async()=>{const ke=await P();if(!ke){H.error(u("gitView.conflict.noDetailsAvailable"));return}f({directoryOverride:i,initialPrompt:ke.visibleText,syntheticParts:[{text:ke.instructionsText,synthetic:!0},{text:ke.payloadText,synthetic:!0}]}),g("chat"),d?.(),r(!1)},e[26]=P,e[27]=i,e[28]=d,e[29]=r,e[30]=f,e[31]=g,e[32]=u,e[33]=B):B=e[33];const $=B;let O,_,q,L,J,Z,ie,ne,me,pe,G,K,Q,W,de,ge,ve,te,he,ce,xe,se;if(e[34]!==v||e[35]!==m||e[36]!==b||e[37]!==S||e[38]!==E||e[39]!==V||e[40]!==$||e[41]!==h||e[42]!==k||e[43]!==r||e[44]!==n||e[45]!==o||e[46]!==u){const ke=u(o==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),X=v?.unmergedFiles||m;q=us,xe=n,se=r,_=ds,ce="max-w-md w-[calc(100vw-2rem)]",W="flex flex-col gap-4 overflow-hidden";let ae;e[69]===Symbol.for("react.memo_cache_sentinel")?(ae=s.jsx(A,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=ae):ae=e[69];const je=s.jsxs("div",{className:"flex items-center gap-2",children:[ae,s.jsx(ms,{children:u("gitView.conflict.detectedTitle",{operation:ke})})]});let le;e[70]!==o||e[71]!==u?(le=u("gitView.conflict.detectedDescription",{operation:o}),e[70]=o,e[71]=u,e[72]=le):le=e[72];let Ne;e[73]!==le?(Ne=s.jsx(Ns,{children:le}),e[73]=le,e[74]=Ne):Ne=e[74],e[75]!==je||e[76]!==Ne?(de=s.jsxs(hs,{children:[je,Ne]}),e[75]=je,e[76]=Ne,e[77]=de):de=e[77],e[78]!==h||e[79]!==u?(ge=h&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:u("gitView.conflict.loading")})]}),e[78]=h,e[79]=u,e[80]=ge):ge=e[80],e[81]!==k||e[82]!==u?(ve=k&&s.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:u("gitView.conflict.errorLoadingDetails",{message:k})}),e[81]=k,e[82]=u,e[83]=ve):ve=e[83],e[84]!==X||e[85]!==u?(te=X.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:X.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:X.map(iN)})})]}),e[84]=X,e[85]=u,e[86]=te):te=e[86],e[87]!==v||e[88]!==u?(he=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]=he):he=e[89],G="flex flex-col gap-2 pt-2";let Me;e[90]!==$?(Me=()=>{$()},e[90]=$,e[91]=Me):Me=e[91];const Ve=h||!v;let we;e[92]!==h?(we=h?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"add",className:"size-4"}),e[92]=h,e[93]=we):we=e[93];let ee;e[94]!==u?(ee=u("gitView.conflict.resolveNewSession"),e[94]=u,e[95]=ee):ee=e[95],e[96]!==Me||e[97]!==Ve||e[98]!==we||e[99]!==ee?(K=s.jsxs(be,{variant:"default",onClick:Me,disabled:Ve,className:"w-full gap-2",children:[we,ee]}),e[96]=Me,e[97]=Ve,e[98]=we,e[99]=ee,e[100]=K):K=e[100];let F;e[101]!==V?(F=()=>{V()},e[101]=V,e[102]=F):F=e[102];const U=h||!v||!b;let oe;e[103]!==h?(oe=h?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"chat-1",className:"size-4"}),e[103]=h,e[104]=oe):oe=e[104];let Te;e[105]!==u?(Te=u("gitView.conflict.resolveCurrentSession"),e[105]=u,e[106]=Te):Te=e[106],e[107]!==F||e[108]!==U||e[109]!==oe||e[110]!==Te?(Q=s.jsxs(be,{variant:"outline",onClick:F,disabled:U,className:"w-full gap-2",children:[oe,Te]}),e[107]=F,e[108]=U,e[109]=oe,e[110]=Te,e[111]=Q):Q=e[111],me="flex gap-2 pt-1";let Oe;e[112]!==u?(Oe=u("gitView.conflict.continueLater"),e[112]=u,e[113]=Oe):Oe=e[113],e[114]!==E||e[115]!==Oe?(pe=s.jsx(be,{variant:"ghost",size:"sm",onClick:E,className:"flex-1",children:Oe}),e[114]=E,e[115]=Oe,e[116]=pe):pe=e[116],O=be,L="destructive",J="sm",Z=S,ie="flex-1",ne=u("gitView.conflict.abortOperation",{operation:ke}),e[34]=v,e[35]=m,e[36]=b,e[37]=S,e[38]=E,e[39]=V,e[40]=$,e[41]=h,e[42]=k,e[43]=r,e[44]=n,e[45]=o,e[46]=u,e[47]=O,e[48]=_,e[49]=q,e[50]=L,e[51]=J,e[52]=Z,e[53]=ie,e[54]=ne,e[55]=me,e[56]=pe,e[57]=G,e[58]=K,e[59]=Q,e[60]=W,e[61]=de,e[62]=ge,e[63]=ve,e[64]=te,e[65]=he,e[66]=ce,e[67]=xe,e[68]=se}else O=e[47],_=e[48],q=e[49],L=e[50],J=e[51],Z=e[52],ie=e[53],ne=e[54],me=e[55],pe=e[56],G=e[57],K=e[58],Q=e[59],W=e[60],de=e[61],ge=e[62],ve=e[63],te=e[64],he=e[65],ce=e[66],xe=e[67],se=e[68];let ue;e[117]!==O||e[118]!==L||e[119]!==J||e[120]!==Z||e[121]!==ie||e[122]!==ne?(ue=s.jsx(O,{variant:L,size:J,onClick:Z,className:ie,children:ne}),e[117]=O,e[118]=L,e[119]=J,e[120]=Z,e[121]=ie,e[122]=ne,e[123]=ue):ue=e[123];let Y;e[124]!==me||e[125]!==pe||e[126]!==ue?(Y=s.jsxs("div",{className:me,children:[pe,ue]}),e[124]=me,e[125]=pe,e[126]=ue,e[127]=Y):Y=e[127];let Se;e[128]!==G||e[129]!==K||e[130]!==Q||e[131]!==Y?(Se=s.jsxs("div",{className:G,children:[K,Q,Y]}),e[128]=G,e[129]=K,e[130]=Q,e[131]=Y,e[132]=Se):Se=e[132];let fe;e[133]!==W||e[134]!==de||e[135]!==ge||e[136]!==ve||e[137]!==te||e[138]!==he||e[139]!==Se?(fe=s.jsxs("div",{className:W,children:[de,ge,ve,te,he,Se]}),e[133]=W,e[134]=de,e[135]=ge,e[136]=ve,e[137]=te,e[138]=he,e[139]=Se,e[140]=fe):fe=e[140];let Ce;e[141]!==_||e[142]!==ce||e[143]!==fe?(Ce=s.jsx(_,{className:ce,children:fe}),e[141]=_,e[142]=ce,e[143]=fe,e[144]=Ce):Ce=e[144];let Ie;return e[145]!==q||e[146]!==xe||e[147]!==se||e[148]!==Ce?(Ie=s.jsx(q,{open:xe,onOpenChange:se,children:Ce}),e[145]=q,e[146]=xe,e[147]=se,e[148]=Ce,e[149]=Ie):Ie=e[149],Ie};function tN(t){return t.openNewSessionDraft}function sN(t){return t.currentSessionId}function nN(t){return t.setPendingInputText}function rN(t){return t.setPendingSyntheticParts}function aN(t){return t.setActiveMainTab}function iN(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const oN=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:a})=>{const{t:i}=ft(),[o,c]=l.useState(!0),[d,p]=l.useState(!1),m=i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),u=async()=>{p(!0);try{await a(o),e(!1)}catch(b){const x=b instanceof Error?b.message:`Failed to ${n}`;H.error(x)}finally{p(!1)}},f=()=>{d||e(!1)};return s.jsx(us,{open:t,onOpenChange:d?void 0:e,children:s.jsxs(ds,{className:"max-w-md",children:[s.jsxs(hs,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),s.jsx(ms,{children:i("gitView.stash.title")})]}),s.jsx(Ns,{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(vs,{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(_s,{className:"gap-2",children:[s.jsx(be,{variant:"ghost",size:"sm",onClick:f,disabled:d,children:i("gitView.common.cancel")}),s.jsx(be,{variant:"default",size:"sm",onClick:u,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),i("gitView.common.processing")]}):i("gitView.stash.confirmButton",{operation:m})})]})]})})},lN=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:a,hasUnresolvedConflicts:i=!1,isLoading:o=!1})=>{const{t:c}=ft(),[d,p]=l.useState(null),m=t&&t.head,u=e&&(e.headName||e.onto),f=m?"merge":u?"rebase":null;if(!f)return null;const b=async()=>{p("continue");try{await n()}finally{p(null)}},x=async()=>{p("abort");try{await r()}finally{p(null)}},y=d!==null,g=c(f==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),h=f==="merge"?"git-merge":"git-branch";let j="";return t?j=t.message?c("gitView.operation.mergingMessage",{message:t.message}):c("gitView.operation.mergeInProgressWithHead",{head:t.head}):e&&(j=e.headName?c("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):c("gitView.operation.rebaseInProgress")),s.jsx("div",{className:"bg-[var(--status-warning-bg)] border border-[var(--status-warning)] rounded-lg p-3 mx-3 mt-3",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[s.jsx(A,{name:h,className:"size-4 text-[var(--status-warning)] shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:c("gitView.operation.inProgressTitle",{operation:g})}),j&&s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:j})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i&&a&&s.jsxs(be,{variant:"outline",size:"sm",onClick:a,disabled:y||o,className:"gap-1.5",children:[s.jsx(A,{name:"sparkling",className:"size-4"}),c("gitView.operation.resolveWithAi")]}),d!=="continue"&&s.jsxs(be,{variant:"ghost",size:"sm",onClick:x,disabled:y||o,className:"gap-1.5",children:[d==="abort"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"close",className:"size-4"}),c("gitView.operation.abort")]}),!i&&s.jsxs(be,{variant:"default",size:"sm",onClick:b,disabled:y||o,className:"gap-1.5",children:[d==="continue"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"check",className:"size-4"}),c("gitView.operation.continue")]})]}),i&&s.jsx("p",{className:"typography-micro text-[var(--status-warning)]",children:c("gitView.operation.resolveConflictsHint")})]})})},cN=t=>{const e=ot.c(104),{currentBranch:n,localBranches:r,remoteBranches:a,onMerge:i,onRebase:o,disabled:c,isOperating:d,operationLogs:p,onOperationComplete:m,mode:u,defaultTargetBranch:f}=t,b=c===void 0?!1:c,x=d===void 0?!1:d,y=p===void 0?[]:p,g=u===void 0?"dialog":u,{t:h}=ft(),[j,v]=l.useState(!1),[C,k]=l.useState("merge"),[w,N]=l.useState(null),[I,T]=l.useState(!1),[P,D]=l.useState(""),S=l.useRef(null),M=l.useRef(null),E=b||x,R=n||h("gitView.branch.currentBranchFallback"),V=y.length>0&&y.every(dN),B=y.some(uN);let $;e[0]===Symbol.for("react.memo_cache_sentinel")?($=()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight)},e[0]=$):$=e[0],l.useEffect($,[y]);let O;if(e[1]!==P||e[2]!==n||e[3]!==r||e[4]!==a){e:{const F=P.toLowerCase();let U;e[6]!==a?(U=new Set(a.map(mN).filter(Boolean)),e[6]=a,e[7]=U):U=e[7];const oe=U;let Te;e[8]!==n||e[9]!==oe?(Te=Pe=>Pe!==n&&!oe.has(Pe),e[8]=n,e[9]=oe,e[10]=Te):Te=e[10];const Oe=r.filter(Te);if(!F){O=Oe;break e}O=Oe.filter(Pe=>Pe.toLowerCase().includes(F))}e[1]=P,e[2]=n,e[3]=r,e[4]=a,e[5]=O}else O=e[5];const _=O;let q;if(e[11]!==P||e[12]!==a){e:{const F=P.toLowerCase();if(!F){q=a;break e}q=a.filter(U=>U.toLowerCase().includes(F))}e[11]=P,e[12]=a,e[13]=q}else q=e[13];const L=q;let J;e[14]!==f||e[15]!==r||e[16]!==a?(J=()=>f&&(a.includes(f)||r.includes(f))?f:null,e[14]=f,e[15]=r,e[16]=a,e[17]=J):J=e[17];const Z=J;let ie;e[18]!==Z||e[19]!==v?(ie=()=>{v(!0),N(Z()),k("merge"),D("")},e[18]=Z,e[19]=v,e[20]=ie):ie=e[20];const ne=ie;let me;e[21]===Symbol.for("react.memo_cache_sentinel")?(me=F=>{N(F),T(!1),D("")},e[21]=me):me=e[21];const pe=me;let G;e[22]!==i||e[23]!==o||e[24]!==C||e[25]!==w?(G=()=>{w&&(C==="merge"?i(w):o(w))},e[22]=i,e[23]=o,e[24]=C,e[25]=w,e[26]=G):G=e[26];const K=G;let Q;e[27]!==x||e[28]!==v?(Q=()=>{x||(N(null),k("merge"),D(""),v(!1))},e[27]=x,e[28]=v,e[29]=Q):Q=e[29];const W=Q,de=()=>{x&&!V||(V&&m?.(),N(null),k("merge"),D(""),v(!1))};let ge,ve;e[30]!==I?(ge=()=>{I||D("")},ve=[I],e[30]=I,e[31]=ge,e[32]=ve):(ge=e[31],ve=e[32]),l.useEffect(ge,ve);let te,he;e[33]!==g||e[34]!==Z||e[35]!==w?(te=()=>{g!=="inline"||w||N(Z())},he=[g,Z,w],e[33]=g,e[34]=Z,e[35]=w,e[36]=te,e[37]=he):(te=e[36],he=e[37]),l.useEffect(te,he);const se=x?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:M,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:s.jsx("div",{className:"space-y-2",children:y.map(pN)})}),V?g==="dialog"?s.jsx(_s,{children:s.jsx(be,{variant:"default",size:"sm",onClick:de,children:h(B?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(be,{variant:"default",size:"sm",onClick:de,children:h(B?"gitView.common.close":"gitView.common.done")})}):null]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:h("gitView.branch.operation")}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>k("merge"),className:ye("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",C==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"git-merge",className:ye("size-4",C==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:ye("typography-ui-label",C==="merge"?"text-foreground":"text-muted-foreground"),children:h("gitView.operation.merge")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:h("gitView.branch.mergeDescription")})]}),s.jsxs("button",{type:"button",onClick:()=>k("rebase"),className:ye("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",C==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"git-branch",className:ye("size-4",C==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:ye("typography-ui-label",C==="rebase"?"text-foreground":"text-muted-foreground"),children:h("gitView.operation.rebase")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:h("gitView.branch.rebaseDescription")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:C==="merge"?h("gitView.branch.branchToMergeInto",{branch:R}):h("gitView.branch.branchToRebaseOnto")}),s.jsxs(As,{open:I,onOpenChange:T,modal:!1,children:[s.jsx(Is,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"lg",className:"w-full justify-between",children:[s.jsx("span",{className:ye("truncate",!w&&"text-muted-foreground"),children:w||h("gitView.branch.selectBranch")}),s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),s.jsx(Ps,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:s.jsxs(qa,{className:"h-full min-h-0",children:[s.jsx(va,{ref:S,placeholder:h("gitView.branch.searchPlaceholder"),value:P,onValueChange:D,onKeyDown:fN}),s.jsxs(Ja,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(Ya,{children:h("gitView.branch.empty")}),_.length>0&&s.jsx(On,{heading:h("gitView.branch.localBranches"),children:_.map(F=>s.jsx(Pn,{onSelect:()=>pe(F),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:F})},`local-${F}`))}),_.length>0&&L.length>0?s.jsx(_a,{}):null,L.length>0&&s.jsx(On,{heading:h("gitView.branch.remoteBranches"),children:L.map(F=>s.jsx(Pn,{onSelect:()=>pe(F),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:F})},`remote-${F}`))})]})]})})]})]}),w?s.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:C==="merge"?s.jsxs(s.Fragment,{children:[h("gitView.branch.summaryMergePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:w})," ",h("gitView.branch.summaryMergeInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R})]}):s.jsxs(s.Fragment,{children:[h("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R})," ",h("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:w})]})})}):null,g==="dialog"?s.jsxs(_s,{className:"gap-2 pt-1",children:[s.jsx(be,{variant:"ghost",size:"sm",onClick:W,children:h("gitView.common.cancel")}),s.jsx(be,{variant:"default",size:"sm",onClick:K,disabled:!w,className:"gap-1.5",children:C==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"git-merge",className:"size-4"}),h("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"git-branch",className:"size-4"}),h("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(be,{variant:"destructive",size:"sm",onClick:W,disabled:E,children:h("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(be,{variant:"default",size:"sm",onClick:K,disabled:E||!w,children:h(C==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(g==="inline"){let F;e[38]!==h?(F=h("gitView.branch.updateTitle"),e[38]=h,e[39]=F):F=e[39];let U;e[40]!==F?(U=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:F}),e[40]=F,e[41]=U):U=e[41];let oe;e[42]!==h?(oe=h("gitView.branch.updateDescriptionPrefix"),e[42]=h,e[43]=oe):oe=e[43];let Te;e[44]!==R?(Te=s.jsx("span",{className:"font-mono text-foreground",children:R}),e[44]=R,e[45]=Te):Te=e[45];let Oe;e[46]!==oe||e[47]!==Te?(Oe=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[oe," ",Te,"."]}),e[46]=oe,e[47]=Te,e[48]=Oe):Oe=e[48];let Pe;e[49]!==U||e[50]!==Oe?(Pe=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[U,Oe]})}),e[49]=U,e[50]=Oe,e[51]=Pe):Pe=e[51];let z;e[52]!==se?(z=s.jsx("div",{className:"pt-3",children:se}),e[52]=se,e[53]=z):z=e[53];let De;return e[54]!==Pe||e[55]!==z?(De=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[Pe,z]}),e[54]=Pe,e[55]=z,e[56]=De):De=e[56],De}let ue;e[57]!==x?(ue=x?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"git-merge",className:"size-4"}),e[57]=x,e[58]=ue):ue=e[58];let Y;e[59]!==h?(Y=h("gitView.branch.mergeRebase"),e[59]=h,e[60]=Y):Y=e[60];let Se;e[61]!==Y?(Se=s.jsx("span",{children:Y}),e[61]=Y,e[62]=Se):Se=e[62];let fe;e[63]!==ne||e[64]!==E||e[65]!==ue||e[66]!==Se?(fe=s.jsx(Ct,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"sm",className:"gap-1.5",onClick:ne,disabled:E,children:[ue,Se]})}),e[63]=ne,e[64]=E,e[65]=ue,e[66]=Se,e[67]=fe):fe=e[67];let Ce;e[68]!==h?(Ce=h("gitView.branch.mergeRebaseTooltip"),e[68]=h,e[69]=Ce):Ce=e[69];let Ie;e[70]!==Ce?(Ie=s.jsx(It,{sideOffset:8,children:Ce}),e[70]=Ce,e[71]=Ie):Ie=e[71];let ke;e[72]!==fe||e[73]!==Ie?(ke=s.jsxs(kt,{children:[fe,Ie]}),e[72]=fe,e[73]=Ie,e[74]=ke):ke=e[74];let X;e[75]!==de||e[76]!==v?(X=F=>{F?v(!0):de()},e[75]=de,e[76]=v,e[77]=X):X=e[77];let ae;e[78]!==h?(ae=h("gitView.branch.updateTitle"),e[78]=h,e[79]=ae):ae=e[79];let je;e[80]!==ae?(je=s.jsx(ms,{children:ae}),e[80]=ae,e[81]=je):je=e[81];let le;e[82]!==B||e[83]!==x||e[84]!==C||e[85]!==V||e[86]!==h||e[87]!==R?(le=x?h(V?B?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":C==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):s.jsxs(s.Fragment,{children:[h("gitView.branch.dialogDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R}),"."]}),e[82]=B,e[83]=x,e[84]=C,e[85]=V,e[86]=h,e[87]=R,e[88]=le):le=e[88];let Ne;e[89]!==le?(Ne=s.jsx(Ns,{children:le}),e[89]=le,e[90]=Ne):Ne=e[90];let Me;e[91]!==je||e[92]!==Ne?(Me=s.jsxs(hs,{children:[je,Ne]}),e[91]=je,e[92]=Ne,e[93]=Me):Me=e[93];let Ve;e[94]!==se||e[95]!==Me?(Ve=s.jsxs(ds,{className:"max-w-md",children:[Me,se]}),e[94]=se,e[95]=Me,e[96]=Ve):Ve=e[96];let we;e[97]!==j||e[98]!==X||e[99]!==Ve?(we=s.jsx(us,{open:j,onOpenChange:X,children:Ve}),e[97]=j,e[98]=X,e[99]=Ve,e[100]=we):we=e[100];let ee;return e[101]!==ke||e[102]!==we?(ee=s.jsxs(s.Fragment,{children:[ke,we]}),e[101]=ke,e[102]=we,e[103]=ee):ee=e[103],ee};function dN(t){return t.status==="done"||t.status==="error"}function uN(t){return t.status==="error"}function mN(t){return t.slice(t.indexOf("/")+1)}function pN(t,e){return s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"mt-0.5 shrink-0",children:[t.status==="running"&&s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),t.status==="done"&&s.jsx(A,{name:"check",className:"size-3.5 text-success"}),t.status==="error"&&s.jsx(A,{name:"close",className:"size-3.5 text-destructive"}),t.status==="pending"&&s.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),s.jsx("span",{className:ye("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 fN(t){return t.stopPropagation()}const hN=({runMutation:t,onMutationComplete:e,onMutationError:n,onPathsComplete:r,scheduleFlush:a})=>{const i=[];let o=!1;return{enqueue:d=>{const p=i[i.length-1];if(p?.directory===d.directory&&p.direction===d.direction){d.paths.forEach(m=>p.paths.add(m));return}i.push(d)},flush:()=>{if(o)return;const d=i.shift();if(!d)return;o=!0;const p={directory:d.directory,direction:d.direction,paths:Array.from(d.paths),rollback:d.rollback};(async()=>{try{await t(p),e(p)}catch(m){n(p,m)}finally{r(p.paths),o=!1,i.length>0&&a()}})()},clear:()=>{i.length=0},size:()=>i.length,isRunning:()=>o}},Qm="oc.git.actionTab",gN=15e3,xN=t=>t==="commit"||t==="branch"||t==="pr",mg="gitmojiCache",bN=1e3*60*60*24*7,pg="1",yN=40,vN=20,wN="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",Xm={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:"},fg=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},jN=()=>{if(typeof window>"u")return null;try{const t=localStorage.getItem(mg);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==pg||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(fg),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},NN=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:pg};localStorage.setItem(mg,JSON.stringify(e))}catch{return}},SN=t=>Date.now()-t.fetchedAt<bN,kN=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,a=n.match(r);if(a){const c=a[1],d=Xm[c];if(d)return e.find(p=>p.code===d)||null}const i=n.split(" ")[0],o=Xm[i];return o&&e.find(c=>c.code===o)||null},Zm=new Map,Jr=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),ep=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},CN=t=>{const e=t.working_dir?.trim(),n=t.index?.trim();return!!(e||n==="?")},hg=()=>{const{t}=ft(),{git:e}=_n(),n=na(),[r,a]=l.useState(null),[i,o]=l.useState(!1),c=$t(Re=>Re.currentSessionId),d=$t(Re=>Re.newSessionDraft),p=$t(Re=>Re.setDraftBootstrapPendingDirectory),m=$t(Re=>Re.worktreeMetadata),u=$t(Re=>Re.availableWorktrees),f=Jr(n),b=l.useMemo(()=>{if(!f)return;const Re=u.find(Xe=>Jr(Xe.path)===f);if(Re)return Re;for(const Xe of m.values())if(Jr(Xe.path)===f)return Xe},[u,f,m]),x=l.useMemo(()=>{if(c)return m.get(c)??b;if(d?.open)return b},[c,b,d?.open,m]),{profiles:y,globalIdentity:g,defaultGitIdentityId:h,loadProfiles:j,loadGlobalIdentity:v,loadDefaultGitIdentityId:C}=tr(Gn(Re=>({profiles:Re.profiles,globalIdentity:Re.globalIdentity,defaultGitIdentityId:Re.defaultGitIdentityId,loadProfiles:Re.loadProfiles,loadGlobalIdentity:Re.loadGlobalIdentity,loadDefaultGitIdentityId:Re.loadDefaultGitIdentityId}))),k=Qd(n??null),w=Zl(n??null),N=ph(Re=>c?Re.getAttachment(c):void 0),I=N?zb(N):[],T=N&&!N.degraded&&!N.legacy?N.worktreeRoot??void 0:void 0,P=aj(n,x,w?.current??void 0),D=Xd(n??null),S=Ub(n??null),M=Wb(n??null),E=Zd(n??null),R=Kb(n??null),V=Ys(Re=>Re.setActiveDirectory),B=Ys(Re=>Re.fetchAll),$=Ys(Re=>Re.ensureAll),O=Ys(Re=>Re.fetchStatus),_=Ys(Re=>Re.fetchBranches),q=Ys(Re=>Re.fetchLog),L=Ys(Re=>Re.fetchIdentity),J=Ys(Re=>Re.prefetchDiffs),Z=Ys(Re=>Re.setLogMaxCount),ie=Ys(Re=>Re.moveStatusPathsOptimistically),ne=Ys(Re=>Re.restoreStatus),me=Ys(Re=>Re.bumpIndexRevision),pe=Fe(Re=>Re.isMobile),G=Fe(Re=>Re.openContextDiff),K=Fe(Re=>Re.navigateToDiff),Q=Fe(Re=>Re.setRightSidebarOpen),W=l.useRef(null),de=l.useRef(null),ge=l.useRef(null),ve=l.useRef(null),te=l.useCallback(()=>{de.current!==null&&(window.clearTimeout(de.current),de.current=null)},[]),he=l.useCallback(Re=>{te(),de.current=window.setTimeout(()=>{de.current=null,Jr(Re)===Jr(n)&&O(Re,e,{silent:!0})},gN)},[te,n,O,e]);l.useEffect(()=>te,[te]);const ce=l.useCallback(()=>{ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null)},[]),xe=l.useCallback(()=>{ge.current===null&&(ge.current=window.setTimeout(()=>{ge.current=null,ve.current?.()},0))},[]),se=l.useCallback(async(Re,Xe,tt)=>{if(Xe==="stage"){if(e.stageGitFiles){await e.stageGitFiles(Re,tt);return}await Promise.all(tt.map(mt=>e.stageGitFile(Re,mt)));return}if(e.unstageGitFiles){await e.unstageGitFiles(Re,tt);return}await Promise.all(tt.map(mt=>e.unstageGitFile(Re,mt)))},[e]),ue=l.useMemo(()=>hN({runMutation:({directory:Re,direction:Xe,paths:tt})=>se(Re,Xe,tt),onMutationComplete:({directory:Re})=>{me(Re),he(Re)},onMutationError:({directory:Re,direction:Xe,rollback:tt},mt)=>{tt?.(),me(Re),he(Re);const At=t(Xe==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");H.error(mt instanceof Error?mt.message:At)},onPathsComplete:Re=>{Ge(Xe=>{const tt=new Set(Xe);return Re.forEach(mt=>tt.delete(mt)),tt})},scheduleFlush:xe}),[me,se,xe,he,t]);l.useEffect(()=>(ve.current=ue.flush,()=>{ve.current=null}),[ue]),l.useEffect(()=>()=>ue.clear(),[ue]),l.useEffect(()=>ce,[ce]),l.useEffect(()=>{if(!n){a(null),o(!1);return}let Re=!1,Xe=null;const tt=async()=>{try{const mt=await Gb(n);if(Re)return;a(mt.status),mt.status==="pending"&&(Xe=window.setTimeout(()=>{tt()},500))}catch{Re||a(null)}};return tt(),()=>{Re=!0,Xe!==null&&window.clearTimeout(Xe)}},[n]),l.useEffect(()=>{const Re=W.current;W.current=r,!(!n||!e)&&(Re==="pending"&&r==="ready"&&(o(!0),B(n,e).finally(()=>{window.setTimeout(()=>{o(!1)},1200)})),r==="failed"&&(p(null),o(!1)))},[n,B,e,p,r]);const Y=Jr(d?.bootstrapPendingDirectory??null),Se=!!(n&&Y&&Y===Jr(n)),Ce=!!(n&&(r==="pending"||Se))||i,Ie=l.useMemo(()=>n?Zm.get(n)??null:null,[n]),ke=wt(Re=>Re.settingsGitmojiEnabled),[X,ae]=l.useState(null);l.useEffect(()=>{const Re=T||P?.projectDirectory;if(!Re){ae(null);return}let Xe=!1;return No(Re).then(tt=>{if(Xe)return;const mt=tt.trim();ae(mt&&mt!=="HEAD"?mt:null)}).catch(()=>{Xe||ae(null)}),()=>{Xe=!0}},[T,P?.projectDirectory]);const[je,le]=l.useState(Ie?.commitMessage??""),[Ne,Me]=l.useState([]),[Ve,we]=l.useState(!1),ee=l.useRef(null),[F,U]=l.useState(null),[oe,Te]=l.useState(!1),[Oe,Pe]=l.useState(null),[z,De]=l.useState(25),[Qe,et]=l.useState(!1),{triggerFireworks:Ze}=ej(),We=l.useRef(new Map),it=l.useRef(0),qe=l.useCallback(()=>{it.current+=1,et(!0)},[]),st=l.useCallback(()=>{it.current=Math.max(0,it.current-1),it.current===0&&et(!1)},[]),[Je,Be]=l.useState(new Set),[nt,Ge]=l.useState(new Set),[at,Ae]=l.useState(!1),[Le,ze]=l.useState(0),[Ke,lt]=l.useState(!1),[xt,dt]=l.useState(Ie?.generatedHighlights??[]),ut=nt.size>0||ue.size()>0||ue.isRunning(),Nt=l.useCallback(()=>{const Re=ee.current;Re&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{Re.scrollTo({top:Re.scrollHeight,behavior:"smooth"})})})},[]),ts=T||P?.projectDirectory||null,Vt=w?.current||null,Xt=l.useMemo(()=>{const Re=w?.tracking;return Re?Re.startsWith("origin/"):!0},[w?.tracking]),ht=l.useMemo(()=>{const Re=P?.createdFromBranch,Xe=typeof Re=="string"?Re.trim():"",tt=typeof w?.current=="string"?w.current.trim():"",mt=typeof X=="string"?X.trim():"";return Xe?Xe===tt&&Xe.startsWith("opencode/")&&mt.length>0&&mt!==Xe?mt:Xe:mt||tt||"HEAD"},[P?.createdFromBranch,w,X]),Bt=l.useCallback(()=>{dt([])},[]),[Zt,gs]=l.useState(new Set),[rs,ps]=l.useState(new Map),[Ut,Ye]=l.useState(new Set),[Tt,Kt]=l.useState(null),[St,es]=l.useState(null),[ss,Ms]=l.useState([]),[xs,Bs]=l.useState(""),[ws,xn]=l.useState(!1),Qs=l.useMemo(()=>[{id:"commit",label:t("gitView.tabs.commit"),icon:s.jsx(A,{name:"git-commit",className:"h-3.5 w-3.5"})},{id:"branch",label:t("gitView.tabs.update"),icon:s.jsx(A,{name:"git-merge",className:"h-3.5 w-3.5"})},{id:"pr",label:t("gitView.tabs.pr"),icon:s.jsx(A,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],[t]),[Wt,qt]=l.useState(()=>{if(typeof window>"u")return"commit";const Re=window.localStorage.getItem(Qm);return Re==="worktree"?"branch":xN(Re)?Re:"commit"}),[re,vt]=l.useState([]),[Ft,ct]=l.useState(null),[ls,cs]=l.useState(null),[He,yt]=l.useState([]),[Et,Rt]=l.useState(!1),[Yt,Ot]=l.useState([]),[Os,Ds]=l.useState("merge"),Ts=l.useMemo(()=>c?`openchamber.conflict:${c}`:null,[c]),Vs=l.useCallback((Re,Xe,tt)=>{if(!Ts||typeof window>"u")return;const mt={directory:Re,conflictFiles:Xe,operation:tt};window.localStorage.setItem(Ts,JSON.stringify(mt))},[Ts]),js=l.useCallback(()=>{!Ts||typeof window>"u"||window.localStorage.removeItem(Ts)},[Ts]);l.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(Qm,Wt)},[Wt]),l.useEffect(()=>{if(!Ts||typeof window>"u"||!n)return;const Re=window.localStorage.getItem(Ts);if(Re)try{const Xe=JSON.parse(Re);if(Xe.directory!==n){window.localStorage.removeItem(Ts);return}Ot(Xe.conflictFiles??[]),Ds(Xe.operation??"merge"),Rt(!0)}catch{window.localStorage.removeItem(Ts)}},[Ts,n]);const[Bn,bn]=l.useState(!1),[mn,lr]=l.useState("merge"),[Us,yn]=l.useState(""),ir=l.useCallback(Re=>{En(Re).then(Xe=>{if(Xe.ok){H.success(t("gitView.toast.commitHashCopied"));return}H.error(t("gitView.toast.copyFailed"))})},[t]),Mn=l.useCallback(Re=>{gs(Xe=>{const tt=new Set(Xe);return tt.has(Re)?tt.delete(Re):tt.add(Re),tt})},[]);l.useEffect(()=>{if(!n||!e)return;const Re=Array.from(Zt).filter(Xe=>!rs.has(Xe)&&!Ut.has(Xe));if(Re.length!==0){Ye(Xe=>{const tt=new Set(Xe);for(const mt of Re)tt.add(mt);return tt});for(const Xe of Re)e.getCommitFiles(n,Xe).then(tt=>{ps(mt=>new Map(mt).set(Xe,tt.files))}).catch(tt=>{console.error("Failed to fetch commit files:",tt),ps(mt=>new Map(mt).set(Xe,[]))}).finally(()=>{Ye(tt=>{const mt=new Set(tt);return mt.delete(Xe),mt})})}},[Zt,n,e,rs,Ut]),l.useEffect(()=>{n&&Zm.set(n,{directory:n,commitMessage:je,generatedHighlights:xt})},[je,n,xt]),l.useEffect(()=>{j(),v(),C()},[j,v,C]),l.useEffect(()=>{if(!n||!e?.getRemoteUrl){es(null);return}e.getRemoteUrl(n).then(es).catch(()=>es(null))},[n,e]);const Rr=l.useCallback(async()=>{if(!n||!e?.getRemotes){vt([]);return}try{const Re=await e.getRemotes(n);vt(Re)}catch{vt([])}},[n,e]);l.useEffect(()=>{Rr()},[Rr]),l.useEffect(()=>{if(!ke){Ms([]);return}let Re=!1;const Xe=jN();return Xe&&(Ms(Xe.gitmojis),SN(Xe))?()=>{Re=!0}:((async()=>{try{const mt=await fetch(wN);if(!mt.ok)throw new Error(`Failed to load gitmojis: ${mt.statusText}`);const At=await mt.json(),zt=Array.isArray(At.gitmojis)?At.gitmojis.filter(fg):[];Re||(Ms(zt),NN(zt))}catch(mt){Re||console.warn("Failed to load gitmoji list:",mt)}})(),()=>{Re=!0})},[ke]),l.useEffect(()=>{n&&(V(n),$(n,e))},[n,V,$,e]),l.useEffect(()=>{if(n)return Dr.onGitRefreshHint(Re=>{Jr(Re.directory)===Jr(n)&&O(n,e)})},[n,O,e]);const $s=l.useCallback(async(Re=!0)=>{if(n)try{await Promise.all([O(n,e),_(n,e)])}catch(Xe){if(Re){const tt=Xe instanceof Error?Xe.message:t("gitView.toast.refreshRepositoryFailed");H.error(tt)}}},[n,e,O,_,t]),Ks=l.useCallback(async()=>{n&&await q(n,e,z)},[n,e,q,z]),Ue=l.useCallback(async()=>{n&&await L(n,e)},[n,e,L]);l.useEffect(()=>{if(!n||!e?.hasLocalIdentity||k!==!0)return;const Re=typeof h=="string"?h.trim():"";if(!Re||Re==="global"||We.current.get(n)===Re)return;let tt=!1;return(async()=>{try{const At=await e.hasLocalIdentity?.(n);if(tt||At===!0)return;qe(),await e.setGitIdentity(n,Re),We.current.set(n,Re),await Ue()}catch(At){console.warn("Failed to auto-apply default git identity:",At)}finally{tt||st()}})(),()=>{tt=!0}},[qe,n,h,st,e,k,Ue]);const Pt=l.useMemo(()=>{if(!w)return[];const Re=w.files??[],Xe=new Map;for(const tt of Re)Xe.set(tt.path,tt);return Array.from(Xe.values()).sort((tt,mt)=>tt.path.localeCompare(mt.path))},[w]),Ht=l.useMemo(()=>Pt.filter(ep),[Pt]),ns=l.useMemo(()=>Pt.filter(CN),[Pt]);l.useEffect(()=>{if(!n||Pt.length===0)return;const Re=[],Xe=new Set,tt=At=>{!At||Xe.has(At)||(Xe.add(At),Re.push(At))};if(Ht.forEach(At=>tt(At.path)),Ne.forEach(tt),Pt.slice(0,vN).forEach(At=>tt(At.path)),Re.length===0)return;const mt=window.setTimeout(()=>{J(n,e,Re,{maxFiles:yN})},120);return()=>{window.clearTimeout(mt)}},[Pt,n,e,J,Ht,Ne]);const qs=async(Re,Xe)=>{if(n){U(Re);try{const tt=mt=>{const At=`${mt.name}/`,zt=w?.tracking?.startsWith(At)?w.tracking.slice(At.length):void 0;return{remote:mt.name,branch:zt,rebase:!0}};if(Re==="fetch"){if(!Xe)throw new Error("No remote available for fetch");await e.gitFetch(n,{remote:Xe.name}),H.success(t("gitView.toast.fetchedFromRemote",{name:Xe.name}))}else if(Re==="pull"){if(!Xe)throw new Error("No remote available for pull");const mt=await e.gitPull(n,tt(Xe));H.success(mt.files.length===1?t("gitView.toast.pulledFilesSingle",{count:mt.files.length,name:Xe.name}):t("gitView.toast.pulledFilesPlural",{count:mt.files.length,name:Xe.name}))}else if(Re==="push")await e.gitPush(n),H.success(t("gitView.toast.pushedToUpstream"));else if(Re==="sync"){if(!Xe)throw new Error("No remote available for sync");let mt=0,At=!1;await e.gitFetch(n,{remote:Xe.name});const zt=await e.getGitStatus(n);if((zt.behind??0)>0){if((zt.files?.length??0)>0){H.error(t("gitView.toast.commitOrStashBeforeSync"));return}mt=(await e.gitPull(n,tt(Xe))).files.length}((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),At=!0),mt>0&&At?H.success(mt===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:mt,name:Xe.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:mt,name:Xe.name})):mt>0?H.success(mt===1?t("gitView.toast.pulledFilesSingle",{count:mt,name:Xe.name}):t("gitView.toast.pulledFilesPlural",{count:mt,name:Xe.name})):At?H.success(t("gitView.toast.pushedToUpstream")):H.success(t("gitView.toast.alreadyUpToDate"))}await $s(!1),await Ks()}catch(tt){const mt=tt instanceof Error?tt.message:t("gitView.toast.syncActionFailed",{action:Re==="sync"?t("gitView.sync.syncChanges"):Re==="pull"?t("gitView.sync.pull"):Re});H.error(mt)}finally{U(null)}}},Gs=l.useCallback(async Re=>{if(!n)return;const Xe=Re.name.trim();if(!Xe){H.error(t("gitView.toast.remoteNameRequired"));return}if(Xe==="origin"){H.error(t("gitView.toast.cannotRemoveOriginRemote"));return}ct(Xe);try{await e.removeRemote(n,{remote:Xe}),H.success(t("gitView.toast.removedRemote",{name:Xe})),await Promise.all([$s(!1),Rr()])}catch(tt){const mt=tt instanceof Error?tt.message:`Failed to remove ${Xe}`;H.error(mt)}finally{ct(null)}},[n,e,Rr,$s,t]),Ls=async(Re={})=>{if(!n)return;if(!je.trim()){H.error(t("gitView.toast.enterCommitMessage"));return}const Xe=Ht.map(mt=>mt.path).sort();if(Xe.length===0){H.error(t("gitView.toast.stageFileToCommit"));return}const tt=Re.pushAfter?"commitAndPush":"commit";Pe(tt);try{if(await e.createGitCommit(n,je.trim(),{files:Xe,stageFiles:[]}),me(n),H.success(t("gitView.toast.commitCreated")),le(""),Bt(),await $s(),Re.pushAfter){U("sync");const mt=w?.tracking?.split("/")[0],At=hn.find(Gr=>Gr.name===mt)??hn[0];if(!At)throw new Error("No remote available for sync");const zt=`${At.name}/`,zs=w?.tracking?.startsWith(zt)?w.tracking.slice(zt.length):void 0;let Fs=0,zn=!1;await e.gitFetch(n,{remote:At.name}),((await e.getGitStatus(n)).behind??0)>0&&(Fs=(await e.gitPull(n,{remote:At.name,branch:zs,rebase:!0})).files.length),((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),zn=!0),Fs>0&&zn?H.success(Fs===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:Fs,name:At.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:Fs,name:At.name})):Fs>0?H.success(Fs===1?t("gitView.toast.pulledFilesSingle",{count:Fs,name:At.name}):t("gitView.toast.pulledFilesPlural",{count:Fs,name:At.name})):zn?H.success(t("gitView.toast.pushedToUpstream")):H.success(t("gitView.toast.alreadyUpToDate")),Ze(),await $s(!1)}else await $s(!1);await Ks(),ze(mt=>mt+1)}catch(mt){const At=mt instanceof Error?mt.message:t("gitView.toast.createCommitFailed");H.error(At)}finally{Pe(null),Re.pushAfter&&U(null)}},sn=l.useCallback(async()=>{if(!n)return;const Re=Ht.map(Xe=>Xe.path).sort();if(Re.length===0){H.error(t("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:n,selectedFiles:Re.length}),lt(!0);try{const{message:Xe}=await Hb(n,Re),tt=Xe.subject?.trim()??"",mt=Array.isArray(Xe.highlights)?Xe.highlights:[];if(tt){let At=tt;if(ke&&ss.length>0){const zt=kN(tt,ss);if(zt){const{code:zs,emoji:Fs}=zt;!tt.startsWith(zs)&&!tt.startsWith(Fs)&&(At=`${zs} ${tt}`)}}le(At)}dt(mt),Nt()}catch(Xe){console.error("[git-generation][browser] GitView generate handler failed",{message:Xe instanceof Error?Xe.message:String(Xe),error:Xe});const tt=Xe instanceof Error?Xe.message:t("gitView.toast.generateCommitMessageFailed");H.error(tt)}finally{lt(!1)}},[n,Ht,ke,ss,Nt,t]),nn=Re=>Re.reason==="attention"?`${Re.attentionReason} in progress`:Re.reason==="missing"?"worktree is missing":"worktree is invalid",qn=async(Re,Xe)=>{if(!n||!w)return;const tt=pc(N);if(tt.length>0){H.error(t("gitView.toast.cannotCreateBranch",{reason:nn(tt[0])}));return}const mt=w.current??null,At=Xe?.name??"origin";try{await e.createBranch(n,Re,mt??"HEAD"),H.success(t("gitView.toast.createdBranch",{name:Re})),await e.checkoutBranch(n,Re);let zt=!1;try{await e.gitPush(n,{remote:At,branch:Re,options:["--set-upstream"]}),zt=!0}catch(zs){const Fs=zs instanceof Error?zs.message:`Unable to push new branch to ${At}.`;H.warning(t("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",Fs]})})}await $s(),await Ks(),zt&&H.success(t("gitView.toast.upstreamSet",{branch:Re,remote:At}))}catch(zt){const zs=zt instanceof Error?zt.message:t("gitView.toast.createBranchFailed");throw H.error(zs),zt}},Jn=async(Re,Xe)=>{if(!n)return;const tt=pc(N);if(tt.length>0){H.error(t("gitView.toast.cannotRenameBranch",{reason:nn(tt[0])}));return}try{await e.renameBranch(n,Re,Xe),H.success(t("gitView.toast.renamedBranch",{oldName:Re,newName:Xe})),await $s(),await Ks()}catch(mt){const At=mt instanceof Error?mt.message:t("gitView.toast.renameBranchFailed",{oldName:Re,newName:Xe});H.error(At)}},aa=async Re=>{if(!n)return;const Xe=pc(N);if(Xe.length>0){H.error(t("gitView.toast.cannotCheckout",{reason:nn(Xe[0])}));return}const tt=Re.replace(/^remotes\//,"");if(w?.current!==tt)try{await e.checkoutBranch(n,tt),H.success(t("gitView.toast.checkedOut",{name:tt})),await $s(),await Ks()}catch(mt){const At=mt instanceof Error?mt.message:t("gitView.toast.checkoutFailed",{name:tt});H.error(At)}},Ur=async Re=>{if(n){qe();try{await e.setGitIdentity(n,Re.id),H.success(t("gitView.toast.appliedIdentity",{name:Re.name})),await Ue()}catch(Xe){const tt=Xe instanceof Error?Xe.message:t("gitView.toast.applyIdentityFailed");H.error(tt)}finally{st()}}},Nn=l.useMemo(()=>D?.all?D.all.filter(Re=>!Re.startsWith("remotes/")).sort():[],[D]),cn=l.useMemo(()=>D?.all?D.all.filter(Re=>Re.startsWith("remotes/")).map(Re=>Re.replace(/^remotes\//,"")).sort():[],[D]),hn=l.useMemo(()=>{if(re.length>0)return re;const Re=new Set,Xe=w?.tracking?.trim();Xe&&Xe.includes("/")&&Re.add(Xe.split("/")[0]);for(const tt of cn){const mt=tt.indexOf("/");mt>0&&Re.add(tt.slice(0,mt))}return Re.size===0&&St&&Re.add("origin"),Array.from(Re).map(tt=>({name:tt,fetchUrl:St??"",pushUrl:St??""}))},[re,cn,St,w?.tracking]),Sn=l.useMemo(()=>{const Re=new Set(hn.map(At=>At.name)),Xe=At=>{if(!At)return"";let zt=At.trim();if(!zt||zt==="HEAD")return"";if(Nn.includes(zt))return zt;zt.startsWith("refs/heads/")&&(zt=zt.slice(11)),zt.startsWith("heads/")&&(zt=zt.slice(6)),zt.startsWith("remotes/")&&(zt=zt.slice(8));const zs=zt.indexOf("/");if(zs>0){const Fs=zt.slice(0,zs);if(Re.has(Fs)){const zn=zt.slice(zs+1).trim();zn&&(zt=zn)}}return zt},tt=Xe(typeof P?.createdFromBranch=="string"?P.createdFromBranch:"");if(tt)return tt;const mt=Xe(typeof X=="string"?X:"");return mt||(Nn.includes("main")?"main":Nn.includes("master")?"master":Nn.includes("develop")?"develop":"main")},[hn,Nn,X,P?.createdFromBranch]),cr=l.useMemo(()=>hn.map(tt=>tt.name).map(tt=>`${tt}/${Sn}`).find(tt=>cn.includes(tt))??Sn,[Sn,hn,cn]),dr=l.useMemo(()=>{const Re=new Map;g&&Re.set(g.id,g);let Xe=null;if(St)try{let tt=St.trim();tt.startsWith("git@")&&(tt=`https://${tt.slice(4).replace(":","/")}`),tt.endsWith(".git")&&(tt=tt.slice(0,-4));const mt=new URL(tt);Xe=mt.hostname+mt.pathname}catch{}for(const tt of y){if(tt.authType!=="token"){Re.set(tt.id,tt);continue}const mt=tt.host;if(!mt){Re.set(tt.id,tt);continue}if(!mt.includes("/")){Re.set(tt.id,tt);continue}Xe&&Xe===mt&&Re.set(tt.id,tt)}return Array.from(Re.values())},[y,g,St]),an=l.useMemo(()=>{if(M?.userName&&M?.userEmail){const Re=y.find(Xe=>Xe.userName===M.userName&&Xe.userEmail===M.userEmail);return Re||(g&&g.userName===M.userName&&g.userEmail===M.userEmail?g:{id:"local-config",name:M.userName,userName:M.userName,userEmail:M.userEmail,sshKey:M.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return g??null},[M,y,g]),Fr=Ht.length,Yn=E||F!==null||Oe!==null,Qn=w?.current??null,ei=!!(P&&ts&&Vt&&Xt),wa=!!(n&&Qn),ti=!!Qn,Xn=ei&&ts&&Vt&&P?{repoRoot:ts,sourceBranch:Vt,worktreeMetadata:P}:null,Wr=l.useMemo(()=>!wa||!n||!Qn?null:{directory:n,branch:Qn},[wa,Qn,n]);l.useEffect(()=>{if(!n||!e||!S?.all?.length||!Qn||!Sn||Qn===Sn){Kt(null);return}let Re=!1;return(async()=>{try{const tt=await e.getGitLog(n,{from:Sn,to:"HEAD",maxCount:z});if(Re)return;const mt=new Set((tt?.all??[]).map(zt=>zt.hash).filter(zt=>typeof zt=="string"&&zt.length>0));if(mt.size===0){Kt(null);return}const At=S.all.findIndex(zt=>!mt.has(zt.hash));if(At===0){Kt(null);return}if(At===-1){Kt({insertBeforeIndex:S.all.length,branchName:Qn,direction:"up"});return}Kt({insertBeforeIndex:At,branchName:Qn,direction:"up"})}catch{Re||Kt(null)}})(),()=>{Re=!0}},[Sn,Qn,n,e,S,z]);const Js=l.useCallback((Re,Xe)=>{if(!n||Re.length===0)return;const tt=Array.from(new Set(Re));Ge(At=>{const zt=new Set(At);return tt.forEach(zs=>zt.add(zs)),zt});const mt=ie(n,tt,Xe);ue.enqueue({directory:n,direction:Xe,paths:new Set(tt),rollback:()=>ne(n,mt)}),xe()},[n,ue,ie,ne,xe]),Vn=l.useCallback(async Re=>{if(n){Be(Xe=>{const tt=new Set(Xe);return tt.add(Re),tt});try{await e.revertGitFile(n,Re,{scope:"working"}),H.success(t("gitView.toast.revertedFile",{path:Re})),await $s(!1)}catch(Xe){const tt=Xe instanceof Error?Xe.message:t("gitView.toast.revertFailed");H.error(tt)}finally{Be(Xe=>{const tt=new Set(Xe);return tt.delete(Re),tt})}}},[n,$s,e,t]),ja=l.useCallback(async Re=>{if(!n||Re.length===0||at)return;const Xe=Array.from(new Set(Re)),tt=new Set(Ht.map(zt=>zt.path)),mt=Xe.some(zt=>tt.has(zt));Ae(!0),Be(zt=>{const zs=new Set(zt);return Xe.forEach(Fs=>zs.add(Fs)),zs});const At=[];try{if(await Promise.all(Xe.map(async zt=>{try{await e.revertGitFile(n,zt)}catch(zs){At.push({path:zt,message:zs instanceof Error?zs.message:t("gitView.toast.revertFailed")})}})),mt&&At.length<Xe.length&&me(n),await $s(!1),At.length===0)H.success(Xe.length===1?t("gitView.toast.revertedFilesSingle",{count:Xe.length}):t("gitView.toast.revertedFilesPlural",{count:Xe.length}));else if(At.length===Xe.length)H.error(At[0]?.message||t("gitView.toast.revertFailed"));else{const zt=Xe.length-At.length;H.warning(zt===1?t("gitView.toast.revertedSomeSingle",{success:zt,failed:At.length}):t("gitView.toast.revertedSomePlural",{success:zt,failed:At.length}))}}finally{Be(zt=>{const zs=new Set(zt);return Xe.forEach(Fs=>zs.delete(Fs)),zs}),Ae(!1)}},[me,n,e,at,$s,Ht,t]),ia=l.useCallback((Re,Xe)=>{if(n&&!pe){G(n,Re,Xe);return}K(Re,Xe),pe&&Q(!1)},[n,pe,K,G,Q]),Nr=l.useCallback(()=>Te(!0),[]),si=l.useMemo(()=>{const Re=[];return Ht.length>0&&Re.push({id:"staged",title:t("gitView.changes.stagedTitle"),entries:Ht,actionSymbol:"-",actionAllLabel:t("gitView.changes.unstageAllAria"),getActionLabel:Xe=>t("gitView.changes.unstageFileAria",{path:Xe}),onActionFile:Xe=>{Js([Xe],"unstage")},onActionAll:Xe=>{Js(Xe,"unstage")},onViewDiff:Xe=>ia(Xe,!0),onRevertFile:Vn,showRevertActions:!1,accent:!0}),ns.length>0&&Re.push({id:"unstaged",title:t("gitView.changes.title"),entries:ns,actionSymbol:"+",actionAllLabel:t("gitView.changes.stageAllAria"),getActionLabel:Xe=>t("gitView.changes.stageFileAria",{path:Xe}),onActionFile:Xe=>{Js([Xe],"stage")},onActionAll:Xe=>{Js(Xe,"stage")},onViewDiff:Xe=>ia(Xe,!1),onRevertFile:Vn}),Re},[Vn,ia,Js,Ht,t,ns]),pn=l.useCallback(Re=>{if(Re.length===0)return;const Xe=Re.map(tt=>tt.trim()).filter(Boolean);if(Xe.length===0){Bt();return}le(tt=>{const mt=tt.trim(),At=mt.length>0?`
|
|
43
|
-
|
|
44
|
-
`:"";return`${mt}${At}${Xe.join(`
|
|
45
|
-
`)}`.trim()}),Bt()},[Bt]),ni=l.useCallback((Re,Xe)=>{const tt=Xe||Re;le(mt=>{const At=mt.trimStart();return At.startsWith(Re)||Xe&&At.startsWith(Xe)?mt:`${tt.endsWith(" ")?tt:`${tt} `}${mt}`.trimStart()}),Bs(""),we(!1)},[]),ri=l.useCallback(Re=>{De(Re),n&&(Z(n,Re),q(n,e,Re))},[n,Z,q,e]),Na=l.useCallback(Re=>{const Xe=Re instanceof Error?Re.message.toLowerCase():"";return Xe.includes("uncommitted changes")||Xe.includes("local changes")||Xe.includes("your local changes would be overwritten")||Xe.includes("please commit your changes or stash them")||Xe.includes("cannot rebase: you have unstaged changes")||Xe.includes("error: cannot pull with rebase")},[]),Sr=l.useCallback((Re,Xe)=>{yt(tt=>[...tt,{message:Re,status:Xe,timestamp:Date.now()}])},[]),An=l.useCallback((Re,Xe)=>{yt(tt=>{if(tt.length===0)return tt;const mt=[...tt];return mt[mt.length-1]={...mt[mt.length-1],status:Re,...Xe?{message:Xe}:{}},mt})},[]),oa=l.useCallback(()=>{yt([])},[]),Fi=l.useCallback(()=>{yt([]),cs(null)},[]),Or=l.useCallback(Re=>{const Xe=Re.trim(),tt=new Set(hn.map(At=>At.name)),mt=Xe.indexOf("/");if(mt>0){const At=Xe.slice(0,mt),zt=Xe.slice(mt+1);if(tt.has(At)&&zt)return{branch:Xe,remote:At,remoteBranch:zt}}for(const At of hn){const zt=`${At.name}/${Xe}`;if(cn.includes(zt))return{branch:zt,remote:At.name,remoteBranch:Xe}}return{branch:Xe,remote:null,remoteBranch:null}},[hn,cn]),Sa=l.useCallback(async Re=>{if(!n)return;cs("merge"),oa();const Xe=w?.current,tt=Or(Re);try{tt.remote&&tt.remoteBranch&&(Sr(`Fetching ${tt.remote}/${tt.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:tt.remote,branch:tt.remoteBranch}),An("done",`Fetched ${tt.remote}/${tt.remoteBranch}`)),Sr(`Merging ${tt.branch} into ${Xe}...`,"running");const mt=await e.merge(n,{branch:tt.branch});mt.conflict?(An("error","Merge conflicts detected"),Ot(mt.conflictFiles??[]),Ds("merge"),Rt(!0),Vs(n,mt.conflictFiles??[],"merge")):(An("done",`Merged ${tt.branch} into ${Xe}`),js(),Sr("Refreshing repository status...","running"),await $s(),await Ks(),An("done","Repository status updated"))}catch(mt){if(Na(mt))An("error","Uncommitted changes detected"),lr("merge"),yn(tt.branch),bn(!0);else{const At=mt instanceof Error?mt.message:`Failed to merge ${tt.branch}`;An("error",At)}}},[n,e,w,Or,$s,Ks,Na,Vs,js,Sr,An,oa]),kn=l.useCallback(async Re=>{if(!n)return;cs("rebase"),oa();const Xe=w?.current,tt=Or(Re);try{tt.remote&&tt.remoteBranch&&(Sr(`Fetching ${tt.remote}/${tt.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:tt.remote,branch:tt.remoteBranch}),An("done",`Fetched ${tt.remote}/${tt.remoteBranch}`)),Sr(`Rebasing ${Xe} onto ${tt.branch}...`,"running");const mt=await e.rebase(n,{onto:tt.branch});mt.conflict?(An("error","Rebase conflicts detected"),Ot(mt.conflictFiles??[]),Ds("rebase"),Rt(!0),Vs(n,mt.conflictFiles??[],"rebase")):(An("done",`Rebased ${Xe} onto ${tt.branch}`),js(),Sr("Refreshing repository status...","running"),await $s(),await Ks(),An("done","Repository status updated"))}catch(mt){if(Na(mt))An("error","Uncommitted changes detected"),lr("rebase"),yn(tt.branch),bn(!0);else{const At=mt instanceof Error?mt.message:`Failed to rebase onto ${tt.branch}`;An("error",At)}}},[n,e,w,Or,$s,Ks,Na,Vs,js,Sr,An,oa]),Hr=l.useCallback(async()=>{if(n)try{Os==="merge"?(await e.abortMerge(n),H.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),H.success(t("gitView.toast.rebaseAborted"))),js(),await $s(),await Ks()}catch(Re){const Xe=Re instanceof Error?Re.message:`Failed to abort ${Os}`;H.error(Xe)}},[n,e,Os,$s,Ks,js,t]),ai=l.useMemo(()=>w?.files?w.files.some(Re=>Re.index==="U"||Re.working_dir==="U"||Re.index==="A"&&Re.working_dir==="A"||Re.index==="D"&&Re.working_dir==="D"):!1,[w?.files]),kr=l.useCallback(async()=>{if(n)try{const Re=!!w?.mergeInProgress?.head,Xe=!!(w?.rebaseInProgress?.headName||w?.rebaseInProgress?.onto);if(Re){const tt=await e.continueMerge(n);tt.conflict?(Ot(tt.conflictFiles??[]),Ds("merge"),Rt(!0),Vs(n,tt.conflictFiles??[],"merge"),H.error(t("gitView.toast.mergeConflictsDetected"))):(js(),H.success(t("gitView.toast.mergeCompleted")),await $s(),await Ks())}else if(Xe){const tt=await e.continueRebase(n);tt.conflict?(Ot(tt.conflictFiles??[]),Ds("rebase"),Rt(!0),Vs(n,tt.conflictFiles??[],"rebase"),H.error(t("gitView.toast.rebaseConflictsDetected"))):(js(),H.success(t("gitView.toast.rebaseStepCompleted")),await $s(),await Ks())}}catch(Re){const Xe=Re instanceof Error?Re.message:t("gitView.toast.continueOperationFailed");H.error(Xe)}},[n,e,w,$s,Ks,Vs,js,t]),Cr=l.useCallback(async()=>{if(n)try{!!w?.mergeInProgress?.head?(await e.abortMerge(n),H.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),H.success(t("gitView.toast.rebaseAborted"))),js(),await $s(),await Ks()}catch(Re){const Xe=Re instanceof Error?Re.message:t("gitView.toast.abortOperationFailed");H.error(Xe)}},[n,e,w,$s,Ks,js,t]),tn=l.useCallback(()=>{if(!n)return;const Xe=!!w?.mergeInProgress?.head?"merge":"rebase",tt=w?.files?.filter(mt=>mt.index==="U"||mt.working_dir==="U").map(mt=>mt.path)??[];tt.length>0&&Ot(tt),Ds(Xe),Rt(!0)},[n,w]),ka=l.useCallback(async Re=>{if(!n)return;const Xe=w?.current,tt=mn,mt=Us,At=(w?.files??[]).some(ep);try{await e.stash(n,{message:`Auto-stash before ${tt} with ${mt}`,includeUntracked:!0}),At&&me(n)}catch(Fs){const zn=Fs instanceof Error?Fs.message:"Failed to stash changes";H.error(zn);return}let zt=!1,zs=!1;try{if(tt==="merge"){const Fs=await e.merge(n,{branch:mt});Fs.conflict?(zs=!0,Ot(Fs.conflictFiles??[]),Ds("merge"),Rt(!0)):(zt=!0,H.success(t("gitView.toast.mergedIntoBranch",{branch:mt,currentBranch:Xe||""})))}else{const Fs=await e.rebase(n,{onto:mt});Fs.conflict?(zs=!0,Ot(Fs.conflictFiles??[]),Ds("rebase"),Rt(!0)):(zt=!0,H.success(t("gitView.toast.rebasedOntoBranch",{currentBranch:Xe||"",branch:mt})))}if(Re&&zt)try{await e.stashPop(n),me(n),H.success(t("gitView.toast.stashedRestored"))}catch(Fs){const zn=Fs instanceof Error?Fs.message:t("gitView.toast.restoreStashFailed");H.error(zn)}else Re&&zs&&H.info(t("gitView.toast.restoreStashManually"));await $s(),await Ks()}catch(Fs){if(Re)try{await e.stashPop(n),me(n)}catch{}throw Fs}},[me,n,e,w,mn,Us,$s,Ks,t]);return n?E&&k===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(A,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:t("gitView.loading.checkingRepository")})]})}):k===!1?Ce?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(A,{name:"loader-4",className:"mb-3 size-6 animate-spin text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t("gitView.empty.worktreeSetupInProgress")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.worktreeSetupDescription")})]}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(A,{name:"git-branch",className:"mb-3 size-6 text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t("gitView.empty.notGitRepository")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.notGitRepositoryDescription")}),I.includes("open-without-worktree-features")?s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:t("gitView.empty.worktreeFeaturesUnavailable")}):null]}):s.jsxs("div",{className:ye("flex h-full flex-col overflow-hidden","bg-sidebar"),children:[s.jsx(Sj,{status:w,localBranches:Nn,remoteBranches:cn,branchInfo:D?.branches,syncAction:F,remotes:hn,onFetch:Re=>qs("fetch",Re),onSync:Re=>qs("sync",Re),onRemoveRemote:Gs,removingRemoteName:Ft,onCheckoutBranch:aa,onCreateBranch:qn,onRenameBranch:Jn,activeIdentityProfile:an,availableIdentities:dr,onSelectIdentity:Ur,isApplyingIdentity:Qe,isWorktreeMode:!!P,onOpenHistory:()=>xn(!0),onOpenStashes:Nr,actionTabItems:Qs,activeActionTab:Wt,onSelectActionTab:Re=>qt(Re)}),n&&(w?.mergeInProgress?.head||w?.rebaseInProgress?.headName||w?.rebaseInProgress?.onto)&&s.jsx(lN,{mergeInProgress:w?.mergeInProgress,rebaseInProgress:w?.rebaseInProgress,onContinue:kr,onAbort:Cr,onResolveWithAI:tn,hasUnresolvedConflicts:ai,isLoading:E}),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:ye("min-w-0 min-h-0 h-full flex flex-col","bg-sidebar"),children:s.jsxs(Ss,{as:jo,ref:ee,outerClassName:"flex-1 min-h-0",className:ye("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:[Wt==="commit"?s.jsx("div",{className:"flex h-full min-h-0 flex-col gap-3",children:(Pt?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(Fj,{groups:si,diffStats:w?.diffStats,revertingPaths:Je,isRevertingAll:at,onVisiblePathsChange:Me,onRevertAll:ja})}),s.jsx(Bj,{stagedCount:Fr,commitMessage:je,onCommitMessageChange:le,generatedHighlights:xt,onInsertHighlights:pn,onGenerateMessage:sn,isGeneratingMessage:Ke,onCommit:()=>Ls({pushAfter:!1}),onCommitAndPush:()=>Ls({pushAfter:!0}),commitAction:Oe,hasPendingIndexMutation:ut,gitmojiEnabled:ke,onOpenGitmojiPicker:()=>we(!0)})]}):s.jsx(Vj,{onOpenStashes:()=>Te(!0)})}):null,Wt==="branch"?s.jsx("div",{className:"space-y-4",children:ti?s.jsxs(s.Fragment,{children:[s.jsx(cN,{mode:"inline",currentBranch:w?.current,localBranches:Nn,remoteBranches:cn,defaultTargetBranch:cr,onMerge:Sa,onRebase:kn,disabled:Yn,isOperating:ls!==null,operationLogs:He,onOperationComplete:Fi}),Xn?s.jsx(gj,{repoRoot:Xn.repoRoot,sourceBranch:Xn.sourceBranch,worktreeMetadata:Xn.worktreeMetadata,localBranches:Nn,defaultTargetBranch:ht,refreshKey:Le,onRefresh:()=>{n&&(O(n,e),_(n,e),q(n,e,z))}},Xn.worktreeMetadata.path):null]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("gitView.branch.actionsUnavailable")})}):null,Wt==="pr"?s.jsx("div",{className:"space-y-4",children:Wr?s.jsx(Z0,{directory:Wr.directory,branch:Wr.branch,baseBranch:Sn,trackingBranch:w?.tracking??void 0,remotes:re,remoteBranches:cn,onGeneratedDescription:Nt}):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(us,{open:ws,onOpenChange:xn,children:s.jsxs(ds,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:t("gitView.history.title")}),s.jsx(Ns,{children:t("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(j0,{log:S,isLogLoading:R,logMaxCount:z,onLogMaxCountChange:ri,expandedCommitHashes:Zt,onToggleCommit:Mn,commitFilesMap:rs,loadingCommitHashes:Ut,onCopyHash:ir,directory:n??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:Tt})})]})}),s.jsx(kj,{open:oe,onOpenChange:Te,directory:n,hasUncommittedChanges:(w?.files?.length??0)>0,hasStagedChanges:Ht.length>0,uncommittedFileCount:w?.files?.length??0,onChanged:async Re=>{n&&Re?.affectsIndex&&me(n),await $s(!1),await Ks()}}),s.jsx(us,{open:Ve,onOpenChange:we,children:s.jsxs(ds,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(hs,{className:"px-4 pt-4",children:s.jsx(ms,{children:t("gitView.gitmoji.title")})}),s.jsxs(qa,{className:"h-[420px]",children:[s.jsx(va,{placeholder:t("gitView.gitmoji.searchPlaceholder"),value:xs,onValueChange:Bs}),s.jsxs(Ja,{children:[s.jsx(Ya,{children:t("gitView.gitmoji.empty")}),s.jsx(On,{children:(ss.length===0?[]:ss.filter(Re=>{const Xe=xs.trim().toLowerCase();return Xe?Re.emoji.includes(Xe)||Re.code.toLowerCase().includes(Xe)||Re.description.toLowerCase().includes(Xe):!0})).map(Re=>s.jsxs(Pn,{onSelect:()=>ni(Re.emoji,Re.code),children:[s.jsx("span",{className:"text-lg",children:Re.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Re.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:Re.description})]},Re.code))})]})]})]})}),n&&s.jsx(eN,{open:Et,onOpenChange:Rt,conflictFiles:Yt,directory:n,operation:Os,onAbort:Hr,onClearState:js}),s.jsx(oN,{open:Bn,onOpenChange:bn,operation:mn,targetBranch:Us,onConfirm:ka})]}):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")})})},IN=Object.freeze(Object.defineProperty({__proto__:null,GitView:hg},Symbol.toStringTag,{value:"Module"})),Cd=5e3,PN=(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},AN=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"},DN=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()},hu=async(t,e)=>{try{const n=await DN(t,e);return PN(n,Cd)>Cd?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:AN(n)}}},gu=t=>t==="too-large"?`File is too large to open (>${Cd.toLocaleString()} lines)`:t==="missing"?"File not found":"Failed to open file",TN=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Kn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},gg=(t,e)=>{const n=Kn(e),r=Kn(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},EN=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),MN=new Set(["node_modules"]),RN=t=>MN.has(t),FN=t=>{const e=Kn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},xg=(t,e)=>s.jsx(Ar,{filePath:t,extension:e}),ON=t=>{const e=ot.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const a=r[n];let i;return e[1]!==a?(i=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:a}}),e[1]=a,e[2]=i):i=e[2],i},LN=t=>{const e=ot.c(63),{node:n,root:r,isExpanded:a,isActive:i,status:o,badge:c,permissions:d,downloadFile:p,contextMenuPath:m,setContextMenuPath:u,onSelect:f,onToggle:b,onRevealPath:x,onOpenDialog:y}=t,{t:g}=ft(),h=n.type==="directory",{canRename:j,canCreateFile:v,canCreateFolder:C,canDelete:k,canReveal:w}=d;let N;e[0]!==v||e[1]!==C||e[2]!==k||e[3]!==j||e[4]!==w||e[5]!==n.path||e[6]!==u?(N=Z=>{!j&&!v&&!C&&!k&&!w||(Z?.preventDefault(),u(n.path))},e[0]=v,e[1]=C,e[2]=k,e[3]=j,e[4]=w,e[5]=n.path,e[6]=u,e[7]=N):N=e[7];const I=N;let T;e[8]!==h||e[9]!==n||e[10]!==f||e[11]!==b?(T=()=>{h?b(n.path):f(n)},e[8]=h,e[9]=n,e[10]=f,e[11]=b,e[12]=T):T=e[12];const P=T;let D;e[13]!==n.path||e[14]!==u?(D=Z=>{Z.stopPropagation(),u(n.path)},e[13]=n.path,e[14]=u,e[15]=D):D=e[15];const S=D;let M;e[16]!==n.path||e[17]!==r?(M=Z=>{const ie=gg(r,n.path);!ie||ie==="."||(Z.dataTransfer.setData("application/x-openchamber-file-path",ie),Z.dataTransfer.effectAllowed="copy")},e[16]=n.path,e[17]=r,e[18]=M):M=e[18];const E=M,R=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let V;e[19]!==R?(V=ye("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",R,"cursor-grab active:cursor-grabbing"),e[19]=R,e[20]=V):V=e[20];let B;e[21]!==h||e[22]!==a||e[23]!==n.extension||e[24]!==n.path?(B=h?a?s.jsx(A,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(A,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):xg(n.path,n.extension),e[21]=h,e[22]=a,e[23]=n.extension,e[24]=n.path,e[25]=B):B=e[25];let $;e[26]!==n.name||e[27]!==n.path?($=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[26]=n.name,e[27]=n.path,e[28]=$):$=e[28];let O;e[29]!==h||e[30]!==o?(O=!h&&o&&s.jsx(ON,{status:o}),e[29]=h,e[30]=o,e[31]=O):O=e[31];let _;e[32]!==c||e[33]!==h?(_=h&&c&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[c.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",c.modified]}),c.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",c.added]})]}),e[32]=c,e[33]=h,e[34]=_):_=e[34];let q;e[35]!==I||e[36]!==E||e[37]!==P||e[38]!==_||e[39]!==V||e[40]!==B||e[41]!==$||e[42]!==O?(q=s.jsxs("button",{type:"button",onClick:P,onContextMenu:I,draggable:!0,onDragStart:E,className:V,children:[B,$,O,_]}),e[35]=I,e[36]=E,e[37]=P,e[38]=_,e[39]=V,e[40]=B,e[41]=$,e[42]=O,e[43]=q):q=e[43];let L;e[44]!==v||e[45]!==C||e[46]!==k||e[47]!==j||e[48]!==w||e[49]!==m||e[50]!==p||e[51]!==S||e[52]!==h||e[53]!==n||e[54]!==y||e[55]!==x||e[56]!==u||e[57]!==g?(L=(j||v||C||k||w)&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(As,{open:m===n.path,onOpenChange:Z=>u(Z?n.path:null),children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(Is,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:S,title:g("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":g("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(A,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:g("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsxs(Ps,{align:"end",side:"bottom",onCloseAutoFocus:()=>u(null),children:[j&&s.jsxs(_t,{onClick:Z=>{Z.stopPropagation(),y("rename",n)},children:[s.jsx(A,{name:"edit",className:"mr-2 h-4 w-4"})," ",g("sidebarFilesTree.menu.rename")]}),s.jsxs(_t,{onClick:Z=>{Z.stopPropagation(),En(n.path).then(ie=>{if(ie.ok){H.success(g("sidebarFilesTree.toast.pathCopied"));return}H.error(g("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(A,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",g("sidebarFilesTree.menu.copyPath")]}),!h&&p&&s.jsxs(_t,{onClick:Z=>{Z.stopPropagation(),p(n.path)},children:[s.jsx(A,{name:"download",className:"mr-2 h-4 w-4"})," ",g("sidebarFilesTree.menu.save")]}),w&&s.jsxs(_t,{onClick:Z=>{Z.stopPropagation(),x(n.path)},children:[s.jsx(A,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",g(su())]}),h&&(v||C)&&s.jsxs(s.Fragment,{children:[s.jsx(nr,{}),v&&s.jsxs(_t,{onClick:Z=>{Z.stopPropagation(),y("createFile",n)},children:[s.jsx(A,{name:"file-add",className:"mr-2 h-4 w-4"})," ",g("sidebarFilesTree.menu.newFile")]}),C&&s.jsxs(_t,{onClick:Z=>{Z.stopPropagation(),y("createFolder",n)},children:[s.jsx(A,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",g("sidebarFilesTree.menu.newFolder")]})]}),k&&s.jsxs(s.Fragment,{children:[s.jsx(nr,{}),s.jsxs(_t,{onClick:Z=>{Z.stopPropagation(),y("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",g("sidebarFilesTree.menu.delete")]})]})]})]})}),e[44]=v,e[45]=C,e[46]=k,e[47]=j,e[48]=w,e[49]=m,e[50]=p,e[51]=S,e[52]=h,e[53]=n,e[54]=y,e[55]=x,e[56]=u,e[57]=g,e[58]=L):L=e[58];let J;return e[59]!==I||e[60]!==q||e[61]!==L?(J=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:I,children:[q,L]}),e[59]=I,e[60]=q,e[61]=L,e[62]=J):J=e[62],J},$N=()=>{const t=ot.c(250),{t:e}=ft(),{files:n,runtime:r}=_n(),a=na()??"";let i;t[0]!==a?(i=Kn(a.trim()),t[0]=a,t[1]=i):i=t[1];const o=i,c=ec(),d=eu(),p=tu(_N),m=Fe(BN),u=Zl(a),[f,b]=l.useState(""),x=tc(f,200),y=l.useRef(null);let g;t[2]===Symbol.for("react.memo_cache_sentinel")?(g=[],t[2]=g):g=t[2];const[h,j]=l.useState(g),[v,C]=l.useState(!1);let k;t[3]===Symbol.for("react.memo_cache_sentinel")?(k={},t[3]=k):k=t[3];const[w,N]=l.useState(k);let I;t[4]===Symbol.for("react.memo_cache_sentinel")?(I=new Set,t[4]=I):I=t[4];const T=l.useRef(I);let P;t[5]===Symbol.for("react.memo_cache_sentinel")?(P=new Set,t[5]=P):P=t[5];const D=l.useRef(P);let S;t[6]===Symbol.for("react.memo_cache_sentinel")?(S=[],t[6]=S):S=t[6];const M=S;let E;t[7]===Symbol.for("react.memo_cache_sentinel")?(E=[],t[7]=E):E=t[7];const R=E;let V;t[8]!==o?(V=Wt=>o?Wt.byRoot[o]?.expandedPaths??M:M,t[8]=o,t[9]=V):V=t[9];const B=Fn(V);let $;t[10]!==o?($=Wt=>o?Wt.byRoot[o]?.selectedPath??null:null,t[10]=o,t[11]=$):$=t[11];const O=Fn($),_=Fn(VN),q=Fn(zN),L=Fn(UN),J=Fn(WN);let Z;t[12]!==o?(Z=Wt=>o?Wt.contextPanelByDirectory[o]?.tabs??R:R,t[12]=o,t[13]=Z):Z=t[13];const ie=Fe(Z);let ne;t[14]!==ie?(ne=new Set(ie.map(KN).filter(HN).map(GN)),t[14]=ie,t[15]=ne):ne=t[15];const me=ne,[pe,G]=l.useState(null),[K,Q]=l.useState(null),[W,de]=l.useState(null),[ge,ve]=l.useState(""),[te,he]=l.useState(!1),ce=!!n.writeFile,xe=!!n.createDirectory,se=!!n.rename,ue=!!n.delete,Y=!!n.revealPath;let Se;t[16]!==ce||t[17]!==xe||t[18]!==ue||t[19]!==se||t[20]!==Y?(Se={canRename:se,canCreateFile:ce,canCreateFolder:xe,canDelete:ue,canReveal:Y},t[16]=ce,t[17]=xe,t[18]=ue,t[19]=se,t[20]=Y,t[21]=Se):Se=t[21];const fe=Se;let Ce;t[22]!==n||t[23]!==e?(Ce=Wt=>{n.revealPath&&n.revealPath(Wt).catch(()=>{H.error(e("sidebarFilesTree.toast.revealFailed"))})},t[22]=n,t[23]=e,t[24]=Ce):Ce=t[24];const Ie=Ce;let ke;t[25]===Symbol.for("react.memo_cache_sentinel")?(ke=(Wt,qt)=>{Q(Wt),de(qt),ve(Wt==="rename"&&qt.name||""),he(!1)},t[25]=ke):ke=t[25];const X=ke;let ae;t[26]!==d||t[27]!==c?(ae=(Wt,qt)=>{const re=qt.filter(qN).filter(vt=>c||!vt.name.startsWith(".")).filter(vt=>d||!RN(vt.name)).map(vt=>{const Ft=vt.name,ct=Kn(vt.path||""),ls=ct?EN(ct)?ct:Kn(`${Wt}/${ct}`):Kn(`${Wt}/${Ft}`),cs=vt.isDirectory?"directory":"file",He=cs==="file"&&Ft.includes(".")?Ft.split(".").pop()?.toLowerCase():void 0;return{name:Ft,path:ls,type:cs,extension:He}});return TN(re)},t[26]=d,t[27]=c,t[28]=ae):ae=t[28];const je=ae;let le;t[29]!==n||t[30]!==je||t[31]!==r.isDesktop||t[32]!==d?(le=async Wt=>{const qt=Kn(Wt.trim());if(!qt||T.current.has(qt)||D.current.has(qt))return;D.current=new Set(D.current),D.current.add(qt);const re=!d;await(r.isDesktop?n.listDirectory(qt,{respectGitignore:re}).then(YN):on.listLocalDirectory(qt,{respectGitignore:re}).then(XN)).then(Ft=>{const ct=je(qt,Ft);T.current=new Set(T.current),T.current.add(qt),N(ls=>({...ls,[qt]:ct}))}).catch(()=>{N(Ft=>({...Ft,[qt]:Ft[qt]??[]}))}).finally(()=>{D.current=new Set(D.current),D.current.delete(qt)})},t[29]=n,t[30]=je,t[31]=r.isDesktop,t[32]=d,t[33]=le):le=t[33];const Ne=le;let Me;t[34]!==Ne||t[35]!==o?(Me=async()=>{o&&(T.current=new Set,D.current=new Set,N(ZN),await Ne(o))},t[34]=Ne,t[35]=o,t[36]=Me):Me=t[36];const Ve=Me;let we;t[37]!==Ne||t[38]!==Ve?(we=async Wt=>{if(!Wt){await Ve();return}const qt=Kn(Wt);T.current=new Set(T.current),T.current.delete(qt),D.current=new Set(D.current),D.current.delete(qt),await Ne(qt)},t[37]=Ne,t[38]=Ve,t[39]=we):we=t[39];const ee=we;let F;t[40]!==Ne||t[41]!==o?(F=()=>{o&&(T.current=new Set,D.current=new Set,N(e2),Ne(o))},t[40]=Ne,t[41]=o,t[42]=F):F=t[42];let U;t[43]!==Ne||t[44]!==o||t[45]!==d||t[46]!==c?(U=[Ne,o,c,d],t[43]=Ne,t[44]=o,t[45]=d,t[46]=c,t[47]=U):U=t[47],l.useEffect(F,U);let oe,Te;t[48]!==B||t[49]!==Ne||t[50]!==o?(oe=()=>{if(!o||B.length===0)return;const Wt=B.map(t2).filter(re=>!!re&&re!==o&&re.startsWith(`${o}/`)&&!T.current.has(re)&&!D.current.has(re)).sort(s2);if(Wt.length===0)return;let qt=!1;return(async()=>{for(let re=0;re<Wt.length&&!qt;re=re+3,re){const vt=Wt.slice(re,re+3);await Promise.all(vt.map(Ft=>Ne(Ft)))}})(),()=>{qt=!0}},Te=[B,Ne,o],t[48]=B,t[49]=Ne,t[50]=o,t[51]=oe,t[52]=Te):(oe=t[51],Te=t[52]),l.useEffect(oe,Te);let Oe,Pe;t[53]!==a||t[54]!==x||t[55]!==p||t[56]!==d||t[57]!==c?(Oe=()=>{if(!a){j([]),C(!1);return}const Wt=x.trim();if(!Wt){j([]),C(!1);return}let qt=!1;return C(!0),p(a,Wt,150,{includeHidden:c,respectGitignore:!d,type:"file"}).then(re=>{if(qt)return;const Ft=re.filter(ct=>d||!FN(ct.path)).map(n2);j(Ft)}).catch(()=>{qt||j([])}).finally(()=>{qt||C(!1)}),()=>{qt=!0}},Pe=[a,x,p,c,d],t[53]=a,t[54]=x,t[55]=p,t[56]=d,t[57]=c,t[58]=Oe,t[59]=Pe):(Oe=t[58],Pe=t[59]),l.useEffect(Oe,Pe);let z;t[60]!==u||t[61]!==me||t[62]!==o?(z=Wt=>{if(me.has(Wt))return"open";if(u?.files){const qt=Wt.startsWith(o+"/")?Wt.slice(o.length+1):Wt,re=u.files.find(vt=>vt.path===qt);if(re){if(re.index==="A"||re.working_dir==="?")return"git-added";if(re.index==="D")return"git-deleted";if(re.index==="M"||re.working_dir==="M")return"git-modified"}}return null},t[60]=u,t[61]=me,t[62]=o,t[63]=z):z=t[63];const De=z;let Qe;t[64]!==u||t[65]!==o?(Qe=Wt=>{if(!u?.files)return null;const qt=Wt.startsWith(o+"/")?Wt.slice(o.length+1):Wt,re=qt?`${qt}/`:"";let vt=0,Ft=0;for(const ct of u.files)ct.path.startsWith(re)&&((ct.index==="M"||ct.working_dir==="M")&&vt++,(ct.index==="A"||ct.working_dir==="?")&&Ft++);return vt+Ft>0?{modified:vt,added:Ft}:null},t[64]=u,t[65]=o,t[66]=Qe):Qe=t[66];const et=Qe;let Ze;t[67]!==q||t[68]!==n||t[69]!==m||t[70]!==o||t[71]!==_?(Ze=async Wt=>{if(!o)return;const qt=await hu(n,Wt.path);if(!qt.ok){H.error(gu(qt.reason));return}_(o,Wt.path),q(o,Wt.path),m(o,Wt.path)},t[67]=q,t[68]=n,t[69]=m,t[70]=o,t[71]=_,t[72]=Ze):Ze=t[72];const We=Ze;let it;t[73]!==Ne||t[74]!==o||t[75]!==J?(it=async Wt=>{const qt=Kn(Wt);o&&(J(o,qt),T.current.has(qt)||await Ne(qt))},t[73]=Ne,t[74]=o,t[75]=J,t[76]=it):it=t[76];const qe=it;let st;t[77]!==K||t[78]!==W||t[79]!==ge||t[80]!==n||t[81]!==ee||t[82]!==L||t[83]!==o||t[84]!==O||t[85]!==_||t[86]!==e?(st=async Wt=>{if(Wt?.preventDefault(),!W||!K)return;he(!0);const qt=()=>he(!1),re=()=>Q(null);if(K==="createFile"){if(!ge.trim()){H.error(e("sidebarFilesTree.toast.filenameRequired")),qt();return}if(!n.writeFile){H.error(e("sidebarFilesTree.toast.writeNotSupported")),qt();return}const vt=W.path,Ft=vt?`${vt}/`:"",ct=Kn(`${Ft}${ge.trim()}`);await n.writeFile(ct,"").then(async ls=>{ls.success&&(H.success(e("sidebarFilesTree.toast.fileCreated")),await ee(vt)),re()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(qt);return}if(K==="createFolder"){if(!ge.trim()){H.error(e("sidebarFilesTree.toast.folderNameRequired")),qt();return}const vt=W.path,Ft=vt?`${vt}/`:"",ct=Kn(`${Ft}${ge.trim()}`);await n.createDirectory(ct).then(async ls=>{ls.success&&(H.success(e("sidebarFilesTree.toast.folderCreated")),await ee(vt)),re()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(qt);return}if(K==="rename"){if(!ge.trim()){H.error(e("sidebarFilesTree.toast.nameRequired")),qt();return}if(!n.rename){H.error(e("sidebarFilesTree.toast.renameNotSupported")),qt();return}const vt=W.path,Ft=vt.split("/").slice(0,-1).join("/"),ct=Ft?`${Ft}/`:"",ls=Kn(`${ct}${ge.trim()}`);await n.rename(vt,ls).then(async cs=>{cs.success&&(H.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await ee(Ft),o&&L(o,vt),(O===vt||O&&O.startsWith(`${vt}/`))&&_(o,null)),re()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(qt);return}if(K==="delete"){if(!n.delete){H.error(e("sidebarFilesTree.toast.deleteNotSupported")),qt();return}const vt=W.path,Ft=vt.split("/").slice(0,-1).join("/");await n.delete(vt).then(async ct=>{ct.success&&(H.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await ee(Ft),o&&L(o,vt),(O===vt||O&&O.startsWith(vt+"/"))&&_(o,null)),re()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(qt);return}qt()},t[77]=K,t[78]=W,t[79]=ge,t[80]=n,t[81]=ee,t[82]=L,t[83]=o,t[84]=O,t[85]=_,t[86]=e,t[87]=st):st=t[87];const Je=st;let Be,nt,Ge,at,Ae,Le,ze;if(t[88]!==ce||t[89]!==xe||t[90]!==w||t[91]!==pe||t[92]!==a||t[93]!==B||t[94]!==fe||t[95]!==n.downloadFile||t[96]!==De||t[97]!==et||t[98]!==We||t[99]!==Ie||t[100]!==Ve||t[101]!==o||t[102]!==f||t[103]!==h||t[104]!==v||t[105]!==O||t[106]!==e||t[107]!==qe){let Wt=function(js,Bn){const bn=w[js]??[];return bn.map((mn,lr)=>{const Us=mn.type==="directory",yn=Us&&B.includes(mn.path),ir=O===mn.path,Mn=lr===bn.length-1;return s.jsxs("li",{className:"relative",children:[Bn>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Mn&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(LN,{node:mn,root:o,isExpanded:yn,isActive:ir,status:Us?void 0:De(mn.path),badge:Us?et(mn.path):void 0,permissions:fe,downloadFile:n.downloadFile,contextMenuPath:pe,setContextMenuPath:G,onSelect:We,onToggle:qe,onRevealPath:Ie,onOpenDialog:X}),Us&&yn&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Wt(mn.path,Bn+1)})]},mn.path)})};const qt=!!(o&&w[o]);Le="flex h-full min-h-0 flex-col overflow-hidden bg-sidebar";let re;t[115]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx(A,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),t[115]=re):re=t[115];let vt;t[116]===Symbol.for("react.memo_cache_sentinel")?(vt=js=>b(js.target.value),t[116]=vt):vt=t[116];let Ft;t[117]!==e?(Ft=e("sidebarFilesTree.search.placeholder"),t[117]=e,t[118]=Ft):Ft=t[118];let ct;t[119]!==f||t[120]!==Ft?(ct=s.jsx(Lt,{ref:y,value:f,onChange:vt,placeholder:Ft,className:"h-8 pl-8 pr-8 typography-meta"}),t[119]=f,t[120]=Ft,t[121]=ct):ct=t[121];let ls;t[122]!==f||t[123]!==e?(ls=f.trim().length>0?s.jsx("button",{type:"button","aria-label":e("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{b(""),y.current?.focus()},children:s.jsx(A,{name:"close",className:"h-4 w-4"})}):null,t[122]=f,t[123]=e,t[124]=ls):ls=t[124];let cs;t[125]!==ct||t[126]!==ls?(cs=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[re,ct,ls]}),t[125]=ct,t[126]=ls,t[127]=cs):cs=t[127];let He;t[128]!==ce||t[129]!==a||t[130]!==e?(He=ce&&s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>X("createFile",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFileTitle"),"aria-label":e("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(A,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:e("sidebarFilesTree.actions.newFileTitle")})]}),t[128]=ce,t[129]=a,t[130]=e,t[131]=He):He=t[131];let yt;t[132]!==xe||t[133]!==a||t[134]!==e?(yt=xe&&s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>X("createFolder",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFolderTitle"),"aria-label":e("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(A,{name:"folder-add",className:"h-4 w-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:e("sidebarFilesTree.actions.newFolderTitle")})]}),t[132]=xe,t[133]=a,t[134]=e,t[135]=yt):yt=t[135];let Et;t[136]!==Ve?(Et=()=>{Ve()},t[136]=Ve,t[137]=Et):Et=t[137];let Rt;t[138]!==e?(Rt=e("sidebarFilesTree.actions.refreshTitle"),t[138]=e,t[139]=Rt):Rt=t[139];let Yt;t[140]!==e?(Yt=e("sidebarFilesTree.actions.refreshTitle"),t[140]=e,t[141]=Yt):Yt=t[141];let Ot;t[142]===Symbol.for("react.memo_cache_sentinel")?(Ot=s.jsx(A,{name:"refresh",className:"h-4 w-4"}),t[142]=Ot):Ot=t[142];let Os;t[143]!==Et||t[144]!==Rt||t[145]!==Yt?(Os=s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(be,{variant:"ghost",size:"sm",onClick:Et,className:"h-8 w-8 p-0 flex-shrink-0",title:Rt,"aria-label":Yt,children:Ot})})}),t[143]=Et,t[144]=Rt,t[145]=Yt,t[146]=Os):Os=t[146];let Ds;t[147]!==e?(Ds=e("sidebarFilesTree.actions.refreshTitle"),t[147]=e,t[148]=Ds):Ds=t[148];let Ts;t[149]!==Ds?(Ts=s.jsx(It,{side:"bottom",sideOffset:6,children:Ds}),t[149]=Ds,t[150]=Ts):Ts=t[150];let Vs;t[151]!==Os||t[152]!==Ts?(Vs=s.jsxs(kt,{children:[Os,Ts]}),t[151]=Os,t[152]=Ts,t[153]=Vs):Vs=t[153],t[154]!==cs||t[155]!==He||t[156]!==yt||t[157]!==Vs?(ze=s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[cs,He,yt,Vs]}),t[154]=cs,t[155]=He,t[156]=yt,t[157]=Vs,t[158]=ze):ze=t[158],Be=Ss,at="flex-1 min-h-0",Ae="p-2",nt="flex flex-col",Ge=v?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("sidebarFilesTree.state.searching")]}):h.length>0?h.map(js=>{const Bn=O===js.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>We(js),draggable:!0,onDragStart:bn=>{const mn=js.relativePath||gg(o??"",js.path);!mn||mn==="."||(bn.dataTransfer.setData("application/x-openchamber-file-path",mn),bn.dataTransfer.effectAllowed="copy")},className:ye("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",Bn?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:js.path,children:[xg(js.path,js.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:js.relativePath??js.path})]})},js.path)}):qt&&o?Wt(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("sidebarFilesTree.state.loading")}),t[88]=ce,t[89]=xe,t[90]=w,t[91]=pe,t[92]=a,t[93]=B,t[94]=fe,t[95]=n.downloadFile,t[96]=De,t[97]=et,t[98]=We,t[99]=Ie,t[100]=Ve,t[101]=o,t[102]=f,t[103]=h,t[104]=v,t[105]=O,t[106]=e,t[107]=qe,t[108]=Be,t[109]=nt,t[110]=Ge,t[111]=at,t[112]=Ae,t[113]=Le,t[114]=ze}else Be=t[108],nt=t[109],Ge=t[110],at=t[111],Ae=t[112],Le=t[113],ze=t[114];let Ke;t[159]!==nt||t[160]!==Ge?(Ke=s.jsx("ul",{className:nt,children:Ge}),t[159]=nt,t[160]=Ge,t[161]=Ke):Ke=t[161];let lt;t[162]!==Be||t[163]!==at||t[164]!==Ae||t[165]!==Ke?(lt=s.jsx(Be,{outerClassName:at,className:Ae,children:Ke}),t[162]=Be,t[163]=at,t[164]=Ae,t[165]=Ke,t[166]=lt):lt=t[166];const xt=!!K;let dt;t[167]===Symbol.for("react.memo_cache_sentinel")?(dt=Wt=>!Wt&&Q(null),t[167]=dt):dt=t[167];let ut;t[168]!==K||t[169]!==e?(ut=K==="createFile"&&e("sidebarFilesTree.dialog.createFile.title"),t[168]=K,t[169]=e,t[170]=ut):ut=t[170];let Nt;t[171]!==K||t[172]!==e?(Nt=K==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.title"),t[171]=K,t[172]=e,t[173]=Nt):Nt=t[173];let ts;t[174]!==K||t[175]!==e?(ts=K==="rename"&&e("sidebarFilesTree.dialog.rename.title"),t[174]=K,t[175]=e,t[176]=ts):ts=t[176];let Vt;t[177]!==K||t[178]!==e?(Vt=K==="delete"&&e("sidebarFilesTree.dialog.delete.title"),t[177]=K,t[178]=e,t[179]=Vt):Vt=t[179];let Xt;t[180]!==ut||t[181]!==Nt||t[182]!==ts||t[183]!==Vt?(Xt=s.jsxs(ms,{children:[ut,Nt,ts,Vt]}),t[180]=ut,t[181]=Nt,t[182]=ts,t[183]=Vt,t[184]=Xt):Xt=t[184];let ht;t[185]!==K||t[186]!==W?.path||t[187]!==e?(ht=K==="createFile"&&e("sidebarFilesTree.dialog.createFile.description",{path:W?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[185]=K,t[186]=W?.path,t[187]=e,t[188]=ht):ht=t[188];let Bt;t[189]!==K||t[190]!==W?.path||t[191]!==e?(Bt=K==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.description",{path:W?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[189]=K,t[190]=W?.path,t[191]=e,t[192]=Bt):Bt=t[192];let Zt;t[193]!==K||t[194]!==W?.name||t[195]!==e?(Zt=K==="rename"&&e("sidebarFilesTree.dialog.rename.description",{name:W?.name??""}),t[193]=K,t[194]=W?.name,t[195]=e,t[196]=Zt):Zt=t[196];let gs;t[197]!==K||t[198]!==W?.name||t[199]!==e?(gs=K==="delete"&&e("sidebarFilesTree.dialog.delete.description",{name:W?.name??""}),t[197]=K,t[198]=W?.name,t[199]=e,t[200]=gs):gs=t[200];let rs;t[201]!==ht||t[202]!==Bt||t[203]!==Zt||t[204]!==gs?(rs=s.jsxs(Ns,{children:[ht,Bt,Zt,gs]}),t[201]=ht,t[202]=Bt,t[203]=Zt,t[204]=gs,t[205]=rs):rs=t[205];let ps;t[206]!==Xt||t[207]!==rs?(ps=s.jsxs(hs,{children:[Xt,rs]}),t[206]=Xt,t[207]=rs,t[208]=ps):ps=t[208];let Ut;t[209]!==K||t[210]!==ge||t[211]!==Je||t[212]!==e?(Ut=K!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Lt,{value:ge,onChange:Wt=>ve(Wt.target.value),placeholder:e(K==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:Wt=>{Wt.key==="Enter"&&Je()},autoFocus:!0})}),t[209]=K,t[210]=ge,t[211]=Je,t[212]=e,t[213]=Ut):Ut=t[213];let Ye;t[214]===Symbol.for("react.memo_cache_sentinel")?(Ye=()=>Q(null),t[214]=Ye):Ye=t[214];let Tt;t[215]!==e?(Tt=e("sidebarFilesTree.dialog.cancel"),t[215]=e,t[216]=Tt):Tt=t[216];let Kt;t[217]!==te||t[218]!==Tt?(Kt=s.jsx(be,{variant:"outline",onClick:Ye,disabled:te,children:Tt}),t[217]=te,t[218]=Tt,t[219]=Kt):Kt=t[219];const St=K==="delete"?"destructive":"default";let es;t[220]!==Je?(es=()=>{Je()},t[220]=Je,t[221]=es):es=t[221];let ss;t[222]!==K||t[223]!==ge||t[224]!==te?(ss=te||K!=="delete"&&!ge.trim(),t[222]=K,t[223]=ge,t[224]=te,t[225]=ss):ss=t[225];let Ms;t[226]!==K||t[227]!==te||t[228]!==e?(Ms=te?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):e(K==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm"),t[226]=K,t[227]=te,t[228]=e,t[229]=Ms):Ms=t[229];let xs;t[230]!==St||t[231]!==es||t[232]!==ss||t[233]!==Ms?(xs=s.jsx(be,{variant:St,onClick:es,disabled:ss,children:Ms}),t[230]=St,t[231]=es,t[232]=ss,t[233]=Ms,t[234]=xs):xs=t[234];let Bs;t[235]!==Kt||t[236]!==xs?(Bs=s.jsxs(_s,{children:[Kt,xs]}),t[235]=Kt,t[236]=xs,t[237]=Bs):Bs=t[237];let ws;t[238]!==ps||t[239]!==Ut||t[240]!==Bs?(ws=s.jsxs(ds,{children:[ps,Ut,Bs]}),t[238]=ps,t[239]=Ut,t[240]=Bs,t[241]=ws):ws=t[241];let xn;t[242]!==xt||t[243]!==ws?(xn=s.jsx(us,{open:xt,onOpenChange:dt,children:ws}),t[242]=xt,t[243]=ws,t[244]=xn):xn=t[244];let Qs;return t[245]!==Le||t[246]!==ze||t[247]!==lt||t[248]!==xn?(Qs=s.jsxs("section",{className:Le,children:[ze,lt,xn]}),t[245]=Le,t[246]=ze,t[247]=lt,t[248]=xn,t[249]=Qs):Qs=t[249],Qs};function _N(t){return t.searchFiles}function BN(t){return t.openContextFile}function VN(t){return t.setSelectedPath}function zN(t){return t.addOpenPath}function UN(t){return t.removeOpenPathsByPrefix}function WN(t){return t.toggleExpandedPath}function KN(t){return t.mode==="file"?t.targetPath:null}function HN(t){return typeof t=="string"&&t.length>0}function GN(t){return Kn(t)}function qN(t){return t&&typeof t.name=="string"&&t.name.length>0}function JN(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function YN(t){return t.entries.map(JN)}function QN(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function XN(t){return t.map(QN)}function ZN(t){return Object.keys(t).length===0?t:{}}function e2(t){return Object.keys(t).length===0?t:{}}function t2(t){return Kn(t)}function s2(t,e){return t.split("/").length-e.split("/").length}function n2(t){return{name:t.name,path:Kn(t.path),type:"file",extension:t.extension,relativePath:t.relativePath}}function r2(t,e){const n=ot.c(6),{git:r}=_n(),a=Ys(a2);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 a2(t){return t.ensureStatus}const bg=()=>{const t=ot.c(17),e=Cs(o2),n=Cs(l2),r=Ws(c2),a=Ys(d2);let i;e:{if(e){let x;t[0]!==e||t[1]!==n?(x=n.find(y=>y.id===e)??n[0]??null,t[0]=e,t[1]=n,t[2]=x):x=t[2],i=x;break e}i=n[0]??null}const o=i;let c;e:{if(!o){c=null;break e}let x;t[3]!==o.id||t[4]!==o.path?(x={id:o.id,path:o.path},t[3]=o.id,t[4]=o.path,t[5]=x):x=t[5],c=x}const d=c;let p;e:{if(!o){p=null;break e}let x;t[6]!==o.label||t[7]!==o.path||t[8]!==r?(x=o.label?.trim()||Ga(o.path,r)||o.path,t[6]=o.label,t[7]=o.path,t[8]=r,t[9]=x):x=t[9],p=x}const m=p;let u;e:{if(!o){u=!1;break e}let x;t[10]!==o.path||t[11]!==a?(x=a.get(o.path)?.isGitRepo,t[10]=o.path,t[11]=a,t[12]=x):x=t[12],u=x===!0}const f=u;let b;return t[13]!==f||t[14]!==m||t[15]!==d?(b=s.jsx("div",{className:"h-full min-h-0 overflow-auto bg-sidebar",children:s.jsx(Kw,{projectRef:d,projectLabel:m,canCreateWorktree:f})}),t[13]=f,t[14]=m,t[15]=d,t[16]=b):b=t[16],b},i2=()=>{const t=ot.c(38),{t:e}=ft(),n=Fe(u2),r=Fe(m2),a=Fe(p2),i=na();r2(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(A,{name:"git-branch",className:"h-3.5 w-3.5"}),t[2]=c):c=t[2];let d;t[3]!==o?(d={id:"git",label:o,icon:c},t[3]=o,t[4]=d):d=t[4];let p;t[5]!==e?(p=e("layout.rightSidebar.files"),t[5]=e,t[6]=p):p=t[6];let m;t[7]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(A,{name:"folder-3",className:"h-3.5 w-3.5"}),t[7]=m):m=t[7];let u;t[8]!==p?(u={id:"files",label:p,icon:m},t[8]=p,t[9]=u):u=t[9];let f;t[10]!==e?(f=e("layout.rightSidebar.context"),t[10]=e,t[11]=f):f=t[11];let b;t[12]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(A,{name:"file-list-2",className:"h-3.5 w-3.5"}),t[12]=b):b=t[12];let x;t[13]!==f?(x={id:"context",label:f,icon:b},t[13]=f,t[14]=x):x=t[14];let y;t[15]!==d||t[16]!==u||t[17]!==x?(y=[d,u,x],t[15]=d,t[16]=u,t[17]=x,t[18]=y):y=t[18];const g=y;let h;t[19]!==r?(h=I=>r(I),t[19]=r,t[20]=h):h=t[20];let j;t[21]!==n||t[22]!==h||t[23]!==g?(j=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx(Er,{items:g,activeId:n,onSelect:h,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[21]=n,t[22]=h,t[23]=g,t[24]=j):j=t[24];let v;t[25]!==n?(v=n==="git"&&s.jsx(hg,{}),t[25]=n,t[26]=v):v=t[26];let C;t[27]!==n?(C=n==="files"&&s.jsx($N,{}),t[27]=n,t[28]=C):C=t[28];let k;t[29]!==n?(k=n==="context"&&s.jsx(bg,{}),t[29]=n,t[30]=k):k=t[30];let w;t[31]!==v||t[32]!==C||t[33]!==k?(w=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[v,C,k]}),t[31]=v,t[32]=C,t[33]=k,t[34]=w):w=t[34];let N;return t[35]!==j||t[36]!==w?(N=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[j,w]}),t[35]=j,t[36]=w,t[37]=N):N=t[37],N};function o2(t){return t.activeProjectId}function l2(t){return t.projects}function c2(t){return t.homeDirectory}function d2(t){return t.directories}function u2(t){return t.rightSidebarTab}function m2(t){return t.setRightSidebarTab}function p2(t){return t.isRightSidebarOpen}const f2=1100,Id=15e3,tp=500,h2=t=>t<=6?t:t<=12?6:t<=25?4:2,yg=l.memo(()=>{const t=ot.c(4),{t:e}=ft();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}),vg={"?":{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"}},g2=vg.M,pl=[{value:"single",labelKey:"diffView.mode.single.label",descriptionKey:"diffView.mode.single.description"},{value:"stacked",labelKey:"diffView.mode.stacked.label",descriptionKey:"diffView.mode.stacked.description"}],x2=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"},wg=t=>{const e=x2(t);return vg[e]??g2},b2=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},y2=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},v2=t=>!!t.working_dir?.trim()||t.index==="?",w2=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),j2=(t,e)=>{const n=t.replace(/\\/g,"/").replace(/\/+$/g,""),r=e.replace(/\\/g,"/");if(w2(r))return r;const a=r.replace(/^\/+/,"");return n?`${n}/${a}`:a},sp=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),np=(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},N2=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},Bl=(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]})},S2=l.memo(t=>{const e=ot.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}=ft();let f;e[0]!==o?(f=N=>{if(!o)return N;const I=N.lastIndexOf("/");return I>=0?N.slice(I+1):N},e[0]=o,e[1]=f):f=e[1];const b=f;if(n.length===0)return null;let x;e[2]!==b||e[3]!==a||e[4]!==u?(x=a?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx(Ar,{filePath:a.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:b(a.path)}),Bl(a.insertions,a.deletions)]}):s.jsx("span",{className:"text-muted-foreground",children:u("diffView.selector.selectFile")}),e[2]=b,e[3]=a,e[4]=u,e[5]=x):x=e[5];let y;e[6]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[6]=y):y=e[6];let g;e[7]!==x?(g=s.jsx(Is,{asChild:!0,children:s.jsxs("button",{className:"flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",children:[x,y]})}),e[7]=x,e[8]=g):g=e[8];let h;e[9]!==d||e[10]!==p||e[11]!==m||e[12]!==u?(h=m&&d&&p?s.jsxs(s.Fragment,{children:[s.jsx(dh,{className:"typography-meta text-muted-foreground",children:u("diffView.selector.viewMode")}),s.jsx(Al,{value:d,onValueChange:N=>p(N),children:pl.map(N=>s.jsx(Dl,{value:N.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:u(N.labelKey)})},N.value))}),s.jsx(nr,{})]}):null,e[9]=d,e[10]=p,e[11]=m,e[12]=u,e[13]=h):h=e[13];const j=r??"";let v;if(e[14]!==n||e[15]!==b){let N;e[17]!==b?(N=I=>s.jsx(Dl,{value:I.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(Ar,{filePath:I.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:b(I.path)}),s.jsx("span",{className:"ml-auto",children:Bl(I.insertions,I.deletions)})]})},I.path),e[17]=b,e[18]=N):N=e[18],v=n.map(N),e[14]=n,e[15]=b,e[16]=v}else v=e[16];let C;e[19]!==i||e[20]!==j||e[21]!==v?(C=s.jsx(Al,{value:j,onValueChange:i,children:v}),e[19]=i,e[20]=j,e[21]=v,e[22]=C):C=e[22];let k;e[23]!==h||e[24]!==C?(k=s.jsxs(Ps,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[h,C]}),e[23]=h,e[24]=C,e[25]=k):k=e[25];let w;return e[26]!==k||e[27]!==g?(w=s.jsxs(As,{children:[g,k]}),e[26]=k,e[27]=g,e[28]=w):w=e[28],w}),k2=l.memo(t=>{const e=ot.c(31),{mode:n,onModeChange:r}=t,{t:a}=ft();let i,o,c,d,p,m;if(e[0]!==n||e[1]!==a){const v=pl.find(C=>C.value===n)??pl[0];o=As,i=Is,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(A,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[11]=f):f=e[11];let b;e[12]!==p||e[13]!==u?(b=s.jsxs("button",{className:p,children:[u,f]}),e[12]=p,e[13]=u,e[14]=b):b=e[14];let x;e[15]!==i||e[16]!==m||e[17]!==b?(x=s.jsx(i,{asChild:m,children:b}),e[15]=i,e[16]=m,e[17]=b,e[18]=x):x=e[18];let y;e[19]!==r?(y=v=>r(v),e[19]=r,e[20]=y):y=e[20];let g;e[21]!==a?(g=pl.map(v=>s.jsx(Dl,{value:v.value,children:s.jsx("span",{className:"typography-meta text-foreground",children:a(v.labelKey)})},v.value)),e[21]=a,e[22]=g):g=e[22];let h;e[23]!==n||e[24]!==g||e[25]!==y?(h=s.jsx(Ps,{className:"min-w-[140px]",children:s.jsx(Al,{value:n,onValueChange:y,children:g})}),e[23]=n,e[24]=g,e[25]=y,e[26]=h):h=e[26];let j;return e[27]!==o||e[28]!==h||e[29]!==x?(j=s.jsxs(o,{children:[x,h]}),e[27]=o,e[28]=h,e[29]=x,e[30]=j):j=e[30],j}),C2=l.memo(t=>{const e=ot.c(11),{changedFiles:n,selectedFile:r,onSelectFile:a}=t,{t:i}=ft();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=wg(p),u=r===p.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>a(p.path),className:ye("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(Ar,{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}),Bl(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(Ss,{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}),I2=l.memo(t=>{const e=ot.c(21),{filePath:n,diff:r,isVisible:a,renderSideBySide:i}=t,{t:o}=ft(),c=r.original.length>0,d=r.modified.length>0;if(!a){let y;return e[0]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"absolute inset-0 hidden"}),e[0]=y):y=e[0],y}const p=i?"flex flex-row gap-6 items-start justify-center h-full":"flex flex-col gap-4 items-center",m=i?"flex flex-col items-center gap-2 flex-1 min-w-0 h-full":"flex flex-col items-center gap-2";let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={contain:"size layout"},e[1]=u):u=e[1];let f;e[2]!==r.original||e[3]!==n||e[4]!==c||e[5]!==m||e[6]!==i||e[7]!==o?(f=c&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:o("diffView.image.original")}),s.jsx("img",{src:r.original,alt:o("diffView.image.originalAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[2]=r.original,e[3]=n,e[4]=c,e[5]=m,e[6]=i,e[7]=o,e[8]=f):f=e[8];let b;e[9]!==r.modified||e[10]!==n||e[11]!==d||e[12]!==c||e[13]!==m||e[14]!==i||e[15]!==o?(b=d&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:o(c?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:o("diffView.image.modifiedAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[9]=r.modified,e[10]=n,e[11]=d,e[12]=c,e[13]=m,e[14]=i,e[15]=o,e[16]=b):b=e[16];let x;return e[17]!==p||e[18]!==f||e[19]!==b?(x=s.jsx("div",{className:"absolute inset-0 overflow-auto p-4",style:u,children:s.jsxs("div",{className:p,children:[f,b]})}),e[17]=p,e[18]=f,e[19]=b,e[20]=x):x=e[20],x}),P2=l.memo(t=>{const e=ot.c(20),{filePath:n,diff:r,renderSideBySide:a}=t,{t:i}=ft(),o=r.original.length>0,c=r.modified.length>0,d=a?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",p=a?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={contain:"layout"},e[0]=m):m=e[0];let u;e[1]!==r.original||e[2]!==n||e[3]!==o||e[4]!==p||e[5]!==a||e[6]!==i?(u=o&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i("diffView.image.original")}),s.jsx("img",{src:r.original,alt:i("diffView.image.originalAlt",{path:n}),className:a?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=r.original,e[2]=n,e[3]=o,e[4]=p,e[5]=a,e[6]=i,e[7]=u):u=e[7];let f;e[8]!==r.modified||e[9]!==n||e[10]!==c||e[11]!==o||e[12]!==p||e[13]!==a||e[14]!==i?(f=c&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i(o?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:i("diffView.image.modifiedAlt",{path:n}),className:a?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=r.modified,e[9]=n,e[10]=c,e[11]=o,e[12]=p,e[13]=a,e[14]=i,e[15]=f):f=e[15];let b;return e[16]!==d||e[17]!==u||e[18]!==f?(b=s.jsx("div",{className:"w-full overflow-auto p-4",style:m,children:s.jsxs("div",{className:d,children:[u,f]})}),e[16]=d,e[17]=u,e[18]=f,e[19]=b):b=e[19],b}),A2=l.memo(t=>{const e=ot.c(15),{filePath:n,diff:r,renderSideBySide:a,wrapLines:i}=t;let o;e[0]!==n?(o=ki(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(yg,{}),e[2]=m):m=e[2],m}if(Ci(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a?(m=s.jsx(P2,{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(mu,{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}),D2=l.memo(t=>{const e=ot.c(15),{filePath:n,diff:r,isVisible:a,renderSideBySide:i,wrapLines:o}=t;let c;e[0]!==n?(c=ki(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(yg,{}),e[2]=m):m=e[2],m}if(!a)return null;if(Ci(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a||e[6]!==i?(m=s.jsx(I2,{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(Ss,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(mu,{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}),T2=l.memo(t=>{const e=ot.c(129),{directory:n,file:r,layout:a,wrapLines:i,scrollRootRef:o,isSelected:c,onSelect:d,registerSectionRef:p,defaultCollapsed:m,expandRequestPath:u,expandRequestNonce:f,showOpenInEditorAction:b,isOpeningInEditor:x,onOpenInEditor:y,staged:g,stagedRevision:h}=t,j=m===void 0?!1:m,v=u===void 0?null:u,C=f===void 0?0:f,k=b===void 0?!1:b,w=x===void 0?!1:x,N=g===void 0?!1:g,I=h===void 0?0:h,{t:T}=ft(),{git:P}=_n();let D;e[0]!==n||e[1]!==r.path?(D=at=>at.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=D):D=e[2];const S=Ys(D),M=Ys(M2),E=Fe(R2),[R,V]=l.useState(!j),[B,$]=l.useState(!1),[O,_]=l.useState(0),[q,L]=l.useState(null),[J,Z]=l.useState(!1),[ie,ne]=l.useState(!1),[me,pe]=l.useState(null),G=l.useRef(null),K=l.useRef(null);let Q;e[3]!==r?(Q=wg(r),e[3]=r,e[4]=Q):Q=e[4];const W=Q,de=a==="side-by-side";let ge;e:{if(N){ge=me;break e}if(!S){ge=null;break e}let at;e[5]!==S.isBinary||e[6]!==S.modified||e[7]!==S.original?(at={original:S.original,modified:S.modified,isBinary:S.isBinary},e[5]=S.isBinary,e[6]=S.modified,e[7]=S.original,e[8]=at):at=e[8],ge=at}const ve=ge;let te;e[9]!==r.path||e[10]!==p?(te=at=>{K.current=at,p(r.path,at)},e[9]=r.path,e[10]=p,e[11]=te):te=e[11];const he=te;let ce;e[12]===Symbol.for("react.memo_cache_sentinel")?(ce=at=>{V(at),at&&$(!0)},e[12]=ce):ce=e[12];const xe=ce;let se;e[13]!==r.path||e[14]!==d?(se=()=>{d(r.path)},e[13]=r.path,e[14]=d,e[15]=se):se=e[15];const ue=se;let Y,Se;e[16]!==B||e[17]!==R||e[18]!==o?(Y=()=>{if(!R||B)return;const at=K.current;if(!at)return;if(!o.current||typeof IntersectionObserver>"u"){$(!0);return}const Ae=new IntersectionObserver(Le=>{Le.some(F2)&&($(!0),Ae.disconnect())},{root:o.current,rootMargin:"200px 0px",threshold:.1});return Ae.observe(at),()=>Ae.disconnect()},Se=[B,R,o],e[16]=B,e[17]=R,e[18]=o,e[19]=Y,e[20]=Se):(Y=e[19],Se=e[20]),l.useEffect(Y,Se);let fe,Ce;e[21]!==C||e[22]!==v||e[23]!==r.path?(fe=()=>{C<=0||v!==r.path||(V(!0),$(!0))},Ce=[C,v,r.path],e[21]=C,e[22]=v,e[23]=r.path,e[24]=fe,e[25]=Ce):(fe=e[24],Ce=e[25]),l.useEffect(fe,Ce);let Ie;e[26]!==N?(Ie=()=>{N&&(pe(null),L(null),G.current=null)},e[26]=N,e[27]=Ie):Ie=e[27];let ke;e[28]!==N||e[29]!==I?(ke=[N,I],e[28]=N,e[29]=I,e[30]=ke):ke=e[30],l.useEffect(Ie,ke);let X,ae;e[31]!==ve||e[32]!==O||e[33]!==n||e[34]!==r.path||e[35]!==P||e[36]!==B||e[37]!==R||e[38]!==M||e[39]!==N||e[40]!==I?(X=()=>{if(!R||!B)return;if(!n||ve){G.current=null,Z(!1);return}const at=`${n}::${r.path}::${N?`staged:${I}`:"unstaged"}::${O}`;if(G.current===at)return;G.current=at,L(null),Z(!0);let Ae=!1;const Le=P.getGitFileDiff(n,{path:r.path,staged:N}),ze=new Promise(O2);return Promise.race([Le,ze]).then(Ke=>{if(Ae)return;const lt={original:Ke.original??"",modified:Ke.modified??"",isBinary:Ke.isBinary};N?pe(lt):M(n,r.path,lt),Z(!1)}).catch(Ke=>{if(Ae)return;const lt=Ke instanceof Error?Ke.message:String(Ke);L(lt),Z(!1)}),()=>{Ae=!0,G.current===at&&(G.current=null)}},ae=[n,ve,O,r.path,P,B,R,M,N,I],e[31]=ve,e[32]=O,e[33]=n,e[34]=r.path,e[35]=P,e[36]=B,e[37]=R,e[38]=M,e[39]=N,e[40]=I,e[41]=X,e[42]=ae):(X=e[41],ae=e[42]),l.useEffect(X,ae);let je;e[43]!==ue||e[44]!==R?(je=()=>{xe(!R),ue()},e[43]=ue,e[44]=R,e[45]=je):je=e[45];const le=je,Ne=R?"rounded-b-none":"rounded-b-xl",Me=c?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let Ve;e[46]!==Ne||e[47]!==Me?(Ve=ye("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",Me),e[46]=Ne,e[47]=Me,e[48]=Ve):Ve=e[48];let we;e[49]===Symbol.for("react.memo_cache_sentinel")?(we=s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-interactive-hover"}),e[49]=we):we=e[49];let ee;e[50]!==R?(ee=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:R?s.jsx(A,{name:"arrow-down-s",className:"size-4"}):s.jsx(A,{name:"arrow-right-s",className:"size-4"})}),e[50]=R,e[51]=ee):ee=e[51];let F;e[52]!==W.color?(F={color:W.color},e[52]=W.color,e[53]=F):F=e[53];let U;e[54]!==W.descriptionKey||e[55]!==T?(U=T(W.descriptionKey),e[54]=W.descriptionKey,e[55]=T,e[56]=U):U=e[56];let oe;e[57]!==W.descriptionKey||e[58]!==T?(oe=T(W.descriptionKey),e[57]=W.descriptionKey,e[58]=T,e[59]=oe):oe=e[59];let Te;e[60]!==W.code||e[61]!==F||e[62]!==U||e[63]!==oe?(Te=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:F,title:U,"aria-label":oe,children:W.code}),e[60]=W.code,e[61]=F,e[62]=U,e[63]=oe,e[64]=Te):Te=e[64];const Oe=r.path;let Pe;e[65]!==r.path?(Pe=s.jsx(Ar,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[65]=r.path,e[66]=Pe):Pe=e[66];let z;if(e[67]!==r.path){e:{const at=r.path.lastIndexOf("/");if(at===-1){let ut;e[69]===Symbol.for("react.memo_cache_sentinel")?(ut={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[69]=ut):ut=e[69],z=s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:ut,children:r.path});break e}const Ae=r.path.slice(0,at),Le=r.path.slice(at+1);let ze;e[70]===Symbol.for("react.memo_cache_sentinel")?(ze={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[70]=ze):ze=e[70];let Ke;e[71]!==Ae?(Ke=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:ze,children:Ae}),e[71]=Ae,e[72]=Ke):Ke=e[72];let lt;e[73]===Symbol.for("react.memo_cache_sentinel")?(lt=s.jsx("span",{className:"text-muted-foreground",children:"/"}),e[73]=lt):lt=e[73];let xt;e[74]!==Le?(xt=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[lt,s.jsx("span",{className:"text-foreground",children:Le})]}),e[74]=Le,e[75]=xt):xt=e[75];let dt;e[76]!==Ke||e[77]!==xt?(dt=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[Ke,xt]}),e[76]=Ke,e[77]=xt,e[78]=dt):dt=e[78],z=dt}e[67]=r.path,e[68]=z}else z=e[68];let De;e[79]!==Pe||e[80]!==z?(De=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[Pe,z]}),e[79]=Pe,e[80]=z,e[81]=De):De=e[81];let Qe;e[82]!==r.path||e[83]!==De?(Qe=s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:Oe,children:De}),e[82]=r.path,e[83]=De,e[84]=Qe):Qe=e[84];let et;e[85]!==ee||e[86]!==Te||e[87]!==Qe?(et=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[ee,Te,Qe]}),e[85]=ee,e[86]=Te,e[87]=Qe,e[88]=et):et=e[88];let Ze;e[89]!==r.deletions||e[90]!==r.insertions?(Ze=Bl(r.insertions,r.deletions),e[89]=r.deletions,e[90]=r.insertions,e[91]=Ze):Ze=e[91];let We;e[92]!==ve||e[93]!==r.path||e[94]!==w||e[95]!==y||e[96]!==k||e[97]!==T?(We=k&&y?s.jsx(be,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:T("diffView.actions.openFileInEditorAtChange"),onClick:at=>{at.stopPropagation(),y(r.path,ve)},disabled:w,children:w?s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(A,{name:"edit",className:"size-3.5"})}):null,e[92]=ve,e[93]=r.path,e[94]=w,e[95]=y,e[96]=k,e[97]=T,e[98]=We):We=e[98];const it=de?"side-by-side":"unified";let qe;e[99]!==r.path||e[100]!==E?(qe=at=>{const Ae=at==="side-by-side"?"side-by-side":"inline";E(r.path,Ae)},e[99]=r.path,e[100]=E,e[101]=qe):qe=e[101];let st;e[102]!==it||e[103]!==qe?(st=s.jsx(jh,{mode:it,onModeChange:qe,className:"opacity-70"}),e[102]=it,e[103]=qe,e[104]=st):st=e[104];let Je;e[105]!==Ze||e[106]!==We||e[107]!==st?(Je=s.jsxs("div",{className:"relative flex items-center gap-2",children:[Ze,We,st]}),e[105]=Ze,e[106]=We,e[107]=st,e[108]=Je):Je=e[108];let Be;e[109]!==le||e[110]!==Ve||e[111]!==et||e[112]!==Je?(Be=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:le,className:Ve,children:[we,et,Je]})}),e[109]=le,e[110]=Ve,e[111]=et,e[112]=Je,e[113]=Be):Be=e[113];let nt;e[114]!==ve||e[115]!==q||e[116]!==r.deletions||e[117]!==r.insertions||e[118]!==r.path||e[119]!==ie||e[120]!==R||e[121]!==J||e[122]!==de||e[123]!==i?(nt=R&&s.jsxs("div",{className:"relative border border-t-0 border-border/60 bg-background rounded-b-xl overflow-hidden",children:[q?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:q}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>_(L2),children:"Retry"})]}):null,J&&!ve&&!q?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),"Loading diff…"]}):null,ve&&!ie&&r.insertions+r.deletions>tp?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:()=>ne(!0),children:"Render anyway"})]}):null,ve&&(ie||r.insertions+r.deletions<=tp)?s.jsx(A2,{filePath:r.path,diff:ve,renderSideBySide:de,wrapLines:i}):null]}),e[114]=ve,e[115]=q,e[116]=r.deletions,e[117]=r.insertions,e[118]=r.path,e[119]=ie,e[120]=R,e[121]=J,e[122]=de,e[123]=i,e[124]=nt):nt=e[124];let Ge;return e[125]!==he||e[126]!==Be||e[127]!==nt?(Ge=s.jsxs("div",{ref:he,className:"scroll-mt-4",children:[Be,nt]}),e[125]=he,e[126]=Be,e[127]=nt,e[128]=Ge):Ge=e[128],Ge}),jg=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:a=!1,diffScope:i="all",targetFilePath:o=null})=>{const{t:c}=ft(),{git:d,files:p}=_n(),m=na(),{screenWidth:u,isMobile:f}=ln(),b=Qd(m??null),x=Zl(m??null),y=Zd(m??null),g=Ys(We=>We.setActiveDirectory),h=Ys(We=>We.ensureStatus),j=Ys(We=>We.fetchStatus),v=Ys(We=>We.setDiff),C=Ys(l.useCallback(We=>m?We.directories.get(m)?.indexRevision??0:0,[m])),[k,w]=l.useState(null),[N,I]=l.useState(!1),[T,P]=l.useState(null),[D,S]=l.useState(null),[M,E]=l.useState(0),[R,V]=l.useState(null),[B,$]=l.useState(0),[O,_]=l.useState(null),q=l.useRef(null),L=Fe(We=>We.pendingDiffFile),J=Fe(We=>We.pendingDiffStaged),Z=Fe(We=>We.setPendingDiffFile),ie=Fe(We=>We.diffLayoutPreference),ne=Fe(We=>We.diffFileLayout),me=Fe(We=>We.setDiffFileLayout),pe=Fe(We=>We.diffWrapLines),G=Fe(We=>We.setDiffWrapLines),K=Fe(We=>We.diffViewMode),Q=Fe(We=>We.setDiffViewMode),W=Fe(We=>We.openContextFileAtLine),de=pe,ge=i==="staged"?!0:i==="working"?!1:null,ve=ge??N,te=K==="stacked",he=f||u<=768,ce=!t&&!he&&u>=1024,xe=l.useRef(null),se=l.useRef(new Map),ue=l.useRef(null),Y=l.useRef(null),Se=l.useRef(!1);l.useEffect(()=>{if(!r||!te||!R)return;const We=xe.current;if(!We)return;let it=null,qe=!1,st=0;const Je=Date.now()+1200;let Be=0;const nt=()=>{qe||(qe=!0,V(null))},Ge=()=>{nt()},at=()=>{if(Be>0){Be-=1;return}nt()};window.addEventListener("wheel",Ge,{passive:!0,capture:!0}),window.addEventListener("touchstart",Ge,{passive:!0,capture:!0}),window.addEventListener("pointerdown",Ge,{capture:!0}),window.addEventListener("keydown",Ge,{capture:!0}),We.addEventListener("scroll",at,{passive:!0});const Ae=()=>{if(qe||Date.now()>Je){nt();return}const Le=xe.current,ze=se.current.get(R);if(!Le||!ze){nt();return}const Ke=Le.getBoundingClientRect(),xt=ze.getBoundingClientRect().top-Ke.top;if(Math.abs(xt)<=1){if(st+=1,st>=2){nt();return}}else{st=0;const dt=Math.max(0,Le.scrollHeight-Le.clientHeight),ut=Math.min(dt,Math.max(0,Le.scrollTop+xt));if(Math.abs(ut-Le.scrollTop)<=.5){nt();return}Be+=1,Le.scrollTop=ut}it=window.requestAnimationFrame(Ae)};return it=window.requestAnimationFrame(Ae),()=>{qe=!0,it!==null&&window.cancelAnimationFrame(it),window.removeEventListener("wheel",Ge,!0),window.removeEventListener("touchstart",Ge,!0),window.removeEventListener("pointerdown",Ge,!0),window.removeEventListener("keydown",Ge,!0),We.removeEventListener("scroll",at)}},[te,r,R]);const fe=l.useMemo(()=>{if(!x?.files)return[];const We=x.diffStats??{},it=i==="staged"?y2:i==="working"?v2:()=>!0;return x.files.filter(it).map(qe=>({...qe,insertions:We[qe.path]?.insertions??0,deletions:We[qe.path]?.deletions??0,isNew:b2(qe)})).sort((qe,st)=>qe.path.localeCompare(st.path))},[i,x]),Ce=l.useMemo(()=>k?fe.find(We=>We.path===k)??null:null,[fe,k]),Ie=l.useCallback(We=>{const it=ne[We.path];if(it)return it;if(ie==="inline")return"inline";if(ie==="side-by-side")return"side-by-side";const qe=u<f2;return We.isNew||qe?"inline":"side-by-side"},[ne,ie,u]),ke=l.useMemo(()=>Ce?Ie(Ce):null,[Ie,Ce]);l.useEffect(()=>{m&&(g(m),h(m,d))},[m,g,h,d]),l.useEffect(()=>{if(m)return Dr.onGitRefreshHint(We=>{sp(We.directory)===sp(m)&&j(m,d)})},[m,j,d]),l.useEffect(()=>{i==="all"&&L&&(w(L),I(J),P(null),Z(null),te&&(Se.current=!0,ue.current=L,S(L),E(We=>We+1)))},[i,te,L,J,Z]),l.useEffect(()=>{if(i==="all")return;const We=o?.trim();We&&(w(We),I(i==="staged"),P(null),te&&(Se.current=!0,ue.current=We,S(We),E(it=>it+1)))},[i,te,o]),l.useEffect(()=>{ve&&(P(null),_(null),q.current=null)},[ve,C]),l.useEffect(()=>{!k&&!L&&fe.length>0&&w(fe[0].path)},[fe,k,L]),l.useEffect(()=>{k&&fe.length>0&&(fe.some(it=>it.path===k)||w(fe[0]?.path??null))},[fe,k]);const X=l.useCallback((We,it)=>{const qe=se.current;it?qe.set(We,it):qe.delete(We)},[]),ae=l.useCallback(We=>{const it=se.current.get(We),qe=xe.current;if(!it||!qe)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const st=qe.getBoundingClientRect(),Be=it.getBoundingClientRect().top-st.top,nt=Math.max(0,qe.scrollHeight-qe.clientHeight),Ge=qe.scrollTop+Be,at=Math.min(nt,Math.max(0,Ge)),Ae=Math.abs(at-qe.scrollTop)>.5;qe.scrollTop=at;const Le=Math.abs(Be)<=1,ze=at<=.5||at>=nt-.5;return{ok:!0,aligned:Le,didMove:Ae,atScrollLimit:ze,delta:Be}},[]);l.useEffect(()=>{if(!te){ue.current=null,Se.current=!1,Y.current!==null&&(window.cancelAnimationFrame(Y.current),Y.current=null);return}if(!ue.current)return;let it=0;const qe=120;let st=!1,Je=0,Be=!1,nt=0;const Ge=Date.now()+2e3,at=()=>{Be||(Be=!0,window.removeEventListener("wheel",Le,!0),window.removeEventListener("touchstart",Le,!0),window.removeEventListener("pointerdown",Le,!0),window.removeEventListener("keydown",Le,!0),Ke?.removeEventListener("scroll",ze))},Ae=()=>{st||(st=!0,at(),ue.current=null,Se.current=!1,Y.current!==null&&(window.cancelAnimationFrame(Y.current),Y.current=null))},Le=()=>{Ae()},ze=()=>{if(Je>0){Je-=1;return}Ae()},Ke=xe.current;window.addEventListener("wheel",Le,{passive:!0,capture:!0}),window.addEventListener("touchstart",Le,{passive:!0,capture:!0}),window.addEventListener("pointerdown",Le,{capture:!0}),window.addEventListener("keydown",Le,{capture:!0}),Ke?.addEventListener("scroll",ze,{passive:!0});const lt=()=>{if(Date.now()>Ge){Ae(),Y.current=null;return}if(st){Y.current=null;return}const xt=ue.current;if(!xt){Ae(),Y.current=null;return}Je+=1;const dt=ae(xt);if(!dt.ok){Je=Math.max(0,Je-1),it+=1,it<qe?Y.current=window.requestAnimationFrame(lt):(Ae(),Y.current=null);return}if(!dt.aligned){if(it+=1,dt.didMove){if(nt=0,it<qe){Y.current=window.requestAnimationFrame(lt);return}}else if(nt+=1,nt<6&&(dt.atScrollLimit||Math.abs(dt.delta)>1)){Y.current=window.requestAnimationFrame(lt);return}}r&&Se.current&&V(xt),Ae()};return Y.current=window.requestAnimationFrame(lt),()=>{st=!0,at(),Y.current!==null&&(window.cancelAnimationFrame(Y.current),Y.current=null)}},[te,r,ae,k,M]);const je=l.useCallback(We=>{w(We),I(!1),P(null)},[]),le=l.useCallback(We=>{if(Y.current!==null&&(window.cancelAnimationFrame(Y.current),Y.current=null),ue.current=null,w(We),I(!1),P(null),!te){Se.current=!1;return}Se.current=!0,ue.current=We,ae(We)},[te,ae]),Ne=l.useCallback(We=>{Q(We),We==="stacked"&&k&&(ae(k).aligned||(ue.current=k))},[ae,k,Q]),Me=l.useCallback(We=>{const it=We==="side-by-side"?"side-by-side":"inline";if(te){fe.forEach(qe=>{me(qe.path,it)});return}Ce&&me(Ce.path,it)},[fe,te,Ce,me]),Ve=(ke??"side-by-side")==="side-by-side",we=!n&&(!te||!ce),ee=Ys(l.useCallback(We=>!m||!k||ve?null:We.directories.get(m)?.diffCache.get(k)??null,[ve,m,k])),F=l.useMemo(()=>ve?T:ee?{original:ee.original,modified:ee.modified,isBinary:ee.isBinary}:null,[ve,ee,T]),[U,oe]=l.useState(null),Te=l.useCallback(async(We,it)=>{if(!(!m||!We)){oe(We);try{let qe=null;if(it&&!it.isBinary&&!Ci(We)&&(qe=np(it.original,it.modified)),qe===null)try{const Ge=await d.getGitDiff(m,{path:We,staged:ve,contextLines:3});qe=N2(Ge.diff)}catch{qe=null}let st=it;if(qe===null||!st){const Ge=await d.getGitFileDiff(m,{path:We,staged:ve});st={original:Ge.original??"",modified:Ge.modified??"",isBinary:Ge.isBinary},ve||v(m,We,st)}const Je=qe??(st.isBinary||Ci(We)?1:np(st.original,st.modified)),Be=j2(m,We),nt=await hu(p,Be);if(!nt.ok){H.error(gu(nt.reason));return}W(m,Be,Je,1)}finally{oe(qe=>qe===We?null:qe)}}},[ve,m,p,d,W,v]),Oe=l.useCallback(async()=>{k&&await Te(k,F)},[Te,F,k]),Pe=!!(k&&U===k),z=ve?!!T:!!ee,De=!te&&!!k&&!z;l.useEffect(()=>{if(te)return;if(_(null),!m||!k){q.current=null;return}if(ve?T:ee){q.current=null;return}const We=`${m}::${k}::${ve?`staged:${C}`:"unstaged"}::${B}`;if(q.current===We)return;q.current=We;let it=!1;const qe=d.getGitFileDiff(m,{path:k,staged:ve}),st=Id,Je=new Promise((Be,nt)=>{setTimeout(()=>nt(new Error(`Timed out after ${st}ms`)),st)});return Promise.race([qe,Je]).then(Be=>{if(it)return;const nt={original:Be.original??"",modified:Be.modified??"",isBinary:Be.isBinary};ve?P(nt):v(m,k,nt)}).catch(Be=>{if(it)return;const nt=Be instanceof Error?Be.message:String(Be);_(nt)}),()=>{it=!0,q.current===We&&(q.current=null)}},[ve,m,C,te,k,ee,T,d,v,B]);const Qe=()=>!m||!k||!F?null:s.jsx(D2,{filePath:k,diff:F,isVisible:!0,renderSideBySide:Ve,wrapLines:de},k),et=()=>{if(!m)return null;const We=h2(fe.length),it=qe=>ge!==null?ge:N&&qe===k;return s.jsxs("div",{className:"flex flex-1 min-h-0 h-full gap-3 px-3 pb-3 pt-2",children:[ce&&s.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:c("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:fe.length})]}),s.jsx(C2,{changedFiles:fe,selectedFile:k,onSelectFile:le})]}),s.jsx(Ss,{ref:xe,outerClassName:"flex-1 min-h-0 h-full",className:"pr-2",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx("div",{className:"flex flex-col gap-3",children:fe.map((qe,st)=>s.jsx(T2,{directory:m,file:qe,layout:Ie(qe),wrapLines:de,scrollRootRef:xe,isSelected:qe.path===k,onSelect:je,registerSectionRef:X,defaultCollapsed:e?!0:st>=We,expandRequestPath:D,expandRequestNonce:M,showOpenInEditorAction:a,isOpeningInEditor:U===qe.path,onOpenInEditor:(Je,Be)=>{Te(Je,Be)},staged:it(qe.path),stagedRevision:C},`${it(qe.path)?"staged":"unstaged"}:${qe.path}`))})})]})},Ze=()=>m?y&&!x?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),c("diffView.state.loadingRepositoryStatus")]}):b===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:c("diffView.state.notGitRepository")}):fe.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:c("diffView.state.cleanWorkingTree")}):te?et():s.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden px-3 py-3 relative","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:[Qe(),De&&!z&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted-foreground",children:O?s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:c("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:O}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>{_(null),$(We=>We+1)},children:c("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),c("diffView.state.loadingDiff")]})})]}):s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:c("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 bg-background",children:[!f&&s.jsxs("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:[s.jsx(A,{name:"git-commit",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:y&&!x?c("diffView.state.loadingChanges"):fe.length===1?c("diffView.summary.changedFilesSingle",{count:fe.length}):c("diffView.summary.changedFilesPlural",{count:fe.length})})]}),!he&&s.jsx(k2,{mode:K,onModeChange:Ne}),we&&s.jsx(S2,{changedFiles:fe,selectedFile:k,selectedFileEntry:Ce,onSelectFile:le,isMobile:he,showModeSelector:he,mode:K,onModeChange:Ne}),s.jsx("div",{className:"flex-1"}),Ce&&s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>G(!pe),className:ye("h-5 w-5 p-0 transition-opacity",de?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:c(de?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(A,{name:"text-wrap",className:"size-4"})}),a&&Ce&&!te&&s.jsx(be,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{Oe()},disabled:Pe,title:c("diffView.actions.openFileAtFirstChangedLine"),children:Pe?s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(A,{name:"edit",className:"size-3.5"})}),Ce&&ke&&s.jsx(jh,{mode:ke==="side-by-side"?"side-by-side":"unified",onModeChange:Me})]}),Ze()]})},E2=()=>{const t=ot.c(6),{git:e}=_n(),n=na(),r=Ys($2),a=Ys(_2),i=qb(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 M2(t){return t.setDiff}function R2(t){return t.setDiffFileLayout}function F2(t){return t.isIntersecting}function O2(t,e){setTimeout(()=>e(new Error(`Timed out after ${Id}ms`)),Id)}function L2(t){return t+1}function $2(t){return t.setActiveDirectory}function _2(t){return t.ensureStatus}const B2=Object.freeze(Object.defineProperty({__proto__:null,DiffView:jg,useDiffFileCount:E2},Symbol.toStringTag,{value:"Module"})),V2={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},z2={case:"Match case",re:"Regular expression",word:"Match whole word"};function U2(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(V2)){const a=e.querySelector(`button[name="${n}"]`);a&&!a.title&&(a.title=r)}for(const[n,r]of Object.entries(z2)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=r)}}}const Lc=new WeakMap;function W2(t,e){const n=Cl(t.state);if(!n.valid)return Lc.delete(t),0;const r=Lc.get(t);if(!e&&r?.doc===t.state.doc&&r.query.eq(n))return r.total;const a=n.getCursor(t.state);let i=0;for(let o=a.next();!o.done;o=a.next())i+=1;return Lc.set(t,{query:n,doc:t.state.doc,total:i}),i}function K2(t){const e=Cl(t.state);if(!e.valid)return 0;const n=t.state.selection.main,r=e.getCursor(t.state);let a=0,i=0;for(let o=r.next();!o.done;o=r.next()){const c=o.value;if(a+=1,i===0&&(i=a),n.from===c.from&&n.to===c.to||n.from<c.to&&n.to>c.from||c.from>=n.head)return a}return i}function rp(t,e,n=!1){const r=t.querySelector(".cm-search");if(!r)return;let a=r.querySelector(".cm-search-message");if(!a){a=document.createElement("span"),a.className="cm-search-message",a.setAttribute("aria-live","polite");const c=r.querySelector('button[name="next"]'),d=c?.parentNode===r?c:r.firstChild;r.insertBefore(a,d)}const i=W2(e,n),o=i===0?0:K2(e);a.textContent=i===0?"":`${o}/${i}`}const ap=new Mi,ip=new Mi,op=new Mi,lp=new Mi,cp=new Mi,dp=new Mi,up=t=>t,$c=Lx,H2=$x,G2=_x;class q2 extends Bx{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 mp=(t,e)=>!t||t.length===0?[]:Ox.define({create(n){const r=new oh,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,lh.widget({widget:new q2(i.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>Ln.decorations.from(n)}),pp=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return Fx.fromClass(class{decorations;constructor(r){this.decorations=this.build(r)}update(r){(r.docChanged||r.viewportChanged)&&(this.decorations=this.build(r.view))}build(r){const a=new oh;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,lh.line({class:"oc-cm-selected-line"}))}return a.finish()}},{decorations:r=>r.decorations})};function yo({value:t,onChange:e,extensions:n,className:r,readOnly:a,lineNumbersConfig:i,highlightLines:o,onViewReady:c,onViewDestroy:d,blockWidgets:p,enableSearch:m,searchOpen:u,onSearchOpenChange:f}){const b=l.useRef(null),x=l.useRef(null),y=l.useRef(t),g=l.useRef(e),h=l.useRef(c),j=l.useRef(d),v=l.useRef(f),C=l.useRef(p),k=l.useRef(new Map),[w,N]=l.useState([]),I=l.useCallback(P=>{const D=(P??[]).map(S=>{const M=k.current.get(S.id);return M?{id:S.id,content:S.content,container:M}:null}).filter(S=>S!==null);N(S=>S.length===D.length&&S.every((M,E)=>{const R=D[E];return M.id===R.id&&M.content===R.content&&M.container===R.container})?S:D)},[]),T=l.useCallback(P=>{const D=b.current,S=P??x.current;if(!D||!S)return;const M=S.dom.querySelector(".cm-gutters"),E=M instanceof HTMLElement?M.getBoundingClientRect().width:0;D.style.setProperty("--oc-editor-gutter-width",`${E}px`)},[]);return l.useEffect(()=>{y.current=t},[t]),l.useEffect(()=>{g.current=e},[e]),l.useEffect(()=>{h.current=c,j.current=d},[c,d]),l.useEffect(()=>{v.current=f},[f]),l.useEffect(()=>{C.current=p,I(p)},[p,I]),l.useEffect(()=>{if(!b.current)return;const P=(()=>{if(typeof document>"u")return null;const S=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(S)return S;const M=window.__OPENCHAMBER_CSP_NONCE__;return typeof M=="string"&&M.length>0?M:null})(),D=Px.create({doc:y.current,extensions:[...P?[Ln.cspNonce.of(P)]:[],Ax({fixed:!0}),ap.of(Au(i)),Dx(),Tx.of(" "),mc.of([Ex,...Mx,...Rx]),Ln.updateListener.of(S=>{T(S.view),(S.viewportChanged||S.geometryChanged)&&I(C.current);const M=Du(S.startState),E=Du(S.state);M!==E&&v.current?.(E);const R=!Cl(S.startState).eq(Cl(S.state));if(E&&(M!==E||R||S.docChanged||S.selectionSet)&&rp(S.view.dom,S.view,M!==E||R||S.docChanged),!S.docChanged)return;const V=S.state.doc.toString();y.current=V,g.current(V),I(C.current)}),ip.of(Ln.editable.of(!a)),op.of(n??[]),lp.of(pp(o)),cp.of(mp(p,k.current)),dp.of(m?[Tu({top:!0}),mc.of(up(Eu))]:[])]});return x.current=new Ln({state:D,parent:b.current}),$c(x.current,x.current.state.doc.length,200),x.current.requestMeasure(),requestAnimationFrame(()=>{T(x.current),I(C.current)}),x.current&&h.current?.(x.current),()=>{j.current?.(),x.current?.destroy(),x.current=null,N([])}},[C,T,I]),l.useEffect(()=>{const P=x.current;P&&(P.dispatch({effects:[ap.reconfigure(Au(i)),ip.reconfigure(Ln.editable.of(!a)),op.reconfigure(n??[]),lp.reconfigure(pp(o)),cp.reconfigure(mp(p,k.current)),dp.reconfigure(m?[Tu({top:!0}),mc.of(up(Eu))]:[])]}),$c(P,P.state.doc.length,200),P.requestMeasure(),requestAnimationFrame(()=>{T(P),I(C.current)}))},[n,o,i,a,p,m,T,I]),l.useEffect(()=>{const P=x.current;!P||m===!1||(u?(H2(P),requestAnimationFrame(()=>{U2(P.dom),rp(P.dom,P,!0)})):G2(P))},[u,m]),l.useEffect(()=>{const P=x.current;if(!P)return;const D=P.state.doc.toString();D!==t&&(P.dispatch({changes:{from:0,to:D.length,insert:t}}),$c(P,P.state.doc.length,300),P.requestMeasure(),requestAnimationFrame(()=>T(P)))},[t,T]),s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:b,className:ye("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",r)}),w.map(P=>sl.createPortal(P.content,P.container,P.id))]})}const J2=(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)},fp=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},hp=(t,e,n)=>{const r=t.state.doc.line(e),a=Math.max(1,Math.min(n,r.length+1)),i=r.from+a-1;t.dispatch({selection:Vx.cursor(i),effects:Ln.scrollIntoView(i,{y:"center"})})};function Y2({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:a}=ft(),[i,o]=l.useState(""),c=l.useRef(null),d=l.useRef(!1),p=l.useRef(null),m=l.useRef(null),u=l.useMemo(()=>J2(i,n),[i,n]);l.useEffect(()=>{!t||!n||(d.current=!1,c.current=fp(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:g}=c.current;n.dispatch({selection:g,effects:Ln.scrollIntoView(g.main.from,{y:"center"})});return}hp(n,u,c.current.character)}},[u,t,n]);const f=l.useCallback(()=>{if(!n||d.current||!c.current)return;const{selection:g}=c.current;n.dispatch({selection:g,effects:Ln.scrollIntoView(g.main.from,{y:"center"})})},[n]),b=l.useCallback(g=>{g||f(),e(g)},[e,f]),x=l.useCallback(()=>{!n||u===null||!c.current||(d.current=!0,hp(n,u,c.current.character),e(!1),n.focus())},[u,e,n]);l.useEffect(()=>{if(!t)return;const g=j=>{const v=p.current,C=j.target;!v||!(C instanceof Node)||v.contains(C)||b(!1)},h=j=>{j.key==="Escape"&&(j.preventDefault(),b(!1))};return document.addEventListener("pointerdown",g,!0),document.addEventListener("keydown",h,!0),()=>{document.removeEventListener("pointerdown",g,!0),document.removeEventListener("keydown",h,!0)}},[b,t,r]);const y=l.useMemo(()=>{if(!n)return a("goToLineDialog.helper.editorUnavailable");if(u===null){const g=c.current??fp(n,n.state.selection);return a("goToLineDialog.helper.currentLineRange",{current:g.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(Lt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:g=>o(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),x())},placeholder:a("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(be,{variant:"outline",size:"xs",onClick:x,disabled:!n||u===null,className:"h-6 px-2",children:a("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:p,className:ye("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(Lt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:g=>o(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),x())},placeholder:a("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:y})]})})}const Vl=t=>{const e=ot.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(A,{name:"eye",className:"size-4","aria-hidden":"true"}):s.jsx(A,{name:"eye-off",className:"size-4","aria-hidden":"true"}),e[0]=a,e[1]=c):c=e[1];let d;e[2]!==i||e[3]!==r||e[4]!==c?(d=s.jsx(Ct,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",onClick:r,"aria-label":i,className:"h-5 w-5 p-0",children:c})}),e[2]=i,e[3]=r,e[4]=c,e[5]=d):d=e[5];let p;e[6]!==o?(p=s.jsx(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(kt,{children:[d,p]}),e[8]=d,e[9]=p,e[10]=m):m=e[10],m};function vo(t){const e=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",r=t.colors.syntax.highlights||{},a=t.colors.syntax.tokens||{},i=Ln.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=Mu.define([{tag:[gt.comment,gt.docComment,gt.meta,gt.documentMeta],class:"cm-comment"},{tag:[gt.keyword,gt.controlKeyword,gt.moduleKeyword,gt.definitionKeyword,gt.modifier],class:"cm-keyword"},{tag:[gt.operatorKeyword,gt.operator,gt.derefOperator,gt.updateOperator,gt.definitionOperator,gt.typeOperator,gt.controlOperator,gt.logicOperator,gt.bitwiseOperator,gt.arithmeticOperator,gt.compareOperator],class:"cm-operator"},{tag:[gt.punctuation,gt.separator,gt.bracket,gt.paren,gt.brace,gt.squareBracket,gt.angleBracket],class:"cm-punctuation"},{tag:[gt.string,gt.regexp,gt.attributeValue,gt.special(gt.string),gt.monospace],class:"cm-string"},{tag:gt.escape,class:"cm-string-2"},{tag:[gt.number,gt.bool,gt.atom,gt.null,gt.self],class:"cm-number"},{tag:[gt.function(gt.variableName),gt.function(gt.definition(gt.variableName)),gt.function(gt.propertyName),gt.standard(gt.variableName),gt.special(gt.variableName)],class:"cm-builtin"},{tag:gt.definition(gt.variableName),class:"cm-def"},{tag:[gt.variableName,gt.local(gt.variableName),gt.constant(gt.variableName),gt.literal],class:"cm-variable"},{tag:gt.propertyName,class:"cm-property"},{tag:gt.attributeName,class:"cm-attribute"},{tag:[gt.className,gt.typeName,gt.namespace],class:"cm-variable-3"},{tag:[gt.tagName,gt.labelName,gt.annotation,gt.macroName],class:"cm-tag"},{tag:gt.link,class:"cm-link"},{tag:[gt.heading,gt.heading1,gt.heading2,gt.heading3,gt.heading4,gt.heading5,gt.heading6],class:"cm-keyword"}]),c=Mu.define([{tag:[gt.comment,gt.docComment,gt.meta,gt.documentMeta],color:t.colors.syntax.base.comment},{tag:[gt.keyword,gt.controlKeyword,gt.moduleKeyword,gt.definitionKeyword,gt.modifier],color:t.colors.syntax.base.keyword},{tag:[gt.operatorKeyword,gt.operator,gt.derefOperator,gt.updateOperator,gt.definitionOperator,gt.typeOperator,gt.controlOperator,gt.logicOperator,gt.bitwiseOperator,gt.arithmeticOperator,gt.compareOperator],color:t.colors.syntax.base.operator},{tag:[gt.string,gt.regexp,gt.attributeValue,gt.special(gt.string),gt.monospace],color:t.colors.syntax.base.string},{tag:gt.escape,color:a.stringEscape||t.colors.syntax.base.string},{tag:[gt.number,gt.bool,gt.atom,gt.null,gt.self],color:t.colors.syntax.base.number},{tag:[gt.function(gt.variableName),gt.function(gt.definition(gt.variableName)),gt.function(gt.propertyName),gt.standard(gt.variableName),gt.special(gt.variableName)],color:t.colors.syntax.base.function},{tag:gt.definition(gt.variableName),color:a.variableGlobal||t.colors.syntax.base.variable},{tag:[gt.variableName,gt.local(gt.variableName),gt.constant(gt.variableName),gt.literal],color:t.colors.syntax.base.variable},{tag:gt.propertyName,color:a.variableProperty||t.colors.syntax.base.variable},{tag:gt.attributeName,color:a.variableOther||t.colors.syntax.base.variable},{tag:[gt.className,gt.typeName,gt.namespace],color:t.colors.syntax.base.type},{tag:[gt.tagName,gt.labelName,gt.annotation,gt.macroName],color:a.tag||t.colors.syntax.base.keyword},{tag:gt.link,color:a.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[gt.punctuation,gt.separator,gt.bracket,gt.paren,gt.brace,gt.squareBracket,gt.angleBracket],color:a.punctuation||t.colors.syntax.base.comment}]);return[i,To(zx,{fallback:!0}),To(Ux),To(o),To(c)]}const Q2=t=>{const e=gn(t);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const n=e.lastIndexOf("/");if(n<0)return e;if(n===0)return"/";const r=e.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r},X2=t=>{const e=ot.c(8),{label:n,iconDataUrl:r}=t,[a,i]=l.useState(!1);let o;e[0]!==n?(o=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=o):o=e[1];const c=o;if(r&&!a){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>i(!0),e[2]=m):m=e[2];let u;return e[3]!==r?(u=s.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=r,e[4]=u):u=e[4],u}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=ye("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=d):d=e[5];let p;return e[6]!==c?(p=s.jsx("span",{className:d,children:c}),e[6]=c,e[7]=p):p=e[7],p},Z2=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),gn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const a=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!a&&!i&&(r=r.replace(/\/+$/,"")),r},eS=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),gp=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,zl=(t,e)=>{const n=gn(e),r=gn(t);if(!n||!r)return!1;const a=gp(n),i=gp(r);return i===a||i.startsWith(`${a}/`)},xp=(t,e)=>{const n=gn(e),r=gn(t);if(!zl(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},Pd=(t,e)=>{if(!e)return"";const n=gn(e);if(!t||!zl(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},tS=new Set(["node_modules"]),sS=t=>{const e=ot.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const a=r[n];let i;return e[1]!==a?(i=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:a}}),e[1]=a,e[2]=i):i=e[2],i},bp=t=>{const e=ot.c(11),{name:n}=t,r=l.useRef(null),a=l.useRef(null),[i,o]=l.useState(!1);let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{const f=r.current,b=a.current;if(!f||!b)return;const x=()=>{o(b.scrollWidth>f.clientWidth+1)};x();const y=new ResizeObserver(x);return y.observe(f),y.observe(b),()=>{y.disconnect()}},e[0]=c):c=e[0];let d;e[1]!==n?(d=[n],e[1]=n,e[2]=d):d=e[2],l.useLayoutEffect(c,d);let p;e[3]!==n?(p=s.jsx("span",{ref:a,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:n}),e[3]=n,e[4]=p):p=e[4];let m;e[5]!==n||e[6]!==i?(m=i?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:n}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:n})]}):s.jsx("span",{className:"block min-w-0 truncate",children:n}),e[5]=n,e[6]=i,e[7]=m):m=e[7];let u;return e[8]!==p||e[9]!==m?(u=s.jsxs("span",{ref:r,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[p,m]}),e[8]=p,e[9]=m,e[10]=u):u=e[10],u},nS=t=>tS.has(t),rS=t=>{const e=gn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},aS=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},yp=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")},Vi=2e5,Ng="openchamber:files:auto-save-enabled",iS=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(Ng)!=="false"}catch{return!0}},Sg=(t,e)=>s.jsx(Ar,{filePath:t,extension:e}),oS=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},lS=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},_c=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},cS=t=>{const e=ot.c(62),{node:n,root:r,isExpanded:a,isActive:i,isMobile:o,alwaysShowActions:c,status:d,badge:p,permissions:m,downloadFile:u,contextMenuPath:f,setContextMenuPath:b,onSelect:x,onToggle:y,onRevealPath:g,onOpenDialog:h}=t,{t:j}=ft(),v=n.type==="directory",{canRename:C,canCreateFile:k,canCreateFolder:w,canDelete:N,canReveal:I}=m;let T;e[0]!==k||e[1]!==w||e[2]!==N||e[3]!==C||e[4]!==I||e[5]!==n.path||e[6]!==b?(T=ne=>{!C&&!k&&!w&&!N&&!I||(ne?.preventDefault(),b(n.path))},e[0]=k,e[1]=w,e[2]=N,e[3]=C,e[4]=I,e[5]=n.path,e[6]=b,e[7]=T):T=e[7];const P=T;let D;e[8]!==v||e[9]!==n||e[10]!==x||e[11]!==y?(D=()=>{v?y(n.path):x(n)},e[8]=v,e[9]=n,e[10]=x,e[11]=y,e[12]=D):D=e[12];const S=D;let M;e[13]!==n.path||e[14]!==b?(M=ne=>{ne.stopPropagation(),b(n.path)},e[13]=n.path,e[14]=b,e[15]=M):M=e[15];const E=M,R=o?void 0:P,V=o?void 0:P,B=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let $;e[16]!==B?($=ye("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",B),e[16]=B,e[17]=$):$=e[17];let O;e[18]!==v||e[19]!==a||e[20]!==n.extension||e[21]!==n.path?(O=v?a?s.jsx(A,{name:"folder-open-fill",className:"size-4 flex-shrink-0 text-primary/60"}):s.jsx(A,{name:"folder-3-fill",className:"size-4 flex-shrink-0 text-primary/60"}):Sg(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 _;e[23]!==n.name||e[24]!==n.path?(_=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[23]=n.name,e[24]=n.path,e[25]=_):_=e[25];let q;e[26]!==v||e[27]!==d?(q=!v&&d&&s.jsx(sS,{status:d}),e[26]=v,e[27]=d,e[28]=q):q=e[28];let L;e[29]!==p||e[30]!==v?(L=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]=L):L=e[31];let J;e[32]!==S||e[33]!==q||e[34]!==L||e[35]!==V||e[36]!==$||e[37]!==O||e[38]!==_?(J=s.jsxs("button",{type:"button",onClick:S,onContextMenu:V,className:$,children:[O,_,q,L]}),e[32]=S,e[33]=q,e[34]=L,e[35]=V,e[36]=$,e[37]=O,e[38]=_,e[39]=J):J=e[39];let Z;e[40]!==c||e[41]!==k||e[42]!==w||e[43]!==N||e[44]!==C||e[45]!==I||e[46]!==f||e[47]!==u||e[48]!==E||e[49]!==v||e[50]!==o||e[51]!==n||e[52]!==h||e[53]!==g||e[54]!==r||e[55]!==b||e[56]!==j?(Z=(C||k||w||N||I)&&s.jsx("div",{className:ye("absolute right-1 top-1/2 -translate-y-1/2",c?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(As,{open:f===n.path,onOpenChange:ne=>b(ne?n.path:null),children:[s.jsx(Is,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"icon",className:"size-6",onClick:E,children:s.jsx(A,{name:"more-2-fill",className:"size-4"})})}),s.jsxs(Ps,{align:"end",side:"bottom",onCloseAutoFocus:()=>b(null),children:[C&&s.jsxs(_t,{onClick:ne=>{ne.stopPropagation(),h("rename",n)},children:[s.jsx(A,{name:"edit",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.rename")]}),s.jsxs(_t,{onClick:ne=>{ne.stopPropagation(),En(n.path).then(me=>{if(me.ok){H.success(j("sidebarFilesTree.toast.pathCopied"));return}H.error(j("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(A,{name:"file-copy",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.copyPath")]}),s.jsxs(_t,{onClick:ne=>{ne.stopPropagation();const me=Pd(r,n.path)||n.path;En(me).then(pe=>{if(pe.ok){H.success(j("filesView.toast.relativePathCopied"));return}H.error(j("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(A,{name:"file-copy-2",className:"mr-2 size-4"})," ",j("filesView.tree.menu.copyRelativePath")]}),!v&&u&&s.jsxs(_t,{onClick:ne=>{ne.stopPropagation(),u(n.path)},children:[s.jsx(A,{name:"download",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.save")]}),I&&s.jsxs(_t,{onClick:ne=>{ne.stopPropagation(),g(n.path)},children:[s.jsx(A,{name:"folder-received",className:"mr-2 size-4"})," ",j(su())]}),v&&(k||w)&&s.jsxs(s.Fragment,{children:[s.jsx(nr,{}),k&&s.jsxs(_t,{onClick:ne=>{ne.stopPropagation(),h("createFile",n)},children:[s.jsx(A,{name:"file-add",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.newFile")]}),w&&s.jsxs(_t,{onClick:ne=>{ne.stopPropagation(),h("createFolder",n)},children:[s.jsx(A,{name:"folder-add",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.newFolder")]})]}),N&&s.jsxs(s.Fragment,{children:[s.jsx(nr,{}),s.jsxs(_t,{onClick:ne=>{ne.stopPropagation(),h("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=c,e[41]=k,e[42]=w,e[43]=N,e[44]=C,e[45]=I,e[46]=f,e[47]=u,e[48]=E,e[49]=v,e[50]=o,e[51]=n,e[52]=h,e[53]=g,e[54]=r,e[55]=b,e[56]=j,e[57]=Z):Z=e[57];let ie;return e[58]!==J||e[59]!==Z||e[60]!==R?(ie=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:R,children:[J,Z]}),e[58]=J,e[59]=Z,e[60]=R,e[61]=ie):ie=e[61],ie},dS=t=>{const e=ot.c(83),{activeDialog:n,dialogData:r,dialogInputValue:a,onDialogInputChange:i,isDialogSubmitting:o,onDialogSubmit:c,onClose:d,inputRef:p}=t,{t:m}=ft(),u=!!n;let f;e[0]!==d?(f=O=>!O&&d(),e[0]=d,e[1]=f):f=e[1];let b;e[2]!==n||e[3]!==m?(b=n==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=n,e[3]=m,e[4]=b):b=e[4];let x;e[5]!==n||e[6]!==m?(x=n==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=n,e[6]=m,e[7]=x):x=e[7];let y;e[8]!==n||e[9]!==m?(y=n==="rename"&&m("filesView.dialog.rename.title"),e[8]=n,e[9]=m,e[10]=y):y=e[10];let g;e[11]!==n||e[12]!==m?(g=n==="delete"&&m("filesView.dialog.delete.title"),e[11]=n,e[12]=m,e[13]=g):g=e[13];let h;e[14]!==b||e[15]!==x||e[16]!==y||e[17]!==g?(h=s.jsxs(ms,{children:[b,x,y,g]}),e[14]=b,e[15]=x,e[16]=y,e[17]=g,e[18]=h):h=e[18];let j;e[19]!==n||e[20]!==r?.path||e[21]!==m?(j=n==="createFile"&&m("filesView.dialog.createFile.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[19]=n,e[20]=r?.path,e[21]=m,e[22]=j):j=e[22];let v;e[23]!==n||e[24]!==r?.path||e[25]!==m?(v=n==="createFolder"&&m("filesView.dialog.createFolder.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[23]=n,e[24]=r?.path,e[25]=m,e[26]=v):v=e[26];let C;e[27]!==n||e[28]!==r?.name||e[29]!==m?(C=n==="rename"&&m("filesView.dialog.rename.description",{name:r?.name??""}),e[27]=n,e[28]=r?.name,e[29]=m,e[30]=C):C=e[30];let k;e[31]!==n||e[32]!==r?.name||e[33]!==m?(k=n==="delete"&&m("filesView.dialog.delete.description",{name:r?.name??""}),e[31]=n,e[32]=r?.name,e[33]=m,e[34]=k):k=e[34];let w;e[35]!==C||e[36]!==k||e[37]!==j||e[38]!==v?(w=s.jsxs(Ns,{children:[j,v,C,k]}),e[35]=C,e[36]=k,e[37]=j,e[38]=v,e[39]=w):w=e[39];let N;e[40]!==w||e[41]!==h?(N=s.jsxs(hs,{children:[h,w]}),e[40]=w,e[41]=h,e[42]=N):N=e[42];let I;e[43]!==n||e[44]!==a||e[45]!==p||e[46]!==i||e[47]!==c||e[48]!==m?(I=n!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Lt,{value:a,onChange:O=>i(O.target.value),placeholder:m(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:O=>{O.key==="Enter"&&c()},ref:p})}),e[43]=n,e[44]=a,e[45]=p,e[46]=i,e[47]=c,e[48]=m,e[49]=I):I=e[49];let T;e[50]!==m?(T=m("filesView.dialog.cancel"),e[50]=m,e[51]=T):T=e[51];let P;e[52]!==o||e[53]!==d||e[54]!==T?(P=s.jsx(be,{variant:"outline",onClick:d,disabled:o,children:T}),e[52]=o,e[53]=d,e[54]=T,e[55]=P):P=e[55];const D=n==="delete"?"destructive":"default";let S;e[56]!==c?(S=()=>{c()},e[56]=c,e[57]=S):S=e[57];let M;e[58]!==n||e[59]!==a||e[60]!==o?(M=o||n!=="delete"&&!a.trim(),e[58]=n,e[59]=a,e[60]=o,e[61]=M):M=e[61];let E;e[62]!==n||e[63]!==o||e[64]!==m?(E=o?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):m(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=o,e[64]=m,e[65]=E):E=e[65];let R;e[66]!==D||e[67]!==S||e[68]!==M||e[69]!==E?(R=s.jsx(be,{variant:D,onClick:S,disabled:M,children:E}),e[66]=D,e[67]=S,e[68]=M,e[69]=E,e[70]=R):R=e[70];let V;e[71]!==P||e[72]!==R?(V=s.jsxs(_s,{children:[P,R]}),e[71]=P,e[72]=R,e[73]=V):V=e[73];let B;e[74]!==p||e[75]!==N||e[76]!==I||e[77]!==V?(B=s.jsxs(ds,{initialFocus:p,children:[N,I,V]}),e[74]=p,e[75]=N,e[76]=I,e[77]=V,e[78]=B):B=e[78];let $;return e[79]!==u||e[80]!==f||e[81]!==B?($=s.jsx(us,{open:u,onOpenChange:f,children:B}),e[79]=u,e[80]=f,e[81]=B,e[82]=$):$=e[82],$},kg=({mode:t="full"})=>{const{t:e}=ft(),{files:n,runtime:r}=_n(),{currentTheme:a,availableThemes:i,lightThemeId:o,darkThemeId:c}=jr(),{isMobile:d,isTablet:p,screenWidth:m}=ln(),u=d||p,f=ec(),b=eu(),x=na()??"",y=gn(x.trim()),g=d||t!=="editor-only",h=t==="editor-only"&&!d,j=tu(Ee=>Ee.searchFiles),v=Zl(x),[C,k]=l.useState(""),w=tc(C,200),N=l.useRef(null),[I,T]=l.useState(!1),[P,D]=l.useState(!0),[S,M]=l.useState(!1),[E,R]=l.useState(!1),[V,B]=l.useState(!1),$=l.useRef(null),O=l.useRef(0),_=l.useCallback(Ee=>{O.current=Math.max(0,O.current+(Ee?1:-1))},[]),q=l.useCallback(Ee=>Ee instanceof Element?Ee.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);l.useEffect(()=>{if(!V)return;const Ee=rt=>{O.current>0||q(rt.target)||$.current&&!$.current.contains(rt.target)&&B(!1)};return document.addEventListener("mousedown",Ee),()=>document.removeEventListener("mousedown",Ee)},[q,V]);const[L,J]=l.useState("edit"),[Z,ie]=l.useState("edit"),[ne,me]=l.useState("tree"),[pe,G]=l.useState("edit"),K=l.useRef({}),Q=l.useRef({}),W=l.useRef({}),de=l.useMemo(()=>i.find(Ee=>Ee.metadata.id===o)??Ni(!1),[i,o]),ge=l.useMemo(()=>i.find(Ee=>Ee.metadata.id===c)??Ni(!0),[i,c]);l.useEffect(()=>{Si(de),Si(ge)},[de,ge]);const ve=l.useMemo(()=>[],[]),te=Fn(Ee=>y?Ee.byRoot[y]?.openPaths??ve:ve),he=Fn(Ee=>y?Ee.byRoot[y]?.selectedPath??null:null),ce=Fn(Ee=>y?Ee.byRoot[y]?.expandedPaths??ve:ve),xe=Fn(Ee=>Ee.addOpenPath),se=Fn(Ee=>Ee.removeOpenPath),ue=Fn(Ee=>Ee.removeOpenPathsByPrefix),Y=Fn(Ee=>Ee.setSelectedPath),Se=Fn(Ee=>Ee.toggleExpandedPath),fe=Fn(Ee=>Ee.expandPaths),Ce=l.useCallback(Ee=>{const rt=gn(Ee),pt=rt.split("/"),jt=pt[pt.length-1]||rt,Jt=jt.includes(".")?jt.split(".").pop()?.toLowerCase():void 0;return{name:jt,path:rt,type:"file",extension:Jt}},[]),Ie=l.useMemo(()=>te.map(Ce),[te,Ce]),ke=l.useMemo(()=>he??te[0]??null,[te,he]),X=l.useMemo(()=>ke?Ce(ke):null,[ke,Ce]),ae=X?.path??"",je=!!(y&&ae&&!zl(ae,y)),le=l.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&je}),[t,je]),Ne=l.useRef(null),[Me,Ve]=l.useState({left:!1,right:!1}),we=l.useCallback(()=>{const Ee=Ne.current;Ee&&Ve({left:Ee.scrollLeft>2,right:Ee.scrollLeft+Ee.clientWidth<Ee.scrollWidth-2})},[]),ee=l.useRef(we);ee.current=we,l.useEffect(()=>{const Ee=Ne.current;if(!Ee)return;const rt=()=>ee.current();rt(),Ee.addEventListener("scroll",rt,{passive:!0});const pt=new ResizeObserver(rt);return pt.observe(Ee),()=>{Ee.removeEventListener("scroll",rt),pt.disconnect()}},[Ie.length]);const[F,U]=l.useState({}),oe=l.useRef(new Set),Te=l.useRef(new Set),Oe=l.useRef(new Map),Pe=l.useRef(0),[z,De]=l.useState([]),[Qe,et]=l.useState(!1),[Ze,We]=l.useState(""),[it,qe]=l.useState(!1),[st,Je]=l.useState(null),[Be,nt]=l.useState(""),[Ge,at]=l.useState(null),[Ae,Le]=l.useState(""),[ze,Ke]=l.useState(!1),lt=l.useRef(null),xt=l.useRef(null),dt=l.useRef(null),ut=l.useRef(0),[Nt,ts]=l.useState("idle"),[Vt,Xt]=l.useState(iS),[ht,Bt]=l.useState(!1),Zt=l.useRef(null),gs=l.useRef(null),rs=l.useRef(null),ps=l.useRef(!1),Ut=l.useRef(null),Ye=l.useRef(null),Tt=l.useRef(null),Kt=l.useRef(null),[St,es]=l.useState(0),ss=l.useRef(null),Ms=l.useRef({key:"",attempts:0});l.useEffect(()=>()=>{ss.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(ss.current),ss.current=null)},[]);const[xs,Bs]=l.useState(null),[ws,xn]=l.useState(null),[Qs,Wt]=l.useState(""),[qt,re]=l.useState(!1),[vt,Ft]=l.useState(null),[ct,ls]=l.useState(!1),[cs,He]=l.useState(!1),[yt,Et]=l.useState(!1),Rt=!!n.writeFile,Yt=!!n.createDirectory,Ot=!!n.rename,Os=!!n.delete,Ds=!!n.revealPath,Ts=Br(Ee=>Ee.availableApps),Vs=Br(Ee=>Ee.isCacheStale),js=Br(Ee=>Ee.initialize),Bn=Br(Ee=>Ee.loadInstalledApps);l.useEffect(()=>{js()},[js]);const bn=l.useCallback(Ee=>{n.revealPath&&n.revealPath(Ee).catch(()=>{H.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),mn=l.useCallback(async Ee=>{if(!X?.path||await Jb(X.path,Ee.id,Ee.appName)||await Il(X.path,Ee.appName))return;const jt=Q2(X.path)||y;jt&&await Il(jt,Ee.appName)||H.error(e("filesView.toast.openInAppFailed",{app:Ee.appName}))},[y,X?.path,e]),lr=l.useCallback((Ee,rt)=>{Bs(Ee),xn(rt),Wt(Ee==="rename"&&rt.name||""),re(!1)},[]),[Us,yn]=l.useState(null),ir=l.useRef(!1),Mn=l.useRef(null),[Rr,$s]=l.useState(!1),Ks=Fe(Ee=>Ee.setMainTabGuard),Ue=Fe(Ee=>Ee.pendingFileNavigation),Pt=Fe(Ee=>Ee.setPendingFileNavigation),Ht=Fe(Ee=>Ee.pendingFileFocusPath),ns=Fe(Ee=>Ee.setPendingFileFocusPath),qs=Fe(Ee=>Ee.shortcutOverrides),Gs=wt(Ee=>Ee.settingsDefaultFileViewerPreview);l.useEffect(()=>{const Ee=()=>{ir.current=!1,Mn.current=null,$s(!1)};return document.addEventListener("mouseup",Ee),()=>document.removeEventListener("mouseup",Ee)},[]),l.useEffect(()=>()=>{Ut.current!==null&&window.clearTimeout(Ut.current),Ye.current!==null&&window.clearTimeout(Ye.current)},[]);const Ls=l.useCallback((Ee,rt)=>{const pt=Ee.split(`
|
|
48
|
-
`),jt=Math.max(1,rt.start),Jt=Math.min(pt.length,rt.end);return jt>Jt?"":pt.slice(jt-1,Jt).join(`
|
|
49
|
-
`)},[]),sn=uu({source:"file",fileLabel:X?.path??null,language:X?.path&&ki(X.path)||"text",getCodeForRange:Ee=>Ls(Ze,$l(Ee)),toStoreRange:Ee=>({startLine:Ee.start,endLine:Ee.end}),fromDraftRange:Ee=>({start:Ee.startLine,end:Ee.endLine})}),{drafts:nn,commentText:qn,editingDraftId:Jn,setSelection:aa,saveComment:Ur,cancel:Nn,reset:cn,startEdit:hn,deleteDraft:Sn}=sn;l.useEffect(()=>{yn(null),cn(),Ks(null),Le(""),Ke(!1)},[X?.path,cn,Ks]),l.useEffect(()=>{aa(Us)},[Us,aa]),l.useEffect(()=>{if(!Us&&!Jn)return;const Ee=pt=>{const jt=pt.target;jt.closest('[data-comment-input="true"]')||jt.closest('[data-comment-card="true"]')||jt.closest(".cm-gutterElement")||jt.closest("[data-sonner-toast]")||jt.closest("[data-sonner-toaster]")||(yn(null),Nn())},rt=setTimeout(()=>{document.addEventListener("click",Ee)},100);return()=>{clearTimeout(rt),document.removeEventListener("click",Ee)}},[Nn,Jn,Us]);const cr=l.useCallback((Ee,rt)=>{const pt=rt??Us??void 0;rt&&yn(rt),Ur(Ee,pt),yn(null)},[Us,Ur]),dr=l.useCallback((Ee,rt)=>{const pt=[];for(const jt of rt){if(!(jt&&typeof jt.name=="string"&&jt.name.length>0)||!f&&jt.name.startsWith(".")||!b&&nS(jt.name))continue;const Jt=jt.name,Qt=gn(jt.path||""),Es=Qt?eS(Qt)?Qt:gn(`${Ee}/${Qt}`):gn(`${Ee}/${Jt}`),Xs=jt.isDirectory?"directory":"file",Un=Xs==="file"&&Jt.includes(".")?Jt.split(".").pop()?.toLowerCase():void 0;pt.push({name:Jt,path:Es,type:Xs,extension:Un})}return Z2(pt)},[b,f]),an=l.useCallback(async Ee=>{const rt=gn(Ee.trim());if(!rt||oe.current.has(rt)||Te.current.has(rt))return;Te.current=new Set(Te.current),Te.current.add(rt);const pt=Pe.current+1;Pe.current=pt,Oe.current=new Map(Oe.current),Oe.current.set(rt,pt);const jt=()=>Oe.current.get(rt)===pt,Jt=!b;await(r.isDesktop?n.listDirectory(rt,{respectGitignore:Jt}).then(Es=>Es.entries.map(Xs=>({name:Xs.name,path:Xs.path,isDirectory:Xs.isDirectory}))):on.listLocalDirectory(rt,{respectGitignore:Jt}).then(Es=>Es.map(Xs=>({name:Xs.name,path:Xs.path,isDirectory:Xs.isDirectory})))).then(Es=>{if(!jt())return;const Xs=dr(rt,Es);oe.current=new Set(oe.current),oe.current.add(rt),U(Un=>({...Un,[rt]:Xs}))}).catch(()=>{jt()&&U(Es=>({...Es,[rt]:Es[rt]??[]}))}).finally(()=>{jt()&&(Oe.current=new Map(Oe.current),Oe.current.delete(rt),Te.current=new Set(Te.current),Te.current.delete(rt))})},[n,dr,r.isDesktop,b]),Fr=l.useCallback(async()=>{y&&(oe.current=new Set,Te.current=new Set,Oe.current=new Map,U(Ee=>Object.keys(Ee).length===0?Ee:{}),await an(y))},[an,y]),Yn=l.useCallback(async Ee=>{if(!Ee){await Fr();return}const rt=gn(Ee);oe.current=new Set(oe.current),oe.current.delete(rt),Te.current=new Set(Te.current),Te.current.delete(rt),await an(rt)},[an,Fr]),Qn=l.useRef(""),ei=l.useRef("");l.useEffect(()=>{if(!y)return;const Ee=`${y}|h${f?"1":"0"}|g${b?"1":"0"}`,rt=Qn.current!==y,pt=ei.current!==Ee;!rt&&!pt||(rt&&(Qn.current=y,We(""),Je(null),nt(""),at(null),T(!1)),pt&&(ei.current=Ee,oe.current=new Set,Te.current=new Set,Oe.current=new Map,U(jt=>Object.keys(jt).length===0?jt:{}),an(y)))},[an,y,b,f]),l.useEffect(()=>{if(!n.listDirectory)return;const Ee=()=>{if(!document.hidden&&ce.length>0)for(const rt of ce)Yn(rt)};return document.addEventListener("visibilitychange",Ee),()=>document.removeEventListener("visibilitychange",Ee)},[ce,n.listDirectory,Yn]),l.useEffect(()=>{if(!n.listDirectory||ce.length===0)return;const Ee=setInterval(()=>{if(!document.hidden)for(const rt of ce)Yn(rt)},8e3);return()=>clearInterval(Ee)},[ce,n.listDirectory,Yn]);const wa=l.useCallback(async Ee=>{if(Ee?.preventDefault(),!ws||!xs)return;re(!0);const rt=()=>{Bs(null)},pt=Jt=>{H.error(Jt)},jt=()=>{re(!1)};if(xs==="createFile"){if(!Qs.trim()){pt(e("sidebarFilesTree.toast.filenameRequired")),jt();return}if(!n.writeFile){pt(e("sidebarFilesTree.toast.writeNotSupported")),jt();return}const Jt=ws.path,Qt=Jt?`${Jt}/`:"",Es=gn(`${Qt}${Qs.trim()}`);await n.writeFile(Es,"").then(async Xs=>{Xs.success&&(H.success(e("sidebarFilesTree.toast.fileCreated")),await Yn(Jt)),rt()}).catch(()=>pt(e("sidebarFilesTree.toast.operationFailed"))).finally(jt);return}if(xs==="createFolder"){if(!Qs.trim()){pt(e("sidebarFilesTree.toast.folderNameRequired")),jt();return}const Jt=ws.path,Qt=Jt?`${Jt}/`:"",Es=gn(`${Qt}${Qs.trim()}`);await n.createDirectory(Es).then(async Xs=>{Xs.success&&(H.success(e("sidebarFilesTree.toast.folderCreated")),await Yn(Jt)),rt()}).catch(()=>pt(e("sidebarFilesTree.toast.operationFailed"))).finally(jt);return}if(xs==="rename"){if(!Qs.trim()){pt(e("sidebarFilesTree.toast.nameRequired")),jt();return}if(!n.rename){pt(e("sidebarFilesTree.toast.renameNotSupported")),jt();return}const Jt=ws.path,Qt=Jt.split("/").slice(0,-1).join("/"),Es=Qt?`${Qt}/`:"",Xs=gn(`${Es}${Qs.trim()}`);await n.rename(Jt,Xs).then(async Un=>{Un.success&&(H.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await Yn(Qt),y&&ue(y,Jt),(X?.path===Jt||X?.path.startsWith(`${Jt}/`))&&(y&&Y(y,null),We(""),Je(null),nt(""),at(null),d&&T(!1))),rt()}).catch(()=>pt(e("sidebarFilesTree.toast.operationFailed"))).finally(jt);return}if(xs==="delete"){if(!n.delete){pt(e("sidebarFilesTree.toast.deleteNotSupported")),jt();return}const Jt=ws.path,Qt=Jt.split("/").slice(0,-1).join("/");await n.delete(Jt).then(async Es=>{Es.success&&(H.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await Yn(Qt),y&&ue(y,Jt),(X?.path===Jt||X?.path.startsWith(`${Jt}/`))&&(y&&Y(y,null),We(""),Je(null),nt(""),at(null),d&&T(!1))),rt()}).catch(()=>pt(e("sidebarFilesTree.toast.operationFailed"))).finally(jt);return}jt()},[xs,ws,Qs,n,Yn,d,ue,y,X?.path,Y,e]);l.useEffect(()=>{if(!x){De([]),et(!1);return}const Ee=w.trim();if(!Ee){De([]),et(!1);return}let rt=!1;return et(!0),j(x,Ee,150,{includeHidden:f,respectGitignore:!b,type:"file"}).then(pt=>{if(rt)return;const Jt=pt.filter(Qt=>b||!rS(Qt.path)).map(Qt=>({name:Qt.name,path:gn(Qt.path),type:"file",extension:Qt.extension,relativePath:Qt.relativePath}));De(Jt)}).catch(()=>{rt||De([])}).finally(()=>{rt||et(!1)}),()=>{rt=!0}},[x,w,j,f,b]);const ti=l.useCallback(async(Ee,rt)=>{if(n.readFile)return(await n.readFile(Ee,rt)).content??"";const pt=new URLSearchParams({path:Ee});rt?.allowOutsideWorkspace&&pt.set("allowOutsideWorkspace","true"),rt?.optional&&pt.set("optional","true");const jt=await fetch(`/api/fs/read?${pt.toString()}`,{cache:rt?.optional?"no-store":"default"});if(!jt.ok){const Jt=await jt.json().catch(()=>({error:jt.statusText}));throw new Error(Jt.error||e("filesView.error.readFileFailed"))}return jt.text()},[n,e]),Xn=l.useCallback(async(Ee,rt)=>{if(n.statFile){const pt=await n.statFile(Ee,rt);return{path:pt.path,size:pt.size,mtimeMs:pt.mtimeMs}}return null},[n]);l.useEffect(()=>{if(!y||!n.statFile||te.length===0)return;let Ee=!1;const rt=[...te];return Promise.all(rt.map(async pt=>{try{const jt=await n.statFile?.(pt);!Ee&&jt&&!jt.isFile&&ue(y,pt)}catch(jt){!Ee&&yp(jt)&&ue(y,pt)}})),()=>{Ee=!0}},[n,te,ue,y]);const Wr=l.useMemo(()=>Ze.length>Vi?`${Ze.slice(0,Vi)}
|
|
50
|
-
|
|
51
|
-
… truncated …`:Ze,[Ze]),Js=Ae!==Wr,Vn=l.useCallback(async()=>{if(!X||!n.writeFile)return H.error(e("filesView.toast.savingNotSupported")),!1;if(!Js)return!0;Ke(!0);try{return(await n.writeFile(X.path,Ae))?.success?(We(Ae),Xn(X.path).then(rt=>{rt&&(dt.current=rt)}).catch(()=>{}),!0):(H.error(e("filesView.toast.writeFileFailed")),!1)}catch(Ee){return H.error(Ee instanceof Error?Ee.message:e("filesView.toast.saveFailed")),!1}finally{Ke(!1)}},[Ae,n,Js,Xn,X,e]);l.useEffect(()=>{if(!Js){Ks(null);return}const Ee=rt=>ps.current?(ps.current=!1,!0):(Bt(!0),gs.current=rt,!1);return Ks(Ee),()=>{Fe.getState().mainTabGuard===Ee&&Ks(null)}},[Js,Ks]),l.useEffect(()=>{try{window.localStorage.setItem(Ng,Vt?"true":"false")}catch{}},[Vt]),l.useEffect(()=>{Vt||(ts("idle"),xt.current&&(clearTimeout(xt.current),xt.current=null))},[Vt]);const ja=1500;l.useEffect(()=>{const Ee=!!(X&&n.writeFile);if(!(!Vt||!Js||!Ee||ze))return xt.current=setTimeout(()=>{Vn().then(rt=>{rt&&(ts("saved"),setTimeout(()=>ts("idle"),2e3))})},ja),()=>{xt.current&&(clearTimeout(xt.current),xt.current=null)}},[Vt,Ae,Js,X,n.writeFile,ze,Vn]),l.useEffect(()=>{ts("idle")},[X?.path]),l.useEffect(()=>{const Ee=rt=>{Yd(rt)&&(rt.key.toLowerCase()==="s"?(rt.preventDefault(),xt.current&&(clearTimeout(xt.current),xt.current=null),ze||Vn().then(pt=>{pt&&(ts("saved"),setTimeout(()=>ts("idle"),2e3))})):rt.key.toLowerCase()==="f"&&(rt.preventDefault(),R(!0)))};return window.addEventListener("keydown",Ee),()=>window.removeEventListener("keydown",Ee)},[ze,Vn]);const ia=l.useCallback(async Ee=>{const rt=ut.current+1;ut.current=rt;const pt=()=>{if(!y)return!1;const Es=Fn.getState().byRoot[y],Xs=Es?.selectedPath??Es?.openPaths[0]??null;return ut.current===rt&&Xs===Ee.path};Je(null),nt(""),at(null);const jt=Ci(Ee.path),Jt=Ee.path.toLowerCase().endsWith(".svg");if(d&&T(!0),r.isDesktop&&jt&&!Jt){We(""),Le(""),qe(!0);return}if(!r.isDesktop&&jt&&!Jt){We(""),Le(""),at(Ee.path),qe(!1);return}qe(!0);const Qt={allowOutsideWorkspace:t==="editor-only"&&!!y&&!zl(Ee.path,y)};await ti(Ee.path,Qt).then(Es=>{pt()&&(We(Es),Le(Es.length>Vi?`${Es.slice(0,Vi)}
|
|
52
|
-
|
|
53
|
-
… truncated …`:Es),at(Ee.path),Xn(Ee.path,Qt).then(Xs=>{Xs&&pt()&&(dt.current=Xs)}).catch(()=>{}))}).catch(Es=>{if(pt()){if(aS(Es)){if(qe(!1),y&&Y(y,null),Je(null),We(""),Le(""),at(null),dt.current=null,C.trim().length>0&&k(""),d&&T(!1),y){const Un=[...xp(Ee.path,y),Ee.path];Un.length>0&&fe(y,Un);for(const Do of Un)oe.current.has(Do)||an(Do)}return}if(yp(Es)){y&&ue(y,Ee.path),We(""),Le(""),Je(null),dt.current=null,d&&T(!1);return}We(""),Le(""),Je(Es instanceof Error?Es.message:e("filesView.error.readFileFailed")),dt.current=null}}).finally(()=>{pt()&&qe(!1)})},[fe,d,an,t,ti,Xn,ue,y,r.isDesktop,C,Y,e]),Nr=l.useCallback(async(Ee,rt)=>{if(!y)return;const pt=xp(Ee,y),jt=rt?[...pt,Ee]:pt;jt.length>0&&fe(y,jt);const Jt=jt.map(Qt=>{if(!oe.current.has(Qt))return an(Qt)}).filter(Boolean);await Promise.all(Jt)},[fe,an,y]),si=l.useCallback((Ee,rt)=>{const pt=rt.findIndex(jt=>jt.path===Ee);return pt===-1||rt.length<=1?null:rt[pt+1]??rt[pt-1]??null},[]),pn=l.useCallback(async Ee=>{if(ps.current)ps.current=!1;else if(Js){Bt(!0),Zt.current=Ee;return}y&&(Y(y,Ee.path),xe(y,Ee.path),Nr(Ee.path,!1)),Je(null),nt(""),We(""),Le(""),at(null),d&&T(!0)},[xe,Nr,Js,d,y,Y]);l.useEffect(()=>{X?.path&&Nr(X.path,!1)},[Nr,X?.path]),l.useEffect(()=>{if(!X){ut.current+=1,qe(!1);return}Ge!==X.path&&ia(X)},[ia,Ge,X]);const ni=l.useRef(Js);ni.current=Js,l.useEffect(()=>{if(!X?.path||Ge!==X.path)return;let Ee=!1;const rt=window.setInterval(()=>{document.hidden||Xn(X.path,le).then(pt=>{if(Ee||!pt)return;const jt=dt.current;if(!jt||jt.path!==X.path){dt.current=pt;return}const Jt=pt.mtimeMs!==void 0&&jt.mtimeMs!==void 0&&pt.mtimeMs!==jt.mtimeMs,Qt=pt.size!==jt.size;!Jt&&!Qt||ni.current||(dt.current=pt,at(null))}).catch(()=>{})},2e3);return()=>{Ee=!0,window.clearInterval(rt)}},[Ge,Xn,X?.path,le]);const ri=l.useCallback(()=>{const Ee=Zt.current,rt=gs.current,pt=rs.current;if(Zt.current=null,gs.current=null,rs.current=null,ps.current=!0,Bt(!1),Le(Wr),pt){y&&se(y,pt),X?.path===pt&&(Ee?pn(Ee):(y&&Y(y,null),We(""),Je(null),nt(""),at(null),d&&T(!1)));return}if(Ee){pn(Ee);return}rt&&(Ks(null),Fe.getState().setActiveMainTab(rt))},[Wr,pn,d,se,y,X?.path,Ks,Y]),Na=l.useCallback(async()=>{const Ee=Zt.current,rt=gs.current,pt=rs.current;if(!await Vn()){ps.current=!1;return}if(Zt.current=null,gs.current=null,rs.current=null,ps.current=!0,Bt(!1),pt){y&&se(y,pt),X?.path===pt&&(Ee?await pn(Ee):(y&&Y(y,null),We(""),Je(null),nt(""),at(null),d&&T(!1)));return}if(Ee){await pn(Ee);return}rt&&(Ks(null),Fe.getState().setActiveMainTab(rt))},[pn,d,se,y,Vn,X?.path,Ks,Y]),Sr=l.useCallback(Ee=>{const rt=X?.path===Ee,pt=si(Ee,Ie);if(rt&&Js){Bt(!0),Zt.current=pt,rs.current=Ee;return}if(y&&se(y,Ee),!!rt){if(pt){pn(pt);return}y&&Y(y,null),We(""),Je(null),nt(""),at(null),d&&T(!1)}},[si,pn,Js,d,Ie,se,y,X?.path,Y]),An=l.useCallback(Ee=>{if(te.includes(Ee))return"open";if(v?.files){const rt=Ee.startsWith(y+"/")?Ee.slice(y.length+1):Ee,pt=v.files.find(jt=>jt.path===rt);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},[te,v,y]),oa=l.useCallback(Ee=>{if(!v?.files)return null;const rt=Ee.startsWith(y+"/")?Ee.slice(y.length+1):Ee,pt=rt?`${rt}/`:"";let jt=0,Jt=0;for(const Qt of v.files)Qt.path.startsWith(pt)&&((Qt.index==="M"||Qt.working_dir==="M")&&jt++,(Qt.index==="A"||Qt.working_dir==="?")&&Jt++);return jt+Jt>0?{modified:jt,added:Jt}:null},[v,y]),Fi=l.useCallback(async Ee=>{const rt=gn(Ee);y&&(Se(y,rt),oe.current.has(rt)||await an(rt))},[an,y,Se]),Or=l.useMemo(()=>({canRename:Ot,canCreateFile:Rt,canCreateFolder:Yt,canDelete:Os,canReveal:Ds}),[Ot,Rt,Yt,Os,Ds]);function Sa(Ee,rt){const pt=F[Ee]??[];return pt.map((jt,Jt)=>{const Qt=jt.type==="directory",Es=Qt&&ce.includes(jt.path),Xs=X?.path===jt.path,Un=Jt===pt.length-1;return s.jsxs("li",{className:"relative",children:[rt>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Un&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(cS,{node:jt,root:y,isExpanded:Es,isActive:Xs,isMobile:d,alwaysShowActions:u,status:Qt?void 0:An(jt.path),badge:Qt?oa(jt.path):void 0,permissions:Or,downloadFile:n.downloadFile,contextMenuPath:vt,setContextMenuPath:Ft,onSelect:pn,onToggle:Fi,onRevealPath:bn,onOpenDialog:lr}),Qt&&Es&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Sa(jt.path,rt+1)})]},jt.path)})}const kn=!!(X?.path&&Ci(X.path)),Hr=!!(X?.path&&X.path.toLowerCase().endsWith(".svg")),ai=l.useMemo(()=>gn(Ue?.path??""),[Ue?.path]),kr=!!(Ue&&ai&&ae&&ae===ai&&!it&&!st&&!kn),Cr=l.useMemo(()=>Pd(y,ae),[ae,y]),tn=!!(X&&(!kn||Hr)&&Ze.length>0),ka=!!(X&&Cr.length>0),Re=!!(X&&!je&&!kn&&n.writeFile&&Ze.length<=Vi),Xe=!!(X?.path&&oS(X.path)),tt=!!(X?.path&&lS(X.path)),mt=!!(X?.path&&_c(X.path)),zt=!!(X&&!kn)&&!Xe&&!(mt&&pe==="preview"),zs=l.useMemo(()=>ae?Tl(ae):null,[ae]),[Fs,zn]=l.useState(null);l.useEffect(()=>{let Ee=!1;const rt=X?.path;if(!rt||zs){zn(null);return}return zn(null),Yb(rt).then(pt=>{Ee||zn(pt)}),()=>{Ee=!0}},[X?.path,zs]),l.useEffect(()=>{!Re&&L==="edit"&&J("view")},[Re,L]);const Oi="openchamber:files:md-viewer-mode",la="openchamber:files:html-viewer-mode",Gr="openchamber:files:json-viewer-mode";l.useEffect(()=>{const Ee=X?.path;if(!Ee)return;const rt=Gs?"view":"edit";J(K.current[Ee]??rt);let pt=Gs?"preview":"edit";try{const Qt=localStorage.getItem(Oi);(Qt==="preview"||Qt==="edit")&&(pt=Qt)}catch{}ie(Q.current[Ee]??pt);let jt=Gs?"preview":"edit";try{const Qt=localStorage.getItem(la);(Qt==="preview"||Qt==="edit")&&(jt=Qt)}catch{}G(W.current[Ee]??jt);let Jt=Gs?"tree":"text";try{const Qt=localStorage.getItem(Gr);(Qt==="tree"||Qt==="text")&&(Jt=Qt)}catch{}me(Jt)},[X?.path,Gs]);const cc=l.useCallback(Ee=>{const rt=X?.path;rt&&(K.current[rt]=Ee),J(Ee)},[X?.path]),dc=l.useCallback(Ee=>{const rt=X?.path;rt&&(Q.current[rt]=Ee),ie(Ee);try{localStorage.setItem(Oi,Ee)}catch{}},[X?.path]),ii=l.useCallback(()=>Z,[Z]),$e=l.useCallback(Ee=>{me(Ee);try{localStorage.setItem(Gr,Ee)}catch{}},[]),Dt=l.useCallback(Ee=>{const rt=X?.path;rt&&(W.current[rt]=Ee),G(Ee);try{localStorage.setItem(la,Ee)}catch{}},[X?.path]),bt=l.useCallback(()=>pe,[pe]);l.useEffect(()=>{if(!Ue||!y)return;const Ee=()=>{typeof window>"u"||ss.current===null&&(ss.current=window.requestAnimationFrame(()=>{ss.current=null,es(qr=>qr+1)}))},rt=(qr,Ia)=>{if(qr.state.doc.length!==Ia.length)return!1;if(Ia.length===0)return!0;const uc=Math.min(128,Ia.length);if(qr.state.sliceDoc(0,uc)!==Ia.slice(0,uc))return!1;const Pu=Math.max(0,Ia.length-uc);return qr.state.sliceDoc(Pu,Ia.length)===Ia.slice(Pu)},pt=gn(Ue.path);if(!pt){Pt(null),Ms.current={key:"",attempts:0};return}const jt=`${pt}:${Ue.line}:${Ue.column??1}`;if(Ms.current.key!==jt&&(Ms.current={key:jt,attempts:0}),X?.path!==pt){if(ht)return;pn(Ce(pt));return}if(it||Ge!==pt)return;if(st||kn){Pt(null),Ms.current={key:"",attempts:0};return}if(!Re)return;if(L!=="edit"){J("edit");return}const Jt=Tt.current;if(!Jt){Ee();return}if(!rt(Jt,Ae)){Ee();return}const Qt=Math.max(1,Math.min(Ue.line,Jt.state.doc.lines)),Es=Jt.state.doc.line(Qt),Xs=Math.max(1,Ue.column||1),Un=Math.max(0,Es.to-Es.from),Do=Math.min(Un,Xs-1),Li=Es.from+Do;if(!(Jt.state.selection.main.head===Li)||Ms.current.attempts===0){Ms.current.attempts+=1,Jt.dispatch({selection:{anchor:Li},effects:Ln.scrollIntoView(Li,{y:"center"})}),Jt.focus(),Ee();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const qr=Tt.current;qr&&(qr.dispatch({selection:{anchor:Li},effects:Ln.scrollIntoView(Li,{y:"center"})}),qr.focus())}),Pt(null),Ms.current={key:"",attempts:0}},[Re,ht,Ae,St,st,it,kn,Ge,pn,Ue,y,X?.path,Pt,L,Ce]),l.useEffect(()=>{if(!Ht||!y)return;const Ee=gn(Ht);if(!Ee){ns(null);return}if(X?.path!==Ee){if(ht)return;pn(Ce(Ee));return}if(!(it||Ge!==Ee||st||kn)){if(Re&&L==="edit"){const rt=Tt.current;if(!rt)return;rt.focus()}ns(null)}},[Re,ht,st,it,pn,kn,Ge,Ht,y,X?.path,ns,L,Ce]);const Gt=l.useCallback(Ee=>{if(!d||!Ee||!Ee.hasFocus||typeof window>"u")return;const rt=window.visualViewport;if(!rt)return;const pt=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,pt-(rt.offsetTop+rt.height))<=0)return;const Jt=Ee.state.selection.main.head,Qt=Ee.coordsAtPos(Jt);if(!Qt)return;const Es=Math.round(rt.offsetTop+rt.height),Un=Qt.bottom+20-Es;Un<=0||(Ee.scrollDOM.scrollTop+=Un)},[d]);l.useEffect(()=>{if(!d||typeof window>"u")return;const Ee=()=>{window.requestAnimationFrame(()=>{Gt(Tt.current)})},rt=window.visualViewport;return rt?.addEventListener("resize",Ee),rt?.addEventListener("scroll",Ee,{passive:!0}),document.addEventListener("selectionchange",Ee),()=>{rt?.removeEventListener("resize",Ee),rt?.removeEventListener("scroll",Ee),document.removeEventListener("selectionchange",Ee)}},[d,Gt]),l.useEffect(()=>{if(!Re||L!=="edit"||d)return;const Ee=Xr("open_go_to_line",qs),rt=pt=>{const jt=pt.target;if(jt?.closest('[role="dialog"]'))return;const Jt=!!jt?.closest(".cm-editor");jt?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!Jt||!document.activeElement?.closest(".cm-editor")||il(pt,Ee)&&(pt.preventDefault(),Et(!0))};return window.addEventListener("keydown",rt),()=>window.removeEventListener("keydown",rt)},[Re,d,qs,L]);const ys=l.useMemo(()=>{if(!X?.path)return[vo(a)];const Ee=[vo(a)],rt=zs??Fs;return rt&&Ee.push(rt),P&&Ee.push(Ln.lineWrapping),d&&Ee.push(Ln.updateListener.of(pt=>{pt.view.hasFocus&&(pt.selectionSet||pt.focusChanged||pt.viewportChanged||pt.geometryChanged)&&window.requestAnimationFrame(()=>{Gt(pt.view)})})),Ee},[a,X?.path,zs,Fs,P,d,Gt]),rn=l.useMemo(()=>({light:de.metadata.id,dark:ge.metadata.id}),[de.metadata.id,ge.metadata.id]),Dn=X?.path&&kn?r.isDesktop?Hr?`data:${Wu(X.path)};utf8,${encodeURIComponent(Ze)}`:Be:Hr?`data:${Wu(X.path)};utf8,${encodeURIComponent(Ze)}`:`/api/fs/raw?${new URLSearchParams({path:X.path,...le.allowOutsideWorkspace?{allowOutsideWorkspace:"true"}:{}}).toString()}`:"";l.useEffect(()=>{let Ee=!1;return(async()=>{if(!r.isDesktop||!X?.path||!kn||Hr){nt("");return}Je(null),await(n.readFileBinary?n.readFileBinary(X.path,le).then(jt=>jt.dataUrl):Promise.resolve(Kx(X.path,"asset"))).then(jt=>{Ee||(nt(jt),at(X.path))}).catch(jt=>{Ee||(nt(""),Je(jt instanceof Error?jt.message:e("filesView.error.readFileFailed")),at(null))}).finally(()=>{Ee||qe(!1)})})(),()=>{Ee=!0}},[n,kn,Hr,r.isDesktop,X?.path,le,e]);const Lr=l.useCallback(()=>Bs(null),[]),ur=l.useMemo(()=>cg({drafts:nn,editingDraftId:Jn,commentText:qn,selection:Us,isDragging:Rr,fileLabel:X?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:Ee=>({start:Ee.startLine,end:Ee.endLine}),onSave:cr,onCancel:()=>{yn(null),Nn()},onEdit:Ee=>{hn(Ee),yn({start:Ee.startLine,end:Ee.endLine})},onDelete:Sn}),[Nn,qn,Sn,Jn,nn,cr,Rr,Us,X?.path,hn]),Tn=l.useCallback((Ee,rt)=>s.jsx("div",{className:"h-full",children:s.jsx(Wx,{file:{name:Ee.name,contents:rt,lang:ki(Ee.path)||void 0},options:{disableFileHeader:!0,overflow:P?"wrap":"scroll",theme:rn,themeType:a.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[a.metadata.variant,rn,P]),Cn=({exitFullscreenOnly:Ee=!1}={})=>{if(!X)return null;const rt=(pt,jt)=>s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:jt})}),s.jsx(It,{side:"bottom",sideOffset:6,children:pt})]});return s.jsxs("div",{className:"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",children:[Re&&L==="edit"&&s.jsxs(s.Fragment,{children:[ze?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):Vt&&Nt==="saved"&&!Js?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(A,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):Js?rt(e(Vt?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${Zi()}+S`}),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{Vn()},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(Vt?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${Zi()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${Zi()}+S`}),children:s.jsx(A,{name:"save-3",className:"size-4"})})):null,rt(e(Vt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>Xt(pt=>!pt),className:ye("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",Vt?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(Vt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(Vt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:Vt?s.jsx(A,{name:"file-check-fill",className:"size-4"}):s.jsx(A,{name:"file-check",className:"size-4"})}))]}),s.jsxs(As,{onOpenChange:_,children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(Is,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(A,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(Ps,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Ts.map(pt=>s.jsxs(_t,{className:"flex items-center gap-2",onClick:()=>{mn(pt)},children:[s.jsx(X2,{label:pt.label,iconDataUrl:pt.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:pt.label})]},pt.id)),Vs?s.jsxs(_t,{className:"flex items-center gap-2",onClick:()=>{Bn(!0)},children:[s.jsx(A,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!kn&&s.jsxs(s.Fragment,{children:[rt(e(P?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>D(!P),className:ye("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",P?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(P?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(A,{name:"text-wrap",className:"size-4"})})),L==="edit"&&s.jsxs(s.Fragment,{children:[rt(e("filesView.editor.findInFile"),s.jsx(be,{variant:"ghost",size:"sm",onClick:pt=>{R(!E),pt.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(A,{name:"search",className:"size-4"})})),rt(e("filesView.editor.goToLine"),s.jsx(be,{variant:"ghost",size:"sm",onClick:pt=>{Et(jt=>!jt),pt.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(A,{name:"menu-fold-2",className:"size-4"})})),s.jsx(Y2,{open:yt,onOpenChange:Et,view:Tt.current,variant:"inline"})]})]}),zt&&Re&&!tt&&!mt&&s.jsx(Vl,{currentMode:L==="view"?"preview":"edit",onToggle:()=>{cc(L==="view"?"edit":"view")}}),(Xe||_c(X?.path??""))&&s.jsx(Vl,{currentMode:Xe?ii():bt(),onToggle:()=>{_c(X?.path??"")?Dt(bt()==="preview"?"edit":"preview"):dc(ii()==="preview"?"edit":"preview")}}),tt&&rt(e(ne==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>$e(ne==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(ne==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:ne==="tree"?s.jsx(A,{name:"code-sslash",className:"size-4"}):s.jsx(A,{name:"node-tree",className:"size-4"})})),tn&&rt(e("filesView.editor.copyFileContents"),s.jsx(be,{variant:"ghost",size:"sm",onClick:async()=>{(await En(Ze)).ok?(ls(!0),Ut.current!==null&&window.clearTimeout(Ut.current),Ut.current=window.setTimeout(()=>{ls(!1)},1200)):H.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:ct?s.jsx(A,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(A,{name:"clipboard",className:"size-4"})})),ka&&rt(e("filesView.editor.copyFilePathTitle",{path:Cr}),s.jsx(be,{variant:"ghost",size:"sm",onClick:async()=>{(await En(Cr)).ok?(He(!0),Ye.current!==null&&window.clearTimeout(Ye.current),Ye.current=window.setTimeout(()=>{He(!1)},1200)):H.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:Cr}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:Cr}),children:cs?s.jsx(A,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(A,{name:"file-copy-2",className:"size-4"})})),n.downloadFile&&rt(e("filesView.editor.saveFile"),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{const pt=n.downloadFile;pt&&pt(X.path)},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(A,{name:"download",className:"size-4"})})),Ee?rt(e("filesView.editor.exitFullscreen"),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>M(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(A,{name:"fullscreen-exit",className:"size-4"})})):!d&&t==="full"&&rt(e(S?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>M(!S),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(S?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(S?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:S?s.jsx(A,{name:"fullscreen-exit",className:"size-4"}):s.jsx(A,{name:"fullscreen",className:"size-4"})}))]})},Ca=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(us,{open:ht,onOpenChange:Ee=>{Ee||Bt(!0)},children:s.jsxs(ds,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:e("filesView.unsaved.title")}),s.jsx(Ns,{children:e("filesView.unsaved.description")})]}),s.jsxs(_s,{children:[s.jsx(be,{variant:"outline",onClick:()=>{Na()},disabled:ze,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(be,{variant:"destructive",onClick:ri,children:e("filesView.unsaved.discard")})]})]})}),s.jsx("div",{className:ye("flex flex-col flex-shrink-0",g&&"border-b border-border/40"),children:g?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[d&&I&&s.jsx("button",{type:"button",onClick:()=>T(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(A,{name:"arrow-left-s",className:"size-5"})}),d?X?s.jsxs(As,{children:[s.jsx(Is,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(Ar,{filePath:X.path,extension:X.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(bp,{name:X.name}),s.jsx(A,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Ps,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Ie.map(Ee=>{const rt=X?.path===Ee.path;return s.jsxs(_t,{onSelect:pt=>{if(pt.target.closest("[data-close-open-file]")){pt.preventDefault();return}rt||pn(Ee)},className:ye("flex min-w-0 items-center justify-between gap-2 overflow-hidden",rt&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[s.jsx(Ar,{filePath:Ee.path,extension:Ee.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(bp,{name:Ee.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:pt=>{pt.preventDefault(),pt.stopPropagation()},onClick:pt=>{pt.preventDefault(),pt.stopPropagation(),Sr(Ee.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:Ee.name}),children:s.jsx(A,{name:"close",className:"size-3.5"})})]},Ee.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Ie.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Me.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"}),Me.right&&s.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),s.jsx("div",{ref:Ne,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Ie.map(Ee=>{const rt=X?.path===Ee.path;return s.jsxs("div",{title:Pd(y,Ee.path),className:ye("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",rt?"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(Ar,{filePath:Ee.path,extension:Ee.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{rt||pn(Ee)},className:"max-w-[12rem] truncate text-left",children:Ee.name}),s.jsx("button",{type:"button",onClick:pt=>{pt.stopPropagation(),Sr(Ee.path)},className:ye("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!rt&&!u&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:Ee.name}),children:s.jsx(A,{name:"close",className:"size-3.5"})})]},Ee.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:[X&&!E&&s.jsx("div",{ref:$,className:"absolute right-3 top-3 z-30",onMouseEnter:()=>B(!0),onMouseLeave:()=>{O.current>0||B(!1)},children:V?Cn():s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>B(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(A,{name:"more-2-fill",className:"size-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.editor.controlsTitle")})]})}),s.jsx(Ss,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:X?it?h?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):st?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:st}):kn?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:Dn,alt:X?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"})}):X&&tt&&ne==="tree"?s.jsx(en,{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(Qb,{jsonString:Ze,maxHeight:"100%",initiallyExpandedDepth:2})})}):X&&Xe&&ii()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[Ze.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(Ze.length/1024)})}),s.jsx(en,{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(ya,{content:Ze,className:"typography-markdown-body",stripFrontmatter:!0})})]}):X&&mt&&pe==="preview"?s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{srcDoc:(()=>{const Ee=X.path.substring(0,X.path.lastIndexOf("/")+1);if(!Ee)return Ze;const rt=`<base href="${r.isDesktop,Ee}">`;return Ze.replace(/<head([^>]*)>/i,`<head$1>${rt}`)})(),className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")})}):X&&zt&&L==="view"?Tn(X,Ae):s.jsxs("div",{className:ye("relative h-full",kr&&"overflow-hidden"),ref:Kt,children:[s.jsx("div",{className:ye("h-full",kr&&"invisible"),children:s.jsx(yo,{value:Ae,onChange:Le,readOnly:!Re,extensions:ys,className:"h-full",blockWidgets:ur,onViewReady:Ee=>{Tt.current=Ee,es(rt=>rt+1),window.requestAnimationFrame(()=>{Gt(Ee)})},onViewDestroy:()=>{Tt.current&&(Tt.current=null),es(Ee=>Ee+1)},enableSearch:!0,searchOpen:E,onSearchOpenChange:R,highlightLines:Us?{start:Math.min(Us.start,Us.end),end:Math.max(Us.start,Us.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(Ee,rt,pt)=>{if(!(pt instanceof MouseEvent)||pt.button!==0)return!1;pt.preventDefault();const jt=Ee.state.doc.lineAt(rt.from).number;if(d&&Us&&!pt.shiftKey){const Jt=Math.min(Us.start,Us.end,jt),Qt=Math.max(Us.start,Us.end,jt);return yn({start:Jt,end:Qt}),ir.current=!1,Mn.current=null,$s(!1),!0}if(ir.current=!0,Mn.current=jt,$s(!0),Us&&pt.shiftKey){const Jt=Math.min(Us.start,jt),Qt=Math.max(Us.end,jt);yn({start:Jt,end:Qt})}else yn({start:jt,end:jt});return!0},mouseover:(Ee,rt,pt)=>{if(!(pt instanceof MouseEvent)||pt.buttons!==1||!ir.current||Mn.current===null)return!1;const jt=Ee.state.doc.lineAt(rt.from).number,Jt=Math.min(Mn.current,jt),Qt=Math.max(Mn.current,jt);return yn({start:Jt,end:Qt}),$s(!0),!1},mouseup:()=>(ir.current=!1,Mn.current=null,$s(!1),!1)}}})}),kr&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),Ao=!!(y&&F[y]),Iu=s.jsxs("section",{className:ye("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:ye("flex flex-col gap-2 py-2",d?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(A,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(Lt,{ref:N,value:C,onChange:Ee=>k(Ee.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),C.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{k(""),N.current?.focus()},children:s.jsx(A,{name:"close",className:"size-4"})})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>lr("createFile",{path:x,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(A,{name:"file-add",className:"size-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>lr("createFolder",{path:x,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(A,{name:"folder-add",className:"size-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{Fr()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(A,{name:"refresh",className:"size-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(Ss,{outerClassName:"flex-1 min-h-0",className:ye("py-2",d?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:Qe?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):z.length>0?z.map(Ee=>{const rt=X?.path===Ee.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{pn(Ee)},className:ye("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",rt?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[Sg(Ee.path,Ee.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:Ee.path,children:Ee.relativePath??Ee.path})]})},Ee.path)}):Ao?Sa(y,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),gx=t==="full"&&S&&X&&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:Cn({exitFullscreenOnly:!0})}),s.jsx(Ss,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:it?h?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):st?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:st}):kn?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:Dn,alt:X.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"})}):Xe&&ii()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[Ze.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(Ze.length/1024)})}),s.jsx(en,{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(ya,{content:Ze,className:"typography-markdown-body",stripFrontmatter:!0})})]}):zt&&L==="view"?Tn(X,Ae):s.jsxs("div",{className:ye("relative h-full",kr&&"overflow-hidden"),children:[s.jsx("div",{className:ye("h-full",kr&&"invisible"),children:s.jsx(yo,{value:Ae,onChange:Le,readOnly:!Re,extensions:ys,className:"h-full",onViewReady:Ee=>{Tt.current=Ee,window.requestAnimationFrame(()=>{Gt(Ee)})},onViewDestroy:()=>{Tt.current&&(Tt.current=null)}})}),kr&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(dS,{activeDialog:xs,dialogData:ws,dialogInputValue:Qs,onDialogInputChange:Wt,isDialogSubmitting:qt,onDialogSubmit:wa,onClose:Lr,inputRef:lt}),gx,d?I?Ca:Iu: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:Ca})}):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:Iu}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:Ca})]})]})},uS=Object.freeze(Object.defineProperty({__proto__:null,FilesView:kg},Symbol.toStringTag,{value:"Module"})),Vr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Bc=(t,e)=>{const n=Vr(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},mS=(t,e,n)=>Bc(Bc(Bc(t,".opencode"),"plans"),`${e}-${n}.md`),pS=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,fS=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},hS=(t,e)=>{const n=Vr(e.currentDirectory),r=Vr(e.homeDirectory),a=Vr(t);return n&&a.startsWith(n+"/")?a.slice(n.length+1):r&&a===r?"~":r&&a.startsWith(r+"/")?`~${a.slice(r.length)}`:a},gS=(t,e,n)=>{const r=Vr(t.trim());if(!r)return null;const a=n?e.find(o=>o.id===n)??null:null;if(a?.path){const o=Vr(a.path);if(r===o||r.startsWith(`${o}/`))return{id:a.id,path:a.path}}const i=e.filter(o=>{const c=Vr(o.path);return r===c||r.startsWith(`${c}/`)}).sort((o,c)=>Vr(c.path).length-Vr(o.path).length)[0];return i?{id:i.id,path:i.path}:null},Cg=({targetPath:t=null})=>{const{t:e}=ft(),n=$t(ee=>ee.currentSessionId),r=$t(ee=>ee.createSession),a=$t(ee=>ee.initializeNewOpenChamberSession),i=$t(ee=>ee.sendMessage),o=$t(ee=>ee.setCurrentSession),c=sc(),d=Ws(ee=>ee.homeDirectory),p=Jd(ee=>ee.planModeEnabled),m=Cs(ee=>ee.projects),u=Cs(ee=>ee.activeProjectId),f=Ys(ee=>ee.directories),b=na()??"",x=Fe(ee=>ee.setActiveMainTab),y=Fe(ee=>ee.setSessionSwitcherOpen),g=_n(),{isMobile:h}=ln(),{currentTheme:j}=jr();l.useMemo(()=>Nh(j),[j]);const v=l.useMemo(()=>n?c.find(ee=>ee.id===n)??null:null,[n,c]),C=l.useMemo(()=>{const ee=typeof v?.directory=="string"?v.directory:"";return Vr(ee||"")},[v?.directory]),k=l.useMemo(()=>Vr(b||C),[b,C]),w=l.useMemo(()=>gS(k,m,u),[u,k,m]),N=l.useMemo(()=>w?f.get(w.path)?.isGitRepo===!0:!1,[w,f]),[I,T]=l.useState(null),[P,D]=l.useState(!1),[S,M]=l.useState(null),E=l.useMemo(()=>!S||!C||!d?S:hS(S,{currentDirectory:C,homeDirectory:d}),[S,C,d]),[R,V]=l.useState(""),[B,$]=l.useState(null),O=l.useMemo(()=>E&&E.split("/").pop()||e("planView.file.defaultName"),[E,e]),_=l.useMemo(()=>R.trim()&&Xb(R).title||e("planView.title.default"),[R,e]),q=l.useMemo(()=>_.trim()||e("planView.title.default"),[_,e]),[L,J]=l.useState(!1),[Z,ie]=l.useState(!1),[ne,me]=l.useState("edit"),pe=l.useRef(null),[G,K]=l.useState(null),Q=l.useRef(null),W=l.useRef(null),de="openchamber:plan:md-viewer-mode";l.useEffect(()=>{try{const ee=localStorage.getItem(de);if(!ee)return;const F=JSON.parse(ee);(F==="preview"||F==="edit")&&me(F)}catch{}},[]);const ge=l.useCallback(ee=>{me(ee);try{localStorage.setItem(de,JSON.stringify(ee))}catch{}},[]),ve=l.useRef(!1),te=l.useRef(null),[he,ce]=l.useState(!1);l.useEffect(()=>{const ee=()=>{ve.current=!1,te.current=null,ce(!1)};return document.addEventListener("mouseup",ee),()=>document.removeEventListener("mouseup",ee)},[]);const xe=l.useCallback((ee,F)=>{const U=ee.split(`
|
|
54
|
-
`),oe=Math.max(1,F.start),Te=Math.min(U.length,F.end);return oe>Te?"":U.slice(oe-1,Te).join(`
|
|
55
|
-
`)},[]),se=uu({source:"plan",fileLabel:O,language:S&&ki(S)||"markdown",getCodeForRange:ee=>xe(R,$l(ee)),toStoreRange:ee=>({startLine:ee.start,endLine:ee.end}),fromDraftRange:ee=>({start:ee.startLine,end:ee.endLine})}),{drafts:ue,commentText:Y,editingDraftId:Se,setSelection:fe,saveComment:Ce,cancel:Ie,reset:ke,startEdit:X,deleteDraft:ae}=se;l.useEffect(()=>{K(null),ke()},[R,ke]),l.useEffect(()=>{fe(G)},[G,fe]);const je=l.useCallback(()=>{K(null),Ie()},[Ie]),le=l.useCallback((ee,F)=>{F&&K(F),Ce(ee,F??G??void 0),K(null)},[G,Ce]);l.useEffect(()=>{if(!G)return;const ee=U=>{const oe=U.target;oe.closest('[data-comment-card="true"]')||oe.closest('[data-comment-input="true"]')||oe.closest(".oc-block-widget")||oe.closest(".cm-gutterElement")||oe.closest("[data-sonner-toast]")||oe.closest("[data-sonner-toaster]")||(K(null),Ie())},F=window.setTimeout(()=>{document.addEventListener("click",ee)},100);return()=>{window.clearTimeout(F),document.removeEventListener("click",ee)}},[Ie,Se,h,G]);const Ne=l.useMemo(()=>{const ee=[vo(j)],F=Tl(S||"plan.md");return F&&ee.push(F),ee.push(Ln.lineWrapping),ee},[j,S]);l.useEffect(()=>{if(!p&&!t){M(null),V(""),J(!1);return}let ee=!1;const F=async oe=>{if(g.files?.readFile)return(await g.files.readFile(oe))?.content??"";const Te=or()?.files;if(Te?.readFile)return(await Te.readFile(oe,{optional:!0}))?.content??"";const Oe=await fetch(`/api/fs/read?path=${encodeURIComponent(oe)}&optional=true`,{cache:"no-store"});if(!Oe.ok)throw new Error(`Failed to read plan file (${Oe.status})`);return Oe.text()};return(async()=>{if(M(null),V(""),$(null),t){J(!0);try{const oe=await F(t);if(ee)return;M(t),V(oe)}catch{if(ee)return;M(null),V("")}finally{ee||J(!1)}return}if(!v?.slug||!v?.time?.created||!C){M(null),V("");return}J(!0);try{const oe=mS(C,v.time.created,v.slug),Te=fS(pS(v.time.created,v.slug),d||null);let Oe=null,Pe=null;try{Pe=await F(oe),Oe=oe}catch{}if(!Oe)try{Pe=await F(Te),Oe=Te}catch{}if(ee)return;if(!Oe||Pe===null){M(null),V("");return}M(Oe),V(Pe)}catch{if(ee)return;M(null),V("")}finally{ee||J(!1)}})(),()=>{ee=!0}},[d,p,g.files,C,v?.slug,v?.time?.created,t]),l.useEffect(()=>{if(!S){$(null);return}const ee=window.setTimeout(async()=>{$(null);try{if(g.files?.writeFile){if(!(await g.files.writeFile(S,R))?.success)throw new Error(e("planView.error.writeFailed"))}else{const F=await fetch("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:S,content:R})});if(!F.ok)throw new Error(e("planView.error.writePlanFileFailed",{status:F.status}))}}catch(F){$(F instanceof Error?F.message:e("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(ee)}},[R,S,g.files,e]),l.useEffect(()=>()=>{pe.current!==null&&window.clearTimeout(pe.current)},[]);const Me=l.useCallback(()=>{x("chat"),y(!1)},[x,y]),Ve=l.useCallback(async ee=>{if(!w||!I)return;const F=await wn(I.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:q}),oe=[{synthetic:!0,text:await wn(I.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:q,plan_path:S??""})}];D(!0);try{Me();let Te=null,Oe=w.path;if(I.target==="worktree"){if(!N)return;const z=await yh(w.path,vh());if(!z?.id)return;Te=z.id,Oe=null}else{const z=await r(void 0,w.path,null);if(!z?.id)return;Te=z.id,Oe=z.directory??w.path,a(z.id,wt.getState().agents??[])}if(!Te)return;const Pe=Ql.getState();Pe.saveSessionModelSelection(Te,ee.providerID,ee.modelID),ee.agent.trim()&&(Pe.saveSessionAgentSelection(Te,ee.agent),Pe.saveAgentModelForSession(Te,ee.agent,ee.providerID,ee.modelID),Pe.saveAgentModelVariantForSession(Te,ee.agent,ee.providerID,ee.modelID,ee.variant||void 0)),o(Te,Oe),await i(F,ee.providerID,ee.modelID,ee.agent.trim()||void 0,void 0,void 0,oe,ee.variant||void 0),T(null)}finally{D(!1)}},[N,r,w,a,I,S,Me,i,q,o]),we=l.useMemo(()=>cg({drafts:ue,editingDraftId:Se,commentText:Y,selection:G,isDragging:he,fileLabel:O,newWidgetId:"plan-new-comment-input",mapDraftToRange:ee=>({start:ee.startLine,end:ee.endLine}),onSave:le,onCancel:je,onEdit:ee=>{X(ee),K({start:ee.startLine,end:ee.endLine})},onDelete:ae}),[Y,ae,Se,je,le,he,G,ue,O,X]);return s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label font-medium truncate",children:_}),B?s.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:B,children:e("planView.error.saveFailed")}):null]}),S?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(As,{children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.improvePlanAria"),disabled:!R.trim(),children:s.jsx(A,{name:"loop-right-ai",className:"size-4"})})})}),s.jsx(It,{sideOffset:8,children:e("planView.actions.improve")})]}),s.jsxs(Ps,{align:"end",children:[s.jsx(_t,{onClick:()=>T({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(_t,{onClick:()=>T({action:"improve",target:"worktree"}),disabled:!N,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsxs(As,{children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.implementPlanAria"),disabled:!R.trim(),children:s.jsx(A,{name:"code-ai",className:"size-4"})})})}),s.jsx(It,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs(Ps,{align:"end",children:[s.jsx(_t,{onClick:()=>T({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(_t,{onClick:()=>T({action:"implement",target:"worktree"}),disabled:!N,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(Vl,{currentMode:ne,onToggle:()=>ge(ne==="preview"?"edit":"preview")}),s.jsx(be,{variant:"ghost",size:"sm",onClick:async()=>{(await En(R)).ok&&(ie(!0),pe.current!==null&&window.clearTimeout(pe.current),pe.current=window.setTimeout(()=>{ie(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:Z?s.jsx(A,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(A,{name:"clipboard",className:"h-4 w-4"})})]}):null]}),s.jsx(Zh,{open:I!==null,onOpenChange:ee=>{!ee&&!P&&T(null)},target:I?.target??"session",projectDirectory:w?.path??null,submitting:P,onConfirm:Ve}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(Ss,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:L?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:ne==="preview"?s.jsx("div",{className:"h-full overflow-auto p-3",children:s.jsx(en,{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(ya,{content:R,className:"typography-markdown-body"})})}):s.jsx("div",{className:"relative h-full",ref:W,children:s.jsx(yo,{value:R,onChange:V,readOnly:!1,className:"h-full",extensions:Ne,onViewReady:ee=>{Q.current=ee},onViewDestroy:()=>{Q.current=null},blockWidgets:we,highlightLines:G?{start:Math.min(G.start,G.end),end:Math.max(G.start,G.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(ee,F,U)=>{if(!(U instanceof MouseEvent)||U.button!==0)return!1;U.preventDefault();const oe=ee.state.doc.lineAt(F.from).number;if(h&&G&&!U.shiftKey){const Te=Math.min(G.start,G.end,oe),Oe=Math.max(G.start,G.end,oe);return K({start:Te,end:Oe}),ve.current=!1,te.current=null,ce(!1),!0}if(ve.current=!0,te.current=oe,ce(!0),G&&U.shiftKey){const Te=Math.min(G.start,oe),Oe=Math.max(G.end,oe);K({start:Te,end:Oe})}else K({start:oe,end:oe});return!0},mouseover:(ee,F,U)=>{if(!(U instanceof MouseEvent)||U.buttons!==1||!ve.current||te.current===null)return!1;const oe=ee.state.doc.lineAt(F.from).number,Te=Math.min(te.current,oe),Oe=Math.max(te.current,oe);return K({start:Te,end:Oe}),ce(!0),!1},mouseup:()=>(ve.current=!1,te.current=null,ce(!1),!1)}}})})})})})})]})},xS=Object.freeze(Object.defineProperty({__proto__:null,PlanView:Cg},Symbol.toStringTag,{value:"Module"})),Ad={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},fl={user:0,assistant:0,tool:0,other:0},Ma=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,vp=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{...Ad,total:Ma(n)};if(!n||typeof n!="object")return Ad;const r=n,a=Ma(r.input),i=Ma(r.output),o=Ma(r.reasoning),c=Ma(r.cache?.read),d=Ma(r.cache?.write);return{input:a,output:i,reasoning:o,cacheRead:c,cacheWrite:d,total:a+i+o+c+d}},bS=(...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,yS=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...fl,assistant:fr(n.text)+fr(n.content)};const a=bS(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}},wp=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),vS=t=>{const e=So(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},wS=(t,e)=>{if(t.length===0)return{...fl};const n=t.reduce((r,a)=>{const i=vS(a);let o={...fl};for(const c of a.parts)o=wp(o,yS(c,i));return wp(r,o)},{...fl});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)}},ui=t=>t.toLocaleString(),jS=t=>!Number.isFinite(t)||t<=0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`,NS=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),SS=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),kS=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,CS=(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}},IS=()=>{const t=ot.c(199),{t:e}=ft(),{currentTheme:n}=jr();let r;t[0]!==n?(r=Nh(n),t[0]=n,t[1]=r):r=t[1];const a=r;let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i={},t[2]=i):i=t[2];const[o,c]=l.useState(i),[d,p]=l.useState(null),m=l.useRef(null),u=$t(PS),f=sc(),b=Zb(u??""),x=wt(AS);let y;t[3]===Symbol.for("react.memo_cache_sentinel")?(y=()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null),c(DS),p(null)},t[3]=y):y=t[3];let g;t[4]!==u?(g=[u],t[4]=u,t[5]=g):g=t[5],l.useEffect(y,g);let h,j;t[6]===Symbol.for("react.memo_cache_sentinel")?(h=()=>()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},j=[],t[6]=h,t[7]=j):(h=t[6],j=t[7]),l.useEffect(h,j);let v;t[8]===Symbol.for("react.memo_cache_sentinel")?(v=async(ut,Nt)=>{(await En(Nt)).ok?(p(ut),m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{p(Vt=>Vt===ut?null:Vt),m.current=null},2e3)):p(null)},t[8]=v):v=t[8];const C=v;let k;t[9]!==u||t[10]!==f?(k=u?f.find(ut=>ut.id===u)??null:null,t[9]=u,t[10]=f,t[11]=k):k=t[11];const w=k;let N,I,T,P,D;if(t[12]!==x||t[13]!==b){N=b.filter(TS);let ut;t[19]!==b?(ut=b.filter(ES),t[19]=b,t[20]=ut):ut=t[20],D=ut;let Nt=null;for(let Vt=N.length-1;Vt>=0;Vt=Vt-1,Vt){const Xt=N[Vt];if(vp(Xt).total>0){Nt=Xt;break}}T=Nt?vp(Nt):Ad,P=N.reduce(MS,0);const ts=Nt?.info??null;I=CS(x,ts?.providerID||"",ts?.modelID||""),t[12]=x,t[13]=b,t[14]=N,t[15]=I,t[16]=T,t[17]=P,t[18]=D}else N=t[14],I=t[15],T=t[16],P=t[17],D=t[18];const S=I,M=S.contextLimit,E=M&&M>0?Math.min(999,T.total/M*100):0;let R;if(t[21]!==b){const ut=[...b].reverse().find(RS)?.info?.system||"";R=wS(b,ut),t[21]=b,t[22]=R}else R=t[22];const V=R,B=V.user,$=V.assistant,O=V.tool,_=Math.max(0,T.input-B-$-O),q=B+$+O+_,L=b[0]?.info?.time?.created,J=b.length>0?b[b.length-1]?.info?.time?.created:null;let Z;t[23]!==w?.title||t[24]!==e?(Z=w?.title||e("contextSidebar.session.untitled"),t[23]=w?.title,t[24]=e,t[25]=Z):Z=t[25];const ie=w?.time?.created??L??null,ne=J??w?.time?.created??null;let me;t[26]!==$||t[27]!==_||t[28]!==O||t[29]!==B?(me={user:B,assistant:$,tool:O,other:_},t[26]=$,t[27]=_,t[28]=O,t[29]=B,t[30]=me):me=t[30];let pe;t[31]!==N.length||t[32]!==q||t[33]!==M||t[34]!==S||t[35]!==b.length||t[36]!==Z||t[37]!==ie||t[38]!==ne||t[39]!==me||t[40]!==T||t[41]!==P||t[42]!==E||t[43]!==D.length?(pe={sessionTitle:Z,messagesCount:b.length,userMessagesCount:D.length,assistantMessagesCount:N.length,createdAt:ie,lastActivityAt:ne,providerModel:S,tokenBreakdown:T,usagePercent:E,totalAssistantCost:P,contextLimit:M,breakdown:me,breakdownTotal:q},t[31]=N.length,t[32]=q,t[33]=M,t[34]=S,t[35]=b.length,t[36]=Z,t[37]=ie,t[38]=ne,t[39]=me,t[40]=T,t[41]=P,t[42]=E,t[43]=D.length,t[44]=pe):pe=t[44];const G=pe;if(!u){let ut;t[45]!==e?(ut=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=ut):ut=t[46];let Nt;return t[47]!==ut?(Nt=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:ut}),t[47]=ut,t[48]=Nt):Nt=t[48],Nt}let K;t[49]!==e?(K=e("contextSidebar.breakdown.user"),t[49]=e,t[50]=K):K=t[50];let Q;t[51]!==K||t[52]!==G.breakdown.user?(Q={key:"user",label:K,value:G.breakdown.user,color:"var(--status-success)"},t[51]=K,t[52]=G.breakdown.user,t[53]=Q):Q=t[53];let W;t[54]!==e?(W=e("contextSidebar.breakdown.assistant"),t[54]=e,t[55]=W):W=t[55];let de;t[56]!==W||t[57]!==G.breakdown.assistant?(de={key:"assistant",label:W,value:G.breakdown.assistant,color:"var(--primary-base)"},t[56]=W,t[57]=G.breakdown.assistant,t[58]=de):de=t[58];let ge;t[59]!==e?(ge=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=ge):ge=t[60];let ve;t[61]!==ge||t[62]!==G.breakdown.tool?(ve={key:"tool",label:ge,value:G.breakdown.tool,color:"var(--status-warning)"},t[61]=ge,t[62]=G.breakdown.tool,t[63]=ve):ve=t[63];let te;t[64]!==e?(te=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=te):te=t[65];let he;t[66]!==te||t[67]!==G.breakdown.other?(he={key:"other",label:te,value:G.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=te,t[67]=G.breakdown.other,t[68]=he):he=t[68];let ce;t[69]!==Q||t[70]!==de||t[71]!==ve||t[72]!==he?(ce=[Q,de,ve,he],t[69]=Q,t[70]=de,t[71]=ve,t[72]=he,t[73]=ce):ce=t[73];const xe=ce;let se;t[74]!==G.sessionTitle?(se=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:G.sessionTitle}),t[74]=G.sessionTitle,t[75]=se):se=t[75];let ue;t[76]!==G.providerModel.modelName||t[77]!==G.providerModel.providerName?(ue=s.jsxs("span",{children:[G.providerModel.providerName," / ",G.providerModel.modelName]}),t[76]=G.providerModel.modelName,t[77]=G.providerModel.providerName,t[78]=ue):ue=t[78];let Y;t[79]!==G.createdAt?(Y=G.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:NS(G.createdAt)})]}),t[79]=G.createdAt,t[80]=Y):Y=t[80];let Se;t[81]!==ue||t[82]!==Y?(Se=s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[ue,Y]}),t[81]=ue,t[82]=Y,t[83]=Se):Se=t[83];let fe;t[84]!==se||t[85]!==Se?(fe=s.jsxs("div",{className:"mb-6",children:[se,Se]}),t[84]=se,t[85]=Se,t[86]=fe):fe=t[86];let Ce;t[87]!==e?(Ce=e("contextSidebar.section.context"),t[87]=e,t[88]=Ce):Ce=t[88];let Ie;t[89]!==Ce?(Ie=s.jsx("span",{className:"typography-micro text-muted-foreground",children:Ce}),t[89]=Ce,t[90]=Ie):Ie=t[90];let ke;t[91]!==G.tokenBreakdown.total?(ke=ui(G.tokenBreakdown.total),t[91]=G.tokenBreakdown.total,t[92]=ke):ke=t[92];let X;t[93]!==G.contextLimit?(X=G.contextLimit?` / ${ui(G.contextLimit)}`:"",t[93]=G.contextLimit,t[94]=X):X=t[94];let ae;t[95]!==ke||t[96]!==X?(ae=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[ke,X]}),t[95]=ke,t[96]=X,t[97]=ae):ae=t[97];let je;t[98]!==Ie||t[99]!==ae?(je=s.jsxs("div",{className:"flex items-baseline justify-between",children:[Ie,ae]}),t[98]=Ie,t[99]=ae,t[100]=je):je=t[100];let le;t[101]!==G.usagePercent?(le=G.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,G.usagePercent)}%`,backgroundColor:G.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[101]=G.usagePercent,t[102]=le):le=t[102];let Ne;t[103]!==le?(Ne=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:le}),t[103]=le,t[104]=Ne):Ne=t[104];let Me;t[105]!==e||t[106]!==G.usagePercent?(Me=e("contextSidebar.context.percentUsed",{percent:G.usagePercent.toFixed(1)}),t[105]=e,t[106]=G.usagePercent,t[107]=Me):Me=t[107];let Ve;t[108]!==Me?(Ve=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Me}),t[108]=Me,t[109]=Ve):Ve=t[109];let we;t[110]!==je||t[111]!==Ne||t[112]!==Ve?(we=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[je,Ne,Ve]}),t[110]=je,t[111]=Ne,t[112]=Ve,t[113]=we):we=t[113];let ee;t[114]!==e?(ee=e("contextSidebar.stats.messages"),t[114]=e,t[115]=ee):ee=t[115];let F;t[116]!==G.messagesCount?(F=ui(G.messagesCount),t[116]=G.messagesCount,t[117]=F):F=t[117];let U;t[118]!==ee||t[119]!==F?(U={label:ee,value:F},t[118]=ee,t[119]=F,t[120]=U):U=t[120];let oe;t[121]!==e?(oe=e("contextSidebar.stats.user"),t[121]=e,t[122]=oe):oe=t[122];let Te;t[123]!==G.userMessagesCount?(Te=ui(G.userMessagesCount),t[123]=G.userMessagesCount,t[124]=Te):Te=t[124];let Oe;t[125]!==oe||t[126]!==Te?(Oe={label:oe,value:Te},t[125]=oe,t[126]=Te,t[127]=Oe):Oe=t[127];let Pe;t[128]!==e?(Pe=e("contextSidebar.stats.assistant"),t[128]=e,t[129]=Pe):Pe=t[129];let z;t[130]!==G.assistantMessagesCount?(z=ui(G.assistantMessagesCount),t[130]=G.assistantMessagesCount,t[131]=z):z=t[131];let De;t[132]!==Pe||t[133]!==z?(De={label:Pe,value:z},t[132]=Pe,t[133]=z,t[134]=De):De=t[134];let Qe;t[135]!==e?(Qe=e("contextSidebar.stats.cost"),t[135]=e,t[136]=Qe):Qe=t[136];let et;t[137]!==G.totalAssistantCost?(et=jS(G.totalAssistantCost),t[137]=G.totalAssistantCost,t[138]=et):et=t[138];let Ze;t[139]!==Qe||t[140]!==et?(Ze={label:Qe,value:et},t[139]=Qe,t[140]=et,t[141]=Ze):Ze=t[141];let We;t[142]!==U||t[143]!==Oe||t[144]!==De||t[145]!==Ze?(We=[U,Oe,De,Ze],t[142]=U,t[143]=Oe,t[144]=De,t[145]=Ze,t[146]=We):We=t[146];const it=We;let qe;t[147]!==it?(qe=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:it.map(FS)}),t[147]=it,t[148]=qe):qe=t[148];let st;t[149]!==e?(st=e("contextSidebar.section.lastAssistantMessage"),t[149]=e,t[150]=st):st=t[150];let Je;t[151]!==st?(Je=s.jsx("div",{className:"typography-micro text-muted-foreground",children:st}),t[151]=st,t[152]=Je):Je=t[152];let Be;t[153]!==e||t[154]!==G.tokenBreakdown.cacheRead||t[155]!==G.tokenBreakdown.cacheWrite||t[156]!==G.tokenBreakdown.input||t[157]!==G.tokenBreakdown.output||t[158]!==G.tokenBreakdown.reasoning?(Be=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:G.tokenBreakdown.input},{label:e("contextSidebar.tokens.output"),value:G.tokenBreakdown.output},{label:e("contextSidebar.tokens.reasoning"),value:G.tokenBreakdown.reasoning},{label:e("contextSidebar.tokens.cacheRead"),value:G.tokenBreakdown.cacheRead},{label:e("contextSidebar.tokens.cacheWrite"),value:G.tokenBreakdown.cacheWrite}].map(OS)}),t[153]=e,t[154]=G.tokenBreakdown.cacheRead,t[155]=G.tokenBreakdown.cacheWrite,t[156]=G.tokenBreakdown.input,t[157]=G.tokenBreakdown.output,t[158]=G.tokenBreakdown.reasoning,t[159]=Be):Be=t[159];let nt;t[160]!==Je||t[161]!==Be?(nt=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Je,Be]}),t[160]=Je,t[161]=Be,t[162]=nt):nt=t[162];let Ge;t[163]!==xe||t[164]!==G.breakdownTotal?(Ge=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:xe.map(ut=>ut.value<=0||G.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${ut.value/G.breakdownTotal*100}%`,backgroundColor:ut.color}},ut.key))}),t[163]=xe,t[164]=G.breakdownTotal,t[165]=Ge):Ge=t[165];let at;t[166]!==xe||t[167]!==G.breakdownTotal?(at=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:xe.map(ut=>{const Nt=G.breakdownTotal>0?ut.value/G.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:ut.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[ut.label," ",s.jsxs("span",{className:"tabular-nums",children:[Nt.toFixed(0),"%"]})]})]},ut.key)})}),t[166]=xe,t[167]=G.breakdownTotal,t[168]=at):at=t[168];let Ae;t[169]!==Ge||t[170]!==at?(Ae=s.jsxs("div",{className:"mb-6",children:[Ge,at]}),t[169]=Ge,t[170]=at,t[171]=Ae):Ae=t[171];let Le;t[172]!==e?(Le=e("contextSidebar.section.rawMessages"),t[172]=e,t[173]=Le):Le=t[173];let ze;t[174]!==Le?(ze=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Le}),t[174]=Le,t[175]=ze):ze=t[175];let Ke;if(t[176]!==d||t[177]!==o||t[178]!==b||t[179]!==a||t[180]!==e){let ut;t[182]!==d||t[183]!==o||t[184]!==a||t[185]!==e?(ut=Nt=>{const ts=So(Nt.info).role,Vt=o[Nt.info.id]===!0,Xt=d===Nt.info.id,ht=Nt.info.time?.created??null,Bt=Vt?JSON.stringify({info:Nt.info,parts:Nt.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":Vt,onClick:()=>{c(Zt=>({...Zt,[Nt.info.id]:Zt[Nt.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:kS(ts)}),s.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground",children:Nt.info.id})]}),s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:SS(ht)})]})}),Vt&&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:Zt=>{Zt.stopPropagation(),C(Nt.info.id,Bt)},"aria-label":e(Xt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Xt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Xt?s.jsx(A,{name:"check",className:"size-3.5"}):s.jsx(A,{name:"file-copy",className:"size-3.5"})})}),s.jsx(Hx,{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:Bt})]})})]},Nt.info.id)},t[182]=d,t[183]=o,t[184]=a,t[185]=e,t[186]=ut):ut=t[186],Ke=[...b].reverse().map(ut),t[176]=d,t[177]=o,t[178]=b,t[179]=a,t[180]=e,t[181]=Ke}else Ke=t[181];let lt;t[187]!==Ke?(lt=s.jsx("div",{className:"mt-2.5 space-y-1",children:Ke}),t[187]=Ke,t[188]=lt):lt=t[188];let xt;t[189]!==ze||t[190]!==lt?(xt=s.jsxs("div",{children:[ze,lt]}),t[189]=ze,t[190]=lt,t[191]=xt):xt=t[191];let dt;return t[192]!==fe||t[193]!==we||t[194]!==qe||t[195]!==nt||t[196]!==Ae||t[197]!==xt?(dt=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[fe,we,qe,nt,Ae,xt]})}),t[192]=fe,t[193]=we,t[194]=qe,t[195]=nt,t[196]=Ae,t[197]=xt,t[198]=dt):dt=t[198],dt};function PS(t){return t.currentSessionId}function AS(t){return t.providers}function DS(t){return Object.keys(t).length>0?{}:t}function TS(t){return So(t.info).role==="assistant"}function ES(t){return So(t.info).isUser}function MS(t,e){const n=Ma(e.info.cost);return t+n}function RS(t){return So(t.info).isUser&&typeof t.info.system=="string"}function FS(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 OS(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:ui(t.value)})]},t.label)}const LS=360,$S=1400,Ig=600,_S=24,jp=200,BS=(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",Dd=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"},Pg=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:a,intro:i})=>{const o=r.text.trim(),c=Object.entries(r.attributes).map(([b,x])=>`${b}="${x}"`).join(" "),d=r.computedStyle,p=r.bounds,m=r.center,u=i.replace(/[.:]+$/g,""),f=r.ancestry.map(b=>b.selectorPart).join(" > ");return[`${u}:`,`Page: ${t||"preview"}`,`Viewport: ${e.width}x${e.height}, DPR ${n}`,`Screenshot: ${a?"attached":"not attached"}`,`Element: ${r.tag}`,o?`Text: ${o}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,f?`- Ancestry: ${f}`:null,c?`- Attributes: ${c}`:null,`- Bounds: x=${Math.round(p.x)}, y=${Math.round(p.y)}, width=${Math.round(p.width)}, height=${Math.round(p.height)}`,`- Center: x=${Math.round(m.x)}, y=${Math.round(m.y)}`,`Styles: display=${d.display}; position=${d.position}; font=${d.fontWeight} ${d.fontSize} / ${d.lineHeight} ${d.fontFamily}; color=${d.color}; background=${d.backgroundColor}; z-index=${d.zIndex}`].filter(b=>typeof b=="string").join(`
|
|
56
|
-
`)},VS=async(t,e)=>{const n=typeof window<"u"?window.__TAURI__:void 0;if(typeof n?.core?.invoke=="function")try{const r=t.getBoundingClientRect(),a=await n.core.invoke("desktop_capture_page_rect",{x:r.left,y:r.top,width:r.width,height:r.height}),i=new Image;await new Promise((y,g)=>{i.onload=()=>y(),i.onerror=()=>g(new Error("Failed to load desktop preview screenshot")),i.src=`data:${a.mime};base64,${a.base64}`});const o=Math.max(1,i.naturalWidth||a.width||Math.floor(r.width)),c=Math.max(1,i.naturalHeight||a.height||Math.floor(r.height)),p=Math.min(1,1200/o),m=document.createElement("canvas");m.width=Math.floor(o*p),m.height=Math.floor(c*p);const u=m.getContext("2d");if(!u)return null;u.scale(p,p),u.drawImage(i,0,0,o,c);const f=o/Math.max(1,r.width),b=c/Math.max(1,r.height);u.fillStyle="rgba(37, 99, 235, 0.28)",u.strokeStyle="rgb(37, 99, 235)",u.lineWidth=Math.max(2,2*f),u.fillRect(e.bounds.x*f,e.bounds.y*b,e.bounds.width*f,e.bounds.height*b),u.strokeRect(e.bounds.x*f,e.bounds.y*b,e.bounds.width*f,e.bounds.height*b);const x=await new Promise(y=>m.toBlob(y,"image/jpeg",.82));return x?new File([x],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(r){return console.warn("[preview] failed to capture annotation screenshot:",r),null}return null},zS=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},Np=t=>Number.isFinite(t)?Math.min($S,Math.max(LS,Math.round(t))):Ig,US=(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},WS=(t,e)=>e(t==="chat"?"contextPanel.mode.chat":t==="file"?"contextPanel.mode.files":t==="diff"?"contextPanel.mode.diff":t==="plan"?"contextPanel.mode.plan":t==="preview"?"contextPanel.mode.preview":t==="browser"?"contextPanel.mode.browser":"contextPanel.mode.context"),KS=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},HS=(t,e)=>{if(t.label)return t.label;if(t.mode==="file")return KS(t.targetPath)||e("contextPanel.mode.files");if(t.mode==="preview"){const n=t.targetPath;if(n)try{const r=new URL(n);return r.host||r.hostname||e("contextPanel.mode.preview")}catch{}return e("contextPanel.mode.preview")}return t.mode==="diff"?t.stagedDiff?e("contextPanel.mode.stagedDiff"):e("contextPanel.mode.workingDiff"):WS(t.mode,e)},GS=t=>{if(t.mode==="file")return t.targetPath?s.jsx(Ar,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(A,{name:"arrow-left-right",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(A,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(A,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(A,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="preview")return s.jsx(A,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return s.jsx(A,{name:"global",className:"h-3.5 w-3.5"})},qS=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,JS=`new Promise((resolve) => {
|
|
57
|
-
const existing = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
58
|
-
if (existing) existing.remove();
|
|
59
|
-
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
60
|
-
try { window.__openchamberDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
|
|
61
|
-
}
|
|
62
|
-
const overlay = document.createElement('div');
|
|
63
|
-
overlay.id = '__openchamber_desktop_browser_overlay';
|
|
64
|
-
overlay.style.cssText = 'position:fixed;z-index:2147483647;pointer-events:none;border:2px solid #60a5fa;background:rgba(96,165,250,.24);border-radius:3px;display:none;box-sizing:border-box;';
|
|
65
|
-
document.documentElement.appendChild(overlay);
|
|
66
|
-
const cssEscape = (value) => {
|
|
67
|
-
try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
|
|
68
|
-
};
|
|
69
|
-
const selectorPart = (element) => {
|
|
70
|
-
const tag = element.tagName.toLowerCase();
|
|
71
|
-
if (element.id) return tag + '#' + cssEscape(element.id);
|
|
72
|
-
const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
|
|
73
|
-
return tag + className;
|
|
74
|
-
};
|
|
75
|
-
const metadata = (element) => {
|
|
76
|
-
const rect = element.getBoundingClientRect();
|
|
77
|
-
const style = getComputedStyle(element);
|
|
78
|
-
const ancestry = [];
|
|
79
|
-
let current = element;
|
|
80
|
-
while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
|
|
81
|
-
ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
|
|
82
|
-
current = current.parentElement;
|
|
83
|
-
}
|
|
84
|
-
const attrs = {};
|
|
85
|
-
for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
|
|
86
|
-
const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
|
|
87
|
-
return {
|
|
88
|
-
frame: 'top',
|
|
89
|
-
tag: element.tagName.toLowerCase(),
|
|
90
|
-
text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
|
|
91
|
-
selector: element.id ? '#' + cssEscape(element.id) : path,
|
|
92
|
-
path,
|
|
93
|
-
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
94
|
-
center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
|
|
95
|
-
attributes: attrs,
|
|
96
|
-
computedStyle: { display: style.display, position: style.position, fontWeight: style.fontWeight, fontSize: style.fontSize, lineHeight: style.lineHeight, fontFamily: style.fontFamily, color: style.color, backgroundColor: style.backgroundColor, zIndex: style.zIndex },
|
|
97
|
-
ancestry,
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
const move = (event) => {
|
|
101
|
-
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
102
|
-
if (!element || element === overlay || element === document.documentElement || element === document.body) return;
|
|
103
|
-
const rect = element.getBoundingClientRect();
|
|
104
|
-
overlay.style.display = 'block';
|
|
105
|
-
overlay.style.left = rect.left + 'px';
|
|
106
|
-
overlay.style.top = rect.top + 'px';
|
|
107
|
-
overlay.style.width = rect.width + 'px';
|
|
108
|
-
overlay.style.height = rect.height + 'px';
|
|
109
|
-
};
|
|
110
|
-
const cleanup = () => {
|
|
111
|
-
window.removeEventListener('mousemove', move, true);
|
|
112
|
-
window.removeEventListener('click', click, true);
|
|
113
|
-
window.removeEventListener('keydown', keydown, true);
|
|
114
|
-
if (window.__openchamberDesktopBrowserCancelInspect === cancel) {
|
|
115
|
-
delete window.__openchamberDesktopBrowserCancelInspect;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
const cancel = () => {
|
|
119
|
-
cleanup();
|
|
120
|
-
overlay.remove();
|
|
121
|
-
resolve(null);
|
|
122
|
-
};
|
|
123
|
-
const click = (event) => {
|
|
124
|
-
event.preventDefault();
|
|
125
|
-
event.stopPropagation();
|
|
126
|
-
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
127
|
-
const result = element ? metadata(element) : null;
|
|
128
|
-
cleanup();
|
|
129
|
-
overlay.remove();
|
|
130
|
-
resolve(result);
|
|
131
|
-
};
|
|
132
|
-
const keydown = (event) => {
|
|
133
|
-
if (event.key !== 'Escape') return;
|
|
134
|
-
cancel();
|
|
135
|
-
};
|
|
136
|
-
window.__openchamberDesktopBrowserCancelInspect = cancel;
|
|
137
|
-
window.addEventListener('mousemove', move, true);
|
|
138
|
-
window.addEventListener('click', click, true);
|
|
139
|
-
window.addEventListener('keydown', keydown, true);
|
|
140
|
-
});`,Vc=`(() => {
|
|
141
|
-
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
142
|
-
window.__openchamberDesktopBrowserCancelInspect();
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
146
|
-
if (overlay) overlay.remove();
|
|
147
|
-
})()`,zc=t=>{const e=t.trim();if(!e)return"about:blank";try{const n=new URL(e.includes("://")?e:`https://${e}`);return n.protocol!=="http:"&&n.protocol!=="https:"?"about:blank":n.toString()}catch{return"about:blank"}},YS=async(t,e,n,r,a,i)=>{if(!t)return null;try{const o=new Image;await new Promise((g,h)=>{o.onload=()=>g(),o.onerror=()=>h(new Error("Failed to load desktop browser screenshot")),o.src=`data:image/jpeg;base64,${t}`});const c=Math.max(1,o.naturalWidth||e),d=Math.max(1,o.naturalHeight||n),m=Math.min(1,1200/c),u=document.createElement("canvas");u.width=Math.floor(c*m),u.height=Math.floor(d*m);const f=u.getContext("2d");if(!f)return null;f.scale(m,m),f.drawImage(o,0,0,c,d);const b=c/Math.max(1,r||c),x=d/Math.max(1,a||d);f.fillStyle="rgba(37, 99, 235, 0.14)",f.strokeStyle="rgb(37, 99, 235)",f.lineWidth=Math.max(2,2*b),f.fillRect(i.bounds.x*b,i.bounds.y*x,i.bounds.width*b,i.bounds.height*x),f.strokeRect(i.bounds.x*b,i.bounds.y*x,i.bounds.width*b,i.bounds.height*x);const y=await new Promise(g=>u.toBlob(g,"image/jpeg",.82));return y?new File([y],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},QS=(t,e,n)=>{if(typeof window>"u")return"";const r=new URL(window.location.pathname,window.location.origin);return r.searchParams.set("ocPanel","session-chat"),r.searchParams.set("sessionId",t),n?r.searchParams.set("readOnly","1"):r.searchParams.delete("readOnly"),e&&e.trim().length>0?r.searchParams.set("directory",e):r.searchParams.delete("directory"),r.hash="",r.toString()},XS=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,Oa=new Map,ZS=3e4,ek=t=>{const e=Oa.get(t);return e?e.expiresAt-Date.now()<=ZS?(Oa.delete(t),null):e:null},tk=({rawUrl:t,onNavigate:e})=>{const{t:n}=ft(),{currentTheme:r}=jr(),[a,i]=l.useReducer(te=>te+1,0),[o,c]=l.useReducer(te=>te+1,0),[d,p]=l.useState({status:"idle"}),m=l.useRef(null),u=l.useRef(1),[f,b]=l.useState(!1),[x,y]=l.useState(!1),[g,h]=l.useState("all"),[j,v]=l.useState([]),[C,k]=l.useState(!1),[w,N]=l.useState(null),I=$t(te=>te.currentSessionId),T=$t(te=>te.newSessionDraft?.open),P=pi(te=>te.addDraft),D=Ha(te=>te.addAttachedFile);let S=null;try{S=t?new URL(t):null}catch{S=null}const M=S?S.hostname==="localhost"||S.hostname==="127.0.0.1"||S.hostname==="::1"||S.hostname==="[::1]"||S.hostname==="0.0.0.0":!1,E=S?S.hostname==="0.0.0.0"?new URL(S.toString().replace("0.0.0.0","127.0.0.1")):S:null,R=E?E.toString():"",V=r.metadata.variant;l.useEffect(()=>{if(!R||!M){p({status:"idle"});return}const te=ek(R);if(te){p({status:"ready",proxyBasePath:te.proxyBasePath,expiresAt:te.expiresAt});return}let he=!1;return p({status:"loading"}),(async()=>{try{const ce=await fetch("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:R})});if(!ce.ok){Oa.delete(R);const Y=await ce.json().catch(()=>({})),Se=typeof Y?.error=="string"?Y.error:`HTTP ${ce.status}`;he||p({status:"error",message:Se});return}const xe=await ce.json(),se=typeof xe.proxyBasePath=="string"?xe.proxyBasePath:"",ue=typeof xe.expiresAt=="number"?xe.expiresAt:0;if(!se){Oa.delete(R),he||p({status:"error",message:n("contextPanel.preview.proxyError")});return}Oa.set(R,{proxyBasePath:se,expiresAt:ue}),he||p({status:"ready",proxyBasePath:se,expiresAt:ue})}catch(ce){if(Oa.delete(R),!he){const xe=ce instanceof Error?ce.message:String(ce);p({status:"error",message:xe})}}})(),()=>{he=!0}},[M,o,n,R]);const B=E&&(E.protocol==="http:"||E.protocol==="https:")?E.toString():"",$=M&&d.status==="ready"&&E?(()=>{const te=E.pathname||"/",he=new URLSearchParams(E.search);he.set("ocPreview",String(a));const ce=he.toString(),xe=E.hash||"";return`${d.proxyBasePath}${te}${ce?`?${ce}`:""}${xe}`})():"",O=M?$:B,_=O||B,q=M&&(d.status==="loading"||d.status==="idle"),L=M&&d.status==="error",J=l.useCallback(te=>{const he=I??(T?"draft":null);if(!he){H.error(n("contextPanel.preview.inspect.attachNoSession"));return}const ce=t||O||"",xe=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},se=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let ue=!1;try{const Y=m.current,Se=Y?await VS(Y,te):null;Se&&(await D(Se),ue=!0)}catch{ue=!1}P({sessionKey:he,source:"preview-annotation",fileLabel:ce||"preview",startLine:1,endLine:1,code:Pg({pageUrl:ce,viewport:xe,devicePixelRatio:se,target:te,screenshotAttached:ue,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),H.success(n("contextPanel.preview.inspect.attached"))})()},[D,P,I,O,T,t,n]);l.useEffect(()=>{b(!1),v([]),y(!1),h("all"),k(!1),N(null),u.current=1},[O]),l.useEffect(()=>{const te=m.current?.contentWindow;!f||!te||te.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:C},window.location.origin)},[f,C]),l.useEffect(()=>{const te=m.current?.contentWindow;!f||!te||te.postMessage({source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:V},window.location.origin)},[f,V]),l.useEffect(()=>{if(!C||typeof window>"u")return;const te=he=>{he.key==="Escape"&&(he.preventDefault(),he.stopImmediatePropagation(),k(!1))};return window.addEventListener("keydown",te,!0),()=>window.removeEventListener("keydown",te,!0)},[C]),l.useEffect(()=>{if(!M||typeof window>"u")return;const te=xe=>{if(typeof xe=="string")return xe;if(xe==null)return"";try{return JSON.stringify(xe)}catch{return String(xe)}},he=xe=>{const se=u.current;u.current+=1,v(ue=>{const Y=[...ue,{...xe,id:se}];return Y.length>jp?Y.slice(Y.length-jp):Y})},ce=xe=>{if(xe.source!==m.current?.contentWindow)return;const se=xe.data;if(!(!se||se.source!=="openchamber-preview-bridge"||se.version!==1)){if(se.type==="ready"){b(!0);return}if(se.type==="console"){const ue=se.level==="error"||se.level==="warn"||se.level==="info"||se.level==="debug"?se.level:"log",Y=Array.isArray(se.args)?se.args.map(te).filter(Boolean):[];he({level:ue,message:Y.join(" "),ts:typeof se.ts=="number"?se.ts:Date.now()});return}if(se.type==="runtime-error"){const ue=te(se.filename),Y=typeof se.line=="number"?se.line:null,Se=typeof se.column=="number"?se.column:null,fe=ue?`${ue}${Y!==null?`:${Y}${Se!==null?`:${Se}`:""}`:""}`:"",Ce=te(se.stack);he({level:"runtime",message:te(se.message)||n("contextPanel.preview.console.runtimeError"),details:[fe,Ce].filter(Boolean).join(`
|
|
148
|
-
`),ts:typeof se.ts=="number"?se.ts:Date.now()});return}if(se.type==="resource-error"){const ue=te(se.tag)||"resource",Y=te(se.url);he({level:"resource",message:Y?`${ue}: ${Y}`:ue,details:te(se.outerHTML),ts:typeof se.ts=="number"?se.ts:Date.now()});return}if(se.type==="hover"){N(Dd(se.target)?se.target:null);return}if(se.type==="select"&&Dd(se.target)){N(se.target),k(!1),J(se.target);return}if(se.type==="navigate-preview"){const ue=typeof se.url=="string"?se.url:"",Y=se.navigation==="external"?"external":"proxy";if(ue&&Y==="external"){rr(ue);return}ue&&e(ue)}}};return window.addEventListener("message",ce),()=>{window.removeEventListener("message",ce)}},[J,M,e,n]);const Z=j.filter(te=>te.level==="error"||te.level==="runtime"||te.level==="resource").length,ie=j.filter(te=>BS(te,g)),ne=l.useCallback(()=>{const te=[`Preview URL: ${t||O||""}`,`Events: ${j.length}`,""].join(`
|
|
149
|
-
`),he=j.map(ce=>{const xe=new Date(ce.ts).toISOString(),se=ce.details?`
|
|
150
|
-
${ce.details}`:"";return`[${xe}] [${ce.level}] ${ce.message}${se}`}).join(`
|
|
151
|
-
`);En(`${te}${he}`).then(ce=>{ce.ok?H.success(n("contextPanel.preview.console.copied")):H.error(n("contextPanel.preview.console.copyFailed"))})},[j,O,t,n]),me=l.useCallback(()=>{const te=I??(T?"draft":null);if(!te){H.error(n("contextPanel.preview.console.attachNoSession"));return}const he=[`Preview URL: ${t||O||""}`,`Events: ${j.length}`,""].join(`
|
|
152
|
-
`),ce=j.map(xe=>{const se=new Date(xe.ts).toISOString(),ue=xe.details?`
|
|
153
|
-
${xe.details}`:"";return`[${se}] [${xe.level}] ${xe.message}${ue}`}).join(`
|
|
154
|
-
`);P({sessionKey:te,source:"preview-console",fileLabel:t||O||"preview",startLine:1,endLine:Math.max(1,j.length),code:`${he}${ce}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),H.success(n("contextPanel.preview.console.attached"))},[P,j,I,O,T,t,n]),[pe,G]=l.useState("unknown"),K=l.useRef(0),Q=l.useRef(0),W=15e3;l.useEffect(()=>{if(!$){G("unknown"),K.current=0,Q.current=0;return}let te=!1;return K.current||(K.current=Date.now(),Q.current=0),G("unknown"),(async()=>{const ce=await(async()=>{try{return await fetch($,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(te)return;if(!ce){G("unreachable");return}if(ce.status===403||ce.status===404){Oa.delete(R),p({status:"loading"}),c();return}if(ce.status!==502){G("reachable");return}const xe=K.current||Date.now();if(Date.now()-xe<W){G("starting"),Q.current+=1;const ue=Q.current,Y=Math.min(2e3,250*Math.pow(2,Math.min(4,ue)));setTimeout(()=>{te||i()},Y).unref?.();return}G("unreachable")})(),()=>{te=!0}},[$,a,R]);const de=M&&d.status==="ready"&&(pe==="unknown"||pe==="starting"),ge=M&&d.status==="ready"&&pe==="unreachable",ve=l.useCallback(te=>{if(!M||d.status!=="ready"||typeof window>"u")return;const he=te.currentTarget.contentWindow;if(he)try{const ce=he.location;if(ce.origin!==window.location.origin||ce.pathname.startsWith(d.proxyBasePath))return;const xe=`${d.proxyBasePath}${ce.pathname}${ce.search}${ce.hash}`;he.location.replace(xe)}catch{}},[M,d]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:_||t,children:_||t||n("contextPanel.preview.empty")}),s.jsx(be,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>i(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!O,children:s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(be,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{B&&rr(B)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!B,children:s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"})}),M?s.jsx(be,{type:"button",size:"sm",variant:C?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>k(te=>!te),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!f,children:s.jsx(A,{name:"cursor",className:"h-3.5 w-3.5"})}):null,M?s.jsxs(be,{type:"button",size:"sm",variant:x?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>y(te=>!te),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&&j.length===0,children:[s.jsx(A,{name:"terminal-box",className:"h-3.5 w-3.5"}),Z>0?s.jsx("span",{className:"typography-micro text-status-error",children:Z}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[de?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.startingServer")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.startingServerHint")})]}):ge?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.upstreamUnreachable")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.upstreamUnreachableHint")}),s.jsx(be,{type:"button",size:"sm",variant:"outline",onClick:()=>i(),children:n("contextPanel.preview.actions.retry")})]}):O&&(!M||pe==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:m,src:O,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:V},onLoad:ve,sandbox:M?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${O}:${a}`),C&&w?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:w.bounds.x,top:w.bounds.y,width:w.bounds.width,height:w.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[w.tag,w.text?` · ${w.text}`:""]})}):null]}):q?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):L?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")}),x?s.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:n("contextPanel.preview.console.title")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(be,{type:"button",size:"xs",variant:"ghost",onClick:me,disabled:j.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(be,{type:"button",size:"xs",variant:"ghost",onClick:ne,disabled:j.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(be,{type:"button",size:"xs",variant:"ghost",onClick:()=>v([]),disabled:j.length===0,children:n("contextPanel.preview.console.clear")})]})]}),s.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(te=>s.jsx(be,{type:"button",size:"xs",variant:g===te?"secondary":"ghost",onClick:()=>h(te),children:n(te==="all"?"contextPanel.preview.console.filter.all":te==="errors"?"contextPanel.preview.console.filter.errors":te==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},te))}),s.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:j.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.empty")}):ie.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):ie.map(te=>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:ye("shrink-0 uppercase",te.level==="error"||te.level==="runtime"||te.level==="resource"?"text-status-error":te.level==="warn"?"text-status-warning":"text-muted-foreground"),children:te.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:te.message})]})},te.id))})]}):null]})]})},sk=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=ft(),a=l.useRef(null),i=Fe(T=>T.setContextPanelTabTargetPath),o=zc(t),c=o!=="about:blank"?o:"",[d,p]=l.useState(c),[m,u]=l.useState(c),[f,b]=l.useState(!1),[x,y]=l.useState(!0),g=l.useRef(null),h=x,j=l.useCallback(T=>{!T||T==="about:blank"||!e||!n||i(e,n,T)},[e,n,i]),v=$t(T=>T.currentSessionId),C=$t(T=>T.newSessionDraft?.open),k=pi(T=>T.addDraft),w=Ha(T=>T.addAttachedFile);l.useEffect(()=>{const T=a.current;if(!T)return;const P=()=>{try{const R=T.getURL();R&&R!=="about:blank"&&(u(R),p(R),j(R))}catch{}},D=R=>{const V=R.detail;typeof V?.url=="string"&&V.url&&(u(V.url),p(V.url),j(V.url))},S=()=>{g.current&&clearTimeout(g.current),g.current=setTimeout(()=>y(!0),200)},M=()=>{g.current&&clearTimeout(g.current),y(!1),P()},E=R=>{const V=R.detail;if(V?.disposition==="new-window"||V?.disposition==="foreground-tab"||V?.disposition==="background-tab"){R.preventDefault();const B=a.current;typeof B?.loadURL=="function"&&V.url&&B.loadURL(V.url)}};T.addEventListener("did-navigate",D),T.addEventListener("did-navigate-in-page",D),T.addEventListener("did-start-loading",S),T.addEventListener("did-stop-loading",M),T.addEventListener("new-window",E);try{T.isLoading()||(y(!1),P())}catch{}return()=>{g.current&&clearTimeout(g.current),T.removeEventListener("did-navigate",D),T.removeEventListener("did-navigate-in-page",D),T.removeEventListener("did-start-loading",S),T.removeEventListener("did-stop-loading",M),T.removeEventListener("new-window",E)}},[j]),l.useEffect(()=>{const T=setTimeout(()=>y(!1),3e4);return()=>clearTimeout(T)},[]),l.useEffect(()=>{if(!f)return;const T=P=>{if(P.key!=="Escape")return;P.preventDefault(),P.stopImmediatePropagation(),b(!1);const D=a.current;try{D?.executeJavaScript?.(Vc).catch(()=>{})}catch{}};return window.addEventListener("keydown",T,!0),()=>window.removeEventListener("keydown",T,!0)},[f]),l.useEffect(()=>{const T=a.current;return()=>{try{const P=T?.getURL?.();P&&P!=="about:blank"&&i(e,n,P)}catch{}try{T?.executeJavaScript?.(Vc).catch(()=>{})}catch{}}},[e,n,i]);const N=l.useCallback(T=>{const P=a.current;if(typeof P?.loadURL!="function")return;const D=zc(T);try{P.loadURL(D)}catch{}},[]),I=l.useCallback(()=>{const T=a.current;if(T){if(f){b(!1);try{T.executeJavaScript?.(Vc).catch(()=>{})}catch{}return}b(!0),T.executeJavaScript?.(JS,!0).then(async P=>{if(b(!1),!P||!Dd(P))return;const D=v??(C?"draft":null);if(!D){H.error(r("contextPanel.preview.inspect.attachNoSession"));return}const S=typeof T.getWebContentsId=="function"?T.getWebContentsId():null;if(S==null)return;const M=await ey("desktop_browser_capture_page",{webContentsId:S}),E=await T.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),R=Number.isFinite(E?.width)?E.width:M.width,V=Number.isFinite(E?.height)?E.height:M.height,B=await YS(M.base64,M.width,M.height,R,V,P),$=!!B;B&&await w(B),k({sessionKey:D,source:"preview-annotation",fileLabel:m||"browser",startLine:1,endLine:1,code:Pg({pageUrl:m,viewport:{width:R,height:V},devicePixelRatio:window.devicePixelRatio||1,target:P,screenshotAttached:$,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),H.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>b(!1))}},[w,k,v,m,f,C,r]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(be,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.goBack?.()}catch{}},children:s.jsx(A,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(be,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.goForward?.()}catch{}},children:s.jsx(A,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(be,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.reload?.()}catch{}},children:s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:T=>{T.preventDefault(),N(d)},children:s.jsx("input",{value:d,onChange:T=>p(T.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(be,{type:"button",variant:f?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:I,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(A,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(be,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{rr(m)},children:s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[s.jsx("webview",{ref:a,src:zc(t),partition:"persist:openchamber-browser",style:{width:"100%",height:"100%",border:"none"}}),(!m||m==="about:blank")&&!x?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(nu,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")})]}):null,h?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},nk=()=>{const{t}=ft(),e=na()??"",n=l.useMemo(()=>zS(e),[e]),r=Fe(W=>n?W.contextPanelByDirectory[n]:void 0),a=Fe(W=>W.closeContextPanel),i=Fe(W=>W.closeContextPanelTab),o=Fe(W=>W.toggleContextPanelExpanded),c=Fe(W=>W.setContextPanelWidth),d=Fe(W=>W.setActiveContextPanelTab),p=Fe(W=>W.reorderContextPanelTabs),m=Fn(W=>W.setSelectedPath),u=Fe(W=>W.openContextPreview),{themeMode:f,lightThemeId:b,darkThemeId:x,currentTheme:y}=jr(),g=l.useMemo(()=>r?.tabs??[],[r?.tabs]),h=g.find(W=>W.id===r?.activeTabId)??g[g.length-1]??null,j=!!(r?.isOpen&&h),v=!!(j&&r?.expanded),C=Np(r?.width??Ig),[k,w]=l.useState(!1),N=l.useRef(0),I=l.useRef(C),T=l.useRef(null),P=l.useRef(null),D=l.useRef(null),S=l.useRef(new Map),M=l.useRef(!1);l.useEffect(()=>{if(!j||M.current){M.current=j;return}const W=window.requestAnimationFrame(()=>{D.current?.focus({preventScroll:!0})});return M.current=!0,()=>window.cancelAnimationFrame(W)},[j]);const E=l.useCallback(W=>{const de=D.current;de&&de.style.setProperty("--oc-context-panel-width",`${W}px`)},[]),R=l.useCallback(W=>{if(!(!j||v||!n)){try{W.currentTarget.setPointerCapture(W.pointerId)}catch{}P.current=W.pointerId,w(!0),N.current=W.clientX,I.current=C,T.current=C,E(C),W.preventDefault()}},[E,n,v,j,C]),V=l.useCallback(W=>{if(!k||P.current!==W.pointerId)return;const de=N.current-W.clientX,ge=Np(I.current+de);T.current!==ge&&(T.current=ge,E(ge))},[E,k]),B=l.useCallback(W=>{if(P.current!==W.pointerId||!n)return;try{W.currentTarget.releasePointerCapture(W.pointerId)}catch{}const de=T.current??C;w(!1),P.current=null,T.current=null,c(n,de)},[n,c,C]);l.useEffect(()=>{k||(T.current=null)},[k]);const $=l.useCallback(()=>{n&&a(n)},[a,n]),O=l.useCallback(()=>{n&&o(n)},[n,o]),_=l.useCallback(W=>{W.key==="Escape"&&(W.preventDefault(),W.stopPropagation(),$())},[$]);l.useEffect(()=>{if(!(!n||!h)&&h.mode==="file"&&h.targetPath){m(n,h.targetPath);return}},[h,n,m]);const q=h?.mode==="chat"?h.id:null,L=l.useCallback(()=>{if(typeof window>"u")return;const W={themeMode:f,lightThemeId:b,darkThemeId:x,currentTheme:y};for(const de of S.current.values()){const ge=de.contentWindow;if(!ge)continue;const ve=ge.__openchamberApplyThemeSync;if(typeof ve=="function")try{ve(W);continue}catch{}ge.postMessage({type:"openchamber:theme-sync",payload:W},window.location.origin)}},[y,x,b,f]),J=l.useCallback(()=>{if(!(typeof window>"u"))for(const[W,de]of S.current.entries()){const ge=de.contentWindow;if(!ge)continue;const ve={visible:q===W},te=ge.__openchamberSetEmbeddedVisibility;if(typeof te=="function")try{te(ve);continue}catch{}ge.postMessage({type:"openchamber:embedded-visibility",payload:ve},window.location.origin)}},[q]);l.useLayoutEffect(()=>{g.some(de=>de.mode==="chat")&&(L(),J())},[x,b,J,L,g,f]);const Z=l.useMemo(()=>g.map(W=>{const de=HS(W,t),ge=XS(de,_S),ve=US(W.targetPath,e);return{id:W.id,label:ge,icon:GS(W),title:ve?`${de}: ${ve}`:de,closeLabel:t("contextPanel.tab.closeTabAria",{label:ge})}}),[e,t,g]),ie=h?.mode==="diff"?s.jsx(jg,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,hideFileSelector:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:h.stagedDiff?"staged":"working",targetFilePath:h.targetPath},h.id):h?.mode==="context"?s.jsx(IS,{}):h?.mode==="plan"?s.jsx(Cg,{targetPath:h.targetPath}):h?.mode==="preview"?s.jsx(tk,{rawUrl:h.targetPath??"",onNavigate:W=>u(e,W)}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(A,{name:"global",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.preview.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.preview.description")})]}),ne=l.useMemo(()=>g.filter(W=>W.mode==="chat"),[g]),me=l.useMemo(()=>g.filter(W=>W.mode==="browser"),[g]),pe=l.useMemo(()=>g.some(W=>W.mode==="file"),[g]),G=h?.mode==="file",K=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-transparent",children:[s.jsx(Er,{items:Z,activeId:h?.id??null,onSelect:W=>{n&&d(n,W)},onClose:W=>{n&&i(n,W)},onReorder:(W,de)=>{n&&p(n,W,de)},layoutMode:"scrollable",variant:"default"}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[s.jsx(be,{type:"button",variant:"ghost",size:"sm",onClick:O,className:"h-7 w-7 p-0",title:t(v?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(v?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:v?s.jsx(A,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(be,{type:"button",variant:"ghost",size:"sm",onClick:$,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]});if(!j)return null;const Q=v?{"--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":`${k?T.current??C:C}px`};return s.jsxs("aside",{ref:D,"data-context-panel":"true",tabIndex:-1,className:ye("flex min-h-0 flex-col overflow-hidden bg-background",!v&&"border-l border-border/40",v?"absolute inset-0 z-20 min-w-0":"relative h-full flex-shrink-0",k?"transition-none":"transition-[width] duration-200 ease-in-out"),onKeyDownCapture:_,style:Q,children:[!v&&s.jsx("div",{className:ye("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",k&&"bg-[var(--interactive-border)]"),onPointerDown:R,onPointerMove:V,onPointerUp:B,onPointerCancel:B,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),K,s.jsxs("div",{className:ye("relative min-h-0 flex-1 overflow-hidden",k&&"pointer-events-none"),children:[pe?s.jsx("div",{className:ye("absolute inset-0",G?"block":"hidden"),children:s.jsx(kg,{mode:"editor-only"})}):null,ne.map(W=>{const de=qS(W.dedupeKey);if(!de)return null;const ge=QS(de,n||null,W.readOnly);return ge?s.jsx("iframe",{ref:ve=>{if(!ve){S.current.delete(W.id);return}S.current.set(W.id,ve)},src:ge,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:de}),className:ye("absolute inset-0 h-full w-full border-0 bg-background",q===W.id?"block":"hidden"),onLoad:()=>{L(),J()}},W.id):null}),me.map(W=>s.jsx("div",{className:ye("absolute inset-0",h?.mode!=="browser"&&"hidden"),children:s.jsx(sk,{initialUrl:W.targetPath??"",directory:n,tabID:W.id})},W.id)),h?.mode!=="chat"&&!G&&h?.mode!=="browser"?ie:null]})]})},xu=[{slug:"home",title:"Settings",group:"general",kind:"single",description:"Search and jump to common pages.",keywords:["search","settings"]},{slug:"projects",title:"Projects",group:"projects",kind:"split",keywords:["project","projects","worktree","worktrees","repo","repository","directory"]},{slug:"remote-instances",title:"Remote Instances",group:"projects",kind:"split",keywords:["ssh","remote","instances","tunnels","forwarding","connection"],isAvailable:t=>t.isDesktop&&!t.isWeb&&!t.isVSCode},{slug:"providers",title:"Providers",group:"opencode",kind:"split",keywords:["provider","providers","models","model","api key","api keys","openai","anthropic","ollama","credentials"]},{slug:"usage",title:"Usage",group:"usage",kind:"split",keywords:["quota","billing","tokens","usage","limits"]},{slug:"agents",title:"Agents",group:"opencode",kind:"split",keywords:["agent","agents","prompts","tools","permissions"]},{slug:"behavior",title:"Behavior",group:"opencode",kind:"single",keywords:["behavior","agents.md","system prompt","global rules","instructions","override"]},{slug:"commands",title:"Commands",group:"opencode",kind:"split",keywords:["command","commands","slash","macros","automation"]},{slug:"mcp",title:"MCP",group:"opencode",kind:"split",keywords:["mcp","model context protocol","servers","tools","remote","stdio"]},{slug:"plugins",title:"Plugins",group:"opencode",kind:"split",keywords:["plugin","plugins","extensions","addons","npm","opencode-wakatime"]},{slug:"skills.installed",title:"Skills",group:"skills",kind:"split",keywords:["skill","skills","instructions","install","catalog"]},{slug:"skills.catalog",title:"Skills Catalog",group:"skills",kind:"single",keywords:["install","catalog","external","repository","skills catalog"]},{slug:"git",title:"Git",group:"git",kind:"single",keywords:["git","github","identity","identities","ssh","profiles","credentials","keys","commit","gitmoji","oauth","prs","issues"],isAvailable:t=>!t.isVSCode},{slug:"appearance",title:"Appearance",group:"appearance",kind:"single",keywords:["theme","font","spacing","padding","corner radius","radius","input bar","keyboard","viewport","mobile","terminal","pwa","install name","app shortcuts"]},{slug:"chat",title:"Chat",group:"general",kind:"single",keywords:["tools","diff","reasoning","dotfiles","draft","queue","output","copy","image","split messages","message actions"]},{slug:"shortcuts",title:"Shortcuts",group:"general",kind:"single",keywords:["keyboard","hotkeys","shortcuts","bindings"],isAvailable:t=>!t.isVSCode},{slug:"sessions",title:"Sessions",group:"general",kind:"single",keywords:["defaults","default agent","default model","retention","memory","limits","zen"]},{slug:"magic-prompts",title:"Magic Prompts",group:"general",kind:"split",keywords:["prompts","templates","git","github","review","commit","pull request"],isAvailable:t=>!t.isVSCode},{slug:"snippets",title:"Snippets",group:"general",kind:"split",keywords:["prompt","templates","multi-run","strategy","approach"]},{slug:"notifications",title:"Notifications",group:"general",kind:"single",keywords:["alerts","native","summary","summarization"]},{slug:"voice",title:"Voice",group:"advanced",kind:"single",keywords:["tts","speech","voice"],isAvailable:t=>!t.isVSCode},{slug:"tunnel",title:"Remote Tunnel",group:"advanced",kind:"single",keywords:["tunnel","cloudflare","qr","remote","mobile","share"],isAvailable:t=>!t.isVSCode}],rk={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function Qi(t){const e=t.trim().toLowerCase();return xu.find(n=>n.slug===e)??null}function bu(t){const e=(t??"").trim().toLowerCase();if(!e)return"home";const n=rk[e];if(n)return n;const r=Qi(e);return r?r.slug:"home"}const Ag=t=>t.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),Po=t=>{const e=ot.c(39),{className:n}=t,{t:r}=ft(),a=Cs(ak),i=Cs(ik),o=Cs(ok),c=fn();let d;e[0]!==a?(d=[...a].sort(lk),e[0]=a,e[1]=d):d=e[1];const p=d;let m;e:{if(p.length===0){m=null;break e}let E;e[2]!==i||e[3]!==p?(E=p.find(R=>R.id===i)??p[0],e[2]=i,e[3]=p,e[4]=E):E=e[4],m=E}const u=m;if(c||p.length===0)return null;let f;e[5]!==u||e[6]!==r?(f=u?.label&&u.label.trim().length>0?u.label:u?.path.split("/").filter(Boolean).pop()||u?.path||r("settings.shared.projectSelector.fallbackProject"),e[5]=u,e[6]=r,e[7]=f):f=e[7];const b=f;let x;e[8]!==b?(x=Ag(b),e[8]=b,e[9]=x):x=e[9];const y=x;let g;e[10]!==n?(g=ye(n),e[10]=n,e[11]=g):g=e[11];let h;e[12]!==r?(h=r("settings.shared.projectSelector.switchProjectAria"),e[12]=r,e[13]=h):h=e[13];let j;e[14]!==r?(j=r("settings.shared.projectSelector.switchProjectTitle"),e[14]=r,e[15]=j):j=e[15];let v,C;e[16]===Symbol.for("react.memo_cache_sentinel")?(v=ye("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),C=s.jsx(A,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=v,e[17]=C):(v=e[16],C=e[17]);let k;e[18]!==y?(k=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:y}),e[18]=y,e[19]=k):k=e[19];let w;e[20]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=w):w=e[20];let N;e[21]!==k||e[22]!==h||e[23]!==j?(N=s.jsx(Is,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":h,title:j,className:v,children:[C,k,w]})}),e[21]=k,e[22]=h,e[23]=j,e[24]=N):N=e[24];const I=u?.id??"";let T;e[25]!==o?(T=E=>{E&&o(E)},e[25]=o,e[26]=T):T=e[26];let P;e[27]!==p?(P=p.map(ck),e[27]=p,e[28]=P):P=e[28];let D;e[29]!==I||e[30]!==T||e[31]!==P?(D=s.jsx(Ps,{align:"start",className:"w-auto",children:s.jsx(Al,{value:I,onValueChange:T,children:P})}),e[29]=I,e[30]=T,e[31]=P,e[32]=D):D=e[32];let S;e[33]!==N||e[34]!==D?(S=s.jsxs(As,{children:[N,D]}),e[33]=N,e[34]=D,e[35]=S):S=e[35];let M;return e[36]!==S||e[37]!==g?(M=s.jsx("div",{className:g,children:S}),e[36]=S,e[37]=g,e[38]=M):M=e[38],M};function ak(t){return t.projects}function ik(t){return t.activeProjectId}function ok(t){return t.setActiveProject}function lk(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function ck(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,n=Ag(e);return s.jsx(Dl,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},t.id)}function dk(t,e){return`opencode:sidebar-group:${t}:${e}`}const Td=t=>{const e=ot.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=dk(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 D=localStorage.getItem(p);if(D!==null)return D==="true"}catch{}return c},e[3]=c,e[4]=p,e[5]=u):u=e[5];const[f,b]=_e.useState(u);let x,y;e[6]!==f||e[7]!==p?(x=()=>{try{localStorage.setItem(p,String(f))}catch{}},y=[p,f],e[6]=f,e[7]=p,e[8]=x,e[9]=y):(x=e[8],y=e[9]),_e.useEffect(x,y);let g;e[10]===Symbol.for("react.memo_cache_sentinel")?(g=()=>b(uk),e[10]=g):g=e[10];let h;e[11]===Symbol.for("react.memo_cache_sentinel")?(h=ye("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=h):h=e[11];const j=!f&&"-rotate-90";let v;e[12]!==j?(v=ye("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",j),e[12]=j,e[13]=v):v=e[13];let C;e[14]!==v?(C=s.jsx(A,{name:"arrow-down-s",className:v}),e[14]=v,e[15]=C):C=e[15];let k;e[16]!==n?(k=s.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=k):k=e[17];let w;e[18]!==r?(w=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:r}),e[18]=r,e[19]=w):w=e[19];let N;e[20]!==m||e[21]!==f||e[22]!==C||e[23]!==k||e[24]!==w?(N=s.jsxs("button",{type:"button",onClick:g,"aria-expanded":f,"aria-controls":m,className:h,children:[C,k,w]}),e[20]=m,e[21]=f,e[22]=C,e[23]=k,e[24]=w,e[25]=N):N=e[25];const I=!f;let T;e[26]!==o||e[27]!==m||e[28]!==I?(T=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]=T):T=e[29];let P;return e[30]!==N||e[31]!==T?(P=s.jsxs("div",{children:[N,T]}),e[30]=N,e[31]=T,e[32]=P):P=e[32],P};function uk(t){return!t}const mk=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},pk=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&e.set(`${n.permission}::${n.pattern}`,n);return Array.from(e.values())},Sp=t=>{const e=pk(mk(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},fk=({onItemSelect:t})=>{const{t:e}=ft(),[n,r]=l.useState(null),[a,i]=l.useState(""),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(!1),[f,b]=l.useState(null),{selectedAgentName:x,agents:y,setSelectedAgent:g,setAgentDraft:h,createAgent:j,deleteAgent:v,loadAgents:C}=ji(Gn(_=>({selectedAgentName:_.selectedAgentName,agents:_.agents,setSelectedAgent:_.setSelectedAgent,setAgentDraft:_.setAgentDraft,createAgent:_.createAgent,deleteAgent:_.deleteAgent,loadAgents:_.loadAgents})));l.useEffect(()=>{C()},[C]);const k="bg-background",w=()=>{const _="new-agent";let q=_,L=1;for(;y.some(J=>J.name===q);)q=`${_}-${L}`,L++;h({name:q,scope:"user"}),g(q),t?.()},N=async _=>{if(fi(_)){H.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}c(_),p("delete")},I=async _=>{fi(_)&&(c(_),p("reset"))},T=()=>{c(null),p(null)},P=async()=>{if(!o||!d)return;u(!0),await v(o.name)?(d==="delete"?H.success(e("settings.agents.sidebar.toast.agentDeleted",{name:o.name})):H.success(e("settings.agents.sidebar.toast.agentReset",{name:o.name})),T()):d==="delete"?H.error(e("settings.agents.sidebar.toast.deleteFailed")):H.error(e("settings.agents.sidebar.toast.resetFailed")),u(!1)},D=_=>{const q=_.name;let L=1,J=`${q}-copy`;for(;y.some(me=>me.name===J);)L++,J=`${q}-copy-${L}`;const Z=_,ie=_.model?.providerID&&_.model?.modelID?`${_.model.providerID}/${_.model.modelID}`:null,ne=_;h({name:J,scope:Z.scope||"user",description:_.description,model:ie,temperature:_.temperature,top_p:_.topP,prompt:_.prompt,mode:_.mode,permission:Sp(_.permission),disable:ne.disable}),g(J)},S=_=>{i(_.name),r(_)},M=async()=>{if(!n)return;const _=a.trim().replace(/\s+/g,"-");if(!_){H.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(_===n.name){r(null);return}if(y.some(Z=>Z.name===_)){H.error(e("settings.agents.sidebar.toast.agentExists"));return}const q=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,L=n;await j({name:_,description:n.description,model:q,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:Sp(n.permission),disable:L.disable,scope:L.scope})?await v(n.name)?(H.success(`Agent renamed to "${_}"`),g(_)):H.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):H.error(e("settings.agents.sidebar.toast.renameFailed")),r(null)},E=_=>{switch(_){case"primary":return s.jsx(A,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(A,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(A,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},R=y.filter(_=>!ty(_)),V=R.filter(fi),B=R.filter(_=>!fi(_)),{groupedCustomAgents:$,ungroupedCustomAgents:O}=_e.useMemo(()=>{const _={},q=[];for(const J of B){const Z=J;Z.group?(_[Z.group]||(_[Z.group]=[]),_[Z.group].push(J)):q.push(J)}return{groupedCustomAgents:Object.keys(_).sort((J,Z)=>J.localeCompare(Z)).map(J=>({name:J,agents:_[J]})),ungroupedCustomAgents:q}},[B]);return s.jsxs("div",{className:ye("flex h-full flex-col",k),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.agents.sidebar.title")}),s.jsx(Po,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:R.length})}),s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:w,children:s.jsx(A,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ss,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:R.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(A,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[V.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")}),V.map(_=>s.jsx(Uc,{agent:_,isSelected:x===_.name,onSelect:()=>{g(_.name),t?.()},onReset:()=>I(_),onDuplicate:()=>D(_),getAgentModeIcon:E,isMenuOpen:f===_.name,onMenuOpenChange:q=>b(q?_.name:null)},_.name))]}),B.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),$.map(({name:_,agents:q})=>s.jsx(Td,{label:_,count:q.length,storageKey:"agents",children:q.map(L=>s.jsx(Uc,{agent:L,isSelected:x===L.name,onSelect:()=>{g(L.name),t?.()},onRename:()=>S(L),onDelete:()=>N(L),onDuplicate:()=>D(L),getAgentModeIcon:E,isMenuOpen:f===L.name,onMenuOpenChange:J=>b(J?L.name:null)},L.name))},_)),O.map(_=>s.jsx(Uc,{agent:_,isSelected:x===_.name,onSelect:()=>{g(_.name),t?.()},onRename:()=>S(_),onDelete:()=>N(_),onDuplicate:()=>D(_),getAgentModeIcon:E,isMenuOpen:f===_.name,onMenuOpenChange:q=>b(q?_.name:null)},_.name))]})]})}),s.jsx(us,{open:o!==null&&d!==null,onOpenChange:_=>{!_&&!m&&T()},children:s.jsxs(ds,{className:"max-w-md",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Ns,{children:d==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:o?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:o?.name??""})})]}),s.jsxs(_s,{children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:T,disabled:m,children:e("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",onClick:P,disabled:m,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(us,{open:n!==null,onOpenChange:_=>!_&&r(null),children:s.jsxs(ds,{children:[s.jsxs(hs,{children:[s.jsx(ms,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Ns,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),s.jsx(Lt,{value:a,onChange:_=>i(_.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:_=>{_.key==="Enter"&&M()}}),s.jsxs(_s,{children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>r(null),children:e("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",onClick:M,children:e("settings.common.actions.rename")})]})]})})]})},Uc=t=>{const e=ot.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}=ft(),b=n;let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=uo(),e[0]=x):x=e[0];const y=x,g=r?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[1]!==g?(h=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",g),e[1]=g,e[2]=h):h=e[2];let j;e[3]!==u?(j=y?void 0:q=>{q.preventDefault(),u(!0)},e[3]=u,e[4]=j):j=e[4];let v;e[5]!==n.name?(v=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=v):v=e[6];let C;e[7]!==n.mode||e[8]!==p?(C=p(n.mode),e[7]=n.mode,e[8]=p,e[9]=C):C=e[9];let k;e[10]!==n||e[11]!==b.scope||e[12]!==f?(k=(b.scope||fi(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:fi(n)?f("settings.agents.sidebar.badge.system"):b.scope}),e[10]=n,e[11]=b.scope,e[12]=f,e[13]=k):k=e[13];let w;e[14]!==v||e[15]!==C||e[16]!==k?(w=s.jsxs("div",{className:"flex items-center gap-1.5",children:[v,C,k]}),e[14]=v,e[15]=C,e[16]=k,e[17]=w):w=e[17];let N;e[18]!==n.description?(N=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[18]=n.description,e[19]=N):N=e[19];let I;e[20]!==a||e[21]!==w||e[22]!==N?(I=s.jsxs("button",{onClick:a,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[w,N]}),e[20]=a,e[21]=w,e[22]=N,e[23]=I):I=e[23];let T;e[24]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(Is,{asChild:!0,children:s.jsx(be,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[24]=T):T=e[24];let P;e[25]!==c||e[26]!==f?(P=c&&s.jsxs(_t,{onClick:q=>{q.stopPropagation(),c()},children:[s.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),f("settings.common.actions.rename")]}),e[25]=c,e[26]=f,e[27]=P):P=e[27];let D;e[28]!==d?(D=q=>{q.stopPropagation(),d()},e[28]=d,e[29]=D):D=e[29];let S;e[30]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(A,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[30]=S):S=e[30];let M;e[31]!==f?(M=f("settings.common.actions.duplicate"),e[31]=f,e[32]=M):M=e[32];let E;e[33]!==D||e[34]!==M?(E=s.jsxs(_t,{onClick:D,children:[S,M]}),e[33]=D,e[34]=M,e[35]=E):E=e[35];let R;e[36]!==o||e[37]!==f?(R=o&&s.jsxs(_t,{onClick:q=>{q.stopPropagation(),o()},children:[s.jsx(A,{name:"restart",className:"h-4 w-4 mr-px"}),f("settings.common.actions.reset")]}),e[36]=o,e[37]=f,e[38]=R):R=e[38];let V;e[39]!==i||e[40]!==f?(V=i&&s.jsxs(_t,{onClick:q=>{q.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),f("settings.common.actions.delete")]}),e[39]=i,e[40]=f,e[41]=V):V=e[41];let B;e[42]!==P||e[43]!==E||e[44]!==R||e[45]!==V?(B=s.jsxs(Ps,{align:"end",className:"w-fit min-w-20",children:[P,E,R,V]}),e[42]=P,e[43]=E,e[44]=R,e[45]=V,e[46]=B):B=e[46];let $;e[47]!==m||e[48]!==u||e[49]!==B?($=s.jsxs(As,{open:m,onOpenChange:u,children:[T,B]}),e[47]=m,e[48]=u,e[49]=B,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 _;return e[54]!==O||e[55]!==h||e[56]!==j?(_=s.jsx("div",{className:h,onContextMenu:j,children:O}),e[54]=O,e[55]=h,e[56]=j,e[57]=_):_=e[57],_};function kp(t,e,n){return Math.min(n,Math.max(e,t))}function hk(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 Cp(t,e){const n=hk(e);return n<=0?t:Number(t.toFixed(n))}const $n=_e.forwardRef((t,e)=>{const n=ot.c(125);let r,a,i,o,c,d,p,m,u,f,b,x,y;n[0]!==t?({value:y,onValueChange:p,min:u,max:f,step:b,className:r,containerClassName:a,onBlur:c,disabled:i,fallbackValue:o,onClear:d,emptyLabel:x,...m}=t,n[0]=t,n[1]=r,n[2]=a,n[3]=i,n[4]=o,n[5]=c,n[6]=d,n[7]=p,n[8]=m,n[9]=u,n[10]=f,n[11]=b,n[12]=x,n[13]=y):(r=n[1],a=n[2],i=n[3],o=n[4],c=n[5],d=n[6],p=n[7],m=n[8],u=n[9],f=n[10],b=n[11],x=n[12],y=n[13]);const g=u===void 0?-1/0:u,h=f===void 0?1/0:f,j=b===void 0?1:b,v=x===void 0?"—":x,{t:C}=ft();let k;n[14]!==y?(k=()=>y===void 0?"":String(y),n[14]=y,n[15]=k):k=n[15];const[w,N]=_e.useState(k),{isMobile:I}=ln(),T=_e.useRef(!1),P=_e.useRef(null);let D;n[16]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{if(typeof document>"u"||typeof window>"u")return;P.current?.();const ke=je=>{je.preventDefault(),je.stopPropagation(),je.stopImmediatePropagation?.(),P.current?.()},X=window.setTimeout(()=>{P.current?.()},700),ae=()=>{window.clearTimeout(X),document.removeEventListener("click",ke,!0),P.current=null};P.current=ae,document.addEventListener("click",ke,!0)},n[16]=D):D=n[16];const S=D;let M,E;n[17]===Symbol.for("react.memo_cache_sentinel")?(M=()=>()=>{P.current?.()},E=[],n[17]=M,n[18]=E):(M=n[17],E=n[18]),_e.useEffect(M,E);let R,V;n[19]!==y?(V=()=>{N(y===void 0?"":String(y))},R=[y],n[19]=y,n[20]=R,n[21]=V):(R=n[20],V=n[21]),_e.useEffect(V,R);let B;e:{if(y!==void 0){B=y;break e}if(o!==void 0){B=o;break e}if(Number.isFinite(g)){B=g;break e}B=0}const $=B;let O;n[22]!==h||n[23]!==g||n[24]!==p||n[25]!==j?(O=ke=>{const X=kp(ke,g,h);p(Cp(X,j))},n[22]=h,n[23]=g,n[24]=p,n[25]=j,n[26]=O):O=n[26];const _=O;let q;n[27]!==_||n[28]!==d?(q=ke=>{const X=ke.target.value;if(N(X),X.trim()===""){d?.();return}const ae=Number(X);Number.isFinite(ae)&&_(ae)},n[27]=_,n[28]=d,n[29]=q):q=n[29];const L=q;let J;n[30]!==w||n[31]!==h||n[32]!==g||n[33]!==c||n[34]!==d||n[35]!==p||n[36]!==j||n[37]!==y?(J=ke=>{if(w.trim()===""){d||N(y===void 0?"":String(y)),c?.(ke);return}const X=Number(w);if(!Number.isFinite(X))N(y===void 0?"":String(y));else{const ae=kp(X,g,h),je=Cp(ae,j);je!==y&&p(je),N(String(je))}c?.(ke)},n[30]=w,n[31]=h,n[32]=g,n[33]=c,n[34]=d,n[35]=p,n[36]=j,n[37]=y,n[38]=J):J=n[38];const Z=J,ie=!!(i||$>=h),ne=!!(i||$<=g);let me;n[39]!==$||n[40]!==_||n[41]!==ne||n[42]!==j?(me=()=>{ne||_($-j)},n[39]=$,n[40]=_,n[41]=ne,n[42]=j,n[43]=me):me=n[43];const pe=me;let G;n[44]!==$||n[45]!==_||n[46]!==ie||n[47]!==j?(G=()=>{ie||_($+j)},n[44]=$,n[45]=_,n[46]=ie,n[47]=j,n[48]=G):G=n[48];const K=G;let Q;if(n[49]!==r||n[50]!==a||n[51]!==ne||n[52]!==w||n[53]!==v||n[54]!==pe||n[55]!==K||n[56]!==ie||n[57]!==I||n[58]!==C||n[59]!==y){Q=Symbol.for("react.early_return_sentinel");e:{const ke=ae=>je=>{je.preventDefault(),je.stopPropagation(),T.current=!0,S(),ae()},X=ae=>je=>{if(T.current){T.current=!1,je.preventDefault(),je.stopPropagation();return}ae()};if(I){let ae;n[61]!==a?(ae=ye("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]=ae):ae=n[62];let je;n[63]!==C?(je=C("numberInput.actions.decreaseAria"),n[63]=C,n[64]=je):je=n[64];const le=ke(pe),Ne=X(pe),Me=!ne&&"active:bg-interactive-hover";let Ve;n[65]!==Me?(Ve=ye("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",Me),n[65]=Me,n[66]=Ve):Ve=n[66];let we;n[67]===Symbol.for("react.memo_cache_sentinel")?(we=s.jsx(A,{name:"subtract",className:"block h-4 w-4"}),n[67]=we):we=n[67];const ee=s.jsx("button",{type:"button","aria-label":je,disabled:ne,onTouchStart:le,onClick:Ne,className:Ve,children:we});let F;n[68]!==r?(F=ye("flex h-full min-w-0 w-14 items-center justify-center bg-transparent px-1.5","text-center text-[16px] leading-none text-foreground [font-variant-numeric:tabular-nums]",r),n[68]=r,n[69]=F):F=n[69];const U=y===void 0?v:w;let oe;n[70]!==F||n[71]!==U?(oe=s.jsx("div",{className:F,"aria-live":"polite",children:U}),n[70]=F,n[71]=U,n[72]=oe):oe=n[72];let Te;n[73]!==C?(Te=C("numberInput.actions.increaseAria"),n[73]=C,n[74]=Te):Te=n[74];const Oe=ke(K),Pe=X(K),z=!ie&&"active:bg-interactive-hover";let De;n[75]!==z?(De=ye("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",z),n[75]=z,n[76]=De):De=n[76];let Qe;n[77]===Symbol.for("react.memo_cache_sentinel")?(Qe=s.jsx(A,{name:"add",className:"block h-4 w-4"}),n[77]=Qe):Qe=n[77];const et=s.jsx("button",{type:"button","aria-label":Te,disabled:ie,onTouchStart:Oe,onClick:Pe,className:De,children:Qe});let Ze;n[78]!==ae||n[79]!==ee||n[80]!==oe||n[81]!==et?(Ze=s.jsxs("div",{className:ae,children:[ee,oe,et]}),n[78]=ae,n[79]=ee,n[80]=oe,n[81]=et,n[82]=Ze):Ze=n[82],Q=Ze;break e}}n[49]=r,n[50]=a,n[51]=ne,n[52]=w,n[53]=v,n[54]=pe,n[55]=K,n[56]=ie,n[57]=I,n[58]=C,n[59]=y,n[60]=Q}else Q=n[60];if(Q!==Symbol.for("react.early_return_sentinel"))return Q;let W;n[83]!==a?(W=ye("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]=W):W=n[84];let de;n[85]!==C?(de=C("numberInput.actions.decreaseAria"),n[85]=C,n[86]=de):de=n[86];let ge;n[87]!==$||n[88]!==_||n[89]!==j?(ge=()=>_($-j),n[87]=$,n[88]=_,n[89]=j,n[90]=ge):ge=n[90];let ve,te;n[91]===Symbol.for("react.memo_cache_sentinel")?(ve=ye("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"),te=s.jsx(A,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=ve,n[92]=te):(ve=n[91],te=n[92]);let he;n[93]!==ne||n[94]!==de||n[95]!==ge?(he=s.jsx("button",{type:"button","aria-label":de,disabled:ne,onClick:ge,className:ve,children:te}),n[93]=ne,n[94]=de,n[95]=ge,n[96]=he):he=n[96];const ce=m.inputMode??"numeric";let xe;n[97]!==r?(xe=ye("h-full min-w-0 w-14 bg-transparent px-1.5 text-center typography-ui-label leading-none text-foreground [font-variant-numeric:tabular-nums]","placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground","appearance-none outline-none [appearance:textfield] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","disabled:pointer-events-none disabled:cursor-not-allowed",r),n[97]=r,n[98]=xe):xe=n[98];let se;n[99]!==i||n[100]!==w||n[101]!==Z||n[102]!==L||n[103]!==m||n[104]!==e||n[105]!==ce||n[106]!==xe?(se=s.jsx("input",{...m,ref:e,type:"text",inputMode:ce,value:w,onChange:L,onBlur:Z,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:xe}),n[99]=i,n[100]=w,n[101]=Z,n[102]=L,n[103]=m,n[104]=e,n[105]=ce,n[106]=xe,n[107]=se):se=n[107];let ue;n[108]!==C?(ue=C("numberInput.actions.increaseAria"),n[108]=C,n[109]=ue):ue=n[109];let Y;n[110]!==$||n[111]!==_||n[112]!==j?(Y=()=>_($+j),n[110]=$,n[111]=_,n[112]=j,n[113]=Y):Y=n[113];let Se,fe;n[114]===Symbol.for("react.memo_cache_sentinel")?(Se=ye("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"),fe=s.jsx(A,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=Se,n[115]=fe):(Se=n[114],fe=n[115]);let Ce;n[116]!==ie||n[117]!==ue||n[118]!==Y?(Ce=s.jsx("button",{type:"button","aria-label":ue,disabled:ie,onClick:Y,className:Se,children:fe}),n[116]=ie,n[117]=ue,n[118]=Y,n[119]=Ce):Ce=n[119];let Ie;return n[120]!==W||n[121]!==he||n[122]!==se||n[123]!==Ce?(Ie=s.jsxs("div",{className:W,children:[he,se,Ce]}),n[120]=W,n[121]=he,n[122]=se,n[123]=Ce,n[124]=Ie):Ie=n[124],Ie});$n.displayName="NumberInput";const Ip=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],hl=t=>t==="allow"||t==="ask"||t==="deny",La=(t,e)=>`${t}::${e}`,Qa=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&hl(n.action)&&e.set(La(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},Wo=t=>{const e=new Map;for(const n of Qa(t))e.set(La(n.permission,n.pattern),n);return e},Pp=t=>[...t].sort((e,n)=>{const r=e.permission.localeCompare(n.permission);return r!==0?r:e.pattern.localeCompare(n.pattern)}),gk=(t,e)=>{const n=Pp(Qa(t)),r=Pp(Qa(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})},xk=t=>t.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",bk=(t,e)=>Qa(t).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),yk=t=>{if(hl(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(hl(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))hl(i)&&e.push({permission:n,pattern:a,action:i})}return e},vk=(t,e)=>{const n=Qa(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},wk=()=>{const{t}=ft(),{isMobile:e}=ln(),{selectedAgentName:n,getAgentByName:r,createAgent:a,updateAgent:i,agents:o,agentDraft:c,setAgentDraft:d}=ji(Gn(ae=>({selectedAgentName:ae.selectedAgentName,getAgentByName:ae.getAgentByName,createAgent:ae.createAgent,updateAgent:ae.updateAgent,agents:ae.agents,agentDraft:ae.agentDraft,setAgentDraft:ae.setAgentDraft}))),p=n?r(n):null,m=!!(c&&c.name===n&&!p),[u,f]=l.useState(""),[b,x]=l.useState("user"),[y,g]=l.useState(""),[h,j]=l.useState("subagent"),[v,C]=l.useState(""),[k,w]=l.useState(void 0),[N,I]=l.useState(void 0),[T,P]=l.useState(""),[D,S]=l.useState("allow"),[M,E]=l.useState([]),[R,V]=l.useState([]),[B,$]=l.useState(""),[O,_]=l.useState("*"),[q,L]=l.useState(!1),[J,Z]=l.useState(!1),ie=l.useRef(null),ne=Ws(ae=>ae.currentDirectory??null),[me,pe]=l.useState([]),G=Sh(ae=>ae.permission);l.useEffect(()=>{let ae=!1;return(async()=>{const le=await on.listToolIds({directory:ne});if(ae)return;const Ne=new Set(["write","patch","multiedit"]),Me=le.map(Ve=>typeof Ve=="string"?Ve.trim():"").filter(Boolean).filter(Ve=>Ve!=="*").filter(Ve=>Ve!=="invalid").filter(Ve=>!Ne.has(Ve));pe(Array.from(new Set(Me)).sort((Ve,we)=>Ve.localeCompare(we)))})(),()=>{ae=!0}},[ne]);const K=l.useMemo(()=>{const ae=new Set;for(const je of o){const le=Qa(Array.isArray(je.permission)?je.permission:[]);for(const Ne of le)Ne.permission&&Ne.permission!=="*"&&Ne.permission!=="invalid"&&ae.add(Ne.permission)}for(const je of Object.values(G))for(const le of je){const Ne=le.permission?.trim();Ne&&Ne!=="invalid"&&ae.add(Ne)}for(const je of me)ae.add(je);return Array.from(ae).sort((je,le)=>je.localeCompare(le))},[o,G,me]),Q=l.useMemo(()=>Wo(M),[M]),W=l.useMemo(()=>Wo(R),[R]),de=l.useCallback(ae=>W.get(La(ae,"*"))?.action,[W]),ge=l.useCallback(ae=>R.filter(je=>je.permission===ae&&je.pattern!=="*").sort((je,le)=>je.pattern.localeCompare(le.pattern)),[R]),ve=l.useMemo(()=>{const ae=new Set;for(const je of Ip)ae.add(je);for(const je of K)ae.add(je);return Array.from(ae).sort((je,le)=>je.localeCompare(le))},[K]),te=l.useCallback(ae=>{const je=ae==="*"?D:de(ae)??D,le=ge(ae),Ne=!1,Me=le.reduce((we,ee)=>(we[ee.action]=(we[ee.action]??0)+1,we),{allow:0,ask:0,deny:0}),Ve=["allow","ask","deny"].filter(we=>Me[we]>0).map(we=>`${Me[we]} ${we}`).join(", ");return{defaultAction:je,patternRulesCount:le.length,patternSummary:Ve,hasDefaultHint:Ne}},[ge,de,D]),he=l.useCallback(ae=>t(ae==="allow"?"settings.common.permission.allow":ae==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[t]),ce=l.useCallback(ae=>ae==="global"?t("settings.common.scope.global"):he(ae),[he,t]),xe=l.useMemo(()=>{const ae=new Set;for(const je of Ip)ae.add(je);for(const je of K)ae.add(je);return Array.from(ae).sort((je,le)=>je.localeCompare(le))},[K]),se=l.useCallback((ae,je,le)=>{V(Ne=>{const Me=Wo(Ne);return Me.set(La(ae,je),{permission:ae,pattern:je,action:le}),Array.from(Me.values())})},[]),ue=l.useCallback((ae,je)=>{V(le=>{const Ne=Wo(le);return Ne.delete(La(ae,je)),Array.from(Ne.values())})},[]),Y=l.useCallback((ae,je)=>{const le=Q.get(La(ae,je));if(le){se(ae,je,le.action);return}ue(ae,je)},[Q,ue,se]),Se=l.useCallback((ae,je,le)=>{se(ae,je,le)},[se]),fe=l.useCallback(ae=>{S(ae),V(je=>je.filter(le=>!(le.pattern==="*"&&le.action===ae)))},[]),Ce=l.useCallback(ae=>{const je=B.trim();if(!je){H.error(t("settings.agents.page.toast.permissionNameRequired"));return}const le=O.trim()||"*";if(je==="*"&&le==="*"){fe(ae),$(""),_("*");return}le==="*"&&je!=="*"&&ae===D?ue(je,"*"):se(je,le,ae),$(""),_("*")},[D,B,O,ue,fe,t,se]),Ie=l.useCallback(ae=>ae==="*"?t("settings.agents.page.permissions.defaultLabel"):ae==="webfetch"?"WebFetch":ae==="websearch"?"WebSearch":ae==="codesearch"?"CodeSearch":ae==="doom_loop"?"Doom Loop":ae==="external_directory"?"External Directory":ae==="todowrite"?"TodoWrite":ae==="todoread"?"TodoRead":ae.split(/[_-]+/g).filter(Boolean).map(je=>je.charAt(0).toUpperCase()+je.slice(1)).join(" "),[t]);l.useEffect(()=>{$(""),_("*");const ae=je=>{const le=Qa(je),Ne=xk(le),Me=bk(le,Ne);return S(Ne),E(Me),V(Me),{global:Ne,rules:Me}};if(m&&c){const je=c.name||"",le=c.scope||"user",Ne=c.description||"",Me=c.mode||"subagent",Ve=c.model||"",we=c.temperature,ee=c.top_p,F=c.prompt||"";f(je),x(le),g(Ne),j(Me),C(Ve),w(we),I(ee),P(F);const U=yk(c.permission),oe=ae(U);ie.current={draftName:je,draftScope:le,description:Ne,mode:Me,model:Ve,temperature:we,topP:ee,prompt:F,globalPermission:oe.global,permissionRules:oe.rules};return}if(p&&n===p.name){const je=p.description||"",le=p.mode||"subagent",Ne=p.model?.providerID&&p.model?.modelID?`${p.model.providerID}/${p.model.modelID}`:"",Me=p.temperature,Ve=p.topP,we=p.prompt||"";g(je),j(le),C(Ne),w(Me),I(Ve),P(we);const ee=ae(Array.isArray(p.permission)?p.permission:[]);ie.current={draftName:"",draftScope:"user",description:je,mode:le,model:Ne,temperature:Me,topP:Ve,prompt:we,globalPermission:ee.global,permissionRules:ee.rules}}},[c,m,p,n]);const ke=l.useMemo(()=>{const ae=ie.current;return ae?!!(m&&(u!==ae.draftName||b!==ae.draftScope)||y!==ae.description||h!==ae.mode||v!==ae.model||k!==ae.temperature||N!==ae.topP||T!==ae.prompt||D!==ae.globalPermission||!gk(R,ae.permissionRules)):!1},[y,u,b,D,m,h,v,R,T,k,N]),X=async()=>{const ae=m?u.trim().replace(/\s+/g,"-"):n?.trim();if(!ae){H.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&o.some(je=>je.name===ae)){H.error(t("settings.agents.sidebar.toast.agentExists"));return}Z(!0);try{const je=v.trim(),le=vk(D,R),Ne={name:ae,description:y.trim()||void 0,mode:h,model:je===""?null:je,temperature:k,top_p:N,prompt:T.trim()||void 0,permission:le,scope:m?b:void 0};let Me;m?(Me=await a(Ne),Me&&d(null)):Me=await i(ae,Ne),Me?H.success(t(m?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):H.error(t(m?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(je){console.error("Error saving agent:",je);const le=je instanceof Error&&je.message?je.message:t("settings.agents.page.toast.saveUnexpectedError");H.error(le)}finally{Z(!1)}};return n?s.jsx(Ss,{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(Lt,{value:u,onChange:ae=>f(ae.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(as,{value:b,onValueChange:ae=>x(ae),children:[s.jsx(is,{className:"w-fit min-w-[100px]",children:s.jsx(fs,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(os,{align:"end",children:[s.jsx(Mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Mt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(un,{value:y,onChange:ae=>g(ae.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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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(be,{variant:"chip",size:"xs","aria-pressed":h==="primary",onClick:()=>j("primary"),className:"!font-normal",children:t("settings.agents.page.mode.primary")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":h==="subagent",onClick:()=>j("subagent"),className:"!font-normal",children:t("settings.agents.page.mode.subagent")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":h==="all",onClick:()=>j("all"),className:"!font-normal",children:t("settings.agents.page.mode.all")})]})]})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.modelParameters")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.overrideModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(Io,{providerId:Ii(v)?.providerId??"",modelId:Ii(v)?.modelId??"",onChange:(ae,je)=>{C(ae&&je?`${ae}/${je}`:"")}})})]}),s.jsxs("div",{className:ye("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:ye("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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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:ye("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx($n,{value:k,fallbackValue:.7,onValueChange:w,onClear:()=>w(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),k!==void 0&&s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>w(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:ye("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:ye("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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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:ye("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx($n,{value:N,fallbackValue:.9,onValueChange:I,onClear:()=>I(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),N!==void 0&&s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>I(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.systemPrompt")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(un,{value:T,onChange:ae=>P(ae.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-4",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.toolPermissions")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>L(ae=>!ae),children:t(q?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),q?s.jsxs("div",{className:"space-y-6 px-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4 py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.permissions.globalDefault")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:"*"})]}),s.jsxs(as,{value:D,onValueChange:ae=>fe(ae),children:[s.jsx(is,{className:"w-[100px]",children:s.jsx(fs,{children:he(D)})}),s.jsxs(os,{children:[s.jsx(Mt,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Mt,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Mt,{value:"deny",children:t("settings.common.permission.deny")})]})]})]}),s.jsx("div",{className:"space-y-4",children:ve.filter(ae=>ae!=="*").map(ae=>{const je=Ie(ae),{defaultAction:le,patternRulesCount:Ne}=te(ae),Me=de(ae),Ve=Me??"global",we=ge(ae),ee=["allow","ask","deny"].filter(F=>F!==D);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:je}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:ae})]}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:Ne>0?t("settings.agents.page.permissions.globalSummary",{summary:le}):le})]}),s.jsxs("div",{className:"space-y-1 pl-2 mt-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t("settings.agents.page.permissions.pattern")}),s.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:"*"}),Me&&s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>Y(ae,"*"),className:"px-1.5 py-0 h-5",children:s.jsx(A,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(as,{value:Ve,onValueChange:F=>{if(F==="global"){ue(ae,"*");return}se(ae,"*",F)},children:[s.jsx(is,{className:"w-[90px]",children:s.jsx(fs,{children:ce(Ve)})}),s.jsxs(os,{children:[s.jsx(Mt,{value:"global",children:t("settings.common.scope.global")}),ee.map(F=>s.jsx(Mt,{value:F,className:"capitalize",children:he(F)},F))]})]})]}),we.map(F=>{const U=La(F.permission,F.pattern),oe=Q.get(U),Te=!oe,Oe=!!(oe&&oe.action!==F.action);return s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5 border-t border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t("settings.agents.page.permissions.pattern")}),s.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:F.pattern}),Te&&s.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:t("settings.common.badge.new")}),Oe&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:t("settings.common.badge.modified")}),(Te||Oe)&&s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>Te?ue(F.permission,F.pattern):Y(F.permission,F.pattern),className:"px-1.5 py-0 h-5",children:s.jsx(A,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(as,{value:F.action,onValueChange:Pe=>Se(F.permission,F.pattern,Pe),children:[s.jsx(is,{className:"w-[90px]",children:s.jsx(fs,{children:he(F.action)})}),s.jsxs(os,{children:[s.jsx(Mt,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Mt,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Mt,{value:"deny",children:t("settings.common.permission.deny")})]})]})]},U)})]})]},ae)})}),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(as,{value:B,onValueChange:$,children:[s.jsx(is,{className:"w-full sm:w-[160px]",children:B?s.jsx("span",{className:"truncate",children:Ie(B)}):s.jsx("span",{className:"text-muted-foreground",children:t("settings.agents.page.permissions.permissionPlaceholder")})}),s.jsx(os,{children:xe.map(ae=>s.jsx(Mt,{value:ae,children:s.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:s.jsx("span",{children:Ie(ae)})})},ae))})]}),s.jsx(Lt,{value:O,onChange:ae=>_(ae.target.value),placeholder:t("settings.agents.page.permissions.patternPlaceholder"),className:"h-7 flex-1 font-mono text-xs"}),s.jsxs("div",{className:"flex gap-1",children:[s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ce("allow"),children:t("settings.common.permission.allow")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ce("ask"),children:t("settings.common.permission.ask")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ce("deny"),children:t("settings.common.permission.deny")})]})]})]})]}):s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:ve.map((ae,je)=>{const{defaultAction:le,patternRulesCount:Ne,patternSummary:Me,hasDefaultHint:Ve}=te(ae),we=Ie(ae),ee=Ve?`${le} (env blocked)`:le;return s.jsxs("div",{className:ye("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",je>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:we}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:ae})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[Ne>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:ee})}):s.jsx("span",{className:ye("typography-micro capitalize px-1.5 py-0.5 rounded",ee==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":ee==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:ee}),Ne>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:Me})})]})]},ae)})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(be,{onClick:X,disabled:J||!ke,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(A,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})},jk="~/.config/opencode/AGENTS.md",Dg=async(t,e)=>{const n=await t.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},Nk=t=>t.length>0&&!t.endsWith(`
|
|
155
|
-
`)?`${t}
|
|
156
|
-
`:t,Ko={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Sk=(t,e)=>t==="custom"?e:ny(t),kk=t=>t==="custom"?"custom":kh(t)?t:"concise",Ap={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"},Dp=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 Dg(n,e))},Ck=()=>{const{t}=ft(),[e,n]=l.useState(""),[r,a]=l.useState(Ko.responseStyleEnabled),[i,o]=l.useState(Ko.responseStylePreset),[c,d]=l.useState(Ko.responseStyleCustomInstructions),[p,m]=l.useState(!0),[u,f]=l.useState(!1),[b,x]=l.useState(""),y=l.useRef(null);l.useEffect(()=>{const v=new AbortController;return(async()=>{try{const[k,w]=await Promise.all([fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:v.signal}),fetch("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:v.signal})]);let N=Ko;if(k.ok){const I=await k.json();N={...N,responseStyleEnabled:I.responseStyleEnabled===!0,responseStylePreset:kk(I.responseStylePreset),responseStyleCustomInstructions:typeof I.responseStyleCustomInstructions=="string"?I.responseStyleCustomInstructions:""},typeof I.globalBehaviorPrompt=="string"&&(N={...N,prompt:I.globalBehaviorPrompt})}if(!N.prompt.trim()&&w.ok){const I=await w.json();typeof I.content=="string"&&(N={...N,prompt:I.content})}n(N.prompt),a(N.responseStyleEnabled),o(N.responseStylePreset),d(N.responseStyleCustomInstructions),x(N.prompt),y.current={enabled:N.responseStyleEnabled,preset:N.responseStylePreset,custom:N.responseStyleCustomInstructions}}catch(k){k.name!=="AbortError"&&console.warn("Failed to load behavior settings:",k)}finally{m(!1)}})(),()=>v.abort()},[]),l.useEffect(()=>{if(p)return;const v=y.current;if(v&&v.enabled===r&&v.preset===i&&v.custom===c)return;const C={enabled:r,preset:i,custom:c},k=setTimeout(async()=>{try{await Dp({responseStyleEnabled:C.enabled,responseStylePreset:C.preset,responseStyleCustomInstructions:C.custom},t("settings.behavior.page.toast.saveFailed")),y.current=C}catch(w){const N=w instanceof Error?w.message:t("settings.behavior.page.toast.saveFailed");H.error(N)}},400);return()=>clearTimeout(k)},[r,i,c,p,t]);const g=Sk(i,c),h=e!==b,j=async()=>{f(!0);try{const v=Nk(e),C=await fetch("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:v})});if(!C.ok)throw new Error(await Dg(C,t("settings.behavior.page.toast.saveFailed")));await Dp({globalBehaviorPrompt:v},t("settings.behavior.page.toast.saveFailed")),n(v),x(v),H.success(t("settings.behavior.page.toast.saved"))}catch(v){console.error("Failed to save behavior:",v);const C=v instanceof Error?v.message:t("settings.behavior.page.toast.saveFailed");H.error(C)}finally{f(!1)}};return s.jsx(Ss,{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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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:jk})})]})})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsx(un,{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(be,{onClick:j,disabled:u||!h||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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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(vs,{checked:r,onChange:a,disabled:p,ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),t("settings.behavior.page.responseStyle.enable")]}),s.jsxs(as,{value:i,onValueChange:v=>o(v),disabled:p||!r,children:[s.jsx(is,{className:"w-full sm:w-56",size:"lg",children:s.jsx(fs,{children:v=>v==="custom"?t("settings.behavior.page.responseStyle.option.custom"):kh(v)?t(Ap[v]):null})}),s.jsxs(os,{children:[sy.map(v=>s.jsx(Mt,{value:v,children:t(Ap[v])},v)),s.jsx(Mt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]}),s.jsx(un,{value:g,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"})]})]})]})})},Ik=t=>{const e=ot.c(169),{onItemSelect:n}=t,{t:r}=ft(),[a,i]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(null),[f,b]=l.useState(!1),[x,y]=l.useState(null),{selectedCommandName:g,commands:h,setSelectedCommand:j,setCommandDraft:v,createCommand:C,deleteCommand:k,loadCommands:w}=ru(Gn(Pk)),N=ha(Ak),I=ha(Dk);let T,P;e[0]!==w||e[1]!==I?(T=()=>{w(),I()},P=[w,I],e[0]=w,e[1]=I,e[2]=T,e[3]=P):(T=e[2],P=e[3]),l.useEffect(T,P);let D;e[4]!==N?(D=new Set(N.map(Tk)),e[4]=N,e[5]=D):D=e[5];const S=D;let M;if(e[6]!==h||e[7]!==S){let Ge;e[9]!==S?(Ge=at=>!S.has(at.name),e[9]=S,e[10]=Ge):Ge=e[10],M=h.filter(Ge),e[6]=h,e[7]=S,e[8]=M}else M=e[8];const E=M;let R,V;e[11]!==g||e[12]!==j||e[13]!==S?(R=()=>{g&&S.has(g)&&j(null)},V=[g,j,S],e[11]=g,e[12]=j,e[13]=S,e[14]=R,e[15]=V):(R=e[14],V=e[15]),l.useEffect(R,V);let B;e[16]!==h||e[17]!==n||e[18]!==v||e[19]!==j?(B=()=>{let Ge="new-command",at=1;for(;h.some(Ae=>Ae.name===Ge);)Ge=`new-command-${at}`,at++;v({name:Ge,scope:"user"}),j(Ge),n?.()},e[16]=h,e[17]=n,e[18]=v,e[19]=j,e[20]=B):B=e[20];const $=B;let O;e[21]!==r?(O=async Ge=>{if(gi(Ge)){H.error(r("settings.commands.sidebar.toast.builtInCannotDelete"));return}p(Ge),u("delete")},e[21]=r,e[22]=O):O=e[22];const _=O;let q;e[23]===Symbol.for("react.memo_cache_sentinel")?(q=async Ge=>{gi(Ge)&&(p(Ge),u("reset"))},e[23]=q):q=e[23];const L=q;let J;e[24]===Symbol.for("react.memo_cache_sentinel")?(J=()=>{p(null),u(null)},e[24]=J):J=e[24];const Z=J;let ie;e[25]!==d||e[26]!==m||e[27]!==k||e[28]!==r?(ie=async()=>{if(!d||!m)return;b(!0),await k(d.name)?(m==="delete"?H.success(r("settings.commands.sidebar.toast.commandDeleted",{name:d.name})):H.success(r("settings.commands.sidebar.toast.commandReset",{name:d.name})),Z()):m==="delete"?H.error(r("settings.commands.sidebar.toast.deleteFailed")):H.error(r("settings.commands.sidebar.toast.resetFailed")),b(!1)},e[25]=d,e[26]=m,e[27]=k,e[28]=r,e[29]=ie):ie=e[29];const ne=ie;let me;e[30]!==h||e[31]!==v||e[32]!==j?(me=Ge=>{const at=Ge.name;let Ae=1,Le=`${at}-copy`;for(;h.some(ze=>ze.name===Le);)Ae++,Le=`${at}-copy-${Ae}`;v({name:Le,scope:Ge.scope||"user",description:Ge.description,template:Ge.template,agent:Ge.agent,model:Ge.model}),j(Le)},e[30]=h,e[31]=v,e[32]=j,e[33]=me):me=e[33];const pe=me;let G;e[34]===Symbol.for("react.memo_cache_sentinel")?(G=Ge=>{c(Ge.name),i(Ge)},e[34]=G):G=e[34];const K=G;let Q;e[35]!==h||e[36]!==C||e[37]!==k||e[38]!==a||e[39]!==o||e[40]!==j||e[41]!==r?(Q=async()=>{if(!a)return;const Ge=o.trim().replace(/\s+/g,"-");if(!Ge){H.error(r("settings.commands.sidebar.toast.commandNameRequired"));return}if(Ge===a.name){i(null);return}if(h.some(Ae=>Ae.name===Ge)){H.error(r("settings.commands.sidebar.toast.commandExists"));return}await C({name:Ge,description:a.description,template:a.template,agent:a.agent,model:a.model})?await k(a.name)?(H.success(`Command renamed to "${Ge}"`),j(Ge)):H.error(r("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):H.error(r("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=h,e[36]=C,e[37]=k,e[38]=a,e[39]=o,e[40]=j,e[41]=r,e[42]=Q):Q=e[42];const W=Q;let de,ge,ve,te,he,ce;if(e[43]!==E||e[44]!==$||e[45]!==_||e[46]!==pe||e[47]!==n||e[48]!==x||e[49]!==g||e[50]!==j||e[51]!==r){const Ge=E.filter(gi),at=E.filter(Ek);e[58]===Symbol.for("react.memo_cache_sentinel")?(he=ye("flex h-full flex-col","bg-background"),e[58]=he):he=e[58];let Ae;e[59]!==r?(Ae=r("settings.commands.sidebar.title"),e[59]=r,e[60]=Ae):Ae=e[60];let Le;e[61]!==Ae?(Le=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:Ae}),e[61]=Ae,e[62]=Le):Le=e[62];let ze;e[63]===Symbol.for("react.memo_cache_sentinel")?(ze=s.jsx(Po,{className:"mb-3"}),e[63]=ze):ze=e[63];let Ke;e[64]!==E.length||e[65]!==r?(Ke=r("settings.commands.sidebar.total",{count:E.length}),e[64]=E.length,e[65]=r,e[66]=Ke):Ke=e[66];let lt;e[67]!==Ke?(lt=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Ke}),e[67]=Ke,e[68]=lt):lt=e[68];let xt;e[69]===Symbol.for("react.memo_cache_sentinel")?(xt=s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[69]=xt):xt=e[69];let dt;e[70]!==$?(dt=s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:$,children:xt}),e[70]=$,e[71]=dt):dt=e[71];let ut;e[72]!==lt||e[73]!==dt?(ut=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[lt,dt]}),e[72]=lt,e[73]=dt,e[74]=ut):ut=e[74],e[75]!==Le||e[76]!==ut?(ce=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Le,ze,ut]}),e[75]=Le,e[76]=ut,e[77]=ce):ce=e[77],de=Ss,ge="flex-1 min-h-0",ve="space-y-1 px-3 py-2",te=E.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(A,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[Ge.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.commands.sidebar.section.builtIn")}),[...Ge].sort(Mk).map(Nt=>s.jsx(Tp,{command:Nt,isSelected:g===Nt.name,onSelect:()=>{j(Nt.name),n?.()},onReset:()=>L(Nt),onDuplicate:()=>pe(Nt),isMenuOpen:x===Nt.name,onMenuOpenChange:ts=>y(ts?Nt.name:null)},Nt.name))]}),at.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")}),[...at].sort(Rk).map(Nt=>s.jsx(Tp,{command:Nt,isSelected:g===Nt.name,onSelect:()=>{j(Nt.name),n?.()},onRename:()=>K(Nt),onDelete:()=>_(Nt),onDuplicate:()=>pe(Nt),isMenuOpen:x===Nt.name,onMenuOpenChange:ts=>y(ts?Nt.name:null)},Nt.name))]})]}),e[43]=E,e[44]=$,e[45]=_,e[46]=pe,e[47]=n,e[48]=x,e[49]=g,e[50]=j,e[51]=r,e[52]=de,e[53]=ge,e[54]=ve,e[55]=te,e[56]=he,e[57]=ce}else de=e[52],ge=e[53],ve=e[54],te=e[55],he=e[56],ce=e[57];let xe;e[78]!==de||e[79]!==ge||e[80]!==ve||e[81]!==te?(xe=s.jsx(de,{outerClassName:ge,className:ve,children:te}),e[78]=de,e[79]=ge,e[80]=ve,e[81]=te,e[82]=xe):xe=e[82];const se=d!==null&&m!==null;let ue;e[83]!==f?(ue=Ge=>{!Ge&&!f&&Z()},e[83]=f,e[84]=ue):ue=e[84];let Y;e[85]!==m||e[86]!==r?(Y=r(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=r,e[87]=Y):Y=e[87];let Se;e[88]!==Y?(Se=s.jsx(ms,{children:Y}),e[88]=Y,e[89]=Se):Se=e[89];let fe;e[90]!==d?.name||e[91]!==m||e[92]!==r?(fe=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]=fe):fe=e[93];let Ce;e[94]!==fe?(Ce=s.jsx(Ns,{children:fe}),e[94]=fe,e[95]=Ce):Ce=e[95];let Ie;e[96]!==Se||e[97]!==Ce?(Ie=s.jsxs(hs,{children:[Se,Ce]}),e[96]=Se,e[97]=Ce,e[98]=Ie):Ie=e[98];let ke;e[99]!==r?(ke=r("settings.common.actions.cancel"),e[99]=r,e[100]=ke):ke=e[100];let X;e[101]!==f||e[102]!==ke?(X=s.jsx(be,{size:"sm",variant:"ghost",onClick:Z,disabled:f,children:ke}),e[101]=f,e[102]=ke,e[103]=X):X=e[103];let ae;e[104]!==m||e[105]!==r?(ae=r(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=r,e[106]=ae):ae=e[106];let je;e[107]!==ne||e[108]!==f||e[109]!==ae?(je=s.jsx(be,{size:"sm",onClick:ne,disabled:f,children:ae}),e[107]=ne,e[108]=f,e[109]=ae,e[110]=je):je=e[110];let le;e[111]!==X||e[112]!==je?(le=s.jsxs(_s,{children:[X,je]}),e[111]=X,e[112]=je,e[113]=le):le=e[113];let Ne;e[114]!==Ie||e[115]!==le?(Ne=s.jsxs(ds,{className:"max-w-md",children:[Ie,le]}),e[114]=Ie,e[115]=le,e[116]=Ne):Ne=e[116];let Me;e[117]!==se||e[118]!==ue||e[119]!==Ne?(Me=s.jsx(us,{open:se,onOpenChange:ue,children:Ne}),e[117]=se,e[118]=ue,e[119]=Ne,e[120]=Me):Me=e[120];const Ve=a!==null;let we;e[121]===Symbol.for("react.memo_cache_sentinel")?(we=Ge=>!Ge&&i(null),e[121]=we):we=e[121];let ee;e[122]!==r?(ee=r("settings.commands.sidebar.renameDialog.title"),e[122]=r,e[123]=ee):ee=e[123];let F;e[124]!==ee?(F=s.jsx(ms,{children:ee}),e[124]=ee,e[125]=F):F=e[125];const U=a?.name??"";let oe;e[126]!==r||e[127]!==U?(oe=r("settings.commands.sidebar.renameDialog.description",{name:U}),e[126]=r,e[127]=U,e[128]=oe):oe=e[128];let Te;e[129]!==oe?(Te=s.jsx(Ns,{children:oe}),e[129]=oe,e[130]=Te):Te=e[130];let Oe;e[131]!==F||e[132]!==Te?(Oe=s.jsxs(hs,{children:[F,Te]}),e[131]=F,e[132]=Te,e[133]=Oe):Oe=e[133];let Pe;e[134]===Symbol.for("react.memo_cache_sentinel")?(Pe=Ge=>c(Ge.target.value),e[134]=Pe):Pe=e[134];let z;e[135]!==r?(z=r("settings.commands.sidebar.renameDialog.placeholder"),e[135]=r,e[136]=z):z=e[136];let De;e[137]!==W?(De=Ge=>{Ge.key==="Enter"&&W()},e[137]=W,e[138]=De):De=e[138];let Qe;e[139]!==o||e[140]!==z||e[141]!==De?(Qe=s.jsx(Lt,{value:o,onChange:Pe,placeholder:z,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:De}),e[139]=o,e[140]=z,e[141]=De,e[142]=Qe):Qe=e[142];let et;e[143]===Symbol.for("react.memo_cache_sentinel")?(et=()=>i(null),e[143]=et):et=e[143];let Ze;e[144]!==r?(Ze=r("settings.common.actions.cancel"),e[144]=r,e[145]=Ze):Ze=e[145];let We;e[146]!==Ze?(We=s.jsx(be,{size:"sm",variant:"ghost",onClick:et,children:Ze}),e[146]=Ze,e[147]=We):We=e[147];let it;e[148]!==r?(it=r("settings.common.actions.rename"),e[148]=r,e[149]=it):it=e[149];let qe;e[150]!==W||e[151]!==it?(qe=s.jsx(be,{size:"sm",onClick:W,children:it}),e[150]=W,e[151]=it,e[152]=qe):qe=e[152];let st;e[153]!==We||e[154]!==qe?(st=s.jsxs(_s,{children:[We,qe]}),e[153]=We,e[154]=qe,e[155]=st):st=e[155];let Je;e[156]!==Oe||e[157]!==Qe||e[158]!==st?(Je=s.jsxs(ds,{children:[Oe,Qe,st]}),e[156]=Oe,e[157]=Qe,e[158]=st,e[159]=Je):Je=e[159];let Be;e[160]!==Ve||e[161]!==Je?(Be=s.jsx(us,{open:Ve,onOpenChange:we,children:Je}),e[160]=Ve,e[161]=Je,e[162]=Be):Be=e[162];let nt;return e[163]!==he||e[164]!==ce||e[165]!==xe||e[166]!==Me||e[167]!==Be?(nt=s.jsxs("div",{className:he,children:[ce,xe,Me,Be]}),e[163]=he,e[164]=ce,e[165]=xe,e[166]=Me,e[167]=Be,e[168]=nt):nt=e[168],nt},Tp=t=>{const e=ot.c(53),{command:n,isSelected:r,onSelect:a,onDelete:i,onReset:o,onRename:c,onDuplicate:d,isMenuOpen:p,onMenuOpenChange:m}=t,{t:u}=ft();let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=uo(),e[0]=f):f=e[0];const b=f,x=r?"bg-interactive-selection":"hover:bg-interactive-hover";let y;e[1]!==x?(y=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",x),e[1]=x,e[2]=y):y=e[2];let g;e[3]!==m?(g=b?void 0:$=>{$.preventDefault(),m(!0)},e[3]=m,e[4]=g):g=e[4];let h;e[5]!==n.name?(h=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[5]=n.name,e[6]=h):h=e[6];let j;e[7]!==n||e[8]!==u?(j=(n.scope||gi(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:gi(n)?u("settings.agents.sidebar.badge.system"):n.scope}),e[7]=n,e[8]=u,e[9]=j):j=e[9];let v;e[10]!==h||e[11]!==j?(v=s.jsxs("div",{className:"flex items-center gap-2",children:[h,j]}),e[10]=h,e[11]=j,e[12]=v):v=e[12];let C;e[13]!==n.description?(C=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[13]=n.description,e[14]=C):C=e[14];let k;e[15]!==a||e[16]!==v||e[17]!==C?(k=s.jsxs("button",{onClick:a,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[v,C]}),e[15]=a,e[16]=v,e[17]=C,e[18]=k):k=e[18];let w;e[19]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(Is,{asChild:!0,children:s.jsx(be,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[19]=w):w=e[19];let N;e[20]!==c||e[21]!==u?(N=c&&s.jsxs(_t,{onClick:$=>{$.stopPropagation(),c()},children:[s.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),e[20]=c,e[21]=u,e[22]=N):N=e[22];let I;e[23]!==d?(I=$=>{$.stopPropagation(),d()},e[23]=d,e[24]=I):I=e[24];let T;e[25]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(A,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[25]=T):T=e[25];let P;e[26]!==u?(P=u("settings.common.actions.duplicate"),e[26]=u,e[27]=P):P=e[27];let D;e[28]!==I||e[29]!==P?(D=s.jsxs(_t,{onClick:I,children:[T,P]}),e[28]=I,e[29]=P,e[30]=D):D=e[30];let S;e[31]!==o||e[32]!==u?(S=o&&s.jsxs(_t,{onClick:$=>{$.stopPropagation(),o()},children:[s.jsx(A,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),e[31]=o,e[32]=u,e[33]=S):S=e[33];let M;e[34]!==i||e[35]!==u?(M=i&&s.jsxs(_t,{onClick:$=>{$.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]}),e[34]=i,e[35]=u,e[36]=M):M=e[36];let E;e[37]!==N||e[38]!==D||e[39]!==S||e[40]!==M?(E=s.jsxs(Ps,{align:"end",className:"w-fit min-w-20",children:[N,D,S,M]}),e[37]=N,e[38]=D,e[39]=S,e[40]=M,e[41]=E):E=e[41];let R;e[42]!==p||e[43]!==m||e[44]!==E?(R=s.jsxs(As,{open:p,onOpenChange:m,children:[w,E]}),e[42]=p,e[43]=m,e[44]=E,e[45]=R):R=e[45];let V;e[46]!==R||e[47]!==k?(V=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[k,R]}),e[46]=R,e[47]=k,e[48]=V):V=e[48];let B;return e[49]!==V||e[50]!==y||e[51]!==g?(B=s.jsx("div",{className:y,onContextMenu:g,children:V}),e[49]=V,e[50]=y,e[51]=g,e[52]=B):B=e[52],B};function Pk(t){return{selectedCommandName:t.selectedCommandName,commands:t.commands,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function Ak(t){return t.skills}function Dk(t){return t.loadSkills}function Tk(t){return t.name}function Ek(t){return!gi(t)}function Mk(t,e){return t.name.localeCompare(e.name)}function Rk(t,e){return t.name.localeCompare(e.name)}const Fk=()=>{const{t}=ft(),{selectedCommandName:e,getCommandByName:n,createCommand:r,updateCommand:a,commands:i,commandDraft:o,setCommandDraft:c}=ru(Gn(D=>({selectedCommandName:D.selectedCommandName,getCommandByName:D.getCommandByName,createCommand:D.createCommand,updateCommand:D.updateCommand,commands:D.commands,commandDraft:D.commandDraft,setCommandDraft:D.setCommandDraft}))),d=e?n(e):null,p=!!(o&&o.name===e&&!d),[m,u]=l.useState(""),[f,b]=l.useState("user"),[x,y]=l.useState(""),[g,h]=l.useState(""),[j,v]=l.useState(""),[C,k]=l.useState(""),[w,N]=l.useState(!1),I=l.useRef(null);l.useEffect(()=>{if(p&&o){const D=o.name||"",S=o.scope||"user",M=o.description||"",E=o.agent||"",R=o.model||"",V=o.template||"";u(D),b(S),y(M),h(E),v(R),k(V),I.current={draftName:D,draftScope:S,description:M,agent:E,model:R,template:V}}else if(d){const D=d.description||"",S=d.agent||"",M=d.model||"",E=d.template||"";y(D),h(S),v(M),k(E),I.current={draftName:"",draftScope:"user",description:D,agent:S,model:M,template:E}}},[d,p,e,i,o]);const T=l.useMemo(()=>{const D=I.current;return D?!!(p&&(m!==D.draftName||f!==D.draftScope)||x!==D.description||g!==D.agent||j!==D.model||C!==D.template):!1},[g,x,m,f,p,j,C]),P=async()=>{const D=p?m.trim().replace(/\s+/g,"-"):e?.trim();if(!D){H.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!C.trim()){H.error(t("settings.commands.page.toast.templateRequired"));return}if(p&&i.some(S=>S.name===D)){H.error(t("settings.commands.sidebar.toast.commandExists"));return}N(!0);try{const S=g.trim(),M=j.trim(),E=C.trim(),R={name:D,description:x.trim()||void 0,agent:S===""?null:S,model:M===""?null:M,template:E,scope:p?f:void 0};let V;p?(V=await r(R),V&&c(null)):V=await a(D,R),V?H.success(t(p?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):H.error(t(p?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(S){console.error("Error saving command:",S),H.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{N(!1)}};return e?s.jsx(Ss,{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(Lt,{value:m,onChange:D=>u(D.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(as,{value:f,onValueChange:D=>b(D),children:[s.jsx(is,{className:"w-fit min-w-[100px]",children:s.jsx(fs,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(os,{align:"end",children:[s.jsx(Mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Mt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(un,{value:x,onChange:D=>y(D.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(ic,{agentName:g,onChange:D=>h(D)})})]}),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(Io,{providerId:Ii(j)?.providerId??"",modelId:Ii(j)?.modelId??"",onChange:(D,S)=>{v(D&&S?`${D}/${S}`:"")}})})]})]})]}),s.jsxs("div",{className:"mb-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.template")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(un,{value:C,onChange:D=>k(D.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"})}),s.jsx("div",{className:"mt-2 px-2",children:s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(be,{onClick:P,disabled:w||!T,size:"xs",className:"!font-normal",children:t(w?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(A,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.commands.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.commands.page.empty.description")})]})})},Ep=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},Mp=t=>{const e=ot.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=ye("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},Ok=t=>{const e=ot.c(116),{onItemSelect:n}=t,{t:r}=ft(),{mcpServers:a,selectedMcpName:i,setSelectedMcp:o,setMcpDraft:c,loadMcpConfigs:d,deleteMcp:p}=go(Gn(Lk)),m=Ws($k);let u;e[0]!==m?(u=ee=>ee.getStatusForDirectory(m??null),e[0]=m,e[1]=u):u=e[1];const f=vn(u),b=vn(_k),x=vn(Bk),[y,g]=l.useState(null),[h,j]=l.useState(!1),[v,C]=l.useState(null),[k,w]=l.useState(!1);let N;e[2]!==a?(N=a.filter(Vk),e[2]=a,e[3]=N):N=e[3];const I=N;let T;e[4]!==a?(T=a.filter(zk),e[4]=a,e[5]=T):T=e[5];const P=T;let D,S;e[6]!==d?(D=()=>{d()},S=[d],e[6]=d,e[7]=D,e[8]=S):(D=e[7],S=e[8]),l.useEffect(D,S);let M;e[9]!==m||e[10]!==x||e[11]!==k||e[12]!==b?(M=()=>{if(k)return;w(!0);const ee=new Promise(Uk);Promise.all([b({directory:m,silent:!0}),ee]).then(()=>{const F=x(m);F&&H.error(F)}).finally(()=>{w(!1)})},e[9]=m,e[10]=x,e[11]=k,e[12]=b,e[13]=M):M=e[13];const E=M;let R;e[14]!==a||e[15]!==n||e[16]!==c||e[17]!==o?(R=()=>{let ee="new-mcp-server",F=1;for(;a.some(oe=>oe.name===ee);)ee=`new-mcp-server-${F}`,F++;c({name:ee,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),o(ee),n?.()},e[14]=a,e[15]=n,e[16]=c,e[17]=o,e[18]=R):R=e[18];const V=R;let B;e[19]!==p||e[20]!==y||e[21]!==r?(B=async()=>{if(!y)return;j(!0);const ee=await p(y.name);ee.ok?ee.reloadFailed?H.warning(ee.message||`MCP server "${y.name}" deleted, but OpenCode reload failed`,{description:ee.warning||r("settings.mcp.sidebar.toast.refreshListIfStale")}):H.success(ee.message||r("settings.mcp.sidebar.toast.serverDeleted",{name:y.name})):H.error(r("settings.mcp.sidebar.toast.deleteFailed")),g(null),j(!1)},e[19]=p,e[20]=y,e[21]=r,e[22]=B):B=e[22];const $=B;let O;e[23]===Symbol.for("react.memo_cache_sentinel")?(O=ye("flex h-full flex-col","bg-background"),e[23]=O):O=e[23];let _;e[24]!==r?(_=r("settings.mcp.sidebar.title"),e[24]=r,e[25]=_):_=e[25];let q;e[26]!==_?(q=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:_}),e[26]=_,e[27]=q):q=e[27];let L;e[28]!==r?(L=r("settings.mcp.sidebar.actions.refreshStatusAria"),e[28]=r,e[29]=L):L=e[29];let J;e[30]!==r?(J=r("settings.mcp.sidebar.actions.refreshStatusTitle"),e[30]=r,e[31]=J):J=e[31];const Z=k&&"animate-spin";let ie;e[32]!==Z?(ie=ye("h-4 w-4",Z),e[32]=Z,e[33]=ie):ie=e[33];let ne;e[34]!==ie?(ne=s.jsx(A,{name:"refresh",className:ie}),e[34]=ie,e[35]=ne):ne=e[35];let me;e[36]!==E||e[37]!==k||e[38]!==L||e[39]!==J||e[40]!==ne?(me=s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:k,onClick:E,"aria-label":L,title:J,children:ne}),e[36]=E,e[37]=k,e[38]=L,e[39]=J,e[40]=ne,e[41]=me):me=e[41];let pe;e[42]!==q||e[43]!==me?(pe=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[q,me]}),e[42]=q,e[43]=me,e[44]=pe):pe=e[44];let G;e[45]===Symbol.for("react.memo_cache_sentinel")?(G=s.jsx(Po,{className:"mb-3"}),e[45]=G):G=e[45];let K;e[46]!==a.length||e[47]!==r?(K=r("settings.mcp.sidebar.total",{count:a.length}),e[46]=a.length,e[47]=r,e[48]=K):K=e[48];let Q;e[49]!==K?(Q=s.jsx("span",{className:"typography-meta text-muted-foreground",children:K}),e[49]=K,e[50]=Q):Q=e[50];let W;e[51]!==r?(W=r("settings.mcp.sidebar.actions.addServerTitle"),e[51]=r,e[52]=W):W=e[52];let de;e[53]===Symbol.for("react.memo_cache_sentinel")?(de=s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[53]=de):de=e[53];let ge;e[54]!==V||e[55]!==W?(ge=s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:V,title:W,children:de}),e[54]=V,e[55]=W,e[56]=ge):ge=e[56];let ve;e[57]!==Q||e[58]!==ge?(ve=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Q,ge]}),e[57]=Q,e[58]=ge,e[59]=ve):ve=e[59];let te;e[60]!==pe||e[61]!==ve?(te=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[pe,G,ve]}),e[60]=pe,e[61]=ve,e[62]=te):te=e[62];let he;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]!==P?(he=s.jsx(Ss,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:a.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(A,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[I.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.mcp.sidebar.group.projectServers")}),I.map(ee=>{const F=f[ee.name],U=Ep(F?.status),oe=i===ee.name,Te=uo();return s.jsxs("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",oe?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Te?void 0:Oe=>{Oe.preventDefault(),C(ee.name)},children:[s.jsxs("button",{onClick:()=>{o(ee.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(Mp,{tone:U,enabled:ee.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:ee.name}),s.jsx("span",{title:ee.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:ee.type==="local"?s.jsx(A,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(A,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:ee.type==="local"?ee.command?.join(" ")??"":ee.url??""})]}),s.jsxs(As,{open:v===ee.name,onOpenChange:Oe=>C(Oe?ee.name:null),children:[s.jsx(Is,{asChild:!0,children:s.jsx(be,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ps,{align:"end",className:"w-fit min-w-20",children:s.jsxs(_t,{onClick:Oe=>{Oe.stopPropagation(),g(ee)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},ee.name)})]}),P.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.mcp.sidebar.group.userServers")}),P.map(ee=>{const F=f[ee.name],U=Ep(F?.status),oe=i===ee.name,Te=uo();return s.jsxs("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",oe?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Te?void 0:Oe=>{Oe.preventDefault(),C(ee.name)},children:[s.jsxs("button",{onClick:()=>{o(ee.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(Mp,{tone:U,enabled:ee.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:ee.name}),s.jsx("span",{title:ee.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:ee.type==="local"?s.jsx(A,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(A,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:ee.type==="local"?ee.command?.join(" ")??"":ee.url??""})]}),s.jsxs(As,{open:v===ee.name,onOpenChange:Oe=>C(Oe?ee.name:null),children:[s.jsx(Is,{asChild:!0,children:s.jsx(be,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ps,{align:"end",className:"w-fit min-w-20",children:s.jsxs(_t,{onClick:Oe=>{Oe.stopPropagation(),g(ee)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},ee.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]=P,e[73]=he):he=e[73];const ce=y!==null;let xe;e[74]!==h?(xe=ee=>{!ee&&!h&&g(null)},e[74]=h,e[75]=xe):xe=e[75];let se;e[76]!==r?(se=r("settings.mcp.sidebar.deleteDialog.title"),e[76]=r,e[77]=se):se=e[77];let ue;e[78]!==se?(ue=s.jsx(ms,{children:se}),e[78]=se,e[79]=ue):ue=e[79];const Y=y?.name||"";let Se;e[80]!==r||e[81]!==Y?(Se=r("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:Y}),e[80]=r,e[81]=Y,e[82]=Se):Se=e[82];let fe;e[83]===Symbol.for("react.memo_cache_sentinel")?(fe=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[83]=fe):fe=e[83];let Ce;e[84]!==Se?(Ce=s.jsxs(Ns,{children:[Se," ",fe,"."]}),e[84]=Se,e[85]=Ce):Ce=e[85];let Ie;e[86]!==ue||e[87]!==Ce?(Ie=s.jsxs(hs,{children:[ue,Ce]}),e[86]=ue,e[87]=Ce,e[88]=Ie):Ie=e[88];let ke;e[89]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>g(null),e[89]=ke):ke=e[89];let X;e[90]!==r?(X=r("settings.common.actions.cancel"),e[90]=r,e[91]=X):X=e[91];let ae;e[92]!==h||e[93]!==X?(ae=s.jsx(be,{size:"sm",variant:"ghost",onClick:ke,disabled:h,children:X}),e[92]=h,e[93]=X,e[94]=ae):ae=e[94];let je;e[95]!==h||e[96]!==r?(je=r(h?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[95]=h,e[96]=r,e[97]=je):je=e[97];let le;e[98]!==$||e[99]!==h||e[100]!==je?(le=s.jsx(be,{size:"sm",onClick:$,disabled:h,children:je}),e[98]=$,e[99]=h,e[100]=je,e[101]=le):le=e[101];let Ne;e[102]!==ae||e[103]!==le?(Ne=s.jsxs(_s,{children:[ae,le]}),e[102]=ae,e[103]=le,e[104]=Ne):Ne=e[104];let Me;e[105]!==Ie||e[106]!==Ne?(Me=s.jsxs(ds,{className:"max-w-md",children:[Ie,Ne]}),e[105]=Ie,e[106]=Ne,e[107]=Me):Me=e[107];let Ve;e[108]!==ce||e[109]!==xe||e[110]!==Me?(Ve=s.jsx(us,{open:ce,onOpenChange:xe,children:Me}),e[108]=ce,e[109]=xe,e[110]=Me,e[111]=Ve):Ve=e[111];let we;return e[112]!==te||e[113]!==he||e[114]!==Ve?(we=s.jsxs("div",{className:O,children:[te,he,Ve]}),e[112]=te,e[113]=he,e[114]=Ve,e[115]=we):we=e[115],we};function Lk(t){return{mcpServers:t.mcpServers,selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function $k(t){return t.currentDirectory}function _k(t){return t.refresh}function Bk(t){return t.getErrorForDirectory}function Vk(t){return t.scope==="project"}function zk(t){return t.scope!=="project"}function Uk(t){return setTimeout(t,500)}function ba(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function zi(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function Aa(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Wc(t,e,n){const r=Wk(n),a=typeof n.url=="string"?n.url.trim():"",i=Rp(n,"env","environment"),o=Rp(n,"headers"),c=Kk(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=Hk(n),b=Gk(n);return{ok:!0,name:t,type:e,command:r,url:a,environment:i,headers:o,oauthEnabled:c,oauthClientId:d,oauthClientSecret:p,oauthScope:m,oauthRedirectUri:u,timeout:f,enabled:b}}function Wk(t){const e=t.command,n=t.args;if(zi(e)&&zi(n))return[...e,...n];if(zi(e))return e;if(typeof e=="string"&&e.trim()){const r=e.trim().split(/\s+/);return zi(n)?[...r,...n]:r}return zi(n)?n:[]}function Rp(t,...e){for(const n of e){const r=t[n];if(!ba(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 Kk(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!ba(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 Hk(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 Gk(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function qk(t){const e=t.mcpServers;if(ba(e)){const r=Object.keys(e);if(r.length===1){const a=r[0],i=e[a];if(ba(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"&&ba(a)});if(n.length===1){const r=n[0],a=t[r];if(Tg(a))return{name:r,entry:a}}return null}function Tg(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function Jk(t,e){let n;try{const o=t.trim();if(!o)return Aa("No JSON content provided");n=JSON.parse(o)}catch(o){return Aa(o instanceof Error?`Invalid JSON: ${o.message}`:"Invalid JSON")}if(!ba(n))return Aa("Expected a JSON object, not an array or primitive");const r=n,a=r.mcpServers;if(ba(a)){const o=Object.keys(a);if(o.length===0)return Aa("mcpServers object is empty",n);if(o.length>1)return Aa("Paste one server at a time. Found "+o.length+" servers in mcpServers",n);const c=o[0],d=a[c];return ba(d)?Wc(c,Kc(d),d):Aa("Server entry is not a valid object",n)}const i=qk(r);if(i)return Wc(i.name,Kc(i.entry),i.entry);if(Tg(r)){const o=Kc(r),c=typeof r.name=="string"&&r.name.trim()?r.name.trim():e?.fallbackName;return Wc(c,o,r)}return Aa("No recognizable MCP server configuration found in JSON",n)}function Kc(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 Yk(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 Eg="/mcp/oauth/callback",Qk=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}},Mg=t=>{const e=Xk(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}},yu=t=>{const e=t.get("state");return typeof e!="string"?null:e.trim()||null},Xk=t=>{if(typeof t!="string"||!t.trim())return null;const e=Qk(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 Zk(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 e3(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:Mg(n.searchParams),stateKey:yu(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const t3=({value:t,onChange:e,pasteCommandTitle:n,pasteCommandLabel:r,pasteSuccess:a,clipboardReadFailed:i,preview:o})=>{const[c,d]=l.useState(()=>t.join(`
|
|
157
|
-
`)),p=l.useRef(t);l.useEffect(()=>{JSON.stringify(p.current)!==JSON.stringify(t)&&(p.current=t,d(t.join(`
|
|
158
|
-
`)))},[t]);const m=f=>{const b=f.split(`
|
|
159
|
-
`).filter(x=>x.trim().length>0);e(b)},u=async()=>{try{const b=(await navigator.clipboard.readText()).trim(),x=b.includes(`
|
|
160
|
-
`)?b.split(`
|
|
161
|
-
`).filter(y=>y.trim()):Zk(b);d(x.join(`
|
|
162
|
-
`)),e(x),H.success(a(x.length))}catch{H.error(i)}};return s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[s.jsx("div",{className:"flex items-center justify-end gap-2",children:s.jsxs(be,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:u,type:"button",title:n,children:[s.jsx(A,{name:"clipboard",className:"h-3 w-3"}),r]})}),s.jsx(un,{value:c,onChange:f=>{d(f.target.value),m(f.target.value)},onBlur:()=>{const f=c.split(`
|
|
163
|
-
`).map(b=>b.trimEnd()).join(`
|
|
164
|
-
`);d(f),m(f)},placeholder:`npx
|
|
165
|
-
-y
|
|
166
|
-
@modelcontextprotocol/server-postgres
|
|
167
|
-
postgresql://user:pass@host/db`,rows:Math.max(4,t.length+1),className:"font-mono typography-meta resize-y min-h-[80px]",spellCheck:!1}),t.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:o(t.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:t.map((f,b)=>s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",b,"]"]}),f]},b))})})]})]})},s3=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),Fp=({value:t,onChange:e,keyTransform:n=s3,keyPlaceholder:r="API_KEY",keyInputClassName:a="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:i="Paste .env",pasteTitle:o="Paste KEY=VALUE lines from clipboard",noPairsFoundError:c,importSuccess:d,clipboardReadFailed:p,keyLabel:m,valueLabel:u,valuePlaceholder:f,hideValueTitle:b,showValueTitle:x,addVariable:y,plainTextWarning:g,removeVariableAria:h})=>{const[j,v]=l.useState(new Set),C=()=>e([...t,{key:"",value:""}]),k=P=>{e(t.filter((D,S)=>S!==P)),v(D=>{const S=new Set(D);return S.delete(P),S})},w=(P,D,S)=>{const M=[...t];M[P]={...M[P],[D]:S},e(M)},N=P=>{v(D=>{const S=new Set(D);return S.has(P)?S.delete(P):S.add(P),S})},I=async()=>{try{const P=await navigator.clipboard.readText(),D=[];for(const M of P.split(`
|
|
168
|
-
`)){const E=M.trim();if(!E||E.startsWith("#"))continue;const R=E.indexOf("=");if(R===-1)continue;const V=E.slice(0,R).trim();let B=E.slice(R+1).trim();(B.startsWith('"')&&B.endsWith('"')||B.startsWith("'")&&B.endsWith("'"))&&(B=B.slice(1,-1)),V&&D.push({key:V,value:B})}if(D.length===0){H.error(c);return}const S=[...t];for(const M of D){const E=S.findIndex(R=>R.key===M.key);E!==-1?S[E]=M:S.push(M)}e(S),H.success(d(D.length))}catch{H.error(p)}},T=t.some(P=>P.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:m}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:u})]}),s.jsxs(be,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:I,type:"button",title:o,children:[s.jsx(A,{name:"clipboard",className:"h-3 w-3"}),i]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((P,D)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Lt,{value:P.key,onChange:S=>w(D,"key",n(S.target.value)),placeholder:r,className:a,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(Lt,{type:j.has(D)?"text":"password",value:P.value,onChange:S=>w(D,"value",S.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:()=>N(D),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:j.has(D)?b:x,children:j.has(D)?s.jsx(A,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>k(D),"aria-label":h,children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},D))}),s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:C,type:"button",children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),y]}),T&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:g})]})},Op=t=>{const e=ot.c(14),{status:n,enabled:r,getStatusLabel:a,variant:i}=t,o=i===void 0?"compact":i;if(!r||!n)return null;let c,d;if(e[0]!==a||e[1]!==n||e[2]!==o){d=Symbol.for("react.early_return_sentinel");e:{const f={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[n]??{text:"text-muted-foreground",bg:""};if(o==="pill"){const b=ye("typography-micro font-medium rounded-full px-2 py-0.5",f.text,f.bg);let x;e[5]!==a||e[6]!==n?(x=a(n),e[5]=a,e[6]=n,e[7]=x):x=e[7],d=s.jsxs("span",{className:b,children:["● ",x]});break e}c=ye("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},n3=(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")}},r3=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)]"}},a3=(t,e,n,r)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||n||r),Lp=(t,e)=>{if(typeof window>"u")return null;const n=new URL(Eg,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()},i3=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")}},o3=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},Ui=async t=>{typeof t!="string"||!t.trim()||await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},Hc=(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},l3=(t,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${n}`},c3=()=>{const{t}=ft(),e=l.useCallback((Ye,Tt)=>t(Ye,Tt),[t]),{selectedMcpName:n,mcpServers:r,mcpDraft:a,setMcpDraft:i,setSelectedMcp:o,getMcpByName:c,createMcp:d,updateMcp:p,deleteMcp:m}=go(Gn(Ye=>({selectedMcpName:Ye.selectedMcpName,mcpServers:Ye.mcpServers,mcpDraft:Ye.mcpDraft,setMcpDraft:Ye.setMcpDraft,setSelectedMcp:Ye.setSelectedMcp,getMcpByName:Ye.getMcpByName,createMcp:Ye.createMcp,updateMcp:Ye.updateMcp,deleteMcp:Ye.deleteMcp}))),u=Ws(Ye=>Ye.currentDirectory),f=l.useMemo(()=>fn(),[]),b=vn(Ye=>Ye.getStatusForDirectory(u??null)),x=vn(Ye=>Ye.getDiagnosticForDirectory(u??null)),y=vn(Ye=>Ye.refresh),g=vn(Ye=>Ye.connect),h=vn(Ye=>Ye.disconnect),j=vn(Ye=>Ye.startAuth),v=vn(Ye=>Ye.completeAuth),C=vn(Ye=>Ye.clearAuth),k=vn(Ye=>Ye.testConnection),w=n?c(n):null,N=!!(a&&a.name===n&&!w),[I,T]=l.useState(""),[P,D]=l.useState("user"),[S,M]=l.useState("local"),[E,R]=l.useState([]),[V,B]=l.useState(""),[$,O]=l.useState([]),[_,q]=l.useState([]),[L,J]=l.useState(!0),[Z,ie]=l.useState(""),[ne,me]=l.useState(""),[pe,G]=l.useState(""),[K,Q]=l.useState(""),[W,de]=l.useState(""),[ge,ve]=l.useState(!0),[te,he]=l.useState(!1),[ce,xe]=l.useState(!1),[se,ue]=l.useState(!1),[Y,Se]=l.useState(!1),[fe,Ce]=l.useState(!1),[Ie,ke]=l.useState(!1),[X,ae]=l.useState(!1),[je,le]=l.useState(!1),[Ne,Me]=l.useState(null),[Ve,we]=l.useState(null),[ee,F]=l.useState(""),[U,oe]=l.useState(!1),Te=l.useRef(0),Oe=l.useRef(!1),[Pe,z]=l.useState(!1),[De,Qe]=l.useState(!1),[et,Ze]=l.useState(""),[We,it]=l.useState(null),qe=l.useMemo(()=>l3(n,u),[u,n]),st=l.useRef(qe),Je=l.useRef(null),Be=l.useCallback(()=>{Me(null),we(null),F(""),oe(!1),Te.current=0,le(!1),Ce(!1),ke(!1),Oe.current=!1},[]),nt=l.useCallback(()=>{Ze(""),it(null),Qe(!0)},[]),Ge=l.useCallback(async()=>{try{const Ye=await navigator.clipboard.readText();Ze(Ye),it(null)}catch{H.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),at=l.useCallback(()=>{const Ye=Jk(et,{fallbackName:I});if(!Ye.ok){it(Ye.error);return}const Kt=Yk(Ye,{name:I,scope:P,type:S,command:E,url:V,environment:$,headers:_,oauthEnabled:L,oauthClientId:Z,oauthClientSecret:ne,oauthScope:pe,oauthRedirectUri:K,timeout:W,enabled:ge},{isNewServer:N});T(Kt.name),M(Kt.type),R(Kt.command??[]),B(Kt.url??""),O(Kt.environment??[]),q(Kt.headers??[]),J(Kt.oauthEnabled??!1),ie(Kt.oauthClientId??""),me(Kt.oauthClientSecret??""),G(Kt.oauthScope??""),Q(Kt.oauthRedirectUri??""),de(Kt.timeout??""),ve(Kt.enabled??!0),Qe(!1),Ze(""),it(null),H.success(t("settings.mcp.page.toast.configImported"))},[et,I,P,S,E,V,$,_,L,Z,ne,pe,K,W,ge,N,t]);l.useEffect(()=>{if(N&&a){T(a.name),D(a.scope||"user"),M(a.type),R(a.command),B(a.url),O(a.environment),q(a.headers),J(a.oauthEnabled),ie(a.oauthClientId),me(a.oauthClientSecret),G(a.oauthScope),Q(a.oauthRedirectUri),de(a.timeout),ve(a.enabled),z(!1),Je.current={mcpType:a.type,command:a.command,url:a.url,envEntries:a.environment,headerEntries:a.headers,oauthEnabled:a.oauthEnabled,oauthClientId:a.oauthClientId,oauthClientSecret:a.oauthClientSecret,oauthScope:a.oauthScope,oauthRedirectUri:a.oauthRedirectUri,timeout:a.timeout,enabled:a.enabled};return}if(w){D(w.scope==="project"?"project":"user");const Ye=gm(w.environment),Tt=w.type==="remote"?w:null,Kt=gm(Tt?.headers),St=Tt?.oauth,es=St&&typeof St=="object"?St:null,ss=St!==!1,Ms=w.type,xs=Ms==="local"?w.command??[]:[],Bs=Ms==="remote"?w.url??"":"",ws=typeof Tt?.timeout=="number"&&Number.isFinite(Tt.timeout)?String(Tt.timeout):"";M(Ms),R(xs),B(Bs),O(Ye),q(Kt),J(ss),ie(ss?es?.clientId??"":""),me(ss?es?.clientSecret??"":""),G(ss?es?.scope??"":""),Q(ss?es?.redirectUri??"":""),de(ws),ve(w.enabled),z(!1),Je.current={mcpType:Ms,command:xs,url:Bs,envEntries:Ye,headerEntries:Kt,oauthEnabled:ss,oauthClientId:ss?es?.clientId??"":"",oauthClientSecret:ss?es?.clientSecret??"":"",oauthScope:ss?es?.scope??"":"",oauthRedirectUri:ss?es?.redirectUri??"":"",timeout:ws,enabled:w.enabled}}},[w,N,a]);const Ae=l.useMemo(()=>{const Ye=Je.current;return Ye?S!==Ye.mcpType||ge!==Ye.enabled||JSON.stringify(E)!==JSON.stringify(Ye.command)||V!==Ye.url||JSON.stringify($)!==JSON.stringify(Ye.envEntries)||JSON.stringify(_)!==JSON.stringify(Ye.headerEntries)||L!==Ye.oauthEnabled||Z!==Ye.oauthClientId||ne!==Ye.oauthClientSecret||pe!==Ye.oauthScope||K!==Ye.oauthRedirectUri||W!==Ye.timeout:!1},[S,E,V,$,_,L,Z,ne,pe,K,W,ge]),Le=async()=>{const Ye=N?I.trim():n??"";if(!Ye){H.error(t("settings.mcp.page.toast.nameRequired"));return}if(N&&r.some(Kt=>Kt.name===Ye)){H.error(t("settings.mcp.page.toast.serverNameExists"));return}if(S==="local"&&E.filter(Boolean).length===0){H.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(S==="remote"&&!V.trim()){H.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const Tt={name:Ye,scope:P,type:S,command:E,url:V,environment:$,headers:_,oauthEnabled:L,oauthClientId:Z,oauthClientSecret:ne,oauthScope:pe,oauthRedirectUri:K,timeout:W,enabled:ge};he(!0);try{const Kt=N?await d(Tt):await p(Ye,Tt);Kt.ok?(await Ui(Ve),Be(),N&&(i(null),o(Ye)),await y({directory:u,silent:!0}),Kt.reloadFailed?H.warning(Kt.message||t(N?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:Kt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):H.success(Kt.message||t(N?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):H.error(t("settings.mcp.page.toast.saveFailed"))}catch(Kt){H.error(Kt instanceof Error?Kt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{he(!1)}},ze=async()=>{if(!n)return;ue(!0);const Ye=await m(n);Ye.ok?(await Ui(Ve),Be(),Ye.reloadFailed?H.warning(Ye.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:Ye.warning||t("settings.mcp.page.toast.refreshListIfStale")}):H.success(Ye.message||t("settings.mcp.page.toast.serverDeleted",{name:n})),xe(!1)):H.error(t("settings.mcp.page.toast.deleteFailed")),ue(!1)},Ke=async()=>{if(n){Se(!0);try{if(b[n]?.status==="connected")await h(n,u),H.success(t("settings.mcp.page.toast.disconnected"));else{await g(n,u),await y({directory:u,silent:!0});const Tt=vn.getState().getStatusForDirectory(u??null)[n];Tt?.status==="connected"?H.success(t("settings.mcp.page.toast.connected")):Tt?.status==="needs_auth"?H.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Tt?.status==="needs_client_registration"?H.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):Tt?.status==="failed"?H.error(Tt.error||t("settings.mcp.page.toast.connectionFailed")):H.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await y({directory:u,silent:!0})}catch(Ye){H.error(Ye instanceof Error?Ye.message:t("settings.mcp.page.toast.connectionFailed"))}finally{Se(!1)}}},lt=l.useCallback(()=>N?(H.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):Ae?(H.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[Ae,N,t]),xt=l.useCallback(async(Ye=!1)=>{try{await y({directory:u,silent:Ye})}catch(Tt){Ye||H.error(Tt instanceof Error?Tt.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[u,y,t]);l.useEffect(()=>{xt(!0)},[xt]),l.useEffect(()=>{st.current=qe,Se(!1),ae(!1),Be()},[Be,qe]);const dt=l.useCallback(async()=>{if(!n||S!=="remote"||!lt())return;Ce(!0);const Ye=qe;let Tt=null;try{const Kt=vn.getState().getStatusForDirectory(u??null)[n]?.status;Oe.current=Kt==="needs_auth"||Kt==="needs_client_registration";const St=Lp(n,u);if(!St)throw new Error(t("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!K.trim()&&!f){const xs=await p(n,{oauthEnabled:L,oauthClientId:Z,oauthClientSecret:ne,oauthScope:pe,oauthRedirectUri:St});if(!xs.ok)throw new Error(t("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(xs.reloadFailed)throw new Error(xs.warning||xs.message||t("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(st.current!==Ye)return;Q(St),Je.current=Je.current?{...Je.current,oauthRedirectUri:St}:Je.current}const es=await j(n,u),ss=yu(new URL(es).searchParams);if(ss&&(Tt=ss,await i3({state:ss,name:n,directory:u})),st.current!==Ye)return;Me(es),we(ss??null),oe(!0),Te.current=0;const Ms=await rr(es);if(st.current!==Ye)return;Ms?H.message(t(f?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):H.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(Kt){await Ui(Tt),st.current===Ye&&H.error(Hc(Kt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{st.current===Ye&&Ce(!1)}},[u,f,S,Z,ne,L,K,pe,lt,qe,n,j,t,e,p]),ut=l.useCallback(async()=>{if(!n||!lt())return;ke(!0);const Ye=qe;try{if(await C(n,u),st.current!==Ye)return;Me(null),we(null),F(""),oe(!1),Te.current=0,await Ui(Ve),H.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(Tt){st.current===Ye&&H.error(Hc(Tt,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{st.current===Ye&&ke(!1)}},[Ve,C,u,lt,qe,n,t,e]),Nt=l.useCallback(async()=>{if(!Ne)return;if((await En(Ne)).ok){H.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}H.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Ne,t]),ts=l.useCallback(async()=>{const Ye=e3(ee);if(!Ye.code){H.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const Tt=Ye.stateKey?await o3(Ye.stateKey):null,Kt=Ye.context??Tt,St=Kt?.name??n,es=Kt?.directory??u;if(!St){H.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!Kt&&!lt())return;le(!0);const ss=qe;try{if(await v(St,Ye.code,es),await Ui(Ye.stateKey??Ve),st.current!==ss)return;F(""),Me(null),we(null),oe(!1),Te.current=0,H.success(St===n?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:St}))}catch(Ms){st.current===ss&&H.error(Hc(Ms,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{st.current===ss&&le(!1)}},[ee,Ve,v,u,lt,qe,n,t,e]),Vt=l.useCallback(async()=>{if(!(!n||!lt())){if(!ge){H.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}ae(!0);try{const Ye=await k(n,u),Tt=Ye.status?.status;Ye.warning?H.warning(Ye.warning):Tt==="connected"?H.success(t("settings.mcp.page.toast.connectionTestSucceeded")):Tt==="needs_auth"?H.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Tt==="needs_client_registration"?H.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):Tt==="failed"?H.error(Ye.status?.error||Ye.error||t("settings.mcp.page.toast.connectionTestFailed")):Ye.error?H.error(Ye.error):H.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(Ye){H.error(Ye instanceof Error?Ye.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{ae(!1)}}},[u,ge,lt,n,t,k]);if(l.useEffect(()=>{if(!U||!n)return;const Ye=window.setInterval(()=>{(async()=>{Te.current+=1,await y({directory:u,silent:!0});const Tt=vn.getState().getStatusForDirectory(u??null)[n];if(Tt){if(Oe.current&&Tt.status!=="needs_auth"&&Tt.status!=="needs_client_registration"){oe(!1),Te.current=0,Oe.current=!1,Me(null),F(""),Tt.status==="connected"&&H.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!Oe.current&&Tt.status==="failed"){oe(!1),Te.current=0,Oe.current=!1,H.error(Tt.error||t("settings.mcp.page.toast.authorizationFailed"));return}Te.current>=30&&(oe(!1),Te.current=0,Oe.current=!1,H.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(Ye)}},[u,U,y,n,t]),!n)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(A,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const Xt=b[n],ht=n?x[n]:void 0,Bt=Xt??ht,Zt=Xt?.status==="connected",gs=Xt?.status==="needs_auth"||Xt?.status==="needs_client_registration",rs=f?null:Lp(n,u),ps=n3(Bt?.status,e,Bt&&"error"in Bt?Bt.error:void 0),Ut=Ye=>{switch(Ye){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return t("settings.mcp.page.status.label.needsRegistration");default:return Ye}};return s.jsxs(Ss,{outerClassName:"h-full",className:"w-full",children:[s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"min-w-0",children:[N?s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.mcp.page.header.newServer")}):s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:n}),s.jsx(Op,{status:Bt?.status,enabled:ge,getStatusLabel:Ut,variant:"pill"})]}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:N?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(S==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")})}),!N&&s.jsxs(s.Fragment,{children:[s.jsx(be,{variant:Zt?"outline":"default",size:"xs",className:"!font-normal",onClick:Ke,disabled:Y||!ge,children:t(Y?"settings.mcp.page.actions.working":Zt?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),S==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(be,{variant:gs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{dt()},disabled:fe||!ge,children:t(fe?"settings.mcp.page.actions.starting":gs?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ut()},disabled:Ie||!ge,children:t(Ie?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),Zt&&s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{Vt()},disabled:X||!ge,children:t(X?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!N&&a3(Bt?.status,Ne,gs,U)&&s.jsx("div",{className:"mb-6 px-2",children:s.jsxs("div",{className:ye("rounded-lg border p-3",r3(Bt?.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(Op,{status:Bt?.status,enabled:ge,getStatusLabel:Ut})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:ps}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:P==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:u??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Zt&&s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Vt()},disabled:X||!ge,children:t(X?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Ne&&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:Ne}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{rr(Ne)},children:[s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Nt()},children:[s.jsx(A,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),S==="remote"&&(gs||U||Ne)&&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(un,{value:ee,onChange:Ye=>F(Ye.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta resize-y","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ts()},disabled:je,children:t(je?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),U&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.mcp.page.server.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[N&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.name")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx(Lt,{value:I,onChange:Ye=>T(Ye.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 font-mono px-2",autoFocus:!0}),s.jsxs(as,{value:P,onValueChange:Ye=>D(Ye),children:[s.jsx(is,{className:"!h-7 !w-7 !min-w-0 !px-0 !py-0 justify-center [&>svg:last-child]:hidden",title:t(P==="user"?"settings.common.scope.global":"settings.common.scope.project"),children:P==="user"?s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5"})}),s.jsxs(os,{align:"end",children:[s.jsx(Mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Mt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),N&&s.jsx("div",{className:"py-1.5",children:s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:nt,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(A,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]})}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ge,onClick:()=>ve(!ge),onKeyDown:Ye=>{(Ye.key===" "||Ye.key==="Enter")&&(Ye.preventDefault(),ve(!ge))},children:[s.jsx(vs,{checked:ge,onChange:ve,ariaLabel:t("settings.mcp.page.server.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.enable")})]}),s.jsx("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:s.jsxs("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.transportMode")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(be,{variant:"chip",size:"xs","aria-pressed":S==="local",onClick:()=>M("local"),className:"!font-normal",children:t("settings.mcp.page.transport.local")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":S==="remote",onClick:()=>M("remote"),className:"!font-normal",children:t("settings.mcp.page.transport.remote")})]})]})})]})]}),s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t(S==="local"?"settings.mcp.page.connection.command":"settings.mcp.page.connection.serverUrl")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:S==="local"?s.jsx(t3,{value:E,onChange:R,pasteCommandTitle:t("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:t("settings.mcp.page.connection.pasteCommand"),pasteSuccess:Ye=>t("settings.mcp.page.toast.pastedArgumentsCount",{count:Ye}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),preview:Ye=>t("settings.mcp.page.connection.previewArgs",{count:Ye})}):s.jsx(Lt,{value:V,onChange:Ye=>B(Ye.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"})})]}),S==="remote"&&s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.mcp.page.advanced.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs(vr,{open:Pe,onOpenChange:z,children:[s.jsxs(Mr,{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(L?"settings.mcp.page.advanced.autoDetect":"settings.mcp.page.advanced.custom")," · ",_.length," ",t("settings.mcp.page.advanced.headers"),W?` · ${W}ms`:"",")"]})]}),Pe?s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(wr,{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(Lt,{type:"number",min:"1",step:"1",value:W,onChange:Ye=>de(Ye.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]}),s.jsx("p",{className:"typography-micro text-muted-foreground sm:pl-64",children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"mb-2 typography-ui-label text-foreground",children:[t("settings.mcp.page.advanced.requestHeaders"),_.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",_.length,")"]})]}),s.jsx(Fp,{value:_,onChange:q,keyTransform:Ye=>Ye.trimStart(),keyPlaceholder:t("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:t("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:t("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Ye=>t("settings.mcp.page.toast.importedVariablesCount",{count:Ye}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":L,onClick:()=>J(!L),onKeyDown:Ye=>{(Ye.key===" "||Ye.key==="Enter")&&(Ye.preventDefault(),J(!L))},children:[s.jsx(vs,{checked:L,onChange:J,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(Lt,{value:Z,onChange:Ye=>ie(Ye.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientIdPlaceholder"),className:"font-mono typography-meta",disabled:!L,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Lt,{value:ne,onChange:Ye=>me(Ye.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientSecretPlaceholder"),className:"font-mono typography-meta",disabled:!L,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Lt,{value:pe,onChange:Ye=>G(Ye.target.value),placeholder:t("settings.mcp.page.advanced.oauthScopesPlaceholder"),className:"font-mono typography-meta",disabled:!L,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Lt,{value:K,onChange:Ye=>Q(Ye.target.value),placeholder:t("settings.mcp.page.advanced.oauthRedirectUriPlaceholder"),className:"font-mono typography-meta",disabled:!L,"data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.advanced.oauthHint")}),rs&&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:rs})]})]})]})})]})})]}),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(be,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>O([{key:"",value:""}]),children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(Fp,{value:$,onChange:O,keyPlaceholder:t("settings.mcp.page.env.keyPlaceholder"),pasteLabel:t("settings.mcp.page.env.pasteEnv"),pasteTitle:t("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Ye=>t("settings.mcp.page.toast.importedVariablesCount",{count:Ye}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})})]}),s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[s.jsx(be,{onClick:Le,disabled:te||!Ae&&!N,size:"xs",className:"!font-normal",children:t(te?"settings.common.actions.saving":N?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!N&&s.jsx(be,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>xe(!0),children:t("settings.common.actions.delete")})]})]}),s.jsx(us,{open:De,onOpenChange:Ye=>{Ye||(Qe(!1),Ze(""),it(null))},children:s.jsxs(ds,{className:"max-w-md",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Ns,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(un,{value:et,onChange:Ye=>{Ze(Ye.target.value),it(null)},placeholder:`{
|
|
169
|
-
"mcpServers": {
|
|
170
|
-
"postgres": {
|
|
171
|
-
"command": "npx",
|
|
172
|
-
"args": ["-y", "@modelcontextprotocol/server-postgres"]
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}`,rows:8,className:"font-mono typography-meta resize-y",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),We&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:We}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Ge,type:"button",children:[s.jsx(A,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(_s,{children:[s.jsx(be,{variant:"outline",onClick:()=>{Qe(!1),Ze(""),it(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(be,{onClick:at,disabled:!et.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(us,{open:ce,onOpenChange:Ye=>{!Ye&&!se&&xe(!1)},children:s.jsxs(ds,{className:"max-w-md",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:t("settings.mcp.page.deleteDialog.title",{name:n??""})}),s.jsxs(Ns,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(_s,{children:[s.jsx(be,{variant:"outline",onClick:()=>xe(!1),disabled:se,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(be,{variant:"destructive",size:"sm",onClick:ze,disabled:se,children:t(se?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},gl=()=>{try{const e=Cs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=on.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},d3=800,u3=5e3,m3="__default__",Ed=new Map,Gc=new Map,p3=1500,Rg=t=>t?.trim()||m3,f3=t=>{Ed.delete(Rg(t))},In=ar()(Xa(Ei((t,e)=>({entries:[],files:[],selectedId:null,isLoading:!1,registryInfo:{},isLoadingRegistry:!1,draft:null,setSelected:n=>t({selectedId:n}),setDraft:n=>t({draft:n}),loadPlugins:async n=>{const r=gl(),a=Rg(r),i=Date.now(),o=Ed.get(a)??0,c=e().entries.length>0||e().files.length>0;if(!n?.force&&c&&i-o<u3)return!0;const d=Gc.get(a);if(!n?.force&&d)return d;const p=(async()=>{t({isLoading:!0});try{const m=await fetch(ma("/api/config/plugins",r),{headers:Wi(r)});if(!m.ok)throw new Error("Failed to load plugins");const u=await xl(m);return t({entries:u.entries??[],files:u.files??[],isLoading:!1}),Ed.set(a,Date.now()),n?.force||e().loadRegistryInfo(),!0}catch(m){return console.error("[PluginsStore] Failed to load plugins:",m),t({isLoading:!1}),!1}})();Gc.set(a,p);try{return await p}finally{Gc.delete(a)}},loadRegistryInfo:async n=>{const r=g3(n?.specs??e().entries.map(a=>a.spec));if(r.length===0){t({isLoadingRegistry:!1});return}t({isLoadingRegistry:!0});try{const a=gl(),i={...e().registryInfo};for(const o of x3(r)){const c=await fetch(h3(o,n?.force===!0,a),{headers:Wi(a)});if(!c.ok)throw new Error("Failed to load plugin registry info");const d=await xl(c);for(const p of d.results??[])i[p.spec]=p}t({registryInfo:i,isLoadingRegistry:!1})}catch(a){console.error("[PluginsStore] Failed to load plugin registry info:",a),t({isLoadingRegistry:!1})}},updateToLatest:async n=>{const r=e().entries.find(i=>i.id===n);if(!r)return{ok:!1};const a=e().registryInfo[r.spec];return!a||a.kind!=="npm-ok"||!a.hasUpdate||!a.latestVersion?{ok:!1}:await e().updateEntry(n,{spec:`${a.name}@${a.latestVersion}`})},createEntry:async n=>{const r=await ci("Creating plugin entry…",async a=>await fetch(ma("/api/config/plugins/entry",a),{method:"POST",headers:Ho(a),body:JSON.stringify($p(n))}),e);return r.ok&&e().loadRegistryInfo({specs:[n.spec],force:!0}),r},updateEntry:async(n,r)=>{const a=e().entries.find(c=>c.id===n)?.spec,i=r.spec??a,o=await ci("Updating plugin entry…",async c=>await fetch(ma(`/api/config/plugins/entry/${encodeURIComponent(n)}`,c),{method:"PATCH",headers:Ho(c),body:JSON.stringify($p(r))}),e);return o.ok&&i&&e().loadRegistryInfo({specs:[i],force:!0}),o},deleteEntry:async n=>{const r=e().entries.find(i=>i.id===n),a=await ci("Deleting plugin entry…",async i=>await fetch(ma(`/api/config/plugins/entry/${encodeURIComponent(n)}`,i),{method:"DELETE",headers:Wi(i)}),e);if(a.ok&&e().selectedId===n&&t({selectedId:null}),a.ok&&r){const i={...e().registryInfo};delete i[r.spec],t({registryInfo:i})}return a},readFile:async n=>{try{const r=gl(),a=await fetch(ma(`/api/config/plugins/file/${encodeURIComponent(n)}`,r),{headers:Wi(r)});if(!a.ok)throw new Error("Failed to read plugin file");return await xl(a)}catch(r){return console.error("[PluginsStore] Failed to read plugin file:",r),null}},createFile:async n=>ci("Creating plugin file…",async r=>await fetch(ma("/api/config/plugins/file",r),{method:"POST",headers:Ho(r),body:JSON.stringify(n)}),e),updateFile:async(n,r)=>ci("Updating plugin file…",async a=>await fetch(ma(`/api/config/plugins/file/${encodeURIComponent(n)}`,a),{method:"PUT",headers:Ho(a),body:JSON.stringify(r)}),e),deleteFile:async n=>{const r=await ci("Deleting plugin file…",async a=>await fetch(ma(`/api/config/plugins/file/${encodeURIComponent(n)}`,a),{method:"DELETE",headers:Wi(a)}),e);return r.ok&&e().selectedId===n&&t({selectedId:null}),r},getById:n=>e().entries.find(r=>r.id===n)??e().files.find(r=>r.id===n)}),{name:"plugins-store",storage:wo(()=>br()),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function ma(t,e){const n=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${n}`}function h3(t,e,n){const r=new URLSearchParams;e&&r.set("refresh","true"),n&&r.set("directory",n);const a=r.toString();return`/api/config/plugins/registry?${`specs=${t.map(encodeURIComponent).join(",")}`}${a?`&${a}`:""}`}function g3(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function x3(t){const e=[];let n=[],r=0;for(const a of t){const i=encodeURIComponent(a),o=n.length===0?i.length:r+1+i.length;n.length>0&&o>p3?(e.push(n),n=[a],r=i.length):(n.push(a),r=o)}return n.length>0&&e.push(n),e}function Wi(t){return t?{"x-opencode-directory":t}:void 0}function Ho(t){return{"Content-Type":"application/json",...t?{"x-opencode-directory":t}:{}}}function $p(t){const e={};return t.spec!==void 0&&(e.spec=t.spec),t.options!==void 0&&(e.options=t.options),t.scope!==void 0&&(e.scope=t.scope),e}async function ci(t,e,n){nl(t);let r=!1;try{const a=gl(),i=await e(a),o=await xl(i).catch(()=>null);if(!i.ok)throw new Error(o?.error||"Failed to update plugin configuration");return f3(a),o?.requiresReload&&(r=!0,await rl({message:o.message,delayMs:o.reloadDelayMs??d3,scopes:["all"]})),await n().loadPlugins({force:!0}),{ok:!0,reloadFailed:o?.reloadFailed===!0,message:o?.message,warning:o?.warning}}catch(a){return console.error("[PluginsStore] Failed to update plugin configuration:",a),{ok:!1}}finally{r||al()}}async function xl(t){return await t.json()}const b3=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function y3(t){const e=t.trim();if(e==="")return{ok:!0,value:void 0};try{const n=JSON.parse(e);return n===null||typeof n!="object"||Array.isArray(n)?{ok:!1}:{ok:!0,value:n}}catch{return{ok:!1}}}const v3=({open:t,onOpenChange:e,defaultScope:n="user"})=>{const{t:r}=ft(),a=In(R=>R.createEntry),i=In(R=>R.createFile),[o,c]=l.useState("npm"),[d,p]=l.useState(""),[m,u]=l.useState(""),[f,b]=l.useState(""),[x,y]=l.useState(""),[g,h]=l.useState(n),[j,v]=l.useState(!1),C=l.useCallback(()=>{p(""),u(""),b(""),y(""),h(n)},[n]);l.useEffect(()=>{t&&(c("npm"),C())},[t,C]);const k=R=>{R!==o&&(c(R),C())},w=l.useMemo(()=>y3(m),[m]),N=!w.ok,I=o==="file"&&f.trim()!==""&&!b3.test(f.trim()),T=(o==="npm"||o==="path")&&d.trim()==="",P=o==="file"&&x.trim()==="",D=o==="file"&&f.trim()==="",S=j||N||o==="npm"&&T||o==="path"&&T||o==="file"&&(D||I||P),M=async()=>{if(!S){v(!0);try{let R;o==="file"?R=await i({fileName:f.trim(),content:x,scope:g}):R=await a({spec:d.trim(),options:w.ok?w.value:void 0,scope:g}),R.ok?(H.success(R.message||r("settings.plugins.toast.created")),R.reloadFailed&&H.warning(r("settings.plugins.toast.reloadFailed")),e(!1)):H.error(R.message||r("settings.plugins.sidebar.toast.deleteFailed"))}finally{v(!1)}}},E=l.useMemo(()=>[{id:"npm",label:r("settings.plugins.dialog.add.tab.npm")},{id:"path",label:r("settings.plugins.dialog.add.tab.path")},{id:"file",label:r("settings.plugins.dialog.add.tab.file")}],[r]);return s.jsx(us,{open:t,onOpenChange:R=>{!R&&j||e(R)},children:s.jsxs(ds,{className:"max-w-xl",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:r("settings.plugins.dialog.add.title")}),s.jsx(Ns,{children:r("settings.plugins.sidebar.empty.description")})]}),s.jsx(Er,{items:E,activeId:o,onSelect:R=>k(R),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),s.jsxs("div",{className:"flex flex-col gap-4",children:[(o==="npm"||o==="path")&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-spec",className:"typography-ui-label text-foreground",children:r("settings.plugins.page.field.spec")}),s.jsx(Lt,{id:"plugin-spec",value:d,onChange:R=>p(R.target.value),placeholder:r("settings.plugins.page.field.spec.placeholder"),"aria-invalid":T?!1:void 0,disabled:j}),T&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:r("settings.plugins.validation.specRequired")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-options",className:"typography-ui-label text-foreground",children:r("settings.plugins.page.field.options")}),s.jsx(un,{id:"plugin-options",value:m,onChange:R=>u(R.target.value),rows:5,className:"font-mono",hasError:N,disabled:j}),N&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r("settings.plugins.page.field.options.invalidJson")})]})]}),o==="file"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-filename",className:"typography-ui-label text-foreground",children:r("settings.plugins.page.field.fileName")}),s.jsx(Lt,{id:"plugin-filename",value:f,onChange:R=>b(R.target.value),placeholder:"my-plugin.ts","aria-invalid":I||void 0,disabled:j}),I&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r("settings.plugins.validation.fileName")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-content",className:"typography-ui-label text-foreground",children:r("settings.plugins.page.field.content")}),s.jsx(un,{id:"plugin-content",value:x,onChange:R=>y(R.target.value),rows:16,className:"font-mono",disabled:j})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.plugins.page.field.scope")}),s.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(R=>{const V=g===R,B=r(R==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>h(R),disabled:j,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(Fa,{checked:V,onChange:()=>h(R),ariaLabel:B}),s.jsx("span",{className:ye("typography-ui-label font-normal",V?"text-foreground":"text-foreground/60"),children:B})]},R)})})]})]}),s.jsxs(_s,{children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:j,children:r("settings.plugins.dialog.add.action.cancel")}),s.jsxs(be,{size:"sm",onClick:()=>{M()},disabled:S,children:[j?s.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,r("settings.plugins.dialog.add.action.submit")]})]})]})})},w3=t=>{const e=ot.c(33),{spec:n}=t;let r;e[0]!==n?(r=c=>c.registryInfo[n],e[0]=n,e[1]=r):r=e[1];const a=In(r),{t:i}=ft();if(!a)return null;const o=j3;switch(a.kind){case"npm-ok":{if(!a.hasUpdate||!a.latestVersion)return null;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=c):c=e[2];let d;e[3]!==a.latestVersion?(d=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[c,a.latestVersion]}),e[3]=a.latestVersion,e[4]=d):d=e[4];let p;return e[5]!==a.currentVersion||e[6]!==a.latestVersion||e[7]!==i||e[8]!==d?(p=o(d,i("settings.plugins.registry.badge.update.tooltip",{current:a.currentVersion??"",latest:a.latestVersion})),e[5]=a.currentVersion,e[6]=a.latestVersion,e[7]=i,e[8]=d,e[9]=p):p=e[9],p}case"npm-missing-version":{let c;e[10]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=c):c=e[10];let d;return e[11]!==a.currentVersion||e[12]!==a.name||e[13]!==i?(d=o(c,i("settings.plugins.registry.badge.missingVersion.tooltip",{version:a.currentVersion,name:a.name})),e[11]=a.currentVersion,e[12]=a.name,e[13]=i,e[14]=d):d=e[14],d}case"npm-missing-package":{let c;e[15]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=c):c=e[15];let d;return e[16]!==a.name||e[17]!==i?(d=o(c,i("settings.plugins.registry.badge.missingPackage.tooltip",{name:a.name})),e[16]=a.name,e[17]=i,e[18]=d):d=e[18],d}case"npm-malformed":{let c;e[19]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=c):c=e[19];let d;return e[20]!==i?(d=o(c,i("settings.plugins.registry.badge.malformed.tooltip")),e[20]=i,e[21]=d):d=e[21],d}case"npm-network":{let c;e[22]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=c):c=e[22];let d;return e[23]!==i?(d=o(c,i("settings.plugins.registry.badge.network.tooltip")),e[23]=i,e[24]=d):d=e[24],d}case"path-missing":{let c;e[25]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=c):c=e[25];let d;return e[26]!==a.absolutePath||e[27]!==i?(d=o(c,i("settings.plugins.registry.badge.pathMissing.tooltip",{path:a.absolutePath})),e[26]=a.absolutePath,e[27]=i,e[28]=d):d=e[28],d}case"path-unreadable":{let c;e[29]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(A,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=c):c=e[29];let d;return e[30]!==a.absolutePath||e[31]!==i?(d=o(c,i("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:a.absolutePath})),e[30]=a.absolutePath,e[31]=i,e[32]=d):d=e[32],d}case"path-ok":return null;default:return null}};function j3(t,e){return s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(It,{children:e})]})}const vu=t=>{const e=ot.c(26),{header:n,footer:r,children:a,className:i,variant:o}=t,c=o===void 0?"sidebar":o,d=fn(),p=l.useRef(null),[m,u]=l.useState(!1),[f,b]=l.useState(!1),x=c==="background"||d?"bg-background":"bg-sidebar",y=x==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{const S=p.current;if(!S){u(!1),b(!1);return}if(!(S.scrollHeight>S.clientHeight+1)){u(!1),b(!1);return}u(S.scrollTop>1),b(S.scrollTop+S.clientHeight<S.scrollHeight-1)},e[0]=g):g=e[0];const h=g;let j;e[1]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{h()},e[1]=j):j=e[1];let v;e[2]!==a?(v=[a,h],e[2]=a,e[3]=v):v=e[3],l.useEffect(j,v);let C,k;e[4]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{const S=p.current;if(!S)return;const M=()=>h();return S.addEventListener("scroll",M,{passive:!0}),()=>S.removeEventListener("scroll",M)},k=[h],e[4]=C,e[5]=k):(C=e[4],k=e[5]),l.useEffect(C,k);let w;e[6]!==x||e[7]!==i?(w=ye("flex h-full flex-col",x,i),e[6]=x,e[7]=i,e[8]=w):w=e[8];let N;e[9]!==a?(N=s.jsx(Ss,{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]=N):N=e[10];let I;e[11]!==y||e[12]!==m?(I=m&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${y} 0%, transparent 100%)`}}),e[11]=y,e[12]=m,e[13]=I):I=e[13];let T;e[14]!==y||e[15]!==f?(T=f&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${y} 0%, transparent 100%)`}}),e[14]=y,e[15]=f,e[16]=T):T=e[16];let P;e[17]!==T||e[18]!==N||e[19]!==I?(P=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[N,I,T]}),e[17]=T,e[18]=N,e[19]=I,e[20]=P):P=e[20];let D;return e[21]!==r||e[22]!==n||e[23]!==P||e[24]!==w?(D=s.jsxs("div",{className:w,children:[n,P,r]}),e[21]=r,e[22]=n,e[23]=P,e[24]=w,e[25]=D):D=e[25],D},Ul=t=>{const e=ot.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=ye("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",u,d),e[0]=d,e[1]=u,e[2]=f):f=e[2];let b;e[3]!==n?(b=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n}),e[3]=n,e[4]=b):b=e[4];let x;e[5]!==o||e[6]!==b?(x=s.jsxs("div",{className:"flex items-center gap-1.5",children:[o,b]}),e[5]=o,e[6]=b,e[7]=x):x=e[7];let y;e[8]!==r?(y=r&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:r}),e[8]=r,e[9]=y):y=e[9];let g;e[10]!==i||e[11]!==x||e[12]!==y?(g=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:[x,y]}),e[10]=i,e[11]=x,e[12]=y,e[13]=g):g=e[13];let h;e[14]!==c||e[15]!==m?(h=m&&s.jsxs(As,{children:[s.jsx(Is,{asChild:!0,children:s.jsx(be,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ps,{align:"end",className:"w-fit min-w-20",children:c.map(N3)})]}),e[14]=c,e[15]=m,e[16]=h):h=e[16];let j;e[17]!==g||e[18]!==h?(j=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[g,h]}),e[17]=g,e[18]=h,e[19]=j):j=e[19];let v;return e[20]!==f||e[21]!==j?(v=s.jsx("div",{className:f,children:j}),e[20]=f,e[21]=j,e[22]=v):v=e[22],v};function N3(t){const e=t.icon;return s.jsxs(_t,{onClick:n=>{n.stopPropagation(),t.onClick()},className:ye(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(A,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const S3=t=>t.parsedKind==="npm"?"code-box":"folder",k3=t=>{const e=ot.c(142),{onItemSelect:n,onAddClick:r}=t,{t:a}=ft(),{entries:i,files:o,selectedId:c,setSelected:d,deleteEntry:p,deleteFile:m,loadPlugins:u}=In(Gn(C3)),f=In(I3),b=In(P3),x=In(A3),y=In(D3),[g,h]=l.useState(null),[j,v]=l.useState(!1),[C,k]=l.useState(!1);let w,N;e[0]!==u?(w=()=>{u()},N=[u],e[0]=u,e[1]=w,e[2]=N):(w=e[1],N=e[2]),l.useEffect(w,N);let I;if(e[3]!==i||e[4]!==f){I={userEntries:0,projectEntries:0};for(const Be of i){const nt=f[Be.spec];nt?.kind==="npm-ok"&&nt.hasUpdate&&(Be.scope==="user"?I.userEntries=I.userEntries+1:Be.scope==="project"&&(I.projectEntries=I.projectEntries+1))}e[3]=i,e[4]=f,e[5]=I}else I=e[5];const T=I;let P;e[6]!==i?(P=i.filter(T3),e[6]=i,e[7]=P):P=e[7];const D=P;let S;e[8]!==i?(S=i.filter(E3),e[8]=i,e[9]=S):S=e[9];const M=S;let E;e[10]!==o?(E=o.filter(M3),e[10]=o,e[11]=E):E=e[11];const R=E;let V;e[12]!==o?(V=o.filter(R3),e[12]=o,e[13]=V):V=e[13];const B=V,$=i.length+o.length,O=$===0;let _;e[14]!==r?(_=()=>{r?r():k(!0)},e[14]=r,e[15]=_):_=e[15];const q=_;let L;e[16]!==n||e[17]!==d?(L=Be=>{d(Be),n?.()},e[16]=n,e[17]=d,e[18]=L):L=e[18];const J=L;let Z;e[19]!==i||e[20]!==f||e[21]!==a||e[22]!==y?(Z=async Be=>{const nt=i.find(Le=>Le.id===Be);if(!nt)return;const Ge=f[nt.spec];if(!Ge||Ge.kind!=="npm-ok"||!Ge.hasUpdate||!Ge.latestVersion)return;const at=Ge.latestVersion;(await y(Be)).ok?H.success(a("settings.plugins.toast.updatedToLatest",{version:at})):H.error(a("settings.plugins.toast.refreshFailed"))},e[19]=i,e[20]=f,e[21]=a,e[22]=y,e[23]=Z):Z=e[23];const ie=Z;let ne;e[24]!==x||e[25]!==a?(ne=async()=>{H.info(a("settings.plugins.toast.refreshing"));try{await x({force:!0})}catch{H.error(a("settings.plugins.toast.refreshFailed"))}},e[24]=x,e[25]=a,e[26]=ne):ne=e[26];const me=ne;let pe;e[27]!==p||e[28]!==m||e[29]!==g||e[30]!==a?(pe=async()=>{if(!g)return;v(!0);const Be=g.kind==="entry"?await p(g.id):await m(g.id);Be.ok?H.success(Be.message||a("settings.plugins.sidebar.toast.deleted",{name:g.label})):H.error(a("settings.plugins.sidebar.toast.deleteFailed")),h(null),v(!1)},e[27]=p,e[28]=m,e[29]=g,e[30]=a,e[31]=pe):pe=e[31];const G=pe;let K;e[32]!==J||e[33]!==ie||e[34]!==f||e[35]!==c||e[36]!==a?(K=Be=>{const nt=f[Be.spec],Ge=nt?.kind==="npm-ok"&&nt.hasUpdate&&!!nt.latestVersion,at=[];return Ge&&at.push({label:a("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{ie(Be.id)}}),at.push({label:a("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>h({kind:"entry",id:Be.id,label:Be.spec})}),s.jsx(Ul,{title:s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Be.spec}),s.jsx(w3,{spec:Be.spec})]}),metadata:Be.parsedKind==="npm"?a("settings.plugins.sidebar.kind.npm"):a("settings.plugins.sidebar.kind.path"),selected:c===Be.id,onSelect:()=>J(Be.id),icon:s.jsx(A,{name:S3(Be),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:at},Be.id)},e[32]=J,e[33]=ie,e[34]=f,e[35]=c,e[36]=a,e[37]=K):K=e[37];const Q=K;let W;e[38]!==J||e[39]!==c||e[40]!==a?(W=Be=>s.jsx(Ul,{title:Be.fileName,metadata:a("settings.plugins.sidebar.kind.file"),selected:c===Be.id,onSelect:()=>J(Be.id),icon:s.jsx(A,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:a("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>h({kind:"file",id:Be.id,label:Be.fileName})}]},Be.id),e[38]=J,e[39]=c,e[40]=a,e[41]=W):W=e[41];const de=W;let ge;e[42]!==a?(ge=(Be,nt,Ge)=>{const at=Ge===void 0?0:Ge;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[Be,at>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:a(at===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:at})})]}),nt]})},e[42]=a,e[43]=ge):ge=e[43];const ve=ge;let te;e[44]!==a?(te=a("settings.plugins.sidebar.title"),e[44]=a,e[45]=te):te=e[45];let he;e[46]!==te?(he=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:"text-base font-semibold text-foreground",children:te})}),e[46]=te,e[47]=he):he=e[47];let ce;e[48]!==a||e[49]!==$?(ce=a("settings.plugins.sidebar.total",{count:$}),e[48]=a,e[49]=$,e[50]=ce):ce=e[50];let xe;e[51]!==ce?(xe=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ce}),e[51]=ce,e[52]=xe):xe=e[52];let se;e[53]!==me?(se=()=>{me()},e[53]=me,e[54]=se):se=e[54];let ue;e[55]!==a?(ue=a("settings.plugins.sidebar.actions.refresh"),e[55]=a,e[56]=ue):ue=e[56];let Y;e[57]!==a?(Y=a("settings.plugins.sidebar.actions.refresh"),e[57]=a,e[58]=Y):Y=e[58];const Se=b?"size-4 animate-spin":"size-4";let fe;e[59]!==Se?(fe=s.jsx(A,{name:"refresh",className:Se}),e[59]=Se,e[60]=fe):fe=e[60];let Ce;e[61]!==b||e[62]!==se||e[63]!==ue||e[64]!==Y||e[65]!==fe?(Ce=s.jsx(be,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:se,disabled:b,"aria-label":ue,title:Y,children:fe}),e[61]=b,e[62]=se,e[63]=ue,e[64]=Y,e[65]=fe,e[66]=Ce):Ce=e[66];let Ie;e[67]!==a?(Ie=a("settings.plugins.sidebar.actions.addTitle"),e[67]=a,e[68]=Ie):Ie=e[68];let ke;e[69]!==a?(ke=a("settings.plugins.sidebar.actions.addTitle"),e[69]=a,e[70]=ke):ke=e[70];let X;e[71]===Symbol.for("react.memo_cache_sentinel")?(X=s.jsx(A,{name:"add",className:"size-4"}),e[71]=X):X=e[71];let ae;e[72]!==q||e[73]!==Ie||e[74]!==ke?(ae=s.jsx(be,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:q,"aria-label":Ie,title:ke,children:X}),e[72]=q,e[73]=Ie,e[74]=ke,e[75]=ae):ae=e[75];let je;e[76]!==Ce||e[77]!==ae?(je=s.jsxs("div",{className:"flex items-center gap-1",children:[Ce,ae]}),e[76]=Ce,e[77]=ae,e[78]=je):je=e[78];let le;e[79]!==xe||e[80]!==je?(le=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[xe,je]}),e[79]=xe,e[80]=je,e[81]=le):le=e[81];let Ne;e[82]!==he||e[83]!==le?(Ne=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[he,le]}),e[82]=he,e[83]=le,e[84]=Ne):Ne=e[84];let Me;e[85]!==O||e[86]!==M||e[87]!==B||e[88]!==Q||e[89]!==de||e[90]!==ve||e[91]!==a||e[92]!==T||e[93]!==D||e[94]!==R?(Me=O?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(A,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.plugins.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.plugins.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[D.length>0&&ve(a("settings.plugins.sidebar.group.userEntries"),D.map(Q),T.userEntries),R.length>0&&ve(a("settings.plugins.sidebar.group.userFiles"),R.map(de)),M.length>0&&ve(a("settings.plugins.sidebar.group.projectEntries"),M.map(Q),T.projectEntries),B.length>0&&ve(a("settings.plugins.sidebar.group.projectFiles"),B.map(de))]}),e[85]=O,e[86]=M,e[87]=B,e[88]=Q,e[89]=de,e[90]=ve,e[91]=a,e[92]=T,e[93]=D,e[94]=R,e[95]=Me):Me=e[95];let Ve;e[96]!==Ne||e[97]!==Me?(Ve=s.jsx(vu,{variant:"background",header:Ne,children:Me}),e[96]=Ne,e[97]=Me,e[98]=Ve):Ve=e[98];let we;e[99]!==C?(we=s.jsx(v3,{open:C,onOpenChange:k}),e[99]=C,e[100]=we):we=e[100];const ee=g!==null;let F;e[101]!==j?(F=Be=>{!Be&&!j&&h(null)},e[101]=j,e[102]=F):F=e[102];let U;e[103]!==a?(U=a("settings.plugins.sidebar.deleteDialog.title"),e[103]=a,e[104]=U):U=e[104];let oe;e[105]!==U?(oe=s.jsx(ms,{children:U}),e[105]=U,e[106]=oe):oe=e[106];const Te=g?.label??"";let Oe;e[107]!==a||e[108]!==Te?(Oe=a("settings.plugins.sidebar.deleteDialog.description",{name:Te}),e[107]=a,e[108]=Te,e[109]=Oe):Oe=e[109];let Pe;e[110]!==Oe?(Pe=s.jsx(Ns,{children:Oe}),e[110]=Oe,e[111]=Pe):Pe=e[111];let z;e[112]!==oe||e[113]!==Pe?(z=s.jsxs(hs,{children:[oe,Pe]}),e[112]=oe,e[113]=Pe,e[114]=z):z=e[114];let De;e[115]===Symbol.for("react.memo_cache_sentinel")?(De=()=>h(null),e[115]=De):De=e[115];let Qe;e[116]!==a?(Qe=a("settings.common.actions.cancel"),e[116]=a,e[117]=Qe):Qe=e[117];let et;e[118]!==j||e[119]!==Qe?(et=s.jsx(be,{size:"sm",variant:"ghost",onClick:De,disabled:j,children:Qe}),e[118]=j,e[119]=Qe,e[120]=et):et=e[120];let Ze;e[121]!==j||e[122]!==a?(Ze=a(j?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[121]=j,e[122]=a,e[123]=Ze):Ze=e[123];let We;e[124]!==G||e[125]!==j||e[126]!==Ze?(We=s.jsx(be,{size:"sm",variant:"destructive",onClick:G,disabled:j,children:Ze}),e[124]=G,e[125]=j,e[126]=Ze,e[127]=We):We=e[127];let it;e[128]!==et||e[129]!==We?(it=s.jsxs(_s,{children:[et,We]}),e[128]=et,e[129]=We,e[130]=it):it=e[130];let qe;e[131]!==z||e[132]!==it?(qe=s.jsxs(ds,{className:"max-w-md",children:[z,it]}),e[131]=z,e[132]=it,e[133]=qe):qe=e[133];let st;e[134]!==ee||e[135]!==F||e[136]!==qe?(st=s.jsx(us,{open:ee,onOpenChange:F,children:qe}),e[134]=ee,e[135]=F,e[136]=qe,e[137]=st):st=e[137];let Je;return e[138]!==Ve||e[139]!==we||e[140]!==st?(Je=s.jsxs(s.Fragment,{children:[Ve,we,st]}),e[138]=Ve,e[139]=we,e[140]=st,e[141]=Je):Je=e[141],Je};function C3(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function I3(t){return t.registryInfo}function P3(t){return t.isLoadingRegistry}function A3(t){return t.loadRegistryInfo}function D3(t){return t.updateToLatest}function T3(t){return t.scope==="user"}function E3(t){return t.scope==="project"}function M3(t){return t.scope==="user"}function R3(t){return t.scope==="project"}const Wl=t=>{const e=ot.c(10),{children:n,className:r,outerClassName:a}=t;let i;e[0]!==a?(i=ye("h-full",a),e[0]=a,e[1]=i):i=e[1];let o;e[2]!==r?(o=ye("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(Ss,{outerClassName:i,className:"w-full",children:c}),e[7]=i,e[8]=c,e[9]=d):d=e[9],d},F3=({entryId:t,spec:e})=>{const{t:n}=ft(),r=In(u=>u.registryInfo[e]),a=In(u=>u.updateToLatest),[i,o]=l.useState(!1);if(!r)return null;if(r.kind==="npm-ok"){if(!r.hasUpdate||!r.latestVersion)return null;const u=r.latestVersion,f=r.currentVersion??"",b=async()=>{o(!0);try{(await a(t)).ok?H.success(n("settings.plugins.toast.updatedToLatest",{version:u})):H.error(n("settings.plugins.toast.refreshFailed"))}finally{o(!1)}};return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(A,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:n("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:n("settings.plugins.registry.banner.updateAvailable.description",{current:f,latest:u})})]}),s.jsx(be,{variant:"default",size:"sm",onClick:()=>{b()},disabled:i,children:n("settings.plugins.registry.banner.updateAvailable.action",{latest:u})})]})}if(r.kind==="path-ok")return null;if(r.kind==="npm-network")return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(A,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),s.jsx("div",{className:"flex-1 min-w-0",children:s.jsx("p",{className:"typography-micro text-muted-foreground",children:n("settings.plugins.registry.badge.network.tooltip")})})]});const c=r.kind==="path-unreadable",d=c?"var(--status-warning)":"var(--status-error)",p=c?"alert":"error-warning",m=(()=>{switch(r.kind){case"npm-missing-version":return n("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return n("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return n("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return n("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return n("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(A,{name:p,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:d}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:d},children:n("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:m})]})]})};function O3(t){const e=t.trim();if(e.length===0)return{ok:!0,value:void 0};try{const n=JSON.parse(e);return n===null||typeof n!="object"||Array.isArray(n)?{ok:!1}:{ok:!0,value:n}}catch{return{ok:!1}}}function Fg(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function _p(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Fg(t.options),fileName:"",content:""}}function Bp(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const Vp=t=>{const e=ot.c(4),{scope:n,label:r}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=ye("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=a):a=e[0];let i;return e[1]!==r||e[2]!==n?(i=s.jsx("span",{className:a,"data-scope":n,children:r}),e[1]=r,e[2]=n,e[3]=i):i=e[3],i},L3=()=>{const{t}=ft(),e=In(g=>g.selectedId),n=In(g=>g.entries),r=In(g=>g.files),a=In(g=>g.draft),i=In(g=>g.setDraft),o=In(g=>g.updateEntry),c=In(g=>g.updateFile),d=In(g=>g.readFile),p=l.useMemo(()=>e?n.find(g=>g.id===e)??null:null,[n,e]),m=l.useMemo(()=>e?r.find(g=>g.id===e)??null:null,[r,e]),[u,f]=l.useState(!1),[b,x]=l.useState(!1),y=l.useRef(new Map);if(l.useEffect(()=>{let g=!1;return p?(i(_p(p)),()=>{g=!0}):m?(x(!0),(async()=>{const h=await d(m.id);if(g)return;x(!1);const j=h?.content??"";y.current.set(m.id,j),i(Bp(m,j))})(),()=>{g=!0}):(i(null),()=>{g=!0})},[p,m,d,i]),!e)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(A,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.plugins.page.empty.select")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.plugins.page.empty.add")})]})});if(p&&a&&a.mode==="entry"){const g=O3(a.optionsJson),h=g.ok,j=a.spec!==p.spec||a.optionsJson!==Fg(p.options),v=()=>{i(_p(p))},C=async()=>{if(!h)return;const k=a.spec.trim();if(!k){H.error(t("settings.plugins.validation.specRequired"));return}f(!0);try{const w=await o(p.id,{spec:k,options:g.value});w.ok?w.reloadFailed?H.warning(w.message||t("settings.plugins.toast.reloadFailed"),{description:w.warning}):H.success(w.message||t("settings.plugins.toast.updated")):H.error(w.message||t("settings.plugins.toast.reloadFailed"))}finally{f(!1)}};return s.jsxs(Wl,{children:[s.jsx("div",{children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.plugins.page.header.entry")}),s.jsx(Vp,{scope:p.scope,label:p.scope==="project"?t("settings.plugins.sidebar.group.projectEntries"):t("settings.plugins.sidebar.group.userEntries")})]})}),s.jsx(F3,{entryId:p.id,spec:p.spec}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-meta text-muted-foreground",children:t("settings.plugins.page.field.spec")}),s.jsx(Lt,{value:a.spec,onChange:k=>i({...a,spec:k.target.value}),placeholder:t("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-meta text-muted-foreground",children:t("settings.plugins.page.field.options")}),s.jsx(un,{value:a.optionsJson,onChange:k=>i({...a,optionsJson:k.target.value}),rows:10,className:ye("font-mono typography-meta min-h-[200px]",!h&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!h&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:t("settings.plugins.page.field.options.invalidJson")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{variant:"default",size:"sm",onClick:()=>{C()},disabled:!j||!h||u,children:t("settings.plugins.page.action.save")}),s.jsx(be,{variant:"outline",size:"sm",onClick:v,disabled:!j||u,children:t("settings.plugins.page.action.discard")})]})]})}if(m&&a&&a.mode==="file"){const g=y.current.get(m.id)??"",h=a.content!==g||a.fileName!==m.fileName,j=()=>{(async()=>{x(!0);const k=(await d(m.id))?.content??"";x(!1),y.current.set(m.id,k),i(Bp(m,k))})()},v=async()=>{f(!0);try{const C=await c(m.id,{content:a.content});C.ok?(y.current.set(m.id,a.content),C.reloadFailed?H.warning(C.message||t("settings.plugins.toast.reloadFailed"),{description:C.warning}):H.success(C.message||t("settings.plugins.toast.updated"))):H.error(C.message||t("settings.plugins.toast.reloadFailed"))}finally{f(!1)}};return s.jsxs(Wl,{children:[s.jsx("div",{children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.plugins.page.header.file")}),s.jsx(Vp,{scope:m.scope,label:m.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:ye("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:m.fileName})]})}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-meta text-muted-foreground",children:t("settings.plugins.page.field.content")}),s.jsx(un,{value:a.content,onChange:C=>i({...a,content:C.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:b})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{variant:"default",size:"sm",onClick:()=>{v()},disabled:!h||u||b,children:t("settings.plugins.page.action.save")}),s.jsx(be,{variant:"outline",size:"sm",onClick:j,disabled:u||b,children:t("settings.plugins.page.action.discard")})]})]})}return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(A,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},$3="<built-in>",mi=t=>t?.path===$3,_3=t=>{const e=ot.c(150),{onItemSelect:n}=t,{t:r}=ft(),[a,i]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(!1),[f,b]=l.useState(null),{selectedSkillName:x,skills:y,setSelectedSkill:g,setSkillDraft:h,createSkill:j,deleteSkill:v,getSkillDetail:C}=ha(Gn(B3));let k;e[0]!==n||e[1]!==g||e[2]!==h||e[3]!==y?(k=()=>{let Ge="new-skill",at=1;for(;y.some(Ae=>Ae.name===Ge);)Ge=`new-skill-${at}`,at++;h({name:Ge,scope:"user",source:"opencode",description:""}),g(Ge),n?.()},e[0]=n,e[1]=g,e[2]=h,e[3]=y,e[4]=k):k=e[4];const w=k;let N;e[5]===Symbol.for("react.memo_cache_sentinel")?(N=async Ge=>{mi(Ge)||p(Ge)},e[5]=N):N=e[5];const I=N;let T;e[6]!==d||e[7]!==v||e[8]!==r?(T=async()=>{if(!d)return;if(mi(d)){p(null);return}u(!0),await v(d.name)?(H.success(r("settings.skills.sidebar.toast.skillDeleted",{name:d.name})),p(null)):H.error(r("settings.skills.sidebar.toast.deleteSkillFailed")),u(!1)},e[6]=d,e[7]=v,e[8]=r,e[9]=T):T=e[9];const P=T;let D;e[10]!==C||e[11]!==g||e[12]!==h||e[13]!==y||e[14]!==r?(D=async Ge=>{if(mi(Ge))return;const at=Ge.name;let Ae=1,Le=`${at}-copy`;for(;y.some(Ke=>Ke.name===Le);)Ae++,Le=`${at}-copy-${Ae}`;const ze=await C(Ge.name);if(!ze){H.error(r("settings.skills.sidebar.toast.duplicateLoadFailed"));return}h({name:Le,scope:Ge.scope||"user",source:Ge.source||"opencode",description:(ze.sources.md.fields.includes("description"),""),instructions:""}),g(Le)},e[10]=C,e[11]=g,e[12]=h,e[13]=y,e[14]=r,e[15]=D):D=e[15];const S=D;let M;e[16]===Symbol.for("react.memo_cache_sentinel")?(M=Ge=>{mi(Ge)||(c(Ge.name),i(Ge))},e[16]=M):M=e[16];const E=M;let R;e[17]!==j||e[18]!==v||e[19]!==C||e[20]!==a||e[21]!==o||e[22]!==g||e[23]!==y||e[24]!==r?(R=async()=>{if(!a)return;if(mi(a)){i(null);return}const Ge=o.trim().replace(/\s+/g,"-").toLowerCase();if(!Ge){H.error(r("settings.skills.page.toast.skillNameRequired"));return}if(Ge===a.name){i(null);return}if(y.some(Le=>Le.name===Ge)){H.error(r("settings.skills.page.toast.skillExists"));return}if(!await C(a.name)){H.error(r("settings.skills.sidebar.toast.renameLoadFailed")),i(null);return}await j({name:Ge,description:"Renamed skill",scope:a.scope,source:a.source})?await v(a.name)?(H.success(`Skill renamed to "${Ge}"`),g(Ge)):H.error(r("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):H.error(r("settings.skills.sidebar.toast.renameFailed")),i(null)},e[17]=j,e[18]=v,e[19]=C,e[20]=a,e[21]=o,e[22]=g,e[23]=y,e[24]=r,e[25]=R):R=e[25];const V=R;let B;e[26]!==y?(B=y.filter(V3),e[26]=y,e[27]=B):B=e[27];const $=B;let O;e[28]!==y?(O=y.filter(z3),e[28]=y,e[29]=O):O=e[29];const _=O;let q;e[30]===Symbol.for("react.memo_cache_sentinel")?(q=function(at){const Ae={},Le=[];for(const Ke of at)Ke.group?(Ae[Ke.group]||(Ae[Ke.group]=[]),Ae[Ke.group].push(Ke)):Le.push(Ke);const ze=Object.keys(Ae).sort(U3).map(Ke=>({name:Ke,skills:[...Ae[Ke]].sort(W3)}));return Le.sort(K3),{sortedGroups:ze,ungrouped:Le}},e[30]=q):q=e[30];const L=q;let J;e[31]!==$?(J=L($),e[31]=$,e[32]=J):J=e[32];const Z=J;let ie;e[33]!==_?(ie=L(_),e[33]=_,e[34]=ie):ie=e[34];const ne=ie;let me;e[35]===Symbol.for("react.memo_cache_sentinel")?(me=ye("flex h-full flex-col","bg-background"),e[35]=me):me=e[35];let pe;e[36]!==r?(pe=r("settings.skills.sidebar.title"),e[36]=r,e[37]=pe):pe=e[37];let G;e[38]!==pe?(G=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:pe}),e[38]=pe,e[39]=G):G=e[39];let K;e[40]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(Po,{className:"mb-3"}),e[40]=K):K=e[40];let Q;e[41]!==y.length||e[42]!==r?(Q=r("settings.skills.sidebar.total",{count:y.length}),e[41]=y.length,e[42]=r,e[43]=Q):Q=e[43];let W;e[44]!==Q?(W=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Q}),e[44]=Q,e[45]=W):W=e[45];let de;e[46]===Symbol.for("react.memo_cache_sentinel")?(de=s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[46]=de):de=e[46];let ge;e[47]!==w?(ge=s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:w,children:de}),e[47]=w,e[48]=ge):ge=e[48];let ve;e[49]!==W||e[50]!==ge?(ve=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[W,ge]}),e[49]=W,e[50]=ge,e[51]=ve):ve=e[51];let te;e[52]!==G||e[53]!==ve?(te=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[G,K,ve]}),e[52]=G,e[53]=ve,e[54]=te):te=e[54];let he;e[55]!==Z||e[56]!==ne||e[57]!==S||e[58]!==n||e[59]!==f||e[60]!==$||e[61]!==x||e[62]!==g||e[63]!==y.length||e[64]!==r||e[65]!==_?(he=s.jsx(Ss,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:y.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(A,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.skills.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[$.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.skills.sidebar.section.project")}),Z.sortedGroups.map(Ge=>{const{name:at,skills:Ae}=Ge;return s.jsx(Td,{label:at,count:Ae.length,storageKey:"project-skills",children:Ae.map(Le=>s.jsx(Go,{skill:Le,isSelected:x===Le.name,onSelect:()=>{g(Le.name),n?.()},onRename:()=>E(Le),onDelete:()=>I(Le),onDuplicate:()=>S(Le),isMenuOpen:f===Le.name,onMenuOpenChange:ze=>b(ze?Le.name:null)},Le.name))},at)}),Z.ungrouped.map(Ge=>s.jsx(Go,{skill:Ge,isSelected:x===Ge.name,onSelect:()=>{g(Ge.name),n?.()},onRename:()=>E(Ge),onDelete:()=>I(Ge),onDuplicate:()=>S(Ge),isMenuOpen:f===Ge.name,onMenuOpenChange:at=>b(at?Ge.name:null)},Ge.name))]}),_.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.skills.sidebar.section.user")}),ne.sortedGroups.map(Ge=>{const{name:at,skills:Ae}=Ge;return s.jsx(Td,{label:at,count:Ae.length,storageKey:"user-skills",children:Ae.map(Le=>s.jsx(Go,{skill:Le,isSelected:x===Le.name,onSelect:()=>{g(Le.name),n?.()},onRename:()=>E(Le),onDelete:()=>I(Le),onDuplicate:()=>S(Le),isMenuOpen:f===Le.name,onMenuOpenChange:ze=>b(ze?Le.name:null)},Le.name))},at)}),ne.ungrouped.map(Ge=>s.jsx(Go,{skill:Ge,isSelected:x===Ge.name,onSelect:()=>{g(Ge.name),n?.()},onRename:()=>E(Ge),onDelete:()=>I(Ge),onDuplicate:()=>S(Ge),isMenuOpen:f===Ge.name,onMenuOpenChange:at=>b(at?Ge.name:null)},Ge.name))]})]})}),e[55]=Z,e[56]=ne,e[57]=S,e[58]=n,e[59]=f,e[60]=$,e[61]=x,e[62]=g,e[63]=y.length,e[64]=r,e[65]=_,e[66]=he):he=e[66];const ce=d!==null;let xe;e[67]!==m?(xe=Ge=>{!Ge&&!m&&p(null)},e[67]=m,e[68]=xe):xe=e[68];let se;e[69]!==r?(se=r("settings.skills.sidebar.deleteDialog.title"),e[69]=r,e[70]=se):se=e[70];let ue;e[71]!==se?(ue=s.jsx(ms,{children:se}),e[71]=se,e[72]=ue):ue=e[72];const Y=d?.name??"";let Se;e[73]!==r||e[74]!==Y?(Se=r("settings.skills.sidebar.deleteDialog.description",{name:Y}),e[73]=r,e[74]=Y,e[75]=Se):Se=e[75];let fe;e[76]!==Se?(fe=s.jsx(Ns,{children:Se}),e[76]=Se,e[77]=fe):fe=e[77];let Ce;e[78]!==ue||e[79]!==fe?(Ce=s.jsxs(hs,{children:[ue,fe]}),e[78]=ue,e[79]=fe,e[80]=Ce):Ce=e[80];let Ie;e[81]===Symbol.for("react.memo_cache_sentinel")?(Ie=()=>p(null),e[81]=Ie):Ie=e[81];let ke;e[82]!==r?(ke=r("settings.common.actions.cancel"),e[82]=r,e[83]=ke):ke=e[83];let X;e[84]!==m||e[85]!==ke?(X=s.jsx(be,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Ie,disabled:m,children:ke}),e[84]=m,e[85]=ke,e[86]=X):X=e[86];let ae;e[87]!==r?(ae=r("settings.common.actions.delete"),e[87]=r,e[88]=ae):ae=e[88];let je;e[89]!==P||e[90]!==m||e[91]!==ae?(je=s.jsx(be,{size:"sm",onClick:P,disabled:m,children:ae}),e[89]=P,e[90]=m,e[91]=ae,e[92]=je):je=e[92];let le;e[93]!==X||e[94]!==je?(le=s.jsxs(_s,{children:[X,je]}),e[93]=X,e[94]=je,e[95]=le):le=e[95];let Ne;e[96]!==Ce||e[97]!==le?(Ne=s.jsxs(ds,{className:"max-w-md",children:[Ce,le]}),e[96]=Ce,e[97]=le,e[98]=Ne):Ne=e[98];let Me;e[99]!==ce||e[100]!==xe||e[101]!==Ne?(Me=s.jsx(us,{open:ce,onOpenChange:xe,children:Ne}),e[99]=ce,e[100]=xe,e[101]=Ne,e[102]=Me):Me=e[102];const Ve=a!==null;let we;e[103]===Symbol.for("react.memo_cache_sentinel")?(we=Ge=>!Ge&&i(null),e[103]=we):we=e[103];let ee;e[104]!==r?(ee=r("settings.skills.sidebar.renameDialog.title"),e[104]=r,e[105]=ee):ee=e[105];let F;e[106]!==ee?(F=s.jsx(ms,{children:ee}),e[106]=ee,e[107]=F):F=e[107];const U=a?.name??"";let oe;e[108]!==r||e[109]!==U?(oe=r("settings.skills.sidebar.renameDialog.description",{name:U}),e[108]=r,e[109]=U,e[110]=oe):oe=e[110];let Te;e[111]!==oe?(Te=s.jsx(Ns,{children:oe}),e[111]=oe,e[112]=Te):Te=e[112];let Oe;e[113]!==F||e[114]!==Te?(Oe=s.jsxs(hs,{children:[F,Te]}),e[113]=F,e[114]=Te,e[115]=Oe):Oe=e[115];let Pe;e[116]===Symbol.for("react.memo_cache_sentinel")?(Pe=Ge=>c(Ge.target.value),e[116]=Pe):Pe=e[116];let z;e[117]!==r?(z=r("settings.skills.sidebar.renameDialog.placeholder"),e[117]=r,e[118]=z):z=e[118];let De;e[119]!==V?(De=Ge=>{Ge.key==="Enter"&&V()},e[119]=V,e[120]=De):De=e[120];let Qe;e[121]!==o||e[122]!==z||e[123]!==De?(Qe=s.jsx(Lt,{value:o,onChange:Pe,placeholder:z,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:De}),e[121]=o,e[122]=z,e[123]=De,e[124]=Qe):Qe=e[124];let et;e[125]===Symbol.for("react.memo_cache_sentinel")?(et=()=>i(null),e[125]=et):et=e[125];let Ze;e[126]!==r?(Ze=r("settings.common.actions.cancel"),e[126]=r,e[127]=Ze):Ze=e[127];let We;e[128]!==Ze?(We=s.jsx(be,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:et,children:Ze}),e[128]=Ze,e[129]=We):We=e[129];let it;e[130]!==r?(it=r("settings.common.actions.rename"),e[130]=r,e[131]=it):it=e[131];let qe;e[132]!==V||e[133]!==it?(qe=s.jsx(be,{size:"sm",onClick:V,children:it}),e[132]=V,e[133]=it,e[134]=qe):qe=e[134];let st;e[135]!==We||e[136]!==qe?(st=s.jsxs(_s,{children:[We,qe]}),e[135]=We,e[136]=qe,e[137]=st):st=e[137];let Je;e[138]!==Oe||e[139]!==Qe||e[140]!==st?(Je=s.jsxs(ds,{children:[Oe,Qe,st]}),e[138]=Oe,e[139]=Qe,e[140]=st,e[141]=Je):Je=e[141];let Be;e[142]!==Ve||e[143]!==Je?(Be=s.jsx(us,{open:Ve,onOpenChange:we,children:Je}),e[142]=Ve,e[143]=Je,e[144]=Be):Be=e[144];let nt;return e[145]!==te||e[146]!==he||e[147]!==Me||e[148]!==Be?(nt=s.jsxs("div",{className:me,children:[te,he,Me,Be]}),e[145]=te,e[146]=he,e[147]=Me,e[148]=Be,e[149]=nt):nt=e[149],nt},Go=t=>{const e=ot.c(38),{skill:n,isSelected:r,onSelect:a,onDelete:i,onRename:o,onDuplicate:c,isMenuOpen:d,onMenuOpenChange:p}=t,{t:m}=ft();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=uo(),e[0]=u):u=e[0];const f=u;let b;e[1]!==n.source||e[2]!==m?(b=n.source==="claude"?m("settings.skills.sidebar.badge.claude"):n.source==="agents"?m("settings.skills.sidebar.badge.agents"):m("settings.skills.sidebar.badge.opencode"),e[1]=n.source,e[2]=m,e[3]=b):b=e[3];const x=b;let y;e[4]!==n?(y=mi(n),e[4]=n,e[5]=y):y=e[5];const g=y,h=r?"bg-interactive-selection":"hover:bg-interactive-hover";let j;e[6]!==h?(j=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",h),e[6]=h,e[7]=j):j=e[7];let v;e[8]!==p?(v=f?void 0:S=>{S.preventDefault(),p(!0)},e[8]=p,e[9]=v):v=e[9];let C;e[10]!==n.name?(C=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[10]=n.name,e[11]=C):C=e[11];let k;e[12]!==n.scope?(k=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:n.scope}),e[12]=n.scope,e[13]=k):k=e[13];let w;e[14]!==x?(w=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:x}),e[14]=x,e[15]=w):w=e[15];let N;e[16]!==C||e[17]!==k||e[18]!==w?(N=s.jsxs("div",{className:"flex items-center gap-1.5",children:[C,k,w]}),e[16]=C,e[17]=k,e[18]=w,e[19]=N):N=e[19];let I;e[20]!==a||e[21]!==N?(I=s.jsx("button",{onClick:a,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:N}),e[20]=a,e[21]=N,e[22]=I):I=e[22];let T;e[23]!==g||e[24]!==d||e[25]!==i||e[26]!==c||e[27]!==p||e[28]!==o||e[29]!==m?(T=g?null:s.jsxs(As,{open:d,onOpenChange:p,children:[s.jsx(Is,{asChild:!0,children:s.jsx(be,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs(Ps,{align:"end",className:"w-fit min-w-20",children:[s.jsxs(_t,{onClick:S=>{S.stopPropagation(),o()},children:[s.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}),s.jsxs(_t,{onClick:S=>{S.stopPropagation(),c()},children:[s.jsx(A,{name:"file-copy",className:"h-4 w-4 mr-px"}),m("settings.common.actions.duplicate")]}),s.jsxs(_t,{onClick:S=>{S.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]})]})]}),e[23]=g,e[24]=d,e[25]=i,e[26]=c,e[27]=p,e[28]=o,e[29]=m,e[30]=T):T=e[30];let P;e[31]!==I||e[32]!==T?(P=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[I,T]}),e[31]=I,e[32]=T,e[33]=P):P=e[33];let D;return e[34]!==P||e[35]!==j||e[36]!==v?(D=s.jsx("div",{className:j,onContextMenu:v,children:P}),e[34]=P,e[35]=j,e[36]=v,e[37]=D):D=e[37],D};function B3(t){return{selectedSkillName:t.selectedSkillName,skills:t.skills,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,createSkill:t.createSkill,deleteSkill:t.deleteSkill,getSkillDetail:t.getSkillDetail}}function V3(t){return t.scope==="project"}function z3(t){return t.scope==="user"}function U3(t,e){return t.localeCompare(e)}function W3(t,e){return t.name.localeCompare(e.name)}function K3(t,e){return t.name.localeCompare(e.name)}const H3=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,G3=t=>{const e=t.trim(),n=e.startsWith("https://")?"https":e.startsWith("git@")?"ssh":"shorthand";if(n==="ssh")return`${e.split(":")[1].replace(/\.git$/i,"")}`;if(n==="https")return e.split("/").slice(3).filter(Boolean).join("/").replace(/\.git$/i,"");const r=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return r?`${r[1]}/${r[2].replace(/\.git$/i,"")}`:e},q3=async()=>{try{const t=or()?.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}},J3=t=>{const e=ot.c(158),{open:n,onOpenChange:r}=t,{t:a}=ft(),i=Va(Y3),o=Va(Q3),c=Va(X3),d=tr(Z3),p=tr(e5),[m,u]=l.useState(""),[f,b]=l.useState(""),[x,y]=l.useState("");let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[0]=g):g=e[0];const[h,j]=l.useState(g),[v,C]=l.useState(null),[k,w]=l.useState(!1);let N;e[1]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[1]=N):N=e[1];const[I,T]=l.useState(N),[P,D]=l.useState(null),S=l.useRef(0);let M;e[2]===Symbol.for("react.memo_cache_sentinel")?(M=Be=>{S.current=S.current+1,w(!1),C(null),Be?.clearIdentity&&(T([]),D(null))},e[2]=M):M=e[2];const E=M;let R,V;e[3]!==p||e[4]!==n?(R=()=>{n&&(S.current=S.current+1,u(""),b(""),y(""),C(null),w(!1),T([]),D(null),p(),(async()=>{const Be=await q3(),nt=Array.isArray(Be?.skillCatalogs)?Be?.skillCatalogs:[];j(nt||[])})())},V=[n,p],e[3]=p,e[4]=n,e[5]=R,e[6]=V):(R=e[5],V=e[6]),l.useEffect(R,V);let B;e[7]!==f?(B=f.trim(),e[7]=f,e[8]=B):B=e[8];const $=B;let O;e[9]!==x?(O=x.trim(),e[9]=x,e[10]=O):O=e[10];const _=O;let q;if(e[11]!==h||e[12]!==$||e[13]!==_){let Be;e[15]!==$||e[16]!==_?(Be=nt=>{const Ge=(nt.source||"").trim(),at=(nt.subpath||"").trim();return Ge===$&&at===_},e[15]=$,e[16]=_,e[17]=Be):Be=e[17],q=h.some(Be),e[11]=h,e[12]=$,e[13]=_,e[14]=q}else q=e[14];const L=q;let J;e[18]!==d||e[19]!==P||e[20]!==m||e[21]!==i||e[22]!==f||e[23]!==x||e[24]!==a?(J=async()=>{const Be=f.trim();if(!Be){H.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||u(G3(Be)),w(!1),C(null);const nt=S.current+1;S.current=nt;const Ge=await i({source:Be,subpath:x.trim()||void 0,gitIdentityId:P||void 0});if(S.current!==nt)return;if(!Ge.ok){if(Ge.error?.kind==="authRequired"){if(fn()){H.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const Ae=Ge.error.identities||[];if(T(Ae),!P&&Ae.length>0){const Le=d&&d!=="global"&&Ae.some(ze=>ze.id===d)?d:Ae[0].id;D(Le)}H.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}H.error(Ge.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const at=Ge.items?.length||0;if(C(at),at===0){H.error(a("settings.skills.catalog.add.toast.noSkillsFound")),w(!1);return}T([]),w(!0),H.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:at}))},e[18]=d,e[19]=P,e[20]=m,e[21]=i,e[22]=f,e[23]=x,e[24]=a,e[25]=J):J=e[25];const Z=J;let ie;e[26]!==h||e[27]!==P||e[28]!==L||e[29]!==m||e[30]!==o||e[31]!==r||e[32]!==k||e[33]!==f||e[34]!==x||e[35]!==a?(ie=async()=>{const Be=m.trim(),nt=f.trim(),Ge=x.trim();if(!Be){H.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!nt){H.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!k){H.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(L){H.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const at={id:H3(),label:Be,source:nt,...Ge?{subpath:Ge}:{},...P?{gitIdentityId:P}:{}},Ae=[...h,at];try{await ks({skillCatalogs:Ae}),j(Ae),H.success(a("settings.skills.catalog.add.toast.catalogAdded")),await o({refresh:!0}),r(!1)}catch(Le){const ze=Le;H.error(ze instanceof Error?ze.message:a("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=h,e[27]=P,e[28]=L,e[29]=m,e[30]=o,e[31]=r,e[32]=k,e[33]=f,e[34]=x,e[35]=a,e[36]=ie):ie=e[36];const ne=ie;let me;e[37]!==a?(me=a("settings.skills.catalog.add.title"),e[37]=a,e[38]=me):me=e[38];let pe;e[39]!==me?(pe=s.jsx(ms,{children:me}),e[39]=me,e[40]=pe):pe=e[40];let G;e[41]!==a?(G=a("settings.skills.catalog.add.descriptionPrefix"),e[41]=a,e[42]=G):G=e[42];let K;e[43]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[43]=K):K=e[43];let Q;e[44]!==a?(Q=a("settings.skills.catalog.add.descriptionSuffix"),e[44]=a,e[45]=Q):Q=e[45];let W;e[46]!==G||e[47]!==Q?(W=s.jsxs(Ns,{children:[G," ",K,Q]}),e[46]=G,e[47]=Q,e[48]=W):W=e[48];let de;e[49]!==pe||e[50]!==W?(de=s.jsxs(hs,{children:[pe,W]}),e[49]=pe,e[50]=W,e[51]=de):de=e[51];let ge;e[52]!==a?(ge=a("settings.skills.catalog.add.field.catalogName"),e[52]=a,e[53]=ge):ge=e[53];let ve;e[54]!==ge?(ve=s.jsx("label",{className:"typography-ui-label text-foreground",children:ge}),e[54]=ge,e[55]=ve):ve=e[55];let te;e[56]===Symbol.for("react.memo_cache_sentinel")?(te=Be=>u(Be.target.value),e[56]=te):te=e[56];let he;e[57]!==a?(he=a("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[57]=a,e[58]=he):he=e[58];let ce;e[59]!==m||e[60]!==he?(ce=s.jsx(Lt,{value:m,onChange:te,placeholder:he}),e[59]=m,e[60]=he,e[61]=ce):ce=e[61];let xe;e[62]!==ve||e[63]!==ce?(xe=s.jsxs("div",{className:"space-y-2",children:[ve,ce]}),e[62]=ve,e[63]=ce,e[64]=xe):xe=e[64];let se;e[65]!==a?(se=a("settings.skills.catalog.add.field.repository"),e[65]=a,e[66]=se):se=e[66];let ue;e[67]!==se?(ue=s.jsx("label",{className:"typography-ui-label text-foreground",children:se}),e[67]=se,e[68]=ue):ue=e[68];let Y;e[69]===Symbol.for("react.memo_cache_sentinel")?(Y=Be=>{b(Be.target.value),E({clearIdentity:!0})},e[69]=Y):Y=e[69];let Se;e[70]!==a?(Se=a("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[70]=a,e[71]=Se):Se=e[71];let fe;e[72]!==f||e[73]!==Se?(fe=s.jsx(Lt,{value:f,onChange:Y,placeholder:Se}),e[72]=f,e[73]=Se,e[74]=fe):fe=e[74];let Ce;e[75]!==a?(Ce=a("settings.skills.catalog.add.field.repositoryHint"),e[75]=a,e[76]=Ce):Ce=e[76];let Ie;e[77]!==Ce?(Ie=s.jsx("p",{className:"typography-micro text-muted-foreground",children:Ce}),e[77]=Ce,e[78]=Ie):Ie=e[78];let ke;e[79]!==ue||e[80]!==fe||e[81]!==Ie?(ke=s.jsxs("div",{className:"space-y-2",children:[ue,fe,Ie]}),e[79]=ue,e[80]=fe,e[81]=Ie,e[82]=ke):ke=e[82];let X;e[83]!==a?(X=a("settings.skills.catalog.add.field.optionalSubpath"),e[83]=a,e[84]=X):X=e[84];let ae;e[85]!==X?(ae=s.jsx("label",{className:"typography-ui-label text-foreground",children:X}),e[85]=X,e[86]=ae):ae=e[86];let je;e[87]===Symbol.for("react.memo_cache_sentinel")?(je=Be=>{y(Be.target.value),E({clearIdentity:!0})},e[87]=je):je=e[87];let le;e[88]!==a?(le=a("settings.skills.catalog.shared.field.subpathPlaceholder"),e[88]=a,e[89]=le):le=e[89];let Ne;e[90]!==x||e[91]!==le?(Ne=s.jsx(Lt,{value:x,onChange:je,placeholder:le}),e[90]=x,e[91]=le,e[92]=Ne):Ne=e[92];let Me;e[93]!==ae||e[94]!==Ne?(Me=s.jsxs("div",{className:"space-y-2",children:[ae,Ne]}),e[93]=ae,e[94]=Ne,e[95]=Me):Me=e[95];let Ve;e[96]!==P||e[97]!==I||e[98]!==a?(Ve=I.length>0&&!fn()?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(as,{value:P||"",onValueChange:Be=>{D(Be),E()},children:[s.jsx(is,{className:"w-fit",children:s.jsx("span",{children:I.find(Be=>Be.id===P)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(os,{align:"start",children:I.map(t5)})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[96]=P,e[97]=I,e[98]=a,e[99]=Ve):Ve=e[99];let we;e[100]!==v||e[101]!==a?(we=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]=we):we=e[102];let ee;e[103]!==L||e[104]!==a?(ee=L?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null,e[103]=L,e[104]=a,e[105]=ee):ee=e[105];let F;e[106]!==xe||e[107]!==ke||e[108]!==Me||e[109]!==Ve||e[110]!==we||e[111]!==ee?(F=s.jsxs("div",{className:"space-y-4",children:[xe,ke,Me,Ve,we,ee]}),e[106]=xe,e[107]=ke,e[108]=Me,e[109]=Ve,e[110]=we,e[111]=ee,e[112]=F):F=e[112];let U;e[113]!==r?(U=()=>r(!1),e[113]=r,e[114]=U):U=e[114];let oe;e[115]!==a?(oe=a("settings.common.actions.cancel"),e[115]=a,e[116]=oe):oe=e[116];let Te;e[117]!==U||e[118]!==oe?(Te=s.jsx(be,{size:"sm",variant:"ghost",onClick:U,children:oe}),e[117]=U,e[118]=oe,e[119]=Te):Te=e[119];let Oe;e[120]!==Z?(Oe=()=>{Z()},e[120]=Z,e[121]=Oe):Oe=e[121];let Pe;e[122]!==c||e[123]!==f?(Pe=c||!f.trim(),e[122]=c,e[123]=f,e[124]=Pe):Pe=e[124];let z;e[125]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(A,{name:"git-repository",className:"h-4 w-4"}),e[125]=z):z=e[125];let De;e[126]!==c||e[127]!==a?(De=a(c?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[126]=c,e[127]=a,e[128]=De):De=e[128];let Qe;e[129]!==Oe||e[130]!==Pe||e[131]!==De?(Qe=s.jsxs(be,{size:"sm",className:"gap-2",variant:"ghost",onClick:Oe,disabled:Pe,children:[z,De]}),e[129]=Oe,e[130]=Pe,e[131]=De,e[132]=Qe):Qe=e[132];let et;e[133]!==ne?(et=()=>{ne()},e[133]=ne,e[134]=et):et=e[134];let Ze;e[135]!==L||e[136]!==m||e[137]!==k||e[138]!==f?(Ze=!k||L||!m.trim()||!f.trim(),e[135]=L,e[136]=m,e[137]=k,e[138]=f,e[139]=Ze):Ze=e[139];let We;e[140]!==a?(We=a("settings.skills.catalog.add.actions.addCatalog"),e[140]=a,e[141]=We):We=e[141];let it;e[142]!==et||e[143]!==Ze||e[144]!==We?(it=s.jsx(be,{size:"sm",onClick:et,disabled:Ze,children:We}),e[142]=et,e[143]=Ze,e[144]=We,e[145]=it):it=e[145];let qe;e[146]!==Te||e[147]!==Qe||e[148]!==it?(qe=s.jsxs(_s,{children:[Te,Qe,it]}),e[146]=Te,e[147]=Qe,e[148]=it,e[149]=qe):qe=e[149];let st;e[150]!==de||e[151]!==F||e[152]!==qe?(st=s.jsxs(ds,{className:"max-w-xl",children:[de,F,qe]}),e[150]=de,e[151]=F,e[152]=qe,e[153]=st):st=e[153];let Je;return e[154]!==r||e[155]!==n||e[156]!==st?(Je=s.jsx(us,{open:n,onOpenChange:r,children:st}),e[154]=r,e[155]=n,e[156]=st,e[157]=Je):Je=e[157],Je};function Y3(t){return t.scanRepo}function Q3(t){return t.loadCatalog}function X3(t){return t.isScanning}function Z3(t){return t.defaultGitIdentityId}function e5(t){return t.loadDefaultGitIdentityId}function t5(t){return s.jsx(Mt,{value:t.id,children:t.name},t.id)}const s5=t=>{const e=ot.c(85),{open:n,onOpenChange:r,conflicts:a,onConfirm:i}=t,{t:o}=ft();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 pe={};for(const G of a)pe[G.skillName]="skip";p(pe)},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=pe=>{const G={};for(const K of a)G[K.skillName]=pe;p(G)},e[5]=a,e[6]=f):f=e[6];const b=f;let x;e[7]!==a||e[8]!==d?(x=a.length>0&&a.every(pe=>d[pe.skillName]),e[7]=a,e[8]=d,e[9]=x):x=e[9];const y=x;let g;e[10]!==o?(g=o("settings.skills.catalog.conflicts.title"),e[10]=o,e[11]=g):g=e[11];let h;e[12]!==g?(h=s.jsx(ms,{children:g}),e[12]=g,e[13]=h):h=e[13];let j;e[14]!==o?(j=o("settings.skills.catalog.conflicts.description"),e[14]=o,e[15]=j):j=e[15];let v;e[16]!==j?(v=s.jsx(Ns,{children:j}),e[16]=j,e[17]=v):v=e[17];let C;e[18]!==h||e[19]!==v?(C=s.jsxs(hs,{children:[h,v]}),e[18]=h,e[19]=v,e[20]=C):C=e[20];let k;e[21]!==a.length||e[22]!==o?(k=o("settings.skills.catalog.conflicts.count",{count:a.length}),e[21]=a.length,e[22]=o,e[23]=k):k=e[23];let w;e[24]!==k?(w=s.jsx("span",{className:"typography-meta text-muted-foreground",children:k}),e[24]=k,e[25]=w):w=e[25];let N;e[26]!==b?(N=()=>b("skip"),e[26]=b,e[27]=N):N=e[27];let I;e[28]!==o?(I=o("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=o,e[29]=I):I=e[29];let T;e[30]!==N||e[31]!==I?(T=s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:N,children:I}),e[30]=N,e[31]=I,e[32]=T):T=e[32];let P;e[33]!==b?(P=()=>b("overwrite"),e[33]=b,e[34]=P):P=e[34];let D;e[35]!==o?(D=o("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=o,e[36]=D):D=e[36];let S;e[37]!==P||e[38]!==D?(S=s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:P,children:D}),e[37]=P,e[38]=D,e[39]=S):S=e[39];let M;e[40]!==T||e[41]!==S?(M=s.jsxs("div",{className:"flex items-center gap-2",children:[T,S]}),e[40]=T,e[41]=S,e[42]=M):M=e[42];let E;e[43]!==w||e[44]!==M?(E=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w,M]}),e[43]=w,e[44]=M,e[45]=E):E=e[45];let R;if(e[46]!==a||e[47]!==d||e[48]!==o){let pe;e[50]!==d||e[51]!==o?(pe=G=>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:G.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:o("settings.skills.catalog.conflicts.installedIn",{scope:G.scope==="project"?o("settings.skills.catalog.conflicts.scope.project"):o("settings.skills.catalog.conflicts.scope.user"),source:G.source==="agents"?o("settings.skills.catalog.conflicts.source.agents"):o("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(as,{value:d[G.skillName]||"skip",onValueChange:K=>p(Q=>({...Q,[G.skillName]:K})),children:[s.jsx(is,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(d[G.skillName]||"skip")==="overwrite"?o("settings.skills.catalog.conflicts.decision.overwrite"):o("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(os,{align:"end",children:[s.jsx(Mt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(Mt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},G.skillName),e[50]=d,e[51]=o,e[52]=pe):pe=e[52],R=a.map(pe),e[46]=a,e[47]=d,e[48]=o,e[49]=R}else R=e[49];let V;e[53]!==R?(V=s.jsx("div",{className:"space-y-2",children:R}),e[53]=R,e[54]=V):V=e[54];let B;e[55]!==E||e[56]!==V?(B=s.jsxs("div",{className:"space-y-3",children:[E,V]}),e[55]=E,e[56]=V,e[57]=B):B=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 _;e[62]!==$||e[63]!==O?(_=s.jsx(be,{size:"sm",variant:"ghost",onClick:$,children:O}),e[62]=$,e[63]=O,e[64]=_):_=e[64];let q;e[65]!==d||e[66]!==i?(q=()=>i(d),e[65]=d,e[66]=i,e[67]=q):q=e[67];const L=!y;let J;e[68]!==o?(J=o("settings.skills.catalog.conflicts.actions.continue"),e[68]=o,e[69]=J):J=e[69];let Z;e[70]!==q||e[71]!==L||e[72]!==J?(Z=s.jsx(be,{size:"sm",onClick:q,disabled:L,children:J}),e[70]=q,e[71]=L,e[72]=J,e[73]=Z):Z=e[73];let ie;e[74]!==_||e[75]!==Z?(ie=s.jsxs(_s,{children:[_,Z]}),e[74]=_,e[75]=Z,e[76]=ie):ie=e[76];let ne;e[77]!==C||e[78]!==B||e[79]!==ie?(ne=s.jsxs(ds,{className:"max-w-2xl",children:[C,B,ie]}),e[77]=C,e[78]=B,e[79]=ie,e[80]=ne):ne=e[80];let me;return e[81]!==r||e[82]!==n||e[83]!==ne?(me=s.jsx(us,{open:n,onOpenChange:r,children:ne}),e[81]=r,e[82]=n,e[83]=ne,e[84]=me):me=e[84],me},wu=[{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 ro(t,e){return t==="project"&&e==="claude"?"project-claude":t==="project"&&e==="agents"?"project-agents":e==="claude"?"user-claude":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function Og(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=wu.find(n=>n.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const n5=t=>{const e=ot.c(124),{open:n,onOpenChange:r,item:a}=t,{t:i}=ft(),o=Va(r5),c=Va(a5),[d,p]=l.useState("user"),[m,u]=l.useState("opencode"),f=Cs(i5),b=Cs(o5),[x,y]=l.useState(null),[g,h]=l.useState(!1);let j;e[0]===Symbol.for("react.memo_cache_sentinel")?(j=[],e[0]=j):j=e[0];const[v,C]=l.useState(j),[k,w]=l.useState(null);let N,I;e[1]!==b||e[2]!==n?(N=()=>{n&&(p("user"),u("opencode"),y(b),h(!1),C([]),w(null))},I=[n,b],e[1]=b,e[2]=n,e[3]=N,e[4]=I):(N=e[3],I=e[4]),l.useEffect(N,I);let T;e[5]!==i?(T=we=>{switch(we){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]=T):T=e[6];const P=T;let D;e[7]!==i?(D=we=>{switch(we){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]=D):D=e[8];const S=D;let M;e:{if(f.length===0){M=null;break e}if(x&&f.some(we=>we.id===x)){M=x;break e}if(b&&f.some(we=>we.id===b)){M=b;break e}M=f[0]?.id??null}const E=M;let R;e:{if(d!=="project"){R=null;break e}const we=E;if(!we){R=null;break e}let ee;if(e[9]!==we||e[10]!==f){let U;e[12]!==we?(U=oe=>oe.id===we,e[12]=we,e[13]=U):U=e[13],ee=f.find(U),e[9]=we,e[10]=f,e[11]=ee}else ee=e[11];R=ee?.path??null}const V=R;let B;e[14]!==o||e[15]!==a||e[16]!==r||e[17]!==i?(B=async we=>{const ee={skillDir:we.skillDir};a?.clawdhub&&(ee.clawdhub={slug:a.clawdhub.slug,version:a.clawdhub.version});const F=await o({source:we.source,subpath:we.subpath,gitIdentityId:a?.gitIdentityId,scope:we.scope,targetSource:we.targetSource,selections:[ee],conflictPolicy:"prompt",conflictDecisions:we.conflictDecisions},{directory:we.directoryOverride??null});if(F.ok){H.success(i("settings.skills.catalog.installSkill.toast.installed")),r(!1);return}if(F.error?.kind==="conflicts"){w({source:we.source,subpath:we.subpath,scope:we.scope,targetSource:we.targetSource,skillDir:we.skillDir,directoryOverride:we.directoryOverride??null}),C(F.error.conflicts),h(!0);return}if(F.error?.kind==="authRequired"){H.error(F.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}H.error(F.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=o,e[15]=a,e[16]=r,e[17]=i,e[18]=B):B=e[18];const $=B;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 _;e[21]!==O?(_=s.jsx(ms,{children:O}),e[21]=O,e[22]=_):_=e[22];let q;e[23]!==i?(q=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=q):q=e[24];let L;e[25]!==a.skillName?(L=s.jsx("span",{className:"font-semibold text-foreground",children:a.skillName}),e[25]=a.skillName,e[26]=L):L=e[26];let J;e[27]!==i?(J=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=J):J=e[28];let Z;e[29]!==q||e[30]!==L||e[31]!==J?(Z=s.jsxs(Ns,{children:[q," ",L," ",J]}),e[29]=q,e[30]=L,e[31]=J,e[32]=Z):Z=e[32];let ie;e[33]!==_||e[34]!==Z?(ie=s.jsxs(hs,{children:[_,Z]}),e[33]=_,e[34]=Z,e[35]=ie):ie=e[35];let ne;e[36]!==i?(ne=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=ne):ne=e[37];let me;e[38]!==ne?(me=s.jsx("span",{className:"typography-ui-label text-foreground",children:ne}),e[38]=ne,e[39]=me):me=e[39];let pe;e[40]!==d||e[41]!==m?(pe=ro(d,m),e[40]=d,e[41]=m,e[42]=pe):pe=e[42];let G;e[43]===Symbol.for("react.memo_cache_sentinel")?(G=we=>{const ee=Og(we);p(ee.scope),u(ee.source==="agents"?"agents":"opencode")},e[43]=G):G=e[43];let K;e[44]!==d?(K=d==="user"?s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=d,e[45]=K):K=e[45];let Q;e[46]!==m?(Q=m==="agents"?s.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=Q):Q=e[47];let W;e[48]!==P||e[49]!==d||e[50]!==m?(W=P(ro(d,m)),e[48]=P,e[49]=d,e[50]=m,e[51]=W):W=e[51];let de;e[52]!==W?(de=s.jsx("span",{children:W}),e[52]=W,e[53]=de):de=e[53];let ge;e[54]!==K||e[55]!==Q||e[56]!==de?(ge=s.jsxs(is,{className:"w-fit gap-1.5",children:[K,Q,de]}),e[54]=K,e[55]=Q,e[56]=de,e[57]=ge):ge=e[57];let ve;e[58]!==S||e[59]!==P?(ve=wu.map(we=>s.jsx(Mt,{value:we.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:[we.scope==="user"?s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),we.source==="agents"?s.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:P(we.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:S(we.value)})]})},we.value)),e[58]=S,e[59]=P,e[60]=ve):ve=e[60];let te;e[61]!==ve?(te=s.jsx(os,{align:"start",children:ve}),e[61]=ve,e[62]=te):te=e[62];let he;e[63]!==pe||e[64]!==ge||e[65]!==te?(he=s.jsxs(as,{value:pe,onValueChange:G,children:[ge,te]}),e[63]=pe,e[64]=ge,e[65]=te,e[66]=he):he=e[66];let ce;e[67]!==me||e[68]!==he?(ce=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[me,he]}),e[67]=me,e[68]=he,e[69]=ce):ce=e[69];let xe;e[70]!==f||e[71]!==E||e[72]!==d||e[73]!==i?(xe=d==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.skills.catalog.installSkill.field.project")}),f.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(as,{value:E??"",onValueChange:we=>y(we),disabled:f.length===1,children:[s.jsx(is,{className:"w-fit",children:s.jsx(fs,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(os,{align:"start",children:f.map(l5)})]})]}),e[70]=f,e[71]=E,e[72]=d,e[73]=i,e[74]=xe):xe=e[74];let se;e[75]!==a.warnings?(se=a.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:a.warnings.join(" · ")}):null,e[75]=a.warnings,e[76]=se):se=e[76];let ue;e[77]!==ce||e[78]!==xe||e[79]!==se?(ue=s.jsxs("div",{className:"mt-2 space-y-3",children:[ce,xe,se]}),e[77]=ce,e[78]=xe,e[79]=se,e[80]=ue):ue=e[80];let Y;e[81]!==r?(Y=()=>r(!1),e[81]=r,e[82]=Y):Y=e[82];let Se;e[83]!==i?(Se=i("settings.common.actions.cancel"),e[83]=i,e[84]=Se):Se=e[84];let fe;e[85]!==Y||e[86]!==Se?(fe=s.jsx(be,{size:"sm",variant:"ghost",onClick:Y,children:Se}),e[85]=Y,e[86]=Se,e[87]=fe):fe=e[87];const Ce=c||!a.installable||d==="project"&&!V;let Ie;e[88]!==V||e[89]!==$||e[90]!==a.repoSource||e[91]!==a.repoSubpath||e[92]!==a.skillDir||e[93]!==d||e[94]!==m?(Ie=()=>{$({source:a.repoSource,subpath:a.repoSubpath,scope:d,targetSource:m,skillDir:a.skillDir,directoryOverride:V})},e[88]=V,e[89]=$,e[90]=a.repoSource,e[91]=a.repoSubpath,e[92]=a.skillDir,e[93]=d,e[94]=m,e[95]=Ie):Ie=e[95];let ke;e[96]!==c||e[97]!==i?(ke=i(c?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=c,e[97]=i,e[98]=ke):ke=e[98];let X;e[99]!==Ce||e[100]!==Ie||e[101]!==ke?(X=s.jsx(be,{size:"sm",disabled:Ce,onClick:Ie,children:ke}),e[99]=Ce,e[100]=Ie,e[101]=ke,e[102]=X):X=e[102];let ae;e[103]!==fe||e[104]!==X?(ae=s.jsxs(_s,{children:[fe,X]}),e[103]=fe,e[104]=X,e[105]=ae):ae=e[105];let je;e[106]!==ie||e[107]!==ue||e[108]!==ae?(je=s.jsxs(ds,{className:"max-w-md",children:[ie,ue,ae]}),e[106]=ie,e[107]=ue,e[108]=ae,e[109]=je):je=e[109];let le;e[110]!==r||e[111]!==n||e[112]!==je?(le=s.jsx(us,{open:n,onOpenChange:r,children:je}),e[110]=r,e[111]=n,e[112]=je,e[113]=le):le=e[113];let Ne;e[114]!==k||e[115]!==$?(Ne=we=>{k&&($({source:k.source,subpath:k.subpath,scope:k.scope,targetSource:k.targetSource,skillDir:k.skillDir,conflictDecisions:we,directoryOverride:k.directoryOverride??null}),h(!1))},e[114]=k,e[115]=$,e[116]=Ne):Ne=e[116];let Me;e[117]!==v||e[118]!==g||e[119]!==Ne?(Me=s.jsx(s5,{open:g,onOpenChange:h,conflicts:v,onConfirm:Ne}),e[117]=v,e[118]=g,e[119]=Ne,e[120]=Me):Me=e[120];let Ve;return e[121]!==le||e[122]!==Me?(Ve=s.jsxs(s.Fragment,{children:[le,Me]}),e[121]=le,e[122]=Me,e[123]=Ve):Ve=e[123],Ve};function r5(t){return t.installSkills}function a5(t){return t.isInstalling}function i5(t){return t.projects}function o5(t){return t.activeProjectId}function l5(t){return s.jsx(Mt,{value:t.id,children:t.label||t.path},t.id)}const c5=async()=>{try{const t=or()?.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}},d5=({mode:t,onModeChange:e,showModeTabs:n=!0})=>{const{t:r}=ft(),{sources:a,itemsBySource:i,selectedSourceId:o,setSelectedSource:c,loadCatalog:d,loadSource:p,loadMoreClawdHub:m,isLoadingCatalog:u,isLoadingSource:f,isLoadingMore:b,loadedSourceIds:x,clawdhubHasMoreBySource:y,lastCatalogError:g}=Va(Gn(_=>({sources:_.sources,itemsBySource:_.itemsBySource,selectedSourceId:_.selectedSourceId,setSelectedSource:_.setSelectedSource,loadCatalog:_.loadCatalog,loadSource:_.loadSource,loadMoreClawdHub:_.loadMoreClawdHub,isLoadingCatalog:_.isLoadingCatalog,isLoadingSource:_.isLoadingSource,isLoadingMore:_.isLoadingMore,loadedSourceIds:_.loadedSourceIds,clawdhubHasMoreBySource:_.clawdhubHasMoreBySource,lastCatalogError:_.lastCatalogError}))),[h,j]=l.useState(""),[v,C]=l.useState(!1),[k,w]=l.useState(!1),[N,I]=l.useState(null),[T,P]=l.useState(!1),[D,S]=l.useState(!1);l.useEffect(()=>{d()},[d]),l.useEffect(()=>{o&&(x[o]||p(o))},[o,x,p]);const M=l.useMemo(()=>o?i[o]||[]:[],[i,o]),E=l.useMemo(()=>{const _=h.trim().toLowerCase();return _?M.filter(q=>{const L=q.skillName.toLowerCase(),J=(q.description||"").toLowerCase(),Z=(q.frontmatterName||"").toLowerCase();return L.includes(_)||J.includes(_)||Z.includes(_)}):M},[M,h]),R=l.useMemo(()=>a.find(_=>_.id===o)||null,[a,o]),V=!!(o&&o.startsWith("custom:")),B=R?.source==="clawdhub:registry"||R?.sourceType==="clawdhub",$=!!(o&&(y[o]??!0)),O=async()=>{if(!(!o||!V)){P(!0);try{const _=await c5(),L=(Array.isArray(_?.skillCatalogs)?_?.skillCatalogs:[]).filter(J=>J.id!==o);await ks({skillCatalogs:L}),await d({refresh:!0}),S(!1)}finally{P(!1)}}};return s.jsx(Ss,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsxs("div",{className:"mb-4",children:[n&&s.jsx("div",{className:"mb-4",children:s.jsx("div",{className:"h-10",children:s.jsx(Er,{items:[{id:"manual",label:r("settings.skills.catalog.page.mode.manual")},{id:"external",label:r("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:_=>e(_),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground px-1",children:r("settings.skills.catalog.page.title")})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:r("settings.skills.catalog.page.section.sourceRepository")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsxs(as,{value:o||"",onValueChange:_=>c(_),children:[s.jsx(is,{className:"w-fit",children:s.jsx(fs,{placeholder:r("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:R?.label})}),s.jsx(os,{align:"start",children:a.map(_=>s.jsx(Mt,{value:_.id,children:_.label},_.id))})]}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{o?p(o,{refresh:!0}):d({refresh:!0})},disabled:u||f,title:r("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(A,{name:"refresh",className:ye("h-3.5 w-3.5",(u||f)&&"animate-spin")})}),V&&s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>S(!0),disabled:T,title:r("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(be,{size:"xs",className:"!font-normal gap-1",onClick:()=>C(!0),children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"})," ",r("settings.skills.catalog.page.actions.addCatalog")]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsxs("div",{className:"relative",children:[s.jsx(A,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Lt,{value:h,onChange:_=>j(_.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:E.length})})]})]})]}),g&&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:g.message})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("section",{className:"px-2 pb-2 pt-0",children:E.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(A,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:r("settings.skills.catalog.page.loading.skills")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:E.map(_=>{const q=_.installed?.isInstalled,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:_.skillName}),q&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:r("settings.skills.catalog.page.badge.installed",{scope:L||r("settings.skills.catalog.page.badge.unknown")})}),!_.installable&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:r("settings.skills.catalog.page.badge.notInstallable")})]}),_.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:_.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:r("settings.skills.catalog.shared.noDescription")}),_.clawdhub&&s.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[_.clawdhub.owner&&s.jsxs("span",{children:[r("settings.skills.catalog.page.byOwnerPrefix")," ",s.jsx("span",{className:"font-medium text-foreground/80",children:_.clawdhub.owner})]}),s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(A,{name:"download",className:"h-3 w-3"}),_.clawdhub.downloads?.toLocaleString()??0]}),(_.clawdhub.stars??0)>0&&s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(A,{name:"star",className:"h-3 w-3"}),_.clawdhub.stars]}),s.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",_.clawdhub.version]})]}),_.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] mt-1.5 bg-[var(--status-warning)]/10 px-2 py-1 rounded w-fit",children:_.warnings.join(" · ")}):null]}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!_.installable,onClick:()=>{I(_),w(!0)},children:r("settings.skills.catalog.shared.actions.install")})]})},`${_.sourceId}:${_.skillDir}`)})})}),B&&$&&!f&&E.length>0&&s.jsx("div",{className:"flex justify-center mt-2 px-2",children:s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:b,children:r(b?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]}),s.jsx(J3,{open:v,onOpenChange:C}),s.jsx(n5,{open:k,onOpenChange:w,item:N}),s.jsx(us,{open:D,onOpenChange:_=>{T||S(_)},children:s.jsxs(ds,{className:"max-w-md",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:r("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Ns,{children:r("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(_s,{children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>S(!1),disabled:T,children:r("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",variant:"destructive",onClick:()=>{O()},disabled:T,children:r("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})},u5=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(d5,{mode:"external",onModeChange:x5,showModeTabs:!1}),t[0]=e):e=t[0],e},m5="SKILL.md",p5="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",bl=(t,e)=>{const n=Gx({description:t}).trimEnd(),r=e.trimStart();return`---
|
|
176
|
-
${n}
|
|
177
|
-
---${r?`
|
|
178
|
-
|
|
179
|
-
${r}`:`
|
|
180
|
-
`}`},f5=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Lg=t=>{const e=t.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/);if(!e)return{description:null,instructions:t};let n=null;try{const r=qx(e[1]);if(f5(r)){const a=r.description;typeof a=="string"&&(n=a)}}catch{n=null}return{description:n,instructions:e[2].replace(/^\r?\n/,"")}},h5=(t,e)=>{const n=Lg(t);return bl(e,n.instructions)},g5=()=>{const{t}=ft(),{currentTheme:e}=jr(),{selectedSkillName:n,getSkillByName:r,getSkillDetail:a,createSkill:i,updateSkill:o,skills:c,skillDraft:d,setSkillDraft:p,setSelectedSkill:m}=ha(Gn(we=>({selectedSkillName:we.selectedSkillName,getSkillByName:we.getSkillByName,getSkillDetail:we.getSkillDetail,createSkill:we.createSkill,updateSkill:we.updateSkill,skills:we.skills,skillDraft:we.skillDraft,setSkillDraft:we.setSkillDraft,setSelectedSkill:we.setSelectedSkill}))),u=n?r(n):null,f=!!(d&&d.name===n&&!u),b=!!(n&&!u&&!d),x=u?.path==="<built-in>";l.useEffect(()=>{b&&m(null)},[b,m]);const[y,g]=l.useState(""),[h,j]=l.useState("user"),[v,C]=l.useState("opencode"),[k,w]=l.useState(""),[N,I]=l.useState(""),[T,P]=l.useState(()=>bl("","")),[D,S]=l.useState("edit"),[M,E]=l.useState([]),[R,V]=l.useState([]),[B,$]=l.useState(!1),[O,_]=l.useState(!1),[q,L]=l.useState(""),[J,Z]=l.useState(""),[ie,ne]=l.useState(!1),[me,pe]=l.useState(""),[G,K]=l.useState(""),[Q,W]=l.useState(null),[de,ge]=l.useState(!1),[ve,te]=l.useState(""),[he,ce]=l.useState(null),[xe,se]=l.useState(!1),ue=f?y.trim()!==""||k.trim()!==""||N.trim()!==""||R.length>0:k!==q||N!==J,Y=Q?G!==ve:me.trim()!=="",Se=l.useCallback(we=>{switch(we){case"project-opencode":return t("settings.skills.location.option.projectOpencode.label");case"user-claude":return t("settings.skills.location.option.userClaude.label");case"project-claude":return t("settings.skills.location.option.projectClaude.label");case"user-agents":return t("settings.skills.location.option.userAgents.label");case"project-agents":return t("settings.skills.location.option.projectAgents.label");default:return t("settings.skills.location.option.userOpencode.label")}},[t]),fe=l.useCallback(we=>{switch(we){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-claude":return t("settings.skills.location.option.userClaude.description");case"project-claude":return t("settings.skills.location.option.projectClaude.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);l.useEffect(()=>{(async()=>{if(f&&d){const ee=d.description||"",F=d.instructions||"";g(d.name||""),j(d.scope||"user"),C(d.source==="agents"?"agents":"opencode"),w(ee),I(F),P(bl(ee,F)),L(""),Z(""),E([]),V(d.pendingFiles||[])}else if(n&&u){_(!0);try{const ee=await a(n);if(ee){const F=ee.sources.md,U=F.description||"",oe=F.instructions||"";w(U),I(oe),P(bl(U,oe)),L(U),Z(oe),E(F.supportingFiles||[])}}catch(ee){console.error("Failed to load skill details:",ee)}finally{_(!1)}}})()},[u,f,n,c,d,a]);const Ce=l.useMemo(()=>{const we=[vo(e)],ee=Tl(m5);return ee&&we.push(ee),we.push(Ln.lineWrapping),we},[e]),Ie=l.useMemo(()=>{const we=me.trim()||"supporting-file.md",ee=[vo(e)],F=Tl(we);return F&&ee.push(F),ee.push(Ln.lineWrapping),ee},[e,me]),ke=l.useCallback(we=>{w(we),P(ee=>h5(ee,we))},[]),X=l.useCallback(we=>{P(we);const ee=Lg(we);w(ee.description??""),I(ee.instructions)},[]),ae=async()=>{const we=f?y.trim().replace(/\s+/g,"-").toLowerCase():n?.trim();if(!we){H.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(we)||we.length>64){H.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!k.trim()){H.error(t("settings.skills.page.toast.descriptionRequired"));return}if(f&&c.some(ee=>ee.name===we)){H.error(t("settings.skills.page.toast.skillExists"));return}$(!0);try{const ee={name:we,description:k.trim(),instructions:N.trim()||void 0,scope:f?h:void 0,source:f?v:void 0,targetPath:f?void 0:u?.path,supportingFiles:f&&R.length>0?R:void 0};let F;f?(F=await i(ee),F&&(p(null),V([]),m(we))):(F=await o(we,ee),F&&(L(k.trim()),Z(N.trim()))),F?H.success(t(f?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated")):H.error(t(f?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(ee){console.error("Error saving skill:",ee),H.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{$(!1)}},je=()=>{W(null),pe(""),K(""),te(""),ne(!0)},le=async we=>{if(W(we),pe(we),f){const F=R.find(U=>U.path===we)?.content||"";K(F),te(F),ne(!0);return}if(n){ge(!0),ne(!0);try{const{readSupportingFile:ee}=ha.getState(),F=await ee(n,we);K(F||""),te(F||"")}catch{H.error(t("settings.skills.page.toast.loadFileContentFailed")),K(""),te("")}finally{ge(!1)}}},Ne=async()=>{if(!me.trim()){H.error(t("settings.skills.page.toast.fileNameRequired"));return}const we=me.trim(),ee=Q!==null;if(f){if(ee)V(oe=>oe.map(Te=>Te.path===Q?{path:we,content:G}:Te)),H.success(t("settings.skills.page.toast.fileUpdated",{path:we}));else{if(R.some(oe=>oe.path===we)){H.error(t("settings.skills.page.toast.fileExists"));return}V(oe=>[...oe,{path:we,content:G}]),H.success(t("settings.skills.page.toast.fileAdded",{path:we}))}ne(!1),W(null);return}if(!n){H.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:F}=ha.getState();if(await F(n,we,G)){H.success(ee?t("settings.skills.page.toast.fileUpdated",{path:we}):t("settings.skills.page.toast.fileCreated",{path:we})),ne(!1),W(null);const oe=await a(n);oe&&E(oe.sources.md.supportingFiles||[])}else H.error(t(ee?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Me=we=>{if(f){V(ee=>ee.filter(F=>F.path!==we)),H.success(t("settings.skills.page.toast.fileRemoved",{path:we}));return}n&&ce(we)},Ve=async()=>{if(!he||!n)return;se(!0);const{deleteSupportingFile:we}=ha.getState();if(await we(n,he)){H.success(t("settings.skills.page.toast.fileDeleted",{path:he}));const F=await a(n);F&&E(F.sources.md.supportingFiles||[]),ce(null)}else H.error(t("settings.skills.page.toast.deleteFileFailed"));se(!1)};return!n&&!d||b?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(A,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):O?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.skills.page.loading.details")})})}):s.jsxs(Ss,{outerClassName:"h-full",className:"w-full",children:[s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate flex items-center gap-2",children:f?t("settings.skills.page.title.newSkill"):n}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:u?t("settings.skills.page.subtitle.skillLocation",{location:Se(ro(u.scope,u.source))}):t("settings.skills.page.subtitle.newSkill")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.basicInformation")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[f&&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(Lt,{value:y,onChange:we=>g(we.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(as,{value:ro(h,v),onValueChange:we=>{const ee=Og(we);j(ee.scope),C(ee.source==="agents"?"agents":"opencode")},children:[s.jsxs(is,{className:"w-fit gap-1.5",children:[h==="user"?s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),v==="agents"?s.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Se(ro(h,v))})]}),s.jsx(os,{align:"start",children:wu.map(we=>s.jsx(Mt,{value:we.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[we.scope==="user"?s.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),we.source==="agents"?s.jsx(A,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Se(we.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:fe(we.value)})]})},we.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(un,{value:k,onChange:we=>ke(we.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent",disabled:x})})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.instructions")}),s.jsx(Vl,{currentMode:D==="preview"?"preview":"edit",onToggle:()=>S(we=>we==="preview"?"edit":"preview")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx("div",{className:ye("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",p5),children:D==="preview"?s.jsx(Ss,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(ya,{content:T,className:"typography-markdown-body",stripFrontmatter:!0})})}):s.jsx(yo,{value:T,onChange:X,readOnly:x,extensions:Ce,className:"h-full",enableSearch:!0})})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.supportingFiles")}),s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:je,disabled:x,children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:(()=>{const we=f?R:M;return we.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:we.map(ee=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>le(ee.path),children:[s.jsx(A,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ee.path}),f&&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")}),!x&&s.jsx(be,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:F=>{F.stopPropagation(),Me(ee.path)},children:s.jsx(A,{name:"delete-bin",className:"h-3 w-3"})})]},ee.path))})})()})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(be,{onClick:ae,disabled:x||B||!ue,size:"xs",className:"!font-normal",children:t(B?"settings.common.actions.saving":f?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(us,{open:he!==null,onOpenChange:we=>{!we&&!xe&&ce(null)},children:s.jsxs(ds,{className:"max-w-md",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Ns,{children:t("settings.skills.page.deleteFileDialog.description",{path:he??""})})]}),s.jsxs(_s,{children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>ce(null),disabled:xe,children:t("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",variant:"destructive",onClick:Ve,disabled:xe,children:t("settings.common.actions.delete")})]})]})}),s.jsx(us,{open:ie,onOpenChange:we=>{ne(we),we||W(null)},children:s.jsxs(ds,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(hs,{className:"flex-shrink-0",children:[s.jsx(ms,{children:t(Q?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Ns,{children:t(Q?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),de?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(Lt,{value:me,onChange:we=>pe(we.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:Q!==null}),!Q&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground flex-shrink-0",children:t("settings.skills.page.fileDialog.field.content")}),s.jsx("div",{className:"h-[45vh] min-h-[250px] max-h-[55vh] overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",children:s.jsx(yo,{value:G,onChange:K,extensions:Ie,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(_s,{className:"mt-4",children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>{ne(!1),W(null)},children:t("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",onClick:Ne,disabled:de||!Y,children:t(Q?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},zp=t=>{const e=ot.c(2),{view:n}=t,r=n===void 0?"installed":n;let a;return e[0]!==r?(a=r==="catalog"?s.jsx(u5,{}):s.jsx(g5,{}),e[0]=r,e[1]=a):a=e[1],a};function x5(){}const b5=t=>{const e=ot.c(41),{onItemSelect:n}=t,{t:r}=ft(),a=Cs(y5),i=Fe(v5),o=Fe(w5),{currentTheme:c}=jr();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=fn(),e[1]=u):u=e[1];const f=u,b=j5;let x,y;e[2]!==a||e[3]!==i||e[4]!==o?(x=()=>{if(a.length===0){i!==null&&o(null);return}i&&a.some(P=>P.id===i)||o(a[0].id)},y=[a,i,o],e[2]=a,e[3]=i,e[4]=o,e[5]=x,e[6]=y):(x=e[5],y=e[6]),l.useEffect(x,y);let g;e[7]===Symbol.for("react.memo_cache_sentinel")?(g=ye("border-b px-3","pt-4 pb-3"),e[7]=g):g=e[7];let h;e[8]!==r?(h=r("settings.page.projects.title"),e[8]=r,e[9]=h):h=e[9];let j;e[10]!==h?(j=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:h}),e[10]=h,e[11]=j):j=e[11];let v;e[12]!==a.length||e[13]!==r?(v=r("settings.projects.sidebar.total",{count:a.length}),e[12]=a.length,e[13]=r,e[14]=v):v=e[14];let C;e[15]!==v?(C=s.jsx("span",{className:"typography-meta text-muted-foreground",children:v}),e[15]=v,e[16]=C):C=e[16];let k;e[17]!==r?(k=!f&&s.jsx(be,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:b,"aria-label":r("settings.projects.sidebar.actions.addProject"),children:s.jsx(A,{name:"add",className:"size-4"})}),e[17]=r,e[18]=k):k=e[18];let w;e[19]!==k||e[20]!==C?(w=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[C,k]}),e[19]=k,e[20]=C,e[21]=w):w=e[21];let N;e[22]!==w||e[23]!==j?(N=s.jsxs("div",{className:g,children:[j,w]}),e[22]=w,e[23]=j,e[24]=N):N=e[24];let I;if(e[25]!==p||e[26]!==c||e[27]!==n||e[28]!==a||e[29]!==i||e[30]!==o){let P;e[32]!==p||e[33]!==c||e[34]!==n||e[35]!==i||e[36]!==o?(P=D=>{const S=D.id===i,M=D.icon?nc[D.icon]:null,E=`${D.id}:${D.iconImage?.updatedAt??0}`,R=p.has(E)?null:ko(D,{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),V=D.color?Co[D.color]??null:null,B=R?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:D.iconBackground?{backgroundColor:D.iconBackground}:void 0,children:s.jsx("img",{src:R,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>{m($=>{if($.has(E))return $;const O=new Set($);return O.add(E),O})}})}):M?s.jsx(A,{name:M,className:ye("h-4 w-4",S?"text-foreground":"text-muted-foreground/70"),style:V?{color:V}:void 0}):s.jsx(A,{name:"folder",className:ye("h-4 w-4",S?"text-foreground":"text-muted-foreground/70"),style:V?{color:V}:void 0});return s.jsx(Ul,{title:D.label||D.path,icon:B,selected:S,onSelect:()=>{o(D.id),n?.()}},D.id)},e[32]=p,e[33]=c,e[34]=n,e[35]=i,e[36]=o,e[37]=P):P=e[37],I=a.map(P),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 T;return e[38]!==N||e[39]!==I?(T=s.jsx(vu,{variant:"background",header:N,children:I}),e[38]=N,e[39]=I,e[40]=T):T=e[40],T};function y5(t){return t.projects}function v5(t){return t.settingsProjectsSelectedId}function w5(t){return t.setSettingsProjectsSelectedId}function j5(){Dr.requestDirectoryDialog()}const N5=({projectRef:t=null})=>{const{t:e}=ft(),{isMobile:n,isTablet:r}=ln(),a=n||r,i=Cs(M=>M.getActiveProject()),o=t?.path??i?.path??null,c=$t(M=>M.getWorktreeMetadata),d=sc(),p=Ws(M=>M.homeDirectory),[m,u]=l.useState([]),[f,b]=l.useState(!1),[x,y]=l.useState(null),[g,h]=l.useState([]),[j,v]=l.useState(!1),C=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]),k=l.useCallback(async()=>{if(!(!C||x===!1))try{const M=await md(C);h(M)}catch{}},[C,x]);l.useEffect(()=>{if(!o)return;let M=!1;return y(null),(async()=>{try{const E=await Ch(o);if(M)return;y(E)}catch{}})(),()=>{M=!0}},[o]),l.useEffect(()=>{if(!C){h([]),v(!1);return}if(x===!1){h([]),v(!1);return}let M=!1;return v(!0),h([]),(async()=>{try{const E=await md(C);if(M)return;h(E)}catch{}finally{M||v(!1)}})(),()=>{M=!0}},[C,x]),l.useEffect(()=>{if(!C)return;let M=!1;return b(!0),(async()=>{try{const E=await au(C);M||u(E.length>0?E:[""])}catch{M||u([""])}finally{M||b(!1)}})(),()=>{M=!0}},[C]);const w=l.useCallback((M,E)=>{u(R=>{const V=[...R];return V[M]=E,V})},[]),N=l.useCallback(()=>{u(M=>[...M,""])},[]),I=l.useCallback(async M=>{if(!C)return;const E=M.filter(R=>R.trim().length>0);await Ih(C,E)},[C]),T=l.useCallback(M=>{u(E=>{const R=E.filter((V,B)=>B!==M);return I(R),R.length>0?R:[""]})},[I]),P=l.useCallback(()=>{I(m)},[I,m]),D=l.useCallback(M=>{const E=L=>L.replace(/\\/g,"/").replace(/\/+$/,""),R=E(M.path),V=d.filter(L=>{const J=c(L.id);if(J?.path&&E(J.path)===R)return!0;const Z=L.directory;return!!(Z&&E(Z)===R)}),B=new Set(V.map(L=>L.id)),$=L=>{const J=d.filter(ie=>{const ne=ie.parentID;return ne&&L.has(ne)});if(J.length===0)return[];const Z=new Set(J.map(ie=>ie.id));return[...J,...$(Z)]},O=$(B),_=new Set,q=[...V,...O].filter(L=>_.has(L.id)?!1:(_.add(L.id),!0));Dr.requestDelete({sessions:q,mode:"worktree",worktree:M})},[d,c]),S=l.useMemo(()=>d.map(M=>M.id).join(","),[d]);return l.useEffect(()=>{x&&o&&k()},[S,x,o,k]),o?x===!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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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((M,E)=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Lt,{value:M,onChange:R=>w(E,R.target.value),onBlur:P,placeholder:e("settings.openchamber.worktrees.setup.commandPlaceholder"),className:"h-7 w-[30rem] max-w-full font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{T(E)},className:"flex-shrink-0 flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("settings.openchamber.worktrees.setup.removeCommandAria"),children:s.jsx(A,{name:"close",className:"h-4 w-4"})})]},E)),s.jsxs(be,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:N,children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e("settings.openchamber.worktrees.setup.addCommand")]})]})]}),s.jsxs("div",{className:"space-y-2 border-t border-border/40 pt-4",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.openchamber.worktrees.list.title")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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")})]})]})}),j?s.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.list.loading")}):g.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:g.map(M=>s.jsxs("div",{className:"group flex w-full items-center gap-2 py-1.5",children:[s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("p",{className:"typography-meta text-foreground truncate min-w-0",children:M.label||M.branch||e("settings.openchamber.worktrees.list.detachedHead")}),s.jsx("span",{className:"typography-micro text-muted-foreground/60 px-1.5 py-[1px] rounded bg-sidebar-accent/40 flex-shrink-0 self-center leading-none",children:"OpenCode"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground/60 truncate",children:mo(M.path,p)})]}),s.jsx("button",{type:"button",onClick:()=>D(M),className:ye("flex-shrink-0 flex h-7 w-7 items-center justify-center rounded text-muted-foreground/50 hover:text-destructive hover:bg-destructive/10 transition-opacity focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",a?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":e("settings.openchamber.worktrees.list.deleteWorktreeAria",{name:M.branch||M.label||M.path}),children:s.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})]},M.path))})]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.selectProject")})},S5=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,k5=()=>({id:S5(),name:"",command:"",icon:"play"}),C5=({projectRef:t})=>{const{t:e}=ft(),n=l.useMemo(()=>jn(),[]),r=Zs(N=>N.instances),a=Zs(N=>N.load),[i,o]=l.useState([]),[c,d]=l.useState(!1),[p,m]=l.useState(!1),[u,f]=l.useState(null),[b,x]=l.useState({});l.useEffect(()=>{n&&a().catch(()=>{})},[n,a]),l.useEffect(()=>{let N=!1;return d(!0),(async()=>{try{const I=await ud(t);if(N)return;o(I.actions),f(JSON.stringify({actions:I.actions}))}catch{if(N)return;o([]),f(JSON.stringify({actions:[]}))}finally{N||d(!1)}})(),()=>{N=!0}},[t]);const y=l.useMemo(()=>n?Qh(r):[],[r,n]),g=l.useMemo(()=>i.some(I=>I.name.trim().length===0||I.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[i,e]),h=l.useMemo(()=>u===null?!1:u!==JSON.stringify({actions:i}),[i,u]),j=l.useCallback(()=>{const N=k5();o(I=>[...I,N]),x(I=>({...I,[N.id]:!0}))},[]),v=l.useCallback(N=>{o(I=>I.filter(T=>T.id!==N)),x(I=>{const T={...I};return delete T[N],T})},[]),C=l.useCallback((N,I)=>{o(T=>T.map(P=>P.id===N?I(P):P))},[]),k=l.useCallback(async()=>{if(g){H.error(g);return}m(!0);try{if(!await ry(t,{actions:i,primaryActionId:null})){H.error(e("settings.projects.actions.toast.saveFailed"));return}f(JSON.stringify({actions:i})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(yd,{detail:{projectId:t.id}})),H.success(e("settings.projects.actions.toast.saved"))}catch{H.error(e("settings.projects.actions.toast.saveFailed"))}finally{m(!1)}},[i,t,e,g]),w=!p&&!c&&h&&!g;return s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 flex items-start justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e("settings.projects.actions.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.description")})]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:j,children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e("settings.projects.actions.actions.add")]})]}),s.jsxs("section",{className:"pb-2 pt-0 space-y-2",children:[c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.loading")}):i.length===0?s.jsx("div",{className:"py-2",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.empty")})}):s.jsx("div",{className:"space-y-0 max-w-[30rem]",children:i.map(N=>{const I=N.icon||"play",T=dl[I]||"play",P=b[N.id]??!1,D=N.name.trim()||e("settings.projects.actions.state.untitled");return s.jsxs(vr,{open:P,onOpenChange:S=>{x(M=>({...M,[N.id]:S}))},className:ye("py-1.5"),children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs(Mr,{className:"group flex-1 justify-start gap-2 rounded-md px-0 pr-1 py-1 hover:bg-[var(--interactive-hover)] focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",children:[P?s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx(A,{name:T,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:D})})})]}),s.jsx(be,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>v(N.id),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(wr,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-2 pb-6 pl-3 pr-3",children:[s.jsxs("div",{className:"flex items-center gap-2 py-1",children:[s.jsxs(As,{children:[s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-[var(--interactive-border)] text-foreground hover:bg-[var(--interactive-hover)]","aria-label":e("settings.projects.actions.field.selectIconAria"),children:s.jsx(A,{name:T,className:"h-4 w-4"})})}),s.jsx(Ps,{align:"start",className:"w-56 p-2",children:s.jsx("div",{className:"grid grid-cols-6 gap-1",children:Jh.map(S=>{const M=S.Icon,E=(N.icon||"play")===S.key;return s.jsx("button",{type:"button",onClick:()=>C(N.id,R=>({...R,icon:S.key})),className:ye("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",E&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:S.label}),children:s.jsx(A,{name:M,className:"h-4 w-4"})},S.key)})})})]}),s.jsx(Lt,{value:N.name,onChange:S=>C(N.id,M=>({...M,name:S.target.value})),placeholder:e("settings.projects.actions.field.actionNamePlaceholder"),className:"h-7 max-w-[14rem]"})]}),s.jsxs("div",{className:"py-1",children:[s.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.command")}),s.jsx(un,{value:N.command,onChange:S=>C(N.id,M=>({...M,command:S.target.value})),placeholder:e("settings.projects.actions.field.commandPlaceholder"),className:"min-h-[88px] max-w-[30rem] font-mono text-xs"})]}),s.jsxs("div",{className:"py-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.projects.actions.field.autoOpenUrl")}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2",role:"button",tabIndex:0,"aria-pressed":N.autoOpenUrl===!0,onClick:()=>C(N.id,S=>({...S,...S.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:S=>{(S.key===" "||S.key==="Enter")&&(S.preventDefault(),C(N.id,M=>({...M,...M.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[s.jsx(vs,{checked:N.autoOpenUrl===!0,onChange:S=>C(N.id,M=>({...M,...S?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:D})}),s.jsx("span",{className:"typography-ui-label font-normal text-foreground/80",children:e("settings.projects.actions.field.autoOpenUrlDescription")})]})]}),N.autoOpenUrl===!0?s.jsxs("div",{className:"mt-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Lt,{value:N.openUrl||"",onChange:S=>C(N.id,M=>({...M,openUrl:S.target.value})),placeholder:e("settings.projects.actions.field.overrideUrlPlaceholder"),className:"h-7 w-full max-w-[24rem]"}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/60 cursor-help"})}),s.jsx(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")}),y.length>0?s.jsxs(as,{value:N.desktopOpenSshForward&&y.some(S=>S.id===N.desktopOpenSshForward)?N.desktopOpenSshForward:"__none__",onValueChange:S=>{C(N.id,M=>({...M,...S==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:S}}))},children:[s.jsx(is,{className:"h-7 w-full max-w-[30rem]",children:s.jsx(fs,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),s.jsxs(os,{children:[s.jsx(Mt,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),y.map(S=>s.jsx(Mt,{value:S.id,children:S.label},S.id))]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.noDesktopSshForwards")})]}):null]}):null]})]})})]},N.id)})}),s.jsxs("div",{className:"pt-3",children:[g?s.jsx("p",{className:"typography-meta mb-2 text-[var(--status-warning)]",children:g}):null,s.jsx(be,{type:"button",size:"xs",className:"!font-normal",onClick:k,disabled:!w,children:e(p?"settings.common.actions.saving":"settings.projects.actions.actions.save")})]})]})]})},I5=()=>{const t=ot.c(201),{t:e}=ft(),n=Cs(P5),r=Cs(A5),a=Cs(D5),i=Cs(T5),o=Cs(E5),c=Fe(M5),d=Fe(R5),{currentTheme:p}=jr();let m;e:{if(!c){m=null;break e}let St;t[0]!==n||t[1]!==c?(St=n.find(es=>es.id===c)??null,t[0]=n,t[1]=c,t[2]=St):St=t[2],m=St}const u=m;let f,b;t[3]!==n||t[4]!==c||t[5]!==d?(f=()=>{if(n.length===0){d(null);return}c&&n.some(St=>St.id===c)||d(n[0].id)},b=[n,c,d],t[3]=n,t[4]=c,t[5]=d,t[6]=f,t[7]=b):(f=t[6],b=t[7]),l.useEffect(f,b);const[x,y]=l.useState(""),[g,h]=l.useState(null),[j,v]=l.useState(null),[C,k]=l.useState(null),[w,N]=l.useState(!1),[I,T]=l.useState(!1),[P,D]=l.useState(!1),[S,M]=l.useState(!1),[E,R]=l.useState(null),[V,B]=l.useState(null),[$,O]=l.useState(!1),_=l.useRef(null);let q;t[8]===Symbol.for("react.memo_cache_sentinel")?(q=()=>{R(null),B(F5)},t[8]=q):q=t[8];const L=q;let J;e:{if(!u){J=null;break e}let St;t[9]!==u.id||t[10]!==u.path?(St={id:u.id,path:u.path},t[9]=u.id,t[10]=u.path,t[11]=St):St=t[11],J=St}const Z=J;let ie,ne;t[12]!==u?(ie=()=>{if(!u){y(""),h(null),v(null),k(null);return}y(u.label??""),h(u.icon??null),v(u.color??null),k(u.iconBackground??null),M(!1),L(),O(!1)},ne=[u,L],t[12]=u,t[13]=ie,t[14]=ne):(ie=t[13],ne=t[14]),l.useEffect(ie,ne);let me,pe;t[15]===Symbol.for("react.memo_cache_sentinel")?(me=()=>()=>{L()},pe=[L],t[15]=me,t[16]=pe):(me=t[15],pe=t[16]),l.useEffect(me,pe);let G;t[17]!==j||t[18]!==g||t[19]!==C||t[20]!==x||t[21]!==S||t[22]!==E||t[23]!==u?(G=!!u&&(x.trim()!==(u?.label??"").trim()||g!==(u?.icon??null)||j!==(u?.color??null)||C!==(u?.iconBackground??null)||S||!!E),t[17]=j,t[18]=g,t[19]=C,t[20]=x,t[21]=S,t[22]=E,t[23]=u,t[24]=G):G=t[24];const K=G;let Q;t[25]!==j||t[26]!==g||t[27]!==C||t[28]!==x||t[29]!==S||t[30]!==E||t[31]!==i||t[32]!==u||t[33]!==e||t[34]!==r||t[35]!==a?(Q=async()=>{if(!u)return;if(E){N(!0);const es=await a(u.id,E);if(N(!1),!es.ok){H.error(es.error||e("settings.projects.page.toast.uploadIconFailed"));return}H.success(e("settings.projects.page.toast.iconUpdated")),L(),M(!1)}const St=S&&!!u.iconImage;if(St){T(!0);const es=await i(u.id);if(T(!1),!es.ok){H.error(es.error||e("settings.projects.page.toast.removeIconFailed"));return}H.success(e("settings.projects.page.toast.iconRemoved")),M(!1),k(null)}r(u.id,{label:x.trim(),icon:g,color:j,iconBackground:St?null:C})},t[25]=j,t[26]=g,t[27]=C,t[28]=x,t[29]=S,t[30]=E,t[31]=i,t[32]=u,t[33]=e,t[34]=r,t[35]=a,t[36]=Q):Q=t[36];const W=Q,de=j?Co[j]??null:null,ge=!!u?.iconImage,ve=!!(E&&V),te=u?.iconImage?.source==="custom",he=ge&&!S||ve,ce=he;let xe;t[37]!==p||t[38]!==ve||t[39]!==ge||t[40]!==S||t[41]!==V||t[42]!==$||t[43]!==u?(xe=$?null:ve?V:u&&ge&&!S?ko(u,{themeVariant:p.metadata.variant,iconColor:p.colors.surface.foreground}):null,t[37]=p,t[38]=ve,t[39]=ge,t[40]=S,t[41]=V,t[42]=$,t[43]=u,t[44]=xe):xe=t[44];const se=xe;let ue;t[45]!==w||t[46]!==u?(ue=St=>{!u||!St||w||(M(!1),O(!1),R(St),B(es=>(es&&URL.revokeObjectURL(es),URL.createObjectURL(St))))},t[45]=w,t[46]=u,t[47]=ue):ue=t[47];const Y=ue;let Se;t[48]!==ve||t[49]!==ce||t[50]!==ge||t[51]!==I||t[52]!==u?(Se=()=>{!u||!ce||I||(ve&&L(),M(!!ge),O(!1))},t[48]=ve,t[49]=ce,t[50]=ge,t[51]=I,t[52]=u,t[53]=Se):Se=t[53];const fe=Se;let Ce;t[54]!==o||t[55]!==P||t[56]!==u||t[57]!==e?(Ce=async()=>{!u||P||(L(),M(!1),O(!1),D(!0),o(u.id).then(St=>{if(!St.ok){H.error(St.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(St.skipped){H.success(e("settings.projects.page.toast.customIconAlreadySet"));return}H.success(e("settings.projects.page.toast.iconDiscovered"))}).finally(()=>{D(!1)}))},t[54]=o,t[55]=P,t[56]=u,t[57]=e,t[58]=Ce):Ce=t[58];const Ie=Ce;if(!u){let St;t[59]!==e?(St=e("settings.projects.page.empty.noProjects"),t[59]=e,t[60]=St):St=t[60];let es;return t[61]!==St?(es=s.jsx(Ss,{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:St})})}),t[61]=St,t[62]=es):es=t[62],es}let ke;t[63]!==u.label||t[64]!==e?(ke=u.label??e("settings.projects.page.title.default"),t[63]=u.label,t[64]=e,t[65]=ke):ke=t[65];let X;t[66]!==ke?(X=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:ke}),t[66]=ke,t[67]=X):X=t[67];let ae;t[68]!==u.path?(ae=s.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:u.path,children:u.path}),t[68]=u.path,t[69]=ae):ae=t[69];let je;t[70]!==X||t[71]!==ae?(je=s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[X,ae]})}),t[70]=X,t[71]=ae,t[72]=je):je=t[72];let le;t[73]!==e?(le=e("settings.projects.page.field.projectName"),t[73]=e,t[74]=le):le=t[74];let Ne;t[75]!==le?(Ne=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:le})}),t[75]=le,t[76]=Ne):Ne=t[76];let Me;t[77]===Symbol.for("react.memo_cache_sentinel")?(Me=St=>y(St.target.value),t[77]=Me):Me=t[77];let Ve;t[78]!==e?(Ve=e("settings.projects.page.field.projectNamePlaceholder"),t[78]=e,t[79]=Ve):Ve=t[79];let we;t[80]!==x||t[81]!==Ve?(we=s.jsx("div",{className:"mt-1.5 flex min-w-0 items-center gap-2",children:s.jsx(Lt,{value:x,onChange:Me,placeholder:Ve,className:"h-7 min-w-0 w-full sm:max-w-[19rem]"})}),t[80]=x,t[81]=Ve,t[82]=we):we=t[82];let ee;t[83]!==Ne||t[84]!==we?(ee=s.jsxs("div",{className:"py-1.5",children:[Ne,we]}),t[83]=Ne,t[84]=we,t[85]=ee):ee=t[85];let F;t[86]!==e?(F=e("settings.projects.page.field.accentColor"),t[86]=e,t[87]=F):F=t[87];let U;t[88]!==F?(U=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:F})}),t[88]=F,t[89]=U):U=t[89];let oe;t[90]===Symbol.for("react.memo_cache_sentinel")?(oe=()=>v(null),t[90]=oe):oe=t[90];const Te=j===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let Oe;t[91]!==Te?(Oe=ye("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Te),t[91]=Te,t[92]=Oe):Oe=t[92];let Pe;t[93]!==e?(Pe=e("settings.projects.page.field.none"),t[93]=e,t[94]=Pe):Pe=t[94];let z;t[95]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(A,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[95]=z):z=t[95];let De;t[96]!==Oe||t[97]!==Pe?(De=s.jsx("button",{type:"button",onClick:oe,className:Oe,title:Pe,children:z}),t[96]=Oe,t[97]=Pe,t[98]=De):De=t[98];let Qe;t[99]!==j?(Qe=ay.map(St=>s.jsx("button",{type:"button",onClick:()=>v(St.key),className:ye("h-7 w-7 rounded-md border transition-colors",j===St.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:St.cssVar},title:St.label},St.key)),t[99]=j,t[100]=Qe):Qe=t[100];let et;t[101]!==De||t[102]!==Qe?(et=s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[De,Qe]}),t[101]=De,t[102]=Qe,t[103]=et):et=t[103];let Ze;t[104]!==U||t[105]!==et?(Ze=s.jsxs("div",{className:"py-1.5",children:[U,et]}),t[104]=U,t[105]=et,t[106]=Ze):Ze=t[106];let We;t[107]!==e?(We=e("settings.projects.page.field.projectIcon"),t[107]=e,t[108]=We):We=t[108];let it;t[109]!==We?(it=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:We})}),t[109]=We,t[110]=it):it=t[110];let qe;t[111]!==Y?(qe=s.jsx("input",{ref:_,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:St=>{const es=St.target.files?.[0]??null;Y(es),St.currentTarget.value=""}}),t[111]=Y,t[112]=qe):qe=t[112];let st;t[113]===Symbol.for("react.memo_cache_sentinel")?(st=()=>h(null),t[113]=st):st=t[113];const Je=g===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let Be;t[114]!==Je?(Be=ye("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Je),t[114]=Je,t[115]=Be):Be=t[115];let nt;t[116]!==e?(nt=e("settings.projects.page.field.none"),t[116]=e,t[117]=nt):nt=t[117];let Ge;t[118]===Symbol.for("react.memo_cache_sentinel")?(Ge=s.jsx(A,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[118]=Ge):Ge=t[118];let at;t[119]!==Be||t[120]!==nt?(at=s.jsx("button",{type:"button",onClick:st,className:Be,title:nt,children:Ge}),t[119]=Be,t[120]=nt,t[121]=at):at=t[121];let Ae;t[122]!==de||t[123]!==g?(Ae=iy.map(St=>{const es=St.Icon;return s.jsx("button",{type:"button",onClick:()=>h(St.key),className:ye("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",g===St.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:St.label,children:s.jsx(A,{name:es,className:"w-4 h-4",style:de&&g===St.key?{color:de}:void 0})},St.key)}),t[122]=de,t[123]=g,t[124]=Ae):Ae=t[124];let Le;t[125]!==at||t[126]!==Ae?(Le=s.jsxs("div",{className:"mt-1.5 flex max-w-[22rem] flex-wrap items-center gap-2",children:[at,Ae]}),t[125]=at,t[126]=Ae,t[127]=Le):Le=t[127];let ze;t[128]!==he||t[129]!==C||t[130]!==se||t[131]!==e?(ze=he&&se&&s.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.projects.page.field.preview")}),s.jsx("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-border/60 bg-[var(--surface-elevated)] p-1",children:s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:C?{backgroundColor:C}:void 0,children:s.jsx("img",{src:se,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>O(!0)})})})]}),t[128]=he,t[129]=C,t[130]=se,t[131]=e,t[132]=ze):ze=t[132];let Ke;t[133]!==he||t[134]!==C||t[135]!==e?(Ke=he&&s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[s.jsx("input",{type:"color",value:C??"#000000",onChange:St=>k(St.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(Lt,{value:C??"",onChange:St=>k(St.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),s.jsx(be,{type:"button",size:"xs",variant:"outline",onClick:()=>k(null),className:"h-7 w-7 p-0","aria-label":e("settings.projects.page.field.clearIconBackgroundAria"),title:e("settings.projects.page.field.clearBackground"),disabled:!C,children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]}),t[133]=he,t[134]=C,t[135]=e,t[136]=Ke):Ke=t[136];let lt;t[137]!==Ie||t[138]!==te||t[139]!==P||t[140]!==w||t[141]!==e?(lt=!te&&s.jsxs(s.Fragment,{children:[s.jsx(be,{size:"xs",className:"h-6 !font-normal",onClick:()=>_.current?.click(),disabled:w,children:e(w?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),s.jsx(be,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{Ie()},disabled:P,children:e(P?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),t[137]=Ie,t[138]=te,t[139]=P,t[140]=w,t[141]=e,t[142]=lt):lt=t[142];let xt;t[143]!==fe||t[144]!==ce||t[145]!==I||t[146]!==e?(xt=ce&&s.jsx(be,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{fe()},disabled:I,children:e(I?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),t[143]=fe,t[144]=ce,t[145]=I,t[146]=e,t[147]=xt):xt=t[147];let dt;t[148]!==I||t[149]!==S||t[150]!==e?(dt=S&&s.jsx(be,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>M(!1),disabled:I,children:e("settings.projects.page.actions.undoRemove")}),t[148]=I,t[149]=S,t[150]=e,t[151]=dt):dt=t[151];let ut;t[152]!==lt||t[153]!==xt||t[154]!==dt?(ut=s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[lt,xt,dt]}),t[152]=lt,t[153]=xt,t[154]=dt,t[155]=ut):ut=t[155];let Nt;t[156]!==it||t[157]!==qe||t[158]!==Le||t[159]!==ze||t[160]!==Ke||t[161]!==ut?(Nt=s.jsxs("div",{className:"py-1.5",children:[it,qe,Le,ze,Ke,ut]}),t[156]=it,t[157]=qe,t[158]=Le,t[159]=ze,t[160]=Ke,t[161]=ut,t[162]=Nt):Nt=t[162];let ts;t[163]!==ee||t[164]!==Ze||t[165]!==Nt?(ts=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[ee,Ze,Nt]}),t[163]=ee,t[164]=Ze,t[165]=Nt,t[166]=ts):ts=t[166];let Vt;t[167]!==K||t[168]!==I||t[169]!==w||t[170]!==x?(Vt=!K||x.trim().length===0||w||I,t[167]=K,t[168]=I,t[169]=w,t[170]=x,t[171]=Vt):Vt=t[171];let Xt;t[172]!==e?(Xt=e("settings.common.actions.saveChanges"),t[172]=e,t[173]=Xt):Xt=t[173];let ht;t[174]!==W||t[175]!==Vt||t[176]!==Xt?(ht=s.jsx("div",{className:"mt-0.5 px-2 py-1",children:s.jsx(be,{onClick:W,disabled:Vt,size:"xs",className:"!font-normal",children:Xt})}),t[174]=W,t[175]=Vt,t[176]=Xt,t[177]=ht):ht=t[177];let Bt;t[178]!==ts||t[179]!==ht?(Bt=s.jsxs("div",{className:"mb-8",children:[ts,ht]}),t[178]=ts,t[179]=ht,t[180]=Bt):Bt=t[180];let Zt;t[181]!==Z?(Zt=Z&&s.jsx(C5,{projectRef:Z}),t[181]=Z,t[182]=Zt):Zt=t[182];let gs;t[183]!==Zt?(gs=s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:Zt})}),t[183]=Zt,t[184]=gs):gs=t[184];let rs;t[185]!==e?(rs=e("settings.projects.page.section.worktree"),t[185]=e,t[186]=rs):rs=t[186];let ps;t[187]!==rs?(ps=s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:rs})}),t[187]=rs,t[188]=ps):ps=t[188];let Ut;t[189]!==Z?(Ut=Z&&s.jsx(N5,{projectRef:Z}),t[189]=Z,t[190]=Ut):Ut=t[190];let Ye;t[191]!==Ut?(Ye=s.jsx("section",{className:"px-2 pb-2 pt-0",children:Ut}),t[191]=Ut,t[192]=Ye):Ye=t[192];let Tt;t[193]!==ps||t[194]!==Ye?(Tt=s.jsxs("div",{className:"mb-8",children:[ps,Ye]}),t[193]=ps,t[194]=Ye,t[195]=Tt):Tt=t[195];let Kt;return t[196]!==je||t[197]!==Bt||t[198]!==gs||t[199]!==Tt?(Kt=s.jsx(Ss,{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:[je,Bt,gs,Tt]})}),t[196]=je,t[197]=Bt,t[198]=gs,t[199]=Tt,t[200]=Kt):Kt=t[200],Kt};function P5(t){return t.projects}function A5(t){return t.updateProjectMeta}function D5(t){return t.uploadProjectIcon}function T5(t){return t.removeProjectIcon}function E5(t){return t.discoverProjectIcon}function M5(t){return t.settingsProjectsSelectedId}function R5(t){return t.setSettingsProjectsSelectedId}function F5(t){return t&&URL.revokeObjectURL(t),null}const O5=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`,L5=()=>Math.floor(2e4+Math.random()*3e4),$5=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")},_5=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"}},B5=({onItemSelect:t})=>{const{t:e}=ft(),n=Zs(h=>h.instances),r=Zs(h=>h.statusesById),a=Zs(h=>h.isLoading),i=Zs(h=>h.load),o=Zs(h=>h.loadImports),c=Zs(h=>h.createFromCommand),d=Zs(h=>h.connect),p=Zs(h=>h.disconnect),m=Zs(h=>h.retry),u=Zs(h=>h.removeInstance),f=Zs(h=>h.upsertInstance),b=Fe(h=>h.settingsRemoteInstancesSelectedId),x=Fe(h=>h.setSettingsRemoteInstancesSelectedId);l.useEffect(()=>{i(),o()},[i,o]),l.useEffect(()=>{if(!a){if(n.length===0){b!==null&&x(null);return}b&&n.some(h=>h.id===b)||x(n[0].id)}},[n,a,b,x]);const y=l.useCallback(async()=>{const h=O5();try{await c(h,"ssh user@example.com",e("settings.remoteInstances.sidebar.newSshInstanceName")),x(h),t?.()}catch(j){H.error(e("settings.remoteInstances.sidebar.toast.createFailed"),{description:j instanceof Error?j.message:String(j)})}},[c,t,x,e]),g=l.useCallback(async h=>{try{await d(h.id);return}catch(j){if(!$5(j)||!window.confirm(e("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw j;const C={...h,localForward:{...h.localForward,preferredLocalPort:L5()}};await f(C),await d(C.id),H.success(e("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[d,e,f]);return s.jsx(vu,{variant:"background",header:s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.remoteInstances.sidebar.title")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.remoteInstances.sidebar.total",{count:n.length})}),s.jsx(be,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:()=>{y()},"aria-label":e("settings.remoteInstances.sidebar.actions.addSshInstance"),children:s.jsx(A,{name:"add",className:"size-4"})})]})]}),children:n.map(h=>{const j=r[h.id],v=h.id===b,C=h.nickname?.trim()||h.sshParsed?.destination||h.id,k=`${e(_5(j?.phase))}${j?.localUrl?` · ${j.localUrl}`:""}`,w=j?.phase==="ready",N=j?.phase==="error"||j?.phase==="degraded";return s.jsx(Ul,{title:C,metadata:k,selected:v,onSelect:()=>{x(h.id),t?.()},actions:[{label:e(w?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect"),icon:w?"stop":"plug-2",onClick:()=>{(w?p(h.id):g(h)).catch(T=>{H.error(e(w?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:T instanceof Error?T.message:String(T)})})}},{label:e("settings.remoteInstances.sidebar.actions.retry"),icon:"refresh",onClick:()=>{N&&m(h.id).catch(I=>{H.error(e("settings.remoteInstances.sidebar.toast.retryFailed"),{description:I instanceof Error?I.message:String(I)})})}},{label:e("settings.remoteInstances.sidebar.actions.remove"),icon:"delete-bin",destructive:!0,onClick:()=>{u(h.id).then(()=>{if(b===h.id){const I=n.find(T=>T.id!==h.id);x(I?.id||null)}}).catch(I=>{H.error(e("settings.remoteInstances.sidebar.toast.removeFailed"),{description:I instanceof Error?I.message:String(I)})})}}]},h.id)})})},Md=()=>Math.floor(2e4+Math.random()*3e4),V5=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")},z5=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"}},U5=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),$g=t=>!!(t&&U5.has(t)),W5=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||$g(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",K5=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}`,H5=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:Md(),remoteHost:"127.0.0.1",remotePort:80}),G5=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Yr=t=>{const e=ot.c(8),{label:n,hint:r}=t;let a;e[0]!==n?(a=s.jsx("span",{children:n}),e[0]=n,e[1]=a):a=e[1];let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),e[2]=i):i=e[2];let o;e[3]!==r?(o=s.jsxs(kt,{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},q5=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"}},Up=(t,e)=>{const n=(t||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},J5=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Y5=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}`},Q5=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},X5=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}},Z5=()=>{const{t}=ft(),e=Zs(F=>F.instances),n=Zs(F=>F.statusesById),r=Zs(F=>F.importCandidates),a=Zs(F=>F.isImportsLoading),i=Zs(F=>F.isSaving),o=Zs(F=>F.error),c=Zs(F=>F.load),d=Zs(F=>F.loadImports),p=Zs(F=>F.refreshStatuses),m=Zs(F=>F.upsertInstance),u=Zs(F=>F.createFromCommand),f=Zs(F=>F.removeInstance),b=Zs(F=>F.connect),x=Zs(F=>F.disconnect),y=Zs(F=>F.retry),g=Fe(F=>F.settingsRemoteInstancesSelectedId),h=Fe(F=>F.setSettingsRemoteInstancesSelectedId),j=l.useMemo(()=>g&&e.find(F=>F.id===g)||null,[e,g]),[v,C]=l.useState(null),[k,w]=l.useState(!1),[N,I]=l.useState(!1),[T,P]=l.useState(null),[D,S]=l.useState([]),[M,E]=l.useState(null),[R,V]=l.useState(""),[B,$]=l.useState(!1),[O,_]=l.useState({}),[q,L]=l.useState(!1),[J,Z]=l.useState(!1),[ie,ne]=l.useState(()=>Date.now());l.useEffect(()=>{c(),d()},[c,d]),l.useEffect(()=>{C(j)},[j]),l.useEffect(()=>{if(!g)return;const F=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||p()},2e3);return()=>{window.clearInterval(F)}},[p,g]),l.useEffect(()=>{let F=null,U=Date.now();const oe=()=>{const Oe=Date.now();Oe-U>=1e3&&(ne(Oe),U=Oe),F=requestAnimationFrame(oe)};(typeof document>"u"||document.visibilityState==="visible")&&(F=requestAnimationFrame(oe));const Te=()=>{document.visibilityState==="visible"&&F===null?F=requestAnimationFrame(oe):document.visibilityState!=="visible"&&F!==null&&(cancelAnimationFrame(F),F=null)};return document.addEventListener("visibilitychange",Te),()=>{document.removeEventListener("visibilitychange",Te),F!==null&&cancelAnimationFrame(F)}},[]);const me=g?n[g]:null,pe=me?.phase,G=pe==="ready",K=pe==="degraded",Q=$g(pe),de=G||(Q||K),ge=me?Math.max(0,ie-me.updatedAtMs):0,ve=K&&ge>12e3,te=l.useMemo(()=>!v||!j?!1:JSON.stringify(v)!==JSON.stringify(j),[v,j]),he=l.useCallback(F=>{C(U=>U&&F(U))},[]),ce=l.useCallback(async()=>{if(!v)return;const F=X5(v);if(!F.sshCommand.trim()){H.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(F.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(F.auth.sshPassword?.enabled&&F.auth.sshPassword.value?.trim()&&F.auth.sshPassword.store!=="settings"){const U=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));F.auth.sshPassword.store=U?"settings":"never",U||(F.auth.sshPassword.value=void 0)}if(F.auth.openchamberPassword?.enabled&&F.auth.openchamberPassword.value?.trim()&&F.auth.openchamberPassword.store!=="settings"){const U=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));F.auth.openchamberPassword.store=U?"settings":"never",U||(F.auth.openchamberPassword.value=void 0)}try{await m(F),H.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(U){H.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:U instanceof Error?U.message:String(U)})}}},[v,t,m]),xe=l.useCallback(async(F,U)=>{const oe=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await u(oe,`ssh ${U}`,F),h(oe),H.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Te){return H.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Te instanceof Error?Te.message:String(Te)}),!1}},[u,h,t]),se=l.useCallback(()=>{B||(E(null),V(""))},[B]),ue=l.useCallback((F,U)=>{if(U){E(F),V(G5(F));return}xe(F,F)},[xe]),Y=l.useCallback(async()=>{const F=M,U=R.trim();if(F){if(!U){H.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}$(!0);try{await xe(F,U)&&(E(null),V(""))}finally{$(!1)}}},[xe,R,M,t]),Se=l.useCallback(async()=>{if(j)try{await b(j.id);return}catch(F){if(!V5(F)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw F;const oe={...j,localForward:{...j.localForward,preferredLocalPort:Md()}};await m(oe),await b(oe.id),H.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[b,j,t,m]),fe=l.useCallback(async F=>(await oy(F,600)).map(oe=>Y5(oe)),[]),Ce=l.useCallback(async()=>{if(v){w(!0),I(!0),P(null);try{const F=await fe(v.id);S(F)}catch(F){S([]),P(F instanceof Error?F.message:String(F))}finally{I(!1)}}},[v,fe]);l.useEffect(()=>{if(!k||!v)return;let F=!1;const U=async()=>{try{const Te=await fe(v.id);F||(S(Te),P(null))}catch(Te){F||P(Te instanceof Error?Te.message:String(Te))}};U();const oe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||U()},1e3);return()=>{F=!0,window.clearInterval(oe)}},[v,k,fe]);const Ie=l.useMemo(()=>D.join(`
|
|
181
|
-
`),[D]),ke=l.useCallback(()=>{if(!Ie.trim()){H.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}En(Ie).then(F=>{F.ok&&H.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[Ie,t]),X=l.useCallback(async()=>{if(v)try{await ly(v.id),S([]),H.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(F){H.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:F instanceof Error?F.message:String(F)})}},[v,t]),ae=l.useCallback(async()=>{if(!me?.localUrl){H.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const F=me.localUrl.trim();if(!F){H.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Q5(F)},[me?.localUrl,t]),je=l.useCallback(()=>{if(!v)return;L(!0),(de?x(v.id):Se()).catch(U=>{const oe=de?G?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";H.error(t(oe),{description:U instanceof Error?U.message:String(U)})}).finally(()=>{L(!1)})},[de,Se,x,v,G,t]),le=l.useCallback(()=>{if(!v||Q)return;Z(!0),(K?x(v.id).then(()=>Se()):y(v.id)).catch(U=>{H.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:U instanceof Error?U.message:String(U)})}).finally(()=>{Z(!1)})},[Se,x,v,Q,K,y,t]),Ne=t(Q?"settings.remoteInstances.page.actions.connecting":K?ve?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Me=!q&&!J&&(pe==="error"||pe==="idle"||!pe||K&&ve)&&!Q,Ve=t(G?"settings.remoteInstances.sidebar.actions.disconnect":de?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!v)return s.jsxs(Wl,{children:[s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.description")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.empty.selectInstance")})})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsx("div",{className:"mb-1 px-1 space-y-0.5",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.import.sectionTitle")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:a?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):r.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.noneFound")}):s.jsx("div",{className:"space-y-2",children:r.map(F=>s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--interactive-border)] px-3 py-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"typography-ui-label text-foreground truncate",children:[F.host,F.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[F.source," config"]})]}),s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ue(F.host,F.pattern)},children:t("settings.remoteInstances.page.actions.create")})]},`${F.source}:${F.host}`))})})]}),s.jsx(us,{open:!!M,onOpenChange:F=>{F||se()},children:s.jsxs(ds,{className:"sm:max-w-md",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Ns,{children:M?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:M}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:F=>{F.preventDefault(),Y()},children:[s.jsx(Lt,{value:R,onChange:F=>V(F.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:se,disabled:B,children:t("settings.common.actions.cancel")}),s.jsx(be,{type:"submit",size:"xs",className:"!font-normal",disabled:B,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const we=v.remoteOpenchamber.mode==="managed",ee=v.nickname?.trim()||v.sshParsed?.destination||v.id;return s.jsxs(Wl,{children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:ee}),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 ${W5(pe)}`}),s.jsx("span",{children:t(z5(pe))}),me?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:me.localUrl}):null,ve?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.actions")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.actionsDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(be,{type:"button",variant:de?"outline":"default",size:"xs",className:"!font-normal",onClick:je,disabled:q||J,children:[de?s.jsx(A,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"plug-2",className:"h-3.5 w-3.5"}),Ve]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:le,disabled:!Me,children:[s.jsx(A,{name:"refresh",className:`h-3.5 w-3.5 ${Q||K&&!ve?"animate-spin":""}`}),Ne]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ce()},children:[s.jsx(A,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&f(v.id).then(()=>{h(null),H.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(U=>{H.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:U instanceof Error?U.message:String(U)})})},children:[s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),me?.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:me.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(Lt,{className:"h-7 md:max-w-xl",value:v.sshCommand,onChange:F=>he(U=>({...U,sshCommand:F.target.value})),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.nickname")}),s.jsx(Lt,{className:"h-7 md:max-w-sm",value:v.nickname||"",onChange:F=>he(U=>({...U,nickname:F.target.value})),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.connectionTimeoutSeconds")}),s.jsx($n,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:v.connectionTimeoutSec,onValueChange:F=>{he(U=>({...U,connectionTimeoutSec:Number.isFinite(F)?F:U.connectionTimeoutSec}))}})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.remoteServer")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.remoteServerDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Yr,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(as,{value:v.remoteOpenchamber.mode,onValueChange:F=>he(U=>({...U,remoteOpenchamber:{...U.remoteOpenchamber,mode:F==="external"?"external":"managed"}})),children:[s.jsx(is,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(fs,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(os,{children:[s.jsx(Mt,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(Mt,{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(Yr,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx($n,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:v.remoteOpenchamber.preferredPort,onValueChange:F=>{he(U=>({...U,remoteOpenchamber:{...U.remoteOpenchamber,preferredPort:Number.isFinite(F)&&F>0?F:void 0}}))},onClear:()=>{he(F=>({...F,remoteOpenchamber:{...F.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),we?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(Yr,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(as,{value:v.remoteOpenchamber.installMethod,onValueChange:F=>he(U=>({...U,remoteOpenchamber:{...U.remoteOpenchamber,installMethod:F==="npm"||F==="download_release"||F==="upload_bundle"?F:"bun"}})),children:[s.jsx(is,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(fs,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(os,{children:[s.jsx(Mt,{value:"bun",children:"bun"}),s.jsx(Mt,{value:"npm",children:"npm"}),s.jsx(Mt,{value:"download_release",children:t("settings.remoteInstances.page.field.installMethodDownloadRelease")}),s.jsx(Mt,{value:"upload_bundle",children:t("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,we?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(Yr,{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(Ml,{checked:v.remoteOpenchamber.keepRunning,onCheckedChange:F=>he(U=>({...U,remoteOpenchamber:{...U.remoteOpenchamber,keepRunning:F}}))})})]}):null]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.mainTunnel")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.mainTunnelDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Yr,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(as,{value:v.localForward.bindHost,onValueChange:F=>{F==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||he(U=>({...U,localForward:{...U.localForward,bindHost:F==="localhost"||F==="0.0.0.0"?F:"127.0.0.1"}}))},children:[s.jsx(is,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(fs,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(os,{children:[s.jsx(Mt,{value:"127.0.0.1",children:"127.0.0.1"}),s.jsx(Mt,{value:"localhost",children:"localhost"}),s.jsx(Mt,{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(Yr,{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($n,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:v.localForward.preferredLocalPort,onValueChange:F=>{he(U=>({...U,localForward:{...U.localForward,preferredLocalPort:Number.isFinite(F)&&F>0?F:void 0}}))},onClear:()=>{he(F=>({...F,localForward:{...F.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>he(F=>({...F,localForward:{...F.localForward,preferredLocalPort:Md()}})),children:s.jsx(A,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.authentication")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.authenticationDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshPasswordOptional")}),s.jsx(Lt,{className:"h-7 md:max-w-sm",type:"password",value:v.auth.sshPassword?.value||"",onChange:F=>he(U=>({...U,auth:{...U.auth,sshPassword:{enabled:F.target.value.trim().length>0,value:F.target.value,store:U.auth.sshPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.uiPasswordOptional")}),s.jsx(Lt,{className:"h-7 md:max-w-sm",type:"password",value:v.auth.openchamberPassword?.value||"",onChange:F=>he(U=>({...U,auth:{...U.auth,openchamberPassword:{enabled:F.target.value.trim().length>0,value:F.target.value,store:U.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.portForwards")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.portForwardsDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[v.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,v.portForwards.map((F,U)=>{const oe=qe=>{he(st=>({...st,portForwards:st.portForwards.map((Je,Be)=>Be===U?qe(Je):Je)}))},Te=F.type==="remote"?"Local target":"Local listen",Oe=F.type==="remote"?"Local host and port on your machine that receives traffic from remote -R listener.":"Local host and port where this forward listens on your machine.",Pe=F.type==="remote"?"Remote listen":"Remote target",z=F.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",De=Up(F.localHost||"localhost",F.localPort),Qe=Up(F.remoteHost||"localhost",F.remotePort),et=F.type==="local"&&typeof F.localPort=="number"&&F.localPort>0,Ze=et?`http://${J5(F.localHost)}:${F.localPort}`:"",We=!!O[F.id],it=F.type==="local"?t("settings.remoteInstances.page.forwardType.local"):F.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(vr,{open:We,onOpenChange:qe=>{_(st=>({...st,[F.id]:qe}))},className:`${U>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex items-center gap-2",children:s.jsxs(Mr,{className:"flex items-center gap-2 group",children:[s.jsx(A,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${We?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:K5(F)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:it})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ml,{checked:F.enabled,onCheckedChange:qe=>oe(st=>({...st,enabled:qe})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(be,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>he(qe=>({...qe,portForwards:qe.portForwards.filter(st=>st.id!==F.id)})),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(wr,{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(q5(F.type))}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Yr,{label:t("settings.remoteInstances.page.field.forwardType"),hint:t("settings.remoteInstances.page.field.forwardTypeHint")})}),s.jsxs(as,{value:F.type,onValueChange:qe=>oe(st=>({...st,type:qe==="dynamic"||qe==="remote"?qe:"local"})),children:[s.jsx(is,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(fs,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(os,{children:[s.jsx(Mt,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(Mt,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(Mt,{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(Yr,{label:Te,hint:Oe})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Lt,{className:"h-7 w-32",value:F.localHost||"127.0.0.1",onChange:qe=>oe(st=>({...st,localHost:qe.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx($n,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:F.localPort,onValueChange:qe=>{oe(st=>({...st,localPort:Number.isFinite(qe)&&qe>0?qe:void 0}))},onClear:()=>{oe(qe=>({...qe,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),F.type!=="dynamic"?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Yr,{label:Pe,hint:z})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Lt,{className:"h-7 w-32",value:F.remoteHost||"",onChange:qe=>oe(st=>({...st,remoteHost:qe.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx($n,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:F.remotePort,onValueChange:qe=>{oe(st=>({...st,remotePort:Number.isFinite(qe)&&qe>0?qe:void 0}))},onClear:()=>{oe(qe=>({...qe,remotePort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}):null,s.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:F.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:De}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):F.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Qe}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(A,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(A,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:De}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:De}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(A,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(A,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Qe}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),et?s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{rr(Ze).then(qe=>{qe||H.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},F.id)}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const F=H5();he(U=>({...U,portForwards:[...U.portForwards,F]})),_(U=>({...U,[F.id]:!0}))},children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.addForward")]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsx("div",{className:"mb-1 px-1 space-y-0.5",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.import.sectionTitle")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:a?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):r.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.noneAvailable")}):s.jsx("div",{children:r.slice(0,8).map((F,U)=>s.jsxs("div",{className:`flex items-center justify-between gap-2 px-1 py-2 ${U>0?"border-t border-[var(--surface-subtle)]":""}`,children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"typography-ui-label text-foreground truncate",children:[F.host,F.pattern?" (pattern)":""]}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:F.sshCommand})]}),s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ue(F.host,F.pattern)},children:t("settings.common.actions.import")})]},`${F.source}:${F.host}`))})})]}),s.jsx("div",{className:"sticky bottom-0 z-10 -mx-3 sm:-mx-6 bg-[var(--surface-background)] border-t border-[var(--interactive-border)] px-3 sm:px-6 py-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{ce()},disabled:!te||i,children:t("settings.common.actions.saveChanges")}),me?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{En(me.localUrl||"").then(F=>{F.ok&&H.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(A,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ae()},children:[s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,o?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:o}):null]})}),s.jsx(us,{open:k,onOpenChange:w,children:s.jsxs(ds,{className:"sm:max-w-2xl",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Ns,{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(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ke,disabled:N||!Ie.trim(),children:[s.jsx(A,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{X()},disabled:N,children:[s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),N?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):T?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:T}):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:D.length>0?D.join(`
|
|
182
|
-
`):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(us,{open:!!M,onOpenChange:F=>{F||se()},children:s.jsxs(ds,{className:"sm:max-w-md",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Ns,{children:M?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:M}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:F=>{F.preventDefault(),Y()},children:[s.jsx(Lt,{value:R,onChange:F=>V(F.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:se,disabled:B,children:t("settings.common.actions.cancel")}),s.jsx(be,{type:"submit",size:"xs",className:"!font-normal",disabled:B,children:t("settings.common.actions.create")})]})]})]})})]})},eC="__add_provider__",tC=()=>{const t=on.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},sC=({onItemSelect:t})=>{const{t:e}=ft(),n=wt(f=>f.providers),r=wt(f=>f.selectedProviderId),a=wt(f=>f.setSelectedProvider),i=Cs(f=>f.activeProjectId),[o,c]=l.useState({}),d=l.useMemo(()=>tC(),[i]);l.useEffect(()=>{if(n.length===0){c({});return}let f=!1;return(async()=>{const x=n.map(async y=>{try{const g=d?`?directory=${encodeURIComponent(d)}`:"",h=await fetch(`/api/provider/${encodeURIComponent(y.id)}/source${g}`,{method:"GET",headers:{Accept:"application/json"}});if(!h.ok)return;const j=await h.json().catch(()=>null),v=j?.sources??j?.data?.sources;if(!v||f)return;c(C=>({...C,[y.id]:v}))}catch{}});await Promise.all(x)})(),()=>{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:ye("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(Po,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{a(eC),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(A,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ss,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:n.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(A,{name:"stack",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.providers.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.providers.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[u.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.providers.sidebar.section.userProviders")}),u.map(f=>s.jsx(Wp,{provider:f,selectedProviderId:r,onSelect:()=>{a(f.id),t?.()}},f.id))]}),m.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ye("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(Wp,{provider:f,selectedProviderId:r,onSelect:()=>{a(f.id),t?.()}},f.id))]})]})})]})},Wp=t=>{const e=ot.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=ye("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(yr,{providerId:n.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=n.id,e[3]=m):m=e[3];const u=n.name||n.id;let f;e[4]!==u?(f=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:u}),e[4]=u,e[5]=f):f=e[5];let b;e[6]!==i?(b=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=b):b=e[7];let x;e[8]!==a||e[9]!==m||e[10]!==f||e[11]!==b?(x=s.jsxs("button",{type:"button",onClick:a,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[m,f,b]}),e[8]=a,e[9]=m,e[10]=f,e[11]=b,e[12]=x):x=e[12];let y;return e[13]!==n.id||e[14]!==p||e[15]!==x?(y=s.jsx("div",{className:p,children:x},c),e[13]=n.id,e[14]=p,e[15]=x,e[16]=y):y=e[16],y},nC=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),Kp=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=nC.format(t);return e.endsWith(".0")?e.slice(0,-2):e},qo="__add_provider__",Di=t=>typeof t=="object"&&t!==null,Hp=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()},rC=t=>{if(!Di(t))return{};const e={};for(const[n,r]of Object.entries(t))Array.isArray(r)&&(e[n]=r.filter(a=>Di(a)));return e},aC=t=>{if(typeof t=="string")return{id:t};if(!Di(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}},iC=t=>{let e=[];Array.isArray(t)?e=t:Di(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const n=e.map(a=>aC(a)).filter(a=>!!a),r=new Set;return n.filter(a=>r.has(a.id)?!1:(r.add(a.id),!0))},oC=()=>{const{t}=ft(),e=wt(se=>se.providers),n=wt(se=>se.selectedProviderId),r=wt(se=>se.setSelectedProvider),a=wt(se=>se.getModelMetadata),i=Fe(se=>se.hiddenModels),o=Fe(se=>se.toggleHiddenModel),c=Fe(se=>se.hideAllModels),d=Fe(se=>se.showAllModels),[p,m]=l.useState({}),[u,f]=l.useState(!1),[b,x]=l.useState({}),[y,g]=l.useState(null),[h,j]=l.useState(""),[v,C]=l.useState(null),[k,w]=l.useState({}),[N,I]=l.useState({}),[T,P]=l.useState([]),[D,S]=l.useState(!1),[M,E]=l.useState(null),[R,V]=l.useState(""),[B,$]=l.useState(""),[O,_]=l.useState(!1),[q,L]=l.useState({}),[J,Z]=l.useState(!1);l.useEffect(()=>{!n&&e.length>0&&r(e[0].id)},[e,n,r]),l.useEffect(()=>{let se=!0;return(async()=>{f(!0);try{const Y=await fetch("/api/provider/auth",{method:"GET",headers:{Accept:"application/json"}});if(!Y.ok)throw new Error(`Auth methods request failed (${Y.status})`);const Se=await Y.json().catch(()=>({}));if(!se)return;m(rC(Se))}catch(Y){if(!se)return;console.error("Failed to load provider auth methods:",Y),H.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{se&&f(!1)}})(),()=>{se=!1}},[t]),l.useEffect(()=>{let se=!0;return(async()=>{S(!0),E(null);try{const Y=await fetch("/api/provider",{method:"GET",headers:{Accept:"application/json"}});if(!Y.ok)throw new Error(`Provider list request failed (${Y.status})`);const Se=await Y.json().catch(()=>({}));if(!se)return;P(iC(Se))}catch(Y){if(!se)return;console.error("Failed to load available providers:",Y),E(t("settings.providers.page.state.unableToLoadProviderList"))}finally{se&&S(!1)}})(),()=>{se=!1}},[t]);const ie=l.useMemo(()=>new Set(e.map(se=>se.id)),[e]),ne=l.useMemo(()=>T.filter(se=>!ie.has(se.id)).sort((se,ue)=>{const Y=(se.name||se.id).toLowerCase(),Se=(ue.name||ue.id).toLowerCase();return Y.localeCompare(Se)}),[T,ie]);l.useEffect(()=>{n===qo&&R&&!ne.some(se=>se.id===R)&&V("")},[n,R,ne]),l.useEffect(()=>{if(n===qo){Z(!0);return}Z(!1)},[n,t]),l.useEffect(()=>{if(!n||n===qo)return;let se=!1;return(async()=>{try{const Y=await fetch(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),Se=await Y.json().catch(()=>null);if(!Y.ok)throw new Error(Se?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const fe=Se?.sources??Se?.data?.sources;!se&&fe&&L(Ce=>({...Ce,[n]:fe}))}catch(Y){se||console.error("Failed to load provider sources:",Y)}})(),()=>{se=!0}},[n,t]);const me=e.find(se=>se.id===n),pe=n?q[n]:void 0,G=async se=>{const ue=b[se]?.trim()??"";if(!ue){H.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Y=`api:${se}`;g(Y);try{const Se=await fetch(`/api/auth/${encodeURIComponent(se)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"api",key:ue})}),fe=await Se.json().catch(()=>null);if(!Se.ok){const Ce=fe?.error||t("settings.providers.page.toast.apiKeySaveFailed");throw new Error(Ce)}H.success(t("settings.providers.page.toast.apiKeySaved")),x(Ce=>({...Ce,[se]:""})),await xi({scopes:["providers"],mode:"active"}),r(se)}catch(Se){console.error("Failed to save API key:",Se),H.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{g(null)}},K=async(se,ue)=>{const Y=`oauth:${se}:${ue}`;g(Y);try{const Se=await fetch(`/api/provider/${encodeURIComponent(se)}/oauth/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:ue})}),fe=await Se.json().catch(()=>null);if(!Se.ok){const le=fe?.error||t("settings.providers.page.toast.oauthStartFailed");throw new Error(le)}const Ce=Di(fe)?fe:{},Ie=Di(Ce.data)?Ce.data:Ce,ke=typeof Ie.url=="string"&&Ie.url||typeof Ie.verification_uri_complete=="string"&&Ie.verification_uri_complete||typeof Ie.verification_uri=="string"&&Ie.verification_uri||void 0,X=typeof Ie.instructions=="string"&&Ie.instructions||typeof Ie.message=="string"&&Ie.message||void 0,ae=typeof Ie.user_code=="string"&&Ie.user_code||typeof Ie.code=="string"&&Ie.code||typeof Ie.userCode=="string"&&Ie.userCode||void 0;if(!ke&&!X&&!ae)throw new Error(t("settings.providers.page.toast.oauthDetailsMissing"));const je=`${se}:${ue}`;I(le=>({...le,[je]:{url:ke,instructions:X,userCode:ae}})),ke&&rr(ke),C({providerId:se,methodIndex:ue}),H.message(t("settings.providers.page.toast.completeOAuthInBrowser"))}catch(Se){console.error("Failed to start OAuth flow:",Se),H.error(t("settings.providers.page.toast.oauthStartFailed"))}finally{g(null)}},Q=async(se,ue)=>{const Y=`${se}:${ue}`,Se=k[Y]?.trim(),fe=`oauth-complete:${se}:${ue}`;g(fe);try{const Ce={method:ue};Se&&(Ce.code=Se);const Ie=await fetch(`/api/provider/${encodeURIComponent(se)}/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Ce)}),ke=await Ie.json().catch(()=>null);if(!Ie.ok){const X=ke?.error||t("settings.providers.page.toast.oauthCompleteFailed");throw new Error(X)}H.success(t("settings.providers.page.toast.oauthCompleted")),w(X=>({...X,[Y]:""})),C(null),await xi({scopes:["providers"],mode:"active"}),r(se)}catch(Ce){console.error("Failed to complete OAuth flow:",Ce),H.error(t("settings.providers.page.toast.oauthCompleteFailed"))}finally{g(null)}},W=async se=>{const ue=await En(se);if(ue.ok){H.success(t("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",ue.error),H.error(t("settings.providers.page.toast.oauthLinkCopyFailed"))},de=async se=>{const ue=await En(se);if(ue.ok){H.success(t("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",ue.error),H.error(t("settings.providers.page.toast.deviceCodeCopyFailed"))},ge=async se=>{const ue=`disconnect:${se}`;g(ue);try{const Y=await fetch(`/api/provider/${encodeURIComponent(se)}/auth?scope=all`,{method:"DELETE",headers:{"Content-Type":"application/json"}}),Se=await Y.json().catch(()=>null);if(!Y.ok){const fe=Se?.error||t("settings.providers.page.toast.providerDisconnectFailed");throw new Error(fe)}H.success(t("settings.providers.page.toast.providerDisconnected")),await xi({scopes:["providers"],mode:"active"})}catch(Y){console.error("Failed to disconnect provider:",Y),H.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{g(null)}},ve=n===qo;if(!ve&&e.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(A,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.noProvidersDetected")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(ve)return s.jsx(Ss,{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")}),D?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):M?s.jsx("p",{className:"typography-meta text-muted-foreground",children:M}):ne.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connect.allProvidersConnected")}):s.jsxs(As,{open:O,onOpenChange:se=>{_(se),se||$("")},children:[s.jsx(Is,{asChild:!0,children:s.jsxs("button",{type:"button",className:ye("flex items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover h-6 w-fit"),children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[R?s.jsx(yr,{providerId:R,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:ye("truncate typography-ui-label font-normal",R?"text-foreground":"text-muted-foreground"),children:R?ne.find(se=>se.id===R)?.name||R:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(Ps,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:se=>se.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:se=>se.stopPropagation(),children:[s.jsx(A,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:B,onChange:se=>$(se.target.value),onKeyDown:se=>se.stopPropagation(),placeholder:t("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),s.jsx(Ss,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const se=ne.filter(ue=>{const Y=B.toLowerCase();return(ue.name||ue.id).toLowerCase().includes(Y)||ue.id.toLowerCase().includes(Y)});return se.length===0?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):se.map(ue=>s.jsxs(_t,{onSelect:()=>{V(ue.id),_(!1),$("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(yr,{providerId:ue.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ue.name||ue.id})]}),R===ue.id&&s.jsx(A,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},ue.id))})()})]})]})]})})]}),R&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")})}),u?s.jsx("p",{className:"typography-meta text-muted-foreground px-2",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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(Lt,{type:"password",value:b[R]??"",onChange:se=>x(ue=>({...ue,[R]:se.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(be,{size:"xs",className:"!font-normal shrink-0",onClick:()=>G(R),disabled:y===`api:${R}`,children:y===`api:${R}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),(()=>{const ue=(p[R]??[]).filter(Y=>Hp(Y)==="oauth");return ue.length===0?null:s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:ue.map((Y,Se)=>{const fe=Y.label||Y.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(Se+1)}),Ce=`${R}:${Se}`,Ie=v?.providerId===R&&v?.methodIndex===Se;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:fe}),(Y.description||Y.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(Y.description||Y.help)})]}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>K(R,Se),disabled:y===`oauth:${R}:${Se}`,children:t("settings.providers.page.actions.connect")})]}),N[Ce]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:N[Ce]?.instructions}),N[Ce]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Lt,{value:N[Ce]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>de(N[Ce]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),N[Ce]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Lt,{value:N[Ce]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>rr(N[Ce]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>W(N[Ce]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),Ie&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Lt,{value:k[Ce]??"",onChange:ke=>w(X=>({...X,[Ce]:ke.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(be,{size:"xs",className:"!font-normal",onClick:()=>Q(R,Se),disabled:y===`oauth-complete:${R}:${Se}`,children:y===`oauth-complete:${R}:${Se}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${R}-${fe}`)})})})()]})]})]})});if(!me)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(A,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.selectProviderFromSidebar")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const te=Array.isArray(me.models)?me.models:[],ce=(p[me.id]??[]).filter(se=>Hp(se)==="oauth"),xe=te.filter(se=>{const ue=typeof se?.name=="string"?se.name:"",Y=typeof se?.id=="string"?se.id:"",Se=h.trim().toLowerCase();return Se?ue.toLowerCase().includes(Se)||Y.toLowerCase().includes(Se):!0});return s.jsx(Ss,{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(yr,{providerId:me.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:me.name||me.id}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s.jsx("span",{className:"font-mono",children:me.id})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Z(se=>!se),children:t(J?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:J?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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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(Lt,{type:"password",value:b[me.id]??"",onChange:se=>x(ue=>({...ue,[me.id]:se.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(be,{size:"xs",className:"!font-normal shrink-0",onClick:()=>G(me.id),disabled:y===`api:${me.id}`,children:y===`api:${me.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),ce.length>0&&s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:ce.map((se,ue)=>{const Y=se.label||se.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(ue+1)}),Se=`${me.id}:${ue}`,fe=v?.providerId===me.id&&v?.methodIndex===ue;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:Y}),(se.description||se.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(se.description||se.help)})]}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>K(me.id,ue),disabled:y===`oauth:${me.id}:${ue}`,children:t("settings.providers.page.actions.connect")})]}),N[Se]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:N[Se]?.instructions}),N[Se]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Lt,{value:N[Se]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>de(N[Se]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),N[Se]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Lt,{value:N[Se]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>rr(N[Se]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>W(N[Se]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),fe&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Lt,{value:k[Se]??"",onChange:Ce=>w(Ie=>({...Ie,[Se]:Ce.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(be,{size:"xs",className:"!font-normal",onClick:()=>Q(me.id,ue),disabled:y===`oauth-complete:${me.id}:${ue}`,children:y===`oauth-complete:${me.id}:${ue}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${me.id}-${Y}`)})})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(A,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.connected")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-1",children:t("settings.providers.page.auth.useReconnectHint")})]})})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.connectionDetails.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:pe&&(pe.auth.exists||pe.user.exists||pe.project.exists||pe.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[pe.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,pe.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,pe.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,pe.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connectionDetails.noActiveSource")})}),s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ge(me.id),disabled:y===`disconnect:${me.id}`,children:y===`disconnect:${me.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"),te.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",te.length,")"]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const se=te.map(ue=>typeof ue?.id=="string"?ue.id:"").filter(ue=>ue.length>0);c(me.id,se)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>d(me.id),children:t("settings.providers.page.actions.showAll")})]})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(A,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Lt,{value:h,onChange:se=>j(se.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),xe.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:xe.map(se=>{const ue=typeof se?.id=="string"?se.id:"",Y=typeof se?.name=="string"?se.name:ue,Se=ue?a(me.id,ue):void 0,fe=i.some(X=>X.providerID===me.id&&X.modelID===ue),Ce=Kp(Se?.limit?.context),Ie=Kp(Se?.limit?.output),ke=[];return Se?.tool_call&&ke.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Se?.reasoning&&ke.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Se?.attachment&&ke.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:ye("flex items-center gap-3",fe&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Y}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(Ce||Ie)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[Ce?`${Ce} ${t("settings.providers.page.models.tokenBadge.context")}`:"",Ce&&Ie?" · ":"",Ie?`${Ie} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),ke.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:ke.map(({key:X,icon:ae,label:je})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:je,"aria-label":je,children:s.jsx(A,{name:ae,className:"h-3 w-3"})},X))}),s.jsx("button",{type:"button",onClick:()=>o(me.id,ue),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(fe?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(fe?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:fe?s.jsx(A,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},ue)})})]})]})]})})},lC=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)},cC=t=>{const e=ot.c(106),{onItemSelect:n}=t,{t:r}=ft(),a=Rs(dC),i=Rs(uC),o=Rs(mC),c=Rs(pC),d=Rs(fC),p=Rs(hC),m=Rs(gC),u=Rs(xC),f=Rs(bC),b=Rs(yC),x=Rs(vC),y=Rs(wC);let g,h;e[0]!==y?(g=()=>{y()},h=[y],e[0]=y,e[1]=g,e[2]=h):(g=e[1],h=e[2]),l.useEffect(g,h);const j=jC;let v;e[3]!==f?(v=ae=>{f(ae),j({usageAutoRefresh:ae})},e[3]=f,e[4]=v):v=e[4];const C=v;let k;e[5]!==b?(k=ae=>{const je=Number(ae);Number.isFinite(je)&&(b(je),j({usageRefreshIntervalMs:je}))},e[5]=b,e[6]=k):k=e[6];const w=k;let N;e[7]!==x?(N=ae=>{ae!=="usage"&&ae!=="remaining"||(x(ae),j({usageDisplayMode:ae}))},e[7]=x,e[8]=N):N=e[8];const I=N;let T;e[9]===Symbol.for("react.memo_cache_sentinel")?(T=ye("flex h-full flex-col","bg-background"),e[9]=T):T=e[9];let P;e[10]!==r?(P=r("settings.usage.sidebar.title"),e[10]=r,e[11]=P):P=e[11];let D;e[12]!==P?(D=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:P}),e[12]=P,e[13]=D):D=e[13];let S;e[14]!==r?(S=r("settings.usage.sidebar.total",{count:Kr.length}),e[14]=r,e[15]=S):S=e[15];let M;e[16]!==S?(M=s.jsx("span",{className:"typography-meta text-muted-foreground",children:S}),e[16]=S,e[17]=M):M=e[17];let E;e[18]!==r?(E=r("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[18]=r,e[19]=E):E=e[19];let R;e[20]!==C||e[21]!==E||e[22]!==p?(R=s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(vs,{checked:p,onChange:C,ariaLabel:E})})}),e[20]=C,e[21]=E,e[22]=p,e[23]=R):R=e[23];let V;e[24]!==r?(V=r("settings.usage.sidebar.tooltip.autoRefresh"),e[24]=r,e[25]=V):V=e[25];let B;e[26]!==V?(B=s.jsx(It,{side:"bottom",children:V}),e[26]=V,e[27]=B):B=e[27];let $;e[28]!==R||e[29]!==B?($=s.jsxs(kt,{children:[R,B]}),e[28]=R,e[29]=B,e[30]=$):$=e[30];const O=String(m),_=!p;let q;e[31]!==r?(q=r("settings.usage.sidebar.field.intervalPlaceholder"),e[31]=r,e[32]=q):q=e[32];let L;e[33]!==q?(L=s.jsx(is,{className:"w-fit",children:s.jsx(fs,{placeholder:q})}),e[33]=q,e[34]=L):L=e[34];let J;e[35]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsxs(os,{children:[s.jsx(Mt,{value:"30000",children:"30s"}),s.jsx(Mt,{value:"60000",children:"1m"}),s.jsx(Mt,{value:"300000",children:"5m"})]}),e[35]=J):J=e[35];let Z;e[36]!==w||e[37]!==O||e[38]!==_||e[39]!==L?(Z=s.jsxs(as,{value:O,onValueChange:w,disabled:_,children:[L,J]}),e[36]=w,e[37]=O,e[38]=_,e[39]=L,e[40]=Z):Z=e[40];let ie;e[41]!==c?(ie=()=>c(),e[41]=c,e[42]=ie):ie=e[42];let ne;e[43]!==r?(ne=r("settings.usage.sidebar.actions.refreshAria"),e[43]=r,e[44]=ne):ne=e[44];let me;e[45]!==r?(me=r("settings.usage.sidebar.actions.refreshTitle"),e[45]=r,e[46]=me):me=e[46];const pe=d&&"animate-spin";let G;e[47]!==pe?(G=ye("h-3.5 w-3.5",pe),e[47]=pe,e[48]=G):G=e[48];let K;e[49]!==G?(K=s.jsx(A,{name:"refresh",className:G}),e[49]=G,e[50]=K):K=e[50];let Q;e[51]!==d||e[52]!==ie||e[53]!==ne||e[54]!==me||e[55]!==K?(Q=s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:ie,"aria-label":ne,title:me,disabled:d,children:K}),e[51]=d,e[52]=ie,e[53]=ne,e[54]=me,e[55]=K,e[56]=Q):Q=e[56];let W;e[57]!==$||e[58]!==Z||e[59]!==Q?(W=s.jsxs("div",{className:"flex items-center gap-2",children:[$,Z,Q]}),e[57]=$,e[58]=Z,e[59]=Q,e[60]=W):W=e[60];let de;e[61]!==M||e[62]!==W?(de=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[M,W]}),e[61]=M,e[62]=W,e[63]=de):de=e[63];let ge;e[64]!==r?(ge=r("settings.usage.sidebar.field.display"),e[64]=r,e[65]=ge):ge=e[65];let ve;e[66]!==ge?(ve=s.jsx("span",{className:"typography-micro text-muted-foreground",children:ge}),e[66]=ge,e[67]=ve):ve=e[67];let te;e[68]!==r?(te=r("settings.usage.sidebar.field.displayModePlaceholder"),e[68]=r,e[69]=te):te=e[69];let he;e[70]!==te?(he=s.jsx(is,{className:"w-fit",children:s.jsx(fs,{placeholder:te})}),e[70]=te,e[71]=he):he=e[71];let ce;e[72]!==r?(ce=r("settings.usage.sidebar.field.displayModeUsage"),e[72]=r,e[73]=ce):ce=e[73];let xe;e[74]!==ce?(xe=s.jsx(Mt,{value:"usage",children:ce}),e[74]=ce,e[75]=xe):xe=e[75];let se;e[76]!==r?(se=r("settings.usage.sidebar.field.displayModeRemaining"),e[76]=r,e[77]=se):se=e[77];let ue;e[78]!==se?(ue=s.jsx(Mt,{value:"remaining",children:se}),e[78]=se,e[79]=ue):ue=e[79];let Y;e[80]!==xe||e[81]!==ue?(Y=s.jsxs(os,{children:[xe,ue]}),e[80]=xe,e[81]=ue,e[82]=Y):Y=e[82];let Se;e[83]!==I||e[84]!==he||e[85]!==Y||e[86]!==u?(Se=s.jsxs(as,{value:u,onValueChange:I,children:[he,Y]}),e[83]=I,e[84]=he,e[85]=Y,e[86]=u,e[87]=Se):Se=e[87];let fe;e[88]!==ve||e[89]!==Se?(fe=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[ve,Se]}),e[88]=ve,e[89]=Se,e[90]=fe):fe=e[90];let Ce;e[91]!==de||e[92]!==fe||e[93]!==D?(Ce=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[D,de,fe]}),e[91]=de,e[92]=fe,e[93]=D,e[94]=Ce):Ce=e[94];let Ie;e[95]!==n||e[96]!==a||e[97]!==i||e[98]!==o||e[99]!==r?(Ie=Kr.map(ae=>{const je=a.find(ee=>ee.providerId===ae.id),le=lC(je?.usage),Ne=Vh(le),Me=ae.id===i,Ve=je?.configured??!1,we=Ve?Ne==="critical"?{backgroundColor:"var(--status-error)"}:Ne==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",Me?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{o(ae.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:we}),s.jsx(yr,{providerId:ae.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:ae.name}),!Ve&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r("settings.usage.sidebar.status.notSet")})]})},ae.id)}),e[95]=n,e[96]=a,e[97]=i,e[98]=o,e[99]=r,e[100]=Ie):Ie=e[100];let ke;e[101]!==Ie?(ke=s.jsx(Ss,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:Ie}),e[101]=Ie,e[102]=ke):ke=e[102];let X;return e[103]!==Ce||e[104]!==ke?(X=s.jsxs("div",{className:T,children:[Ce,ke]}),e[103]=Ce,e[104]=ke,e[105]=X):X=e[105],X};function dC(t){return t.results}function uC(t){return t.selectedProviderId}function mC(t){return t.setSelectedProvider}function pC(t){return t.fetchAllQuotas}function fC(t){return t.isLoading}function hC(t){return t.autoRefresh}function gC(t){return t.refreshIntervalMs}function xC(t){return t.displayMode}function bC(t){return t.setAutoRefresh}function yC(t){return t.setRefreshInterval}function vC(t){return t.setDisplayMode}function wC(t){return t.loadSettings}async function jC(t){try{await ks(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const qc=t=>{const e=ot.c(52),{title:n,window:r,subtitle:a,showToggle:i,toggleEnabled:o,onToggle:c}=t,d=i===void 0?!1:i,p=o===void 0?!1:o,m=Rs(NC),u=m==="remaining"?r.remainingPercent:r.usedPercent,f=m==="remaining"?"remaining":"used";let b;e[0]!==u||e[1]!==r.valueLabel?(b=fo(r.valueLabel,u),e[0]=u,e[1]=r.valueLabel,e[2]=b):b=e[2];const x=b,y=r.resetAfterFormatted??r.resetAtFormatted;let g;e[3]!==y||e[4]!==r.resetAt?(g=lu(r.resetAt,y),e[3]=y,e[4]=r.resetAt,e[5]=g):g=e[5];const h=g;let j;e[6]!==n?(j=cu(n),e[6]=n,e[7]=j):j=e[7];const v=j;let C;e[8]!==n||e[9]!==r.resetAt||e[10]!==r.usedPercent||e[11]!==r.windowSeconds?(C=ho(r.usedPercent,r.resetAt,r.windowSeconds,n),e[8]=n,e[9]=r.resetAt,e[10]=r.usedPercent,e[11]=r.windowSeconds,e[12]=C):C=e[12];const k=C;let w;e:{if(!k||k.dailyAllocationPercent===null){w=null;break e}const Z=Zr(k.elapsedRatio);w=m==="remaining"?100-Z:Z}const N=w;let I;e[13]!==c||e[14]!==d||e[15]!==p?(I=d&&s.jsx(vs,{checked:p,onChange:Z=>c?.(Z),ariaLabel:"Show in dropdown"}),e[13]=c,e[14]=d,e[15]=p,e[16]=I):I=e[16];let T;e[17]!==v?(T=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:v}),e[17]=v,e[18]=T):T=e[18];let P;e[19]!==a?(P=a&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:a}),e[19]=a,e[20]=P):P=e[20];let D;e[21]!==T||e[22]!==P?(D=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[T,P]}),e[21]=T,e[22]=P,e[23]=D):D=e[23];let S;e[24]!==D||e[25]!==I?(S=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[I,D]}),e[24]=D,e[25]=I,e[26]=S):S=e[26];const M=x==="-"?"":x;let E;e[27]!==M?(E=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:M}),e[27]=M,e[28]=E):E=e[28];let R;e[29]!==S||e[30]!==E?(R=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[S,E]}),e[29]=S,e[30]=E,e[31]=R):R=e[31];let V;e[32]!==u||e[33]!==N||e[34]!==r.usedPercent?(V=s.jsx(xo,{percent:u,tonePercent:r.usedPercent,expectedMarkerPercent:N,className:"h-1.5"}),e[32]=u,e[33]=N,e[34]=r.usedPercent,e[35]=V):V=e[35];const B=h?`Resets ${h}`:"";let $;e[36]!==B?($=s.jsx("span",{className:"typography-micro text-muted-foreground",children:B}),e[36]=B,e[37]=$):$=e[37];let O;e[38]!==f?(O=s.jsx("span",{className:"typography-micro text-muted-foreground",children:f}),e[38]=f,e[39]=O):O=e[39];let _;e[40]!==$||e[41]!==O?(_=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[$,O]}),e[40]=$,e[41]=O,e[42]=_):_=e[42];let q;e[43]!==V||e[44]!==_?(q=s.jsxs("div",{className:"mt-2.5",children:[V,_]}),e[43]=V,e[44]=_,e[45]=q):q=e[45];let L;e[46]!==k?(L=k&&s.jsx("div",{className:"mt-1.5",children:s.jsx(bo,{paceInfo:k})}),e[46]=k,e[47]=L):L=e[47];let J;return e[48]!==R||e[49]!==q||e[50]!==L?(J=s.jsxs("div",{className:"py-3",children:[R,q,L]}),e[48]=R,e[49]=q,e[50]=L,e[51]=J):J=e[51],J};function NC(t){return t.displayMode}const SC=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},kC=()=>{const{t}=ft(),e=Rs(S=>S.results),n=Rs(S=>S.selectedProviderId),r=Rs(S=>S.setSelectedProvider),a=Rs(S=>S.loadSettings),i=Rs(S=>S.fetchAllQuotas),o=Rs(S=>S.isLoading),c=Rs(S=>S.lastUpdated),d=Rs(S=>S.error),p=Rs(S=>S.dropdownProviderIds),m=Rs(S=>S.setDropdownProviderIds),u=Rs(S=>S.selectedModels),f=Rs(S=>S.toggleModelSelected),b=Rs(S=>S.applyDefaultSelections);Hh(),l.useEffect(()=>{a(),i()},[a,i]),l.useEffect(()=>{if(n||e.length===0)return;const S=e.find(M=>M.configured)?.providerId;r(S??Kr[0]?.id??null)},[e,n,r]);const x=e.find(S=>S.providerId===n)??null,g=Kr.find(S=>S.id===n)?.name??n??t("settings.usage.sidebar.title"),h=x?.usage,j=n?p.includes(n):!1,v=l.useCallback(S=>{if(!n)return;const M=S?Array.from(new Set([...p,n])):p.filter(E=>E!==n);m(M),ks({usageDropdownProviders:M})},[p,n,m]),C=l.useMemo(()=>h?.models?Object.entries(h.models).map(([S,M])=>({name:S,windows:M})).filter(S=>Object.keys(S.windows.windows).length>0):[],[h?.models]);l.useEffect(()=>{n&&C.length>0&&b(n,C.map(S=>S.name))},[n,C,b]);const k=l.useMemo(()=>!n||C.length===0?new Map:u1(C,S=>S.name,n),[C,n]),w=l.useMemo(()=>{if(!n)return[];const S=Wh(n);return Kh(S)},[n]),[N,I]=l.useState(()=>({})),T=l.useCallback(S=>{I(M=>({...M,[S]:!M[S]}))},[]),P=l.useCallback(S=>{if(!n)return;f(n,S);const M=u[n]??[],R=M.includes(S)?M.filter(B=>B!==S):[...M,S],V={...u,[n]:R};ks({usageSelectedModels:V})},[n,u,f]),D=n?u[n]??[]:[];return n?s.jsx(Ss,{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(yr,{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:g})}),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:SC(c)})})]})]}),s.jsx("div",{className:"mb-8 px-2",children:s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":j,onClick:()=>v(!j),onKeyDown:S=>{(S.key===" "||S.key==="Enter")&&(S.preventDefault(),v(!j))},children:[s.jsx(vs,{checked:j,onChange:v,ariaLabel:t("settings.usage.page.options.showInHeaderAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.options.showInHeader")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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")})]})]})]})}),!x&&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})]}),x&&!x.configured&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),h?.windows&&Object.keys(h.windows).length>0&&s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(h.windows).map(([S,M])=>s.jsx(qc,{title:S,window:M},S))})})}),C.length>0&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.usage.page.section.modelQuotas")})}),s.jsxs("div",{className:"space-y-3",children:[w.map(S=>{const M=k.get(S.id)??[];if(M.length===0)return null;const E=N[S.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(vr,{open:!E,onOpenChange:()=>T(S.id),children:[s.jsxs(Mr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:S.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",M.length,")"]})]}),E?s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(wr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:M.map(R=>{const V=Object.entries(R.windows.windows);if(V.length===0)return null;const[B,$]=V[0],O=D.includes(R.name);return s.jsx(qc,{title:B,subtitle:El(R.name),window:$,showToggle:!0,toggleEnabled:O,onToggle:()=>P(R.name)},R.name)})})})]})},S.id)}),(()=>{const S=k.get(null)??[];if(S.length===0)return null;const M=N.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(vr,{open:!M,onOpenChange:()=>T("other"),children:[s.jsxs(Mr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",S.length,")"]})]}),M?s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(wr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:S.map(E=>{const R=Object.entries(E.windows.windows);if(R.length===0)return null;const[V,B]=R[0],$=D.includes(E.name);return s.jsx(qc,{title:V,subtitle:El(E.name),window:B,showToggle:!0,toggleEnabled:$,onToggle:()=>P(E.name)},E.name)})})})]})})})()]})]}),x?.configured&&h&&Object.keys(h.windows??{}).length===0&&C.length===0&&s.jsxs("div",{className:"mb-8 px-2",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noQuotaWindowsTitle")}),s.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:t("settings.usage.page.state.noQuotaWindowsDescription")})]})]})}):s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.usage.page.empty.selectProvider")})})},CC="git.commit.generate",Rd=ar(t=>({selectedPromptId:CC,setSelectedPromptId:e=>{t(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),IC=t=>{const e=ot.c(23),{onItemSelect:n}=t,{t:r}=ft(),a=Rd(PC),i=Rd(AC);let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=o):o=e[0];let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=c):c=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=d):d=e[2];let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=[o,c,d,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[3]=p):p=e[3];const m=p;let u;e[4]!==r?(u=r("settings.magicPrompts.sidebar.title"),e[4]=r,e[5]=u):u=e[5];let f;e[6]!==u?(f=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:u}),e[6]=u,e[7]=f):f=e[7];let b;e[8]!==r?(b=r("settings.magicPrompts.sidebar.description"),e[8]=r,e[9]=b):b=e[9];let x;e[10]!==b?(x=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:b}),e[10]=b,e[11]=x):x=e[11];let y;e[12]!==f||e[13]!==x?(y=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[f,x]}),e[12]=f,e[13]=x,e[14]=y):y=e[14];let g;e[15]!==n||e[16]!==a||e[17]!==i||e[18]!==r?(g=s.jsx(Ss,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(j=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:r(j.groupKey)}),j.items.map(v=>{const C=a===v.id;return s.jsx("button",{type:"button",onClick:()=>{i(v.id),n?.()},className:ye("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",C?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:r(v.titleKey)})},v.id)})]},j.groupKey))}),e[15]=n,e[16]=a,e[17]=i,e[18]=r,e[19]=g):g=e[19];let h;return e[20]!==g||e[21]!==y?(h=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[y,g]}),e[20]=g,e[21]=y,e[22]=h):h=e[22],h};function PC(t){return t.selectedPromptId}function AC(t){return t.setSelectedPromptId}const Gp={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},qp=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Jp=t=>t.endsWith(".visible"),DC=()=>{const{t}=ft(),e=l.useCallback(w=>t(w),[t]),n=Rd(w=>w.selectedPromptId),[r,a]=l.useState(!0),[i,o]=l.useState({}),[c,d]=l.useState({}),[p,m]=l.useState({}),[u,f]=l.useState({}),[b,x]=l.useState(!1);l.useEffect(()=>{let w=!0;return(async()=>{a(!0);try{const I=await my();if(!w)return;o(I)}catch(I){console.warn("Failed to load magic prompts:",I),H.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{w&&a(!1)}})(),()=>{w=!1}},[t]);const y=Gp[n]??Gp["git.commit.generate"],g=l.useCallback(w=>qp(i,w)?i[w]:fc(w),[i]),h=l.useCallback(w=>c[w]??g(w),[c,g]),j=l.useCallback((w,N)=>{d(I=>I[w]===N?I:{...I,[w]:N})},[]),v=l.useCallback(async w=>{const N=h(w);if(Jp(w)&&N.trim().length===0){H.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(I=>({...I,[w]:!0}));try{const I=N===fc(w)?await Ku(w):await cy(w,N);o(I.overrides),H.success(t("settings.magicPrompts.page.toast.saved"))}catch(I){const T=I instanceof Error?I.message:String(I);H.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:T})}finally{m(I=>({...I,[w]:!1}))}},[h,t]),C=l.useCallback(async w=>{f(N=>({...N,[w]:!0}));try{const N=await Ku(w);o(N.overrides),d(I=>({...I,[w]:fc(w)})),H.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(N){const I=N instanceof Error?N.message:String(N);H.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:I})}finally{f(N=>({...N,[w]:!1}))}},[t]),k=l.useCallback(async()=>{x(!0);try{const w=await dy();o(w.overrides),d({}),H.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(w){const N=w instanceof Error?w.message:String(w);H.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:N})}finally{x(!1)}},[t]);return r?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl px-6 py-6 space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[s.jsx("div",{className:"space-y-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:e(y.titleKey)}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:e(y.descriptionKey)})]})]})}),s.jsx(be,{variant:"outline",size:"sm",onClick:()=>{k()},disabled:b||Object.keys(i).length===0,children:t(b?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")})]}),y.blocks.map((w,N)=>{const I=uy(w.id),T=g(w.id),P=h(w.id),D=qp(i,w.id),S=P!==T,M=Jp(w.id)&&P.trim().length===0,E=p[w.id]===!0,R=u[w.id]===!0;return s.jsxs("section",{className:N>0?"space-y-3 pt-5 border-t border-border":"space-y-3",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label text-foreground",children:e(w.titleKey)}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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(V=>`{{${V.key}}}`).join(", ")]})]}),s.jsx(un,{value:P,onChange:V=>j(w.id,V.target.value),className:"min-h-[220px] font-mono text-sm"}),M&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(S?"settings.magicPrompts.page.status.unsavedChanges":D?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{variant:"outline",size:"sm",onClick:()=>{C(w.id)},disabled:!D||E||R,children:t(R?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(be,{size:"sm",onClick:()=>{v(w.id)},disabled:!S||E||R||M,children:t(E?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},w.id)})]})})},TC=t=>{const e=ot.c(87),{onItemSelect:n}=t,{t:r}=ft(),[a,i]=l.useState(null),[o,c]=l.useState(null),{selectedSnippetName:d,snippets:p,setSelectedSnippet:m,setSnippetDraft:u,deleteSnippet:f,loadSnippets:b}=rc(Gn(EC));let x,y;e[0]!==b?(x=()=>{b()},y=[b],e[0]=b,e[1]=x,e[2]=y):(x=e[1],y=e[2]),l.useEffect(x,y);let g;e[3]!==n||e[4]!==m||e[5]!==u||e[6]!==p?(g=async()=>{const ve=new Set(p.map(MC));let te="new-snippet",he=1;for(;ve.has(te);)te=`new-snippet-${he++}`;u({name:te,scope:"global"}),m(te),n?.()},e[3]=n,e[4]=m,e[5]=u,e[6]=p,e[7]=g):g=e[7];const h=g;let j;e[8]!==a||e[9]!==f||e[10]!==r?(j=async()=>{if(!a)return;await f(a.name)?(H.success(r("settings.snippets.sidebar.toast.deleted")),i(null)):H.error(r("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=a,e[9]=f,e[10]=r,e[11]=j):j=e[11];const v=j;let C;e[12]!==p?(C=[...p].sort(RC),e[12]=p,e[13]=C):C=e[13];const k=C;let w;e[14]===Symbol.for("react.memo_cache_sentinel")?(w=ye("flex h-full flex-col","bg-background"),e[14]=w):w=e[14];let N;e[15]!==r?(N=r("settings.snippets.sidebar.title"),e[15]=r,e[16]=N):N=e[16];let I;e[17]!==N?(I=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:N}),e[17]=N,e[18]=I):I=e[18];let T;e[19]!==p.length||e[20]!==r?(T=r("settings.snippets.sidebar.total",{count:p.length}),e[19]=p.length,e[20]=r,e[21]=T):T=e[21];let P;e[22]!==T?(P=s.jsx("span",{className:"typography-meta text-muted-foreground",children:T}),e[22]=T,e[23]=P):P=e[23];let D;e[24]!==r?(D=r("settings.snippets.sidebar.actions.create"),e[24]=r,e[25]=D):D=e[25];let S;e[26]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[26]=S):S=e[26];let M;e[27]!==h||e[28]!==D?(M=s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:h,"aria-label":D,children:S}),e[27]=h,e[28]=D,e[29]=M):M=e[29];let E;e[30]!==P||e[31]!==M?(E=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[P,M]}),e[30]=P,e[31]=M,e[32]=E):E=e[32];let R;e[33]!==E||e[34]!==I?(R=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[I,E]}),e[33]=E,e[34]=I,e[35]=R):R=e[35];let V;if(e[36]!==n||e[37]!==o||e[38]!==d||e[39]!==m||e[40]!==k||e[41]!==r){let ve;e[43]!==n||e[44]!==o||e[45]!==d||e[46]!==m||e[47]!==r?(ve=te=>s.jsxs("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",d===te.name?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsxs("button",{onClick:()=>{m(te.name),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["#",te.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:r(`snippets.source.${te.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:te.description||te.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(As,{open:o===te.name,onOpenChange:he=>c(he?te.name:null),children:[s.jsx(Is,{asChild:!0,children:s.jsx(be,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100","aria-label":r("settings.snippets.sidebar.actions.more",{name:te.name}),children:s.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ps,{align:"end",className:"w-fit min-w-20",children:s.jsxs(_t,{onClick:he=>{he.stopPropagation(),i(te)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},`${te.source}:${te.filePath}`),e[43]=n,e[44]=o,e[45]=d,e[46]=m,e[47]=r,e[48]=ve):ve=e[48],V=k.map(ve),e[36]=n,e[37]=o,e[38]=d,e[39]=m,e[40]=k,e[41]=r,e[42]=V}else V=e[42];let B;e[49]!==V?(B=s.jsx(Ss,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:V}),e[49]=V,e[50]=B):B=e[50];const $=a!==null;let O;e[51]===Symbol.for("react.memo_cache_sentinel")?(O=ve=>{ve||i(null)},e[51]=O):O=e[51];let _;e[52]!==r?(_=r("settings.snippets.sidebar.dialog.deleteTitle"),e[52]=r,e[53]=_):_=e[53];let q;e[54]!==_?(q=s.jsx(ms,{children:_}),e[54]=_,e[55]=q):q=e[55];const L=a?.name??"";let J;e[56]!==r||e[57]!==L?(J=r("settings.snippets.sidebar.dialog.deleteDescription",{name:L}),e[56]=r,e[57]=L,e[58]=J):J=e[58];let Z;e[59]!==J?(Z=s.jsx(Ns,{children:J}),e[59]=J,e[60]=Z):Z=e[60];let ie;e[61]!==q||e[62]!==Z?(ie=s.jsxs(hs,{children:[q,Z]}),e[61]=q,e[62]=Z,e[63]=ie):ie=e[63];let ne;e[64]===Symbol.for("react.memo_cache_sentinel")?(ne=()=>i(null),e[64]=ne):ne=e[64];let me;e[65]!==r?(me=r("settings.common.actions.cancel"),e[65]=r,e[66]=me):me=e[66];let pe;e[67]!==me?(pe=s.jsx(be,{size:"sm",variant:"ghost",onClick:ne,children:me}),e[67]=me,e[68]=pe):pe=e[68];let G;e[69]!==r?(G=r("settings.common.actions.delete"),e[69]=r,e[70]=G):G=e[70];let K;e[71]!==v||e[72]!==G?(K=s.jsx(be,{size:"sm",onClick:v,children:G}),e[71]=v,e[72]=G,e[73]=K):K=e[73];let Q;e[74]!==pe||e[75]!==K?(Q=s.jsxs(_s,{children:[pe,K]}),e[74]=pe,e[75]=K,e[76]=Q):Q=e[76];let W;e[77]!==ie||e[78]!==Q?(W=s.jsxs(ds,{className:"max-w-md",children:[ie,Q]}),e[77]=ie,e[78]=Q,e[79]=W):W=e[79];let de;e[80]!==$||e[81]!==W?(de=s.jsx(us,{open:$,onOpenChange:O,children:W}),e[80]=$,e[81]=W,e[82]=de):de=e[82];let ge;return e[83]!==R||e[84]!==B||e[85]!==de?(ge=s.jsxs("div",{className:w,children:[R,B,de]}),e[83]=R,e[84]=B,e[85]=de,e[86]=ge):ge=e[86],ge};function EC(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function MC(t){return t.name}function RC(t,e){return t.name.localeCompare(e.name)}const FC=()=>{const{t}=ft(),{selectedSnippetName:e,snippets:n,snippetDraft:r,setSnippetDraft:a,updateSnippet:i,createSnippet:o}=rc(Gn(I=>({selectedSnippetName:I.selectedSnippetName,snippets:I.snippets,snippetDraft:I.snippetDraft,setSnippetDraft:I.setSnippetDraft,updateSnippet:I.updateSnippet,createSnippet:I.createSnippet}))),c=l.useMemo(()=>e?n.find(I=>I.name===e||I.aliases.includes(e))??null:null,[e,n]),d=!!(r&&r.name===e&&!c),[p,m]=l.useState(""),[u,f]=l.useState("global"),[b,x]=l.useState(""),[y,g]=l.useState(""),[h,j]=l.useState(""),[v,C]=l.useState(!1),k=l.useRef(null);l.useEffect(()=>{if(d&&r){const I={draftName:r.name||"",draftScope:r.scope||"global",description:r.description||"",aliases:(r.aliases||[]).join(", "),content:r.content||""};m(I.draftName),f(I.draftScope),x(I.description),g(I.aliases),j(I.content),k.current=I}else if(c){const I={draftName:"",draftScope:"global",description:c.description??"",aliases:c.aliases.join(", "),content:c.content};x(I.description),g(I.aliases),j(I.content),k.current=I}},[c,d,e,r]);const w=l.useMemo(()=>{const I=k.current;return I?d&&p!==I.draftName||d&&u!==I.draftScope?!0:b!==I.description||y!==I.aliases||h!==I.content:!1},[y,h,b,p,u,d]),N=async()=>{const I=d?p.trim().replace(/\s+/g,"-"):e?.trim();if(!I){H.error(t("settings.snippets.page.toast.nameRequired"));return}if(!h.trim()){H.error(t("settings.snippets.page.toast.contentRequired"));return}const T=y.split(",").map(P=>P.trim()).filter(Boolean);C(!0);try{if(!(d?await o(I,h,{aliases:T,description:b,scope:u}):await i(I,{content:h,aliases:T,description:b}))){H.error(t("settings.snippets.page.toast.saveFailed"));return}H.success(t("settings.snippets.page.toast.saved")),d&&a(null)}finally{C(!1)}};return e?s.jsx(Ss,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsxs("div",{className:"mb-4 min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:d?t("settings.snippets.page.title.new"):`#${e}`}),c?s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:c.filePath}):null]}),s.jsxs("div",{className:"mb-8 space-y-3 px-2",children:[s.jsxs("div",{children:[d?s.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"#"}),s.jsx(Lt,{value:p,onChange:I=>m(I.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(as,{value:u,onValueChange:I=>f(I),children:[s.jsx(is,{className:"w-fit min-w-[100px]",children:s.jsx(fs,{})}),s.jsxs(os,{align:"end",children:[s.jsx(Mt,{value:"global",children:t("settings.common.scope.global")}),s.jsx(Mt,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx(Lt,{value:b,onChange:I=>x(I.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"mt-1.5 h-7 w-full max-w-sm px-2"})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.aliases")}),s.jsx(Lt,{value:y,onChange:I=>g(I.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"mt-1.5 h-7 w-full max-w-sm px-2"})]})]}),s.jsxs("div",{className:"mb-2 px-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.content")}),s.jsx(un,{value:h,onChange:I=>j(I.target.value),placeholder:t("settings.snippets.page.field.contentPlaceholder"),rows:12,className:"mt-1.5 w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),s.jsx("p",{className:"mt-2 typography-meta text-muted-foreground",children:t("settings.snippets.page.hint")})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(be,{onClick:N,disabled:v||!w,size:"xs",className:"!font-normal",children:t(v?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(A,{name:"file-text",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.snippets.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.snippets.page.empty.description")})]})})},_g=()=>{const{t}=ft(),e=wt(u=>u.settingsGitmojiEnabled),n=wt(u=>u.setSettingsGitmojiEnabled),r=eu(),a=Fe(u=>u.gitChangesViewMode),i=Fe(u=>u.setGitChangesViewMode),[o,c]=l.useState(!0),d=l.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);l.useEffect(()=>{(async()=>{try{let f=null;if(!f){const b=or()?.settings;if(b)try{const y=(await b.load())?.settings;y&&(f={gitmojiEnabled:typeof y.gitmojiEnabled=="boolean"?y.gitmojiEnabled:void 0,gitChangesViewMode:y.gitChangesViewMode==="flat"||y.gitChangesViewMode==="tree"?y.gitChangesViewMode:void 0})}catch{}}if(!f){const b=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});b.ok&&(f=await b.json())}f&&(typeof f.gitmojiEnabled=="boolean"&&n(f.gitmojiEnabled),(f.gitChangesViewMode==="flat"||f.gitChangesViewMode==="tree")&&i(f.gitChangesViewMode))}catch(f){console.warn("Failed to load git settings:",f)}finally{c(!1)}})()},[i,n]);const p=l.useCallback(async u=>{n(u);try{await ks({gitmojiEnabled:u})}catch(f){console.warn("Failed to save gitmoji setting:",f)}},[n]),m=l.useCallback(u=>{u!==a&&(i(u),ks({gitChangesViewMode:u}))},[a,i]);return o?null:s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.git.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"pt-1 pb-1",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.git.changesViewTitle")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.openchamber.git.changesViewAria"),className:"mt-0.5 space-y-0",children:d.map(u=>{const f=a===u.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>{m(u.id)},onKeyDown:b=>{(b.key===" "||b.key==="Enter")&&(b.preventDefault(),m(u.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Fa,{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(vs,{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:()=>hc(!r),onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),hc(!r))},children:[s.jsx(vs,{checked:r,onChange:hc,ariaLabel:t("settings.openchamber.git.showGitignoredAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.showGitignored")})]})]})]})},Bg=()=>{const{t}=ft(),{isMobile:e}=ln(),n=or()?.github,r=Hn(I=>I.status),a=Hn(I=>I.isLoading),i=Hn(I=>I.hasChecked),o=Hn(I=>I.refreshStatus),c=Hn(I=>I.setStatus),d=l.useCallback(async I=>{await rr(I)},[]),[p,m]=l.useState(!1),[u,f]=l.useState(null),[b,x]=l.useState(null),y=l.useRef(null),g=l.useCallback(()=>{y.current!=null&&(window.clearInterval(y.current),y.current=null),x(null)},[]);l.useEffect(()=>((async()=>{try{i||await o(n)}catch(I){console.warn("Failed to load GitHub auth status:",I)}})(),()=>{g()}),[i,o,n,g]);const h=l.useCallback(async()=>{m(!0);try{const I=n?await n.authStart():await(async()=>{const P=await fetch("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),D=await P.json().catch(()=>null);if(!P.ok||!D||!("deviceCode"in D))throw new Error(D?.error||P.statusText);return D})();f(I),x(Math.max(1,I.interval)*1e3);const T=I.verificationUriComplete||I.verificationUri;d(T)}catch(I){console.error("Failed to start GitHub connect:",I),H.error(t("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[d,n,t]),j=l.useCallback(async I=>{if(n)return n.authComplete(I);const T=await fetch("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:I})}),P=await T.json().catch(()=>null);if(!T.ok||!P)throw new Error(P?.error||T.statusText);return P},[n]);l.useEffect(()=>{if(!(!u?.deviceCode||!b)&&y.current==null)return y.current=window.setInterval(()=>{(async()=>{try{const I=await j(u.deviceCode);if(I.connected){H.success(t("settings.github.page.toast.connected")),f(null),g(),await o(n,{force:!0});return}I.status==="slow_down"&&x(T=>T?T+5e3:5e3),(I.status==="expired_token"||I.status==="access_denied")&&(H.error(I.error||t("settings.github.page.toast.authorizationFailed")),f(null),g())}catch(I){console.warn("GitHub polling failed:",I)}})()},b),()=>{y.current!=null&&(window.clearInterval(y.current),y.current=null)}},[u,b,j,o,n,g,t]);const v=l.useCallback(async()=>{m(!0);try{if(g(),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)}H.success(t("settings.github.page.toast.disconnected")),await o(n,{force:!0})}catch(I){console.error("Failed to disconnect GitHub:",I),H.error(t("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[o,n,g,t]),C=l.useCallback(async I=>{if(I){m(!0);try{const T=n?await n.authActivate(I):await(async()=>{const P=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:I})}),D=await P.json().catch(()=>null);if(!P.ok||!D)throw new Error(D?.error||P.statusText);return D})();c(T),H.success(t("settings.github.page.toast.accountSwitched"))}catch(T){console.error("Failed to switch GitHub account:",T),H.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,c,t]);if(a)return null;const k=!!r?.connected,w=r?.user,N=r?.accounts??[];return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:"GitHub"}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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:[k?s.jsxs("div",{className:ye("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ye("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[w?.avatarUrl?s.jsx("img",{src:w.avatarUrl,alt:w.login?t("settings.github.page.avatarAlt.withLogin",{login:w.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:w?.name?.trim()||w?.login||"GitHub"}),s.jsxs("div",{className:ye("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(A,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:w?.login||t("settings.github.page.label.unknownUser")}),w?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),w?.email&&s.jsx("span",{children:w.email})]}),r?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.label.scopes",{value:r.scope})})]})]}),s.jsx(be,{size:"sm",variant:"outline",onClick:v,disabled:p,className:ye("text-[var(--status-error)] hover:text-[var(--status-error)]",e?"w-full":void 0),children:t("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.github.page.status.notConnected")})}),s.jsx(be,{size:"sm",variant:"default",onClick:h,disabled:p,children:t("settings.github.page.actions.connect")})]}),N.length>1&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:t("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:N.map(I=>{const T=I.user,P=!!I.current;return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[T?.avatarUrl?s.jsx("img",{src:T.avatarUrl,alt:T.login?t("settings.github.page.avatarAlt.withLogin",{login:T.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(A,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:T?.name?.trim()||T?.login||"GitHub"}),T?.login&&s.jsx("span",{className:"typography-micro text-muted-foreground truncate font-mono",children:T.login})]})]}),P?s.jsx("span",{className:"typography-micro text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:t("settings.github.page.status.active")}):s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>C(I.id),disabled:p,children:t("settings.github.page.actions.switchTo")})]},I.id)})})]})]}),k&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(be,{size:"sm",variant:"outline",onClick:h,disabled:p,className:ye(e?"w-full":void 0),children:t("settings.github.page.actions.addAccount")})}),u&&s.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h4",{className:"typography-ui-label text-foreground",children:t("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:u.userCode}),s.jsx(be,{size:"sm",asChild:!0,children:s.jsx("a",{href:u.verificationUriComplete||u.verificationUri,target:"_blank",rel:"noopener noreferrer",children:t("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.github.page.flow.waiting")}),s.jsx(be,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{g(),f(null)},children:t("settings.common.actions.cancel")})]})]})]})},Yp=[{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)"}],OC=[{key:"branch",Icon:"git-branch",label:"Branch"},{key:"briefcase",Icon:"briefcase",label:"Work"},{key:"house",Icon:"home",label:"Personal"},{key:"graduation",Icon:"graduation-cap",label:"School"},{key:"code",Icon:"code",label:"Code"}],LC=({open:t,onOpenChange:e,profileId:n,importData:r})=>{const{t:a}=ft(),i=tr(L=>L.getProfileById),o=tr(L=>L.createProfile),c=tr(L=>L.updateProfile),d=tr(L=>L.deleteProfile),p=l.useMemo(()=>n&&n!=="new"&&!r?i(n):null,[n,i,r]),m=n==="new"||r!=null,u=n==="global",[f,b]=l.useState(""),[x,y]=l.useState(""),[g,h]=l.useState(""),[j,v]=l.useState("ssh"),[C,k]=l.useState(""),[w,N]=l.useState(""),[I,T]=l.useState("keyword"),[P,D]=l.useState("branch"),[S,M]=l.useState(!1),[E,R]=l.useState(!1),[V,B]=l.useState(!1);l.useEffect(()=>{if(t){if(r){const L=r.host.split("/"),J=L.length>=3?L[L.length-1]:r.host;b(J),y(r.username),h(""),v("token"),k(""),N(r.host),T("string"),D("code")}else if(m)b(""),y(""),h(""),v("ssh"),k(""),N(""),T("keyword"),D("branch");else if(p)b(p.name),y(p.userName),h(p.userEmail),v(p.authType||"ssh"),k(p.sshKey||""),N(p.host||""),T(p.color||"keyword"),D(p.icon||"branch");else if(u){const L=i("global");L&&(b(L.name),y(L.userName),h(L.userEmail),v(L.authType||"ssh"),k(L.sshKey||""),N(L.host||""),T(L.color||"keyword"),D(L.icon||"branch"))}}},[t,n,p,m,r,u,i]);const $=async()=>{if(!x.trim()||!g.trim()){H.error(a("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(j==="token"&&!w.trim()){H.error(a("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}M(!0);try{const L={name:f.trim()||x.trim(),userName:x.trim(),userEmail:g.trim(),authType:j,sshKey:j==="ssh"&&C.trim()||null,host:j==="token"&&w.trim()||null,color:I,icon:P};let J;if(m)J=await o(L);else if(n)J=await c(n,L);else return;J?(H.success(a(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):H.error(a(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(L){console.error("Error saving profile:",L),H.error(a("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{M(!1)}},O=async()=>{if(!(!n||m)){B(!0);try{await d(n)?(H.success(a("settings.gitIdentities.editor.toast.profileDeleted")),R(!1),e(!1)):H.error(a("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(L){console.error("Error deleting profile:",L),H.error(a("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{B(!1)}}},_=l.useMemo(()=>Yp.find(J=>J.key===I)?.cssVar||"var(--syntax-keyword)",[I]),q=r?a("settings.gitIdentities.editor.title.importCredential"):m?a("settings.gitIdentities.editor.title.newIdentity"):u?a("settings.gitIdentities.editor.title.globalIdentity"):p?.name||a("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(us,{open:t,onOpenChange:e,children:s.jsxs(ds,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:q}),s.jsx(Ns,{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(Lt,{value:f,onChange:L=>b(L.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:Yp.map(L=>s.jsx("button",{type:"button",onClick:()=>T(L.key),className:ye("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",I===L.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:L.cssVar},title:L.label},L.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:OC.map(L=>{const J=L.Icon;return s.jsx("button",{type:"button",onClick:()=>D(L.key),className:ye("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",P===L.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:L.label,children:s.jsx(A,{name:J,className:"w-3.5 h-3.5",style:{color:P===L.key?_:"var(--surface-muted-foreground)"}})},L.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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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(Lt,{value:x,onChange:L=>y(L.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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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(Lt,{type:"email",value:g,onChange:L=>h(L.target.value),placeholder:a("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!u,readOnly:u,disabled:u,className:"h-8"})]})]}),!u&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(be,{size:"sm",type:"button",variant:"chip","aria-pressed":j==="ssh",onClick:()=>v("ssh"),children:[s.jsx(A,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(be,{size:"sm",type:"button",variant:"chip","aria-pressed":j==="token",onClick:()=>v("token"),children:[s.jsx(A,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",a("settings.gitIdentities.editor.field.authToken")]})]})]}),j==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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(Lt,{value:C,onChange:L=>k(L.target.value),placeholder:a("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),j==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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(Lt,{value:w,onChange:L=>N(L.target.value),placeholder:a("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(_s,{className:"gap-2",children:[!u&&!m&&s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>R(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(A,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",a("settings.common.actions.delete")]}),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:a(u?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!u&&s.jsx(be,{size:"sm",onClick:$,disabled:S,children:a(S?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(us,{open:E,onOpenChange:L=>{V||R(L)},children:s.jsxs(ds,{className:"max-w-md",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:a("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Ns,{children:a("settings.gitIdentities.page.deleteDialog.description",{name:p?.name||f})})]}),s.jsxs(_s,{children:[s.jsx(be,{variant:"ghost",onClick:()=>R(!1),disabled:V,children:a("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",variant:"destructive",onClick:()=>{O()},disabled:V,children:a("settings.common.actions.delete")})]})]})})]})},$C={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},_C={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},BC=()=>{const t=ot.c(116),{t:e}=ft(),{profiles:n,globalIdentity:r,defaultGitIdentityId:a,deleteProfile:i,loadProfiles:o,loadGlobalIdentity:c,loadDiscoveredCredentials:d,loadDefaultGitIdentityId:p,setDefaultGitIdentityId:m,getUnimportedCredentials:u}=tr(Gn(zC)),[f,b]=l.useState(!1),[x,y]=l.useState(null),[g,h]=l.useState(null),[j,v]=l.useState(null),[C,k]=l.useState(!1);let w,N;t[0]!==p||t[1]!==d||t[2]!==c||t[3]!==o?(w=()=>{o(),c(),d(),p()},N=[o,c,d,p],t[0]=p,t[1]=d,t[2]=c,t[3]=o,t[4]=w,t[5]=N):(w=t[4],N=t[5]),l.useEffect(w,N);let I,T,P,D,S,M,E,R,V,B,$,O,_;if(t[6]!==a||t[7]!==j||t[8]!==i||t[9]!==u||t[10]!==r||t[11]!==n||t[12]!==m||t[13]!==e){const Ce=u();let Ie;t[27]===Symbol.for("react.memo_cache_sentinel")?(Ie=(F,U)=>{y(F),h(U??null),b(!0)},t[27]=Ie):Ie=t[27];const ke=Ie;let X;t[28]!==a||t[29]!==m||t[30]!==e?(X=async F=>{const U=a===F?null:F;if(!await m(U)){H.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}H.success(e(U?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[28]=a,t[29]=m,t[30]=e,t[31]=X):X=t[31];const ae=X;let je;t[32]!==j||t[33]!==i||t[34]!==e?(je=async()=>{if(!j)return;k(!0),await i(j.id)?(H.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:j.name})),v(null)):H.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),k(!1)},t[32]=j,t[33]=i,t[34]=e,t[35]=je):je=t[35],T=je,I=Ss,D="h-full",S="w-full bg-background",_="mx-auto w-full max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",t[36]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(Bg,{}),t[36]=P):P=t[36],$="border-t border-border/40 pt-6";let le;t[37]!==e?(le=e("settings.gitIdentities.page.section.title"),t[37]=e,t[38]=le):le=t[38];let Ne;t[39]!==le?(Ne=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:le})}),t[39]=le,t[40]=Ne):Ne=t[40];let Me,Ve;t[41]===Symbol.for("react.memo_cache_sentinel")?(Me=()=>ke("new"),Ve=s.jsx(A,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=Me,t[42]=Ve):(Me=t[41],Ve=t[42]);let we;t[43]!==e?(we=e("settings.common.badge.new"),t[43]=e,t[44]=we):we=t[44];let ee;t[45]!==we?(ee=s.jsxs(be,{size:"sm",variant:"outline",onClick:Me,children:[Ve," ",we]}),t[45]=we,t[46]=ee):ee=t[46],t[47]!==Ne||t[48]!==ee?(O=s.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[Ne,ee]}),t[47]=Ne,t[48]=ee,t[49]=O):O=t[49],M="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",E=r&&s.jsx(Qp,{profile:r,isDefault:a==="global",onEdit:()=>ke("global"),onToggleDefault:()=>ae("global"),isReadOnly:!0,hasBorder:n.length>0||Ce.length>0}),R=n.map((F,U)=>s.jsx(Qp,{profile:F,isDefault:a===F.id,onEdit:()=>ke(F.id),onToggleDefault:()=>ae(F.id),onDelete:()=>v(F),hasBorder:U<n.length-1||Ce.length>0},F.id)),V=!r&&n.length===0&&Ce.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(A,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),B=Ce.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")})}),Ce.map((F,U)=>s.jsx(VC,{credential:F,onImport:()=>ke("new",{host:F.host,username:F.username}),hasBorder:U<Ce.length-1},`${F.host}-${F.username}`))]}),t[6]=a,t[7]=j,t[8]=i,t[9]=u,t[10]=r,t[11]=n,t[12]=m,t[13]=e,t[14]=I,t[15]=T,t[16]=P,t[17]=D,t[18]=S,t[19]=M,t[20]=E,t[21]=R,t[22]=V,t[23]=B,t[24]=$,t[25]=O,t[26]=_}else I=t[14],T=t[15],P=t[16],D=t[17],S=t[18],M=t[19],E=t[20],R=t[21],V=t[22],B=t[23],$=t[24],O=t[25],_=t[26];let q;t[50]!==M||t[51]!==E||t[52]!==R||t[53]!==V||t[54]!==B?(q=s.jsxs("div",{className:M,children:[E,R,V,B]}),t[50]=M,t[51]=E,t[52]=R,t[53]=V,t[54]=B,t[55]=q):q=t[55];let L;t[56]!==q||t[57]!==$||t[58]!==O?(L=s.jsxs("div",{className:$,children:[O,q]}),t[56]=q,t[57]=$,t[58]=O,t[59]=L):L=t[59];let J;t[60]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(_g,{}),t[60]=J):J=t[60];let Z;t[61]!==P||t[62]!==L||t[63]!==_?(Z=s.jsxs("div",{className:_,children:[P,L,J]}),t[61]=P,t[62]=L,t[63]=_,t[64]=Z):Z=t[64];let ie;t[65]!==I||t[66]!==D||t[67]!==S||t[68]!==Z?(ie=s.jsx(I,{outerClassName:D,className:S,children:Z}),t[65]=I,t[66]=D,t[67]=S,t[68]=Z,t[69]=ie):ie=t[69];let ne;t[70]!==g||t[71]!==f||t[72]!==x?(ne=s.jsx(LC,{open:f,onOpenChange:b,profileId:x,importData:g}),t[70]=g,t[71]=f,t[72]=x,t[73]=ne):ne=t[73];const me=j!==null;let pe;t[74]!==C?(pe=Ce=>{C||Ce||v(null)},t[74]=C,t[75]=pe):pe=t[75];let G;t[76]!==e?(G=e("settings.gitIdentities.page.deleteDialog.title"),t[76]=e,t[77]=G):G=t[77];let K;t[78]!==G?(K=s.jsx(ms,{children:G}),t[78]=G,t[79]=K):K=t[79];const Q=j?.name??"";let W;t[80]!==e||t[81]!==Q?(W=e("settings.gitIdentities.page.deleteDialog.description",{name:Q}),t[80]=e,t[81]=Q,t[82]=W):W=t[82];let de;t[83]!==W?(de=s.jsx(Ns,{children:W}),t[83]=W,t[84]=de):de=t[84];let ge;t[85]!==K||t[86]!==de?(ge=s.jsxs(hs,{children:[K,de]}),t[85]=K,t[86]=de,t[87]=ge):ge=t[87];let ve;t[88]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>v(null),t[88]=ve):ve=t[88];let te;t[89]!==e?(te=e("settings.common.actions.cancel"),t[89]=e,t[90]=te):te=t[90];let he;t[91]!==C||t[92]!==te?(he=s.jsx(be,{variant:"ghost",onClick:ve,disabled:C,children:te}),t[91]=C,t[92]=te,t[93]=he):he=t[93];let ce;t[94]!==T?(ce=()=>{T()},t[94]=T,t[95]=ce):ce=t[95];let xe;t[96]!==e?(xe=e("settings.common.actions.delete"),t[96]=e,t[97]=xe):xe=t[97];let se;t[98]!==C||t[99]!==ce||t[100]!==xe?(se=s.jsx(be,{size:"sm",variant:"destructive",onClick:ce,disabled:C,children:xe}),t[98]=C,t[99]=ce,t[100]=xe,t[101]=se):se=t[101];let ue;t[102]!==he||t[103]!==se?(ue=s.jsxs(_s,{children:[he,se]}),t[102]=he,t[103]=se,t[104]=ue):ue=t[104];let Y;t[105]!==ge||t[106]!==ue?(Y=s.jsxs(ds,{className:"max-w-md",children:[ge,ue]}),t[105]=ge,t[106]=ue,t[107]=Y):Y=t[107];let Se;t[108]!==me||t[109]!==pe||t[110]!==Y?(Se=s.jsx(us,{open:me,onOpenChange:pe,children:Y}),t[108]=me,t[109]=pe,t[110]=Y,t[111]=Se):Se=t[111];let fe;return t[112]!==ie||t[113]!==ne||t[114]!==Se?(fe=s.jsxs(s.Fragment,{children:[ie,ne,Se]}),t[112]=ie,t[113]=ne,t[114]=Se,t[115]=fe):fe=t[115],fe},Qp=t=>{const e=ot.c(54),{profile:n,isDefault:r,onEdit:a,onToggleDefault:i,onDelete:o,isReadOnly:c,hasBorder:d}=t,{t:p}=ft(),m=$C[n.icon||"branch"]||"git-branch",u=_C[n.color||""],f=n.authType||"ssh";let b;e[0]!==a?(b=O=>{O.currentTarget===O.target&&(O.key!=="Enter"&&O.key!==" "||(O.preventDefault(),a()))},e[0]=a,e[1]=b):b=e[1];const x=b,y=d&&"border-b border-[var(--surface-subtle)]";let g;e[2]!==y?(g=ye("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",y),e[2]=y,e[3]=g):g=e[3];let h;e[4]!==u?(h={color:u},e[4]=u,e[5]=h):h=e[5];let j;e[6]!==m||e[7]!==h?(j=s.jsx(A,{name:m,className:"w-4 h-4 shrink-0",style:h}),e[6]=m,e[7]=h,e[8]=j):j=e[8];let v;e[9]!==n.name?(v=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:n.name}),e[9]=n.name,e[10]=v):v=e[10];let C;e[11]!==f?(C=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:f}),e[11]=f,e[12]=C):C=e[12];let k;e[13]!==r||e[14]!==p?(k=r&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:p("settings.gitIdentities.page.badge.default")}),e[13]=r,e[14]=p,e[15]=k):k=e[15];let w;e[16]!==c||e[17]!==p?(w=c&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:p("settings.agents.sidebar.badge.system")}),e[16]=c,e[17]=p,e[18]=w):w=e[18];let N;e[19]!==v||e[20]!==C||e[21]!==k||e[22]!==w?(N=s.jsxs("div",{className:"flex items-center gap-1.5",children:[v,C,k,w]}),e[19]=v,e[20]=C,e[21]=k,e[22]=w,e[23]=N):N=e[23];const I=f==="token"&&n.host?n.host:n.userEmail;let T;e[24]!==I?(T=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:I}),e[24]=I,e[25]=T):T=e[25];let P;e[26]!==N||e[27]!==T?(P=s.jsxs("div",{className:"min-w-0",children:[N,T]}),e[26]=N,e[27]=T,e[28]=P):P=e[28];let D;e[29]!==P||e[30]!==j?(D=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[j,P]}),e[29]=P,e[30]=j,e[31]=D):D=e[31];let S;e[32]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(Is,{asChild:!0,children:s.jsx(be,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:UC,children:s.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[32]=S):S=e[32];let M;e[33]!==i?(M=O=>{O.stopPropagation(),i()},e[33]=i,e[34]=M):M=e[34];let E;e[35]!==r||e[36]!==p?(E=p(r?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault"),e[35]=r,e[36]=p,e[37]=E):E=e[37];let R;e[38]!==M||e[39]!==E?(R=s.jsx(_t,{onClick:M,children:E}),e[38]=M,e[39]=E,e[40]=R):R=e[40];let V;e[41]!==c||e[42]!==o||e[43]!==p?(V=!c&&o&&s.jsxs(_t,{onClick:O=>{O.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]}),e[41]=c,e[42]=o,e[43]=p,e[44]=V):V=e[44];let B;e[45]!==R||e[46]!==V?(B=s.jsxs(As,{children:[S,s.jsxs(Ps,{align:"end",className:"w-fit min-w-28",children:[R,V]})]}),e[45]=R,e[46]=V,e[47]=B):B=e[47];let $;return e[48]!==x||e[49]!==a||e[50]!==D||e[51]!==B||e[52]!==g?($=s.jsxs("div",{className:g,onClick:a,role:"button",tabIndex:0,onKeyDown:x,children:[D,B]}),e[48]=x,e[49]=a,e[50]=D,e[51]=B,e[52]=g,e[53]=$):$=e[53],$},VC=t=>{const e=ot.c(21),{credential:n,onImport:r,hasBorder:a}=t,{t:i}=ft();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=ye("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",m),e[2]=m,e[3]=u):u=e[3];let f;e[4]!==d?(f=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:d}),e[4]=d,e[5]=f):f=e[5];const b=p?n.host:n.username;let x;e[6]!==b?(x=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:b}),e[6]=b,e[7]=x):x=e[7];let y;e[8]!==f||e[9]!==x?(y=s.jsxs("div",{className:"min-w-0",children:[f,x]}),e[8]=f,e[9]=x,e[10]=y):y=e[10];let g;e[11]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(A,{name:"download",className:"h-3 w-3"}),e[11]=g):g=e[11];let h;e[12]!==i?(h=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=h):h=e[13];let j;e[14]!==r||e[15]!==h?(j=s.jsxs(be,{size:"sm",variant:"ghost",onClick:r,className:"gap-1 shrink-0",children:[g,h]}),e[14]=r,e[15]=h,e[16]=j):j=e[16];let v;return e[17]!==j||e[18]!==u||e[19]!==y?(v=s.jsxs("div",{className:u,children:[y,j]}),e[17]=j,e[18]=u,e[19]=y,e[20]=v):v=e[20],v};function zC(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 UC(t){return t.stopPropagation()}const Vg=()=>{const t=py();return{displayMode:t,installed:t!=="browser",browserTab:t==="browser"}},zg=()=>{const t=ot.c(2),[e,n]=l.useState(WC);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(Vg())};o();for(const c of i)typeof c.addEventListener=="function"?c.addEventListener("change",o):typeof c.addListener=="function"&&c.addListener(o);return window.addEventListener("appinstalled",o),window.addEventListener("focus",o),()=>{for(const c of i)typeof c.removeEventListener=="function"?c.removeEventListener("change",o):typeof c.removeListener=="function"&&c.removeListener(o);window.removeEventListener("appinstalled",o),window.removeEventListener("focus",o)}},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),l.useEffect(r,a),e};function WC(){return Vg()}const KC=[{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"}],HC=[{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"}],GC=[{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"}],qC=[{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"}],Ki="OpenChamber - AI Coding Assistant",Xp=[{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"}],Zp=[{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"}],Jc=t=>t==="portrait"||t==="landscape"?t:"system",JC=[{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"}],YC=[{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"}],ef=[{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"}],QC=[{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"}],tf=[{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"}],sf=[{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"}],XC=t=>t==="markdown"?"markdown":"plain",ju=({visibleSettings:t})=>{const{locale:e,locales:n,setLocale:r,label:a,t:i}=ft(),o=l.useCallback(re=>i(re),[i]),{isMobile:c}=ln(),{browserTab:d}=zg(),p=ec(),m=Fe(re=>re.showReasoningTraces),u=Fe(re=>re.setShowReasoningTraces),f=Fe(re=>re.collapsibleThinkingBlocks),b=Fe(re=>re.setCollapsibleThinkingBlocks),x=Fe(re=>re.mermaidRenderingMode),y=Fe(re=>re.setMermaidRenderingMode),g=Fe(re=>re.userMessageRenderingMode),h=Fe(re=>re.setUserMessageRenderingMode),j=Fe(re=>re.stickyUserHeader),v=Fe(re=>re.setStickyUserHeader),C=Fe(re=>re.wideChatLayoutEnabled),k=Fe(re=>re.setWideChatLayoutEnabled),w=Fe(re=>re.chatRenderMode),N=Fe(re=>re.setChatRenderMode),I=Fe(re=>re.activityRenderMode),T=Fe(re=>re.setActivityRenderMode),P=Fe(re=>re.fontSize),D=Fe(re=>re.setFontSize),S=Fe(re=>re.terminalFontSize),M=Fe(re=>re.setTerminalFontSize),E=Fe(re=>re.uiFont),R=Fe(re=>re.setUiFont),V=Fe(re=>re.monoFont),B=Fe(re=>re.setMonoFont),$=Fe(re=>re.padding),O=Fe(re=>re.setPadding),_=Fe(re=>re.inputBarOffset),q=Fe(re=>re.setInputBarOffset),L=Fe(re=>re.mobileKeyboardMode),J=Fe(re=>re.setMobileKeyboardMode),Z=Fe(re=>re.diffLayoutPreference),ie=Fe(re=>re.setDiffLayoutPreference),ne=Fe(re=>re.diffViewMode),me=Fe(re=>re.setDiffViewMode),pe=Fe(re=>re.showTerminalQuickKeysOnDesktop),G=Fe(re=>re.setShowTerminalQuickKeysOnDesktop),K=Hu(re=>re.queueModeEnabled),Q=Hu(re=>re.setQueueMode),W=Fe(re=>re.persistChatDraft),de=Fe(re=>re.setPersistChatDraft),ge=Fe(re=>re.inputSpellcheckEnabled),ve=Fe(re=>re.setInputSpellcheckEnabled),te=Fe(re=>re.showToolFileIcons),he=Fe(re=>re.setShowToolFileIcons),ce=Fe(re=>re.showExpandedBashTools),xe=Fe(re=>re.setShowExpandedBashTools),se=Fe(re=>re.showExpandedEditTools),ue=Fe(re=>re.setShowExpandedEditTools),Y=Fe(re=>re.timeFormatPreference),Se=Fe(re=>re.setTimeFormatPreference),fe=Fe(re=>re.weekStartPreference),Ce=Fe(re=>re.setWeekStartPreference),Ie=Fe(re=>re.showSplitAssistantMessageActions),ke=Fe(re=>re.setShowSplitAssistantMessageActions),X=Fe(re=>re.showMobileSessionStatusBar),ae=Fe(re=>re.setShowMobileSessionStatusBar),je=wt(re=>re.settingsMessageStreamTransport),le=wt(re=>re.setSettingsMessageStreamTransport),Ne=Fe(re=>re.isSettingsDialogOpen),{themeMode:Me,setThemeMode:Ve,availableThemes:we,customThemesLoading:ee,reloadCustomThemes:F,lightThemeId:U,darkThemeId:oe,setLightThemePreference:Te,setDarkThemePreference:Oe}=jr(),[Pe,z]=l.useState(!1),[De,Qe]=l.useState(0),et=Fe(re=>re.reportUsage),Ze=Fe(re=>re.setReportUsage),We=l.useCallback(re=>{Ze(re),ks({reportUsage:re})},[Ze]),it=Ne&&(t?t.includes("chatRenderMode"):!0);l.useEffect(()=>{if(!it)return;let re=null,vt=Date.now();const Ft=()=>{const ls=Date.now();ls-vt>=420&&(Qe(cs=>(cs+1)%24),vt=ls),re=requestAnimationFrame(Ft)};(typeof document>"u"||document.visibilityState==="visible")&&(re=requestAnimationFrame(Ft));const ct=()=>{document.visibilityState==="visible"&&re===null?re=requestAnimationFrame(Ft):document.visibilityState!=="visible"&&re!==null&&(cancelAnimationFrame(re),re=null)};return document.addEventListener("visibilitychange",ct),()=>{document.removeEventListener("visibilitychange",ct),re!==null&&cancelAnimationFrame(re)}},[it]);const qe=l.useCallback(re=>{h(re),ks({userMessageRenderingMode:re})},[h]),st=l.useCallback(re=>{v(re),ks({stickyUserHeader:re})},[v]),Je=l.useCallback(re=>{k(re),ks({wideChatLayoutEnabled:re})},[k]),Be=l.useCallback(re=>{ke(re),ks({showSplitAssistantMessageActions:re})},[ke]),nt=l.useCallback(re=>{ve(re),ks({inputSpellcheckEnabled:re})},[ve]),Ge=l.useCallback(re=>{N(re),ks({chatRenderMode:re})},[N]),at=l.useCallback(re=>{le(re),ks({messageStreamTransport:re})},[le]),Ae=l.useCallback(re=>{T(re),ks({activityRenderMode:re})},[T]),Le=l.useCallback(re=>{y(re),ks({mermaidRenderingMode:re})},[y]),ze=l.useCallback(re=>{he(re),ks({showToolFileIcons:re})},[he]),Ke=l.useCallback(re=>{xe(re),ks({showExpandedBashTools:re})},[xe]),lt=l.useCallback(re=>{ue(re),ks({showExpandedEditTools:re})},[ue]),xt=l.useCallback(re=>{Se(re),ks({timeFormatPreference:re})},[Se]),dt=l.useCallback(re=>{Ce(re),ks({weekStartPreference:re})},[Ce]),ut=l.useMemo(()=>we.filter(re=>re.metadata.variant==="light").sort((re,vt)=>re.metadata.name.localeCompare(vt.metadata.name)),[we]),Nt=l.useMemo(()=>we.filter(re=>re.metadata.variant==="dark").sort((re,vt)=>re.metadata.name.localeCompare(vt.metadata.name)),[we]),ts=l.useMemo(()=>ut.find(re=>re.metadata.id===U)??ut[0],[ut,U]),Vt=l.useMemo(()=>Nt.find(re=>re.metadata.id===oe)??Nt[0],[Nt,oe]),Xt=l.useCallback((re,vt)=>{const Ft=vt==="dark"?" Dark":" Light";return re.endsWith(Ft)?re.slice(0,-Ft.length):re},[]),ht=re=>t?t.includes(re):!0,Bt=fn(),Zt=ht("theme")&&!Bt,gs=ht("theme")||ht("timeFormat")||ht("weekStart"),rs=Bt?gs:ht("theme")||ht("pwaInstallName")||ht("pwaOrientation")||ht("timeFormat")||ht("weekStart"),ps=ht("fontSize")||ht("terminalFontSize")||ht("spacing")||ht("inputBarOffset"),Ut=ht("terminalQuickKeys")&&!c,Ye=ht("mermaidRendering")||ht("userMessageRendering")||ht("chatRenderMode")||ht("messageTransport")||ht("activityRenderMode")&&w==="sorted"||ht("stickyUserHeader")||ht("wideChatLayout")||ht("splitAssistantMessageActions")||ht("diffLayout")||ht("mobileStatusBar")&&c||ht("dotfiles")||ht("reasoning")||ht("queueMode")||ht("persistDraft")||ht("showToolFileIcons")||ht("expandedTools")||!c&&ht("inputSpellcheck"),Tt=ht("pwaInstallName")&&ea()&&d&&!jn()&&!Bt,Kt=ht("pwaOrientation")&&ea()&&!jn()&&!Bt,St=ht("mobileKeyboardMode")&&ea()&&!jn()&&!Bt&&fy(),[es,ss]=l.useState(""),[Ms,xs]=l.useState("system"),Bs=l.useMemo(()=>{const re=tf.find(vt=>vt.id===Y);return o(re?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Y,o]),ws=l.useMemo(()=>{const re=sf.find(vt=>vt.id===fe);return o(re?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[fe,o]),xn=l.useMemo(()=>{const re=Xp.find(vt=>vt.id===Ms);return re?o(re.labelKey):void 0},[Ms,o]),Qs=l.useMemo(()=>{const re=Zp.find(vt=>vt.id===L);return re?o(re.labelKey):void 0},[L,o]),Wt=l.useCallback(async re=>{if(typeof window>"u")return;const vt=window,ct=re.trim().replace(/\s+/g," ").slice(0,64);if(await ks({pwaAppName:ct}),typeof vt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const ls=vt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(ct);ss(ls);return}ss(ct||Ki),vt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),qt=l.useCallback(async re=>{if(typeof window>"u")return;const vt=window,Ft=Jc(re);if(await ks({pwaOrientation:Ft}),typeof vt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const ct=vt.__OPENCHAMBER_SET_PWA_ORIENTATION__(Ft);xs(ct);return}xs(Ft),vt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return l.useEffect(()=>{if(typeof window>"u"||!Tt&&!Kt&&!St)return;let re=!1;return(async()=>{try{const Ft=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!Ft.ok){re||ss(Ki);return}const ct=await Ft.json().catch(()=>({})),cs=(typeof ct?.pwaAppName=="string"?ct.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),He=Jc(ct?.pwaOrientation),yt=Qu(ct?.mobileKeyboardMode);re||(Tt&&ss(cs||Ki),Kt&&xs(He),St&&J(yt))}catch{re||(Tt&&ss(Ki),Kt&&xs("system"),St&&J("native"))}})(),()=>{re=!0}},[J,St,Tt,Kt]),s.jsxs("div",{className:"space-y-8",children:[rs&&s.jsxs("div",{className:"mb-8 space-y-6",children:[Zt&&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:KC.map(re=>s.jsx(be,{variant:"chip",size:"xs","aria-pressed":Me===re.value,className:"!font-normal",onClick:()=>Ve(re.value),children:o(re.labelKey)},re.value))})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.lightTheme")}),s.jsxs(as,{value:ts?.metadata.id??"",onValueChange:Te,children:[s.jsx(is,{"aria-label":i("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:s.jsx(fs,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:ts?Xt(ts.metadata.name,"light"):void 0})}),s.jsx(os,{children:ut.map(re=>s.jsx(Mt,{value:re.metadata.id,children:Xt(re.metadata.name,"light")},re.metadata.id))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.darkTheme")}),s.jsxs(as,{value:Vt?.metadata.id??"",onValueChange:Oe,children:[s.jsx(is,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:s.jsx(fs,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:Vt?Xt(Vt.metadata.name,"dark"):void 0})}),s.jsx(os,{children:Nt.map(re=>s.jsx(Mt,{value:re.metadata.id,children:Xt(re.metadata.name,"dark")},re.metadata.id))})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("button",{type:"button",disabled:ee||Pe,onClick:()=>{const re=Date.now();z(!0),F().finally(()=>{const vt=Date.now()-re;if(vt<500){window.setTimeout(()=>{z(!1)},500-vt);return}z(!1)})},className:"inline-flex items-center typography-ui-label font-normal text-foreground underline decoration-[1px] underline-offset-2 hover:text-foreground/80 disabled:cursor-not-allowed disabled:text-muted-foreground/60",children:i(Pe?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:"flex items-center justify-center rounded-md p-1 text-muted-foreground/70 hover:text-foreground","aria-label":i("settings.openchamber.visual.field.themeImportInfoAria"),children:s.jsx(A,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(It,{sideOffset:8,children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),gs&&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(as,{value:e,onValueChange:re=>r(re),children:[s.jsx(is,{"aria-label":i("settings.appearance.language.select"),className:"w-fit",children:s.jsx(fs,{children:a(e)})}),s.jsx(os,{children:n.map(re=>s.jsx(Mt,{value:re,children:a(re)},re))})]})]}),!Bt&&(ht("timeFormat")||ht("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:[ht("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(as,{value:Y,onValueChange:re=>xt(re),children:[s.jsx(is,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:s.jsx(fs,{children:Bs})}),s.jsx(os,{children:tf.map(re=>s.jsx(Mt,{value:re.id,children:o(re.labelKey)},re.id))})]})]}),ht("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(as,{value:fe,onValueChange:re=>dt(re),children:[s.jsx(is,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:s.jsx(fs,{children:ws})}),s.jsx(os,{children:sf.map(re=>s.jsx(Mt,{value:re.id,children:o(re.labelKey)},re.id))})]})]})]})]}),(Tt||Kt||St)&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[Tt&&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(Lt,{value:es,onChange:re=>{ss(re.target.value)},onBlur:()=>{Wt(es)},onKeyDown:re=>{re.key==="Enter"&&(re.preventDefault(),Wt(es))},className:"h-7",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ss(Ki),Wt("")},className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:i("settings.common.actions.reset"),children:s.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Kt&&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(as,{value:Ms,onValueChange:re=>{const vt=Jc(re);xs(vt),qt(vt)},children:[s.jsx(is,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),className:"w-full",children:s.jsx(fs,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:xn})}),s.jsx(os,{children:Xp.map(re=>s.jsx(Mt,{value:re.id,children:o(re.labelKey)},re.id))})]}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>{xs("system"),qt("system")},disabled:Ms==="system",className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:i("settings.common.actions.reset"),children:s.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),St&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.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(as,{value:L,onValueChange:re=>{const vt=Qu(re);J(vt),ks({mobileKeyboardMode:vt})},children:[s.jsx(is,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),className:"w-full",children:s.jsx(fs,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Qs})}),s.jsx(os,{children:Zp.map(re=>s.jsx(Mt,{value:re.id,children:o(re.labelKey)},re.id))})]}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>{J("native"),ks({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(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]}),ps&&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:[ht("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(as,{value:E,onValueChange:re=>R(re),children:[s.jsx(is,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:s.jsx(fs,{children:Gu.find(re=>re.id===E)?.label})}),s.jsx(os,{children:Gu.map(re=>s.jsx(Mt,{value:re.id,children:s.jsx("span",{style:{fontFamily:re.stack},children:re.label})},re.id))})]}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>R(qu),disabled:E===qu,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ht("terminalFontSize")&&s.jsxs("div",{className:ye("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ye("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:ye("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsxs(as,{value:V,onValueChange:re=>B(re),children:[s.jsx(is,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:s.jsx(fs,{children:Ju.find(re=>re.id===V)?.label})}),s.jsx(os,{children:Ju.map(re=>s.jsx(Mt,{value:re.id,children:s.jsx("span",{style:{fontFamily:re.stack},children:re.label})},re.id))})]}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>B(Yu),disabled:V===Yu,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetCodeFontAria"),title:i("settings.common.actions.reset"),children:s.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ht("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($n,{value:P,onValueChange:D,min:50,max:200,step:5,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria"),className:"w-16"}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>D(100),disabled:P===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ht("terminalFontSize")&&s.jsxs("div",{className:ye("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ye("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:ye("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx($n,{value:S,onValueChange:M,min:9,max:52,step:1,className:"w-16"}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>M(13),disabled:S===13,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ht("spacing")&&s.jsxs("div",{className:ye("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ye("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:ye("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx($n,{value:$,onValueChange:O,min:50,max:200,step:5,className:"w-16"}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>O(100),disabled:$===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetSpacingAria"),title:i("settings.common.actions.reset"),children:s.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ht("inputBarOffset")&&s.jsxs("div",{className:ye("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:ye("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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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:ye("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx($n,{value:_,onValueChange:q,min:0,max:100,step:5,className:"w-16"}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>q(0),disabled:_===0,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:i("settings.common.actions.reset"),children:s.jsx(A,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]})}),Ut&&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")}),ht("terminalQuickKeys")&&!c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":pe,onClick:()=>G(!pe),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),G(!pe))},children:[s.jsx(vs,{checked:pe,onChange:G,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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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")})]})]})]})]})}),Ye&&s.jsxs("div",{className:"space-y-3",children:[(ht("userMessageRendering")||ht("mermaidRendering")||ht("chatRenderMode")||ht("messageTransport")||ht("activityRenderMode")&&w==="sorted"||ht("diffLayout")&&!Bt)&&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:[ht("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:YC.map(re=>{const vt=w===re.id,Ft=De%12;return s.jsxs("button",{type:"button",onClick:()=>Ge(re.id),"aria-pressed":vt,className:ye("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",vt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:ye("typography-ui-label",vt?"text-foreground":"text-muted-foreground"),children:o(re.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:re.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(ct=>{const ls=ct*3+1,cs=Ft-ls+1,He=cs<=0?0:cs===1?42:cs===2?68:92,yt=He>0;return s.jsxs("div",{className:ye("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",yt?"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:`${He}%`}})]},ct)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(ct=>{const ls=Ft>=(ct+1)*3;return s.jsxs("div",{className:ye("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",ls?"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%"}})]},ct)})})})]},re.id)})})]}),ht("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:ef.map(re=>s.jsx(be,{variant:"chip",size:"xs","aria-pressed":je===re.id,className:"!font-normal",onClick:()=>at(re.id),children:o(re.labelKey)},re.id))}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const re=ef.find(vt=>vt.id===je);return re?.descriptionKey?o(re.descriptionKey):""})()})]})]}),ht("activityRenderMode")&&w==="sorted"&&s.jsxs("section",{className:"p-2 md:col-span-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.activityDefault")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.activityDefaultAria"),className:"mt-0.5 space-y-0",children:QC.map(re=>{const vt=I===re.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":vt,onClick:()=>Ae(re.id),onKeyDown:Ft=>{(Ft.key===" "||Ft.key==="Enter")&&(Ft.preventDefault(),Ae(re.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Fa,{checked:vt,onChange:()=>Ae(re.id),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:o(re.labelKey)})}),s.jsx("span",{className:ye("typography-ui-label font-normal",vt?"text-foreground":"text-foreground/50"),children:o(re.labelKey)})]},re.id)})})]}),ht("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":ce,onClick:()=>Ke(!ce),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),Ke(!ce))},children:[s.jsx(vs,{checked:ce,onChange:Ke,ariaLabel:i("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.bash")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":se,onClick:()=>lt(!se),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),lt(!se))},children:[s.jsx(vs,{checked:se,onChange:lt,ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editTools")})]})]}),ht("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:JC.map(re=>{const vt=XC(g)===re.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":vt,onClick:()=>qe(re.id),onKeyDown:Ft=>{(Ft.key===" "||Ft.key==="Enter")&&(Ft.preventDefault(),qe(re.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Fa,{checked:vt,onChange:()=>qe(re.id),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:o(re.labelKey)})}),s.jsx("span",{className:ye("typography-ui-label font-normal",vt?"text-foreground":"text-foreground/50"),children:o(re.labelKey)})]},re.id)})})]}),ht("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:qC.map(re=>{const vt=x===re.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":vt,onClick:()=>Le(re.id),onKeyDown:Ft=>{(Ft.key===" "||Ft.key==="Enter")&&(Ft.preventDefault(),Le(re.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Fa,{checked:vt,onChange:()=>Le(re.id),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:o(re.labelKey)})}),s.jsx("span",{className:ye("typography-ui-label font-normal",vt?"text-foreground":"text-foreground/50"),children:o(re.labelKey)})]},re.id)})})]}),ht("diffLayout")&&!Bt&&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:HC.map(re=>{const vt=Z===re.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":vt,onClick:()=>ie(re.id),onKeyDown:Ft=>{(Ft.key===" "||Ft.key==="Enter")&&(Ft.preventDefault(),ie(re.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Fa,{checked:vt,onChange:()=>ie(re.id),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:o(re.labelKey)})}),s.jsx("span",{className:ye("typography-ui-label font-normal",vt?"text-foreground":"text-foreground/50"),children:o(re.labelKey)})]},re.id)})})]}),ht("diffLayout")&&!Bt&&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:GC.map(re=>{const vt=ne===re.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":vt,onClick:()=>me(re.id),onKeyDown:Ft=>{(Ft.key===" "||Ft.key==="Enter")&&(Ft.preventDefault(),me(re.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Fa,{checked:vt,onChange:()=>me(re.id),ariaLabel:i("settings.openchamber.visual.field.diffViewModeAria",{option:o(re.labelKey)})}),s.jsx("span",{className:ye("typography-ui-label font-normal",vt?"text-foreground":"text-foreground/50"),children:o(re.labelKey)})]},re.id)})})]})]}),(ht("stickyUserHeader")||ht("wideChatLayout")||ht("splitAssistantMessageActions")||ht("mobileStatusBar")&&c||ht("dotfiles")||ht("queueMode")||ht("persistDraft")||ht("showToolFileIcons")||!c&&ht("inputSpellcheck")||ht("reasoning"))&&s.jsxs("section",{className:"p-2 space-y-0.5",children:[ht("reasoning")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),u(!m))},children:[s.jsx(vs,{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")})]}),ht("reasoning")&&m&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>b(!f),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),b(!f))},children:[s.jsx(vs,{checked:f,onChange:b,ariaLabel:i("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.collapsibleThinkingBlocks")})]}),ht("stickyUserHeader")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":j,onClick:()=>st(!j),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),st(!j))},children:[s.jsx(vs,{checked:j,onChange:st,ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.stickyUserHeader")})]}),ht("wideChatLayout")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":C,onClick:()=>Je(!C),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),Je(!C))},children:[s.jsx(vs,{checked:C,onChange:Je,ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.wideChatLayout")})]}),ht("splitAssistantMessageActions")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Ie,onClick:()=>Be(!Ie),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),Be(!Ie))},children:[s.jsx(vs,{checked:Ie,onChange:Be,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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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")})]})]})]}),ht("showToolFileIcons")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":te,onClick:()=>ze(!te),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),ze(!te))},children:[s.jsx(vs,{checked:te,onChange:ze,ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showToolFileIcons")})]}),ht("mobileStatusBar")&&c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":X,onClick:()=>ae(!X),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),ae(!X))},children:[s.jsx(vs,{checked:X,onChange:ae,ariaLabel:i("settings.openchamber.visual.field.showMobileStatusBarAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showMobileStatusBar")})]}),ht("dotfiles")&&!fn()&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>ol(!p),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),ol(!p))},children:[s.jsx(vs,{checked:p,onChange:ol,ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showDotfiles")})]}),ht("queueMode")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":K,onClick:()=>Q(!K),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),Q(!K))},children:[s.jsx(vs,{checked:K,onChange:Q,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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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:Zi()})})]})]})]}),ht("persistDraft")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":W,onClick:()=>de(!W),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),de(!W))},children:[s.jsx(vs,{checked:W,onChange:de,ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.persistDraftMessages")})]}),!c&&ht("inputSpellcheck")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ge,onClick:()=>nt(!ge),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),nt(!ge))},children:[s.jsx(vs,{checked:ge,onChange:nt,ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs")})]})]})]}),ht("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(vs,{checked:et,onChange:We,ariaLabel:i("settings.openchamber.visual.field.sendAnonymousUsageReportsAria")}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[s.jsx("div",{className:"group flex cursor-pointer",role:"button",tabIndex:0,"aria-pressed":et,onClick:()=>We(!et),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),We(!et))},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 ZC(){if(typeof window>"u")return"unknown";try{const{deviceType:t}=by();return t}catch{return"unknown"}}function e4(){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 t4(){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 s4(t){const e=Fe.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",ZC()),n.set("arch",e4()),n.set("platform",t4()),t==="desktop"?(n.set("appType",xy()?"desktop-electron":"desktop-tauri"),n.set("instanceMode",ta()?"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 Yc(t,e){try{const n=s4(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 n4(){return Ka()?ta()?"desktop":"web":fn()?"vscode":ea()?"web":null}const nf={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},Ua=ar()((t,e)=>({...nf,checkForUpdates:async()=>{const n=n4();if(!n)return null;t({checking:!0,error:null,runtimeType:n});try{let r=null,a=null;if(n==="desktop"){let i=await gc();t({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null});const o=await Yc("desktop",i?.currentVersion);if(a=o?.nextSuggestedCheckInSec??null,o?.available&&!i?.available){const c=await gc();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 Yc("web"),a=r?.nextSuggestedCheckInSec??null):n==="vscode"&&(a=(await Yc("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 gc();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 gy(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 hy())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(nf)}})),rf="https://github.com/btriapitsyn/openchamber/releases";function r4(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 a4(t){return t.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function af(t){return t.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function i4(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 o4(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 of=2e3,l4=600*1e3;async function c4(){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 d4(){try{return(await fetch("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function u4(t,e=Math.ceil(l4/of),n=of){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 d4())return!0}catch{}await new Promise(a=>setTimeout(a,n))}return!1}const Fd=({open:t,onOpenChange:e,info:n,downloading:r,downloaded:a,progress:i,error:o,onDownload:c,onRestart:d,runtimeType:p="desktop"})=>{const{t:m}=ft(),[u,f]=_e.useState(!1),[b,x]=_e.useState("idle"),[y,g]=_e.useState(null),h=n?.version?`${rf}/tag/v${n.version}`:rf,j=i?.total?Math.round(i.downloaded/i.total*100):0,v=p==="web",C=n?.updateCommand||"openchamber update";_e.useEffect(()=>{t||(x("idle"),g(null))},[t]);const k=async()=>{(await En(C)).ok&&(f(!0),setTimeout(()=>f(!1),2e3))},w=_e.useCallback(async P=>{await rr(P)},[]),N=_e.useCallback(async()=>{x("updating"),g(null);const P=await c4();if(!P.success){x("error"),g(P.error||m("updateDialog.error.updateFailed"));return}P.autoRestart&&(x("restarting"),await new Promise(S=>setTimeout(S,2e3))),x("reconnecting"),await u4(n?.currentVersion)?window.location.reload():(x("error"),g(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),I=b!=="idle"&&b!=="error",T=_e.useMemo(()=>{if(!n?.body)return null;const P=n.body.trim();if(!P)return null;const D=o4(P);if(D.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:af(P)};const S=[...D].sort((M,E)=>i4(M.version,E.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:S.map(M=>({version:M.version,dateLabel:r4(M.date),content:af(a4(M.raw)||P)}))}},[n?.body,m]);return s.jsx(us,{open:t,onOpenChange:I?void 0:e,children:s.jsxs(ds,{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(ms,{className:"flex items-center gap-2.5",children:[s.jsx(A,{name:"download-cloud",className:"h-5 w-5 text-[var(--primary-base)]"}),s.jsx("span",{className:"text-lg font-semibold text-foreground",children:m(b==="restarting"||b==="reconnecting"?"updateDialog.header.updating":"updateDialog.header.updateAvailable")})]}),(n?.currentVersion||n?.version)&&s.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm ml-3",children:[n?.currentVersion&&s.jsx("span",{className:"text-muted-foreground",children:n.currentVersion}),n?.currentVersion&&n?.version&&s.jsx("span",{className:"text-muted-foreground/50",children:"→"}),n?.version&&s.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:n.version})]})]}),s.jsxs("div",{className:"space-y-2",children:[v&&I&&s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/30 p-5 border border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(A,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),s.jsxs("div",{className:"typography-ui-label text-foreground",children:[b==="updating"&&m("updateDialog.status.installingUpdate"),b==="restarting"&&m("updateDialog.status.serverRestarting"),b==="reconnecting"&&m("updateDialog.status.waitingForServer")]})]}),s.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:m("updateDialog.status.autoReloadHint")})]}),T&&!I&&s.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:s.jsx(Ss,{className:"max-h-[400px] p-0",fillContainer:!1,children:T.kind==="raw"?s.jsx("div",{className:"p-4 typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:P=>{const S=P.target.closest("a");S&&S.href&&(P.preventDefault(),P.stopPropagation(),w(S.href))},children:s.jsx(ya,{content:T.content,disableLinkSafety:!0})}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:T.sections.map(P=>s.jsxs("div",{className:"p-4",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[s.jsxs("span",{className:"typography-ui-label font-mono text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:["v",P.version]}),s.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:P.dateLabel})]}),s.jsx("div",{className:"typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:D=>{const M=D.target.closest("a");M&&M.href&&(D.preventDefault(),D.stopPropagation(),w(M.href))},children:s.jsx(ya,{content:P.content,disableLinkSafety:!0})})]},P.version))})})}),v&&b==="error"&&s.jsxs("div",{className:"space-y-2 mt-4",children:[s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(A,{name:"terminal",className:"h-4 w-4"}),s.jsx("span",{children:m("updateDialog.fallback.updateViaTerminal")})]}),s.jsxs("div",{className:"flex items-center gap-2 p-1 pl-3 bg-[var(--surface-elevated)]/50 rounded-md border border-[var(--surface-subtle)]",children:[s.jsx("code",{className:"flex-1 font-mono text-sm text-foreground overflow-x-auto whitespace-nowrap",children:C}),s.jsx("button",{onClick:k,className:ye("flex items-center justify-center p-2 rounded","text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]","transition-colors",u&&"text-[var(--status-success)]"),title:m(u?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:u?s.jsx(A,{name:"check",className:"h-4 w-4"}):s.jsx(A,{name:"clipboard",className:"h-4 w-4"})})]})]}),!v&&r&&s.jsxs("div",{className:"space-y-2 mt-4",children:[s.jsxs("div",{className:"flex items-center justify-between text-sm",children:[s.jsx("span",{className:"text-muted-foreground",children:m("updateDialog.status.downloadingPayload")}),s.jsxs("span",{className:"font-mono text-foreground",children:[j,"%"]})]}),s.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${j}%`}})})]}),(o||y)&&s.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:s.jsx("p",{className:"text-sm text-[var(--status-error)]",children:o||y})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[s.jsxs("a",{href:h,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0",children:[s.jsx(A,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),s.jsxs("div",{className:"flex-1 flex justify-end",children:[!v&&!a&&!r&&s.jsxs("button",{onClick:c,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[s.jsx(A,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!v&&r&&s.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[s.jsx(A,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.downloading")]}),!v&&a&&s.jsxs("button",{onClick:d,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--status-success)] text-white hover:opacity-90 transition-opacity",children:[s.jsx(A,{name:"restart",className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),v&&!I&&s.jsxs("button",{onClick:N,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[s.jsx(A,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),v&&I&&s.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[s.jsx(A,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},lf="https://github.com/btriapitsyn/openchamber",m4=800,p4=()=>{const t=ot.c(103),{t:e}=ft(),[n,r]=l.useState(!1),[a,i]=l.useState(!1),o=Ua(Gn(f4)),{isMobile:c}=ln(),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&&(H.success(e("settings.openchamber.about.toast.latestVersion")),p.current=!1)},m4);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:ye("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 _;t[13]!==f||t[14]!==e||t[15]!==o.available?(_=!f&&o.available&&s.jsxs("button",{onClick:()=>r(!0),className:"flex items-center gap-1 typography-meta text-[var(--primary-base)] hover:underline",children:[s.jsx(A,{name:"download",className:"h-3.5 w-3.5"}),e("settings.openchamber.about.actions.update")]}),t[13]=f,t[14]=e,t[15]=o.available,t[16]=_):_=t[16];let q;t[17]!==$||t[18]!==O||t[19]!==_?(q=s.jsxs("div",{className:"flex items-center justify-between",children:[$,O,_]}),t[17]=$,t[18]=O,t[19]=_,t[20]=q):q=t[20];let L;t[21]!==o.error?(L=o.error&&s.jsx("p",{className:"typography-micro text-[var(--status-error)] truncate",children:o.error}),t[21]=o.error,t[22]=L):L=t[22];let J;t[23]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsxs("a",{href:lf,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(A,{name:"github-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"GitHub"})]}),t[23]=J):J=t[23];let Z;t[24]===Symbol.for("react.memo_cache_sentinel")?(Z=s.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(A,{name:"discord-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"Discord"})]}),t[24]=Z):Z=t[24];let ie;t[25]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsxs("div",{className:"flex items-center gap-3",children:[J,Z,s.jsxs("a",{href:"https://x.com/btriapitsyn",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(A,{name:"twitter-xfill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[25]=ie):ie=t[25];let ne;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?(ne=s.jsx(Fd,{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]=ne):ne=t[35];let me;return t[36]!==ne||t[37]!==q||t[38]!==L?(me=s.jsxs("div",{className:"w-full space-y-2",children:[q,L,ie,ne]}),t[36]=ne,t[37]=q,t[38]=L,t[39]=me):me=t[39],me}let b;t[40]!==e?(b=e("settings.openchamber.about.title"),t[40]=e,t[41]=b):b=t[41];let x;t[42]!==b?(x=s.jsx("div",{className:"mb-3 px-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:b})}),t[42]=b,t[43]=x):x=t[43];let y;t[44]!==e?(y=e("settings.openchamber.about.field.version"),t[44]=e,t[45]=y):y=t[45];let g;t[46]!==y?(g=s.jsx("span",{className:"typography-ui-label text-foreground",children:y}),t[46]=y,t[47]=g):g=t[47];let h;t[48]!==d?(h=s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:d}),t[48]=d,t[49]=h):h=t[49];let j;t[50]!==g||t[51]!==h?(j=s.jsxs("div",{className:"flex min-w-0 flex-col",children:[g,h]}),t[50]=g,t[51]=h,t[52]=j):j=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(A,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),t[53]=e,t[54]=o.checking,t[55]=v):v=t[55];let C;t[56]!==e||t[57]!==o.available||t[58]!==o.checking||t[59]!==o.info?.version?(C=!o.checking&&o.available&&s.jsxs(be,{size:"sm",variant:"default",onClick:()=>r(!0),children:[s.jsx(A,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:o.info?.version||""})]}),t[56]=e,t[57]=o.available,t[58]=o.checking,t[59]=o.info?.version,t[60]=C):C=t[60];let k;t[61]!==e||t[62]!==o.available||t[63]!==o.checking||t[64]!==o.error?(k=!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]=k):k=t[65];let w;t[66]!==o?(w=()=>o.checkForUpdates(),t[66]=o,t[67]=w):w=t[67];const N=o.checking;let I;t[68]!==e?(I=e("settings.openchamber.about.actions.checkForUpdates"),t[68]=e,t[69]=I):I=t[69];let T;t[70]!==w||t[71]!==I||t[72]!==o.checking?(T=s.jsx(be,{size:"sm",variant:"outline",onClick:w,disabled:N,children:I}),t[70]=w,t[71]=I,t[72]=o.checking,t[73]=T):T=t[73];let P;t[74]!==k||t[75]!==T||t[76]!==v||t[77]!==C?(P=s.jsxs("div",{className:"flex items-center gap-3",children:[v,C,k,T]}),t[74]=k,t[75]=T,t[76]=v,t[77]=C,t[78]=P):P=t[78];let D;t[79]!==P||t[80]!==j?(D=s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-4 py-3 border-b border-[var(--surface-subtle)]",children:[j,P]}),t[79]=P,t[80]=j,t[81]=D):D=t[81];let S;t[82]!==o.error?(S=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]=S):S=t[83];let M;t[84]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsxs("a",{href:lf,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(A,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),t[84]=M):M=t[84];let E;t[85]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[M,s.jsxs("a",{href:"https://x.com/btriapitsyn",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(A,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[85]=E):E=t[85];let R;t[86]!==D||t[87]!==S?(R=s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[D,S,E]}),t[86]=D,t[87]=S,t[88]=R):R=t[88];let V;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?(V=s.jsx(Fd,{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]=V):V=t[98];let B;return t[99]!==R||t[100]!==V||t[101]!==x?(B=s.jsxs("div",{className:"mb-8",children:[x,R,V]}),t[99]=R,t[100]=V,t[101]=x,t[102]=B):B=t[102],B};function f4(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 h4=1,g4=365,cf=30,x4=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Ug=()=>{const t=ot.c(113),{t:e}=ft(),n=Fe(b4),r=Fe(y4),a=Fe(v4),i=Fe(w4),o=Fe(j4),c=Fe(N4);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}=yy(d),b=p.length;let x;t[1]!==u||t[2]!==e?(x=async()=>{const Y=await u({force:!0});if(Y.completedIds.length===0&&Y.failedIds.length===0){H.message(Y.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}Y.completedIds.length>0&&H.success(Y.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:Y.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:Y.completedIds.length})),Y.failedIds.length>0&&H.error(Y.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:Y.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:Y.failedIds.length}))},t[1]=u,t[2]=e,t[3]=x):x=t[3];const y=x;let g;t[4]!==e?(g=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=g):g=t[5];let h;t[6]!==g?(h=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:g}),t[6]=g,t[7]=h):h=t[7];let j;t[8]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[8]=j):j=t[8];let v;t[9]!==e?(v=e("settings.openchamber.sessionRetention.tooltip"),t[9]=e,t[10]=v):v=t[10];let C;t[11]!==v?(C=s.jsxs(kt,{children:[j,s.jsx(It,{sideOffset:8,className:"max-w-xs",children:v})]}),t[11]=v,t[12]=C):C=t[12];let k;t[13]!==h||t[14]!==C?(k=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[h,C]})}),t[13]=h,t[14]=C,t[15]=k):k=t[15];let w,N;t[16]!==n||t[17]!==i?(w=()=>i(!n),N=Y=>{(Y.key===" "||Y.key==="Enter")&&(Y.preventDefault(),i(!n))},t[16]=n,t[17]=i,t[18]=w,t[19]=N):(w=t[18],N=t[19]);let I;t[20]!==e?(I=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[20]=e,t[21]=I):I=t[21];let T;t[22]!==n||t[23]!==i||t[24]!==I?(T=s.jsx(vs,{checked:n,onChange:i,ariaLabel:I}),t[22]=n,t[23]=i,t[24]=I,t[25]=T):T=t[25];let P;t[26]!==e?(P=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[26]=e,t[27]=P):P=t[27];let D;t[28]!==P?(D=s.jsx("span",{className:"typography-ui-label text-foreground",children:P}),t[28]=P,t[29]=D):D=t[29];let S;t[30]!==n||t[31]!==T||t[32]!==D||t[33]!==w||t[34]!==N?(S=s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":n,onClick:w,onKeyDown:N,children:[T,D]}),t[30]=n,t[31]=T,t[32]=D,t[33]=w,t[34]=N,t[35]=S):S=t[35];let M;t[36]!==e?(M=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[36]=e,t[37]=M):M=t[37];let E;t[38]!==M?(E=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:M})}),t[38]=M,t[39]=E):E=t[39];let R;t[40]!==e?(R=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[40]=e,t[41]=R):R=t[41];let V;t[42]!==r||t[43]!==o||t[44]!==R?(V=s.jsx($n,{value:r,onValueChange:o,min:h4,max:g4,step:1,"aria-label":R,className:"w-20 tabular-nums"}),t[42]=r,t[43]=o,t[44]=R,t[45]=V):V=t[45];let B;t[46]!==e?(B=e("settings.openchamber.sessionRetention.field.days"),t[46]=e,t[47]=B):B=t[47];let $;t[48]!==B?($=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:B}),t[48]=B,t[49]=$):$=t[49];let O;t[50]!==o?(O=()=>o(cf),t[50]=o,t[51]=O):O=t[51];const _=r===cf;let q;t[52]!==e?(q=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[52]=e,t[53]=q):q=t[53];let L;t[54]!==e?(L=e("settings.common.actions.reset"),t[54]=e,t[55]=L):L=t[55];let J;t[56]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(A,{name:"restart",className:"h-3.5 w-3.5"}),t[56]=J):J=t[56];let Z;t[57]!==O||t[58]!==_||t[59]!==q||t[60]!==L?(Z=s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:O,disabled:_,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":q,title:L,children:J}),t[57]=O,t[58]=_,t[59]=q,t[60]=L,t[61]=Z):Z=t[61];let ie;t[62]!==V||t[63]!==$||t[64]!==Z?(ie=s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[V,$,Z]}),t[62]=V,t[63]=$,t[64]=Z,t[65]=ie):ie=t[65];let ne;t[66]!==E||t[67]!==ie?(ne=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[E,ie]}),t[66]=E,t[67]=ie,t[68]=ne):ne=t[68];let me;t[69]!==e?(me=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[69]=e,t[70]=me):me=t[70];let pe;t[71]!==me?(pe=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:me})}),t[71]=me,t[72]=pe):pe=t[72];let G;t[73]!==a||t[74]!==c||t[75]!==e?(G=x4.map(Y=>s.jsx(be,{type:"button",variant:"chip",size:"xs","aria-pressed":a===Y.value,className:"!font-normal",onClick:()=>c(Y.value),children:e(Y.labelKey)},Y.value)),t[73]=a,t[74]=c,t[75]=e,t[76]=G):G=t[76];let K;t[77]!==G?(K=s.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:G}),t[77]=G,t[78]=K):K=t[78];let Q;t[79]!==pe||t[80]!==K?(Q=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[pe,K]}),t[79]=pe,t[80]=K,t[81]=Q):Q=t[81];let W;t[82]!==S||t[83]!==ne||t[84]!==Q?(W=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[S,ne,Q]}),t[82]=S,t[83]=ne,t[84]=Q,t[85]=W):W=t[85];let de;t[86]!==e?(de=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[86]=e,t[87]=de):de=t[87];let ge;t[88]!==de?(ge=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:de})}),t[88]=de,t[89]=ge):ge=t[89];let ve;t[90]!==m||t[91]!==e?(ve=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[90]=m,t[91]=e,t[92]=ve):ve=t[92];let te;t[93]!==y||t[94]!==m||t[95]!==ve?(te=s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsx(be,{type:"button",variant:"outline",size:"xs",onClick:y,disabled:m,className:"!font-normal",children:ve})}),t[93]=y,t[94]=m,t[95]=ve,t[96]=te):te=t[96];let he;t[97]!==ge||t[98]!==te?(he=s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[ge,te]}),t[97]=ge,t[98]=te,t[99]=he):he=t[99];let ce;t[100]!==f||t[101]!==b||t[102]!==e?(ce=f==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:b}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:b}),t[100]=f,t[101]=b,t[102]=e,t[103]=ce):ce=t[103];let xe;t[104]!==ce?(xe=s.jsx("p",{className:"typography-meta text-muted-foreground",children:ce}),t[104]=ce,t[105]=xe):xe=t[105];let se;t[106]!==he||t[107]!==xe?(se=s.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[he,xe]}),t[106]=he,t[107]=xe,t[108]=se):se=t[108];let ue;return t[109]!==W||t[110]!==se||t[111]!==k?(ue=s.jsxs("div",{className:"mb-8",children:[k,W,se]}),t[109]=W,t[110]=se,t[111]=k,t[112]=ue):ue=t[112],ue};function b4(t){return t.autoDeleteEnabled}function y4(t){return t.autoDeleteAfterDays}function v4(t){return t.sessionRetentionAction}function w4(t){return t.setAutoDeleteEnabled}function j4(t){return t.setAutoDeleteAfterDays}function N4(t){return t.setSessionRetentionAction}const df=(t,e)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(t),Wg=()=>{const{t}=ft(),[e,n]=l.useState(!1),[r,a]=l.useState(!0),[i,o]=l.useState(!1),[c,d]=l.useState(null),[p,m]=l.useState(!1),[u,f]=l.useState([]),[b,x]=l.useState(vy),[y,g]=l.useState(""),h=l.useMemo(()=>wy(),[]),j=l.useCallback(async()=>{a(!0),g("");try{const w=await jy();f(w)}catch(w){const N=w instanceof Error?w.message:t("settings.openchamber.passkeys.toast.loadFailed");g(N)}finally{a(!1)}},[t]);l.useEffect(()=>{let w=!1;return(async()=>{try{if(!h.supported){w||(n(!1),a(!1));return}w||n(!0)}catch{w||n(!1)}if(!w){const N=await xc();if(x(N),!N.enabled){f([]),a(!1);return}await j()}})(),()=>{w=!0,Xu()}},[j,h.supported]);const v=l.useCallback(async()=>{if(!b.enabled){const w=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");g(w),H.message(w);return}if(!e){g(h.reason),H.message(h.reason);return}if(i){Xu(),o(!1);return}g(""),o(!0);try{await Ny(),x(await xc()),await j(),H.success(t("settings.openchamber.passkeys.toast.added"))}catch(w){if(Sy(w)){H.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const N=w instanceof Error?w.message:t("settings.openchamber.passkeys.toast.addFailed");g(N),H.error(N)}finally{o(!1)}},[i,j,b.enabled,h.reason,e,t]),C=l.useCallback(async w=>{d(w),g("");try{await ky(w),x(await xc()),await j(),H.success(t("settings.openchamber.passkeys.toast.removed"))}catch(N){const I=N instanceof Error?N.message:t("settings.openchamber.passkeys.toast.removeFailed");g(I),H.error(I)}finally{d(null)}},[j,t]),k=l.useCallback(async()=>{m(!0),g("");try{await Cy(),window.location.reload()}catch(w){const N=w instanceof Error?w.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");g(N),H.error(N),m(!1)}},[t]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.passkeys.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.passkeys.field.currentDevice")})}),s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[s.jsx(be,{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(be,{type:"button",variant:"ghost",size:"xs",onClick:()=>{k()},disabled:r||i||p,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(p?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]})]}),!b.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),b.enabled&&!e&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:h.reason}),r?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):u.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:u.map(w=>s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:w.label})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:w.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:df(w.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"))}):t("settings.openchamber.passkeys.item.added",{time:df(w.createdAt,t("settings.openchamber.passkeys.time.neverUsed"))})}),s.jsx(be,{type:"button",variant:"ghost",size:"xs",onClick:()=>{C(w.id)},disabled:c===w.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===w.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]})]},w.id))})]}),y&&s.jsx("div",{className:"mt-1 px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:y})})]})},S4=t=>{const e=Ii(t);return e||{providerId:"",modelId:""}},Kg=()=>{const{t}=ft(),e=wt(E=>E.setProvider),n=wt(E=>E.setModel),r=wt(E=>E.setAgent),a=wt(E=>E.setCurrentVariant),i=wt(E=>E.setSettingsDefaultModel),o=wt(E=>E.setSettingsDefaultVariant),c=wt(E=>E.setSettingsDefaultAgent),d=wt(E=>E.setSettingsDefaultFileViewerPreview),p=wt(E=>E.settingsDefaultFileViewerPreview),m=Fe(E=>E.showDeletionDialog),u=Fe(E=>E.setShowDeletionDialog),f=wt(E=>E.providers),[b,x]=l.useState(),[y,g]=l.useState(),[h,j]=l.useState(),[v,C]=l.useState(!0),k=l.useMemo(()=>S4(b),[b]);l.useEffect(()=>{(async()=>{try{let R=null;if(!R){const V=or()?.settings;if(V)try{const $=(await V.load())?.settings;$&&(R={defaultModel:typeof $.defaultModel=="string"?$.defaultModel:void 0,defaultVariant:typeof $.defaultVariant=="string"?$.defaultVariant:void 0,defaultAgent:typeof $.defaultAgent=="string"?$.defaultAgent:void 0})}catch{}}if(!R){const V=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});V.ok&&(R=await V.json())}if(R){const V=typeof R.defaultModel=="string"&&R.defaultModel.trim().length>0?R.defaultModel.trim():void 0,B=typeof R.defaultVariant=="string"&&R.defaultVariant.trim().length>0?R.defaultVariant.trim():void 0,$=typeof R.defaultAgent=="string"&&R.defaultAgent.trim().length>0?R.defaultAgent.trim():void 0;V!==void 0&&x(V),B!==void 0&&g(B),$!==void 0&&j($)}}catch(R){console.warn("Failed to load defaults settings:",R)}finally{C(!1)}})()},[]);const w=l.useCallback(async(E,R)=>{const V=E&&R?`${E}/${R}`:void 0;x(V),g(void 0),o(void 0),a(void 0),i(V),E&&R&&f.find($=>$.id===E)&&(e(E),n(R));try{await ks({defaultModel:V??"",defaultVariant:""});const B=await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:V})});B.ok||console.warn("Failed to save default model to server:",B.status,B.statusText)}catch(B){console.warn("Failed to save default model:",B)}},[f,a,n,e,i,o]),N="__default__",I=l.useCallback(E=>E===N?t("settings.openchamber.defaults.option.default"):E.charAt(0).toUpperCase()+E.slice(1),[t]),T=l.useCallback(async E=>{const R=E===N?void 0:E||void 0;g(R),o(R),a(R);try{await ks({defaultVariant:R??""})}catch(V){console.warn("Failed to save default variant:",V)}},[a,o]),P=l.useCallback(async E=>{const R=E||void 0;j(R),c(R),E&&r(E);try{await ks({defaultAgent:R??""})}catch(V){console.warn("Failed to save default agent:",V)}},[r,c]),D=l.useCallback(()=>{const E=!p;d(E),ks({defaultFileViewerPreview:E}).catch(console.warn)},[p,d]),S=l.useMemo(()=>{if(!k.providerId||!k.modelId)return[];const V=f.find(B=>B.id===k.providerId)?.models.find(B=>B.id===k.modelId)?.variants;return V?Object.keys(V):[]},[k.modelId,k.providerId,f]),M=S.length>0;return l.useEffect(()=>{!M&&y&&(g(void 0),o(void 0),a(void 0),ks({defaultVariant:""}).catch(()=>{}))},[y,a,o,M]),v?null:s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-0.5 px-1",children:s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.defaults.title")})})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",k.providerId?s.jsxs("span",{className:"text-foreground",children:[k.providerId,"/",k.modelId,M?` (${y??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),h&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:h})]})]}),s.jsxs("div",{className:ye("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(Io,{providerId:k.providerId,modelId:k.modelId,onChange:w})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultThinking")})}),s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsxs(as,{value:y??N,onValueChange:T,disabled:!M,children:[s.jsx(is,{className:"w-fit min-w-[120px]",children:s.jsx(fs,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:I(y??N)})}),s.jsxs(os,{children:[s.jsx(Mt,{value:N,children:t("settings.openchamber.defaults.option.default")}),S.map(E=>s.jsx(Mt,{value:E,children:I(E)},E))]})]})})]}),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(ic,{agentName:h||"",onChange:P})})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:E=>{(E.key===" "||E.key==="Enter")&&(E.preventDefault(),u(!m))},children:[s.jsx(vs,{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:D,onKeyDown:E=>{(E.key===" "||E.key==="Enter")&&(E.preventDefault(),D())},children:[s.jsx(vs,{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")})]})]})]})},uf={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"}},k4={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"},C4=()=>{const{t}=ft(),e=l.useMemo(()=>jn(),[]),n=l.useMemo(()=>fn(),[]),r=!e&&!n,a=Fe(L=>L.nativeNotificationsEnabled),i=Fe(L=>L.setNativeNotificationsEnabled),o=Fe(L=>L.notificationMode),c=Fe(L=>L.setNotificationMode),d=Fe(L=>L.notifyOnSubtasks),p=Fe(L=>L.setNotifyOnSubtasks),m=Fe(L=>L.notifyOnCompletion),u=Fe(L=>L.setNotifyOnCompletion),f=Fe(L=>L.notifyOnError),b=Fe(L=>L.setNotifyOnError),x=Fe(L=>L.notifyOnQuestion),y=Fe(L=>L.setNotifyOnQuestion),g=Fe(L=>L.notificationTemplates),h=Fe(L=>L.setNotificationTemplates),[j,v]=l.useState("default"),[C,k]=l.useState(!1),[w,N]=l.useState(!1),[I,T]=l.useState(!1);l.useEffect(()=>{if(!r){k(!1),N(!1);return}typeof Notification<"u"&&v(Notification.permission);const L=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;k(L),(async()=>{if(!L){N(!1);return}try{const Z=await navigator.serviceWorker.getRegistration();if(!Z){N(!1);return}const ie=await Z.pushManager.getSubscription();N(!!ie)}catch{N(!1)}})()},[r]);const P=async L=>{if(e){i(L);return}if(!r){i(L);return}if(L&&typeof Notification<"u"&&Notification.permission==="default")try{const J=await Notification.requestPermission();v(J),J==="granted"?i(!0):H.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(J){console.error("Failed to request notification permission:",J),H.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else i(!!(L&&j==="granted"))},D=e||n||r&&typeof Notification<"u"&&Notification.permission==="granted",S=(L,J,Z)=>{h({...g,[L]:{...g[L],[J]:Z}})},M=L=>{const J="=".repeat((4-L.length%4)%4),Z=(L+J).replace(/-/g,"+").replace(/_/g,"/"),ie=atob(Z),ne=new Uint8Array(ie.length);for(let me=0;me<ie.length;me+=1)ne[me]=ie.charCodeAt(me);return ne},E=async(L,J,Z)=>{let ie=null;const ne=new Promise((me,pe)=>{ie=setTimeout(()=>{pe(new Error(Z))},J)});try{return await Promise.race([L,ne])}finally{ie&&clearTimeout(ie)}},R=async L=>{if(L.active)return;const J=L.installing||L.waiting;J&&J.state!=="activated"&&await E(new Promise(Z=>{const ie=()=>{J.state==="activated"&&(J.removeEventListener("statechange",ie),Z())};J.addEventListener("statechange",ie),ie()}),15e3,"Service worker activation timed out")},V=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const L=[{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 J=null;for(const Z of L)try{const ie=Z.opts?navigator.serviceWorker.register("/sw.js",Z.opts):navigator.serviceWorker.register("/sw.js");return await E(ie,1e4,`Service worker registration timed out (${Z.label})`)}catch(ie){J=ie}throw J instanceof Error?J:new Error("Service worker registration failed")},B=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const L=await navigator.serviceWorker.getRegistration();if(L)return L;const J=await V();try{await J.update()}catch{}return await R(J),J},$=L=>{const J=L,Z=[`type=${typeof L}`,`toString=${String(L)}`,`name=${String(J?.name??"")}`,`message=${String(J?.message??"")}`];let ie="";try{ie=JSON.stringify(L)}catch{}return{summary:Z.filter(Boolean).join(" | "),json:ie,stack:typeof J?.stack=="string"?J.stack:""}},O=async()=>{const L=or();if(!L?.notifications){H.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await L.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?H.success(t("settings.notifications.page.toast.testNotificationSent")):H.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(J){console.error("Test notification failed:",J),H.error(t("settings.notifications.page.toast.testNotificationFailed"))}},_=async()=>{if(!C){H.error(t("settings.notifications.page.toast.pushUnsupported"));return}const L=or();if(!L?.push){H.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const K=await Notification.requestPermission();if(v(K),K!=="granted"){H.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){H.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const J=await L.push.getVapidPublicKey();if(!J?.publicKey){H.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const Z=await B();await R(Z);const ie=await Z.pushManager.getSubscription();if(!("pushManager"in Z)||!Z.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const me=(ie??await E(Z.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:M(J.publicKey)}),15e3,"Push subscription timed out")).toJSON(),pe=me.keys;if(!me.endpoint||!pe?.p256dh||!pe.auth)throw new Error("Push subscription missing keys");if(!(await E(L.push.subscribe({endpoint:me.endpoint,keys:{p256dh:pe.p256dh,auth:pe.auth},origin:typeof window<"u"?window.location.origin:void 0}),15e3,"Push subscribe request timed out"))?.ok){H.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}N(!0),H.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(J){console.error("[Push] Enable failed:",J);const Z=$(J);H.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:Z.summary})}finally{T(!1)}},q=async()=>{if(!C){N(!1);return}const L=or();if(!L?.push){H.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{const Z=await(await B()).pushManager.getSubscription();if(!Z){N(!1);return}const ie=Z.endpoint;await Z.unsubscribe(),await L.push.unsubscribe({endpoint:ie}),N(!1),H.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{T(!1)}};return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.delivery.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":a&&D,onClick:()=>{P(!(a&&D))},onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),P(!(a&&D)))},children:[s.jsx(vs,{checked:a&&D,onChange:L=>{P(L)},ariaLabel:t("settings.notifications.page.delivery.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.enableLabel")})]}),a&&D&&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":o==="always",onClick:()=>c(o==="always"?"hidden-only":"always"),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),c(o==="always"?"hidden-only":"always"))},children:[s.jsx(vs,{checked:o==="always",onChange:L=>c(L?"always":"hidden-only"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.focusedLabel")})]}),s.jsx("div",{className:"py-2",children:s.jsx(be,{type:"button",variant:"outline",size:"sm",onClick:()=>{O()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),r&&s.jsxs("div",{className:"mt-1 px-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.browserPermissionHint")}),j==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),j==="granted"&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]}),n&&s.jsx("div",{className:"mt-1 px-2",children:s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.vscodeHint")})})]}),a&&D&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.events.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),u(!m))},children:[s.jsx(vs,{checked:m,onChange:u,ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.completionLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":d,onClick:()=>p(!d),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),p(!d))},children:[s.jsx(vs,{checked:d,onChange:p,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":f,onClick:()=>b(!f),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),b(!f))},children:[s.jsx(vs,{checked:f,onChange:b,ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.errorLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":x,onClick:()=>y(!x),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),y(!x))},children:[s.jsx(vs,{checked:x,onChange:y,ariaLabel:t("settings.notifications.page.events.questionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.questionLabel")})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.template.title")}),s.jsxs("p",{className:"typography-meta text-muted-foreground mt-0.5",children:[t("settings.notifications.page.template.variablesLabel")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]})]}),s.jsx("div",{className:"grid grid-cols-1 gap-2 md:grid-cols-2 md:gap-3",children:["completion","subtask","error","question"].map(L=>s.jsxs("section",{className:"p-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground font-normal capitalize block",children:t(k4[L])}),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(Lt,{value:g[L].title,onChange:J=>S(L,"title",J.target.value),className:"h-7",placeholder:t(uf[L].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(Lt,{value:g[L].message,onChange:J=>S(L,"message",J.target.value),className:"h-7",placeholder:t(uf[L].messageKey)})]})]})]},L))})]})]}),r&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.push.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[s.jsx(vs,{checked:C?w:!1,disabled:!C||I,onChange:L=>{L?_():q()},ariaLabel:t("settings.notifications.page.push.enableAria")}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:ye("typography-ui-label",C?"text-foreground":"text-muted-foreground"),children:t("settings.notifications.page.push.enableLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t(C?"settings.notifications.page.push.supportedHint":"settings.notifications.page.push.unsupportedHint")})]}),I&&s.jsx("div",{className:"pt-0.5 text-muted-foreground",children:s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")})})]})})]})]})},Zn=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},I4=[{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:"Українська"}],P4=t=>{const e=ot.c(45),{modelId:n}=t,{t:r}=ft();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=Ji.getModelStatus(),e[0]=a):a=e[0];const[i,o]=_e.useState(a),[c,d]=_e.useState(!1);let p,m;e[1]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{const w=N=>o(N);return Ji.onModelStatusChange=w,T4},m=[],e[1]=p,e[2]=m):(p=e[1],m=e[2]),_e.useEffect(p,m);const u=Ji.getCurrentModelId(),f=i.state==="downloading"||i.state==="loading";let b,x;e[3]!==i.state?(b=()=>{i.state!=="downloading"&&i.state!=="loading"&&d(!1)},x=[i.state],e[3]=i.state,e[4]=b,e[5]=x):(b=e[4],x=e[5]),_e.useEffect(b,x);let y;e[6]!==n?(y=async()=>{d(!0);try{await Ji.loadModel(n)}catch{}},e[6]=n,e[7]=y):y=e[7];const g=y;if(i.state==="ready"&&u===n){let w;e[8]!==r?(w=r("settings.voice.page.stt.wasmLoaded"),e[8]=r,e[9]=w):w=e[9];let N;return e[10]!==w?(N=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"typography-ui-compact text-green-600 dark:text-green-400",children:w})}),e[10]=w,e[11]=N):N=e[11],N}if(f){let w;e[12]!==i.progress||e[13]!==i.state?(w=i.state==="downloading"?Math.round(i.progress):void 0,e[12]=i.progress,e[13]=i.state,e[14]=w):w=e[14];const N=w;let I;e[15]!==i.state||e[16]!==r?(I=i.state==="downloading"?r("settings.voice.page.stt.wasmDownloading"):r("settings.voice.page.stt.wasmLoading"),e[15]=i.state,e[16]=r,e[17]=I):I=e[17];const T=N!==void 0?` (${N}%)`:"";let P;return e[18]!==I||e[19]!==T?(P=s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[I,T]})}),e[18]=I,e[19]=T,e[20]=P):P=e[20],P}if(i.state==="error"){let w;e[21]!==i.error?(w=s.jsx("span",{className:"typography-ui-compact text-destructive",children:i.error}),e[21]=i.error,e[22]=w):w=e[22];let N;e[23]!==r?(N=r("settings.voice.page.stt.wasmRetry"),e[23]=r,e[24]=N):N=e[24];let I;e[25]!==g||e[26]!==c||e[27]!==N?(I=s.jsx(be,{variant:"chip",size:"xs",disabled:c,onClick:g,children:N}),e[25]=g,e[26]=c,e[27]=N,e[28]=I):I=e[28];let T;return e[29]!==w||e[30]!==I?(T=s.jsxs("div",{className:"flex items-center gap-2",children:[w,I]}),e[29]=w,e[30]=I,e[31]=T):T=e[31],T}let h;e[32]!==r?(h=r("settings.voice.page.stt.wasmNotLoaded"),e[32]=r,e[33]=h):h=e[33];let j;e[34]!==h?(j=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:h}),e[34]=h,e[35]=j):j=e[35];let v;e[36]!==r?(v=r("settings.voice.page.stt.wasmDownload"),e[36]=r,e[37]=v):v=e[37];let C;e[38]!==g||e[39]!==c||e[40]!==v?(C=s.jsx(be,{variant:"chip",size:"xs",disabled:c,onClick:g,children:v}),e[38]=g,e[39]=c,e[40]=v,e[41]=C):C=e[41];let k;return e[42]!==C||e[43]!==j?(k=s.jsxs("div",{className:"flex items-center gap-2",children:[j,C]}),e[42]=C,e[43]=j,e[44]=k):k=e[44],k},A4=[{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"}],D4=()=>{const{t}=ft(),{isMobile:e}=ln(),{isSupported:n,language:r,setLanguage:a}=Iy(),i=wt(z=>z.voiceProvider),o=wt(z=>z.setVoiceProvider),c=wt(z=>z.speechRate),d=wt(z=>z.setSpeechRate),p=wt(z=>z.speechPitch),m=wt(z=>z.setSpeechPitch),u=wt(z=>z.speechVolume),f=wt(z=>z.setSpeechVolume),b=wt(z=>z.sayVoice),x=wt(z=>z.setSayVoice),y=wt(z=>z.browserVoice),g=wt(z=>z.setBrowserVoice),h=wt(z=>z.openaiVoice),j=wt(z=>z.setOpenaiVoice),v=wt(z=>z.openaiApiKey),C=wt(z=>z.setOpenaiApiKey),k=wt(z=>z.openaiCompatibleUrl),w=wt(z=>z.setOpenaiCompatibleUrl),N=wt(z=>z.openaiCompatibleApiKey),I=wt(z=>z.setOpenaiCompatibleApiKey),T=wt(z=>z.openaiCompatibleVoice),P=wt(z=>z.setOpenaiCompatibleVoice),D=wt(z=>z.openaiCompatibleTtsModel),S=wt(z=>z.setOpenaiCompatibleTtsModel),M=wt(z=>z.showMessageTTSButtons),E=wt(z=>z.sttProvider),R=wt(z=>z.setSttProvider),V=wt(z=>z.sttServerUrl),B=wt(z=>z.setSttServerUrl),$=wt(z=>z.sttApiKey),O=wt(z=>z.setSttApiKey),_=wt(z=>z.sttModel),q=wt(z=>z.setSttModel),L=wt(z=>z.wasmSttModel),J=wt(z=>z.setWasmSttModel),Z=wt(z=>z.sttLanguage),ie=wt(z=>z.setSttLanguage),ne=wt(z=>z.sttSilenceThresholdDb),me=wt(z=>z.setSttSilenceThresholdDb),pe=wt(z=>z.sttSilenceHoldMs),G=wt(z=>z.setSttSilenceHoldMs),K=wt(z=>z.sttTranscribeOnStop),Q=wt(z=>z.setSttTranscribeOnStop),W=wt(z=>z.setShowMessageTTSButtons),de=wt(z=>z.voiceModeEnabled),ge=wt(z=>z.setVoiceModeEnabled),[ve,te]=_e.useState(!1),[he,ce]=_e.useState([]),[xe,se]=_e.useState(!1),[ue,Y]=_e.useState(null),[Se,fe]=_e.useState(!1),[Ce,Ie]=_e.useState(!1),[ke,X]=_e.useState(null),[ae,je]=_e.useState(!1),[le,Ne]=_e.useState(null),[Me,Ve]=_e.useState([]),[we,ee]=_e.useState(!1);_e.useEffect(()=>((async()=>{const De=await bc.waitForVoices();Ve(De)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Ve(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const F=_e.useMemo(()=>Me.filter(z=>z.lang).sort((z,De)=>{const Qe=z.lang.startsWith("en"),et=De.lang.startsWith("en");if(Qe&&!et)return-1;if(!Qe&&et)return 1;const Ze=z.lang.localeCompare(De.lang);return Ze!==0?Ze:z.name.localeCompare(De.name)}),[Me]),U=_e.useCallback(()=>{if(we){bc.cancelSpeech(),ee(!1);return}const z=Me.find(Ze=>Ze.name===y),De=z?.name??t("settings.voice.page.preview.browserVoiceFallback"),Qe=t("settings.voice.page.preview.voiceLine",{voiceName:De});ee(!0);const et=new SpeechSynthesisUtterance(Qe);et.rate=c,et.pitch=p,et.volume=u,z&&(et.voice=z,et.lang=z.lang),et.onend=()=>ee(!1),et.onerror=()=>ee(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(et)},[y,Me,c,p,u,we,t]);_e.useEffect(()=>()=>{we&&bc.cancelSpeech()},[we]),_e.useEffect(()=>{if(!de||i!=="openai"&&i!=="openai-compatible"){fe(v.trim().length>0);return}(async()=>{try{const et=(await(await fetch("/api/tts/status")).json()).available,Ze=v.trim().length>0;fe(et||Ze)}catch{fe(v.trim().length>0)}})()},[v,de,i]),_e.useEffect(()=>{if(!de){te(!1),ce([]);return}fetch("/api/tts/say/status").then(z=>z.json()).then(z=>{if(te(z.available),z.voices){const De=z.voices.filter((Qe,et,Ze)=>Ze.findIndex(We=>We.name===Qe.name)===et).sort((Qe,et)=>Qe.name.localeCompare(et.name));ce(De)}}).catch(()=>{te(!1)})},[de]);const oe=_e.useCallback(async()=>{if(ue){Zn(ue),Y(null),se(!1);return}se(!0);let z=null;try{const De=await fetch("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:b}),voice:b,rate:Math.round(100+(c-.5)*200)})});if(!De.ok)throw new Error("Preview failed");const Qe=await De.blob(),et=URL.createObjectURL(Qe);z=new Audio(et),z.onended=()=>{Zn(z),Y(null),se(!1)},z.onerror=()=>{Zn(z),Y(null),se(!1)},Y(z),await z.play()}catch{Zn(z),Y(null),se(!1)}},[b,c,ue,t]);_e.useEffect(()=>()=>{Zn(ue)},[ue]);const Te=_e.useCallback(async()=>{if(ke){Zn(ke),X(null),Ie(!1);return}Ie(!0);let z=null;try{const De=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:h}),voice:h,speed:c,apiKey:v||void 0})});if(!De.ok){const Ze=await De.json().catch(()=>({error:"Unknown error"}));throw new Error(Ze.error||`HTTP ${De.status}`)}const Qe=await De.blob(),et=URL.createObjectURL(Qe);z=new Audio(et),z.onended=()=>{Zn(z),X(null),Ie(!1)},z.onerror=()=>{Zn(z),X(null),Ie(!1)},X(z),await z.play()}catch{Zn(z),X(null),Ie(!1)}},[h,c,ke,v,t]);_e.useEffect(()=>()=>{Zn(ke)},[ke]);const Oe=_e.useCallback(async()=>{if(le){Zn(le),Ne(null),je(!1);return}if(!k.trim())return;je(!0);let z=null;try{const De=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:T,model:D||void 0,speed:c,baseURL:k,apiKey:N||void 0})});if(!De.ok){const Ze=await De.json().catch(()=>({error:"Unknown error"}));throw new Error(Ze.error||`HTTP ${De.status}`)}const Qe=await De.blob(),et=URL.createObjectURL(Qe);z=new Audio(et),z.onended=()=>{Zn(z),Ne(null),je(!1)},z.onerror=()=>{Zn(z),Ne(null),je(!1)},Ne(z),await z.play()}catch{Zn(z),Ne(null),je(!1)}},[k,T,D,N,c,le,t]);_e.useEffect(()=>()=>{Zn(le)},[le]);const Pe="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":de,onClick:()=>ge(!de),onKeyDown:z=>{(z.key===" "||z.key==="Enter")&&(z.preventDefault(),ge(!de))},children:[s.jsx(vs,{checked:de,onChange:ge,ariaLabel:t("settings.voice.page.field.enableVoiceModeAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.enableVoiceMode")})]}),de&&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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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(be,{variant:"chip",size:"xs","aria-pressed":i==="browser",onClick:()=>o("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":i==="openai",onClick:()=>o("openai"),className:"!font-normal",children:"OpenAI"}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":i==="openai-compatible",onClick:()=>o("openai-compatible"),className:"!font-normal",children:t("settings.voice.page.provider.custom")}),ve&&s.jsxs(be,{variant:"chip",size:"xs","aria-pressed":i==="say",onClick:()=>o("say"),className:"!font-normal",children:[s.jsx(A,{name:"apple",className:"w-3.5 h-3.5 mr-0.5"}),t("settings.voice.page.provider.say")]})]})]})}),i==="openai"&&s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:ye("typography-ui-label text-foreground",!Se&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:ye("typography-meta ml-2",Se?"text-muted-foreground":"text-[var(--status-error)]/80"),children:t(Se&&!v?"settings.voice.page.field.apiKeyHintUsingConfig":Se?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"password",value:v,onChange:z=>C(z.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),v&&s.jsx("button",{type:"button",onClick:()=>C(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"w-3.5 h-3.5"})})]})]}),i==="openai-compatible"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:ye("typography-ui-label text-foreground",!k.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.serverUrlHint")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"text",value:k,onChange:z=>w(z.target.value),placeholder:"http://localhost:8880/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),k&&s.jsx("button",{type:"button",onClick:()=>w(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"API Key"}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:"Optional"}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"password",value:N,onChange:z=>I(z.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),N&&s.jsx("button",{type:"button",onClick:()=>I(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.model")}),s.jsx("div",{className:"relative mt-1.5 max-w-xs",children:s.jsx("input",{type:"text",value:D,onChange:z=>S(z.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.voice")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.voiceIdentifierHint")}),s.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[s.jsx("div",{className:"relative max-w-xs flex-1",children:s.jsx("input",{type:"text",value:T,onChange:z=>P(z.target.value),placeholder:"af_sky",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})}),s.jsx(be,{size:"xs",variant:"ghost",onClick:Oe,title:t("settings.voice.page.actions.preview"),disabled:!k.trim(),children:ae?s.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(A,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.voice")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[i==="openai"&&Se&&s.jsxs(s.Fragment,{children:[s.jsxs(as,{value:h,onValueChange:j,children:[s.jsx(is,{className:"w-fit",children:s.jsx(fs,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(os,{children:A4.map(z=>s.jsx(Mt,{value:z.value,children:z.label},z.value))})]}),s.jsx(be,{size:"xs",variant:"ghost",onClick:Te,title:t("settings.voice.page.actions.preview"),children:Ce?s.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(A,{name:"play",className:"w-3.5 h-3.5"})})]}),i==="openai-compatible"&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.voice.page.field.configuredAbove")}),i==="say"&&ve&&he.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(as,{value:b,onValueChange:x,children:[s.jsx(is,{className:"w-fit",children:s.jsx(fs,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(os,{children:he.map(z=>s.jsx(Mt,{value:z.name,children:z.name},z.name))})]}),s.jsx(be,{size:"xs",variant:"ghost",onClick:oe,title:t("settings.voice.page.actions.preview"),children:xe?s.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(A,{name:"play",className:"w-3.5 h-3.5"})})]}),i==="browser"&&F.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(as,{value:y||"$auto",onValueChange:z=>g(z==="$auto"?"":z),children:[s.jsx(is,{className:"w-fit max-w-[200px]",children:s.jsx(fs,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(os,{children:[s.jsx(Mt,{value:"$auto",children:t("settings.voice.page.field.auto")}),F.map(z=>s.jsxs(Mt,{value:z.name,children:[z.name," (",z.lang,")"]},z.name))]})]}),s.jsx(be,{size:"xs",variant:"ghost",onClick:U,title:t("settings.voice.page.actions.preview"),children:we?s.jsx(A,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(A,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.speechRate")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:c,onChange:z=>d(Number(z.target.value)),disabled:!n,className:Pe}),s.jsx($n,{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:z=>m(Number(z.target.value)),disabled:!n,className:Pe}),s.jsx($n,{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:z=>f(Number(z.target.value)),disabled:!n,className:Pe}),e?s.jsx($n,{value:Math.round(u*100),onValueChange:z=>f(z/100),min:0,max:100,step:10,className:"w-16 tabular-nums"}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(u*100),"%"]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.language")}),s.jsx("div",{className:"flex items-center gap-2 w-fit",children:s.jsxs(as,{value:r,onValueChange:a,disabled:!n,children:[s.jsx(is,{className:"w-fit",children:s.jsx(fs,{placeholder:t("settings.voice.page.field.selectLanguagePlaceholder")})}),s.jsx(os,{children:I4.map(z=>s.jsx(Mt,{value:z.value,children:z.label},z.value))})]})})]})]})]})]}),de&&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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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(be,{variant:"chip",size:"xs","aria-pressed":E==="browser",onClick:()=>R("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":E==="server",onClick:()=>R("server"),className:"!font-normal",children:t("settings.voice.page.provider.server")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":E==="wasm",onClick:()=>R("wasm"),className:"!font-normal",children:t("settings.voice.page.provider.wasm")})]})]})}),E==="server"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":K,onClick:()=>Q(!K),onKeyDown:z=>{(z.key===" "||z.key==="Enter")&&(z.preventDefault(),Q(!K))},children:[s.jsx(vs,{checked:K,onChange:Q,ariaLabel:t("settings.voice.page.field.transcribeOnStopAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.transcribeOnStop")})]}),!Py.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:ye("typography-ui-label text-foreground",!V.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:V,onChange:z=>B(z.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),V&&s.jsx("button",{type:"button",onClick:()=>B(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"API Key"}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:"Optional"}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"password",value:$,onChange:z=>O(z.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),$&&s.jsx("button",{type:"button",onClick:()=>O(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.model")}),s.jsx("div",{className:"relative mt-1.5 max-w-xs",children:s.jsx("input",{type:"text",value:_,onChange:z=>q(z.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.language")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.sttLanguageHint")}),s.jsx("div",{className:"relative mt-1.5 max-w-[8rem]",children:s.jsx("input",{type:"text",value:Z,onChange:z=>ie(z.target.value),placeholder:"auto",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"flex items-center gap-8 py-0.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.silenceThreshold")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:-60,max:-20,step:1,value:ne,onChange:z=>me(Number(z.target.value)),className:Pe}),s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3.5rem] text-right",children:[ne," dB"]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-0.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.silenceHold")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:500,max:3e3,step:100,value:pe,onChange:z=>G(Number(z.target.value)),className:Pe}),s.jsx($n,{value:pe,onValueChange:G,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")})]})]})]}),E==="wasm"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:t("settings.voice.page.stt.wasmModel")}),s.jsxs(as,{value:L,onValueChange:J,children:[s.jsx(is,{className:"mt-0.5",children:s.jsx(fs,{placeholder:t("settings.voice.page.stt.wasmModel")})}),s.jsx(os,{children:Zu.map(z=>s.jsx(Mt,{value:z.id,children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{children:z.name}),s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[z.size," · ",z.languages]})]})},z.id))})]}),s.jsx("p",{className:"typography-ui-compact text-muted-foreground mt-0.5",children:Zu.find(z=>z.id===L)?.description})]}),s.jsx(P4,{modelId:L})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.playbackAndSummary")})}),s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":M,onClick:()=>W(!M),onKeyDown:z=>{(z.key===" "||z.key==="Enter")&&(z.preventDefault(),W(!M))},children:[s.jsx(vs,{checked:M,onChange:W,ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.messageReadAloudButton")})]})}),de&&n&&s.jsx("div",{className:"mt-2 px-2",children:s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[t("settings.voice.page.hint.shiftClickPrefix")," ",s.jsx("kbd",{className:"px-1 py-0.5 mx-0.5 rounded border border-[var(--interactive-border)] bg-background typography-mono text-[10px]",children:"Shift"})," + ",s.jsx("kbd",{className:"px-1 py-0.5 mx-0.5 rounded border border-[var(--interactive-border)] bg-background typography-mono text-[10px]",children:"Click"})," ",t("settings.voice.page.hint.shiftClickSuffix")]})})]})]})};function T4(){Ji.onModelStatusChange=null}const Jo=[{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}],Yo=[{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}],E4="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",M4="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Qc=[{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"}],R4=[".yml",".yaml",".json"],F4="settings.openchamber.tunnel.error.invalidConfigExtension",Hi=t=>{const e=t.trim().toLowerCase();return R4.some(n=>e.endsWith(n))},Od=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,mf=t=>{const e=ot.c(11),{provider:n}=t;let r;e[0]!==n?(r=Od(n),e[0]=n,e[1]=r):r=e[1];const a=r,c=n==="cloudflare"||n==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let d;e[2]!==c?(d=ye("size-4 shrink-0",c),e[2]=c,e[3]=d):d=e[3];let p;e[4]!==d?(p=s.jsx(A,{name:"cloud",className:d}),e[4]=d,e[5]=p):p=e[5];let m;e[6]!==a?(m=s.jsx("span",{children:a}),e[6]=a,e[7]=m):m=e[7];let u;return e[8]!==p||e[9]!==m?(u=s.jsxs("span",{className:"flex items-center gap-2",children:[p,m]}),e[8]=p,e[9]=m,e[10]=u):u=e[10],u},pa=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",Ld=(t,e,n)=>t.find(a=>a.ms===e)?.value||n,pf=(t,e,n)=>{const r=Ld(t,e,n);return t.find(a=>a.value===r)?.label||r},ff=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`},O4=t=>new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),yl=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()}},L4=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=yl(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},$4=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,_4=()=>{const{t}=ft(),e=l.useCallback(Ae=>t(Ae),[t]),[n,r]=l.useState("checking"),[a,i]=l.useState(null),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(null),[f,b]=l.useState(null),[x,y]=l.useState(!1),[g,h]=l.useState(!1),[j,v]=l.useState(!1),[C,k]=l.useState("cloudflare"),[w,N]=l.useState([]),[I,T]=l.useState("quick"),[P,D]=l.useState(null),[S,M]=l.useState([]),[E,R]=l.useState({}),[V,B]=l.useState(""),[$,O]=l.useState({}),[_,q]=l.useState(new Set),[L,J]=l.useState(!1),[Z,ie]=l.useState(""),[ne,me]=l.useState(""),[pe,G]=l.useState(""),[K,Q]=l.useState(1800*1e3),[W,de]=l.useState(480*60*1e3),[ge,ve]=l.useState(""),[te,he]=l.useState([]),[ce,xe]=l.useState(()=>Date.now()),[se,ue]=l.useState(null),Y=t(F4),Se=l.useRef(null),fe=l.useMemo(()=>P?!Hi(P):!1,[P]),Ce=l.useMemo(()=>S.find(Ae=>Ae.id===V)||S[0]||null,[S,V]),Ie=l.useMemo(()=>te.map(Ae=>{const Le=Ae.expiresAt<=ce,ze=Ae.status==="active"&&!Le,Ke=ze?ff(Ae.expiresAt-ce):Ae.inactiveReason==="expired"||Le?"expired":"inactive",lt=Ke==="expired"?t("settings.openchamber.tunnel.state.expired"):Ae.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),xt=pa(Ae.mode);return{...Ae,isActive:ze,mode:xt,remainingTextForSession:Ke,inactiveLabel:lt}}),[ce,te,t]),ke=l.useMemo(()=>a?.connectUrl?a.bootstrapExpiresAt===null?!0:a.bootstrapExpiresAt>ce:!1,[ce,a?.bootstrapExpiresAt,a?.connectUrl]),X=l.useMemo(()=>!a||n!=="active"&&n!=="stopping"?!1:o===I,[o,n,a,I]),ae=l.useMemo(()=>!a||n!=="active"||!o?!1:o!==I,[o,n,a,I]),je=l.useMemo(()=>{if(typeof se=="number"&&Number.isFinite(se)&&se>0)return se;if(typeof window>"u")return null;const Ae=Number(window.location.port);return Number.isFinite(Ae)&&Ae>0?Ae:null},[se]),le=l.useMemo(()=>w.find(Ae=>Ae.provider===C)??null,[w,C]),Ne=l.useMemo(()=>{const Ae=new Set(le?.modes?.map(Le=>Le.key).filter(Le=>Le==="quick"||Le==="managed-remote"||Le==="managed-local"));return Ae.size===0?Qc:Qc.filter(Le=>Ae.has(Le.value))},[le]),Me=l.useMemo(()=>Ne.some(Ae=>Ae.value==="managed-remote"||Ae.value==="managed-local"),[Ne]),Ve=C==="ngrok"?"brew install ngrok":"brew install cloudflared",we=l.useCallback(async Ae=>{await rr(Ae)},[]),ee=l.useCallback(async Ae=>{try{const[Le,ze,Ke,lt]=await Promise.all([fetch("/api/openchamber/tunnel/check",{signal:Ae}),fetch("/api/openchamber/tunnel/status",{signal:Ae}),fetch("/api/config/settings",{signal:Ae,headers:{Accept:"application/json"}}),fetch("/api/openchamber/tunnel/providers",{signal:Ae})]),xt=await Le.json(),dt=await ze.json(),ut=Ke.ok?await Ke.json():{},Nt=lt.ok?await lt.json():{},ts=dt.ttlConfig?.bootstrapTtlMs??(ut?.tunnelBootstrapTtlMs===null?null:typeof ut?.tunnelBootstrapTtlMs=="number"?ut.tunnelBootstrapTtlMs:1800*1e3),Vt=typeof dt.ttlConfig?.sessionTtlMs=="number"?dt.ttlConfig.sessionTtlMs:typeof ut?.tunnelSessionTtlMs=="number"?ut.tunnelSessionTtlMs:480*60*1e3,Xt=pa(dt.mode??ut?.tunnelMode),ht=typeof ut?.tunnelProvider=="string"&&ut.tunnelProvider.trim().length>0?ut.tunnelProvider.trim().toLowerCase():"cloudflare",Bt=typeof ut?.managedLocalTunnelConfigPath=="string"&&ut.managedLocalTunnelConfigPath.trim()||null,Zt=L4(dt?.managedRemoteTunnelPresets),gs=typeof dt.managedRemoteTunnelHostname=="string"?dt.managedRemoteTunnelHostname:"",rs=Zt.length>0?Zt:gs?[{id:`legacy-${yl(gs)}`,name:gs,hostname:yl(gs)}]:[],ps=rs[0]?.id||"";if(Q(ts),de(Vt),k(ht),N(Array.isArray(Nt?.providers)?Nt.providers:[]),T(Xt),D(Bt),M(rs),B(ps),he(Array.isArray(dt.activeSessions)?dt.activeSessions:[]),c(dt.activeTunnelMode?pa(dt.activeTunnelMode):dt.active&&dt.mode?pa(dt.mode):null),q(new Set(Array.isArray(dt.managedRemoteTunnelTokenPresetIds)?dt.managedRemoteTunnelTokenPresetIds:[])),ue(typeof dt.localPort=="number"?dt.localPort:null),dt.active&&dt.url){i({url:dt.url,connectUrl:null,bootstrapExpiresAt:typeof dt.bootstrapExpiresAt=="number"?dt.bootstrapExpiresAt:null}),r("active");return}r(xt.available?"idle":"not-available")}catch{Ae.aborted||(r("error"),u(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[t]);l.useEffect(()=>{const Ae=new AbortController;return ee(Ae.signal),()=>Ae.abort()},[ee]),l.useEffect(()=>{if(!a?.connectUrl){p(null);return}let Ae=!1;return Jx.toDataURL(a.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(Le=>{Ae||p(Le)}).catch(()=>{Ae||p(null)}),()=>{Ae=!0}},[a?.connectUrl]),l.useEffect(()=>{if(!a?.bootstrapExpiresAt){ve(t("settings.openchamber.tunnel.state.noExpiry"));return}let Ae=null,Le=Date.now();const ze=()=>{const xt=a.bootstrapExpiresAt?a.bootstrapExpiresAt-Date.now():0;xt<=0?ve(t("settings.openchamber.tunnel.state.expired")):ve(ff(xt))},Ke=()=>{const xt=Date.now();xt-Le>=1e3&&(ze(),Le=xt),Ae=requestAnimationFrame(Ke)};ze(),(typeof document>"u"||document.visibilityState==="visible")&&(Ae=requestAnimationFrame(Ke));const lt=()=>{document.visibilityState==="visible"&&Ae===null?Ae=requestAnimationFrame(Ke):document.visibilityState!=="visible"&&Ae!==null&&(cancelAnimationFrame(Ae),Ae=null)};return document.addEventListener("visibilitychange",lt),()=>{document.removeEventListener("visibilitychange",lt),Ae!==null&&cancelAnimationFrame(Ae)}},[t,a?.bootstrapExpiresAt]),l.useEffect(()=>{let Ae=null,Le=Date.now();const ze=()=>{const lt=Date.now();lt-Le>=1e3&&(xe(lt),Le=lt),Ae=requestAnimationFrame(ze)};(typeof document>"u"||document.visibilityState==="visible")&&(Ae=requestAnimationFrame(ze));const Ke=()=>{document.visibilityState==="visible"&&Ae===null?Ae=requestAnimationFrame(ze):document.visibilityState!=="visible"&&Ae!==null&&(cancelAnimationFrame(Ae),Ae=null)};return document.addEventListener("visibilitychange",Ke),()=>{document.removeEventListener("visibilitychange",Ke),Ae!==null&&cancelAnimationFrame(Ae)}},[]),l.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let Ae=!1;const Le=async()=>{try{const Ke=await fetch("/api/openchamber/tunnel/status");if(!Ke.ok||Ae)return;const lt=await Ke.json();if(Ae)return;he(Array.isArray(lt.activeSessions)?lt.activeSessions:[]),q(new Set(Array.isArray(lt.managedRemoteTunnelTokenPresetIds)?lt.managedRemoteTunnelTokenPresetIds:[])),ue(typeof lt.localPort=="number"?lt.localPort:null)}catch{}},ze=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Le()},5e3);return()=>{Ae=!0,window.clearInterval(ze)}},[n]);const F=l.useCallback(async Ae=>{v(!0);try{await ks(Ae),Object.prototype.hasOwnProperty.call(Ae,"tunnelMode")&&Ae.tunnelMode&&T(Ae.tunnelMode),Object.prototype.hasOwnProperty.call(Ae,"tunnelProvider")&&typeof Ae.tunnelProvider=="string"&&k(Ae.tunnelProvider),Object.prototype.hasOwnProperty.call(Ae,"managedLocalTunnelConfigPath")&&D(Ae.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(Ae,"managedRemoteTunnelPresets")&&Ae.managedRemoteTunnelPresets&&M(Ae.managedRemoteTunnelPresets)}catch{H.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{v(!1)}},[t]),U=l.useCallback(async(Ae,Le)=>{h(!0);try{await ks({tunnelBootstrapTtlMs:Ae,tunnelSessionTtlMs:Le})}catch{H.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{h(!1)}},[t]),oe=l.useCallback(async Ae=>{const Le=Ae.token.trim();if(Le)try{const ze={...$,[Ae.presetId]:Le};await ks({managedRemoteTunnelPresetTokens:ze}),q(Ke=>{const lt=new Set(Ke);return lt.add(Ae.presetId),lt})}catch{H.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[$,t]),Te=l.useCallback(async Ae=>{b(null),u(null);const Le=w.find(Ke=>Ke.provider===Ae),ze=Le?.modes?.some(Ke=>Ke.key===I)?I:pa(Le?.modes?.[0]?.key);await F({tunnelProvider:Ae,tunnelMode:ze})},[w,F,I]),Oe=l.useCallback(async()=>{const Ae=await wh({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(Ae.success&&typeof Ae.path=="string"&&Ae.path.trim().length>0){const Le=Ae.path.trim();if(!Hi(Le)){H.error(Y);return}D(Le),await F({managedLocalTunnelConfigPath:Le});return}Se.current?.click()},[Y,F]),Pe=l.useCallback(Ae=>{const Le=Ae.trim();D(Le.length>0?Le:null)},[]),z=l.useCallback(async()=>{if(P&&!Hi(P)){H.error(Y);return}await F({managedLocalTunnelConfigPath:P})},[Y,P,F]),De=l.useCallback(async()=>{D(null),await F({managedLocalTunnelConfigPath:null})},[F]),Qe=l.useCallback(async Ae=>{const Le=Ae.target.files?.[0];if(!Le)return;const ze=Le.name.trim();if(ze.length!==0){if(!Hi(ze)){H.error(Y);return}D(ze),await F({managedLocalTunnelConfigPath:ze}),Ae.target.value=""}},[Y,F]),et=l.useCallback(async()=>{if(u(null),b(null),I==="managed-local"&&P&&!Hi(P)){u(Y),H.error(Y);return}r("starting");try{let Ae="",Le="";if(I==="managed-remote"){if(!Ce){r("idle"),b(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),H.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}Ae=Ce.hostname,Le=($[Ce.id]||"").trim(),await F({tunnelMode:"managed-remote",managedRemoteTunnelPresets:S})}const ze=await fetch("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:C,mode:I,...I==="managed-remote"&&Ce?{managedRemoteTunnelPresetId:Ce.id,managedRemoteTunnelPresetName:Ce.name}:{},...I==="managed-remote"&&Ae?{managedRemoteTunnelHostname:Ae}:{},...I==="managed-remote"&&Le?{managedRemoteTunnelToken:Le}:{},...I==="managed-local"&&P?{configPath:P}:{}})}),Ke=await ze.json();if(!ze.ok||!Ke.ok){if(I==="managed-remote"&&typeof Ke.error=="string"&&Ke.error.includes("Managed remote tunnel token is required")){r("idle"),b(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),H.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),u(Ke.error||t("settings.openchamber.tunnel.toast.startFailed")),H.error(Ke.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const lt=typeof Ke.url=="string"?Ke.url:"";if(!lt){r("error"),u(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),H.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(i({url:lt,connectUrl:typeof Ke.connectUrl=="string"?Ke.connectUrl:null,bootstrapExpiresAt:typeof Ke.bootstrapExpiresAt=="number"?Ke.bootstrapExpiresAt:null}),c(Ke.activeTunnelMode?pa(Ke.activeTunnelMode):Ke.mode?pa(Ke.mode):I),he(Array.isArray(Ke.activeSessions)?Ke.activeSessions:[]),Array.isArray(Ke.managedRemoteTunnelTokenPresetIds)&&q(new Set(Ke.managedRemoteTunnelTokenPresetIds)),typeof Ke.localPort=="number"&&ue(Ke.localPort),typeof Ke.mode=="string"&&T(pa(Ke.mode)),r("active"),Ke.replacedTunnel){const xt=typeof Ke.revokedBootstrapCount=="number"?Ke.revokedBootstrapCount:0,dt=typeof Ke.invalidatedSessionCount=="number"?Ke.invalidatedSessionCount:0;xt===1&&dt===1?H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):xt===1?H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:dt})):dt===1?H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:xt})):H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:xt,invalidatedSessionCount:dt}))}else H.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.startFailed")),H.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[Y,S,F,Ce,$,t,C,I,P]),Ze=l.useCallback(async()=>{r("stopping");try{await fetch("/api/openchamber/tunnel/stop",{method:"POST"});const Ae=await fetch("/api/openchamber/tunnel/status");if(Ae.ok){const Le=await Ae.json();he(Array.isArray(Le.activeSessions)?Le.activeSessions:[]),q(new Set(Array.isArray(Le.managedRemoteTunnelTokenPresetIds)?Le.managedRemoteTunnelTokenPresetIds:[])),ue(typeof Le.localPort=="number"?Le.localPort:null)}i(null),c(null),p(null),r("idle"),H.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.stopFailed")),H.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),We=l.useCallback(async()=>{if(a?.connectUrl)try{await navigator.clipboard.writeText(a.connectUrl),y(!0),H.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>y(!1),2e3)}catch{H.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,a?.connectUrl]),it=l.useCallback(async Ae=>{const Le=Jo.find(ze=>ze.value===Ae);Le&&(Q(Le.ms),await U(Le.ms,W))},[U,W]),qe=l.useCallback(async Ae=>{const Le=Yo.find(ze=>ze.value===Ae);!Le||Le.ms===null||(de(Le.ms),await U(K,Le.ms))},[K,U]),st=l.useCallback(async Ae=>{b(null),u(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await F({tunnelMode:Ae,managedRemoteTunnelPresets:S})},[S,F,n]),Je=l.useCallback(async(Ae,Le)=>{try{await ks({managedRemoteTunnelPresets:Le})}catch{H.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Be=l.useCallback(Ae=>{const Le=S.find(ze=>ze.id===Ae);Le&&(B(Le.id),b(null),Je(Le,S))},[S,Je]),nt=l.useCallback(async()=>{const Ae=Z.trim(),Le=yl(ne),ze=pe.trim();if(!Ae){H.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!Le){H.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!ze){H.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(S.some(xt=>xt.hostname===Le)){H.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Ke={id:$4(),name:Ae,hostname:Le},lt=[...S,Ke];M(lt),B(Ke.id),R(xt=>({...xt,[Ke.id]:!0})),O(xt=>({...xt,[Ke.id]:ze})),b(null),J(!1),ie(""),me(""),G(""),await F({tunnelMode:"managed-remote",managedRemoteTunnelPresets:lt,managedRemoteTunnelPresetTokens:{...$,[Ke.id]:ze}}),await oe({presetId:Ke.id,presetName:Ke.name,hostname:Ke.hostname,token:ze}),H.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[S,ne,Z,pe,oe,F,$,t]),Ge=l.useCallback(async Ae=>{const Le=S.find(dt=>dt.id===Ae);if(!Le)return;const ze=S.filter(dt=>dt.id!==Le.id),Ke=ze[0]?.id||"",lt=V===Le.id?Ke:V,xt=Object.fromEntries(Object.entries($).filter(([dt,ut])=>dt!==Le.id&&ut.trim().length>0));M(ze),B(lt),R(dt=>{const ut={...dt};return delete ut[Le.id],ut}),O(dt=>{const ut={...dt};return delete ut[Le.id],ut}),q(dt=>{const ut=new Set(dt);return ut.delete(Le.id),ut}),b(null),await F({managedRemoteTunnelPresets:ze,managedRemoteTunnelPresetTokens:xt}),H.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[S,F,V,$,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")})]}),Ie.length>0&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(A,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:Ie.map(Ae=>{const Le=Ae.mode==="quick",ze=Ae.mode==="managed-remote",Ke=Le?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":ze?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",lt=Ae.isActive?Le?"text-[var(--status-warning)]":ze?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",xt=t(Le?"settings.openchamber.tunnel.badge.quick":ze?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(A,{name:"checkbox-blank-circle-fill",className:ye("size-2.5 shrink-0",lt)}),s.jsx("span",{className:ye("typography-micro rounded border px-1.5 py-0.5 uppercase",Ke),children:xt}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:O4(Ae.createdAt)})}),s.jsx("span",{className:"typography-meta text-foreground",children:Ae.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:Ae.remainingTextForSession}):Ae.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:Ae.inactiveLabel})})]},Ae.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(A,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsxs("p",{className:"typography-meta font-medium text-foreground",children:[Od(C)," tunnel dependency was not found."]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:Ve})]})]})}),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(as,{value:C,onValueChange:Ae=>{Te(Ae)},disabled:j||n==="starting"||n==="stopping",children:[s.jsx(is,{className:"max-w-[16rem]",children:s.jsx(fs,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:Od(C)})}),s.jsxs(os,{children:[w.length>0?w.map(Ae=>s.jsx(Mt,{value:Ae.provider,children:s.jsx(mf,{provider:Ae.provider})},Ae.provider)):s.jsx(Mt,{value:"cloudflare",children:s.jsx(mf,{provider:"cloudflare"})}),s.jsx(Mt,{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:Ne.map(Ae=>s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(be,{variant:"chip",size:"xs","aria-pressed":I===Ae.value,className:"!font-normal",onClick:()=>{st(Ae.value)},disabled:j||n==="starting"||n==="stopping",children:e(Ae.labelKey)})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:e(Ae.tooltipKey)})]},Ae.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(as,{value:Ld(Jo,K,"1800000"),onValueChange:Ae=>{it(Ae)},disabled:g||j||n==="starting"||n==="stopping",children:[s.jsx(is,{className:"max-w-[11rem] min-w-0",children:s.jsx(fs,{className:"truncate",children:pf(Jo,K,"1800000")})}),s.jsx(os,{children:Jo.map(Ae=>s.jsx(Mt,{value:Ae.value,children:Ae.label},Ae.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(as,{value:Ld(Yo,W,"28800000"),onValueChange:Ae=>{qe(Ae)},disabled:g||j||n==="starting"||n==="stopping",children:[s.jsx(is,{className:"max-w-[11rem] min-w-0",children:s.jsx(fs,{className:"truncate",children:pf(Yo,W,"28800000")})}),s.jsx(os,{children:Yo.map(Ae=>s.jsx(Mt,{value:Ae.value,children:Ae.label},Ae.value))})]})]})]}),I==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(A,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.option.mode.quick.tooltip")}),Me&&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 je=="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:",je]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(be,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>J(Ae=>!Ae),disabled:n==="starting"||n==="stopping"||j,children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),S.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:S.map((Ae,Le)=>{const ze=$[Ae.id]||"",Ke=_.has(Ae.id),lt=E[Ae.id]??!1;return s.jsx("div",{className:ye(Le<S.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(vr,{open:lt,onOpenChange:xt=>{R(dt=>({...dt,[Ae.id]:xt})),xt&&Be(Ae.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Mr,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||j,children:[lt?s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:Ae.name})]}),s.jsx(be,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.openchamber.tunnel.actions.removePresetAria",{name:Ae.name}),onClick:()=>{Ge(Ae.id)},disabled:n==="starting"||n==="stopping"||j,children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(wr,{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:Ae.hostname})]}),s.jsx(Lt,{type:"password",value:ze,onChange:xt=>{const dt=xt.target.value;b(null),O(ut=>({...ut,[Ae.id]:dt}))},onBlur:xt=>{const dt=xt.currentTarget.value.trim();dt&&oe({presetId:Ae.id,presetName:Ae.name,hostname:Ae.hostname,token:dt})},placeholder:t(Ke?"settings.openchamber.tunnel.field.savedTokenAvailablePlaceholder":"settings.openchamber.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||ze.trim().length===0,onClick:()=>{oe({presetId:Ae.id,presetName:Ae.name,hostname:Ae.hostname,token:ze})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},Ae.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),L&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Lt,{value:Z,onChange:Ae=>ie(Ae.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:j||n==="starting"||n==="stopping"}),s.jsx(Lt,{value:ne,onChange:Ae=>me(Ae.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:j||n==="starting"||n==="stopping"}),s.jsx(Lt,{type:"password",value:pe,onChange:Ae=>G(Ae.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:j||n==="starting"||n==="stopping"}),typeof je=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",je]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{nt()},disabled:j||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{J(!1),ie(""),me(""),G("")},disabled:j||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground/70 hover:text-foreground","aria-label":t("settings.openchamber.tunnel.field.managedRemoteTokenInfoAria"),children:s.jsx(A,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]})]}),!Ce&&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:Se,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:Ae=>{Qe(Ae)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Lt,{value:P||"",onChange:Ae=>{Pe(Ae.target.value)},onBlur:()=>{z()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||j}),s.jsx(be,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{Oe()},disabled:n==="starting"||n==="stopping"||j,children:s.jsx(A,{name:"folder",className:"size-3.5"})}),P&&s.jsx(be,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{De()},disabled:n==="starting"||n==="stopping"||j,children:s.jsx(A,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(P?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),fe&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Y})]})}),!X&&s.jsxs("div",{className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(A,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[I==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{we(E4)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(A,{name:"external-link",className:"size-3.5"})]})]}),I==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{we(M4)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(A,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.startModeAndGenerateLink",{mode:e(Qc.find(Ae=>Ae.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(as,{value:V||(S[0]?.id??""),onValueChange:Ae=>{Be(Ae)},disabled:j||n==="starting"||n==="stopping"||S.length<=1,children:[s.jsx(is,{children:s.jsx(fs,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Ce?.name})}),s.jsx(os,{fitContent:!0,children:S.map(Ae=>s.jsx(Mt,{value:Ae.id,children:Ae.name},Ae.id))})]})]}),ae&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(A,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(be,{size:"sm",variant:"outline",onClick:et,disabled:n==="starting"||j||I==="managed-remote"&&!Ce||I==="managed-local"&&fe,className:ye(at,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),X&&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})]}),ke&&a.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:a.connectUrl}),s.jsxs(be,{size:"sm",variant:"ghost",onClick:We,className:"shrink-0 gap-1.5",children:[x?s.jsx(A,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(A,{name:"file-copy",className:"size-3.5"}),t(x?"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?ge:t("settings.openchamber.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[d?s.jsx("img",{src:d,alt:t("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(be,{size:"sm",variant:"outline",onClick:et,disabled:n==="stopping"||j||I==="managed-local"&&fe,className:at,children:[s.jsx(A,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(be,{size:"sm",variant:"ghost",onClick:Ze,disabled:n==="stopping"||j,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&m&&s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m}),s.jsx(be,{size:"sm",variant:"ghost",onClick:et,children:t("settings.openchamber.tunnel.actions.retry")})]})]})},Hg=()=>{const{t}=ft(),[e,n]=_e.useState(""),[r,a]=_e.useState(!0),[i,o]=_e.useState(!1),c=Fe(u=>u.showOpenCodeUpdateNotifications),d=Fe(u=>u.setShowOpenCodeUpdateNotifications);_e.useEffect(()=>{let u=!1;return(async()=>{try{const f=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!f.ok)return;const b=await f.json().catch(()=>null);if(u||!b)return;const x=typeof b.opencodeBinary=="string"?b.opencodeBinary.trim():"";n(x)}catch{}finally{u||a(!1)}})(),()=>{u=!0}},[]);const p=_e.useCallback(async()=>{if(typeof window>"u"||!jn()||!Ka())return;const u=window.__TAURI__;if(u?.dialog?.open)try{const f=await u.dialog.open({title:t("settings.openchamber.opencodeCli.dialog.selectBinaryTitle"),multiple:!1,directory:!1});typeof f=="string"&&f.trim().length>0&&n(f.trim())}catch{}},[t]),m=_e.useCallback(async()=>{o(!0);try{await ks({opencodeBinary:e.trim()}),await xi({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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",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(Lt,{value:e,onChange:u=>n(u.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:r||i,className:"h-7 min-w-0 flex-1 font-mono text-xs"}),s.jsx(be,{type:"button",variant:"outline",size:"xs",onClick:p,disabled:r||i||!jn()||!Ka(),className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(A,{name:"folder",className:"h-4 w-4"})})]})]}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"typography-micro text-muted-foreground/70",children:[t("settings.openchamber.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.openchamber.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]})}),s.jsxs("label",{className:"flex cursor-pointer items-center gap-2 py-1.5",children:[s.jsx(vs,{checked:c,onChange:d,ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.opencodeCli.field.showUpdateNotifications")})]}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(be,{type:"button",size:"xs",onClick:m,disabled:r||i,className:"shrink-0 !font-normal",children:t(i?"settings.common.actions.saving":"settings.openchamber.opencodeCli.actions.saveAndReload")})})]})]})},Gg=()=>{const{t}=ft(),e=jn()&&ta(),[n,r]=_e.useState(!1),[a,i]=_e.useState(!1),[o,c]=_e.useState(""),[d,p]=_e.useState(""),[m,u]=_e.useState(!0),[f,b]=_e.useState(!1),[x,y]=_e.useState(null),[g,h]=_e.useState(null);_e.useEffect(()=>{if(!e){u(!1);return}let N=!1;return(async()=>{try{const I=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!I.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const T=await I.json().catch(()=>null);if(N)return;const P=T?.desktopLanAccessEnabled===!0,D=typeof T?.desktopUiPassword=="string"?T.desktopUiPassword:"";r(P),i(P),c(D),p(D),y(null)}catch(I){N||y(I instanceof Error?I.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{N||u(!1)}})(),()=>{N=!0}},[e,t]),_e.useEffect(()=>{if(!e||!a){h(null);return}let N=!1;return(async()=>{const I=await Ay();N||h(I)})(),()=>{N=!0}},[a,e]);const j=a!==n||d!==o,v=_e.useMemo(()=>{if(typeof window>"u")return null;const N=Number(window.location.port);return Number.isFinite(N)&&N>0?N:null},[]),C=a&&g&&v?`http://${g}:${v}`:null,k=_e.useCallback(()=>{i(N=>!N)},[]),w=_e.useCallback(async()=>{if(j){b(!0),y(null);try{if(!(await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:a,desktopUiPassword:d})})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(r(a),c(d),!await Ph())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(N){y(N instanceof Error?N.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),b(!1)}}},[d,a,j,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:"space-y-1 py-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",htmlFor:"desktop-ui-password",children:t("settings.openchamber.desktopPassword.field.password")}),s.jsx(Lt,{id:"desktop-ui-password",type:"password",className:"h-7 max-w-sm",value:d,onChange:N=>p(N.target.value),placeholder:t("settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:m||f}),s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t("settings.openchamber.desktopPassword.field.passwordDescription")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:k,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),k())},children:[s.jsx(vs,{checked:a,onChange:k,ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria"),disabled:m||f}),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")})]})]}),x?s.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:x}):null,C?s.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[t(j&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:C})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(be,{type:"button",size:"xs",onClick:w,disabled:m||f||!j,className:"shrink-0 !font-normal",children:t(f?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})]}):null},B4=new Set(["shift","control","alt","meta"]),V4=t=>{if(B4.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=Ty(t.key);return n?(e.push(n),di(e.join("+"))):null},z4=()=>{const t=ot.c(58),{t:e}=ft();let n;t[0]!==e?(n=pe=>e(pe),t[0]=e,t[1]=n):n=t[1];const r=n,a=Fe(U4),i=Fe(W4),o=Fe(K4),c=Fe(H4);let d;t[2]===Symbol.for("react.memo_cache_sentinel")?(d=Dy(),t[2]=d):d=t[2];const p=d;let m;t[3]!==r?(m=(pe,G)=>{const K=`settings.openchamber.keyboardShortcuts.action.${pe}.label`,Q=r(K);return Q===K?G:Q},t[3]=r,t[4]=m):m=t[4];const u=m,[f,b]=l.useState(null);let x;t[5]===Symbol.for("react.memo_cache_sentinel")?(x={},t[5]=x):x=t[5];const[y,g]=l.useState(x),[h,j]=l.useState(""),[v,C]=l.useState(""),[k,w]=l.useState(null);let N;t[6]!==a?(N=(pe,G)=>{const K=di(G);for(const Q of p){if(Q.id===pe)continue;const W=Xr(Q.id,a);if(di(W)===K)return Q.id}return null},t[6]=a,t[7]=N):N=t[7];const I=N;let T;t[8]!==I||t[9]!==i||t[10]!==e?(T=(pe,G)=>{const K=di(G),Q=I(pe,K);if(Q){w({actionId:pe,combo:K,conflictActionId:Q}),j("");return}i(pe,K),w(null),j(""),C(em(K)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),g(W=>{const de={...W};return delete de[pe],de})},t[8]=I,t[9]=i,t[10]=e,t[11]=T):T=t[11];const P=T;let D;t[12]!==k||t[13]!==i||t[14]!==e?(D=()=>{k&&(i(k.conflictActionId,Ey),i(k.actionId,k.combo),w(null),j(""),C(em(k.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),g(pe=>{const G={...pe};return delete G[k.actionId],G}))},t[12]=k,t[13]=i,t[14]=e,t[15]=D):D=t[15];const S=D;let M;t[16]!==o?(M=pe=>{o(pe),g(G=>{const K={...G};return delete K[pe],K}),w(null),j(""),C("")},t[16]=o,t[17]=M):M=t[17];const E=M;let R;t[18]!==e?(R=e("settings.openchamber.keyboardShortcuts.title"),t[18]=e,t[19]=R):R=t[19];let V;t[20]!==R?(V=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:R}),t[20]=R,t[21]=V):V=t[21];let B;t[22]!==c?(B=()=>{c(),g({}),w(null),j(""),C("")},t[22]=c,t[23]=B):B=t[23];let $;t[24]!==e?($=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),t[24]=e,t[25]=$):$=t[25];let O;t[26]!==B||t[27]!==$?(O=s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:B,children:$}),t[26]=B,t[27]=$,t[28]=O):O=t[28];let _;t[29]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(Ct,{asChild:!0,children:s.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[29]=_):_=t[29];let q;t[30]!==e?(q=e("settings.openchamber.keyboardShortcuts.tooltip"),t[30]=e,t[31]=q):q=t[31];let L;t[32]!==q?(L=s.jsxs(kt,{children:[_,s.jsx(It,{sideOffset:8,className:"max-w-xs",children:q})]}),t[32]=q,t[33]=L):L=t[33];let J;t[34]!==O||t[35]!==L||t[36]!==V?(J=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[V,O,L]})}),t[34]=O,t[35]=L,t[36]=V,t[37]=J):J=t[37];let Z;t[38]!==S||t[39]!==h||t[40]!==k||t[41]!==e||t[42]!==v?(Z=(h||v||k)&&s.jsxs("div",{className:"mb-2 space-y-2 px-1",children:[k&&s.jsxs("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[s.jsx("span",{className:"typography-meta text-foreground",children:e("settings.openchamber.keyboardShortcuts.overwritePrompt")}),s.jsxs("div",{className:"flex gap-2 shrink-0",children:[s.jsx(be,{type:"button",size:"xs",className:"!font-normal",onClick:S,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),s.jsx(be,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>w(null),children:e("settings.common.actions.cancel")})]})]}),h&&s.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:h}),v&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:v})]}),t[38]=S,t[39]=h,t[40]=k,t[41]=e,t[42]=v,t[43]=Z):Z=t[43];let ie;t[44]!==u||t[45]!==f||t[46]!==y||t[47]!==E||t[48]!==P||t[49]!==a||t[50]!==e?(ie=p.map((pe,G)=>{const K=Xr(pe.id,a),Q=y[pe.id],W=Q??K,de=typeof Q=="string"&&di(Q)!==di(K);return s.jsxs("div",{className:ye("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",G>0&&"border-t border-[var(--surface-subtle)]"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:u(pe.id,pe.label)})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx(Lt,{readOnly:!0,value:f===pe.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):Yl(W),onFocus:()=>{b(pe.id),j("")},onBlur:()=>{f===pe.id&&b(null)},onKeyDown:ge=>{if(ge.preventDefault(),ge.stopPropagation(),ge.key==="Escape"){b(null);return}const ve=V4(ge);ve&&(g(te=>({...te,[pe.id]:ve})),b(null),w(null),j(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),s.jsx(be,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const ge=y[pe.id];if(!ge){j(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}P(pe.id,ge)},disabled:!de,children:e("settings.common.actions.saveChanges")}),s.jsx(be,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>E(pe.id),children:e("settings.common.actions.reset")})]})]},pe.id)}),t[44]=u,t[45]=f,t[46]=y,t[47]=E,t[48]=P,t[49]=a,t[50]=e,t[51]=ie):ie=t[51];let ne;t[52]!==ie?(ne=s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:ie}),t[52]=ie,t[53]=ne):ne=t[53];let me;return t[54]!==J||t[55]!==Z||t[56]!==ne?(me=s.jsxs("div",{className:"mb-8",children:[J,Z,ne]}),t[54]=J,t[55]=Z,t[56]=ne,t[57]=me):me=t[57],me};function U4(t){return t.shortcutOverrides}function W4(t){return t.setShortcutOverride}function K4(t){return t.clearShortcutOverride}function H4(t){return t.resetAllShortcutOverrides}const G4=t=>{const e=ot.c(20),{section:n}=t,{isMobile:r}=ln();let a;e[0]!==r?(a=r&&ea(),e[0]=r,e[1]=a):a=e[1];const i=a;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=fn(),e[2]=o):o=e[2];const c=o;let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=jn()&&ta(),e[3]=d):d=e[3];const p=d;if(!n){let x;e[4]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(ju,{}),e[4]=x):x=e[4];let y,g,h;e[5]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Kg,{})}),g=!c&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Hg,{})}),h=p&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Gg,{})}),e[5]=y,e[6]=g,e[7]=h):(y=e[5],g=e[6],h=e[7]);let j;e[8]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ug,{})}),e[8]=j):j=e[8];let v;e[9]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Wg,{})}),e[9]=v):v=e[9];let C;e[10]!==i?(C=i&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(p4,{})}),e[10]=i,e[11]=C):C=e[11];let k;return e[12]!==C?(k=s.jsx(Ss,{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:[x,y,g,h,j,v,C]})}),e[12]=C,e[13]=k):k=e[13],k}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return s.jsx(J4,{});case"chat":return s.jsx(Y4,{});case"sessions":return s.jsx(Q4,{});case"shortcuts":return s.jsx(q4,{});case"git":return s.jsx(X4,{});case"github":return s.jsx(Z4,{});case"notifications":return s.jsx(eI,{});case"voice":return s.jsx(tI,{});case"tunnel":return s.jsx(sI,{});default:return null}},e[14]=n,e[15]=m):m=e[15];const u=m;let f;e[16]!==u?(f=u(),e[16]=u,e[17]=f):f=e[17];let b;return e[18]!==f?(b=s.jsx(Ss,{outerClassName:"h-full",className:"w-full",children:s.jsx("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",children:f})}),e[18]=f,e[19]=b):b=e[19],b},q4=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(z4,{}),t[0]=e):e=t[0],e},J4=()=>{const t=ot.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=fn(),t[0]=e):e=t[0];const n=e;let r;return t[1]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(ju,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat","weekStart","fontSize","terminalFontSize","spacing","inputBarOffset",...n?[]:["terminalQuickKeys"],"reportUsage"]}),t[1]=r):r=t[1],r},Y4=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(ju,{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},Q4=()=>{const t=ot.c(7);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=fn(),t[0]=e):e=t[0];const n=e;let r;t[1]===Symbol.for("react.memo_cache_sentinel")?(r=jn()&&ta(),t[1]=r):r=t[1];const a=r;let i,o,c;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Kg,{}),o=!n&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Hg,{})}),c=a&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Gg,{})}),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(Ug,{})}),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(Wg,{})})]}),t[6]=p):p=t[6],p},X4=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"space-y-6",children:s.jsx(_g,{})}),t[0]=e):e=t[0],e},Z4=()=>{const t=ot.c(1);if(fn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Bg,{}),t[0]=e):e=t[0],e},eI=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(C4,{}),t[0]=e):e=t[0],e},tI=()=>{const t=ot.c(1);if(fn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(D4,{}),t[0]=e):e=t[0],e},sI=()=>{const t=ot.c(1);if(fn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(_4,{}),t[0]=e):e=t[0],e},$d=176,_d=280,hf=8,qg="__openchamberSettingsDetail";function Xc(t){return Math.min(_d,Math.max($d,t))}const nI=["appearance","chat","notifications","sessions","shortcuts","git","magic-prompts","snippets","projects","remote-instances","agents","behavior","commands","mcp","plugins","providers","usage","skills.installed","skills.catalog","voice","tunnel"],rI={icon:"chat-thread"};function aI(t){const e=fn(),n=!t&&ea();return{isVSCode:e,isWeb:n,isDesktop:t}}function gf(t,e){return t.isAvailable?t.isAvailable(e):!0}function Bd(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Zc(t){if(!Bd(t))return null;const e=t[qg];if(!Bd(e))return null;const n=e.page,r=e.stage;return typeof n!="string"||r!=="page-content"?null:{page:bu(n),stage:r}}function iI(){return typeof window>"u"||!Bd(window.history.state)?{}:window.history.state}function Nu(t){switch(t){case"projects":return"folders";case"remote-instances":return"server";case"appearance":return"palette";case"chat":return"chat-ai-3";case"magic-prompts":return"ai-generate-2";case"snippets":return rI.icon;case"notifications":return"notification-3";case"shortcuts":return"command";case"sessions":return"chat-history";case"providers":return"cloud";case"agents":return"ai-agent";case"behavior":return"brain";case"commands":return"slash-commands-2";case"mcp":return"plug-2";case"plugins":return"code-box";case"skills.installed":return"book-open";case"skills.catalog":return"book";case"git":return"git-branch";case"usage":return"bar-chart-2";case"voice":return"mic";case"tunnel":return"global";case"home":return null;default:return"robot-2"}}const ed=t=>{const e=ot.c(95),{onOpen:n}=t,{t:r}=ft();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=ye("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[13]=m):m=e[13];let u;e[14]!==r?(u=r("settings.view.home.cards.providers.title"),e[14]=r,e[15]=u):u=e[15];let f;e[16]!==u?(f=s.jsx("div",{className:"typography-ui-label text-foreground",children:u}),e[16]=u,e[17]=f):f=e[17];let b;e[18]!==r?(b=r("settings.view.home.cards.providers.description"),e[18]=r,e[19]=b):b=e[19];let x;e[20]!==b?(x=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:b}),e[20]=b,e[21]=x):x=e[21];let y;e[22]!==x||e[23]!==p||e[24]!==f?(y=s.jsxs("button",{type:"button",onClick:p,className:m,children:[f,x]}),e[22]=x,e[23]=p,e[24]=f,e[25]=y):y=e[25];let g;e[26]!==n?(g=()=>n("agents"),e[26]=n,e[27]=g):g=e[27];let h;e[28]===Symbol.for("react.memo_cache_sentinel")?(h=ye("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[28]=h):h=e[28];let j;e[29]!==r?(j=r("settings.view.home.cards.agents.title"),e[29]=r,e[30]=j):j=e[30];let v;e[31]!==j?(v=s.jsx("div",{className:"typography-ui-label text-foreground",children:j}),e[31]=j,e[32]=v):v=e[32];let C;e[33]!==r?(C=r("settings.view.home.cards.agents.description"),e[33]=r,e[34]=C):C=e[34];let k;e[35]!==C?(k=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:C}),e[35]=C,e[36]=k):k=e[36];let w;e[37]!==g||e[38]!==v||e[39]!==k?(w=s.jsxs("button",{type:"button",onClick:g,className:h,children:[v,k]}),e[37]=g,e[38]=v,e[39]=k,e[40]=w):w=e[40];let N;e[41]!==n?(N=()=>n("skills.catalog"),e[41]=n,e[42]=N):N=e[42];let I;e[43]===Symbol.for("react.memo_cache_sentinel")?(I=ye("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 T;e[44]!==r?(T=r("settings.view.home.cards.skillsCatalog.title"),e[44]=r,e[45]=T):T=e[45];let P;e[46]!==T?(P=s.jsx("div",{className:"typography-ui-label text-foreground",children:T}),e[46]=T,e[47]=P):P=e[47];let D;e[48]!==r?(D=r("settings.view.home.cards.skillsCatalog.description"),e[48]=r,e[49]=D):D=e[49];let S;e[50]!==D?(S=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:D}),e[50]=D,e[51]=S):S=e[51];let M;e[52]!==N||e[53]!==P||e[54]!==S?(M=s.jsxs("button",{type:"button",onClick:N,className:I,children:[P,S]}),e[52]=N,e[53]=P,e[54]=S,e[55]=M):M=e[55];let E;e[56]!==n?(E=()=>n("mcp"),e[56]=n,e[57]=E):E=e[57];let R;e[58]===Symbol.for("react.memo_cache_sentinel")?(R=ye("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[58]=R):R=e[58];let V;e[59]!==r?(V=r("settings.view.home.cards.mcp.title"),e[59]=r,e[60]=V):V=e[60];let B;e[61]!==V?(B=s.jsx("div",{className:"typography-ui-label text-foreground",children:V}),e[61]=V,e[62]=B):B=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 _;e[67]!==E||e[68]!==B||e[69]!==O?(_=s.jsxs("button",{type:"button",onClick:E,className:R,children:[B,O]}),e[67]=E,e[68]=B,e[69]=O,e[70]=_):_=e[70];let q;e[71]!==n?(q=()=>n("usage"),e[71]=n,e[72]=q):q=e[72];let L;e[73]===Symbol.for("react.memo_cache_sentinel")?(L=ye("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[73]=L):L=e[73];let J;e[74]!==r?(J=r("settings.view.home.cards.usage.title"),e[74]=r,e[75]=J):J=e[75];let Z;e[76]!==J?(Z=s.jsx("div",{className:"typography-ui-label text-foreground",children:J}),e[76]=J,e[77]=Z):Z=e[77];let ie;e[78]!==r?(ie=r("settings.view.home.cards.usage.description"),e[78]=r,e[79]=ie):ie=e[79];let ne;e[80]!==ie?(ne=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:ie}),e[80]=ie,e[81]=ne):ne=e[81];let me;e[82]!==q||e[83]!==Z||e[84]!==ne?(me=s.jsxs("button",{type:"button",onClick:q,className:L,children:[Z,ne]}),e[82]=q,e[83]=Z,e[84]=ne,e[85]=me):me=e[85];let pe;e[86]!==y||e[87]!==w||e[88]!==M||e[89]!==_||e[90]!==me?(pe=s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[y,w,M,_,me]}),e[86]=y,e[87]=w,e[88]=M,e[89]=_,e[90]=me,e[91]=pe):pe=e[91];let G;return e[92]!==pe||e[93]!==d?(G=s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl px-6 py-6 space-y-6",children:[d,pe]})}),e[92]=pe,e[93]=d,e[94]=G):G=e[94],G},oI=t=>{const e=ot.c(97),{onClose:n,forceMobile:r,isWindowed:a}=t,{t:i}=ft(),o=ln(),c=r??o.isMobile,d=Fe(lI),p=Fe(cI),m=Fe(dI);let u;e[0]!==d?(u=bu(d),e[0]=d,e[1]=u):u=e[1];const f=u,[b,x]=l.useState("nav"),y=l.useRef(null),[g,h]=l.useState(216),[j,v]=l.useState(!1),[C,k]=l.useState(!1),w=l.useRef(0),N=l.useRef(g),I=l.useRef(null);let T;e[2]===Symbol.for("react.memo_cache_sentinel")?(T=jn(),e[2]=T):T=e[2];const P=T;let D;e[3]===Symbol.for("react.memo_cache_sentinel")?(D=aI(P),e[3]=D):D=e[3];const S=D;let M;if(e[4]!==c){let Je;e[6]===Symbol.for("react.memo_cache_sentinel")?(Je=nt=>gf(nt,S),e[6]=Je):Je=e[6];let Be;e[7]===Symbol.for("react.memo_cache_sentinel")?(Be=nt=>!(S.isVSCode&&nt.slug==="projects"),e[7]=Be):Be=e[7],M=xu.filter(uI).filter(Je).filter(Be).filter(nt=>!(c&&nt.slug==="shortcuts")),e[4]=c,e[5]=M}else M=e[5];const E=M;let R;e[8]===Symbol.for("react.memo_cache_sentinel")?(R=new Map(nI.map(mI)),e[8]=R):R=e[8];const V=R;let B;if(e[9]!==E){let Je;e[11]===Symbol.for("react.memo_cache_sentinel")?(Je=(Be,nt)=>(V.get(Be.slug)??999)-(V.get(nt.slug)??999),e[11]=Je):Je=e[11],B=E.slice().sort(Je),e[9]=E,e[10]=B}else B=e[10];const $=B,O=Cs(pI);let _,q;e[12]!==j?(_=()=>{if(typeof window>"u")return;const Je=()=>{if(!j){const Be=Xc(Math.floor(window.innerWidth*.12));h(Be)}};return window.addEventListener("resize",Je),()=>window.removeEventListener("resize",Je)},q=[j],e[12]=j,e[13]=_,e[14]=q):(_=e[13],q=e[14]),l.useEffect(_,q);let L,J;e[15]!==C?(J=()=>{if(!C)return;const Je=nt=>{const Ge=nt.clientX-w.current,at=Xc(N.current+Ge);h(at),v(!0)},Be=()=>k(!1);return window.addEventListener("pointermove",Je),window.addEventListener("pointerup",Be,{once:!0}),()=>{window.removeEventListener("pointermove",Je),window.removeEventListener("pointerup",Be)}},L=[C],e[15]=C,e[16]=L,e[17]=J):(L=e[16],J=e[17]),l.useEffect(J,L);let Z;e[18]!==g?(Z=Je=>{k(!0),w.current=Je.clientX,N.current=g,Je.preventDefault()},e[18]=g,e[19]=Z):Z=e[19];const ie=Z;let ne;e[20]!==g?(ne=Je=>{const Be=Je.shiftKey?hf*4:hf;let nt;e:switch(Je.key){case"ArrowLeft":{nt=g-Be;break e}case"ArrowRight":{nt=g+Be;break e}case"Home":{nt=$d;break e}case"End":{nt=_d;break e}default:return}Je.preventDefault(),h(Xc(nt)),v(!0)},e[20]=g,e[21]=ne):ne=e[21];const me=ne;let pe;e[22]!==p||e[23]!==a||e[24]!==f?(pe=()=>{if(!(!p&&!S.isVSCode&&!a)){if(f==="agents"){ji.getState().loadAgents();return}if(f==="commands"){ru.getState().loadCommands();return}if(f==="mcp"){go.getState().loadMcpConfigs();return}if(f==="plugins"){In.getState().loadPlugins();return}(f==="skills.installed"||f==="skills.catalog")&&(ha.getState().loadSkills(),Va.getState().loadCatalog()),f==="snippets"&&rc.getState().loadSnippets()}},e[22]=p,e[23]=a,e[24]=f,e[25]=pe):pe=e[25];let G;e[26]!==O||e[27]!==p||e[28]!==a||e[29]!==f?(G=[O,p,a,S.isVSCode,f],e[26]=O,e[27]=p,e[28]=a,e[29]=f,e[30]=G):G=e[30],l.useEffect(pe,G);let K;e[31]!==c||e[32]!==m?(K=Je=>{if(m(Je),y.current=Je,!c)return;const Be=Qi(Je);if(!Be||Be.slug==="home"){x("nav");return}x(Be.kind==="split"?"page-sidebar":"page-content")},e[31]=c,e[32]=m,e[33]=K):K=e[33];const Q=K;let W;e[34]!==f?(W=Qi(f),e[34]=f,e[35]=W):W=e[35];const de=W;let ge;e[36]===Symbol.for("react.memo_cache_sentinel")?(ge={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[36]=ge):ge=e[36];const ve=ge;let te;e[37]!==i?(te=Je=>{switch(Je){case"projects":return i("settings.page.projects.title");case"remote-instances":return i("settings.page.remoteInstances.title");case"providers":return i("settings.page.providers.title");case"usage":return i("settings.page.usage.title");case"agents":return i("settings.page.agents.title");case"behavior":return i("settings.page.behavior.title");case"commands":return i("settings.page.commands.title");case"mcp":return i("settings.page.mcp.title");case"plugins":return i("settings.page.plugins.title");case"skills.installed":return i("settings.page.skills.title");case"skills.catalog":return i("settings.page.skillsCatalog.title");case"git":return i("settings.page.git.title");case"appearance":return i("settings.page.appearance.title");case"chat":return i("settings.page.chat.title");case"shortcuts":return i("settings.page.shortcuts.title");case"sessions":return i("settings.page.sessions.title");case"magic-prompts":return i("settings.page.magicPrompts.title");case"snippets":return i("settings.page.snippets.title");case"notifications":return i("settings.page.notifications.title");case"voice":return i("settings.page.voice.title");case"tunnel":return i("settings.page.tunnel.title");default:return i("settings.view.home.title")}},e[37]=i,e[38]=te):te=e[38];const he=te;let ce;e[39]!==i?(ce=()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:i("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:i("settings.view.unavailable.description")})]})}),e[39]=i,e[40]=ce):ce=e[40];const xe=ce,se=fI;let ue;e[41]!==Q||e[42]!==xe?(ue=Je=>{const Be=Qi(Je);if(Be&&!gf(Be,S))return xe();switch(Je){case"home":return s.jsx(ed,{onOpen:Q});case"projects":return s.jsx(I5,{});case"remote-instances":return s.jsx(Z5,{});case"agents":return s.jsx(wk,{});case"behavior":return s.jsx(Ck,{});case"commands":return s.jsx(Fk,{});case"mcp":return s.jsx(c3,{});case"plugins":return s.jsx(L3,{});case"skills.installed":return s.jsx(zp,{view:"installed"});case"skills.catalog":return s.jsx(zp,{view:"catalog"});case"providers":return s.jsx(oC,{});case"usage":return s.jsx(kC,{});case"magic-prompts":return s.jsx(DC,{});case"snippets":return s.jsx(FC,{});case"git":return s.jsx(BC,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const nt=ve[Je]??"visual";return s.jsx(G4,{section:nt})}default:return s.jsx(ed,{onOpen:Q})}},e[41]=Q,e[42]=xe,e[43]=ue):ue=e[43];const Y=ue;let Se,fe;e[44]!==c||e[45]!==b||e[46]!==f?(Se=()=>{if(!c||b!=="nav"||f==="home"||y.current===f)return;const Je=Qi(f);!Je||Je.slug==="home"||(y.current=f,x(Je.kind==="split"?"page-sidebar":"page-content"))},fe=[c,b,f],e[44]=c,e[45]=b,e[46]=f,e[47]=Se,e[48]=fe):(Se=e[47],fe=e[48]),l.useEffect(Se,fe);const Ce=c&&b!=="nav",Ie=c&&b==="page-content"&&f==="skills.installed",ke=b==="page-content"&&de?.kind==="split"&&!Ie;let X;e[49]!==Ie||e[50]!==Ce||e[51]!==i?(X=i(Ie?"settings.view.actions.back":Ce?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),e[49]=Ie,e[50]=Ce,e[51]=i,e[52]=X):X=e[52];const ae=X,je=Zi();let le;e[53]===Symbol.for("react.memo_cache_sentinel")?(le=Je=>{if(typeof window>"u"||S.isVSCode)return;const Be=Zc(window.history.state);Be?.page===Je&&Be.stage==="page-content"||window.history.pushState({...iI(),[qg]:{page:Je,stage:"page-content"}},"",window.location.href)},e[53]=le):le=e[53];const Ne=le;let Me;e[54]!==f?(Me=()=>{x("page-content"),f==="skills.installed"&&Ne(f)},e[54]=f,e[55]=Me):Me=e[55];const Ve=Me;let we;e[56]!==Ie||e[57]!==f?(we=()=>{if(Ie){if((typeof window<"u"?Zc(window.history.state):null)?.page===f&&!S.isVSCode){window.history.back();return}x("page-sidebar");return}x("nav")},e[56]=Ie,e[57]=f,e[58]=we):we=e[58];const ee=we;let F,U;e[59]!==c||e[60]!==f?(F=()=>{if(!c||S.isVSCode)return;const Je=Be=>{if(f!=="skills.installed")return;if(Zc(Be.state)?.page==="skills.installed"){x("page-content");return}x(hI)};return window.addEventListener("popstate",Je),()=>{window.removeEventListener("popstate",Je)}},U=[c,S.isVSCode,f],e[59]=c,e[60]=f,e[61]=F,e[62]=U):(F=e[61],U=e[62]),l.useEffect(F,U);let oe;e[63]===Symbol.for("react.memo_cache_sentinel")?(oe=()=>{x("page-sidebar")},e[63]=oe):oe=e[63];const Te=oe;let Oe;e[64]!==he||e[65]!==Q||e[66]!==f||e[67]!==$||e[68]!==i?(Oe=()=>s.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden",children:s.jsx("div",{className:"flex flex-col gap-0.5 pt-4 pb-2 px-2",children:$.map(Je=>{const Be=f===Je.slug,nt=Nu(Je.slug);return nt?s.jsx(kt,{children:s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>Q(Je.slug),"aria-current":Be?"page":void 0,className:ye("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",Be?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[s.jsx(A,{name:nt,className:"h-4 w-4 shrink-0"}),s.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[s.jsx("span",{className:"typography-ui-label font-normal truncate",children:he(Je.slug)}),(Je.slug==="voice"||Je.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")})]})]})})},Je.slug):null})})}),s.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:s.jsx("div",{className:"border-t border-border bg-sidebar px-2 py-1 space-y-0.5",children:!S.isVSCode&&s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",className:ye("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:gI,children:[s.jsx(A,{name:"restart",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[64]=he,e[65]=Q,e[66]=f,e[67]=$,e[68]=i,e[69]=Oe):Oe=e[69];const Pe=Oe;let z;e[70]!==de||e[71]!==Ve||e[72]!==b||e[73]!==Y||e[74]!==Pe||e[75]!==f?(z=()=>{if(b==="nav")return s.jsx("div",{className:ye("flex-1 min-h-0 overflow-hidden",S.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(en,{children:Pe()})})});if(!de)return s.jsx("div",{className:"flex-1 bg-background"});if(b==="page-sidebar"){if(de.kind!=="split"){const Be=Y(f);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(en,{children:Be})})}return s.jsx("div",{className:ye("flex-1 min-h-0 overflow-hidden",S.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx(en,{children:se(f,{onItemSelect:Ve})})})}const Je=Y(f);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(en,{children:Je})})},e[70]=de,e[71]=Ve,e[72]=b,e[73]=Y,e[74]=Pe,e[75]=f,e[76]=z):z=e[76];const De=z;let Qe;e[77]!==de||e[78]!==Q||e[79]!==Y||e[80]!==f?(Qe=()=>!de||f==="home"?s.jsx(ed,{onOpen:Q}):de.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:ye("w-[264px] min-w-[264px] border-r",S.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:s.jsx(en,{children:se(f,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(en,{children:Y(f)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:s.jsx(en,{children:Y(f)})}),e[77]=de,e[78]=Q,e[79]=Y,e[80]=f,e[81]=Qe):Qe=e[81];const et=Qe,Ze="true";let We;e[82]===Symbol.for("react.memo_cache_sentinel")?(We=ye("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[82]=We):We=e[82];const it=c?s.jsxs("div",{className:ye("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:Ce?ee:n,"aria-label":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(A,{name:"arrow-left-s",className:"h-5 w-5"})}),s.jsx("div",{className:"min-w-0 flex-1 typography-ui-label font-medium text-foreground truncate",children:b==="nav"?i("settings.view.home.title"):de?he(de.slug):i("settings.view.home.title")}),ke&&s.jsx("button",{type:"button",onClick:Te,"aria-label":i("settings.view.actions.openSectionList"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(A,{name:"list-unordered",className:"h-5 w-5"})}),n&&s.jsx("button",{type:"button",onClick:n,"aria-label":i("settings.view.actions.closeSettings"),title:i("settings.view.actions.closeSettingsWithShortcut",{shortcut:je}),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(A,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[Ce&&s.jsx("div",{className:ye("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:ee,"aria-label":i("settings.view.actions.back"),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(A,{name:"arrow-left-s",className:"h-5 w-5"})})}),n&&s.jsx("div",{className:ye("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:je}),className:"inline-flex h-7 w-7 items-center justify-center rounded-md p-0.5 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(A,{name:"close",className:"h-5 w-5"})})})]});let qe;e[83]!==ie||e[84]!==me||e[85]!==c||e[86]!==C||e[87]!==g||e[88]!==et||e[89]!==De||e[90]!==Pe||e[91]!==i?(qe=s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?De():s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:ye("relative flex h-full min-h-0 flex-col overflow-hidden border-r",P?"bg-sidebar":S.isVSCode?"bg-background":"bg-sidebar",C?"":"transition-[width,min-width] duration-200 ease-[cubic-bezier(0.25,0.1,0.25,1)]"),style:{width:`${g}px`,minWidth:`${g}px`,borderColor:"var(--interactive-border)"},children:[s.jsx("div",{className:ye("absolute right-0 top-0 z-20 h-full w-[6px] -mr-[3px] cursor-col-resize","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",C?"bg-primary/30":"bg-transparent hover:bg-primary/20"),tabIndex:0,onPointerDown:ie,onKeyDown:me,role:"separator","aria-orientation":"vertical","aria-valuemin":$d,"aria-valuemax":_d,"aria-valuenow":g,"aria-label":i("settings.view.actions.resizeNavigation")}),s.jsx(en,{children:Pe()})]}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:et()})]})}),e[83]=ie,e[84]=me,e[85]=c,e[86]=C,e[87]=g,e[88]=et,e[89]=De,e[90]=Pe,e[91]=i,e[92]=qe):qe=e[92];let st;return e[93]!==We||e[94]!==it||e[95]!==qe?(st=s.jsxs("div",{ref:I,"data-settings-view":Ze,className:We,children:[it,qe]}),e[93]=We,e[94]=it,e[95]=qe,e[96]=st):st=e[96],st};function lI(t){return t.settingsPage}function cI(t){return t.isSettingsDialogOpen}function dI(t){return t.setSettingsPage}function uI(t){return t.slug!=="home"}function mI(t,e){return[t,e]}function pI(t){return t.activeProjectId}function fI(t,e){switch(t){case"projects":return s.jsx(b5,{onItemSelect:e.onItemSelect});case"remote-instances":return s.jsx(B5,{onItemSelect:e.onItemSelect});case"agents":return s.jsx(fk,{onItemSelect:e.onItemSelect});case"commands":return s.jsx(Ik,{onItemSelect:e.onItemSelect});case"mcp":return s.jsx(Ok,{onItemSelect:e.onItemSelect});case"plugins":return s.jsx(k3,{onItemSelect:e.onItemSelect});case"skills.installed":return s.jsx(_3,{onItemSelect:e.onItemSelect});case"providers":return s.jsx(sC,{onItemSelect:e.onItemSelect});case"usage":return s.jsx(cC,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(IC,{onItemSelect:e.onItemSelect});case"snippets":return s.jsx(TC,{onItemSelect:e.onItemSelect});default:return null}}function hI(t){return t==="page-content"?"page-sidebar":t}function gI(){xi({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]})}const xI=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:oI,getSettingsNavIcon:Nu},Symbol.toStringTag,{value:"Module"})),Vd=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},bI=()=>{const t=ot.c(162),{t:e}=ft(),n=Fe(yI),r=Fe(vI),a=Fe(wI),i=Fe(jI),o=Fe(NI),c=Fe(SI),d=Fe(kI),p=Fe(CI),m=Fe(II),u=Fe(PI),f=Fe(AI),b=Fe(DI),x=$t(TI),y=$t(EI),g=xa(MI),h=Ws(RI),j=Cs(FI),v=na(),C=tu(OI),{files:k,git:w}=_n(),N=Ys(LI),{isMobile:I}=ln();let T;t[0]!==v?(T=v?Vd(v):null,t[0]=v,t[1]=T):T=t[1];const P=T,[D,S]=l.useState(""),M=tc(D,200);let E;t[2]!==M?(E=M.trim(),t[2]=M,t[3]=E):E=t[3];const R=E;let V;t[4]!==D?(V=D.trim(),t[4]=D,t[5]=V):V=t[5];const B=V;let $,O;t[6]!==n?($=()=>{n&&S("")},O=[n],t[6]=n,t[7]=$,t[8]=O):($=t[7],O=t[8]),l.useEffect($,O);let _,q;t[9]!==g||t[10]!==N||t[11]!==w||t[12]!==n?(_=()=>{if(!n||!w)return;const Le=setTimeout(()=>{const ze=new Set;for(const Ke of g){const lt=eo(Ke);!lt||ze.has(lt)||(ze.add(lt),N(lt,w))}},0);return()=>clearTimeout(Le)},q=[n,g,w,N],t[9]=g,t[10]=N,t[11]=w,t[12]=n,t[13]=_,t[14]=q):(_=t[13],q=t[14]),l.useEffect(_,q);let L;t[15]!==r?(L=()=>r(!1),t[15]=r,t[16]=L):L=t[16];const J=L;let Z;t[17]!==J?(Z=Le=>()=>{J(),Le()},t[17]=J,t[18]=Z):Z=t[18];const ie=Z;let ne;t[19]!==j?.id||t[20]!==j?.path||t[21]!==h||t[22]!==I||t[23]!==u||t[24]!==x||t[25]!==ie||t[26]!==a||t[27]!==c||t[28]!==i||t[29]!==e||t[30]!==m||t[31]!==p||t[32]!==d?(ne=()=>{const Le=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(A,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:ie(()=>{a("chat"),c(!1),x()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(A,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:ie($I)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(A,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:ie(_I)},{id:"toggle-sidebar",title:e(I?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(A,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(I?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:ie(()=>{if(I){const{isSessionSwitcherOpen:ze}=Fe.getState();c(!ze)}else d()})},{id:"toggle-right-sidebar",title:e("commandPalette.item.toggleRightSidebar"),icon:s.jsx(A,{name:"layout-right",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_right_sidebar",searchText:e("commandPalette.item.toggleRightSidebar"),onSelect:ie(()=>p())},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(A,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:ie(()=>m())},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(A,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:ie(()=>{h&&u(h)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(A,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:ie(()=>i(!0))}];return qd()&&Le.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(A,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:ie(()=>{Pl("desktop_open_draft_mini_chat_window",{directory:Vd(h||j?.path||""),projectId:j?.id??null}).catch(BI)})}),Le},t[19]=j?.id,t[20]=j?.path,t[21]=h,t[22]=I,t[23]=u,t[24]=x,t[25]=ie,t[26]=a,t[27]=c,t[28]=i,t[29]=e,t[30]=m,t[31]=p,t[32]=d,t[33]=ne):ne=t[33],j?.id,j?.path;let me;t[34]!==ne?(me=ne(),t[34]=ne,t[35]=me):me=t[35];const pe=me;let G;t[36]===Symbol.for("react.memo_cache_sentinel")?(G=jn(),t[36]=G):G=t[36];const K=G;let Q;t[37]===Symbol.for("react.memo_cache_sentinel")?(Q={isVSCode:fn(),isWeb:!K&&ea(),isDesktop:K},t[37]=Q):Q=t[37];const W=Q;let de;if(t[38]!==ie||t[39]!==i||t[40]!==o){let Le;t[42]===Symbol.for("react.memo_cache_sentinel")?(Le=ze=>ze.isAvailable?ze.isAvailable(W):!0,t[42]=Le):Le=t[42],de=xu.filter(VI).filter(Le).map(ze=>{const Ke=Nu(ze.slug)??"settings-3",lt=(ze.keywords??[]).join(" ");return{id:`settings:${ze.slug}`,title:ze.title,icon:s.jsx(A,{name:Ke,className:"mr-2 h-4 w-4"}),searchText:`${ze.title} ${ze.group} ${lt}`,onSelect:ie(()=>{o(ze.slug),i(!0)})}}),t[38]=ie,t[39]=i,t[40]=o,t[41]=de}else de=t[41];const ge=de,ve=zI;let te;if(t[43]!==g){let Le;t[45]===Symbol.for("react.memo_cache_sentinel")?(Le=(ze,Ke)=>ve(Ke)-ve(ze),t[45]=Le):Le=t[45],te=[...g].sort(Le),t[43]=g,t[44]=te}else te=t[44];const he=te,ce=Ah(),xe=$t(UI);let se;t[46]!==ce||t[47]!==xe?(se=(Le,ze)=>{const Ke=xe.get(Le);return Ke?.branch?Ke.branch.trim()||null:ze&&ce.get(ze)?.trim()||null},t[46]=ce,t[47]=xe,t[48]=se):se=t[48];const ue=se;let Y;t[49]===Symbol.for("react.memo_cache_sentinel")?(Y=[],t[49]=Y):Y=t[49];const[Se,fe]=l.useState(Y),[Ce,Ie]=l.useState(!1);let ke,X;t[50]!==P||t[51]!==n||t[52]!==C||t[53]!==R?(ke=()=>{if(!n){fe([]),Ie(!1);return}if(!P||R.length===0){fe([]),Ie(!1);return}let Le=!1;return Ie(!0),C(P,R,10,{type:"file"}).then(ze=>{Le||fe(ze.map(WI))}).catch(()=>{Le||fe([])}).finally(()=>{Le||Ie(!1)}),()=>{Le=!0}},X=[n,P,R,C],t[50]=P,t[51]=n,t[52]=C,t[53]=R,t[54]=ke,t[55]=X):(ke=t[54],X=t[55]),l.useEffect(ke,X);const ae=B.length>0;let je;e:{if(!ae){let ze;t[56]!==pe?(ze=pe.map(KI),t[56]=pe,t[57]=ze):ze=t[57],je=ze;break e}let Le;t[58]!==pe||t[59]!==B?(Le=Mo(pe,B,HI,{limit:7,noFuzzy:!0}),t[58]=pe,t[59]=B,t[60]=Le):Le=t[60],je=Le}const le=je;let Ne;e:{if(!ae){let ze;t[61]===Symbol.for("react.memo_cache_sentinel")?(ze=[],t[61]=ze):ze=t[61],Ne=ze;break e}let Le;t[62]!==B||t[63]!==ge?(Le=Mo(ge,B,GI,{limit:7,noFuzzy:!0}),t[62]=B,t[63]=ge,t[64]=Le):Le=t[64],Ne=Le}const Me=Ne;let Ve;e:{if(!ae){let ze;t[65]!==he?(ze=he.slice(0,5).map(qI),t[65]=he,t[66]=ze):ze=t[66],Ve=ze;break e}let Le;t[67]!==B||t[68]!==he?(Le=Mo(he,B,JI,{limit:7,threshold:.2}),t[67]=B,t[68]=he,t[69]=Le):Le=t[69],Ve=Le}const we=Ve;let ee;e:{if(!ae||Se.length===0){let ze;t[70]===Symbol.for("react.memo_cache_sentinel")?(ze=[],t[70]=ze):ze=t[70],ee=ze;break e}let Le;t[71]!==Se||t[72]!==B?(Le=Mo(Se,B,YI,{limit:10,threshold:.4}),t[71]=Se,t[72]=B,t[73]=Le):Le=t[73],ee=Le}const F=ee;let U,oe,Te,Oe,Pe,z,De,Qe,et,Ze,We,it,qe,st,Je;if(t[74]!==ue||t[75]!==J||t[76]!==P||t[77]!==k||t[78]!==ae||t[79]!==n||t[80]!==f||t[81]!==D||t[82]!==le||t[83]!==F||t[84]!==we||t[85]!==Me||t[86]!==r||t[87]!==y||t[88]!==b||t[89]!==e){const Le=le.map(QI),ze=Me.map(XI),Ke=we.map(ZI);Je=ae?F.map(e6):[];let lt;e:{if(!ae){lt=["commands","sessions"];break e}const Ut=t6,Ye=[{key:"commands",score:Ut(le)},{key:"settings",score:Ut(Me)},{key:"sessions",score:Ut(we)},{key:"files",score:Ut(F)}];Ye.sort(s6),lt=Ye.map(n6)}const xt=lt;let dt;t[105]!==J||t[106]!==y?(dt=Ut=>{J(),y(Ut.id,eo(Ut))},t[105]=J,t[106]=y,t[107]=dt):dt=t[107];const ut=dt;let Nt;t[108]!==J||t[109]!==P||t[110]!==k||t[111]!==f?(Nt=async Ut=>{if(!P)return;const Ye=await hu(k,Ut);if(!Ye.ok){H.error(gu(Ye.reason));return}f(P,Ut),J()},t[108]=J,t[109]=P,t[110]=k,t[111]=f,t[112]=Nt):Nt=t[112];const ts=Nt;let Vt;t[113]!==b?(Vt=Ut=>Yl(Xr(Ut,b)),t[113]=b,t[114]=Vt):Vt=t[114];const Xt=Vt;Oe=us,it=n,qe=r;let ht;t[115]!==e?(ht=e("commandPalette.title"),t[115]=e,t[116]=ht):ht=t[116];let Bt;t[117]!==ht?(Bt=s.jsx(ms,{children:ht}),t[117]=ht,t[118]=Bt):Bt=t[118];let Zt;t[119]!==e?(Zt=e("commandPalette.description"),t[119]=e,t[120]=Zt):Zt=t[120];let gs;t[121]!==Zt?(gs=s.jsx(Ns,{children:Zt}),t[121]=Zt,t[122]=gs):gs=t[122],t[123]!==Bt||t[124]!==gs?(st=s.jsxs(hs,{className:"sr-only",children:[Bt,gs]}),t[123]=Bt,t[124]=gs,t[125]=st):st=t[125],Te=ds,Ze="overflow-hidden p-0",We=!0,oe=qa,De=!1,Qe="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta";let rs;t[126]!==e?(rs=e("commandPalette.input.placeholder"),t[126]=e,t[127]=rs):rs=t[127],t[128]!==D||t[129]!==rs?(et=s.jsx(va,{value:D,onValueChange:S,placeholder:rs}),t[128]=D,t[129]=rs,t[130]=et):et=t[130],U=Ja;let ps;t[131]!==e?(ps=e("commandPalette.empty.noResults"),t[131]=e,t[132]=ps):ps=t[132],t[133]!==ps?(Pe=s.jsx(Ya,{children:ps}),t[133]=ps,t[134]=Pe):Pe=t[134],z=xt.map(Ut=>Ut==="commands"&&Le.length>0?s.jsx(On,{children:Le.map(Ye=>s.jsxs(Pn,{value:Ye.id,onSelect:Ye.onSelect,children:[Ye.icon,s.jsx("span",{children:Ye.title}),Ye.shortcutId?s.jsx(tj,{children:Xt(Ye.shortcutId)}):null]},Ye.id))},"commands"):Ut==="settings"&&ze.length>0?s.jsx(On,{children:ze.map(r6)},"settings"):Ut==="sessions"&&Ke.length>0?s.jsx(On,{children:Ke.map(Ye=>{const Tt=Ye.title||e("commandPalette.session.untitled"),Kt=eo(Ye),St=ue(Ye.id,Kt);return s.jsxs(Pn,{value:`session:${Ye.id}`,onSelect:()=>ut(Ye),children:[s.jsx(A,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:Tt}),St?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:St})]}):null]},Ye.id)})},"sessions"):Ut==="files"&&Je.length>0?s.jsx(On,{children:Je.map(Ye=>{const Tt=My(Ye.relativePath||Ye.name,{maxLength:80});return s.jsxs(Pn,{value:`file:${Ye.path}`,onSelect:()=>{ts(Ye.path)},children:[s.jsx(Ar,{filePath:Ye.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":Ye.relativePath,children:Tt})]},`file:${Ye.path}`)})},"files"):null),t[74]=ue,t[75]=J,t[76]=P,t[77]=k,t[78]=ae,t[79]=n,t[80]=f,t[81]=D,t[82]=le,t[83]=F,t[84]=we,t[85]=Me,t[86]=r,t[87]=y,t[88]=b,t[89]=e,t[90]=U,t[91]=oe,t[92]=Te,t[93]=Oe,t[94]=Pe,t[95]=z,t[96]=De,t[97]=Qe,t[98]=et,t[99]=Ze,t[100]=We,t[101]=it,t[102]=qe,t[103]=st,t[104]=Je}else U=t[90],oe=t[91],Te=t[92],Oe=t[93],Pe=t[94],z=t[95],De=t[96],Qe=t[97],et=t[98],Ze=t[99],We=t[100],it=t[101],qe=t[102],st=t[103],Je=t[104];let Be;t[135]!==ae||t[136]!==Ce||t[137]!==e||t[138]!==Je?(Be=ae&&Ce&&Je.length===0?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[135]=ae,t[136]=Ce,t[137]=e,t[138]=Je,t[139]=Be):Be=t[139];let nt;t[140]!==U||t[141]!==Pe||t[142]!==z||t[143]!==Be?(nt=s.jsxs(U,{children:[Pe,z,Be]}),t[140]=U,t[141]=Pe,t[142]=z,t[143]=Be,t[144]=nt):nt=t[144];let Ge;t[145]!==oe||t[146]!==De||t[147]!==Qe||t[148]!==et||t[149]!==nt?(Ge=s.jsxs(oe,{shouldFilter:De,className:Qe,children:[et,nt]}),t[145]=oe,t[146]=De,t[147]=Qe,t[148]=et,t[149]=nt,t[150]=Ge):Ge=t[150];let at;t[151]!==Te||t[152]!==Ze||t[153]!==We||t[154]!==Ge?(at=s.jsx(Te,{className:Ze,showCloseButton:We,children:Ge}),t[151]=Te,t[152]=Ze,t[153]=We,t[154]=Ge,t[155]=at):at=t[155];let Ae;return t[156]!==Oe||t[157]!==it||t[158]!==qe||t[159]!==st||t[160]!==at?(Ae=s.jsxs(Oe,{open:it,onOpenChange:qe,children:[st,at]}),t[156]=Oe,t[157]=it,t[158]=qe,t[159]=st,t[160]=at,t[161]=Ae):Ae=t[161],Ae};function yI(t){return t.isCommandPaletteOpen}function vI(t){return t.setCommandPaletteOpen}function wI(t){return t.setActiveMainTab}function jI(t){return t.setSettingsDialogOpen}function NI(t){return t.setSettingsPage}function SI(t){return t.setSessionSwitcherOpen}function kI(t){return t.toggleSidebar}function CI(t){return t.toggleRightSidebar}function II(t){return t.toggleBottomTerminal}function PI(t){return t.openContextOverview}function AI(t){return t.openContextFile}function DI(t){return t.shortcutOverrides}function TI(t){return t.openNewSessionDraft}function EI(t){return t.setCurrentSession}function MI(t){return t.activeSessions}function RI(t){return t.currentDirectory}function FI(t){return t.getActiveProject()}function OI(t){return t.searchFiles}function LI(t){return t.ensureStatus}function $I(){Dh()}function _I(){Dr.requestDirectoryDialog()}function BI(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function VI(t){return t.slug!=="home"}function zI(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function UI(t){return t.worktreeMetadata}function WI(t){return{path:Vd(t.path),name:t.name,relativePath:t.relativePath}}function KI(t){return{item:t,score:0}}function HI(t){return t.searchText}function GI(t){return t.searchText}function qI(t){return{item:t,score:0}}function JI(t){return t.title||""}function YI(t){return t.name}function QI(t){return t.item}function XI(t){return t.item}function ZI(t){return t.item}function e6(t){return t.item}function t6(t){return t.length?t[0].score:1/0}function s6(t,e){return t.score-e.score}function n6(t){return t.key}function r6(t){return s.jsxs(Pn,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const xf=(t,e,n)=>Fy(t)?Yl(Xr(t,n)):e,a6=()=>{const t=ot.c(68),{t:e}=ft(),n=Fe(i6),r=Fe(o6),a=Fe(l6);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=Ry(),t[0]=i):i=t[0];const o=i;let c,d,p,m,u,f,b,x,y;if(t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==e){const R=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${o} + N`],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_right_sidebar",descriptionKey:"helpDialog.item.toggleRightSidebar",icon:"layout-right",keys:""},{id:"open_right_sidebar_git",descriptionKey:"helpDialog.item.openRightSidebarGitTab",icon:"git-branch",keys:""},{id:"open_right_sidebar_files",descriptionKey:"helpDialog.item.openRightSidebarFilesTab",icon:"layout-right",keys:""},{id:"cycle_right_sidebar_tab",descriptionKey:"helpDialog.item.cycleRightSidebarTab",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{id:"toggle_context_plan",descriptionKey:"helpDialog.item.togglePlanContextPanel",icon:"time",keys:""}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{keys:[`${o} + 1...9`],descriptionKey:"helpDialog.item.switchProject",icon:"layout-left"},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];d=us,x=n,y=r,c=ds,f="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let V;t[14]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(A,{name:"settings-3",className:"h-5 w-5"}),t[14]=V):V=t[14];let B;t[15]!==e?(B=e("helpDialog.title"),t[15]=e,t[16]=B):B=t[16];let $;t[17]!==B?($=s.jsxs(ms,{className:"flex items-center gap-2",children:[V,B]}),t[17]=B,t[18]=$):$=t[18];let O;t[19]!==e?(O=e("helpDialog.description"),t[19]=e,t[20]=O):O=t[20];let _;t[21]!==O?(_=s.jsx(Ns,{children:O}),t[21]=O,t[22]=_):_=t[22],t[23]!==$||t[24]!==_?(b=s.jsxs(hs,{children:[$,_]}),t[23]=$,t[24]=_,t[25]=b):b=t[25],u="flex-1 overflow-y-auto mt-3 pr-1",p="space-y-4",m=R.map(q=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(q.categoryKey)}),s.jsx("div",{className:"space-y-1",children:q.items.map(L=>{const J=L.id?xf(L.id,Array.isArray(L.keys)?L.keys[0]:L.keys,a):Array.isArray(L.keys)?L.keys:L.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:[L.icon&&s.jsx(A,{name:L.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(L.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(J)?J:[J]).map((Z,ie)=>s.jsxs(l.Fragment,{children:[ie>0&&s.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:e("helpDialog.keyCombiner.or")}),s.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:Z})]},`${Z}-${ie}`))})]},L.id||L.descriptionKey)})})]},q.categoryKey)),t[1]=n,t[2]=r,t[3]=a,t[4]=e,t[5]=c,t[6]=d,t[7]=p,t[8]=m,t[9]=u,t[10]=f,t[11]=b,t[12]=x,t[13]=y}else c=t[5],d=t[6],p=t[7],m=t[8],u=t[9],f=t[10],b=t[11],x=t[12],y=t[13];let g;t[26]!==p||t[27]!==m?(g=s.jsx("div",{className:p,children:m}),t[26]=p,t[27]=m,t[28]=g):g=t[28];let h;t[29]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(A,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[29]=h):h=t[29];let j;t[30]!==e?(j=e("helpDialog.proTips.title"),t[30]=e,t[31]=j):j=t[31];let v;t[32]!==j?(v=s.jsx("p",{className:"font-medium mb-1",children:j}),t[32]=j,t[33]=v):v=t[33];let C;t[34]!==a||t[35]!==e?(C=e("helpDialog.proTips.commandPalette",{shortcut:xf("open_command_palette",`${o} P`,a)}),t[34]=a,t[35]=e,t[36]=C):C=t[36];let k;t[37]!==C?(k=s.jsxs("li",{children:["• ",C]}),t[37]=C,t[38]=k):k=t[38];let w;t[39]!==e?(w=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=w):w=t[40];let N;t[41]!==w?(N=s.jsxs("li",{children:["• ",w]}),t[41]=w,t[42]=N):N=t[42];let I;t[43]!==e?(I=e("helpDialog.proTips.themeCycling"),t[43]=e,t[44]=I):I=t[44];let T;t[45]!==I?(T=s.jsxs("li",{children:["• ",I]}),t[45]=I,t[46]=T):T=t[46];let P;t[47]!==k||t[48]!==N||t[49]!==T?(P=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[k,N,T]}),t[47]=k,t[48]=N,t[49]=T,t[50]=P):P=t[50];let D;t[51]!==v||t[52]!==P?(D=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[h,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[v,P]})]})}),t[51]=v,t[52]=P,t[53]=D):D=t[53];let S;t[54]!==D||t[55]!==u||t[56]!==g?(S=s.jsxs("div",{className:u,children:[g,D]}),t[54]=D,t[55]=u,t[56]=g,t[57]=S):S=t[57];let M;t[58]!==c||t[59]!==S||t[60]!==f||t[61]!==b?(M=s.jsxs(c,{className:f,children:[b,S]}),t[58]=c,t[59]=S,t[60]=f,t[61]=b,t[62]=M):M=t[62];let E;return t[63]!==d||t[64]!==M||t[65]!==x||t[66]!==y?(E=s.jsx(d,{open:x,onOpenChange:y,children:M}),t[63]=d,t[64]=M,t[65]=x,t[66]=y,t[67]=E):E=t[67],E};function i6(t){return t.isHelpDialogOpen}function o6(t){return t.setHelpDialogOpen}function l6(t){return t.shortcutOverrides}const c6=()=>{const t=ot.c(32),{t:e}=ft(),n=Fe(d6),r=Fe(u6),a=Fe(m6);let i;t[0]!==a||t[1]!==e?(i=async()=>{if(!a)return;if((await En(a)).ok){H.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}H.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(ms,{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(Ns,{children:p}),t[9]=p,t[10]=m):m=t[10];let u;t[11]!==d||t[12]!==m?(u=s.jsxs(hs,{children:[d,m]}),t[11]=d,t[12]=m,t[13]=u):u=t[13];let f;t[14]!==e?(f=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=f):f=t[15];let b;t[16]!==o||t[17]!==f?(b=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:o,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:f})}),t[16]=o,t[17]=f,t[18]=b):b=t[18];let x;t[19]!==a||t[20]!==e?(x=a||e("openCodeStatusDialog.empty.noData"),t[19]=a,t[20]=e,t[21]=x):x=t[21];let y;t[22]!==x?(y=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:x}),t[22]=x,t[23]=y):y=t[23];let g;t[24]!==u||t[25]!==b||t[26]!==y?(g=s.jsxs(ds,{className:"max-w-2xl",children:[u,b,y]}),t[24]=u,t[25]=b,t[26]=y,t[27]=g):g=t[27];let h;return t[28]!==n||t[29]!==r||t[30]!==g?(h=s.jsx(us,{open:n,onOpenChange:r,children:g}),t[28]=n,t[29]=r,t[30]=g,t[31]=h):h=t[31],h};function d6(t){return t.isOpenCodeStatusDialogOpen}function u6(t){return t.setOpenCodeStatusDialogOpen}function m6(t){return t.openCodeStatusText}const p6=180,bf=600,f6=1,h6=6,g6=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],ensureSessionRenderable:r})=>{const a=l.useRef(new Map),i=l.useRef([]),o=l.useRef(new Set),c=l.useMemo(()=>fn(),[]),d=l.useCallback(()=>{if(!(c||typeof window>"u"))for(;o.current.size<f6&&i.current.length>0;){const m=i.current.shift();if(!m)break;$t.getState().currentSessionId!==m&&(tm(m).renderable||(o.current.add(m),r(m).catch(()=>{}).finally(()=>{o.current.delete(m),d()})))}},[r,c]),p=l.useCallback(m=>{if(c||!m||m===t||typeof window>"u"||tm(m).renderable||o.current.has(m)||i.current.includes(m))return;i.current.length>=h6&&i.current.shift();const u=a.current.get(m);u!==void 0&&window.clearTimeout(u);const f=window.setTimeout(()=>{a.current.delete(m),i.current.push(m),d()},p6);a.current.set(m,f)},[t,c,d]);l.useEffect(()=>{if(c||!t||e.length===0)return;const m=window.setTimeout(()=>{const u=e.findIndex(f=>f.id===t);u<0||(p(e[u-1]?.id),p(e[u+1]?.id))},bf);return()=>window.clearTimeout(m)},[t,c,p,e]),l.useEffect(()=>{if(c||!t||n.length===0)return;const m=window.setTimeout(()=>{const u=n.indexOf(t);u<0||(p(n[u-1]),p(n[u+1]))},bf);return()=>window.clearTimeout(m)},[t,c,n,p]),l.useEffect(()=>{const m=a.current;return()=>{m.forEach(u=>{clearTimeout(u)}),m.clear(),i.current=[]}},[])};function yf(t){const{localBranches:e,remoteBranches:n,query:r}=t,a=r.trim();if(!a)return{matching:[],otherLocal:e,otherRemote:n};const i=sm(e,a,m=>m),o=sm(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 x6({open:t,onOpenChange:e,onSelect:n}){const{t:r}=ft(),a=Fe(ce=>ce.isMobile),{github:i}=_n(),o=Hn(ce=>ce.status),c=Hn(ce=>ce.hasChecked),d=Fe(ce=>ce.setSettingsDialogOpen),p=Fe(ce=>ce.setSettingsPage),m=Cs(ce=>ce.getActiveProject()),u=m?.path??null,f=_e.useMemo(()=>u&&m?{id:m.id,path:u}:null,[m,u]),[b,x]=_e.useState("issues"),[y,g]=_e.useState(""),[h,j]=_e.useState([]),[v,C]=_e.useState([]),[k,w]=_e.useState(!1),[N,I]=_e.useState(!1),[T,P]=_e.useState(null),[D,S]=_e.useState(null),[M,E]=_e.useState(null),[R,V]=_e.useState(!1),[B,$]=_e.useState(new Map),[O,_]=_e.useState(1),[q,L]=_e.useState(!1),J=_e.useCallback(async()=>{if(!(!u||!i)&&!(c&&o?.connected===!1)){w(!0),P(null),_(1),L(!1);try{if(b==="issues"&&i.issuesList){const ce=await i.issuesList(u,{page:1});ce.connected===!1?(P(r("session.githubIntegration.error.notConnected")),j([])):(j(ce.issues??[]),_(ce.page??1),L(!!ce.hasMore))}else if(b==="prs"&&i.prsList){const ce=await i.prsList(u,{page:1});ce.connected===!1?(P(r("session.githubIntegration.error.notConnected")),C([])):(C(ce.prs??[]),_(ce.page??1),L(!!ce.hasMore))}}catch(ce){P(ce instanceof Error?ce.message:r("session.githubIntegration.error.loadDataFailed"))}finally{w(!1)}}},[u,i,c,o,b,r]),Z=_e.useCallback(async()=>{if(!(!u||!i)&&!(k||N)&&q){I(!0);try{const ce=O+1;if(b==="issues"&&i.issuesList){const xe=await i.issuesList(u,{page:ce});xe.connected!==!1&&(j(se=>[...se,...xe.issues??[]]),_(xe.page??ce),L(!!xe.hasMore))}else if(b==="prs"&&i.prsList){const xe=await i.prsList(u,{page:ce});xe.connected!==!1&&(C(se=>[...se,...xe.prs??[]]),_(xe.page??ce),L(!!xe.hasMore))}}catch{}finally{I(!1)}}},[u,i,b,O,q,k,N]);_e.useEffect(()=>{if(!t){x("issues"),g(""),j([]),C([]),S(null),E(null),V(!1),P(null),$(new Map),_(1),L(!1);return}J()},[t,J]);const ie=_e.useCallback(async ce=>{if(!(!f||!ce)&&!B.has(ce))try{const se=(await Th(f,{mode:"new",branchName:ce,worktreeName:ce})).errors.find(ue=>ue.code==="branch_in_use");$(ue=>new Map(ue).set(ce,{isValid:!se,error:se?r(se.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{$(xe=>new Map(xe).set(ce,{isValid:!1,error:r("session.githubIntegration.validation.failed")}))}},[f,B,r]);_e.useEffect(()=>{!t||b!=="prs"||v.forEach(ce=>{ce.head&&ie(ce.head)})},[t,b,v,ie]);const ne=_e.useMemo(()=>{const ce=y.trim().toLowerCase();return ce?h.filter(xe=>String(xe.number)===ce.replace(/^#/,"")?!0:xe.title.toLowerCase().includes(ce)):h},[h,y]),me=_e.useMemo(()=>{const ce=y.trim().toLowerCase();return ce?v.filter(xe=>String(xe.number)===ce.replace(/^#/,"")?!0:xe.title.toLowerCase().includes(ce)):v},[v,y]),pe=c&&o?.connected===!0,G=()=>{p("github"),d(!0)},K=ce=>{S(ce),E(null)},Q=ce=>{E(ce),S(null)},W=()=>{D?n({type:"issue",item:D}):M&&n({type:"pr",item:M,includeDiff:R}),e(!1)},de=()=>{S(null),E(null),V(!1)},ge=D||M&&B.get(M.head??"")?.isValid!==!1,ve=ce=>ce.head?B.get(ce.head)?.isValid===!1:!0,te=s.jsx(s.Fragment,{children:pe?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"relative mt-2",children:[s.jsx(A,{name:"search",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),s.jsx(Lt,{value:y,onChange:ce=>g(ce.target.value),placeholder:r(b==="issues"?"session.githubIntegration.search.issuesPlaceholder":"session.githubIntegration.search.prsPlaceholder"),className:"h-8 pl-9"})]}),s.jsx("div",{className:"mt-2 h-[300px] overflow-hidden",children:s.jsxs("div",{className:"h-full overflow-y-auto",children:[k&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx(A,{name:"loader-4",className:"h-5 w-5 animate-spin text-muted-foreground"})}),T&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive",children:[s.jsx(A,{name:"error-warning",className:"h-4 w-4"}),s.jsx("span",{className:"typography-small",children:T})]})}),!k&&!T&&b==="issues"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[ne.length>0?ne.map(ce=>s.jsx("button",{onClick:()=>K(ce),className:ye("w-full text-left px-2 py-1.5 rounded transition-colors",D?.number===ce.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:["#",ce.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-2",children:ce.title}),ce.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:[ce.sourceRepo.owner,"/",ce.sourceRepo.repo]}):null]})]})},`${ce.sourceRepo?.owner??""}-${ce.sourceRepo?.repo??""}-${ce.number}`)):s.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:r("session.githubIntegration.empty.noIssuesFound")}),q&&!N&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{Z()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),N&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),!k&&!T&&b==="prs"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[me.length>0?me.map(ce=>{const xe=ve(ce),se=ce.head?B.get(ce.head):void 0;return s.jsx("button",{onClick:()=>!xe&&Q(ce),disabled:xe,className:ye("w-full text-left px-2 py-1.5 rounded transition-colors",M?.number===ce.number?"bg-interactive-selection text-interactive-selection-foreground":xe?"opacity-50 cursor-not-allowed":"hover:bg-interactive-hover"),children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("span",{className:"text-muted-foreground shrink-0 typography-micro",children:["#",ce.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-1",children:ce.title}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[ce.head," → ",ce.base]}),ce.sourceRepo?.source==="upstream"?s.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[ce.sourceRepo.owner,"/",ce.sourceRepo.repo]}):null,xe&&se?.error&&s.jsx("span",{className:"typography-micro text-destructive",children:se.error})]})]})]})},`${ce.sourceRepo?.owner??""}-${ce.sourceRepo?.repo??""}-${ce.number}`)}):s.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:r("session.githubIntegration.empty.noPullRequestsFound")}),q&&!N&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{Z()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),N&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]})]})})]}):s.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 gap-4",children:[s.jsx(A,{name:"github",className:"h-12 w-12 text-muted-foreground"}),s.jsxs("div",{className:"text-center",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:r("session.githubIntegration.connect.title")}),s.jsx("p",{className:"typography-small text-muted-foreground mt-1",children:r("session.githubIntegration.connect.description")})]}),s.jsx(be,{onClick:G,size:"sm",children:r("session.githubIntegration.connect.action")})]})}),he=s.jsxs("div",{className:ye("w-full",a?"flex flex-col gap-2":"flex flex-row items-center"),children:[s.jsxs("div",{className:ye("flex items-center gap-4",a?"w-full justify-center order-1":"flex-1"),children:[!a&&(D||M)&&s.jsxs("div",{className:"flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50",children:[s.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate max-w-[150px]",children:D?r("session.githubIntegration.selected.issueNumber",{number:D.number}):r("session.githubIntegration.selected.prNumber",{number:M?.number??""})}),s.jsx("button",{onClick:de,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]}),b==="prs"&&M&&s.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[s.jsx(vs,{checked:R,onChange:ce=>V(ce),ariaLabel:r("session.githubIntegration.includeDiffAria")}),s.jsx("span",{className:"typography-small text-foreground",children:r("session.githubIntegration.includeDiff")})]})]}),s.jsxs("div",{className:ye("flex gap-2",a?"w-full order-2":"justify-end"),children:[s.jsx(be,{variant:"outline",size:"sm",onClick:()=>e(!1),className:ye(a&&"flex-1"),children:r("session.githubIntegration.actions.cancel")}),s.jsx(be,{size:"sm",onClick:W,disabled:!ge,className:ye(a&&"flex-1"),children:r("session.githubIntegration.actions.select")})]})]});return s.jsx(s.Fragment,{children:a?s.jsx(zr,{open:t,title:r("session.githubIntegration.title"),onClose:()=>e(!1),footer:pe?he:void 0,renderHeader:ce=>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")}),ce]}),s.jsx("div",{className:"w-full",children:s.jsx(Er,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(A,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:xe=>{x(xe),g("")},variant:"active-pill",layoutMode:"fit"})}),(D||M)&&s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50",children:[s.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate flex-1",children:D?r("session.githubIntegration.selected.issueNumber",{number:D.number}):r("session.githubIntegration.selected.prNumber",{number:M?.number??""})}),s.jsx("button",{onClick:de,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]}),children:te}):s.jsx(us,{open:t,onOpenChange:e,children:s.jsxs(ds,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsx(hs,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(ms,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(A,{name:"github",className:"h-5 w-5"}),r("session.githubIntegration.title")]}),s.jsx("div",{className:"w-[220px]",children:s.jsx(Er,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(A,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:ce=>{x(ce),g("")},variant:"active-pill",layoutMode:"fit"})})]})}),te,s.jsx(_s,{className:"mt-1",children:he})]})})})}const Xi=t=>t.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),Rn=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),vf="oc:lastWorktreeSourceBranch",b6=t=>String(t).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",wf=(t,e,n)=>{const r=Xi(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-${b6(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}`}},y6=t=>{const e={repo:t.repo??null,issue:t.issue,comments:t.comments};return`GitHub issue context (JSON)
|
|
183
|
-
${JSON.stringify(e,null,2)}`},v6=t=>`GitHub pull request context (JSON)
|
|
184
|
-
${JSON.stringify(t,null,2)}`;function w6({open:t,onOpenChange:e,onWorktreeCreated:n}){const{t:r}=ft(),{github:a,git:i}=_n(),o=Fe(z=>z.isMobile),c=Hn(z=>z.status),d=Hn(z=>z.hasChecked),p=Cs(z=>z.getActiveProject()),m=p?.path??null,u=_e.useMemo(()=>m&&p?{id:p.id,path:m}:null,[p,m]),[f,b]=_e.useState("new-branch"),[x,y]=_e.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[g,h]=_e.useState({selectedBranch:"",worktreeName:""}),j=Xd(m),v=Eh(m),C=Ys(z=>z.fetchBranches),k=_e.useMemo(()=>j?.all?j.all.filter(z=>!z.startsWith("remotes/")).sort():[],[j]),w=_e.useMemo(()=>j?.all?j.all.filter(z=>z.startsWith("remotes/")).map(z=>z.replace(/^remotes\//,"")).sort():[],[j]),N=$t(z=>z.availableWorktreesByProject),I=_e.useMemo(()=>{if(!m)return new Set;const z=N.get(m)??[];return new Set(z.map(De=>De.name))},[N,m]),T=_e.useCallback((z=10)=>{for(let De=0;De<z;De++){const Qe=yc();if(!I.has(Qe))return Qe}return`${yc()}-${Date.now().toString(36).slice(-4)}`},[I]),[P,D]=_e.useState(!1),[S,M]=_e.useState(!1),[E,R]=_e.useState(!1),[V,B]=_e.useState(!1),[$,O]=_e.useState(!1),[_,q]=_e.useState(""),[L,J]=_e.useState(""),Z=_e.useRef(null),ie=_e.useRef(null),ne=_e.useRef(null),me=_e.useRef(null),pe=_e.useCallback(z=>{z.stopPropagation()},[]),G=_e.useCallback(z=>{let De=z;for(;De&&De!==document.body;){const{overflowY:Qe}=window.getComputedStyle(De);if((Qe==="auto"||Qe==="scroll")&&De.scrollHeight>De.clientHeight)return De;De=De.parentElement}return null},[]),K=_e.useCallback(z=>{z&&(z.scrollTop=0)},[]),Q=_e.useCallback(z=>{const De=z.current?.querySelector('[data-slot="command-list"]')??null;K(De)},[K]),W=_e.useCallback(z=>{const De=G(z.current);K(De)},[G,K]),de=_e.useMemo(()=>yf({localBranches:k,remoteBranches:w,query:_}),[k,w,_]),ge=_e.useMemo(()=>yf({localBranches:k,remoteBranches:w,query:L}),[k,w,L]),ve=_.trim().length>0,te=L.trim().length>0,he=de.matching.length>0,ce=ge.matching.length>0,xe=!!(m&&i),se=_e.useCallback(()=>{!m||!i||C(m,i)},[m,i,C]);_e.useEffect(()=>{!S&&!V&&q("")},[S,V]),_e.useEffect(()=>{!E&&!$&&J("")},[E,$]),_e.useEffect(()=>{S&&Q(Z),V&&W(ne)},[S,V,_,Q,W]),_e.useEffect(()=>{E&&Q(ie),$&&W(me)},[E,$,L,Q,W]);const[ue,Y]=_e.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[Se,fe]=_e.useState(!1),[Ce,Ie]=_e.useState(null),ke=_e.useCallback(()=>{const z=wt.getState(),De=z.getVisibleAgents();if(z.settingsDefaultAgent){const Qe=De.find(et=>et.name===z.settingsDefaultAgent);if(Qe)return Qe.name}return De.find(Qe=>Qe.name==="build")?.name||De[0]?.name},[]),X=_e.useCallback(()=>{const z=wt.getState(),De=z.settingsDefaultModel;if(!De)return null;const Qe=Ii(De);if(!Qe)return null;const{providerId:et,modelId:Ze}=Qe;return z.getModelMetadata(et,Ze)?{providerID:et,modelID:Ze}:null},[]),ae=_e.useCallback((z,De)=>{const Qe=wt.getState(),et=Qe.settingsDefaultVariant;if(!et)return;const it=Qe.providers.find(qe=>qe.id===z)?.models.find(qe=>qe.id===De)?.variants;if(it&&Object.prototype.hasOwnProperty.call(it,et))return et},[]),je=_e.useCallback(z=>{const De=wt.getState();try{Ro.getState().saveSessionModelSelection(z.sessionId,z.providerID,z.modelID)}catch{}if(z.agentName){try{De.setAgent(z.agentName)}catch{}try{Ro.getState().saveSessionAgentSelection(z.sessionId,z.agentName)}catch{}try{Ro.getState().saveAgentModelForSession(z.sessionId,z.agentName,z.providerID,z.modelID)}catch{}if(z.variant!==void 0){try{De.setCurrentVariant(z.variant)}catch{}try{Ro.getState().saveAgentModelVariantForSession(z.sessionId,z.agentName,z.providerID,z.modelID,z.variant)}catch{}}}},[]),le=_e.useCallback(async z=>{if(!m||!a)return;const De=wt.getState(),Qe=Ql.getState().lastUsedProvider,et=X(),Ze=et?.providerID||De.currentProviderId||Qe?.providerID,We=et?.modelID||De.currentModelId||Qe?.modelID,it=ke()||De.currentAgentName||void 0;if(!Ze||!We){H.error(r("session.newWorktree.error.noModelSelected"));return}const qe=ae(Ze,We);if(je({sessionId:z.sessionId,providerID:Ze,modelID:We,agentName:it,variant:qe}),z.issue){if(!a.issueGet||!a.issueComments)return;const st=await a.issueGet(m,z.issue.number);if(st.connected===!1||!st.repo||!st.issue)throw new Error("Failed to load issue context");const Je=await a.issueComments(m,z.issue.number);if(Je.connected===!1)throw new Error("Failed to load issue comments");const Be=await wn("github.issue.review.visible",{issue_number:String(z.issue.number)}),nt=await wn("github.issue.review.instructions"),Ge=y6({repo:st.repo,issue:st.issue,comments:Je.comments??[]});await on.sendMessage({id:z.sessionId,providerID:Ze,modelID:We,agent:it,variant:qe,text:Be,additionalParts:[{text:nt,synthetic:!0},{text:Ge,synthetic:!0}]}),H.success(r("session.newWorktree.toast.sessionFromIssue"));return}if(z.pr){if(!a.prContext)return;const st=await a.prContext(m,z.pr.number,{includeDiff:z.includeDiff,includeCheckDetails:!1});if(st.connected===!1||!st.repo||!st.pr)throw new Error("Failed to load PR context");const Je=await wn("github.pr.review.visible",{pr_number:String(z.pr.number)}),Be=await wn("github.pr.review.instructions"),nt=v6(st);await on.sendMessage({id:z.sessionId,providerID:Ze,modelID:We,agent:it,variant:qe,text:Je,additionalParts:[{text:Be,synthetic:!0},{text:nt,synthetic:!0}]}),H.success(r("session.newWorktree.toast.sessionFromPr"))}},[je,a,m,ke,X,ae,r]),Ne=f==="new-branch"?x:g;_e.useEffect(()=>{if(!j?.all||!m||x.sourceBranch)return;(async()=>{try{const De=await No(m).catch(()=>null),Qe=localStorage.getItem(vf),et=Qe&&j.all?.includes(Qe)?Qe:De&&j.all?.includes(De)?De:j.all?.includes("main")?"main":j.all?.includes("master")?"master":j.all?.[0]||"";et&&y(Ze=>({...Ze,sourceBranch:et}))}catch{}})()},[j,m,x.sourceBranch]),_e.useEffect(()=>{if(!t)return;b("new-branch"),h({selectedBranch:"",worktreeName:""}),M(!1),R(!1),B(!1),O(!1),q(""),J(""),Y({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const z=T();y({branchName:z,worktreeName:z,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[t,T]),_e.useEffect(()=>{if(f!=="new-branch"||!x.isSyncingWorktreeName)return;const z=Xi(x.branchName),De=Rn(z);y(Qe=>({...Qe,worktreeName:De}))},[f,x.branchName,x.isSyncingWorktreeName]);const Me=_e.useCallback(async()=>{if(!u||!ue.touched||Se)return;Ce&&Ce.abort();const z=new AbortController;Ie(z),Y(De=>({...De,isValidating:!0}));try{const De=f==="new-branch"?x.branchName:g.selectedBranch,Qe=Ne.worktreeName,et=Xi(De),Ze=Rn(Qe);let We=null,it=null;if(et||(We=r("session.newWorktree.error.branchNameRequired")),Ze||(it=r("session.newWorktree.error.worktreeDirectoryRequired")),et&&Ze){const qe=f==="new-branch"?x.linkedPr:null,st=qe?wf(qe,k,w):null,Je=await Th(u,{mode:f==="existing-branch"||st?"existing":"new",branchName:et,worktreeName:Ze,existingBranch:st?.existingBranch??(f==="existing-branch"?et:void 0),...st?.ensureRemoteName?{ensureRemoteName:st.ensureRemoteName}:{},...st?.ensureRemoteUrl?{ensureRemoteUrl:st.ensureRemoteUrl}:{}});if(z.signal.aborted)return;Je.ok||Je.errors.forEach(Be=>{if(Be.code==="worktree_exists"){it=it??Be.message;return}Be.code.startsWith("branch_")&&(We=We??Be.message)})}z.signal.aborted||Y(qe=>({...qe,isValidating:!1,branchError:We,worktreeError:it}))}catch{z.signal.aborted||Y(De=>({...De,isValidating:!1}))}},[u,f,x.branchName,x.linkedPr,g.selectedBranch,Ne.worktreeName,k,w,ue.touched,Ce,Se,r]),Ve=f==="new-branch"?x.branchName:g.selectedBranch;_e.useEffect(()=>{if(!t||!u||!ue.touched||Se)return;const z=setTimeout(()=>{Me()},300);return()=>clearTimeout(z)},[Ne.worktreeName,Ve,t,u,Me,ue.touched,Se]);const we=async()=>{if(!u||!m){H.error(r("session.newWorktree.error.noActiveProject"));return}Y(Ze=>({...Ze,touched:!0}));const z=f==="new-branch"?x.branchName:g.selectedBranch,De=Ne.worktreeName,Qe=Xi(z),et=Rn(De);if(!Qe){H.error(r("session.newWorktree.error.branchNameRequired"));return}if(!et){H.error(r("session.newWorktree.error.worktreeDirectoryRequired"));return}Ce&&(Ce.abort(),Ie(null)),Y(Ze=>({...Ze,isValidating:!1,branchError:null,worktreeError:null})),fe(!0);try{const Ze=await au(u),We=f==="new-branch"?x.linkedPr:null,it=x.sourceBranch;let qe="";const st=(()=>{if(We){const Le=wf(We,k,w);return qe=Le.sourceLabel,{preferredName:Qe||et,mode:"existing",branchName:Qe,worktreeName:et,existingBranch:Le.existingBranch,setupCommands:Ze,setUpstream:Le.setUpstream,upstreamRemote:Le.upstreamRemote,upstreamBranch:Le.upstreamBranch,...Le.ensureRemoteName?{ensureRemoteName:Le.ensureRemoteName}:{},...Le.ensureRemoteUrl?{ensureRemoteUrl:Le.ensureRemoteUrl}:{}}}return qe=f==="new-branch"?it:"",{preferredName:Qe||et,mode:f==="existing-branch"?"existing":"new",branchName:f==="existing-branch"?void 0:Qe,worktreeName:et,existingBranch:f==="existing-branch"?Qe:void 0,setupCommands:Ze,...it&&f==="new-branch"?{startRef:it}:{}}})(),Je=await Oy(m,st),Be=await Ly(u,Je),nt=f==="new-branch"?x.linkedIssue:null,Ge=f==="new-branch"?x.linkedPr:null,at=f==="new-branch"?x.includePrDiff:!1;let Ae=null;if(nt||Ge){const Le=nt?`#${nt.number} ${nt.title}`.trim():Ge?`#${Ge.number} ${Ge.title}`.trim():r("session.newWorktree.newSessionTitle"),ze=await $y(Le,Be.path,null);if(!ze?.id)throw new Error("Failed to create session");Ae=ze.id,_y(ze.id,Le).catch(()=>{});try{$t.getState().initializeNewOpenChamberSession(ze.id,wt.getState().agents)}catch{}}x.sourceBranch&&f==="new-branch"&&!x.linkedPr&&localStorage.setItem(vf,x.sourceBranch),H.success(r("session.newWorktree.toast.worktreeCreated"),{description:r("session.newWorktree.toast.worktreeCreatedDescription",{target:`${Be.branch||Be.name}${qe?` ${r("session.newWorktree.fromSource",{source:qe})}`:""}`})}),e(!1),Ae?(n?.(Be.path,{sessionId:Ae}),le({sessionId:Ae,issue:nt,pr:Ge,includeDiff:at}).catch(Le=>{const ze=Le instanceof Error?Le.message:r("session.newWorktree.error.sendGitHubContextFailed");H.error(r("session.newWorktree.error.sendGitHubContextFailed"),{description:ze})})):n?.(Be.path)}catch(Ze){const We=Ze instanceof Error?Ze.message:r("session.newWorktree.error.createWorktreeFailed");H.error(r("session.newWorktree.error.createWorktreeFailed"),{description:We})}finally{fe(!1)}},ee=z=>{b(z),Y(De=>({...De,touched:!1,branchError:null,worktreeError:null}))},F=z=>{if(!z){y(De=>({...De,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(z.type==="issue"){const De=z.item,Qe=`issue-${De.number}-${yc()}`;y(et=>({...et,linkedIssue:De,linkedPr:null,includePrDiff:!1,branchName:Qe,worktreeName:Rn(Qe),isSyncingWorktreeName:!0}))}else if(z.type==="pr"){const De=z.item;y(Qe=>({...Qe,linkedPr:De,linkedIssue:null,includePrDiff:z.includeDiff??!1,branchName:De.head,worktreeName:Rn(De.head),isSyncingWorktreeName:!0}))}},U=d&&c?.connected===!0,Te=(f==="existing-branch"?!!g.selectedBranch&&!!g.worktreeName&&!ue.branchError&&!ue.worktreeError:!!Xi(x.branchName)&&!!x.worktreeName&&!ue.branchError&&!ue.worktreeError)&&!Se,Oe=()=>{y(z=>({...z,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},Pe=s.jsxs("div",{className:ye("flex gap-2",o?"flex-col w-full":"flex-row items-center"),children:[s.jsx("div",{className:ye("flex items-center gap-1.5 text-destructive",o?"w-full justify-center order-first":"mr-auto"),children:ue.touched&&(ue.branchError||ue.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:ue.branchError||ue.worktreeError})]})}),s.jsxs("div",{className:ye("flex gap-2",o&&"w-full"),children:[s.jsx(be,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Se,className:ye(o&&"flex-1"),children:r("session.newWorktree.actions.cancel")}),s.jsxs(be,{size:"sm",onClick:we,disabled:!Te||Se,className:ye("gap-1.5",o&&"flex-1"),children:[Se&&s.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(Se?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return s.jsxs(s.Fragment,{children:[o?s.jsxs(zr,{open:t,title:r("session.newWorktree.title"),onClose:()=>e(!1),footer:Pe,children:[s.jsx("div",{className:"w-full mb-4",children:s.jsx(Er,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(A,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:f,onSelect:z=>ee(z),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),s.jsxs("div",{className:"space-y-6",children:[f==="existing-branch"?s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.selectBranch")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>B(!0),className:"flex-1 justify-between h-9",children:[s.jsx("span",{className:g.selectedBranch?"text-foreground":"text-muted-foreground",children:g.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(A,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(be,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:se,disabled:!xe||v,title:r("session.newWorktree.fetchBranches"),children:v?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"refresh",className:"size-4"})})]}),s.jsx(zr,{open:V,title:r("session.newWorktree.selectBranch"),onClose:()=>B(!1),children:s.jsxs("div",{className:"space-y-4",ref:ne,children:[s.jsx(Lt,{value:_,onChange:z=>q(z.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),v?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):k.length===0&&w.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[ve&&he&&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:de.matching.map(z=>s.jsx("button",{onClick:()=>{h(De=>({...De,selectedBranch:z.value,worktreeName:Rn(z.label)})),Y(De=>({...De,touched:!0})),B(!1)},className:ye("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.selectedBranch===z.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z.label})},`${z.source}-${z.value}`))})]}),ve&&!he&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),de.otherLocal.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(ve?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:de.otherLocal.map(z=>s.jsx("button",{onClick:()=>{h(De=>({...De,selectedBranch:z,worktreeName:Rn(z)})),Y(De=>({...De,touched:!0})),B(!1)},className:ye("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.selectedBranch===z?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z})},z))})]}),de.otherRemote.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(ve?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:de.otherRemote.map(z=>s.jsx("button",{onClick:()=>{h(De=>({...De,selectedBranch:`remotes/${z}`,worktreeName:Rn(z)})),Y(De=>({...De,touched:!0})),B(!1)},className:ye("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.selectedBranch===`remotes/${z}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z})},`remotes/${z}`))})]})]})]})})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),f==="new-branch"&&U&&s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>D(!0),className:"gap-1.5 h-7",children:[s.jsx(A,{name:"github",className:"size-4 text-status-success"}),x.linkedIssue||x.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Lt,{value:x.branchName,onChange:z=>{y(De=>({...De,branchName:z.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>Y(z=>({...z,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!x.linkedPr,className:ye("h-8",ue.touched&&ue.branchError&&"border-destructive",x.linkedPr&&"bg-muted text-muted-foreground")}),x.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:x.linkedPr.head})})]}),x.linkedIssue&&!x.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:x.linkedIssue.number,title:x.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 z=Rn(f==="new-branch"?x.branchName:"");y(De=>({...De,worktreeName:z,isSyncingWorktreeName:!0}))},disabled:!x.branchName||x.worktreeName===Rn(x.branchName),className:ye("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",x.worktreeName===Rn(x.branchName)||!x.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(A,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Lt,{value:Ne.worktreeName,onChange:z=>{f==="new-branch"?y(De=>({...De,worktreeName:z.target.value,isSyncingWorktreeName:!1})):h(De=>({...De,worktreeName:z.target.value}))},onBlur:()=>Y(z=>({...z,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:ye("h-8",ue.touched&&ue.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!x.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>O(!0),className:"w-full justify-between h-9",children:[s.jsx("span",{className:x.sourceBranch?"text-foreground":"text-muted-foreground",children:x.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(A,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),x.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:x.sourceBranch})}),s.jsx(zr,{open:$,title:r("session.newWorktree.selectSourceBranch"),onClose:()=>O(!1),children:s.jsxs("div",{className:"space-y-4",ref:me,children:[s.jsx(Lt,{value:L,onChange:z=>J(z.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),v?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):k.length===0&&w.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[te&&ce&&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:ge.matching.map(z=>s.jsx("button",{onClick:()=>{y(De=>({...De,sourceBranch:z.value})),O(!1)},className:ye("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.sourceBranch===z.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z.label})},`${z.source}-${z.value}`))})]}),te&&!ce&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),ge.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(te?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:ge.otherLocal.map(z=>s.jsx("button",{onClick:()=>{y(De=>({...De,sourceBranch:z})),O(!1)},className:ye("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.sourceBranch===z?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z})},z))})]}),ge.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(te?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:ge.otherRemote.map(z=>s.jsx("button",{onClick:()=>{y(De=>({...De,sourceBranch:`remotes/${z}`})),O(!1)},className:ye("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.sourceBranch===`remotes/${z}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z})},`remotes/${z}`))})]})]})]})})]}),(x.linkedIssue||x.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(A,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),x.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:x.linkedIssue.number})}),x.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:x.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:x.linkedIssue?.title||x.linkedPr?.title}),s.jsx("a",{href:x.linkedIssue?.url||x.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:z=>z.stopPropagation(),children:s.jsx(A,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:Oe,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]}),x.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:[x.linkedPr.head," → ",x.linkedPr.base]}),x.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(us,{open:t,onOpenChange:e,children:s.jsxs(ds,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[s.jsx(hs,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(ms,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(A,{name:"git-branch",className:"h-5 w-5"}),r("session.newWorktree.title")]}),s.jsx("div",{className:"w-[280px] shrink-0",children:s.jsx(Er,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(A,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:f,onSelect:z=>ee(z),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(As,{open:S,onOpenChange:M,children:[s.jsx(Is,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:ye("truncate",g.selectedBranch?"text-foreground":"text-muted-foreground"),children:g.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(Ps,{align:"start",sideOffset:6,portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:Z,children:s.jsxs(qa,{shouldFilter:!1,children:[s.jsx(va,{placeholder:r("session.newWorktree.searchBranches"),value:_,onValueChange:q,onKeyDown:pe}),s.jsx(Ja,{disableHorizontal:!0,children:v?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):k.length===0&&w.length===0?s.jsx(Ya,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[ve&&he&&s.jsx(On,{heading:r("session.newWorktree.matchingBranches"),children:de.matching.map(z=>s.jsx(Pn,{value:z.value,onSelect:()=>{h(De=>({...De,selectedBranch:z.value,worktreeName:Rn(z.label)})),Y(De=>({...De,touched:!0})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z.label})},`${z.source}-${z.value}`))}),ve&&!he&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),de.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[ve&&s.jsx(_a,{}),s.jsx(On,{heading:r(ve?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:de.otherLocal.map(z=>s.jsx(Pn,{value:z,onSelect:()=>{h(De=>({...De,selectedBranch:z,worktreeName:Rn(z)})),Y(De=>({...De,touched:!0})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z})},`local-${z}`))})]}),de.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(de.otherLocal.length>0||ve)&&s.jsx(_a,{}),s.jsx(On,{heading:r(ve?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:de.otherRemote.map(z=>s.jsx(Pn,{value:`remotes/${z}`,onSelect:()=>{h(De=>({...De,selectedBranch:`remotes/${z}`,worktreeName:Rn(z)})),Y(De=>({...De,touched:!0})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z})},`remote-${z}`))})]})]})})]})})]}),s.jsx(be,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:se,disabled:!xe||v,title:r("session.newWorktree.fetchBranches"),children:v?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"refresh",className:"size-4"})})]})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),f==="new-branch"&&U&&s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>D(!0),className:"gap-1.5 h-7",children:[s.jsx(A,{name:"github",className:"size-4 text-status-success"}),x.linkedIssue||x.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Lt,{value:x.branchName,onChange:z=>{y(De=>({...De,branchName:z.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>Y(z=>({...z,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!x.linkedPr,className:ye("h-8",ue.touched&&ue.branchError&&"border-destructive",x.linkedPr&&"bg-muted text-muted-foreground")}),x.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:x.linkedPr.head})})]}),x.linkedIssue&&!x.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(A,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:x.linkedIssue.number,title:x.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 z=Rn(f==="new-branch"?x.branchName:"");y(De=>({...De,worktreeName:z,isSyncingWorktreeName:!0}))},disabled:!x.branchName||x.worktreeName===Rn(x.branchName),className:ye("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",x.worktreeName===Rn(x.branchName)||!x.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(A,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Lt,{value:Ne.worktreeName,onChange:z=>{f==="new-branch"?y(De=>({...De,worktreeName:z.target.value,isSyncingWorktreeName:!1})):h(De=>({...De,worktreeName:z.target.value}))},onBlur:()=>Y(z=>({...z,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:ye("h-8",ue.touched&&ue.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!x.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(As,{open:E,onOpenChange:R,children:[s.jsx(Is,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:ye("truncate",x.sourceBranch?"text-foreground":"text-muted-foreground"),children:x.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(Ps,{align:"start",portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:ie,children:s.jsxs(qa,{shouldFilter:!1,children:[s.jsx(va,{placeholder:r("session.newWorktree.searchBranches"),value:L,onValueChange:J,onKeyDown:pe}),s.jsx(Ja,{disableHorizontal:!0,children:v?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):k.length===0&&w.length===0?s.jsx(Ya,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[te&&ce&&s.jsx(On,{heading:r("session.newWorktree.matchingBranches"),children:ge.matching.map(z=>s.jsx(Pn,{value:z.value,onSelect:()=>{y(De=>({...De,sourceBranch:z.value})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z.label})},`${z.source}-${z.value}`))}),te&&!ce&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),ge.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[te&&s.jsx(_a,{}),s.jsx(On,{heading:r(te?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:ge.otherLocal.map(z=>s.jsx(Pn,{value:z,onSelect:()=>{y(De=>({...De,sourceBranch:z})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z})},`local-${z}`))})]}),ge.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(ge.otherLocal.length>0||te)&&s.jsx(_a,{}),s.jsx(On,{heading:r(te?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:ge.otherRemote.map(z=>s.jsx(Pn,{value:`remotes/${z}`,onSelect:()=>{y(De=>({...De,sourceBranch:`remotes/${z}`})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z})},`remote-${z}`))})]})]})})]})})]}),x.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:x.sourceBranch})})]}),(x.linkedIssue||x.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(A,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),x.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:x.linkedIssue.number})}),x.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:x.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:x.linkedIssue?.title||x.linkedPr?.title}),s.jsx("a",{href:x.linkedIssue?.url||x.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:z=>z.stopPropagation(),children:s.jsx(A,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:Oe,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]}),x.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:[x.linkedPr.head," → ",x.linkedPr.base]}),x.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(_s,{className:"mt-1 flex items-center justify-between",children:[s.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:ue.touched&&(ue.branchError||ue.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:ue.branchError||ue.worktreeError})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Se,children:r("session.newWorktree.actions.cancel")}),s.jsxs(be,{size:"sm",onClick:we,disabled:!Te||Se,className:"gap-1.5",children:[Se&&s.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(Se?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),s.jsx(x6,{open:P,onOpenChange:D,onSelect:F})]})}let yi=null,vi=null,vl=null,Kl=0;const Wa=new Set,j6=3e4,N6=45e3,Jg=()=>{vl&&(clearTimeout(vl),vl=null)},Yg=()=>{if(vi||Wa.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(Kl,5)),j6);vi=setTimeout(()=>{vi=null,Kl+=1,Qg()},t)},Hl=()=>{Jg(),yi&&yi.close(),yi=null},jf=()=>{Jg(),Wa.size!==0&&(vl=setTimeout(()=>{Hl(),Yg()},N6))},S6=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}},k6=t=>{if(t.type==="openchamber:event-stream-ready"){Kl=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 Wa)d(c)},Qg=()=>{if(typeof window>"u"||Wa.size===0||typeof EventSource!="function"||yi&&yi.readyState!==EventSource.CLOSED)return;Hl();const t=new EventSource("/api/openchamber/events");t.onopen=()=>{jf()},t.onmessage=e=>{jf();const n=S6(e.data);n&&k6(n)},t.onerror=()=>{Hl(),Yg()},yi=t},Xg=t=>(Wa.add(t),Qg(),()=>{Wa.delete(t),Wa.size===0&&(vi&&(clearTimeout(vi),vi=null),Kl=0,Hl())}),lc=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},Ti=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},C6=async t=>{const e=Ti(t),n=await fetch(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await lc(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},Nf=async(t,e)=>{const n=Ti(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 lc(r,"Failed to save scheduled task"));const a=await r.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},I6=async(t,e)=>{const n=Ti(t),r=Ti(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 lc(a,"Failed to delete scheduled task"));const i=await a.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},P6=async(t,e)=>{const n=Ti(t),r=Ti(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 lc(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}},Zg=[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"],kf=()=>{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}`},wl=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},Cf=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},A6=(t,e,n)=>{const r=wl(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},If=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),D6=(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},T6=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}},Da=(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")}`},Ri=(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"},Pf=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:Ri(t,{min:1,max:12}),Qo=t=>/^[0-5][0-9]$/.test(t)?t:Ri(t,{max:59}),E6=(t,e)=>Ri(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),Af=(t,e)=>Ri(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),M6=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}},R6=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}},F6=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Zg.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},O6=(t,e)=>[...t.slice(e),...t.slice(0,e)],Ir=t=>{const e=ot.c(6),{htmlFor:n,required:r,children:a}=t;let i;e[0]!==r?(i=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=i):i=e[1];let o;return e[2]!==a||e[3]!==n||e[4]!==i?(o=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,i]})}),e[2]=a,e[3]=n,e[4]=i,e[5]=o):o=e[5],o},Df=t=>{const e=ot.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=T6(n),e[0]=n,e[1]=m):m=e[1];const u=m,f=_e.useRef(null),b=_e.useRef(null),[x,y]=_e.useState(null),[g,h]=_e.useState(null),j=_e.useRef(null),v=_e.useRef(null);let C;e[2]===Symbol.for("react.memo_cache_sentinel")?(C=Y=>{j.current=Y,y(Y)},e[2]=C):C=e[2];const k=C;let w;e[3]===Symbol.for("react.memo_cache_sentinel")?(w=Y=>{v.current=Y,h(Y)},e[3]=w):w=e[3];const N=w,I=z6,T=U6,P=W6;let D;e[4]!==r||e[5]!==u.meridiem||e[6]!==u.minute||e[7]!==a?(D=Y=>{const Se=Y.replace(/\D/g,"").slice(0,2);k(Se),Se.length===2&&(r(a?P(I(Se),u.minute):Da(Pf(Se),u.minute,u.meridiem)),k(null),b.current?.focus())},e[4]=r,e[5]=u.meridiem,e[6]=u.minute,e[7]=a,e[8]=D):D=e[8];const S=D;let M;e[9]!==r||e[10]!==u.meridiem||e[11]!==u.minute||e[12]!==a?(M=()=>{const Y=j.current;if(Y!==null&&(k(null),Y.length!==0)){if(a){r(P(I(Y.padStart(2,"0")),u.minute));return}r(Da(Pf(Y.padStart(2,"0")),u.minute,u.meridiem))}},e[9]=r,e[10]=u.meridiem,e[11]=u.minute,e[12]=a,e[13]=M):M=e[13];const E=M;let R;e[14]!==r||e[15]!==u.hour12||e[16]!==u.hour24||e[17]!==u.meridiem||e[18]!==a?(R=Y=>{const Se=Y.replace(/\D/g,"").slice(0,2);N(Se),Se.length===2&&(r(a?P(u.hour24,Qo(Se)):Da(u.hour12,Qo(Se),u.meridiem)),N(null))},e[14]=r,e[15]=u.hour12,e[16]=u.hour24,e[17]=u.meridiem,e[18]=a,e[19]=R):R=e[19];const V=R;let B;e[20]!==r||e[21]!==u.hour12||e[22]!==u.hour24||e[23]!==u.meridiem||e[24]!==a?(B=()=>{const Y=v.current;Y!==null&&(N(null),Y.length!==0&&r(a?P(u.hour24,Qo(Y.padStart(2,"0"))):Da(u.hour12,Qo(Y.padStart(2,"0")),u.meridiem)))},e[20]=r,e[21]=u.hour12,e[22]=u.hour24,e[23]=u.meridiem,e[24]=a,e[25]=B):B=e[25];const $=B;let O;e[26]!==r||e[27]!==u.hour12||e[28]!==u.hour24||e[29]!==u.meridiem||e[30]!==u.minute||e[31]!==a?(O=Y=>r(a?P(T(u.hour24,Y),u.minute):Da(E6(u.hour12,Y),u.minute,u.meridiem)),e[26]=r,e[27]=u.hour12,e[28]=u.hour24,e[29]=u.meridiem,e[30]=u.minute,e[31]=a,e[32]=O):O=e[32];const _=O;let q;e[33]!==r||e[34]!==u.hour12||e[35]!==u.hour24||e[36]!==u.meridiem||e[37]!==u.minute||e[38]!==a?(q=Y=>r(a?P(u.hour24,Af(u.minute,Y)):Da(u.hour12,Af(u.minute,Y),u.meridiem)),e[33]=r,e[34]=u.hour12,e[35]=u.hour24,e[36]=u.meridiem,e[37]=u.minute,e[38]=a,e[39]=q):q=e[39];const L=q;let J;e[40]!==r||e[41]!==u.hour12||e[42]!==u.meridiem||e[43]!==u.minute?(J=Y=>{Y!==u.meridiem&&r(Da(u.hour12,u.minute,Y))},e[40]=r,e[41]=u.hour12,e[42]=u.meridiem,e[43]=u.minute,e[44]=J):J=e[44];const Z=J;let ie;e[45]!==E||e[46]!==_?(ie=Y=>{if(Y.key==="ArrowRight"){Y.preventDefault(),E(),b.current?.focus();return}(Y.key==="ArrowUp"||Y.key==="ArrowDown")&&(Y.preventDefault(),k(null),_(Y.key==="ArrowUp"?1:-1))},e[45]=E,e[46]=_,e[47]=ie):ie=e[47];const ne=ie;let me;e[48]!==$||e[49]!==L?(me=Y=>{if(Y.key==="ArrowLeft"&&(Y.currentTarget.selectionStart??0)===0){Y.preventDefault(),$(),f.current?.focus();return}(Y.key==="ArrowUp"||Y.key==="ArrowDown")&&(Y.preventDefault(),N(null),L(Y.key==="ArrowUp"?1:-1))},e[48]=$,e[49]=L,e[50]=me):me=e[50];const pe=me,G=a?"px-2":"pl-2 pr-1";let K;e[51]!==G?(K=ye("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",G),e[51]=G,e[52]=K):K=e[52];const Q=x??(a?u.hour24:u.hour12);let W;e[53]!==S?(W=Y=>S(Y.target.value),e[53]=S,e[54]=W):W=e[54];let de;e[55]===Symbol.for("react.memo_cache_sentinel")?(de=()=>k(""),e[55]=de):de=e[55];let ge;e[56]!==E||e[57]!==i||e[58]!==ne||e[59]!==Q||e[60]!==W?(ge=s.jsx("input",{ref:f,inputMode:"numeric",value:Q,onChange:W,onKeyDown:ne,onFocus:de,onBlur:E,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]=E,e[57]=i,e[58]=ne,e[59]=Q,e[60]=W,e[61]=ge):ge=e[61];let ve;e[62]===Symbol.for("react.memo_cache_sentinel")?(ve=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=ve):ve=e[62];const te=g??u.minute;let he;e[63]!==V?(he=Y=>V(Y.target.value),e[63]=V,e[64]=he):he=e[64];let ce;e[65]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>N(""),e[65]=ce):ce=e[65];let xe;e[66]!==$||e[67]!==o||e[68]!==pe||e[69]!==te||e[70]!==he?(xe=s.jsx("input",{ref:b,inputMode:"numeric",value:te,onChange:he,onKeyDown:pe,onFocus:ce,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]=pe,e[69]=te,e[70]=he,e[71]=xe):xe=e[71];let se;e[72]!==d||e[73]!==u.meridiem||e[74]!==c||e[75]!==p||e[76]!==Z||e[77]!==a?(se=a?null:s.jsxs(as,{value:u.meridiem,onValueChange:Y=>Z(Y),children:[s.jsx(is,{"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(fs,{})}),s.jsxs(os,{children:[s.jsx(Mt,{value:"AM",children:d}),s.jsx(Mt,{value:"PM",children:p})]})]}),e[72]=d,e[73]=u.meridiem,e[74]=c,e[75]=p,e[76]=Z,e[77]=a,e[78]=se):se=e[78];let ue;return e[79]!==K||e[80]!==ge||e[81]!==xe||e[82]!==se?(ue=s.jsxs("div",{className:K,children:[ge,ve,xe,se]}),e[79]=K,e[80]=ge,e[81]=xe,e[82]=se,e[83]=ue):ue=e[83],ue},Tf=t=>new Date(t.getFullYear(),t.getMonth(),1),L6=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},Ef=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),$6=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:$6(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:kf(),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:kf(),onceTime:"09:00",weekdays:[1],timezone:n},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent}}},_6=(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")},B6=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 V6(t){const{open:e,task:n,onOpenChange:r,onSave:a}=t,{t:i,locale:o}=ft(),c=wt(U=>U.loadProviders),d=wt(U=>U.loadAgents),p=wt(U=>U.providers),m=wt(U=>U.currentProviderId),u=wt(U=>U.currentModelId),f=wt(U=>U.currentVariant||""),b=wt(U=>U.currentAgentName||""),x=Fe(U=>U.timeFormatPreference),y=Fe(U=>U.weekStartPreference),g=Fe(U=>U.isMobile),[h,j]=_e.useState(()=>Mf(n,{providerID:m,modelID:u,variant:f,agent:b})),[v,C]=_e.useState(!1),[k,w]=_e.useState(!1),[N,I]=_e.useState(!1),[T,P]=_e.useState(""),[D,S]=_e.useState(!1),[M,E]=_e.useState(""),[R,V]=_e.useState(!1),[B,$]=_e.useState(""),[O,_]=_e.useState(()=>{const U=wl(n?.schedule?.date||"")||new Date;return new Date(U.getFullYear(),U.getMonth(),1)}),q=_e.useRef(null),L=_e.useRef(null),J=_e.useRef(null),Z=_e.useRef(null),ie=_e.useRef(null),ne=_e.useMemo(()=>R6(o),[o]),me=_e.useMemo(()=>M6(o),[o]),pe=_e.useMemo(()=>x==="24h"?!0:x==="12h"?!1:ne,[x,ne]),G=_e.useMemo(()=>y==="sunday"?0:y==="monday"?1:me,[y,me]),K=_e.useMemo(()=>{const U=F6(o);return O6(Zg.map(oe=>({value:oe,label:U[oe]||""})),G)},[o,G]);_e.useEffect(()=>{e&&(c(),d())},[e,c,d]),_e.useEffect(()=>{if(!e)return;j(Mf(n,{providerID:m,modelID:u,variant:f,agent:b}));const U=wl(n?.schedule?.date||"")||new Date;_(new Date(U.getFullYear(),U.getMonth(),1)),w(!1),S(!1),I(!1),E(""),P("")},[e,n,m,u,f,b]),_e.useEffect(()=>{if(!k)return;const U=oe=>{q.current&&!q.current.contains(oe.target)&&w(!1)};return document.addEventListener("mousedown",U),()=>{document.removeEventListener("mousedown",U)}},[k]);const Q=_e.useMemo(()=>{const oe=p.find(Te=>Te.id===h.execution.providerID)?.models?.find(Te=>Te.id===h.execution.modelID);return oe?.variants?Object.keys(oe.variants):[]},[p,h.execution.providerID,h.execution.modelID]),W=Q.length>0,de=_e.useMemo(()=>!W||!h.execution.variant?"__default":Q.includes(h.execution.variant)?h.execution.variant:"__default",[h.execution.variant,W,Q]);_e.useEffect(()=>{W||!h.execution.variant||j(U=>({...U,execution:{...U.execution,variant:""}}))},[W,h.execution.variant]);const ge=_e.useCallback((U,oe)=>{j(Te=>{const Oe=new Set(Te.schedule.weekdays);return oe?Oe.add(U):Oe.delete(U),{...Te,schedule:{...Te.schedule,weekdays:Array.from(Oe).sort((Pe,z)=>Pe-z)}}})},[]),ve=_e.useCallback((U,oe)=>{j(Te=>{const Oe=Te.schedule.times.slice();return Oe[U]=oe,{...Te,schedule:{...Te.schedule,times:Oe}}})},[]),te=_e.useCallback(U=>{j(oe=>{const Te=oe.schedule.times.filter((Oe,Pe)=>Pe!==U);return{...oe,schedule:{...oe.schedule,times:Te.length>0?Te:["09:00"]}}})},[]),he=_e.useCallback(()=>{j(U=>({...U,schedule:{...U.schedule,times:[...U.schedule.times,"12:00"]}}))},[]),ce=_e.useMemo(()=>L6(),[]),xe=_e.useMemo(()=>Tf(ce),[ce]),se=_e.useMemo(()=>{const U=wl(h.schedule.onceDate);return U?Ef(U,ce)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(o,{weekday:"short"}).format(U):null},[h.schedule.onceDate,o,i,ce]),ue=_e.useMemo(()=>Tf(O).getTime()<=xe.getTime(),[O,xe]),Y=_e.useMemo(()=>K.map(U=>U.label),[K]),Se=_e.useCallback(U=>{j(oe=>({...oe,schedule:{...oe.schedule,onceDate:U}}))},[]),fe=_e.useCallback((U,oe)=>{if(U.startsWith("/")){const z=U.indexOf(" "),De=U.indexOf(`
|
|
185
|
-
`),Qe=Math.min(z===-1?U.length:z,De===-1?U.length:De);if(oe<=Qe&&z===-1){E(U.substring(1,Qe)),S(!0),I(!1),V(!1);return}}S(!1);const Te=U.substring(0,oe),Oe=Te.lastIndexOf("#");if(Oe!==-1){const z=Oe>0?Te[Oe-1]:null,De=Te.substring(Oe+1);if((!z||/\s/.test(z))&&!De.includes(" ")&&!De.includes(`
|
|
186
|
-
`)){$(De),V(!0),I(!1);return}}V(!1);const Pe=Te.lastIndexOf("@");if(Pe!==-1){const z=Pe>0?Te[Pe-1]:null,De=Te.substring(Pe+1);(!z||/\s/.test(z))&&!De.includes(" ")&&!De.includes(`
|
|
187
|
-
`)?(P(De),I(!0)):I(!1);return}I(!1)},[]),Ce=_e.useCallback(U=>{j(oe=>({...oe,execution:{...oe.execution,prompt:U}}))},[]),Ie=_e.useCallback(U=>{const oe=h.execution.prompt,Oe=L.current?.selectionStart??oe.length,z=oe.substring(0,Oe).lastIndexOf("@"),De=U.relativePath&&U.relativePath.trim().length>0?U.relativePath.trim():U.path||U.name,Qe=z!==-1?z:Oe,et=`${oe.substring(0,Qe)}@${De} ${oe.substring(Oe)}`,Ze=Qe+De.length+2;Ce(et),I(!1),P(""),requestAnimationFrame(()=>{const We=L.current;We&&(We.selectionStart=Ze,We.selectionEnd=Ze,We.focus()),fe(et,Ze)})},[h.execution.prompt,Ce,fe]),ke=_e.useCallback(U=>{const oe=h.execution.prompt,Oe=L.current?.selectionStart??oe.length,z=oe.substring(0,Oe).lastIndexOf("@"),De=z!==-1?z:Oe,Qe=`${oe.substring(0,De)}@${U} ${oe.substring(Oe)}`,et=De+U.length+2;Ce(Qe),I(!1),P(""),requestAnimationFrame(()=>{const Ze=L.current;Ze&&(Ze.selectionStart=et,Ze.selectionEnd=et,Ze.focus()),fe(Qe,et)})},[h.execution.prompt,Ce,fe]),X=_e.useCallback(U=>{const oe=`/${U.name} `;Ce(oe),S(!1),E(""),V(!1),requestAnimationFrame(()=>{const Te=L.current;Te&&(Te.focus(),Te.selectionStart=Te.value.length,Te.selectionEnd=Te.value.length),fe(oe,oe.length)})},[Ce,fe]),ae=_e.useCallback((U,oe)=>{const Te=h.execution.prompt,Pe=L.current?.selectionStart??Te.length,De=Te.substring(0,Pe).lastIndexOf("#"),Qe=De!==-1?De:Pe,et=`${Te.substring(0,Qe)}#${oe} ${Te.substring(Pe)}`,Ze=Qe+oe.length+2;Ce(et),V(!1),$(""),requestAnimationFrame(()=>{const We=L.current;We&&(We.selectionStart=Ze,We.selectionEnd=Ze,We.focus()),fe(et,Ze)})},[h.execution.prompt,Ce,fe]),je=_e.useCallback(U=>{if(D&&Z.current&&(U.key==="Enter"||U.key==="ArrowUp"||U.key==="ArrowDown"||U.key==="Escape"||U.key==="Tab")){U.preventDefault(),Z.current.handleKeyDown(U.key);return}N&&J.current&&(U.key==="Enter"||U.key==="ArrowUp"||U.key==="ArrowDown"||U.key==="Escape"||U.key==="Tab")&&(U.preventDefault(),J.current.handleKeyDown(U.key)),R&&ie.current&&(U.key==="Enter"||U.key==="ArrowUp"||U.key==="ArrowDown"||U.key==="Escape"||U.key==="Tab")&&(U.preventDefault(),ie.current.handleKeyDown(U.key))},[D,N,R]),le=_e.useCallback(async()=>{const U=_6(h,i);if(U){H.error(U);return}const oe=B6(h.schedule.times),Te={...h.id?{id:h.id}:{},name:h.name.trim(),enabled:h.enabled,schedule:{kind:h.schedule.kind,timezone:h.schedule.timezone.trim(),...h.schedule.kind==="once"?{date:h.schedule.onceDate,time:h.schedule.onceTime}:{times:oe,...h.schedule.kind==="weekly"?{weekdays:h.schedule.weekdays}:{}}},execution:{prompt:h.execution.prompt,providerID:h.execution.providerID,modelID:h.execution.modelID,...h.execution.variant.trim()?{variant:h.execution.variant.trim()}:{},...h.execution.agent.trim()?{agent:h.execution.agent.trim()}:{}},...h.state?{state:h.state}:{}};C(!0);try{await a(Te),r(!1)}catch(Oe){H.error(Oe instanceof Error?Oe.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{C(!1)}},[h,r,a,i]),Ne=_e.useId(),Me=_e.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),Ve=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),we=i("sessions.scheduledTasks.editor.description"),ee=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(Lt,{id:"sched-name",value:h.name,onChange:U=>j(oe=>({...oe,name:U.target.value})),placeholder:i("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ir,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(as,{value:h.schedule.kind,onValueChange:U=>{j(oe=>({...oe,schedule:{...oe.schedule,kind:U}}))},children:[s.jsx(is,{className:"w-fit max-w-full",children:s.jsx(fs,{children:U=>i(U==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":U==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(os,{children:[s.jsx(Mt,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(Mt,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(Mt,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")})]})]})]})]}),h.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:q,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:()=>w(U=>!U),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(A,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:A6(h.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),o)})]}),s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),k?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-background p-3 shadow-sm",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>_(U=>If(U,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:ue,children:s.jsx(A,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(o,{month:"long",year:"numeric"}).format(O)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>_(U=>If(U,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:Y.map((U,oe)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:U},`${U}-${oe}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:D6(O,G).map(({date:U,inCurrentMonth:oe})=>{const Te=Cf(U),Oe=Te===h.schedule.onceDate,Pe=Ef(U,ce),z=U.getTime()<ce.getTime(),De=Oe?"bg-interactive-selection text-interactive-selection-foreground":z?"text-muted-foreground/40":oe?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{z||(Se(Te),w(!1))},disabled:z,className:["h-8 rounded-md typography-ui-label",De,Pe&&!Oe?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",z?"cursor-not-allowed opacity-45":""].join(" "),children:U.getDate()},Te)})}),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(be,{type:"button",size:"xs",variant:"ghost",onClick:()=>{Se(Cf(ce)),_(new Date(ce.getFullYear(),ce.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(Df,{value:h.schedule.onceTime,use24Hour:pe,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:U=>j(oe=>({...oe,schedule:{...oe.schedule,onceTime:U}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(Ir,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(as,{value:h.schedule.timezone,onValueChange:U=>{j(oe=>({...oe,schedule:{...oe.schedule,timezone:U}}))},children:[s.jsx(is,{className:"w-fit max-w-full",children:s.jsx(fs,{})}),s.jsx(os,{children:Sf.map(U=>s.jsx(Mt,{value:U,children:U},U))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[h.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(Ir,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:K.map(U=>{const oe=h.schedule.weekdays.includes(U.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",oe?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(vs,{checked:oe,onChange:Te=>ge(U.value,Te),ariaLabel:U.label}),s.jsx("button",{type:"button",onClick:()=>ge(U.value,!oe),className:"group-hover:text-foreground",children:U.label})]},U.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(Ir,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:h.schedule.times.map((U,oe)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Df,{value:U,use24Hour:pe,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:Te=>ve(oe,Te)}),h.schedule.times.length>1?s.jsx(be,{type:"button",size:"icon",variant:"ghost",onClick:()=>te(oe),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(A,{name:"close",className:"h-4 w-4"})}):null]},oe))}),s.jsx("div",{children:s.jsxs(be,{type:"button",size:"sm",variant:"outline",onClick:he,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"})," ",i("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ir,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(as,{value:h.schedule.timezone,onValueChange:U=>{j(oe=>({...oe,schedule:{...oe.schedule,timezone:U}}))},children:[s.jsx(is,{className:"w-fit max-w-full",children:s.jsx(fs,{})}),s.jsx(os,{children:Sf.map(U=>s.jsx(Mt,{value:U,children:U},U))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Ir,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(Io,{providerId:h.execution.providerID,modelId:h.execution.modelID,onChange:(U,oe)=>{j(Te=>({...Te,execution:{...Te.execution,providerID:U,modelID:oe,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(as,{value:de,disabled:!W,onValueChange:U=>{j(oe=>({...oe,execution:{...oe.execution,variant:U==="__default"?"":U}}))},children:[s.jsx(is,{className:"w-fit max-w-full",children:s.jsx(fs,{children:U=>U==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):U})}),s.jsxs(os,{children:[s.jsx(Mt,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),Q.map(U=>s.jsx(Mt,{value:U,children:U},U))]})]})]})]}),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(ic,{agentName:h.execution.agent,filter:U=>bh(U.mode),onChange:U=>j(oe=>({...oe,execution:{...oe.execution,agent:U}}))})]}),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(un,{id:"sched-prompt",ref:L,value:h.execution.prompt,onChange:U=>{const oe=U.target.value;Ce(oe);const Te=U.target.selectionStart??oe.length;fe(oe,Te)},onKeyDown:je,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),D?s.jsx(Mh,{ref:Z,searchQuery:M,onCommandSelect:X,onClose:()=>S(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,N?s.jsx(Rh,{ref:J,searchQuery:T,onFileSelect:Ie,onAgentSelect:ke,onClose:()=>I(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,R?s.jsx(Fh,{ref:ie,searchQuery:B,onSnippetSelect:ae,onClose:()=>V(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),F=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(vs,{checked:h.enabled,onChange:U=>j(oe=>({...oe,enabled:U})),ariaLabel:i("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:v,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(be,{type:"button",size:"sm",onClick:le,disabled:v,children:i(v?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return g?s.jsx(zr,{open:e,title:Ve,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:U=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:Ve}),U]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:we})]}),footer:F,children:ee}):s.jsx(us,{open:e,onOpenChange:U=>{!U&&Me()||r(U)},children:s.jsxs(ds,{"aria-describedby":Ne,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Ns,{id:Ne,className:"sr-only",children:we}),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(ms,{className:"typography-ui-label font-medium text-foreground",children:Ve}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:we})]})}),s.jsx(jo,{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:ee})}),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:F})})]})})}function z6(t){return Ri(t,{min:0,max:23})}function U6(t,e){return Ri(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function W6(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 K6=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))},H6=(t,e)=>{const n=K6(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||""})},G6=t=>!t||!Number.isFinite(t)?"":new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),Rf=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),a=6e4,i=60*a,o=24*i,c=n>=0;if(r<a)return e(c?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<i){const u=Math.round(r/a);return c?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:u}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:u})}if(r<o){const u=Math.floor(r/i),f=Math.round(r%i/a),b=f>0?`${u}h ${f}m`:`${u}h`;return c?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:b}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:b})}const d=Math.floor(r/o),p=Math.round(r%o/i),m=p>0?`${d}d ${p}h`:`${d}d`;return c?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:m}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:m})},q6={success:{tone:"success",Icon:"checkbox-circle"},error:{tone:"error",Icon:"error-warning"},running:{tone:"warning",Icon:"loader-4",spin:!0},idle:{tone:"muted",Icon:"pulse"}},J6=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function Y6(){const{t}=ft(),e=Fe(E=>E.isScheduledTasksDialogOpen),n=Fe(E=>E.setScheduledTasksDialogOpen),r=Fe(E=>E.isMobile),a=Cs(E=>E.projects),i=Cs(E=>E.getActiveProject()),o=Ws(E=>E.homeDirectory),{currentTheme:c}=jr(),[d,p]=_e.useState(""),[m,u]=_e.useState([]),[f,b]=_e.useState(!0),[x,y]=_e.useState(!1),[g,h]=_e.useState(null),[j,v]=_e.useState(null),C=_e.useMemo(()=>a.find(E=>E.id===d)||null,[a,d]),k=_e.useCallback(E=>{const R=E.label?.trim()||Ga(E.path,o||void 0),V=ko({id:E.id,iconImage:E.iconImage??null},{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),B=E.icon?nc[E.icon]:null,$=E.color?Co[E.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[V?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:E.iconBackground?{backgroundColor:E.iconBackground}:void 0,children:s.jsx("img",{src:V,alt:"",className:"h-full w-full object-contain",draggable:!1})}):B?s.jsx(A,{name:B,className:"h-3.5 w-3.5 shrink-0",style:$?{color:$}:void 0}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:$?{color:$}:void 0}),s.jsx("span",{className:"truncate",children:R})]})},[o,c.metadata.variant,c.colors.surface.foreground]),w=_e.useCallback(async(E,R)=>{if(!E){u([]);return}R?.silent||b(!0);try{const V=await C6(E);V.sort((B,$)=>{if(B.enabled!==$.enabled)return B.enabled?-1:1;const O=B.name.localeCompare($.name);return O!==0?O:(B.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-($.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),u(V)}catch(V){H.error(V instanceof Error?V.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),R?.silent||u([])}finally{R?.silent||b(!1)}},[t]);_e.useEffect(()=>{if(!e)return;const E=i?.id||a[0]?.id||"";p(E),E?w(E):(u([]),b(!1))},[e,i,a,w]),_e.useEffect(()=>{if(!e)return;let E=null;const R=Xg(V=>{V.type==="scheduled-task-ran"&&V.projectId===d&&(E&&clearTimeout(E),E=setTimeout(()=>{w(d,{silent:!0})},400))});return()=>{E&&clearTimeout(E),R()}},[e,d,w]);const N=_e.useCallback(async E=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Nf(d,E),await w(d),H.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,w,t]),I=_e.useCallback(async(E,R)=>{if(d){v(E.id),u(V=>V.map(B=>B.id===E.id?{...B,enabled:R}:B));try{await Nf(d,{...E,enabled:R}),await w(d,{silent:!0})}catch(V){H.error(V instanceof Error?V.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await w(d,{silent:!0})}finally{v(null)}}},[d,w,t]),T=_e.useCallback(async E=>{if(!(!d||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:E.name})))){v(E.id);try{await I6(d,E.id),await w(d,{silent:!0}),H.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(V){H.error(V instanceof Error?V.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{v(null)}}},[d,w,t]),P=_e.useCallback(async E=>{if(d){v(E.id);try{await P6(d,E.id),await Promise.all([w(d,{silent:!0}),pd()]),H.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(R){H.error(R instanceof Error?R.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{v(null)}}},[d,w,t]),D=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(as,{value:d||"__none",onValueChange:E=>{const R=E==="__none"?"":E;p(R),R?w(R):u([])},children:[s.jsx(is,{className:r?"w-full":void 0,children:C?s.jsx(fs,{children:k(C)}):s.jsx(fs,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(os,{children:[a.length===0?s.jsx(Mt,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,a.map(E=>s.jsx(Mt,{value:E.id,children:k(E)},E.id))]})]})]}),S=()=>{h(null),y(!0)},M=s.jsxs("div",{className:"space-y-4",children:[r?D:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[D,s.jsxs(be,{onClick:S,disabled:!d,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})]}),s.jsx("div",{className:"min-h-[280px]",children:f?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):m.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(d?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:m.map(E=>{const R=j===E.id,V=E.state?.lastStatus||"idle",B=q6[V],$=t(V==="success"?"sessions.scheduledTasks.dialog.status.success":V==="error"?"sessions.scheduledTasks.dialog.status.error":V==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),O=E.state?.nextRunAt,_=E.state?.lastRunAt;return s.jsxs("div",{className:ye("rounded-lg border border-border p-4 transition-opacity",!E.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:E.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:H6(E,t)})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(A,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),O?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:Rf(O,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:G6(O)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(A,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),V==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):_?s.jsxs(s.Fragment,{children:[B.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${B.tone})`},children:[s.jsx(A,{name:B.Icon,className:"h-3.5 w-3.5"}),$]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:Rf(_,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),E.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:J6("error"),children:[s.jsx(A,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:E.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:ye("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",E.enabled?"text-foreground":"text-muted-foreground",R&&"cursor-not-allowed opacity-50"),children:[s.jsx(vs,{checked:E.enabled,onChange:q=>{I(E,q)},ariaLabel:E.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:E.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:E.name}),disabled:R}),E.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>{P(E)},disabled:R,children:[s.jsx(A,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>{h(E),y(!0)},disabled:R,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:E.name}),children:[s.jsx(A,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(be,{variant:"destructive",size:"sm",onClick:()=>{T(E)},disabled:R,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:E.name}),children:s.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},E.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(zr,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:E=>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")}),E]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(be,{className:"w-full",onClick:S,disabled:!d,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:M}):s.jsx(us,{open:e,onOpenChange:n,children:s.jsxs(ds,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(Ns,{children:t("sessions.scheduledTasks.dialog.description")})]}),M]})}),s.jsx(V6,{open:x,task:g,onOpenChange:y,onSave:N})]})}const Q6=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(c=>bs(c.path)??c.path).filter(c=>!!c)]),i=(c=>c.filter(d=>po(d,t.normalizedPath,r)))(e.archivedSessions),o=e.sessions.filter(c=>c.time?.archived||bs(c.directory??null)?!1:po(c,t.normalizedPath,r));return Pi([...i,...o])},X6=t=>{const e=ot.c(12),{normalizedProjects:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:o,isSessionsLoading:c,foldersMap:d,createFolder:p,addSessionToFolder:m,cleanupSessions:u}=t;let f,b;e[0]!==m||e[1]!==a||e[2]!==i||e[3]!==u||e[4]!==p||e[5]!==d||e[6]!==c||e[7]!==o||e[8]!==n||e[9]!==r?(f=()=>{c||n.forEach(x=>{const y=iu(x.normalizedPath),g=Q6(x,{sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:o}),h=new Set(g.map(Z6)),j=d[y]??[],v=new Map(j.map(eP));g.forEach(C=>{const k=By(C,x.normalizedPath),w=k.toLowerCase();let N=v.get(w);N||(N=p(y,k),v.set(w,N)),N.sessionIds.includes(C.id)||m(y,N.id,C.id)}),u(y,h)})},b=[n,r,a,i,o,c,d,p,m,u],e[0]=m,e[1]=a,e[2]=i,e[3]=u,e[4]=p,e[5]=d,e[6]=c,e[7]=o,e[8]=n,e[9]=r,e[10]=f,e[11]=b):(f=e[10],b=e[11]),l.useEffect(f,b)};function Z6(t){return t.id}function eP(t){return[t.name.toLowerCase(),t]}const tP=t=>{const e=ot.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:a,availableWorktreesByProject:i,projectRepoStatus:o,projectRootBranches:c,lastRepoStatus:d,buildGroupedSessions:p,hasSessionSearchQuery:m,normalizedSessionSearchQuery:u,filterSessionNodesForSearch:f,buildGroupSearchText:b,foldersMap:x}=t;let y;if(e[0]!==i||e[1]!==p||e[2]!==a||e[3]!==r||e[4]!==d||e[5]!==n||e[6]!==o||e[7]!==c){let P;e[9]!==i||e[10]!==p||e[11]!==a||e[12]!==r||e[13]!==d||e[14]!==o||e[15]!==c?(P=D=>{const S=Pi([...r(D),...a(D)]),M=i.get(D.normalizedPath)??[],E=o.has(D.id)?!!o.get(D.id):d,R=p(S,D.normalizedPath,M,c.get(D.id)??null,E);return{project:D,groups:R}},e[9]=i,e[10]=p,e[11]=a,e[12]=r,e[13]=d,e[14]=o,e[15]=c,e[16]=P):P=e[16],y=n.map(P),e[0]=i,e[1]=p,e[2]=a,e[3]=r,e[4]=d,e[5]=n,e[6]=o,e[7]=c,e[8]=y}else y=e[8];const g=y,h=g;let j;if(e[17]!==b||e[18]!==f||e[19]!==x||e[20]!==m||e[21]!==u||e[22]!==h){e:{const P=new WeakMap;if(!m){j=P;break e}const D=S=>S.reduce((M,E)=>M+1+D(E.children),0);h.forEach(S=>{S.groups.forEach(M=>{const E=f(M.sessions,u),R=D(E),V=b(M).includes(u),B=bs(M.directory??null),O=(B?x[B]??[]:[]).filter(_=>_.name.toLowerCase().includes(u)).length;P.set(M,{filteredNodes:E,matchedSessionCount:R,folderNameMatchCount:O,groupMatches:V,hasMatch:V||R>0||O>0})})}),j=P}e[17]=b,e[18]=f,e[19]=x,e[20]=m,e[21]=u,e[22]=h,e[23]=j}else j=e[23];const v=j;let C;e:{if(!m){C=h;break e}let P;if(e[24]!==v||e[25]!==h){let D;e[27]!==v?(D=S=>({...S,groups:S.groups.filter(M=>v.get(M)?.hasMatch===!0)}),e[27]=v,e[28]=D):D=e[28],P=h.map(D).filter(sP),e[24]=v,e[25]=h,e[26]=P}else P=e[26];C=P}const k=C,w=m?k:h;let N;e:{if(!m){N=0;break e}let P;if(e[29]!==v||e[30]!==w){let D;e[32]!==v?(D=(S,M)=>S+M.groups.reduce((E,R)=>{const V=v.get(R);if(!V)return E;const B=V.folderNameMatchCount+(V.groupMatches?1:0);return E+V.matchedSessionCount+B},0),e[32]=v,e[33]=D):D=e[33],P=w.reduce(D,0),e[29]=v,e[30]=w,e[31]=P}else P=e[31];N=P}const I=N;let T;return e[34]!==v||e[35]!==g||e[36]!==I||e[37]!==k||e[38]!==w||e[39]!==h?(T={projectSections:g,visibleProjectSections:h,groupSearchDataByGroup:v,searchableProjectSections:k,sectionsForRender:w,searchMatchCount:I},e[34]=v,e[35]=g,e[36]=I,e[37]=k,e[38]=w,e[39]=h,e[40]=T):T=e[40],T};function sP(t){return t.groups.length>0}const nP=t=>{const e=ot.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:a,setActiveSessionByProject:i,currentSessionId:o,handleSessionSelect:c,newSessionDraftOpen:d,mobileVariant:p,openNewSessionDraft:m,setActiveMainTab:u,setSessionSwitcherOpen:f,sessions:b,worktreeMetadata:x}=t;let y,g;if(e[0]!==n){g=new Map,y=new Map;const D=(S,M,E,R)=>{g.has(S)||g.set(S,new Map);const V=g.get(S);R.forEach(B=>{const $=bs(B.worktree?.path??B.session.directory??E??M);V.set(B.session.id,{directory:$}),y.has(S)||y.set(S,{id:B.session.id,directory:$}),B.children.length>0&&D(S,M,$,B.children)})};n.forEach(S=>{S.groups.forEach(M=>{D(S.project.id,S.project.normalizedPath,M.directory,M.sessions)})}),e[0]=n,e[1]=y,e[2]=g}else y=e[1],g=e[2];let h;e[3]!==y||e[4]!==g?(h={metaByProject:g,firstSessionByProject:y},e[3]=y,e[4]=g,e[5]=h):h=e[5];const j=h,v=l.useRef(null);let C,k;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]!==j||e[15]!==u||e[16]!==i||e[17]!==f?(C=()=>{if(!r||d||v.current===r)return;const D=n.find($=>$.project.id===r);if(!D)return;v.current=r;const S=j.metaByProject.get(r);if(o&&S&&S.has(o)){i($=>{if($.get(r)===o)return $;const O=new Map($);return O.set(r,o),O});return}if(!S||S.size===0){u("chat"),p&&f(!1),m({directoryOverride:D.project.normalizedPath});return}const M=a.get(r),E=M&&S.has(M)?M:null,R=j.firstSessionByProject.get(r)?.id??null,V=E??R;if(!V||V===o)return;const B=S.get(V)?.directory??null;c(V,B,!1,r)},k=[r,a,o,c,d,p,m,n,j,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]=j,e[15]=u,e[16]=i,e[17]=f,e[18]=C,e[19]=k):(C=e[18],k=e[19]),l.useLayoutEffect(C,k);let w,N;e[20]!==r||e[21]!==o||e[22]!==j||e[23]!==i?(w=()=>{if(!r||!o)return;const D=j.metaByProject.get(r);!D||!D.has(o)||i(S=>{if(S.get(r)===o)return S;const M=new Map(S);return M.set(r,o),M})},N=[r,o,j,i],e[20]=r,e[21]=o,e[22]=j,e[23]=i,e[24]=w,e[25]=N):(w=e[24],N=e[25]),l.useEffect(w,N);let I;if(e[26]!==o||e[27]!==b||e[28]!==x){e:{if(!o){I=null;break e}const D=x.get(o)?.path;if(D){I=bs(D)??D;break e}let S;e[30]!==o?(S=E=>E.id===o,e[30]=o,e[31]=S):S=e[31];const M=b.find(S);if(!M){I=null;break e}I=bs(M.directory??null)}e[26]=o,e[27]=b,e[28]=x,e[29]=I}else I=e[29];const T=I;let P;return e[32]!==T?(P={currentSessionDirectory:T},e[32]=T,e[33]=P):P=e[33],P},rP=t=>{const e=ot.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(aP)),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 aP(t){return[t.id,t]}const Xo=t=>!!t.time?.archived,iP=t=>{const{t:e}=ft(),n=l.useCallback(o=>[o.label,o.branch??"",o.description??"",o.directory??""].join(" ").toLowerCase(),[]),r=l.useCallback(o=>{const c=bs(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=bs(c??null),f=Pi(o).sort((D,S)=>bi(D,S,t.pinnedSessionIds)),b=new Map(f.map(D=>[D.id,D])),x=new Map;f.forEach(D=>{const S=D.parentID;if(!S)return;const M=b.get(S);if(!M||Xo(M)!==Xo(D))return;const E=x.get(S)??[];E.push(D),x.set(S,E)}),x.forEach(D=>D.sort((S,M)=>bi(S,M,t.pinnedSessionIds)));const y=new Map;d.forEach(D=>{if(D.path){const S=bs(D.path)??D.path;y.set(S,D)}});const g=D=>{const S=bs(D.directory??null),M=t.worktreeMetadata.get(D.id)??null;if(M)return M;if(S){const E=y.get(S)??null;if(E&&S!==u)return E}return null},h=D=>{const S=x.get(D.id)??[];return{session:D,children:S.map(M=>h(M)),worktree:g(D)}},j=f.filter(D=>{const S=D.parentID;if(!S)return!0;const M=b.get(S);return M?Xo(M)!==Xo(D):!0}),v=new Map,C="__archived__",k=D=>{if(D.time?.archived)return C;const S=bs(t.worktreeMetadata.get(D.id)?.path??null),M=bs(D.directory??null);if(!S&&!M)return C;const E=bs(D.project?.worktree??null),R=S??M??E;return R?R!==u&&y.has(R)?R:R===u?u??"__project_root__":C:C};j.forEach(D=>{const S=h(D),M=k(D);v.has(M)||v.set(M,[]),v.get(M)?.push(S)});const w=u??"__project_root__",N=[{id:"root",label:m&&p&&p!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:p}):e("sessions.sidebar.grouping.projectRoot"),branch:p??null,description:u?mo(u,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:u,folderScopeKey:u,sessions:v.get(w)??[]}],I=new Map;d.forEach(D=>{const S=bs(D.path)??D.path,M=v.get(S)??[],E=M.length>0,R=M.reduce((V,B)=>{const $=Number(B.session.time?.updated??B.session.time?.created??0);return Number.isFinite($)?Math.max(V,$):V},0);I.set(S,{hasActiveSession:E,lastUpdatedAt:R})}),[...d].sort((D,S)=>{const M=bs(D.path)??D.path,E=bs(S.path)??S.path,R=I.get(M)??{hasActiveSession:!1,lastUpdatedAt:0},V=I.get(E)??{hasActiveSession:!1,lastUpdatedAt:0};if(R.hasActiveSession!==V.hasActiveSession)return R.hasActiveSession?-1:1;if(R.hasActiveSession&&V.hasActiveSession)return V.lastUpdatedAt-R.lastUpdatedAt;const B=(D.label||D.branch||D.name||D.path||"").toLowerCase(),$=(S.label||S.branch||S.name||S.path||"").toLowerCase();return B.localeCompare($)}).forEach(D=>{const S=bs(D.path)??D.path,M=t.gitBranches.get(S)?.trim()||null,E=D.branch?.trim()||null,V=!!(M&&E&&D.label&&nm(D.label)===nm(E))?M:D.label||D.name||Ga(S,t.homeDirectory)||S;N.push({id:`worktree:${S}`,label:V,branch:M||E,description:mo(S,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:D,directory:S,folderScopeKey:S,sessions:v.get(S)??[]})});const P=v.get(C)??[];return P.length>0&&N.push({id:"archived",label:e("sessions.sidebar.grouping.archived"),branch:null,description:e("sessions.sidebar.grouping.archivedDescription"),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&u?iu(u):null,sessions:P}),N},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:a,buildGroupedSessions:i}},oP=t=>{const e=ot.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)},lP=t=>{const e=ot.c(42),{t:n}=ft(),[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=(V,B,$,O)=>{if($)return;const _=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(O&&O!==t.activeProjectId&&t.setActiveProjectIdOnly(O),B&&B!==t.currentDirectory&&t.setDirectory(B,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),V===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(V),_();return}t.setCurrentSession(V,B??null),t.onSessionSelected?.(V),_()},e[2]=t,e[3]=d):d=e[3];const p=d;let m;e[4]!==t?(m=(V,B)=>{t.setEditingId(V),t.setEditTitle(B)},e[4]=t,e[5]=m):m=e[5];const u=m;let f;e[6]!==t?(f=async()=>{if(!t.editingId)return;const V=t.editTitle.trim();V&&await t.updateSessionTitle(t.editingId,V),t.setEditingId(null),t.setEditTitle("")},e[6]=t,e[7]=f):f=e[7];const b=f;let x;e[8]!==t?(x=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=x):x=e[9];const y=x;let g;e[10]!==t||e[11]!==n?(g=async V=>{const B=await t.shareSession(V.id);B&&B.share?.url?H.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):H.error(n("sessions.sidebar.session.share.error"))},e[10]=t,e[11]=n,e[12]=g):g=e[12];const h=g;let j;e[13]!==n?(j=(V,B)=>{En(V).then($=>{if(!$.ok){H.error(n("sessions.sidebar.session.share.copyUrlError"));return}a(B),i.current&&clearTimeout(i.current),i.current=window.setTimeout(()=>{a(null),i.current=null},2e3)}).catch(()=>{H.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=j):j=e[14];const v=j;let C;e[15]!==t||e[16]!==n?(C=async V=>{await t.unshareSession(V)?H.success(n("sessions.sidebar.session.unshare.success")):H.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=C):C=e[17];const k=C;let w;e[18]!==t.childrenMap?(w=V=>{const B=[],$=O=>{(t.childrenMap.get(O)??[]).forEach(q=>{B.push(q),$(q.id)})};return $(V),B},e[18]=t.childrenMap,e[19]=w):w=e[19];const N=w,I=dP;let T;e[20]!==t||e[21]!==N||e[22]!==n?(T=async(V,B,$)=>{const O=B?.archivedBucket===!0,_=$?.descendantIds??I(N(V.id),O).map(uP);if(_.length===0){(O?await t.deleteSession(V.id):await t.archiveSession(V.id))?H.success(n(O?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):H.error(n(O?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const q=[V.id,..._];if(O){const{deletedIds:Z,failedIds:ie}=await t.deleteSessions(q);Z.length>0&&H.success(Z.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:Z.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:Z.length})),ie.length>0&&H.error(ie.length===1?n("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ie.length}):n("sessions.sidebar.bulkActions.failedDeletePlural",{count:ie.length}));return}const{archivedIds:L,failedIds:J}=await t.archiveSessions(q);L.length>0&&H.success(L.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:L.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:L.length})),J.length>0&&H.error(J.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:J.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:J.length}))},e[20]=t,e[21]=N,e[22]=n,e[23]=T):T=e[23];const P=T;let D;e[24]!==t||e[25]!==N||e[26]!==P?(D=(V,B)=>{const $=B?.archivedBucket===!0,O=I(N(V.id),$).map(mP);if(!t.showDeletionDialog){P(V,B,{descendantIds:O});return}t.setDeleteSessionConfirm({session:V,descendantCount:O.length,descendantIds:O,archivedBucket:$})},e[24]=t,e[25]=N,e[26]=P,e[27]=D):D=e[27];const S=D;let M;e[28]!==t||e[29]!==P?(M=async()=>{if(!t.deleteSessionConfirm)return;const{session:V,archivedBucket:B,descendantIds:$}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await P(V,{archivedBucket:B},{descendantIds:$})},e[28]=t,e[29]=P,e[30]=M):M=e[30];const E=M;let R;return e[31]!==E||e[32]!==r||e[33]!==y||e[34]!==v||e[35]!==S||e[36]!==b||e[37]!==u||e[38]!==p||e[39]!==h||e[40]!==k?(R={copiedSessionId:r,handleSessionSelect:p,handleSessionDoubleClick:u,handleSaveEdit:b,handleCancelEdit:y,handleShareSession:h,handleCopyShareUrl:v,handleUnshareSession:k,handleDeleteSession:S,confirmDeleteSession:E},e[31]=E,e[32]=r,e[33]=y,e[34]=v,e[35]=S,e[36]=b,e[37]=u,e[38]=p,e[39]=h,e[40]=k,e[41]=R):R=e[41],R};function cP(t){return!t.time?.archived}function dP(t,e){return e?t:t.filter(cP)}function uP(t){return t.id}function mP(t){return t.id}const pP=["project:active:","project:archived:","recent:active:","recent:archived:"],fP=t=>{const{isVSCode:e,hasLoadedGlobalSessions:n,safeStorage:r,keys:a,sessions:i,setPinnedSessionIds:o,groupOrderByProject:c,activeSessionByProject:d,collapsedGroups:p,setExpandedParents:m,setCollapsedProjects:u}=t,f=l.useRef(null),b=l.useRef(null),x=l.useCallback(()=>{if(e)return;const g=b.current;if(b.current=null,f.current=null,!g)return;const{projects:h}=Cs.getState(),j=h.map(v=>({...v,sidebarCollapsed:g.has(v.id)}));ks({projects:j}).catch(()=>{})},[e]),y=l.useCallback(g=>{typeof window>"u"||e||(b.current=g,f.current!==null&&window.clearTimeout(f.current),f.current=window.setTimeout(()=>{x()},700))},[e,x]);return l.useEffect(()=>()=>{typeof window<"u"&&f.current!==null&&window.clearTimeout(f.current),f.current=null,b.current=null},[]),l.useEffect(()=>{try{const g=r.getItem(a.sessionExpanded);if(g){const j=JSON.parse(g);Array.isArray(j)&&m(new Set(j.filter(v=>typeof v=="string")))}else{const j=r.getItem(a.sessionExpandedLegacy);if(j){try{const v=JSON.parse(j);if(Array.isArray(v)){const C=new Set;if(v.forEach(k=>{typeof k!="string"||k.length===0||pP.forEach(w=>C.add(`${w}${k}`))}),C.size>0){m(C);try{r.setItem(a.sessionExpanded,JSON.stringify(Array.from(C)))}catch{}}}}catch{}try{r.removeItem?.(a.sessionExpandedLegacy)}catch{}}}const h=r.getItem(a.projectCollapse);if(h){const j=JSON.parse(h);Array.isArray(j)&&u(new Set(j.filter(v=>typeof v=="string")))}}catch{}},[a.projectCollapse,a.sessionExpanded,a.sessionExpandedLegacy,r,u,m]),l.useEffect(()=>{if(!n)return;const g=new Set(i.map(h=>h.id));o(h=>{let j=!1;const v=new Set;return h.forEach(C=>{g.has(C)?v.add(C):j=!0}),j?v:h})},[n,i,o]),l.useEffect(()=>{try{const g=Object.fromEntries(c.entries());r.setItem(a.groupOrder,JSON.stringify(g))}catch{}},[c,a.groupOrder,r]),l.useEffect(()=>{try{const g=Object.fromEntries(d.entries());r.setItem(a.projectActiveSession,JSON.stringify(g))}catch{}},[d,a.projectActiveSession,r]),l.useEffect(()=>{try{r.setItem(a.groupCollapse,JSON.stringify(Array.from(p)))}catch{}},[p,a.groupCollapse,r]),{scheduleCollapsedProjectsPersist:y}},hP=t=>{const e=ot.c(26),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:a,setProjectRootBranches:i}=t,{git:o}=_n(),c=Ys(gP);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(j=>{c(j.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 j=new Map;n.forEach(v=>{j.set(v.id,r.get(v.normalizedPath)?.isGitRepo??null)}),a(j)},u=[n,r,a],e[6]=r,e[7]=n,e[8]=a,e[9]=m,e[10]=u):(m=e[9],u=e[10]),l.useEffect(m,u);let f;if(e[11]!==r||e[12]!==n){let j;e[14]!==r?(j=v=>{const C=r.get(v.normalizedPath)?.branch??"";return`${v.id}:${C}`},e[14]=r,e[15]=j):j=e[15],f=n.map(j).join("|"),e[11]=r,e[12]=n,e[13]=f}else f=e[13];const b=f;let x;e[16]===Symbol.for("react.memo_cache_sentinel")?(x=new Map,e[16]=x):x=e[16];const y=l.useRef(x);let g;e[17]!==r||e[18]!==n||e[19]!==i?(g=()=>{let j=!1;const v=setTimeout(()=>{(async()=>{const k=new Set(n.map(xP));for(const T of y.current.keys())k.has(T)||y.current.delete(T);const w=n.filter(T=>{const P=r.get(T.normalizedPath);if(P?.isGitRepo===!1)return y.current.delete(T.id),!1;if(P?.isGitRepo!==!0||P.branch===null)return!1;const D=P.branch.trim(),S=`${T.normalizedPath}\0${D}`,M=y.current.get(T.id);return M===void 0||M!==S});if(w.length===0)return;const N=await dg(w,2,async T=>{const P=r.get(T.normalizedPath)?.branch?.trim()??"",D=`${T.normalizedPath}\0${P}`,S=await No(T.normalizedPath,P?{knownBranch:P}:void 0).catch(bP);return{id:T.id,inputKey:D,branch:S}});if(j)return;const I=N.filter(yP);I.length!==0&&(i(T=>{const P=new Map(T);return I.forEach(D=>{const{id:S,branch:M}=D;M&&P.set(S,M)}),P}),I.forEach(T=>{const{id:P,inputKey:D}=T;y.current.set(P,D)}))})()},150);return()=>{j=!0,clearTimeout(v)}},e[17]=r,e[18]=n,e[19]=i,e[20]=g):g=e[20];let h;e[21]!==r||e[22]!==n||e[23]!==b||e[24]!==i?(h=[n,b,r,i],e[21]=r,e[22]=n,e[23]=b,e[24]=i,e[25]=h):h=e[25],l.useEffect(g,h)};function gP(t){return t.ensureStatus}function xP(t){return t.id}function bP(){return null}function yP(t){return t.branch}const vP=t=>{const e=ot.c(14),{isVSCode:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i}=t;let o;e[0]!==r?(o=new Map,r.forEach(b=>{const x=bs(b.directory??null)??bs(b.project?.worktree??null);if(!x)return;const y=o.get(x)??[];y.push(b),o.set(x,y)}),e[0]=r,e[1]=o):o=e[1];const c=o;let d;e[2]!==i||e[3]!==n||e[4]!==c?(d=b=>{const x=n?[]:i.get(b.normalizedPath)??[],y=[b.normalizedPath,...x.map(wP).filter(jP)],g=new Set,h=[];return y.forEach(j=>{(c.get(j)??[]).forEach(C=>{g.has(C.id)||(g.add(C.id),h.push(C))})}),h},e[2]=i,e[3]=n,e[4]=c,e[5]=d):d=e[5];const p=d;let m;e[6]!==a||e[7]!==i||e[8]!==n||e[9]!==r?(m=b=>{if(n){const v=a.filter(k=>{const w=bs(k.directory??null),N=bs(k.project?.worktree??null);return w?w===b.normalizedPath:N===b.normalizedPath}),C=r.filter(k=>k.time?.archived||bs(k.directory??null)?!1:bs(k.project?.worktree??null)===b.normalizedPath);return Pi([...v,...C])}const x=n?[]:i.get(b.normalizedPath)??[],y=new Set([b.normalizedPath,...x.map(NP).filter(SP)]),h=(v=>v.filter(C=>po(C,b.normalizedPath,y)))(a),j=r.filter(v=>{if(v.time?.archived||bs(v.directory??null))return!1;const k=bs(v.project?.worktree??null);return k?k===b.normalizedPath||k.startsWith(`${b.normalizedPath}/`):!1});return Pi([...h,...j])},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 wP(t){return bs(t.path)??t.path}function jP(t){return!!t}function NP(t){return bs(t.path)??t.path}function SP(t){return!!t}const kP=t=>{const e=ot.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(x=>{const y=bs(x.directory??null);if(!y)return;const g=u.get(y);if(g){g.add(x.id);return}u.set(y,new Set([x.id]))}),i.forEach(x=>{const y=iu(x.normalizedPath),g=o?[]:c.get(x.normalizedPath)??[],h=new Set([x.normalizedPath,...g.map(CP).filter(IP)]),j=Pi([...a,...r.filter(v=>v.time?.archived||bs(v.directory??null)?!1:po(v,x.normalizedPath,h))]).filter(v=>po(v,x.normalizedPath,h));u.set(y,new Set(j.map(PP)))});const f=er.getState().foldersMap;new Set([...Object.keys(f),...u.keys()]).forEach(x=>{d(x,u.get(x)??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 CP(t){return bs(t.path)??t.path}function IP(t){return!!t}function PP(t){return t.id}const AP=t=>{const e=ot.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:a}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[o,c]=l.useState(i);let d;e[1]!==n||e[2]!==a?(d=()=>{if(!n)return;const m=new IntersectionObserver(u=>{u.forEach(f=>{const b=f.target.dataset.projectId;b&&c(x=>{const y=new Set(x);return f.isIntersecting?y.delete(b):y.add(b),y})})},{threshold:0});return a.current.forEach(u=>{u&&m.observe(u)}),()=>m.disconnect()},e[1]=n,e[2]=a,e[3]=d):d=e[3];let 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},DP=t=>{const e=ot.c(85),{folder:n,sessions:r,subFolderItems:a,isCollapsed:i,onToggle:o,onRename:c,onDelete:d,renderSessionNode:p,groupDirectory:m,projectId:u,mobileVariant:f,alwaysShowActions:b,isRenaming:x,renameDraft:y,onRenameDraftChange:g,onRenameSave:h,onRenameCancel:j,droppableRef:v,isDropTarget:C,onNewSession:k,onNewSubFolder:w,depth:N,hideActions:I,archivedBucket:T}=t,D=b===void 0?f===void 0?!1:f:b,S=x===void 0?!1:x,M=y===void 0?"":y,E=C===void 0?!1:C,R=N===void 0?0:N,V=I===void 0?!1:I,B=T===void 0?!1:T,{t:$}=ft(),[O,_]=l.useState(!1),[q,L]=l.useState(""),J=l.useRef(null),Z=S||O,ie=S?M:q;let ne;e[0]!==n.name?(ne=()=>{L(n.name),_(!0)},e[0]=n.name,e[1]=ne):ne=e[1];const me=ne;let pe;e[2]!==ie||e[3]!==n.name||e[4]!==S||e[5]!==c||e[6]!==h?(pe=()=>{const U=ie.trim();U&&U!==n.name&&c(U),S&&h&&h(),_(!1),L("")},e[2]=ie,e[3]=n.name,e[4]=S,e[5]=c,e[6]=h,e[7]=pe):pe=e[7];const G=pe;let K;e[8]!==S||e[9]!==j?(K=()=>{S&&j&&j(),_(!1),L("")},e[8]=S,e[9]=j,e[10]=K):K=e[10];const Q=K;let W;e[11]!==S||e[12]!==g?(W=U=>{S&&g?g(U):L(U)},e[11]=S,e[12]=g,e[13]=W):W=e[13];const de=W;let ge,ve;e[14]!==S?(ge=()=>{if(!S)return;const U=()=>{const Oe=J.current;Oe&&(Oe.focus(),Oe.select())},oe=requestAnimationFrame(U),Te=window.setTimeout(U,0);return()=>{cancelAnimationFrame(oe),window.clearTimeout(Te)}},ve=[S],e[14]=S,e[15]=ge,e[16]=ve):(ge=e[15],ve=e[16]),l.useEffect(ge,ve);const te=i?"folder":"folder-open",ce=R>0&&"ml-3";let xe;e[17]!==ce?(xe=ye("oc-folder",ce),e[17]=ce,e[18]=xe):xe=e[18];const se=E&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let ue;e[19]!==se?(ue=ye("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",se),e[19]=se,e[20]=ue):ue=e[20];const Y=Z?void 0:o,Se=Z?void 0:"button",fe=Z?void 0:0;let Ce;e[21]!==o||e[22]!==Z?(Ce=Z?void 0:U=>{(U.key==="Enter"||U.key===" ")&&(U.preventDefault(),o())},e[21]=o,e[22]=Z,e[23]=Ce):Ce=e[23];let Ie;e[24]!==n.name||e[25]!==i||e[26]!==$?(Ie=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]=Ie):Ie=e[27];const ke=B?D?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let X;e[28]!==ke?(X=ye("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",ke),e[28]=ke,e[29]=X):X=e[29];const ae=E?"text-primary":"text-muted-foreground";let je;e[30]!==ae?(je=ye("h-3.5 w-3.5 flex-shrink-0",ae),e[30]=ae,e[31]=je):je=e[31];let le;e[32]!==te||e[33]!==je?(le=s.jsx(A,{name:te,className:je}),e[32]=te,e[33]=je,e[34]=le):le=e[34];let Ne;e[35]!==ie||e[36]!==n.name||e[37]!==Q||e[38]!==de||e[39]!==G||e[40]!==i||e[41]!==E||e[42]!==Z||e[43]!==r||e[44]!==$?(Ne=Z?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:EP,onMouseDown:MP,onSubmit:U=>{U.preventDefault(),G()},children:[s.jsx("input",{ref:J,value:ie,onChange:U=>de(U.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:$("sessions.sidebar.folderItem.namePlaceholder"),onClick:RP,onPointerDown:FP,onMouseDown:OP,onKeyDown:U=>{if(U.key==="Escape"){U.stopPropagation(),Q();return}(U.key===" "||U.key==="Enter")&&U.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:LP,onPointerDown:$P,onMouseDown:_P,children:s.jsx(A,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:U=>{U.stopPropagation(),Q()},onPointerDown:BP,onMouseDown:VP,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsx("span",{className:ye("typography-ui-label font-semibold truncate",E?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),i?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=ie,e[36]=n.name,e[37]=Q,e[38]=de,e[39]=G,e[40]=i,e[41]=E,e[42]=Z,e[43]=r,e[44]=$,e[45]=Ne):Ne=e[45];let Me;e[46]!==X||e[47]!==le||e[48]!==Ne?(Me=s.jsxs("div",{className:X,children:[le,Ne]}),e[46]=X,e[47]=le,e[48]=Ne,e[49]=Me):Me=e[49];let Ve;e[50]!==D||e[51]!==B||e[52]!==R||e[53]!==n.name||e[54]!==me||e[55]!==V||e[56]!==d||e[57]!==k||e[58]!==w||e[59]!==Z||e[60]!==$?(Ve=!Z&&(!V||B)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:ye("flex items-center gap-0.5 transition-opacity",D?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",B&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!B&&k?s.jsx("button",{type:"button",onClick:U=>{U.stopPropagation(),k()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":$("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:$("sessions.sidebar.project.actions.newSession"),children:s.jsx(A,{name:"add",className:"h-3.5 w-3.5"})}):null,!B&&w&&R===0?s.jsx("button",{type:"button",onClick:U=>{U.stopPropagation(),w()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":$("sessions.sidebar.folderItem.newSubfolderAria",{folderName:n.name}),title:$("sessions.sidebar.folderItem.newSubfolder"),children:s.jsx(A,{name:"folder-add",className:"h-3.5 w-3.5"})}):null,B?null:s.jsx("button",{type:"button",onClick:U=>{U.stopPropagation(),me()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":$("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(A,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:U=>{U.stopPropagation(),d()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":B?$("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):$("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[50]=D,e[51]=B,e[52]=R,e[53]=n.name,e[54]=me,e[55]=V,e[56]=d,e[57]=k,e[58]=w,e[59]=Z,e[60]=$,e[61]=Ve):Ve=e[61];let we;e[62]!==v||e[63]!==ue||e[64]!==Y||e[65]!==Se||e[66]!==fe||e[67]!==Ce||e[68]!==Ie||e[69]!==Me||e[70]!==Ve?(we=s.jsxs("div",{ref:v,className:ue,onClick:Y,role:Se,tabIndex:fe,onKeyDown:Ce,"aria-label":Ie,children:[Me,Ve]}),e[62]=v,e[63]=ue,e[64]=Y,e[65]=Se,e[66]=fe,e[67]=Ce,e[68]=Ie,e[69]=Me,e[70]=Ve,e[71]=we):we=e[71];let ee;e[72]!==B||e[73]!==m||e[74]!==i||e[75]!==u||e[76]!==p||e[77]!==r||e[78]!==a||e[79]!==$?(ee=i?null:s.jsxs("div",{className:"pb-1 pl-2",children:[a,r.length>0?r.map(U=>p(U,0,m??null,u??null,B)):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]=B,e[73]=m,e[74]=i,e[75]=u,e[76]=p,e[77]=r,e[78]=a,e[79]=$,e[80]=ee):ee=e[80];let F;return e[81]!==xe||e[82]!==we||e[83]!==ee?(F=s.jsxs("div",{className:xe,children:[we,ee]}),e[81]=xe,e[82]=we,e[83]=ee,e[84]=F):F=e[84],F},TP=l.memo(DP);function EP(t){return t.stopPropagation()}function MP(t){return t.stopPropagation()}function RP(t){return t.stopPropagation()}function FP(t){return t.stopPropagation()}function OP(t){return t.stopPropagation()}function LP(t){return t.stopPropagation()}function $P(t){return t.stopPropagation()}function _P(t){return t.stopPropagation()}function BP(t){return t.stopPropagation()}function VP(t){return t.stopPropagation()}const zP=t=>{const e=ot.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}=Yx(d);let b;e[7]!==m?(b=h=>{h.stopPropagation(),m?.onPointerDown&&m.onPointerDown(h)},e[7]=m,e[8]=b):b=e[8];const x=b,y=f?"opacity-30":void 0;let g;return e[9]!==p||e[10]!==i||e[11]!==x||e[12]!==u||e[13]!==y?(g=s.jsx("div",{ref:u,...p,onPointerDown:x,className:y,children:i}),e[9]=p,e[10]=i,e[11]=x,e[12]=u,e[13]=y,e[14]=g):g=e[14],g},UP=t=>{const e=ot.c(11),{folderId:n,children:r}=t,a=`folder-drop:${n}`;let i;e[0]!==n?(i={type:"folder",folderId:n},e[0]=n,e[1]=i):i=e[1];let 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}=Qx(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},WP=t=>{const e=ot.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=io(hi(oo,o)),[d,p]=l.useState(null),[m,u]=l.useState("Session"),[f,b]=l.useState(null),[x,y]=l.useState(null);if(!n){let N;return e[1]!==i?(N=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=N):N=e[2],N}let g;e[3]!==a?(g=N=>{p(null),b(null),y(null);const{active:I,over:T}=N;if(!T)return;const P=I.data.current,D=T.data.current;P?.type==="session"&&P.sessionId&&D?.type==="folder"&&D.folderId&&a(P.sessionId,D.folderId)},e[3]=a,e[4]=g):g=e[4];const h=g;let j,v;e[5]===Symbol.for("react.memo_cache_sentinel")?(j=N=>{const I=N.active.data.current;if(I?.type==="session"&&I.sessionId){p(I.sessionId),u(I.sessionTitle??"Session");const T=N.active.rect.current.initial?.width,P=N.active.rect.current.initial?.height;b(typeof T=="number"?T:null),y(typeof P=="number"?P:null)}},v=()=>{p(null),b(null),y(null)},e[5]=j,e[6]=v):(j=e[5],v=e[6]);let C;e[7]!==x||e[8]!==d||e[9]!==m||e[10]!==f||e[11]!==r?(C=d&&r?s.jsxs("div",{style:{width:f?`${f}px`:"auto",height:x?`${x}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(A,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:m})]}):null,e[7]=x,e[8]=d,e[9]=m,e[10]=f,e[11]=r,e[12]=C):C=e[12];let k;e[13]!==C?(k=s.jsx(kl,{children:C}),e[13]=C,e[14]=k):k=e[14];let w;return e[15]!==i||e[16]!==h||e[17]!==c||e[18]!==k?(w=s.jsxs(lo,{sensors:c,collisionDetection:co,onDragStart:j,onDragCancel:v,onDragEnd:h,children:[i,k]}),e[15]=i,e[16]=h,e[17]=c,e[18]=k,e[19]=w):w=e[19],w},Ba=ar()(Ei(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"})),KP=50,HP=28;function GP(t){const{t:e}=ft(),{group:n,groupKey:r,projectId:a,hideGroupLabel:i,hasSessionSearchQuery:o,normalizedSessionSearchQuery:c,groupSearchDataByGroup:d,expandedSessionGroups:p,collapsedGroups:m,hideDirectoryControls:u,collapsedFolderIds:f,toggleFolderCollapse:b,renameFolder:x,deleteFolder:y,showDeletionDialog:g,setDeleteFolderConfirm:h,renderSessionNode:j,projectRepoStatus:v,lastRepoStatus:C,toggleGroupSessionLimit:k,mobileVariant:w,alwaysShowActions:N,activeProjectId:I,setActiveProjectIdOnly:T,setActiveMainTab:P,setSessionSwitcherOpen:D,openNewSessionDraft:S,addSessionToFolder:M,createFolderAndStartRename:E,renamingFolderId:R,renameFolderDraft:V,setRenameFolderDraft:B,setRenamingFolderId:$,pinnedSessionIds:O,sessionOrderIndex:_,prVisualStateByDirectoryBranch:q,onToggleCollapsedGroup:L,dragHandleProps:J,compactBodyPadding:Z=!1}=t,ie=l.useCallback((Ke,lt)=>{const xt=_.get(Ke.session.id),dt=_.get(lt.session.id);if(xt!==void 0||dt!==void 0){if(xt===void 0)return 1;if(dt===void 0)return-1;if(xt!==dt)return xt-dt}return bi(Ke.session,lt.session,O)},[O,_]),ne=o?d.get(n):null,me=Ba(Ke=>Ke.displayMode),pe=er(Ke=>Ke.foldersMap),G=me==="minimal",K=p.has(r),Q=o?!1:m.has(r),W=u?10:5,de=o?ne?.groupMatches===!0:!1,ge=o,ve=l.useMemo(()=>[...ge?ne?.filteredNodes??[]:n.sessions].sort(ie),[ie,n.sessions,ne?.filteredNodes,ge]),te=n.folderScopeKey??bs(n.directory??null),he=l.useMemo(()=>te?pe[te]??[]:[],[te,pe]),ce=l.useMemo(()=>{const Ke=new Map,lt=xt=>{xt.forEach(dt=>{Ke.set(dt.session.id,dt),dt.children.length>0&<(dt.children)})};return lt(ve),Ke},[ve]),xe=l.useMemo(()=>he.map(Ke=>{const lt=Ke.sessionIds.map(xt=>ce.get(xt)).filter(xt=>!!xt).sort(ie);return{folder:Ke,nodes:lt}}),[he,ce,ie]),se=l.useMemo(()=>{const Ke=new Map(xe.map(ut=>[ut.folder.id,ut])),lt=new Map;for(const{folder:ut}of xe){if(!ut.parentId)continue;const Nt=lt.get(ut.parentId);Nt?Nt.push(ut.id):lt.set(ut.parentId,[ut.id])}const xt=new Map,dt=ut=>{const Nt=xt.get(ut);if(Nt!==void 0)return Nt;const ts=Ke.get(ut);if(!ts)return xt.set(ut,!1),!1;const Vt=lt.get(ut)??[];if(n.isArchivedBucket&&ts.nodes.length===0){const Bt=Vt.some(Zt=>dt(Zt));return xt.set(ut,Bt),Bt}if(!o||ts.folder.name.toLowerCase().includes(c)||ts.nodes.length>0)return xt.set(ut,!0),!0;const ht=Vt.some(Bt=>dt(Bt));return xt.set(ut,ht),ht};return xe.filter(({folder:ut})=>dt(ut.id))},[xe,n.isArchivedBucket,o,c]),ue=l.useMemo(()=>new Set(se.flatMap(Ke=>Ke.folder.sessionIds)),[se]),Y=l.useMemo(()=>ve.filter(Ke=>!ue.has(Ke.session.id)),[ve,ue]),Se=l.useMemo(()=>se.filter(({folder:Ke})=>!Ke.parentId),[se]),fe=Y.length,Ce=n.isArchivedBucket||o||K?Y:Y.slice(0,W),Ie=fe-Ce.length,ke=n.isArchivedBucket===!0&&!o&&Ce.length>=KP,X=l.useRef(null),[ae,je]=l.useState(null),[le,Ne]=l.useState(0),Me=ih({count:Ce.length,getScrollElement:()=>ae,estimateSize:()=>HP,overscan:8,enabled:ke&&ae!==null,scrollMargin:le});l.useLayoutEffect(()=>{if(!ke){ae!==null&&je(null),le!==0&&Ne(0);return}const Ke=X.current;if(!Ke)return;let lt=ae;if(!lt||!lt.contains(Ke)){let dt=Ke.parentElement;for(;dt;){const ut=window.getComputedStyle(dt);if(ut.overflowY==="auto"||ut.overflowY==="scroll"){lt=dt;break}dt=dt.parentElement}if(lt!==ae){je(lt);return}}if(!lt)return;const xt=Ke.getBoundingClientRect().top-lt.getBoundingClientRect().top+lt.scrollTop;Ne(dt=>Math.abs(dt-xt)<1?dt:xt)}),l.useEffect(()=>{if(!ke||!ae)return;const Ke=new ResizeObserver(()=>{Me.measure()});return Ke.observe(ae),()=>Ke.disconnect()},[ke,ae,Me]);const Ve=Me.getTotalSize(),we=ke&&ae!==null?Me.getVirtualItems():[];if(o&&!de&&Se.length===0&&Y.length===0)return null;const ee=Ke=>{const lt=[],xt=dt=>{dt.forEach(ut=>{lt.push(ut.session),ut.children.length>0&&xt(ut.children)})};return xt(Ke),lt},F=ee(ve),U=a&&v.has(a)?!!v.get(a):C,oe=bs(n.directory??null),Te=n.branch?.trim()??null,Oe=oe&&Te?q.get(`${oe}::${Te}`)??null:null,Pe=!!(Oe&&n.branch),z=!Oe&&!n.isMain&&!!n.branch,De=Oe?.visualState??null,Qe=Oe&&Oe.state==="open"&&Oe.checks?e("sessions.sidebar.group.pr.checksPassed",{success:Oe.checks.success,total:Oe.checks.total}):null,et=Oe&&Oe.state==="open"&&Oe.checks?[Oe.checks.failure>0?e("sessions.sidebar.group.pr.failingCount",{count:Oe.checks.failure}):null,Oe.checks.pending>0?e("sessions.sidebar.group.pr.pendingCount",{count:Oe.checks.pending}):null].filter(Ke=>!!Ke).join(", "):null,Ze=Oe&&Oe.state==="open"?Oe.mergeableState==="blocked"||Oe.mergeableState==="dirty"?e("sessions.sidebar.group.pr.conflictsOrBlocked"):Oe.mergeableState==="clean"||Oe.canMerge===!0?e("sessions.sidebar.group.pr.mergeable"):null:null,We=Oe&&Oe.state==="open"&&Oe.mergeableState?e("sessions.sidebar.group.pr.mergeState",{state:Oe.mergeableState}):null,it=Oe?.base??null,qe=Oe?.head??null,st=(()=>{if(!Oe)return n.branch&&Vy(n.branch,n.label)?{label:n.branch,color:null}:null;switch(Oe.visualState){case"merged":return{label:e("sessions.sidebar.group.pr.status.merged"),color:"var(--pr-merged)"};case"open":return Oe.canMerge===!0||Oe.mergeableState==="clean"||Oe.checks?.state==="success"?{label:e("sessions.sidebar.group.pr.status.readyToMerge"),color:"var(--pr-open)"}:{label:e("sessions.sidebar.group.pr.status.open"),color:"var(--pr-open)"};case"blocked":return{label:Oe.mergeableState==="dirty"?e("sessions.sidebar.group.pr.status.mergeConflicts"):e("sessions.sidebar.group.pr.status.mergeBlocked"),color:"var(--pr-blocked)"};case"draft":return{label:e("sessions.sidebar.group.pr.status.draft"),color:"var(--pr-draft)"};case"closed":return{label:e("sessions.sidebar.group.pr.status.closed"),color:"var(--pr-closed)"};default:return null}})(),Je=st?.color??(De?`var(--pr-${De})`:void 0),Be=Ke=>{Ke.preventDefault(),Ke.stopPropagation();const lt=Oe?.url;lt&&rr(lt)},nt=(Ke,lt,xt)=>{const dt=se.filter(({folder:Vt})=>Vt.parentId===Ke.id),ut=dt.length>0?s.jsx(s.Fragment,{children:dt.map(({folder:Vt,nodes:Xt})=>nt(Vt,Xt,xt+1))}):void 0,Nt=Vt=>{const Xt=se.find(({folder:Bt})=>Bt.id===Vt)?.nodes??[],ht=se.filter(({folder:Bt})=>Bt.parentId===Vt);return[...ee(Xt),...ht.flatMap(({folder:Bt})=>Nt(Bt.id))]},ts=n.isArchivedBucket?Nt(Ke.id):[];return s.jsx(UP,{folderId:Ke.id,children:(Vt,Xt)=>s.jsx(TP,{folder:Ke,sessions:lt,subFolderItems:ut,isCollapsed:o?!1:f.has(Ke.id),onToggle:()=>b(Ke.id),onRename:ht=>{te&&x(te,Ke.id,ht)},onDelete:()=>{if(n.isArchivedBucket){Dr.requestDelete({sessions:ts,mode:"session"});return}if(!te)return;if(!g){y(te,Ke.id);return}const ht=se.filter(({folder:Zt})=>Zt.parentId===Ke.id).length,Bt=lt.length;h({scopeKey:te,folderId:Ke.id,folderName:Ke.name,subFolderCount:ht,sessionCount:Bt})},renderSessionNode:j,groupDirectory:n.directory,projectId:a,mobileVariant:w,alwaysShowActions:N,isRenaming:R===Ke.id,renameDraft:R===Ke.id?V:void 0,onRenameDraftChange:ht=>B(ht),onRenameSave:()=>{const ht=V.trim();ht&&te&&x(te,Ke.id,ht),$(null),B("")},onRenameCancel:()=>{$(null),B("")},droppableRef:Vt,isDropTarget:Xt,depth:xt,onNewSession:()=>{a&&a!==I&&T(a),P("chat"),w&&D(!1),S({directoryOverride:n.directory,targetFolderId:Ke.id})},onNewSubFolder:xt===0?()=>{te&&E(te,Ke.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},Ke.id)},Ge=()=>Se.map(({folder:Ke,nodes:lt})=>nt(Ke,lt,0)),at=!!(!n.isMain&&n.worktree),Ae=N?at?"pr-14":"pr-7":G?at?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":at?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",Le=s.jsxs(WP,{scopeKey:te,hasFolders:se.length>0,onSessionDroppedOnFolder:(Ke,lt)=>{te&&M(te,lt,Ke)},children:[Ge(),ke?s.jsx("div",{ref:X,style:{position:"relative",height:Ve>0?Ve:void 0,width:"100%"},children:we.map(Ke=>{const lt=Ce[Ke.index];return lt?s.jsx("div",{"data-index":Ke.index,ref:Me.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${Ke.start-le}px)`},children:j(lt,0,n.directory,a,!0)},Ke.key):null})}):Ce.map(Ke=>j(Ke,0,n.directory,a,n.isArchivedBucket===!0)),fe===0&&se.length===0?s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?e("sessions.sidebar.group.empty.noArchivedSessions"):e("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,Ie>0&&!K?s.jsx("button",{type:"button",onClick:()=>k(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:Ie===1?e("sessions.sidebar.group.showMoreSingle",{count:Ie}):e("sessions.sidebar.group.showMorePlural",{count:Ie})}):null,K&&fe>W?s.jsx("button",{type:"button",onClick:()=>k(r),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showFewer")}):null]}),ze=Z?"pb-2 pl-1":"pb-3 pl-4";return i?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:ye("oc-group-body",ze),children:Le})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:ye("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>L(r),role:"button",tabIndex:0,onKeyDown:Ke=>{(Ke.key==="Enter"||Ke.key===" ")&&(Ke.preventDefault(),L(r))},"aria-label":Q?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!Q,children:[s.jsx("div",{ref:J?.setActivatorNodeRef,className:ye("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",Ae),...J?.listeners??{},children:s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:Pe&&Oe?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 leading-none align-middle",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(A,{name:"git-branch",className:ye("h-3.5 w-3.5 shrink-0",N?"hidden":"group-hover/gh:hidden"),style:Je?{color:Je}:void 0}),s.jsx("span",{className:ye("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Q?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),Oe.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:Ke=>Ke.stopPropagation(),onClick:Be,children:["#",Oe.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",Oe.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:[it||qe?s.jsx("div",{className:"text-muted-foreground truncate",children:it&&qe?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:it}),s.jsx(A,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:qe})]}):s.jsx("span",{children:it??qe??""})}):null,We?s.jsx("div",{className:"text-muted-foreground truncate",children:We}):null,Ze||Qe?s.jsxs("div",{className:"text-muted-foreground truncate",children:[Ze??"",Ze&&Qe?" • ":"",Qe??"",et?` (${et})`:""]}):null]})})]}),s.jsx("span",{className:"ml-1 min-w-0 flex-1 truncate leading-none align-middle",children:n.branch})]}):n.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(A,{name:"archive",className:ye("h-3.5 w-3.5 shrink-0 text-muted-foreground",N?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:ye("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Q?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:to(n.label,c)})]}):!n.isMain||n.worktree?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(A,{name:"git-branch",className:ye("h-3.5 w-3.5 shrink-0 text-muted-foreground",N?"hidden":"group-hover/gh:hidden"),style:Je?{color:Je}:void 0}),s.jsx("span",{className:ye("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Q?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:to(n.label,c)})]}):to(n.label,c)}),z&&st?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(A,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!n.isMain||U?Pe&&Oe?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5 text-muted-foreground",style:Je?{color:Je}: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:[it||qe?s.jsx("div",{className:"text-muted-foreground truncate",children:it&&qe?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:it}),s.jsx(A,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:qe})]}):s.jsx("span",{children:it??qe??""})}):null,We?s.jsx("div",{className:"text-muted-foreground truncate",children:We}):null,Ze||Qe?s.jsxs("div",{className:"text-muted-foreground truncate",children:[Ze??"",Ze&&Qe?" • ":"",Qe??"",et?` (${et})`:""]}):null]})})]}):s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:Je?{color:Je}:void 0}):null,s.jsx("span",{className:ye("min-w-0 truncate text-[11px] font-medium",!st.color&&"text-muted-foreground/80"),style:st.color?{color:st.color}:void 0,children:st.label})]}):null]})}),n.isArchivedBucket&&F.length>0?s.jsx("div",{className:ye("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ke=>{Ke.stopPropagation(),Dr.requestDelete({sessions:F,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:ye("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ke=>{Ke.stopPropagation(),Dr.requestDelete({sessions:F,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:ye("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ke=>{Ke.stopPropagation(),a&&a!==I&&T(a),P("chat"),w&&D(!1),S({directoryOverride:n.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(A,{name:"add",className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),Q?null:s.jsx("div",{className:ye("oc-group-body",ze),children:Le})]})}function qP(t){const e=ot.c(196),{t:n}=ft(),{hideDirectoryControls:r,mobileVariant:a,handleOpenDirectoryDialog:i,openNewSessionDraft:o,canOpenMultiRun:c,openMultiRunLauncher:d,headerActionIconClass:p,headerActionButtonClass:m,isSessionSearchOpen:u,setIsSessionSearchOpen:f,sessionSearchInputRef:b,sessionSearchQuery:x,setSessionSearchQuery:y,hasSessionSearchQuery:g,searchMatchCount:h,collapseAllProjects:j,expandAllProjects:v,openScheduledTasksDialog:C,selectionModeEnabled:k,onToggleSelectionMode:w}=t,N=Ba(ZP),I=Ba(XP),T=Ba(QP),P=Ba(YP);if(r)return null;let D;e[0]!==n?(D=n("sessions.sidebar.header.actions.addProject"),e[0]=n,e[1]=D):D=e[1];let S;e[2]!==p?(S=s.jsx(A,{name:"folder-add",className:p}),e[2]=p,e[3]=S):S=e[3];let M;e[4]!==i||e[5]!==m||e[6]!==D||e[7]!==S?(M=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:m,"aria-label":D,children:S})}),e[4]=i,e[5]=m,e[6]=D,e[7]=S,e[8]=M):M=e[8];let E;e[9]!==n?(E=n("sessions.sidebar.header.actions.addProject"),e[9]=n,e[10]=E):E=e[10];let R;e[11]!==E?(R=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:E})}),e[11]=E,e[12]=R):R=e[12];let V;e[13]!==M||e[14]!==R?(V=s.jsxs(kt,{children:[M,R]}),e[13]=M,e[14]=R,e[15]=V):V=e[15];let B;e[16]!==m||e[17]!==p||e[18]!==a||e[19]!==o||e[20]!==n?(B=a?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:m,"aria-label":n("sessions.sidebar.header.actions.newSession"),children:s.jsx(A,{name:"chat-new",className:p})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newSession")})})]}):null,e[16]=m,e[17]=p,e[18]=a,e[19]=o,e[20]=n,e[21]=B):B=e[21];let $;e[22]!==n?($=n("sessions.sidebar.header.actions.newMultiRun"),e[22]=n,e[23]=$):$=e[23];const O=!c;let _;e[24]!==p?(_=s.jsx(zy,{className:p}),e[24]=p,e[25]=_):_=e[25];let q;e[26]!==m||e[27]!==d||e[28]!==$||e[29]!==O||e[30]!==_?(q=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:d,className:m,"aria-label":$,disabled:O,children:_})}),e[26]=m,e[27]=d,e[28]=$,e[29]=O,e[30]=_,e[31]=q):q=e[31];let L;e[32]!==n?(L=n("sessions.sidebar.header.actions.newMultiRun"),e[32]=n,e[33]=L):L=e[33];let J;e[34]!==L?(J=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:L})}),e[34]=L,e[35]=J):J=e[35];let Z;e[36]!==q||e[37]!==J?(Z=s.jsxs(kt,{children:[q,J]}),e[36]=q,e[37]=J,e[38]=Z):Z=e[38];let ie;e[39]!==n?(ie=n("sessions.sidebar.header.actions.scheduledTasks"),e[39]=n,e[40]=ie):ie=e[40];let ne;e[41]!==p?(ne=s.jsx(A,{name:"calendar-schedule",className:p}),e[41]=p,e[42]=ne):ne=e[42];let me;e[43]!==m||e[44]!==C||e[45]!==ie||e[46]!==ne?(me=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:C,className:m,"aria-label":ie,children:ne})}),e[43]=m,e[44]=C,e[45]=ie,e[46]=ne,e[47]=me):me=e[47];let pe;e[48]!==n?(pe=n("sessions.sidebar.header.actions.scheduledTasks"),e[48]=n,e[49]=pe):pe=e[49];let G;e[50]!==pe?(G=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:pe})}),e[50]=pe,e[51]=G):G=e[51];let K;e[52]!==me||e[53]!==G?(K=s.jsxs(kt,{children:[me,G]}),e[52]=me,e[53]=G,e[54]=K):K=e[54];let Q;e[55]!==Z||e[56]!==K||e[57]!==V||e[58]!==B?(Q=s.jsxs("div",{className:"flex items-center gap-1.5",children:[V,B,Z,K]}),e[55]=Z,e[56]=K,e[57]=V,e[58]=B,e[59]=Q):Q=e[59];let W;e[60]!==f?(W=()=>f(JP),e[60]=f,e[61]=W):W=e[61];let de;e[62]!==n?(de=n("sessions.sidebar.header.actions.searchSessions"),e[62]=n,e[63]=de):de=e[63];let ge;e[64]!==p?(ge=s.jsx(A,{name:"search",className:p}),e[64]=p,e[65]=ge):ge=e[65];let ve;e[66]!==m||e[67]!==u||e[68]!==W||e[69]!==de||e[70]!==ge?(ve=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:W,className:m,"aria-label":de,"aria-expanded":u,children:ge})}),e[66]=m,e[67]=u,e[68]=W,e[69]=de,e[70]=ge,e[71]=ve):ve=e[71];let te;e[72]!==n?(te=n("sessions.sidebar.header.actions.searchSessions"),e[72]=n,e[73]=te):te=e[73];let he;e[74]!==te?(he=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:te})}),e[74]=te,e[75]=he):he=e[75];let ce;e[76]!==ve||e[77]!==he?(ce=s.jsxs(kt,{children:[ve,he]}),e[76]=ve,e[77]=he,e[78]=ce):ce=e[78];const xe=k&&"bg-interactive-hover text-primary";let se;e[79]!==m||e[80]!==xe?(se=ye(m,xe),e[79]=m,e[80]=xe,e[81]=se):se=e[81];let ue;e[82]!==k||e[83]!==n?(ue=n(k?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[82]=k,e[83]=n,e[84]=ue):ue=e[84];let Y;e[85]!==p?(Y=s.jsx(A,{name:"checkbox-multiple",className:p}),e[85]=p,e[86]=Y):Y=e[86];let Se;e[87]!==w||e[88]!==k||e[89]!==se||e[90]!==ue||e[91]!==Y?(Se=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:w,className:se,"aria-label":ue,"aria-pressed":k,children:Y})}),e[87]=w,e[88]=k,e[89]=se,e[90]=ue,e[91]=Y,e[92]=Se):Se=e[92];let fe;e[93]!==k||e[94]!==n?(fe=n(k?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[93]=k,e[94]=n,e[95]=fe):fe=e[95];let Ce;e[96]!==fe?(Ce=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:fe})}),e[96]=fe,e[97]=Ce):Ce=e[97];let Ie;e[98]!==Se||e[99]!==Ce?(Ie=s.jsxs(kt,{children:[Se,Ce]}),e[98]=Se,e[99]=Ce,e[100]=Ie):Ie=e[100];let ke;e[101]!==n?(ke=n("sessions.sidebar.header.actions.sessionDisplayMode"),e[101]=n,e[102]=ke):ke=e[102];let X;e[103]!==p?(X=s.jsx(A,{name:"equalizer-2",className:p}),e[103]=p,e[104]=X):X=e[104];let ae;e[105]!==m||e[106]!==ke||e[107]!==X?(ae=s.jsx(Ct,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:m,"aria-label":ke,children:X})})}),e[105]=m,e[106]=ke,e[107]=X,e[108]=ae):ae=e[108];let je;e[109]!==n?(je=n("sessions.sidebar.header.displayMode.label"),e[109]=n,e[110]=je):je=e[110];let le;e[111]!==je?(le=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:je})}),e[111]=je,e[112]=le):le=e[112];let Ne;e[113]!==ae||e[114]!==le?(Ne=s.jsxs(kt,{children:[ae,le]}),e[113]=ae,e[114]=le,e[115]=Ne):Ne=e[115];let Me;e[116]!==T?(Me=()=>T("default"),e[116]=T,e[117]=Me):Me=e[117];let Ve;e[118]!==n?(Ve=n("sessions.sidebar.header.displayMode.default"),e[118]=n,e[119]=Ve):Ve=e[119];let we;e[120]!==Ve?(we=s.jsx("span",{children:Ve}),e[120]=Ve,e[121]=we):we=e[121];let ee;e[122]!==N?(ee=N==="default"?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null,e[122]=N,e[123]=ee):ee=e[123];let F;e[124]!==Me||e[125]!==we||e[126]!==ee?(F=s.jsxs(_t,{onClick:Me,className:"flex items-center justify-between",children:[we,ee]}),e[124]=Me,e[125]=we,e[126]=ee,e[127]=F):F=e[127];let U;e[128]!==T?(U=()=>T("minimal"),e[128]=T,e[129]=U):U=e[129];let oe;e[130]!==n?(oe=n("sessions.sidebar.header.displayMode.minimal"),e[130]=n,e[131]=oe):oe=e[131];let Te;e[132]!==oe?(Te=s.jsx("span",{children:oe}),e[132]=oe,e[133]=Te):Te=e[133];let Oe;e[134]!==N?(Oe=N==="minimal"?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null,e[134]=N,e[135]=Oe):Oe=e[135];let Pe;e[136]!==U||e[137]!==Te||e[138]!==Oe?(Pe=s.jsxs(_t,{onClick:U,className:"flex items-center justify-between",children:[Te,Oe]}),e[136]=U,e[137]=Te,e[138]=Oe,e[139]=Pe):Pe=e[139];let z;e[140]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(nr,{}),e[140]=z):z=e[140];let De;e[141]!==n?(De=n("sessions.sidebar.header.displayMode.showRecent"),e[141]=n,e[142]=De):De=e[142];let Qe;e[143]!==De?(Qe=s.jsx("span",{children:De}),e[143]=De,e[144]=Qe):Qe=e[144];let et;e[145]!==I?(et=I?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null,e[145]=I,e[146]=et):et=e[146];let Ze;e[147]!==Qe||e[148]!==et||e[149]!==P?(Ze=s.jsxs(_t,{onClick:P,className:"flex items-center justify-between",children:[Qe,et]}),e[147]=Qe,e[148]=et,e[149]=P,e[150]=Ze):Ze=e[150];let We;e[151]===Symbol.for("react.memo_cache_sentinel")?(We=s.jsx(nr,{}),e[151]=We):We=e[151];let it;e[152]===Symbol.for("react.memo_cache_sentinel")?(it=s.jsx(A,{name:"contract-up-down",className:"h-4 w-4"}),e[152]=it):it=e[152];let qe;e[153]!==n?(qe=n("sessions.sidebar.header.displayMode.collapseAll"),e[153]=n,e[154]=qe):qe=e[154];let st;e[155]!==qe?(st=s.jsx("span",{children:qe}),e[155]=qe,e[156]=st):st=e[156];let Je;e[157]!==j||e[158]!==st?(Je=s.jsxs(_t,{onClick:j,className:"flex items-center gap-2",children:[it,st]}),e[157]=j,e[158]=st,e[159]=Je):Je=e[159];let Be;e[160]===Symbol.for("react.memo_cache_sentinel")?(Be=s.jsx(A,{name:"expand-up-down",className:"h-4 w-4"}),e[160]=Be):Be=e[160];let nt;e[161]!==n?(nt=n("sessions.sidebar.header.displayMode.expandAll"),e[161]=n,e[162]=nt):nt=e[162];let Ge;e[163]!==nt?(Ge=s.jsx("span",{children:nt}),e[163]=nt,e[164]=Ge):Ge=e[164];let at;e[165]!==v||e[166]!==Ge?(at=s.jsxs(_t,{onClick:v,className:"flex items-center gap-2",children:[Be,Ge]}),e[165]=v,e[166]=Ge,e[167]=at):at=e[167];let Ae;e[168]!==F||e[169]!==Pe||e[170]!==Ze||e[171]!==Je||e[172]!==at?(Ae=s.jsxs(Ps,{align:"end",className:"min-w-[160px]",children:[F,Pe,z,Ze,We,Je,at]}),e[168]=F,e[169]=Pe,e[170]=Ze,e[171]=Je,e[172]=at,e[173]=Ae):Ae=e[173];let Le;e[174]!==Ne||e[175]!==Ae?(Le=s.jsxs(As,{children:[Ne,Ae]}),e[174]=Ne,e[175]=Ae,e[176]=Le):Le=e[176];let ze;e[177]!==ce||e[178]!==Ie||e[179]!==Le?(ze=s.jsxs("div",{className:"flex items-center gap-1.5",children:[ce,Ie,Le]}),e[177]=ce,e[178]=Ie,e[179]=Le,e[180]=ze):ze=e[180];let Ke;e[181]!==Q||e[182]!==ze?(Ke=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[Q,ze]}),e[181]=Q,e[182]=ze,e[183]=Ke):Ke=e[183];let lt;e[184]!==g||e[185]!==u||e[186]!==h||e[187]!==b||e[188]!==x||e[189]!==f||e[190]!==y||e[191]!==n?(lt=u?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[g?s.jsx("span",{children:h===1?n("sessions.sidebar.header.search.matchCountSingle",{count:h}):n("sessions.sidebar.header.search.matchCountPlural",{count:h})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(A,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:b,value:x,onChange:dt=>y(dt.target.value),placeholder:n("sessions.sidebar.header.search.placeholder"),className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-8 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50",onKeyDown:dt=>{dt.key==="Escape"&&(dt.stopPropagation(),g?y(""):f(!1))}}),x.length>0?s.jsx("button",{type:"button",onClick:()=>y(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null,e[184]=g,e[185]=u,e[186]=h,e[187]=b,e[188]=x,e[189]=f,e[190]=y,e[191]=n,e[192]=lt):lt=e[192];let xt;return e[193]!==Ke||e[194]!==lt?(xt=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 py-1",children:s.jsxs("div",{className:"flex h-auto min-h-8 flex-col gap-1",children:[Ke,lt]})}),e[193]=Ke,e[194]=lt,e[195]=xt):xt=e[195],xt}function JP(t){return!t}function YP(t){return t.toggleRecentSection}function QP(t){return t.setDisplayMode}function XP(t){return t.showRecentSection}function ZP(t){return t.displayMode}const Ff=7;function eA(t){const e=ot.c(20),{sections:n,renderSessionNode:r}=t,{t:a}=ft();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(C=>{const k=new Set(C);return k.has(v)?k.delete(v):k.add(v),k})},e[2]=u):u=e[2];const f=u;let b;e[3]===Symbol.for("react.memo_cache_sentinel")?(b=v=>{m(C=>{const k=new Set(C);return k.has(v)?k.delete(v):k.add(v),k})},e[3]=b):b=e[3];const x=b;let y,g,h;if(e[4]!==o||e[5]!==p||e[6]!==r||e[7]!==n||e[8]!==a){h=Symbol.for("react.early_return_sentinel");e:{const v=n.filter(tA);if(v.length===0){h=null;break e}y="space-y-2 pb-2 pt-1";let C;e[12]!==o||e[13]!==p||e[14]!==r||e[15]!==a?(C=k=>{const w=o.has(k.key),N=p.has(k.key),I=N?k.items:k.items.slice(0,Ff),T=k.items.length-I.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>f(k.key),className:"group flex w-full items-center gap-1 rounded-md px-0.5 py-0.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!w,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:w?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:k.title})]}),w?null:s.jsxs("div",{className:ye("space-y-0.5 pl-7"),children:[I.map(P=>r(P.node,0,P.groupDirectory,P.projectId,!1,P.secondaryMeta,"recent")),T>0&&!N?s.jsx("button",{type:"button",onClick:()=>x(k.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:T===1?a("sessions.sidebar.group.showMoreSingle",{count:T}):a("sessions.sidebar.group.showMorePlural",{count:T})}):null,N&&k.items.length>Ff?s.jsx("button",{type:"button",onClick:()=>x(k.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:a("sessions.sidebar.group.showFewer")}):null]})]},k.key)},e[12]=o,e[13]=p,e[14]=r,e[15]=a,e[16]=C):C=e[16],g=v.map(C)}e[4]=o,e[5]=p,e[6]=r,e[7]=n,e[8]=a,e[9]=y,e[10]=g,e[11]=h}else y=e[9],g=e[10],h=e[11];if(h!==Symbol.for("react.early_return_sentinel"))return h;let j;return e[17]!==y||e[18]!==g?(j=s.jsx("div",{className:y,children:g}),e[17]=y,e[18]=g,e[19]=j):j=e[19],j}function tA(t){return t.items.length>0}const td="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 sA(t){const e=ot.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}=ft();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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:td,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(A,{name:"settings-3",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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:td,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(A,{name:"question",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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:td,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(A,{name:"information",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(be,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:i,children:m("sessions.sidebar.footer.actions.update")}):null,e[6]=i,e[7]=p,e[8]=m,e[9]=f):f=e[9];let b;return e[10]!==u||e[11]!==f?(b=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[u,f]}),e[10]=u,e[11]=f,e[12]=b):b=e[12],b}const nA=t=>{const e=ot.c(58),{id:n,projectLabel:r,projectDescription:a,projectIcon:i,projectColor:o,projectIconImage:c,projectIconBackground:d,isCollapsed:p,isActiveProject:m,isRepo:u,isDesktopShell:f,isStuck:b,hideDirectoryControls:x,alwaysShowActions:y,onToggle:g,onNewSession:h,onNewWorktreeSession:j,onRenameStart:v,onClose:C,sentinelRef:k,children:w,showCreateButtons:N,hideHeader:I,openSidebarMenuKey:T,setOpenSidebarMenuKey:P}=t,D=N===void 0?!0:N,S=I===void 0?!1:I,{t:M}=ft(),{currentTheme:E}=jr();let R;e[0]!==n?(R={id:n},e[0]=n,e[1]=R):R=e[1];const{attributes:V,listeners:B,setNodeRef:$,transform:O,transition:_,isDragging:q}=ql(R),[L,J]=l.useState(!1),Z=l.useRef(!1),ie=`project:${n}`,ne=T===ie;let me;e[2]===Symbol.for("react.memo_cache_sentinel")?(me=()=>{J(!1)},e[2]=me):me=e[2];const pe=c?.updatedAt;let G;e[3]!==n||e[4]!==pe?(G=[n,pe],e[3]=n,e[4]=pe,e[5]=G):G=e[5],l.useEffect(me,G);const K=i?nc[i]:null,Q=o?Co[o]??null:null;let W;e[6]!==E||e[7]!==n||e[8]!==L||e[9]!==c?(W=L?null:ko({id:n,iconImage:c},{themeVariant:E.metadata.variant,iconColor:E.colors.surface.foreground}),e[6]=E,e[7]=n,e[8]=L,e[9]=c,e[10]=W):W=e[10];const de=W;let ge;e[11]!==ie||e[12]!==P?(ge=ae=>{P(ae?ie:null)},e[11]=ie,e[12]=P,e[13]=ge):ge=e[13];const ve=ge,te=iA,he=oA,ce=lA;let xe;e[14]===Symbol.for("react.memo_cache_sentinel")?(xe=ae=>{(ae.button===2||ae.button===0&&ae.ctrlKey)&&(Z.current=!0)},e[14]=xe):xe=e[14];const se=xe;let ue;e[15]!==g?(ue=()=>{if(Z.current){Z.current=!1;return}g()},e[15]=g,e[16]=ue):ue=e[16];const Y=ue;let Se;e[17]!==O?(Se=Jl.Transform.toString(O),e[17]=O,e[18]=Se):Se=e[18];let fe;e[19]!==Se||e[20]!==_?(fe={transform:Se,transition:_},e[19]=Se,e[20]=_,e[21]=fe):fe=e[21];const Ce=q&&"opacity-30";let Ie;e[22]!==Ce?(Ie=ye("relative",Ce),e[22]=Ce,e[23]=Ie):Ie=e[23];let ke;e[24]!==y||e[25]!==V||e[26]!==ve||e[27]!==Y||e[28]!==x||e[29]!==S||e[30]!==Q||e[31]!==n||e[32]!==de||e[33]!==m||e[34]!==p||e[35]!==f||e[36]!==ne||e[37]!==u||e[38]!==b||e[39]!==B||e[40]!==C||e[41]!==h||e[42]!==j||e[43]!==v||e[44]!==a||e[45]!==d||e[46]!==K||e[47]!==r||e[48]!==k||e[49]!==D||e[50]!==M?(ke=S?null:s.jsxs(s.Fragment,{children:[f&&s.jsx("div",{ref:k,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:ye("w-full text-left group/project select-none"),style:{backgroundColor:f&&b?"transparent":void 0},children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",...V,children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:se,onClick:Y,...B,className:ye("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&&!x?y?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":y?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[s.jsx("span",{className:ye("h-3.5 w-3.5 items-center justify-center text-muted-foreground",y?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:p?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),de?s.jsx("span",{className:ye("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",y?"hidden":"inline-flex group-hover/project:hidden group-focus-within/project:hidden"),style:d?{backgroundColor:d}:void 0,children:s.jsx("img",{src:de,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>J(!0)})}):K?s.jsx(A,{name:K,className:ye("h-3.5 w-3.5",y?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:Q?{color:Q}:void 0}):s.jsx(A,{name:"folder",className:ye("h-3.5 w-3.5 text-muted-foreground/80",y?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:Q?{color:Q}:void 0})]}),s.jsx("span",{className:ye("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:ye("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",D?"right-7":"right-0.5"),children:[D&&u&&!x&&j?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ae=>{ae.stopPropagation(),j()},className:ye("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground transition-opacity",y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(A,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:M("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(As,{open:ne,onOpenChange:ve,children:[s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:ye("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",ne?"opacity-100 pointer-events-auto":y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M("sessions.sidebar.project.actions.projectMenu"),onPointerDown:he,onMouseDown:ce,onClick:te,children:s.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs(Ps,{align:"end",className:"min-w-[180px]",children:[D&&!u&&!x&&h&&s.jsxs(_t,{onClick:h,children:[s.jsx(A,{name:"add",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.project.actions.newSession")]}),s.jsxs(_t,{onClick:v,children:[s.jsx(A,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.session.menu.rename")]}),s.jsxs(_t,{onClick:C,className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"close",className:"mr-1.5 h-4 w-4"}),M("sessions.sidebar.project.actions.closeProject")]})]})]})]}),D&&h?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ae=>{ae.stopPropagation(),h()},className:ye("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":M(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(A,{name:"add",className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:M(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})})]}),e[24]=y,e[25]=V,e[26]=ve,e[27]=Y,e[28]=x,e[29]=S,e[30]=Q,e[31]=n,e[32]=de,e[33]=m,e[34]=p,e[35]=f,e[36]=ne,e[37]=u,e[38]=b,e[39]=B,e[40]=C,e[41]=h,e[42]=j,e[43]=v,e[44]=a,e[45]=d,e[46]=K,e[47]=r,e[48]=k,e[49]=D,e[50]=M,e[51]=ke):ke=e[51];let X;return e[52]!==w||e[53]!==$||e[54]!==fe||e[55]!==Ie||e[56]!==ke?(X=s.jsxs("div",{ref:$,style:fe,className:Ie,children:[ke,w]}),e[52]=w,e[53]=$,e[54]=fe,e[55]=Ie,e[56]=ke,e[57]=X):X=e[57],X},rA=t=>{const e=ot.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}=ql(o);let b;e[3]!==c||e[4]!==p?(b={listeners:c,setActivatorNodeRef:p},e[3]=c,e[4]=p,e[5]=b):b=e[5];const x=b;let y;e[6]!==m?(y=Jl.Transform.toString(m),e[6]=m,e[7]=y):y=e[7];let g;e[8]!==y||e[9]!==u?(g={transform:y,transition:u},e[8]=y,e[9]=u,e[10]=g):g=e[10];const h=f&&"opacity-50";let j;e[11]!==h?(j=ye("space-y-0.5 rounded-md",h),e[11]=h,e[12]=j):j=e[12];let v;e[13]!==a||e[14]!==x?(v=typeof a=="function"?a(x):a,e[13]=a,e[14]=x,e[15]=v):v=e[15];let C;return e[16]!==d||e[17]!==g||e[18]!==j||e[19]!==v?(C=s.jsx("div",{ref:d,style:g,className:j,children:v}),e[16]=d,e[17]=g,e[18]=j,e[19]=v,e[20]=C):C=e[20],C},aA=l.memo(rA);function iA(t){t.stopPropagation()}function oA(t){t.stopPropagation()}function lA(t){t.stopPropagation()}function cA(t){const e=ot.c(25),{t:n}=ft();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:Zx},e[1]=a):a=e[1];const i=io(hi(oo,r),hi(Xx,a));let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o={activationConstraint:{distance:8}},e[2]=o):o=e[2];const c=io(hi(oo,o));if(t.projectSections.length===0){const f=(t.mobileVariant,"");let b;e[3]!==f?(b=ye("space-y-1 pb-1 pl-2.5 pr-2",f),e[3]=f,e[4]=b):b=e[4];let x;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==b?(x=s.jsxs(Ss,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:b,children:[t.topContent,t.emptyState]}),e[5]=t.emptyState,e[6]=t.topContent,e[7]=b,e[8]=x):x=e[8],x}if(t.sectionsForRender.length===0){const f=(t.mobileVariant,"");let b;e[9]!==f?(b=ye("space-y-1 pb-1 pl-2.5 pr-2",f),e[9]=f,e[10]=b):b=e[10];let x;return e[11]!==t.searchEmptyState||e[12]!==b?(x=s.jsx(Ss,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:b,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=b,e[13]=x):x=e[13],x}const d=(t.mobileVariant,"");let p;e[14]!==d?(p=ye("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(g=>g.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!f)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const b=f.groups.find(xA)??f.groups.find(gA)??f.groups.find(hA)??f.groups[0];if(!b)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")});const x=f.groups.find(fA);return[b,...x&&x.id!==b.id?[x]:[]].map(g=>{const h=`${f.project.id}:${g.id}`,j=g.id===b.id;return s.jsx(l.Fragment,{children:t.renderGroupSessions(g,h,f.project.id,j,null,!0)},h)})})()}):s.jsx(s.Fragment,{children:s.jsxs(lo,{sensors:i,collisionDetection:co,onDragEnd:f=>{if(t.isInlineEditing)return;const{active:b,over:x}=f;if(!x||b.id===x.id)return;const y=t.sectionsForRender.findIndex(h=>h.project.id===b.id),g=t.sectionsForRender.findIndex(h=>h.project.id===x.id);y===-1||g===-1||y===g||t.reorderProjects(y,g)},children:[s.jsx(Sl,{items:t.sectionsForRender.map(pA),strategy:dd,children:t.sectionsForRender.map(f=>{const b=f.project,x=b.id,y=Oh(b.label?.trim()||Ga(b.normalizedPath,t.homeDirectory)||b.normalizedPath),g=mo(b.normalizedPath,t.homeDirectory),h=t.collapsedProjects.has(x),j=x===t.activeProjectId,v=t.projectRepoStatus.get(x),C=t.getOrderedGroups(x,f.groups),k=C.find(mA)??null,w=k?C.filter(N=>N.id!==k.id):C;return s.jsx(nA,{id:x,projectLabel:y,projectDescription:g,projectIcon:b.icon,projectColor:b.color,projectIconImage:b.iconImage,projectIconBackground:b.iconBackground,isCollapsed:h,isActiveProject:j,isRepo:!!v,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(x),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onToggle:()=>t.toggleProject(x),onNewSession:()=>{x!==t.activeProjectId&&t.setActiveProjectIdOnly(x),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:b.normalizedPath})},onNewWorktreeSession:()=>{x!==t.activeProjectId&&t.setActiveProjectIdOnly(x),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(x),onClose:()=>t.removeProject(x),sentinelRef:N=>{t.projectHeaderSentinelRefs.current.set(x,N)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:h?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:f.groups.length>0?s.jsxs(lo,{sensors:c,collisionDetection:co,onDragEnd:N=>{if(t.isInlineEditing)return;const{active:I,over:T}=N;if(!T||I.id===T.id)return;const P=w.findIndex(E=>E.id===I.id),D=w.findIndex(E=>E.id===T.id);if(P===-1||D===-1||P===D)return;const S=ah(w,P,D).map(uA),M=k?[k.id,...S]:S;t.setGroupOrderByProject(E=>{const R=new Map(E);return R.set(x,M),R})},children:[k?t.renderGroupSessions(k,`${x}:${k.id}`,x,!0):null,s.jsx(Sl,{items:w.map(dA),strategy:dd,children:w.map(N=>{const I=`${x}:${N.id}`;return s.jsx(aA,{id:N.id,disabled:t.isInlineEditing,children:T=>t.renderGroupSessions(N,I,x,!1,T)},N.id)})}),s.jsx(kl,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})},x)})}),s.jsx(kl,{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(Ss,{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 dA(t){return t.id}function uA(t){return t.id}function mA(t){return t.isMain}function pA(t){return t.project.id}function fA(t){return t.isArchivedBucket}function hA(t){return t.isMain}function gA(t){return t.sessions.length>0}function xA(t){return t.isMain&&t.sessions.length>0}function bA(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 yA(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 vA(t){const e=t.info.role==="user"?"User":"Assistant",n=bA(t.info.time?.created),r=yA(t),a=n&&r?`${n} (${r})`:n||r;return a?`**${e}**
|
|
188
|
-
|
|
189
|
-
*${a}*`:`**${e}**`}function wA(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function ex(t){const e=vA(t),n=wA(t.parts).trim();return n?`${e}
|
|
190
|
-
|
|
191
|
-
${n}`:""}function tx(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",a=`${n} Sub-agent: ${t.title}${r}
|
|
192
|
-
|
|
193
|
-
---
|
|
194
|
-
|
|
195
|
-
`,i=t.records.map(ex).filter(Boolean).join(`
|
|
196
|
-
|
|
197
|
-
---
|
|
198
|
-
|
|
199
|
-
`),o=[a+i];for(const c of t.children)o.push(tx(c,e+1));return o.join(`
|
|
200
|
-
|
|
201
|
-
---
|
|
202
|
-
|
|
203
|
-
`)}function jA(t,e,n){const r=e?.trim()||"Session",a=new Date().toISOString().split("T")[0],i=`# ${r}
|
|
204
|
-
|
|
205
|
-
*Exported on ${a}*
|
|
206
|
-
|
|
207
|
-
---
|
|
208
|
-
|
|
209
|
-
`,o=t.map(ex).filter(Boolean).join(`
|
|
210
|
-
|
|
211
|
-
---
|
|
212
|
-
|
|
213
|
-
`);let c=i+o;if(n&&n.length>0){const d=n.map(p=>tx(p,1)).join(`
|
|
214
|
-
|
|
215
|
-
---
|
|
216
|
-
|
|
217
|
-
`);c+=`
|
|
218
|
-
|
|
219
|
-
---
|
|
220
|
-
|
|
221
|
-
`+d}return c}function NA(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 SA(t,e){const n=await Uy(e,t);if(n)return n;if(!fn())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 kA(t){const e=or()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await Wy(t)?!0:Il(t)}function CA(){return su()}function IA(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 PA=(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},gr=ar()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,a)=>{const i=e(),o=new Set(i.selectedIds);let c=i.scopeKey,d=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(o.clear(),c=r,d=null):c===null&&r!==null&&(c=r);const m=a&&a.length>0?[n,...a]:[n];if(o.has(n)){for(const f of m)o.delete(f);d===n&&(d=null)}else{for(const f of m)o.add(f);d=n}o.size===0?t({selectedIds:o,scopeKey:null,anchorId:null}):t({selectedIds:o,scopeKey:c,anchorId:d})},setRange:(n,r,a,i,o)=>{const c=e();if(a.length===0)return;const d=n&&a.includes(n)?n:a[0],p=a.indexOf(d),m=a.indexOf(r);if(p<0||m<0)return;const[u,f]=p<=m?[p,m]:[m,p],b=a.slice(u,f+1),x=PA(b,o),g=i!==null&&c.scopeKey!==null&&i!==c.scopeKey?new Set:new Set(c.selectedIds);for(const h of x)g.add(h);t({selectedIds:g,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}))}})),AA=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,sx=/^g[1-9]\d*$/,Gi=(t,e,n,r,a)=>{if(!AA.test(t)||e!==void 0&&!sx.test(e)||!n?.trim()||!r?.trim()||n!==n.trim()||r!==r.trim())return null;if(a===void 0)return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!1};if(a==="fusion")return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!0};if(!/^\d+$/.test(a))return null;const i=Number.parseInt(a,10);return!Number.isSafeInteger(i)||i<=0?null:{groupSlug:t,runGroup:e,providerID:n,modelID:r,index:i,fusion:!1}},jl=t=>{if(!t)return null;const e=t.split("/");if(e.length<3||e.length>5)return null;const[n]=e;if(e.length===3)return Gi(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,c,d,p]=e;return sx.test(c)?Gi(n,c,d,p,void 0):Gi(n,void 0,c,d,p)}const[,r,a,i,o]=e;return r===""?Gi(n,void 0,a,i,o):Gi(n,r,a,i,o)},DA=t=>{const e=[t.groupSlug];return t.runGroup&&e.push(t.runGroup),e.push(t.providerID,t.modelID),t.index!==void 0&&e.push(String(t.index)),e.join("/")},TA=(t,e,n,r)=>{const a=[t];return r&&a.push(r),a.push(e,n,"fusion"),a.join("/")},nx=t=>{const e=ot.c(35),{value:n,onChange:r,className:a,disabled:i,id:o,portalToBody:c}=t,{t:d}=ft(),p=wt(EA),m=wt(MA),u=wt(RA);let f;e[0]!==p?(f=p(),e[0]=p,e[1]=f):f=e[1];const b=f;let x;e[2]!==b?(x=b.filter(FA),e[2]=b,e[3]=x):x=e[3];const y=x;let g,h;e[4]!==m?(g=()=>{m()},h=[m],e[4]=m,e[5]=g,e[6]=h):(g=e[5],h=e[6]),l.useEffect(g,h);let j,v;e[7]!==u||e[8]!==i||e[9]!==r||e[10]!==y||e[11]!==n?(j=()=>{if(i)return;const S=n.trim();if(S.length>0&&y.some(R=>R.name===S))return;const M=typeof u=="string"&&u.trim().length>0?u.trim():null;if(M&&y.some(R=>R.name===M)){r(M);return}const E=y[0]?.name;E&&r(E)},v=[u,i,r,y,n],e[7]=u,e[8]=i,e[9]=r,e[10]=y,e[11]=n,e[12]=j,e[13]=v):(j=e[12],v=e[13]),l.useEffect(j,v);const C=n.trim().length>0?n:void 0;let k;e[14]!==a?(k=ye("max-w-full typography-meta text-foreground !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 data-[popup-open]:!bg-[var(--interactive-active)]/70",a),e[14]=a,e[15]=k):k=e[15];let w;e[16]!==d?(w=d("multirun.agentSelector.placeholder"),e[16]=d,e[17]=w):w=e[17];let N;e[18]!==w?(N=s.jsx(fs,{placeholder:w}),e[18]=w,e[19]=N):N=e[19];let I;e[20]!==o||e[21]!==k||e[22]!==N?(I=s.jsx(is,{id:o,size:"lg",className:k,children:N}),e[20]=o,e[21]=k,e[22]=N,e[23]=I):I=e[23];let T;e[24]!==y?(T=y.length>0&&s.jsx(fd,{children:y.map(OA)}),e[24]=y,e[25]=T):T=e[25];let P;e[26]!==c||e[27]!==T?(P=s.jsx(os,{fitContent:!0,portalToBody:c,children:T}),e[26]=c,e[27]=T,e[28]=P):P=e[28];let D;return e[29]!==i||e[30]!==r||e[31]!==C||e[32]!==I||e[33]!==P?(D=s.jsxs(as,{value:C,onValueChange:r,disabled:i,children:[I,P]}),e[29]=i,e[30]=r,e[31]=C,e[32]=I,e[33]=P,e[34]=D):D=e[34],D};function EA(t){return t.getVisibleAgents}function MA(t){return t.loadAgents}function RA(t){return t.currentAgentName}function FA(t){return t.mode!=="subagent"}function OA(t){return s.jsx(Mt,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const rx="h-7",ao=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,LA=t=>{const e=ot.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=ye("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",rx),e[0]=d):d=e[0];let p;e[1]!==n.providerID?(p=s.jsx(yr,{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(A,{name:"close",className:"h-3.5 w-3.5"}),e[5]=u):u=e[5];let f;e[6]!==i?(f=s.jsx("button",{type:"button",onClick:i,className:"text-muted-foreground hover:text-foreground ml-0.5",children:u}),e[6]=i,e[7]=f):f=e[7];let b;return e[8]!==p||e[9]!==m||e[10]!==f?(b=s.jsxs("div",{className:d,children:[p,m,f]}),e[8]=p,e[9]=m,e[10]=f,e[11]=b):b=e[11],b},ax=t=>{const e=ot.c(117),{selectedModels:n,onAdd:r,onRemove:a,onUpdate:i,minModels:o,addButtonLabel:c,showChips:d,maxModels:p,addButtonClassName:m,dropdownSide:u,dropdownClassName:f,containerClassName:b,triggerIcon:x}=t,y=d===void 0?!0:d,g=u===void 0?"top":u,{t:h}=ft(),j=wt($A),v=wt(_A),C=Fe(BA),k=Fe(VA),{favoriteModelsList:w,recentModelsList:N}=gh(),[I,T]=l.useState(!1),[P,D]=l.useState(""),[S,M]=l.useState(null),E=l.useRef(null),R=l.useRef(null),V=p===1,B=p===void 0||n.length<p||V;let $;if(e[0]!==n){$=new Map;for(const U of n){const oe=`${U.providerID}:${U.modelID}`;$.set(oe,($.get(oe)||0)+1)}e[0]=n,e[1]=$}else $=e[1];const O=$;let _;e[2]!==n?(_=U=>n.filter(Te=>Te.providerID===U.providerID&&Te.modelID===U.modelID).findIndex(Te=>Te.instanceId===U.instanceId)+1,e[2]=n,e[3]=_):_=e[3];const q=_;let L,J;e[4]!==g||e[5]!==I?(L=()=>{if(!I||!R.current)return;const U=R.current.getBoundingClientRect();if(g==="bottom"){const De=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-U.bottom-16-112;M(Math.max(160,Math.min(320,De)));return}let oe=R.current.parentElement;for(;oe&&!(oe.getAttribute("role")==="dialog"||oe.hasAttribute("data-scroll-shadow"));){const Pe=getComputedStyle(oe);if(Pe.overflow==="auto"||Pe.overflow==="hidden"||Pe.overflowY==="auto"||Pe.overflowY==="hidden")break;oe=oe.parentElement}const Te=oe?oe.getBoundingClientRect().top:0,Oe=U.top-Te-16;M(Math.max(150,Math.min(300,Oe)))},J=[g,I],e[4]=g,e[5]=I,e[6]=L,e[7]=J):(L=e[6],J=e[7]),l.useEffect(L,J);let Z,ie;e[8]!==B||e[9]!==I?(Z=()=>{!B&&I&&(T(!1),D(""))},ie=[B,I],e[8]=B,e[9]=I,e[10]=Z,e[11]=ie):(Z=e[10],ie=e[11]),l.useEffect(Z,ie);let ne,me;e[12]!==I?(ne=()=>{if(!I)return;const U=oe=>{E.current&&!E.current.contains(oe.target)&&(T(!1),D(""))};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},me=[I],e[12]=I,e[13]=ne,e[14]=me):(ne=e[13],me=e[14]),l.useEffect(ne,me);let pe;e[15]!==V||e[16]!==r||e[17]!==i||e[18]!==n.length?(pe=U=>{const oe={providerID:U.providerID,modelID:U.modelID,displayName:U.model.name||U.modelID,instanceId:ao()};V&&n.length>0&&i?i(0,oe):r(oe),V&&(T(!1),D(""))},e[15]=V,e[16]=r,e[17]=i,e[18]=n.length,e[19]=pe):pe=e[19];const G=pe;let K;e[20]!==h?(K=h("multirun.modelMultiSelect.search.placeholder"),e[20]=h,e[21]=K):K=e[21];let Q;e[22]!==h?(Q=h("multirun.modelMultiSelect.search.noResults"),e[22]=h,e[23]=Q):Q=e[23];let W;e[24]!==h?(W=h("multirun.modelMultiSelect.sections.favorites"),e[24]=h,e[25]=W):W=e[25];let de;e[26]!==h?(de=h("multirun.modelMultiSelect.sections.recent"),e[26]=h,e[27]=de):de=e[27];let ge;e[28]!==h?(ge=h("multirun.modelMultiSelect.keyboard.hint"),e[28]=h,e[29]=ge):ge=e[29];let ve;e[30]!==h?(ve=h("settings.agents.modelSelector.actions.favorite"),e[30]=h,e[31]=ve):ve=e[31];let te;e[32]!==h?(te=h("settings.agents.modelSelector.actions.unfavorite"),e[32]=h,e[33]=te):te=e[33];let he;e[34]!==h?(he=h("chat.modelControls.capabilities"),e[34]=h,e[35]=he):he=e[35];let ce;e[36]!==h?(ce=h("chat.modelControls.capability.toolCalling"),e[36]=h,e[37]=ce):ce=e[37];let xe;e[38]!==h?(xe=h("chat.modelControls.capability.reasoning"),e[38]=h,e[39]=xe):xe=e[39];let se;e[40]!==h?(se=h("chat.modelControls.input"),e[40]=h,e[41]=se):se=e[41];let ue;e[42]!==h?(ue=h("chat.modelControls.output"),e[42]=h,e[43]=ue):ue=e[43];let Y;e[44]!==h?(Y=h("chat.modelControls.costPerMillion"),e[44]=h,e[45]=Y):Y=e[45];let Se;e[46]!==K||e[47]!==Q||e[48]!==W||e[49]!==de||e[50]!==ge||e[51]!==ve||e[52]!==te||e[53]!==he||e[54]!==ce||e[55]!==xe||e[56]!==se||e[57]!==ue||e[58]!==Y?(Se={searchPlaceholder:K,noResults:Q,favorites:W,recent:de,keyboardHint:ge,favorite:ve,unfavorite:te,capabilities:he,capabilityToolCalling:ce,capabilityReasoning:xe,input:se,output:ue,costPerMillion:Y},e[46]=K,e[47]=Q,e[48]=W,e[49]=de,e[50]=ge,e[51]=ve,e[52]=te,e[53]=he,e[54]=ce,e[55]=xe,e[56]=se,e[57]=ue,e[58]=Y,e[59]=Se):Se=e[59];const fe=Se;let Ce;e[60]!==b?(Ce=ye("relative",b),e[60]=b,e[61]=Ce):Ce=e[61];let Ie;e[62]!==m?(Ie=ye(rx,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",m),e[62]=m,e[63]=Ie):Ie=e[63];const ke=!B;let X;e[64]!==I?(X=()=>{T(!I)},e[64]=I,e[65]=X):X=e[65];let ae;e[66]!==x?(ae=x??s.jsx(A,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=x,e[67]=ae):ae=e[67];let je;e[68]!==c||e[69]!==h?(je=c??h("multirun.modelMultiSelect.actions.addModel"),e[68]=c,e[69]=h,e[70]=je):je=e[70];let le;e[71]!==Ie||e[72]!==ke||e[73]!==X||e[74]!==ae||e[75]!==je?(le=s.jsxs(be,{ref:R,type:"button",variant:"outline",size:"sm",className:Ie,disabled:ke,onClick:X,children:[ae,je]}),e[71]=Ie,e[72]=ke,e[73]=X,e[74]=ae,e[75]=je,e[76]=le):le=e[76];let Ne;e[77]!==S||e[78]!==B||e[79]!==f||e[80]!==g||e[81]!==w||e[82]!==G||e[83]!==k||e[84]!==I||e[85]!==fe||e[86]!==O||e[87]!==v||e[88]!==j||e[89]!==N||e[90]!==P||e[91]!==C?(Ne=I?s.jsx("div",{className:ye("absolute left-0 z-50 w-[min(420px,calc(100vw-2rem))] max-w-[calc(100vw-2rem)] flex flex-col overflow-hidden rounded-xl border border-border/50 shadow-lg",g==="top"?"bottom-full mb-1":"top-full mt-1",f),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:s.jsx(xh,{providers:j,favoriteModels:w,recentModels:N,modelsMetadata:v,searchQuery:P,onSearchQueryChange:D,onSelect:G,labels:fe,selectionCount:U=>O.get(`${U.providerID}:${U.modelID}`)||0,disabled:!B,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:S?`${S}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:I,isFavorite:U=>k(U.providerID,U.modelID),onToggleFavorite:U=>C(U.providerID,U.modelID),onEscape:()=>{T(!1),D("")}})}):null,e[77]=S,e[78]=B,e[79]=f,e[80]=g,e[81]=w,e[82]=G,e[83]=k,e[84]=I,e[85]=fe,e[86]=O,e[87]=v,e[88]=j,e[89]=N,e[90]=P,e[91]=C,e[92]=Ne):Ne=e[92];let Me;e[93]!==Ce||e[94]!==le||e[95]!==Ne?(Me=s.jsxs("div",{className:Ce,ref:E,children:[le,Ne]}),e[93]=Ce,e[94]=le,e[95]=Ne,e[96]=Me):Me=e[96];let Ve;e[97]!==q||e[98]!==O||e[99]!==a||e[100]!==i||e[101]!==j||e[102]!==n||e[103]!==y||e[104]!==h?(Ve=y&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((U,oe)=>{const Te=`${U.providerID}:${U.modelID}`,Oe=O.get(Te)||1,Pe=q(U),De=j.find(We=>We.id===U.providerID)?.models?.find(We=>We.id===U.modelID),Qe=De?.variants?Object.keys(De.variants):[],et=Qe.length>0,Ze=U.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(LA,{model:U,instanceIndex:Pe,totalSameModel:Oe,onRemove:()=>a(oe)}),et&&s.jsxs(as,{value:Ze,onValueChange:We=>{if(!i)return;i(oe,{...U,variant:We==="__default__"?void 0:We})},children:[s.jsxs(is,{size:"chip",className:"px-2 gap-1.5 rounded-md !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground",children:[s.jsx(A,{name:"brain-ai-3",className:ye("h-3.5 w-3.5 flex-shrink-0",Ze==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(fs,{placeholder:h("multirun.modelMultiSelect.variant.placeholder"),children:We=>We==="__default__"?h("multirun.modelMultiSelect.variant.default"):We})]}),s.jsxs(os,{fitContent:!0,children:[s.jsx(Mt,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:h("multirun.modelMultiSelect.variant.default")}),Qe.map(zA)]})]})]},U.instanceId)})}),e[97]=q,e[98]=O,e[99]=a,e[100]=i,e[101]=j,e[102]=n,e[103]=y,e[104]=h,e[105]=Ve):Ve=e[105];let we;e[106]!==Me||e[107]!==Ve?(we=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[Me,Ve]}),e[106]=Me,e[107]=Ve,e[108]=we):we=e[108];let ee;e[109]!==p||e[110]!==o||e[111]!==n.length||e[112]!==h?(ee=o!==void 0&&n.length<o&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:p!==void 0?h("multirun.modelMultiSelect.validation.minToMax",{min:o,max:p}):h("multirun.modelMultiSelect.validation.minOnly",{min:o})}),e[109]=p,e[110]=o,e[111]=n.length,e[112]=h,e[113]=ee):ee=e[113];let F;return e[114]!==we||e[115]!==ee?(F=s.jsxs("div",{className:"space-y-2",children:[we,ee]}),e[114]=we,e[115]=ee,e[116]=F):F=e[116],F};function $A(t){return t.providers}function _A(t){return t.modelsMetadata}function BA(t){return t.toggleFavoriteModel}function VA(t){return t.isFavoriteModel}function zA(t){return s.jsx(Mt,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const UA=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
|
|
222
|
-
|
|
223
|
-
--- RESULT ${n+1}: ${r} ---
|
|
224
|
-
${e.trim()}
|
|
225
|
-
--- END RESULT ${n+1} ---`},Of=(t,e)=>$t.getState().getWorktreeMetadata(t)?.projectDirectory??e,WA=async t=>{const e=t.directory??void 0,n=Ky(t.session.id,e);if(n.length===0&&t.directory){const a=(await on.withDirectory(t.directory,()=>on.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let i=a.length-1;i>=0;i-=1){const o=a[i];if(o.info?.role==="assistant")return rm(o.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const a=n[r];if(a.role==="assistant")return rm(Hy(a.id,e)).trim()}return""};function KA({session:t,open:e,onOpenChange:n}){const{t:r}=ft(),a=Gd(),i=xa($=>$.activeSessions),o=xa($=>$.archivedSessions),c=wt($=>$.providers),d=wt($=>$.currentProviderId),p=wt($=>$.currentModelId),m=wt($=>$.currentAgentName),[u,f]=l.useState(d??""),[b,x]=l.useState(p??""),[y,g]=l.useState(()=>d&&p?[{providerID:d,modelID:p,instanceId:ao()}]:[]),[h,j]=l.useState(""),[v,C]=l.useState(m??""),[k,w]=l.useState([]),[N,I]=l.useState(!1),T=l.useMemo(()=>jl(t.title),[t.title]),P=l.useMemo(()=>{const $=new Map;for(const O of a)$.set(O.id,O);for(const O of i)$.set(O.id,O);for(const O of o)$.set(O.id,O);return t.id&&$.set(t.id,t),Array.from($.values())},[i,o,a,t]);l.useEffect(()=>{if(!e||!T)return;const $=$t.getState().getDirectoryForSession(t.id),O=Of(t.id,$),_=P.map(q=>{const L=jl(q.title);if(!L||L.groupSlug!==T.groupSlug||L.fusion||(L.runGroup??null)!==(T.runGroup??null))return null;const J=$t.getState().getDirectoryForSession(q.id)??eo(q),Z=Of(q.id,J);return O&&Z&&O!==Z?null:{session:q,directory:J,projectDirectory:Z}}).filter(q=>q!==null).sort((q,L)=>(q.session.time?.created??0)-(L.session.time?.created??0));w(_)},[P,e,T,t.id]);const S=c.find($=>$.id===u)?.models.find($=>$.id===b),M=S?.variants?Object.keys(S.variants):[],E=!!(T&&u&&b&&k.length>0&&!N),R=l.useCallback($=>{g([$]),f($.providerID),x($.modelID),j("")},[]),V=y[0]?.displayName||y[0]?.modelID||r("multirun.fusion.model.placeholder"),B=async()=>{if(!(!T||!u||!b)){I(!0);try{const $=await Promise.all(k.map(ie=>WA(ie))),O=k.map((ie,ne)=>({source:ie,text:$[ne]??""})).filter(ie=>ie.text.trim().length>0);if(O.length===0){H.error(r("multirun.fusion.toast.noOutputs"));return}const _=k[0]?.projectDirectory??k[0]?.directory??null,q=TA(T.groupSlug,u,b,T.runGroup),[L,J]=await Promise.all([wn("session.fusion.visible"),wn("session.fusion.instructions")]),Z=await $t.getState().createSession(q,_,null);if(!Z)throw new Error("Failed to create fusion session");$t.getState().setCurrentSession(Z.id,_),n(!1),await on.withDirectory(_??on.getDirectory(),()=>on.sendMessage({id:Z.id,providerID:u,modelID:b,variant:h||void 0,agent:v||void 0,text:L,additionalParts:[{text:J,synthetic:!0},...O.map((ie,ne)=>({text:UA(ie.source,ie.text,ne),synthetic:!0})),{text:`
|
|
226
|
-
|
|
227
|
-
--- FUSION INPUTS END ---
|
|
228
|
-
Now write the final fused answer.`,synthetic:!0}]}))}catch($){console.error("[MultiRunFusion] Failed to start fusion",$),H.error(r("multirun.fusion.toast.failed"))}finally{I(!1)}}};return s.jsx(us,{open:e,onOpenChange:n,children:s.jsxs(ds,{className:"max-w-xl overflow-visible",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:r("multirun.fusion.title")}),s.jsx(Ns,{children:r("multirun.fusion.description")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"max-w-full",children:s.jsx(ax,{selectedModels:y,onAdd:R,onUpdate:($,O)=>R(O),onRemove:()=>{g([]),f(""),x(""),j("")},maxModels:1,addButtonLabel:V,showChips:!1,addButtonClassName:"h-8 w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:u?s.jsx(yr,{providerId:u,className:"h-3.5 w-3.5 mr-1"}):void 0})}),M.length>0?s.jsxs(as,{value:h||"__default__",onValueChange:$=>j($==="__default__"?"":$),children:[s.jsxs(is,{size:"lg",className:"h-8 w-fit rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground px-3 py-1.5",children:[s.jsx(A,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(fs,{children:$=>$==="__default__"?r("multirun.modelMultiSelect.variant.default"):$})]}),s.jsxs(os,{fitContent:!0,portalToBody:!0,children:[s.jsx(Mt,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),M.map($=>s.jsx(Mt,{value:$,children:$},$))]})]}):null,s.jsx(nx,{value:v,onChange:C,portalToBody:!0,className:"h-8 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta font-medium text-foreground",children:r("multirun.fusion.sources.label",{count:k.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:k.map($=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(yr,{providerId:jl($.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:$.session.title||$.session.id}),s.jsx("button",{type:"button",onClick:()=>w(O=>O.filter(_=>_.session.id!==$.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"h-4 w-4"})})]},$.session.id))})]}),s.jsxs(_s,{children:[s.jsx(be,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(be,{onClick:B,disabled:!E,children:r(N?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function HA(t){const e=ot.c(7);let n,r,a,i,o;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),a=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),i=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),o=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=a,e[3]=i,e[4]=o):(n=e[0],r=e[1],a=e[2],i=e[3],o=e[4]);let c;return e[5]!==t?(c=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,a,i,o]}),e[5]=t,e[6]=c):c=e[6],c}const Lf=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),Ra=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(Ra(n,e))return!0;return!1},zd=(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(zd(i,e,n,r))return!0;return!1},GA=(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||Lf(t.node)!==Lf(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=Ra(t.node,t.currentSessionId),u=Ra(e.node,e.currentSessionId);if(m||u)return!1}if(t.pinnedSessionIds.has(a)!==e.pinnedSessionIds.has(i))return!1;{const m=t.renderContext??"project",u=e.renderContext??"project",f=t.archivedBucket??!1,b=e.archivedBucket??!1,x=`${m}:${f?"archived":"active"}:${a}`,y=`${u}:${b?"archived":"active"}:${i}`;if(t.expandedParents.has(x)!==e.expandedParents.has(y))return!1}if(t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const m=Ra(t.node,t.editingId),u=Ra(e.node,e.editingId);if(m||u)return!1}if(t.editTitle!==e.editTitle){const m=Ra(t.node,t.editingId),u=Ra(e.node,e.editingId);if(m||u)return!1}if(t.copiedSessionId===a!=(e.copiedSessionId===i))return!1;const o=zd(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),c=zd(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(o!==c)return!1;const d=bs(n.directory??null)??bs(t.groupDirectory??null),p=bs(r.directory??null)??bs(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 qA(t){const{t:e}=ft(),{node:n,depth:r=0,groupDirectory:a,projectId:i,archivedBucket:o=!1,directoryStatus:c,currentSessionId:d,pinnedSessionIds:p,expandedParents:m,hasSessionSearchQuery:u,normalizedSessionSearchQuery:f,notifyOnSubtasks:b,editingId:x,setEditingId:y,editTitle:g,setEditTitle:h,handleSaveEdit:j,handleCancelEdit:v,toggleParent:C,handleSessionSelect:k,handleSessionDoubleClick:w,togglePinnedSession:N,handleShareSession:I,copiedSessionId:T,handleCopyShareUrl:P,handleUnshareSession:D,openSidebarMenuKey:S,setOpenSidebarMenuKey:M,renamingFolderId:E,getFoldersForScope:R,getSessionFolderId:V,removeSessionFromFolder:B,addSessionToFolder:$,createFolderAndStartRename:O,openContextPanelTab:_,handleDeleteSession:q,mobileVariant:L,alwaysShowActions:J,renderSessionNode:Z,secondaryMeta:ie,renderContext:ne="project"}=t,me=!!ie?.projectLabel,pe=!!ie?.branchLabel,K=Ba(ct=>ct.displayMode)==="minimal",Q=l.useMemo(()=>fn(),[]),W=l.useMemo(()=>qd(),[]),de=l.useContext(Gy),ge=Q?"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",ve=Q?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",te=Q,he=!o&&!L,ce=K?Q?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":Q?he&&te?"group-hover:pr-18":he||te?"group-hover:pr-12":"group-hover:pr-5":he?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",xe=he?"pr-13":"pr-7",se=l.useRef(!1),ue=l.useRef(!1),[Y,Se]=l.useState(!1),fe=n.session,Ie=uh(fe.id)??fe,ke=bs(fe.directory??null)??bs(a??null),X=qy(ke??void 0),ae=ou(),je=gr(ct=>ct.enabled),le=gr(l.useCallback(ct=>ct.selectedIds.has(fe.id),[fe.id])),Ne=gr(ct=>ct.toggleSelected),Me=gr(ct=>ct.setRange),Ve=l.useCallback(ct=>{const ls=[],cs=He=>{He.children.forEach(yt=>{ls.push(yt.session.id),cs(yt)})};return cs(ct),ls},[]),[we,ee]=l.useState(!1),[F,U]=l.useState(!0),oe=`${ne}:${o?"archived":"active"}:${fe.id}`,Te=Lh(l.useCallback(ct=>!!ct.sessionMemoryState.get(fe.id)?.isZombie,[fe.id])),Oe=Jy(fe.id),Pe=Yy(fe.id,ke??void 0),De=(ke?c.get(ke):null)==="missing",Qe=d===fe.id,et=Ie.title||e("sessions.sidebar.session.untitled"),Ze=n.children.length>0,We=p.has(fe.id),it=oe,qe=u?!0:m.has(it),st=!!Ie.parentID,Be=Qy(fe.id)>0&&(!st||b),nt=Ie.summary,Ge=fh(nt),at=Ie.time?.updated||Ie.time?.created||Date.now(),Ae=Xy(at),Le=sv(at),ze=S===oe,Ke=l.useMemo(()=>jl(Ie.title)!==null,[Ie.title]),[lt,xt]=l.useState(!1),dt=l.useMemo(()=>Ve(n).length,[Ve,n]),ut=l.useCallback(async ct=>{const ls=[];let cs=0;for(const He of ct)try{await ae.ensureSessionRenderable(He.session.id);const yt=am(X.getState(),He.session.id).list,Et=He.session.title||e("sessions.sidebar.session.export.untitledSubagent"),Rt=He.session.agent,Yt=await ut(He.children);cs+=Yt.skipped,ls.push({title:Et,agent:Rt,records:yt,children:Yt.children})}catch{cs+=Ve(He).length+1}return{children:ls,skipped:cs}},[Ve,X,ae,e]),Nt=l.useCallback(ct=>{ct<=0||H.warning(ct===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:ct}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:ct}))},[e]),ts=l.useCallback(async ct=>{if(!ke){H.error(e("sessions.sidebar.session.export.nothingToExport"));return}await ae.ensureSessionRenderable(fe.id);const ls=am(X.getState(),fe.id).list;if(ls.length===0){H.error(e("sessions.sidebar.session.export.nothingToExport"));return}let cs,He=0;if(ct&&n.children.length>0){const Yt=await ut(n.children);cs=Yt.children,He=Yt.skipped}const yt=jA(ls,Ie.title??null,cs),Et=IA(Ie.title??null),Rt=await SA(yt,Et);if(Rt){H.success(e("sessions.sidebar.session.export.success"),{action:{label:e(CA()),onClick:()=>{kA(Rt).then(Yt=>{Yt||H.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),Nt(He);return}NA(yt,Et),H.success(e("sessions.sidebar.session.export.success")),Nt(He)},[ut,X,n.children,Ie.title,fe.id,ke,Nt,ae,e]),Vt=l.useCallback(async()=>{if(n.children.length>0){U(!0),ee(!0);return}await ts(!1)},[ts,n.children.length]),Xt=l.useCallback(()=>{ke&&Pl("desktop_open_session_mini_chat_window",{sessionId:fe.id,directory:ke}).catch(ct=>{console.warn("[session-sidebar] failed to open mini chat window",ct)})},[fe.id,ke]);if(x===fe.id)return s.jsx("div",{className:ye("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:ct=>{ct.preventDefault(),j()},children:[s.jsx("input",{value:g,onChange:ct=>h(ct.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:ct=>{if(ct.key==="Escape"){ct.stopPropagation(),ue.current=!0,v();return}(ct.key===" "||ct.key==="Enter")&&ct.stopPropagation()},onBlur:()=>{if(ue.current){ue.current=!1;return}j()}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:v,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"size-4"})})]}),K?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:[Ze?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:qe?s.jsx(A,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(A,{name:"arrow-right-s",className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:Ae}),Ge?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:["+",Ge.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",Ge.deletions]})]}):null,me?s.jsx("span",{className:"truncate",children:ie?.projectLabel}):null,pe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ie?.branchLabel})]}):null]})})]})},fe.id);const ht=Oe?.type??"idle",Bt=ht==="busy"||ht==="retry",Zt=Pe.length,rs=Bt||!Bt&&Be&&!Qe,ps=Bt?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")}),Ut=rs||We?s.jsxs("span",{className:ye("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",K?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",rs&&We?"left-[-18px] w-6":"left-[-10px] w-3.5",Ze&&!J?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[rs?ps:null,We?s.jsx(A,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,Ye=Ze?s.jsx("span",{role:"button",tabIndex:0,onClick:ct=>{ct.stopPropagation(),C(it)},onKeyDown:ct=>{(ct.key==="Enter"||ct.key===" ")&&(ct.preventDefault(),ct.stopPropagation(),C(it))},className:ye("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",K?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",K&&rs&&!J?"opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto":""),"aria-label":e(qe?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:qe?s.jsx(A,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(A,{name:"arrow-right-s",className:"h-3 w-3"})}):null,Tt=Te?s.jsx(A,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Kt=ct=>{M(ct?oe:null)},St=ct=>{ct.preventDefault(),ct.stopPropagation(),M(ze?null:oe)},es=ct=>{ct.preventDefault(),ct.stopPropagation()},ss=ct=>{ct.preventDefault(),ct.stopPropagation()},Ms=ct=>{ct.preventDefault(),ct.stopPropagation()},xs=ct=>{ct.preventDefault(),ct.stopPropagation()},Bs=ct=>{ct.preventDefault(),ct.stopPropagation(),M(null),q(fe,{archivedBucket:o})},ws=ct=>{ct.preventDefault(),ct.stopPropagation()},xn=ct=>{ct.preventDefault(),ct.stopPropagation()},Qs=ct=>{ct.preventDefault(),ct.stopPropagation(),de?.vscode?.executeCommand("openchamber.openSessionInEditor",fe.id,et)},Wt=ct=>{if(se.current){se.current=!1;return}if(je){if(ct?.preventDefault(),ct?.stopPropagation(),ct?.shiftKey){const cs=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(Et=>Et.getAttribute("data-session-row")).filter(Et=>typeof Et=="string"&&Et.length>0),He=gr.getState().anchorId,yt=new Map;yt.set(fe.id,Ve(n)),Me(He,fe.id,cs,ke??null,yt);return}Ne(fe.id,ke??null,Ve(n));return}k(fe.id,ke,De,i)},qt=ct=>{(ct.button===2||ct.button===0&&ct.ctrlKey&&!je)&&(se.current=!0)},re=ct=>{L&&ct.pointerType==="touch"&&Se(!0)},vt=ct=>{L&&ct.pointerType==="touch"&&Se(!1)},Ft=s.jsxs(Ps,{align:"end",className:"min-w-[180px]",onCloseAutoFocus:ct=>{E&&ct.preventDefault()},children:[s.jsxs(_t,{onClick:()=>{y(fe.id),h(et)},className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(_t,{onClick:()=>N(fe.id),className:"[&>svg]:mr-1",children:[We?s.jsx(A,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(A,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(We?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),Ie.share?s.jsxs(s.Fragment,{children:[s.jsx(_t,{onClick:()=>{Ie.share?.url&&P(Ie.share.url,fe.id)},className:"[&>svg]:mr-1",children:T===fe.id?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(_t,{onClick:()=>D(fe.id),className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(_t,{onClick:()=>I(Ie),className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(_t,{onClick:()=>{Vt()},className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),Ke?s.jsxs(_t,{onClick:()=>xt(!0),className:"[&>svg]:mr-1",children:[s.jsx(HA,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,ke&&!o?(()=>{const ct=R(ke),ls=V(ke,fe.id);return s.jsxs(s.Fragment,{children:[s.jsx(nr,{}),s.jsxs(Zy,{children:[s.jsxs(ev,{className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(tv,{className:"min-w-[180px]",children:[ct.length===0?s.jsx(_t,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):ct.map(cs=>s.jsxs(_t,{onClick:()=>{ls===cs.id?B(ke,fe.id):$(ke,cs.id,fe.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:cs.name}),ls===cs.id?s.jsx(A,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},cs.id)),s.jsx(nr,{}),s.jsxs(_t,{onClick:()=>{const cs=O(ke);cs&&$(ke,cs.id,fe.id)},children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),ls?s.jsxs(_t,{onClick:()=>{B(ke,fe.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,Q?null:s.jsxs(_t,{disabled:!ke,onClick:()=>{ke&&_(ke,{mode:"chat",dedupeKey:`session:${fe.id}`,label:et})},className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),W?s.jsxs(_t,{disabled:!ke,onClick:Xt,className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(nr,{}),s.jsxs(_t,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>q(fe,{archivedBucket:o}),children:[s.jsx(A,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e(o?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(l.Fragment,{children:[s.jsx(zP,{sessionId:fe.id,sessionDirectory:ke??null,sessionTitle:et,children:s.jsxs("div",{"data-session-row":fe.id,"data-session-scope":ke??"","data-session-archived":o?"1":"0",className:ye("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",De?"opacity-75":"",r>0&&"pl-[20px]",le&&"bg-primary/15"),children:[Ut,Ye,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:K?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",disabled:De,onPointerDown:re,onPointerUp:vt,onPointerCancel:vt,onMouseDown:qt,onClick:ct=>Wt(ct),onDoubleClick:ct=>{ct.stopPropagation(),w(fe.id,et)},className:ye("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]",Y&&"bg-interactive-hover/70",J?Q?ce:xe:ce),children:s.jsxs("div",{className:ye("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:ye("block min-w-0 flex-1 truncate typography-ui-label font-normal",Qe?"text-primary":"text-foreground"),children:to(et,f)}),J?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Le}):null,J?null:s.jsx("div",{className:"relative ml-1 flex h-4 min-w-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:ye("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",ze?"opacity-0":ve),children:Le})}),Zt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(A,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Zt})]}):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:ye("flex items-center gap-3 text-left text-muted-foreground",ie?.projectLabel?"justify-between":"justify-start"),children:[ie?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:ie.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:Ae})]}),ie?.branchLabel||Ge?s.jsxs("div",{className:ye("flex items-center gap-3 text-left text-muted-foreground",ie?.branchLabel?"justify-between":"justify-start"),children:[ie?.branchLabel?s.jsx("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ie.branchLabel})]})}):null,Ge?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",Ge.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",Ge.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:De,onPointerDown:re,onPointerUp:vt,onPointerCancel:vt,onMouseDown:qt,onClick:ct=>Wt(ct),onDoubleClick:ct=>{ct.stopPropagation(),w(fe.id,et)},className:ye("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]",Y&&"bg-interactive-hover/70",J?Q?ce:xe:ce),children:[s.jsxs("div",{className:ye("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:ye("block min-w-0 flex-1 truncate typography-ui-label font-normal",Qe?"text-primary":"text-foreground"),children:to(et,f)}),Zt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(A,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Zt})]}):null]}),K?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:Ae}),Ge?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:["+",Ge.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Ge.deletions]})]}):null,me?s.jsx("span",{className:"truncate",children:ie?.projectLabel}):null,pe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ie?.branchLabel})]}):null]})})]})}),Tt&&!L?s.jsx("div",{className:ye("absolute top-1/2 -translate-y-1/2 z-10",K?"right-0":"right-[30px]"),children:Tt}):null,s.jsxs("div",{className:ye("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",ze||J&&!Q?"opacity-100":ye("opacity-0",ge)),children:[he?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:ye("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",K&&!J?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:Ms,onMouseDown:xs,onClick:Bs,onKeyDown:ct=>ct.stopPropagation(),children:s.jsx(A,{name:"archive",className:ye(K&&!J?"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,te?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:ye("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",K&&!J?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:ws,onMouseDown:xn,onClick:Qs,onKeyDown:ct=>ct.stopPropagation(),children:s.jsx(A,{name:"external-link",className:ye(K&&!J?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(It,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(As,{open:ze,onOpenChange:Kt,children:[s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:ye("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",K&&!J?ze?"h-4 w-4 opacity-100":ye("h-4 w-4 opacity-0",ge):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:es,onMouseDown:ss,onClick:St,onKeyDown:ct=>ct.stopPropagation(),children:s.jsx(A,{name:"more-2",className:ye(K&&!J?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),Ft]})]})]})}),Ze&&qe?n.children.map(ct=>Z(ct,r+1,ke??a,i,o,void 0,ne)):null,s.jsx(us,{open:we,onOpenChange:ee,children:s.jsxs(ds,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(hs,{children:[s.jsx(ms,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Ns,{children:dt===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:dt}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:dt})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:F,onChange:ct=>U(ct.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(_s,{children:[s.jsx(be,{type:"button",onClick:()=>ee(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(be,{type:"button",onClick:()=>{ee(!1),ts(F)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),Ke?s.jsx(KA,{session:Ie,open:lt,onOpenChange:xt}):null]},fe.id)}const JA=l.memo(qA,GA);function YA(t){const e=ot.c(71),{t:n}=ft(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:o,onConfirm:c}=t;let d,p,m,u,f,b,x,y,g,h;if(e[0]!==a||e[1]!==n||e[2]!==r){const O=n("sessions.sidebar.session.untitled");u=us,g=!!r,e[13]!==a?(h=q=>{q||a(null)},e[13]=a,e[14]=h):h=e[14],m=ds,x=!1,y="max-w-sm gap-5",p=hs;let _;e[15]!==n||e[16]!==r?.archivedBucket?(_=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=_):_=e[17],e[18]!==_?(b=s.jsx(ms,{children:_}),e[18]=_,e[19]=b):b=e[19],d=Ns,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]=b,e[9]=x,e[10]=y,e[11]=g,e[12]=h}else d=e[3],p=e[4],m=e[5],u=e[6],f=e[7],b=e[8],x=e[9],y=e[10],g=e[11],h=e[12];let j;e[20]!==d||e[21]!==f?(j=s.jsx(d,{children:f}),e[20]=d,e[21]=f,e[22]=j):j=e[22];let v;e[23]!==p||e[24]!==b||e[25]!==j?(v=s.jsxs(p,{children:[b,j]}),e[23]=p,e[24]=b,e[25]=j,e[26]=v):v=e[26];let C;e[27]!==o||e[28]!==i?(C=()=>o(!i),e[27]=o,e[28]=i,e[29]=C):C=e[29];const k=!i;let w;e[30]!==i?(w=i?s.jsx(A,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(A,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=i,e[31]=w):w=e[31];let N;e[32]!==n?(N=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=N):N=e[33];let I;e[34]!==w||e[35]!==N||e[36]!==C||e[37]!==k?(I=s.jsxs("button",{type:"button",onClick:C,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":k,children:[w,N]}),e[34]=w,e[35]=N,e[36]=C,e[37]=k,e[38]=I):I=e[38];let T;e[39]!==a?(T=()=>a(null),e[39]=a,e[40]=T):T=e[40];let P;e[41]!==n?(P=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=P):P=e[42];let D;e[43]!==T||e[44]!==P?(D=s.jsx("button",{type:"button",onClick:T,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:P}),e[43]=T,e[44]=P,e[45]=D):D=e[45];let S;e[46]!==c?(S=()=>{c()},e[46]=c,e[47]=S):S=e[47];let M;e[48]!==n||e[49]!==r?.archivedBucket?(M=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=M):M=e[50];let E;e[51]!==S||e[52]!==M?(E=s.jsx("button",{type:"button",onClick:S,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:M}),e[51]=S,e[52]=M,e[53]=E):E=e[53];let R;e[54]!==D||e[55]!==E?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[D,E]}),e[54]=D,e[55]=E,e[56]=R):R=e[56];let V;e[57]!==I||e[58]!==R?(V=s.jsxs(_s,{className:"w-full sm:items-center sm:justify-between",children:[I,R]}),e[57]=I,e[58]=R,e[59]=V):V=e[59];let B;e[60]!==m||e[61]!==x||e[62]!==V||e[63]!==y||e[64]!==v?(B=s.jsxs(m,{showCloseButton:x,className:y,children:[v,V]}),e[60]=m,e[61]=x,e[62]=V,e[63]=y,e[64]=v,e[65]=B):B=e[65];let $;return e[66]!==u||e[67]!==B||e[68]!==g||e[69]!==h?($=s.jsx(u,{open:g,onOpenChange:h,children:B}),e[66]=u,e[67]=B,e[68]=g,e[69]=h,e[70]=$):$=e[70],$}function QA(t){const e=ot.c(57),{t:n}=ft(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:o,onConfirm:c}=t,d=r?.archivedBucket===!0,p=r?.sessionCount??0;let m;e[0]!==d||e[1]!==p||e[2]!==n?(m=n(d?p===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":p===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=p,e[2]=n,e[3]=m):m=e[3];const u=m;let f;e[4]!==d||e[5]!==p||e[6]!==n?(f=d?p===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:p}):p===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:p}),e[4]=d,e[5]=p,e[6]=n,e[7]=f):f=e[7];const b=f,x=!!r;let y;e[8]!==a?(y=$=>{$||a(null)},e[8]=a,e[9]=y):y=e[9];let g;e[10]!==u?(g=s.jsx(ms,{children:u}),e[10]=u,e[11]=g):g=e[11];let h;e[12]!==b?(h=s.jsx(Ns,{children:b}),e[12]=b,e[13]=h):h=e[13];let j;e[14]!==g||e[15]!==h?(j=s.jsxs(hs,{children:[g,h]}),e[14]=g,e[15]=h,e[16]=j):j=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 C=!i;let k;e[20]!==i?(k=i?s.jsx(A,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(A,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=i,e[21]=k):k=e[21];let w;e[22]!==n?(w=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=w):w=e[23];let N;e[24]!==w||e[25]!==v||e[26]!==C||e[27]!==k?(N=s.jsxs("button",{type:"button",onClick:v,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":C,children:[k,w]}),e[24]=w,e[25]=v,e[26]=C,e[27]=k,e[28]=N):N=e[28];let I;e[29]!==a?(I=()=>a(null),e[29]=a,e[30]=I):I=e[30];let T;e[31]!==n?(T=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=T):T=e[32];let P;e[33]!==I||e[34]!==T?(P=s.jsx("button",{type:"button",onClick:I,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:T}),e[33]=I,e[34]=T,e[35]=P):P=e[35];let D;e[36]!==c?(D=()=>{c()},e[36]=c,e[37]=D):D=e[37];let S;e[38]!==d||e[39]!==n?(S=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=S):S=e[40];let M;e[41]!==D||e[42]!==S?(M=s.jsx("button",{type:"button",onClick:D,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:S}),e[41]=D,e[42]=S,e[43]=M):M=e[43];let E;e[44]!==P||e[45]!==M?(E=s.jsxs("div",{className:"flex items-center gap-2",children:[P,M]}),e[44]=P,e[45]=M,e[46]=E):E=e[46];let R;e[47]!==N||e[48]!==E?(R=s.jsxs(_s,{className:"w-full sm:items-center sm:justify-between",children:[N,E]}),e[47]=N,e[48]=E,e[49]=R):R=e[49];let V;e[50]!==R||e[51]!==j?(V=s.jsxs(ds,{showCloseButton:!1,className:"max-w-sm gap-5",children:[j,R]}),e[50]=R,e[51]=j,e[52]=V):V=e[52];let B;return e[53]!==x||e[54]!==V||e[55]!==y?(B=s.jsx(us,{open:x,onOpenChange:y,children:V}),e[53]=x,e[54]=V,e[55]=y,e[56]=B):B=e[56],B}function XA(t){const e=ot.c(36),{t:n}=ft(),{value:r,setValue:a,onConfirm:i}=t,o=!!r;let c;e[0]!==a?(c=k=>{k||a(null)},e[0]=a,e[1]=c):c=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let p;e[4]!==d?(p=s.jsx(ms,{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(Ns,{children:m}),e[9]=m,e[10]=u):u=e[10];let f;e[11]!==p||e[12]!==u?(f=s.jsxs(hs,{children:[p,u]}),e[11]=p,e[12]=u,e[13]=f):f=e[13];let b;e[14]!==a?(b=()=>a(null),e[14]=a,e[15]=b):b=e[15];let x;e[16]!==n?(x=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=x):x=e[17];let y;e[18]!==b||e[19]!==x?(y=s.jsx("button",{type:"button",onClick:b,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:x}),e[18]=b,e[19]=x,e[20]=y):y=e[20];let g;e[21]!==n?(g=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=g):g=e[22];let h;e[23]!==i||e[24]!==g?(h=s.jsx("button",{type:"button",onClick:i,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:g}),e[23]=i,e[24]=g,e[25]=h):h=e[25];let j;e[26]!==h||e[27]!==y?(j=s.jsxs(_s,{children:[y,h]}),e[26]=h,e[27]=y,e[28]=j):j=e[28];let v;e[29]!==j||e[30]!==f?(v=s.jsxs(ds,{showCloseButton:!1,className:"max-w-sm gap-5",children:[f,j]}),e[29]=j,e[30]=f,e[31]=v):v=e[31];let C;return e[32]!==o||e[33]!==c||e[34]!==v?(C=s.jsx(us,{open:o,onOpenChange:c,children:v}),e[32]=o,e[33]=c,e[34]=v,e[35]=C):C=e[35],C}const ZA=t=>{const e=ot.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}=ft(),b=!!r&&!i;let x;e[0]!==i||e[1]!==f?(x=f(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=f,e[2]=x):x=e[2];const y=x;let g;e[3]!==n||e[4]!==f?(g=f("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=f,e[5]=g):g=e[5];let h;e[6]!==g?(h=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:g}),e[6]=g,e[7]=h):h=e[7];let j;e[8]!==b||e[9]!==p||e[10]!==c||e[11]!==o||e[12]!==d||e[13]!==a||e[14]!==f?(j=b?s.jsxs(As,{children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":f("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(A,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:f("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Ps,{align:"end",className:"min-w-[180px]",children:[a.length===0?s.jsx(_t,{disabled:!0,className:"text-muted-foreground",children:f("sessions.sidebar.folders.none")}):a.map(V=>s.jsx(_t,{onClick:()=>o(V.id),children:s.jsx("span",{className:"flex-1 truncate",children:V.name})},V.id)),s.jsx(nr,{}),s.jsxs(_t,{onClick:c,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"}),f("sessions.sidebar.folders.newFolderEllipsis")]}),p?s.jsxs(_t,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"close",className:"mr-1 h-4 w-4"}),f("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=b,e[9]=p,e[10]=c,e[11]=o,e[12]=d,e[13]=a,e[14]=f,e[15]=j):j=e[15];let v;e[16]===Symbol.for("react.memo_cache_sentinel")?(v=ye("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[16]=v):v=e[16];let C;e[17]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(A,{name:"delete-bin",className:"h-4 w-4"}),e[17]=C):C=e[17];let k;e[18]!==y||e[19]!==m?(k=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:v,"aria-label":y,children:C})}),e[18]=y,e[19]=m,e[20]=k):k=e[20];let w;e[21]!==y?(w=s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:y})}),e[21]=y,e[22]=w):w=e[22];let N;e[23]!==k||e[24]!==w?(N=s.jsxs(kt,{children:[k,w]}),e[23]=k,e[24]=w,e[25]=N):N=e[25];let I;e[26]!==f?(I=f("sessions.sidebar.header.actions.exitSelection"),e[26]=f,e[27]=I):I=e[27];let T;e[28]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(A,{name:"close",className:"h-4 w-4"}),e[28]=T):T=e[28];let P;e[29]!==u||e[30]!==I?(P=s.jsx(Ct,{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:T})}),e[29]=u,e[30]=I,e[31]=P):P=e[31];let D;e[32]!==f?(D=f("sessions.sidebar.header.actions.exitSelection"),e[32]=f,e[33]=D):D=e[33];let S;e[34]!==D?(S=s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:D})}),e[34]=D,e[35]=S):S=e[35];let M;e[36]!==P||e[37]!==S?(M=s.jsxs(kt,{children:[P,S]}),e[36]=P,e[37]=S,e[38]=M):M=e[38];let E;e[39]!==M||e[40]!==j||e[41]!==N?(E=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[j,N,M]}),e[39]=M,e[40]=j,e[41]=N,e[42]=E):E=e[42];let R;return e[43]!==E||e[44]!==h?(R=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[h,E]}),e[43]=E,e[44]=h,e[45]=R):R=e[45],R},ix="oc.sessions.activeNow",eD=2160*60*1e3,ox=t=>!!t.parentID,Su=t=>!!t.time?.archived,Ud=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},tD=t=>{try{const e=t.getItem(ix);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[]}},sd=(t,e)=>{try{t.setItem(ix,JSON.stringify(e))}catch{}},sD=(t,e,n=Date.now())=>{const r=n-eD;return t.filter(a=>{const i=e.get(a.sessionId);return i?Su(i)?!1:Ud(i)>=r:!0})},nD=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],lx=t=>[...t].sort((e,n)=>Ud(n)-Ud(e)),rD=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!Su(r)).filter(r=>!ox(r));return lx(n)},aD=(t,e)=>{const n=t.filter(r=>{if(Su(r)||ox(r))return!1;const a=e[r.id];return a?.type==="busy"||a?.type==="retry"});return lx(n)},Zo=br(),nd=ar((t,e)=>({entries:tD(Zo),setEntries:n=>{n!==e().entries&&(t({entries:n}),sd(Zo,n))},addSession:n=>{const r=nD(e().entries,n);r!==e().entries&&(t({entries:r}),sd(Zo,r))},prune:n=>{const r=e().entries,a=sD(r,n);a.length===r.length&&a.every((i,o)=>i.sessionId===r[o]?.sessionId)||(t({entries:a}),sd(Zo,a))}})),el="oc.sessions.projectCollapse",$f="oc.sessions.groupOrder",_f="oc.sessions.groupCollapse",Bf="oc.sessions.activeSessionByProject",rd="oc.sessions.expandedParents.v2",iD="oc.sessions.expandedParents",oD="oc.sessions.pinned",lD=(t,e)=>{const n=new Set;for(const r of t){const a=bs(r.path)?.toLowerCase();a&&n.add(a)}for(const r of e.values())for(const a of r){const i=bs(a.path)?.toLowerCase();i&&n.add(i)}return n},cD=(t,e)=>{if(t.time?.archived)return!0;const n=bs(eo(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},dD=5*6e4,Vf=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:a=!1})=>{const{t:i}=ft(),[o,c]=l.useState(!1),[d,p]=l.useState(""),m=l.useRef(null),u=l.useRef(null),f=l.useRef(new Set),[b,x]=l.useState(null),[y,g]=l.useState(""),[h,j]=l.useState(null),[v,C]=l.useState(new Set),[k]=l.useState(()=>new Map),w=l.useMemo(()=>br(),[]),N=nd($e=>$e.entries),I=nd($e=>$e.addSession),T=nd($e=>$e.prune),[P,D]=l.useState(new Set),[S,M]=l.useState(new Map),[E,R]=l.useState(new Set),[V,B]=l.useState(!1),[$,O]=l.useState(!1),[_,q]=l.useState(null),[L,J]=l.useState(null),[Z,ie]=l.useState(""),[ne,me]=l.useState(null),[pe,G]=l.useState(null),[K,Q]=l.useState(null),W=vc($e=>$e.ids),de=vc($e=>$e.setIds),ge=vc($e=>$e.toggle),[ve,te]=l.useState(()=>{try{const $e=br().getItem(_f);if(!$e)return new Set;const Dt=JSON.parse($e);return new Set(Array.isArray(Dt)?Dt.filter(bt=>typeof bt=="string"):[])}catch{return new Set}}),[he,ce]=l.useState(()=>{try{const $e=br().getItem($f);if(!$e)return new Map;const Dt=JSON.parse($e),bt=new Map;return Object.entries(Dt).forEach(([Gt,ys])=>{Array.isArray(ys)&&bt.set(Gt,ys.filter(rn=>typeof rn=="string"))}),bt}catch{return new Map}}),[xe,se]=l.useState(()=>{try{const $e=br().getItem(Bf);if(!$e)return new Map;const Dt=JSON.parse($e),bt=new Map;return Object.entries(Dt).forEach(([Gt,ys])=>{typeof ys=="string"&&ys.length>0&&bt.set(Gt,ys)}),bt}catch{return new Map}}),[ue,Y]=l.useState(new Map),Se=l.useRef(new Map),fe=l.useRef(0),Ce=Ws($e=>$e.homeDirectory),Ie=Ws($e=>$e.currentDirectory),ke=Ws($e=>$e.setDirectory),X=Cs($e=>$e.projects),ae=Cs($e=>$e.activeProjectId),je=Cs($e=>$e.removeProject),le=Cs($e=>$e.setActiveProjectIdOnly),Ne=Cs($e=>$e.updateProjectMeta),Me=Cs($e=>$e.reorderProjects),Ve=Fe($e=>$e.setActiveMainTab),we=Fe($e=>$e.openContextPanelTab),ee=Fe($e=>$e.setSettingsDialogOpen),F=Fe($e=>$e.toggleHelpDialog),U=Fe($e=>$e.setAboutDialogOpen),oe=Fe($e=>$e.setSessionSwitcherOpen),Te=Fe($e=>$e.setScheduledTasksDialogOpen),Oe=Fe($e=>$e.openMultiRunLauncher),Pe=Fe($e=>$e.notifyOnSubtasks),z=Fe($e=>$e.showDeletionDialog),De=Fe($e=>$e.setShowDeletionDialog),Qe=tc(d,120),et=l.useMemo(()=>Qe.trim().toLowerCase(),[Qe]),Ze=et.length>0,We=er($e=>$e.collapsedFolderIds),it=er($e=>$e.foldersMap),qe=er($e=>$e.getFoldersForScope),st=er($e=>$e.createFolder),Je=er($e=>$e.renameFolder),Be=er($e=>$e.deleteFolder),nt=er($e=>$e.addSessionToFolder),Ge=er($e=>$e.addSessionsToFolder),at=er($e=>$e.removeSessionFromFolder),Ae=er($e=>$e.removeSessionsFromFolders),Le=er($e=>$e.toggleFolderCollapse),ze=er($e=>$e.cleanupSessions),Ke=er($e=>$e.getSessionFolderId);oP({isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchContainerRef:m});const lt=Ah(),xt=ou(),dt=Gd(),ut=nv(),Nt=xa($e=>$e.hasLoaded),ts=xa($e=>$e.activeSessions),Vt=xa($e=>$e.archivedSessions),Xt=$t($e=>$e.currentSessionId),ht=$t($e=>!!$e.newSessionDraft?.open),Bt=$t($e=>$e.setCurrentSession),Zt=$t($e=>$e.updateSessionTitle),gs=$t($e=>$e.shareSession),rs=$t($e=>$e.unshareSession),ps=$t($e=>$e.worktreeMetadata),Ut=$t($e=>$e.availableWorktreesByProject),Ye=$t($e=>$e.openNewSessionDraft),Tt=Ua(Gn($e=>({checkForUpdates:$e.checkForUpdates,available:$e.available,runtimeType:$e.runtimeType,info:$e.info,downloading:$e.downloading,downloaded:$e.downloaded,progress:$e.progress,error:$e.error,downloadUpdate:$e.downloadUpdate,restartToUpdate:$e.restartToUpdate}))),Kt=l.useMemo(()=>lD(X,Ut),[Ut,X]),St=l.useMemo(()=>{const $e=new Map(dt.map(Gt=>[Gt.id,Gt])),Dt=ts.map(Gt=>$e.get(Gt.id)??Gt),bt=new Set(Dt.map(Gt=>Gt.id));return dt.forEach(Gt=>{bt.has(Gt.id)||Dt.push(Gt)}),Dt.filter(Gt=>cD(Gt,Kt))},[ts,Kt,dt]),es=l.useMemo(()=>dt.map($e=>{const Dt=bs($e.directory??null)??"";return`${$e.id}:${$e.title??""}:${$e.time?.archived?1:0}:${Dt}`}).join("|"),[dt]),ss=l.useRef(dt);l.useEffect(()=>{ss.current=dt},[es,dt]);const Ms=l.useMemo(()=>X.map($e=>`${$e.id}:${bs($e.path)??""}`).join("|"),[X]),xs=l.useRef(!1);l.useEffect(()=>{xs.current||(xs.current=!0,pd(ss.current))},[]),l.useEffect(()=>{let $e=!1;return(async()=>{const bt=Cs.getState().projects;if(bt.length===0)return;const Gt=new Map,ys=[];await Promise.all(bt.map(async rn=>{const Dn=bs(rn.path);if(Dn)try{if(!(Ys.getState().directories.get(Dn)?.isGitRepo??await Tr(()=>import("./modelPrefsAutoSave-DRJSYigo.js").then(Cn=>Cn.eZ),__vite__mapDeps([2,0,1,3,4])).then(Cn=>Cn.checkIsGitRepository(Dn))))return;const Tn=await md({id:rn.id,path:Dn});if($e||Tn.length===0)return;Gt.set(Dn,Tn),ys.push(...Tn)}catch{}})),!$e&&$t.setState({availableWorktrees:ys,availableWorktreesByProject:Gt})})(),()=>{$e=!0}},[Ms]),l.useEffect(()=>{let $e=null;const Dt=Xg(bt=>{bt.type==="scheduled-task-ran"&&($e&&clearTimeout($e),$e=setTimeout(()=>{pd(ss.current)},500))});return()=>{$e&&clearTimeout($e),Dt()}},[]);const Bs=l.useMemo(()=>jn(),[]),ws=l.useMemo(()=>fn(),[]),{isTablet:xn}=ln(),Qs=t||xn,{buildGroupSearchText:Wt,filterSessionNodesForSearch:qt,buildGroupedSessions:re}=iP({homeDirectory:Ce,worktreeMetadata:ps,pinnedSessionIds:W,gitBranches:lt,isVSCode:ws}),{scheduleCollapsedProjectsPersist:vt}=fP({isVSCode:ws,hasLoadedGlobalSessions:Nt,safeStorage:w,keys:{sessionExpanded:rd,sessionExpandedLegacy:iD,projectCollapse:el,sessionPinned:oD,groupOrder:$f,projectActiveSession:Bf,groupCollapse:_f},sessions:St,setPinnedSessionIds:de,groupOrderByProject:he,activeSessionByProject:xe,collapsedGroups:ve,setExpandedParents:C,setCollapsedProjects:D}),Ft=l.useMemo(()=>[...St].sort(($e,Dt)=>bi($e,Dt,W)),[St,W]),ct=l.useMemo(()=>new Map(Ft.map(($e,Dt)=>[$e.id,Dt])),[Ft]),ls=l.useMemo(()=>{const $e=new Map;return Ft.forEach(Dt=>{const bt=Dt.parentID;if(!bt)return;const Gt=$e.get(bt)??[];Gt.push(Dt),$e.set(bt,Gt)}),$e.forEach(Dt=>Dt.sort((bt,Gt)=>bi(bt,Gt,W))),$e},[Ft,W]),cs=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")})]}),He=l.useMemo(()=>X.find($e=>$e.id===h)??null,[X,h]),yt=l.useCallback($e=>{h&&(Ne(h,$e),j(null))},[h,Ne]),Et=l.useCallback(()=>{B(!0)},[]),Rt=l.useCallback(()=>{const $e=Ua.getState();if($e.available&&$e.info){O(!0);return}Tt.checkForUpdates().then(()=>{const{available:Dt,error:bt}=Ua.getState();if(bt){H.error(i("sessions.sidebar.updateCheck.errorTitle"),{description:bt});return}if(!Dt){H.success(i("sessions.sidebar.updateCheck.latestVersion"));return}O(!0)})},[i,Tt]),Yt=l.useCallback(()=>{t&&oe(!1),ee(!0)},[t,oe,ee]),Ot=Tt.available&&(Tt.runtimeType==="desktop"||Tt.runtimeType==="web"),Os=$t($e=>$e.deleteSession),Ds=$t($e=>$e.deleteSessions),Ts=$t($e=>$e.archiveSession),Vs=$t($e=>$e.archiveSessions),{copiedSessionId:js,handleSessionSelect:Bn,handleSessionDoubleClick:bn,handleSaveEdit:mn,handleCancelEdit:lr,handleShareSession:Us,handleCopyShareUrl:yn,handleUnshareSession:ir,handleDeleteSession:Mn,confirmDeleteSession:Rr}=lP({activeProjectId:ae,currentDirectory:Ie,currentSessionId:Xt,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:o,sessionSearchQuery:d,setSessionSearchQuery:p,setIsSessionSearchOpen:c,setActiveProjectIdOnly:le,setDirectory:ke,setActiveMainTab:Ve,setSessionSwitcherOpen:oe,setCurrentSession:Bt,updateSessionTitle:Zt,shareSession:gs,unshareSession:rs,deleteSession:Os,deleteSessions:Ds,archiveSession:Ts,archiveSessions:Vs,childrenMap:ls,showDeletionDialog:z,setDeleteSessionConfirm:me,deleteSessionConfirm:ne,setEditingId:x,setEditTitle:g,editingId:b,editTitle:y}),$s=l.useCallback(()=>{if(!pe)return;const{scopeKey:$e,folderId:Dt}=pe;G(null),Be($e,Dt)},[pe,Be]),Ks=l.useCallback(()=>{Dr.requestDirectoryDialog()},[]);l.useEffect(()=>{if(!Xt)return;const Dt=St.find(Gt=>Gt.id===Xt)?.parentID;if(!Dt)return;const bt=[`project:active:${Dt}`,`project:archived:${Dt}`,`recent:active:${Dt}`,`recent:archived:${Dt}`];C(Gt=>{if(bt.every(rn=>Gt.has(rn)))return Gt;const ys=new Set(Gt);bt.forEach(rn=>ys.add(rn));try{w.setItem(rd,JSON.stringify(Array.from(ys)))}catch{}return ys})},[Xt,St,w]);const Ue=l.useCallback($e=>{C(Dt=>{const bt=new Set(Dt);bt.has($e)?bt.delete($e):bt.add($e);try{w.setItem(rd,JSON.stringify(Array.from(bt)))}catch{}return bt})},[w]),Pt=l.useCallback(($e,Dt)=>{if(!$e)return null;Dt&&We.has(Dt)&&Le(Dt);const bt=st($e,i("sessions.sidebar.folder.newFolderName"),Dt);return J(bt.id),ie(bt.name),bt},[We,Le,st,i]),Ht=l.useCallback($e=>{R(Dt=>{const bt=new Set(Dt);return bt.has($e)?bt.delete($e):bt.add($e),bt})},[]),ns=l.useCallback(()=>{fe.current=Date.now()+150,D(()=>{const $e=new Set(X.map(Dt=>Dt.id));try{w.setItem(el,JSON.stringify(Array.from($e)))}catch{}return ws||vt($e),$e})},[X,ws,w,vt]),qs=l.useCallback(()=>{fe.current=Date.now()+150,D(()=>{const $e=new Set;try{w.setItem(el,JSON.stringify([]))}catch{}return ws||vt($e),$e})},[ws,w,vt]),Gs=l.useCallback($e=>{fe.current=Date.now()+150,D(Dt=>{const bt=new Set(Dt);bt.has($e)?bt.delete($e):bt.add($e);try{w.setItem(el,JSON.stringify(Array.from(bt)))}catch{}return ws||vt(bt),bt})},[ws,w,vt]),Ls=l.useMemo(()=>X.map($e=>({...$e,normalizedPath:bs($e.path)})).filter($e=>!!$e.normalizedPath),[X]),sn=l.useMemo(()=>Ls.map($e=>$e.normalizedPath),[Ls]),{github:nn}=_n(),qn=Hn($e=>$e.status),Jn=Hn($e=>$e.hasChecked),aa=rv(sn),Ur=xr($e=>$e.ensureEntry),Nn=xr($e=>$e.setParams),cn=xr($e=>$e.refreshTargets);hP({normalizedProjects:Ls,gitRepoStatus:aa,setProjectRepoStatus:M,setProjectRootBranches:Y});const hn=$t($e=>$e.isLoading);kP({isSessionsLoading:hn,sessions:St,archivedSessions:Vt,normalizedProjects:Ls,isVSCode:ws,availableWorktreesByProject:Ut,cleanupSessions:ze});const{getSessionsForProject:Sn,getArchivedSessionsForProject:cr}=vP({isVSCode:ws,sessions:St,archivedSessions:Vt,availableWorktreesByProject:Ut});X6({normalizedProjects:Ls,sessions:St,archivedSessions:Vt,availableWorktreesByProject:Ut,isVSCode:ws,isSessionsLoading:hn,foldersMap:it,createFolder:st,addSessionToFolder:nt,cleanupSessions:ze});const dr=l.useRef(!1);ae&&S.has(ae)&&(dr.current=!!S.get(ae));const{projectSections:an,groupSearchDataByGroup:Fr,sectionsForRender:Yn,searchMatchCount:Qn}=tP({normalizedProjects:Ls,getSessionsForProject:Sn,getArchivedSessionsForProject:cr,availableWorktreesByProject:Ut,projectRepoStatus:S,projectRootBranches:ue,lastRepoStatus:dr.current,buildGroupedSessions:re,hasSessionSearchQuery:Ze,normalizedSessionSearchQuery:et,filterSessionNodesForSearch:qt,buildGroupSearchText:Wt,foldersMap:it}),ei=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:i("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:i("sessions.sidebar.empty.noMatches.description")})]}),{currentSessionDirectory:wa}=nP({projectSections:an,activeProjectId:ae,activeSessionByProject:xe,setActiveSessionByProject:se,currentSessionId:Xt,handleSessionSelect:Bn,newSessionDraftOpen:ht,mobileVariant:t,openNewSessionDraft:Ye,setActiveMainTab:Ve,setSessionSwitcherOpen:oe,sessions:St,worktreeMetadata:ps}),{getOrderedGroups:ti}=rP(he),Xn=l.useRef(!1);l.useEffect(()=>{if(Xn.current||an.length===0)return;const $e=an.flatMap(Dt=>Dt.groups.filter(bt=>bt.isArchivedBucket).map(bt=>`${Dt.project.id}:${bt.id}`));$e.length>0&&te(Dt=>new Set([...Dt,...$e])),Xn.current=!0},[an]);const Wr=l.useMemo(()=>{const $e=new Map,Dt=new Map;return an.forEach(bt=>{const Gt=Oh(bt.project.label?.trim()||Ga(bt.project.normalizedPath,Ce)||bt.project.normalizedPath);bt.groups.forEach(ys=>{const rn=ys.branch&&ys.branch!=="HEAD"&&ys.branch!==Gt?ys.branch:null,Dn={projectLabel:Gt,branchLabel:rn},Lr=ur=>{ur.forEach(Tn=>{const Cn=bt.project.normalizedPath.length,Ca=Dt.get(Tn.session.id)??-1;Cn<Ca||($e.set(Tn.session.id,{node:Tn,projectId:bt.project.id,groupDirectory:ys.directory,secondaryMeta:Dn}),Dt.set(Tn.session.id,Cn),Tn.children.length>0&&Lr(Tn.children))})};Lr(ys.sessions)})}),$e},[an,Ce]),Js=Ba($e=>$e.showRecentSection),Vn=l.useMemo(()=>Js?rD(N,new Map(St.map($e=>[$e.id,$e]))).sort(($e,Dt)=>bi($e,Dt,W)):[],[N,W,St,Js]),ja=l.useMemo(()=>Js?aD(St,ut):[],[ut,St,Js]);l.useEffect(()=>{!Js||ja.length===0||ja.forEach($e=>I($e.id))},[I,ja,Js]),l.useEffect(()=>{if(!Js)return;const $e=new Map;[...St,...Vt].forEach(Dt=>{$e.set(Dt.id,Dt)}),T($e)},[Vt,T,St,Js]);const ia=l.useMemo(()=>{if(!Js)return[];const $e=Dt=>{const bt=Wr.get(Dt.id),Gt=bs(Dt.directory??null);return{node:bt?.node??{session:Dt,children:[],worktree:null},projectId:bt?.projectId??null,groupDirectory:bt?.groupDirectory??Gt,secondaryMeta:bt?.secondaryMeta??null}};return[{key:"active-now",title:i("sessions.sidebar.activity.recentTitle"),items:Vn.map($e)}]},[Vn,Wr,Js,i]),Nr=l.useMemo(()=>new Set(Vn.map($e=>$e.id)),[Vn]),si=l.useMemo(()=>[...Nr],[Nr]);g6({currentSessionId:Xt,sortedSessions:Ft,recentSessionIds:si,ensureSessionRenderable:xt.ensureSessionRenderable});const pn=l.useMemo(()=>{if(!ws||Ze||Nr.size===0)return Yn;const $e=Dt=>Dt.reduce((bt,Gt)=>{if(Nr.has(Gt.session.id))return bt;const ys=$e(Gt.children);return ys.length===Gt.children.length?(bt.push(Gt),bt):(bt.push({...Gt,children:ys}),bt)},[]);return Yn.map(Dt=>({...Dt,groups:Dt.groups.map(bt=>({...bt,sessions:$e(bt.sessions)}))}))},[ws,Ze,Nr,Yn]),ni=l.useMemo(()=>{const $e=new Set;return pn.forEach(Dt=>{Dt.groups.forEach(bt=>{const Gt=bs(bt.directory??null),ys=bt.branch?.trim()||lt.get(Gt||"")?.trim();!Gt||!ys||$e.add(no(Gt,ys))})}),[...$e]},[lt,pn]),ri=W0(ni);l.useEffect(()=>{if(!Jn||!qn?.connected||!nn)return;const $e=[],Dt=Date.now();if(pn.forEach(Gt=>{P.has(Gt.project.id)||Gt.groups.forEach(ys=>{const rn=bs(ys.directory??null),Dn=ys.branch?.trim()||lt.get(rn||"")?.trim();if(!rn||!Dn)return;const Lr=no(rn,Dn),ur=xr.getState().entries[Lr],Tn=!!ur?.status?.pr,Cn=`${rn}::${Dn}`,Ca=Math.max(ur?.lastRefreshAt??0,ur?.lastDiscoveryPollAt??0),Ao=!!(ur?.isInitialStatusResolved&&!Tn&&(!f.current.has(Cn)||Dt-Ca>=dD));(!ur||!ur.isInitialStatusResolved||Ao)&&(Ao&&f.current.add(Cn),$e.push({directory:rn,branch:Dn}))})}),$e.length===0)return;const bt=new Map;$e.forEach(Gt=>{const ys=no(Gt.directory,Gt.branch,Gt.remoteName??null);bt.has(ys)||bt.set(ys,Gt)}),bt.forEach((Gt,ys)=>{Ur(ys),Nn(ys,{directory:Gt.directory,branch:Gt.branch,remoteName:Gt.remoteName??null,canShow:!0,github:nn,githubAuthChecked:Jn,githubConnected:qn.connected})}),cn([...bt.values()],{silent:!0,markInitialResolved:!0})},[P,Ur,nn,Jn,qn?.connected,lt,cn,pn,Nn]);const An=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",oa="h-4.5 w-4.5",Fi=AP({isDesktopShellRuntime:Bs,projectSections:an,projectHeaderSentinelRefs:Se}),Or=l.useCallback(($e,Dt=0,bt,Gt,ys=!1,rn,Dn="project")=>s.jsx(JA,{node:$e,depth:Dt,groupDirectory:bt,projectId:Gt,archivedBucket:ys,directoryStatus:k,currentSessionId:Xt,pinnedSessionIds:W,expandedParents:v,hasSessionSearchQuery:Ze,normalizedSessionSearchQuery:et,notifyOnSubtasks:Pe,editingId:b,setEditingId:x,editTitle:y,setEditTitle:g,handleSaveEdit:mn,handleCancelEdit:lr,toggleParent:Ue,handleSessionSelect:Bn,handleSessionDoubleClick:bn,togglePinnedSession:ge,handleShareSession:Us,copiedSessionId:js,handleCopyShareUrl:yn,handleUnshareSession:ir,openSidebarMenuKey:_,setOpenSidebarMenuKey:q,renamingFolderId:L,getFoldersForScope:qe,getSessionFolderId:Ke,removeSessionFromFolder:at,addSessionToFolder:nt,createFolderAndStartRename:Pt,openContextPanelTab:we,handleDeleteSession:Mn,mobileVariant:t,alwaysShowActions:Qs,renderSessionNode:Or,secondaryMeta:rn,renderContext:Dn}),[k,Xt,W,v,Ze,et,Pe,b,x,y,g,mn,lr,Ue,Bn,bn,ge,Us,js,yn,ir,_,q,L,qe,Ke,at,nt,Pt,we,Mn,t,Qs]),Sa=l.useCallback($e=>{te(Dt=>{const bt=new Set(Dt);return bt.has($e)?bt.delete($e):bt.add($e),bt})},[]),kn=l.useMemo(()=>{const $e=new Map;for(const[Dt,bt]of ri)$e.set(Dt,{visualState:bt.visualState,number:bt.number,url:bt.url,state:bt.prState,draft:bt.draft,title:bt.title,base:bt.base,head:bt.head,checks:bt.checks,canMerge:bt.canMerge,mergeableState:bt.mergeableState,repo:bt.repo});return $e},[ri]),Hr=l.useCallback(($e,Dt,bt,Gt,ys,rn)=>s.jsx(GP,{group:$e,groupKey:Dt,projectId:bt,hideGroupLabel:Gt,compactBodyPadding:rn,hasSessionSearchQuery:Ze,normalizedSessionSearchQuery:et,groupSearchDataByGroup:Fr,expandedSessionGroups:E,collapsedGroups:ve,hideDirectoryControls:r,collapsedFolderIds:We,toggleFolderCollapse:Le,renameFolder:Je,deleteFolder:Be,showDeletionDialog:z,setDeleteFolderConfirm:G,renderSessionNode:Or,currentSessionDirectory:wa,projectRepoStatus:S,lastRepoStatus:dr.current,toggleGroupSessionLimit:Ht,mobileVariant:t,alwaysShowActions:Qs,activeProjectId:ae,setActiveProjectIdOnly:le,setActiveMainTab:Ve,setSessionSwitcherOpen:oe,openNewSessionDraft:Ye,addSessionToFolder:nt,createFolderAndStartRename:Pt,renamingFolderId:L,renameFolderDraft:Z,setRenameFolderDraft:ie,setRenamingFolderId:J,pinnedSessionIds:W,sessionOrderIndex:ct,prVisualStateByDirectoryBranch:kn,onToggleCollapsedGroup:Sa,dragHandleProps:ys}),[Ze,et,Fr,E,ve,r,We,Le,Je,Be,z,Or,wa,S,Ht,t,Qs,ae,le,Ve,oe,Ye,nt,Pt,L,Z,W,ct,kn,Sa]),ai=Js&&!Ze?s.jsx(eA,{sections:ia,renderSessionNode:Or}):null,kr=!!(L||b||h),Cr=gr($e=>$e.enabled),tn=gr($e=>$e.selectedIds),ka=gr($e=>$e.scopeKey),Re=gr,Xe=l.useCallback(()=>{gr.getState().toggleMode()},[]),tt=l.useCallback(()=>{gr.getState().disable()},[]),mt=l.useMemo(()=>{if(tn.size===0||typeof document>"u")return!1;let $e=!1,Dt=!1;for(const bt of tn){const Gt=document.querySelectorAll(`[data-session-row="${CSS.escape(bt)}"]`);for(const ys of Gt)ys.getAttribute("data-session-archived")==="1"?Dt=!0:$e=!0}return Dt&&!$e},[tn]),At=l.useMemo(()=>{if(ka)return ka;if(tn.size===0||typeof document>"u")return null;for(const $e of tn){const bt=document.querySelector(`[data-session-row="${CSS.escape($e)}"]`)?.getAttribute("data-session-scope");if(bt&&bt.length>0)return bt}return null},[tn,ka]),zt=l.useMemo(()=>At?it[At]??[]:[],[it,At]),zs=l.useMemo(()=>{if(!At||tn.size===0)return!1;const $e=it[At]??[];for(const Dt of $e)for(const bt of Dt.sessionIds)if(tn.has(bt))return!0;return!1},[it,At,tn]),Fs=l.useCallback($e=>{!At||tn.size===0||Ge(At,$e,Array.from(tn))},[Ge,tn,At]),zn=l.useCallback(()=>{if(!At||tn.size===0)return;const $e=Pt(At);$e&&Ge(At,$e.id,Array.from(tn))},[Ge,Pt,tn,At]),Oi=l.useCallback(()=>{!At||tn.size===0||Ae(At,Array.from(tn))},[Ae,tn,At]),la=l.useCallback(async()=>{const $e=Array.from(tn);if($e.length!==0){if(mt){const{deletedIds:Dt,failedIds:bt}=await Ds($e);Dt.length>0&&H.success(Dt.length===1?i("sessions.sidebar.bulkActions.deletedSingle",{count:Dt.length}):i("sessions.sidebar.bulkActions.deletedPlural",{count:Dt.length})),bt.length>0&&H.error(bt.length===1?i("sessions.sidebar.bulkActions.failedDeleteSingle",{count:bt.length}):i("sessions.sidebar.bulkActions.failedDeletePlural",{count:bt.length}))}else{const{archivedIds:Dt,failedIds:bt}=await Vs($e);Dt.length>0&&H.success(Dt.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:Dt.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:Dt.length})),bt.length>0&&H.error(bt.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:bt.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:bt.length}))}gr.getState().clear()}},[Vs,mt,Ds,tn,i]),Gr=l.useCallback(()=>{const $e=tn.size;if($e!==0){if(!z){la();return}Q({sessionCount:$e,archivedBucket:mt})}},[mt,la,tn,z]),cc=l.useCallback(async()=>{Q(null),await la()},[la]);l.useEffect(()=>{if(!Cr)return;const $e=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),Dt=bt=>{if(kr)return;const Gt=bt.target;if(Gt&&(Gt.tagName==="INPUT"||Gt.tagName==="TEXTAREA"||Gt.isContentEditable))return;const ys=$e?bt.metaKey:bt.ctrlKey;if(bt.key==="Escape"){bt.preventDefault(),gr.getState().disable();return}if(ys&&bt.key==="Backspace"){bt.preventDefault(),Gr();return}if(ys&&(bt.key==="a"||bt.key==="A")){const rn=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(rn.length===0)return;bt.preventDefault();const Lr=Re.getState().scopeKey??rn[0]?.getAttribute("data-session-scope")??null,ur=Cn=>Lr?Cn.getAttribute("data-session-scope")===Lr:!0,Tn=rn.filter(ur).map(Cn=>Cn.getAttribute("data-session-row")).filter(Cn=>typeof Cn=="string"&&Cn.length>0);if(Tn.length===0)return;Re.getState().replaceAll(Tn,Lr||null)}};return window.addEventListener("keydown",Dt),()=>window.removeEventListener("keydown",Dt)},[Gr,kr,Re,Cr]);const dc=l.useCallback(()=>{Ve("chat"),t&&oe(!1),Oe()},[t,Oe,Ve,oe]),ii=l.useCallback(()=>{Ve("chat"),t&&oe(!1),Ye()},[t,Ye,Ve,oe]);return s.jsxs("div",{ref:m,className:ye("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[s.jsx(qP,{hideDirectoryControls:r,mobileVariant:t,handleOpenDirectoryDialog:Ks,openNewSessionDraft:ii,canOpenMultiRun:X.length>0,openMultiRunLauncher:dc,headerActionIconClass:oa,headerActionButtonClass:An,isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchQuery:d,setSessionSearchQuery:p,hasSessionSearchQuery:Ze,searchMatchCount:Qn,collapseAllProjects:ns,expandAllProjects:qs,openScheduledTasksDialog:()=>Te(!0),selectionModeEnabled:Cr,onToggleSelectionMode:Xe}),s.jsx(cA,{topContent:ai,sectionsForRender:pn,projectSections:an,activeProjectId:ae,showOnlyMainWorkspace:a,hasSessionSearchQuery:Ze,emptyState:cs,searchEmptyState:ei,renderGroupSessions:Hr,homeDirectory:Ce,collapsedProjects:P,hideDirectoryControls:r,projectRepoStatus:S,isDesktopShellRuntime:Bs,stuckProjectHeaders:Fi,mobileVariant:t,alwaysShowActions:Qs,toggleProject:Gs,setActiveProjectIdOnly:le,setActiveMainTab:Ve,setSessionSwitcherOpen:oe,openNewSessionDraft:Ye,openNewWorktreeDialog:Et,openProjectEditDialog:j,removeProject:je,projectHeaderSentinelRefs:Se,reorderProjects:Me,getOrderedGroups:ti,setGroupOrderByProject:ce,openSidebarMenuKey:_,setOpenSidebarMenuKey:q,isInlineEditing:kr}),Cr&&tn.size>0?s.jsx(ZA,{selectedCount:tn.size,scopeKey:At,scopeFolders:zt,archivedBucket:mt,onMoveToFolder:Fs,onCreateFolderAndMove:zn,onRemoveFromFolder:Oi,canRemoveFromFolder:zs,onDelete:Gr,onDone:tt}):null,s.jsx(sA,{onOpenSettings:Yt,onOpenShortcuts:F,onOpenAbout:()=>U(!0),onOpenUpdate:Rt,showRuntimeButtons:!ws,showUpdateButton:Ot}),s.jsx(Fd,{open:$,onOpenChange:O,info:Tt.info,downloading:Tt.downloading,downloaded:Tt.downloaded,progress:Tt.progress,error:Tt.error,onDownload:Tt.downloadUpdate,onRestart:Tt.restartToUpdate,runtimeType:Tt.runtimeType}),He?s.jsx(av,{open:!!He,onOpenChange:$e=>{$e||j(null)},projectId:He.id,projectName:He.label||Ga(He.path,Ce),projectPath:He.path,initialIcon:He.icon,initialColor:He.color,initialIconBackground:He.iconBackground,onSave:yt}):null,s.jsx(w6,{open:V,onOpenChange:B,onWorktreeCreated:($e,Dt)=>{if(Ve("chat"),t&&oe(!1),Dt?.sessionId){Bt(Dt.sessionId);return}Ye({directoryOverride:$e})}}),s.jsx(Y6,{}),s.jsx(YA,{value:ne,setValue:me,showDeletionDialog:z,setShowDeletionDialog:De,onConfirm:Rr}),s.jsx(XA,{value:pe,setValue:G,onConfirm:$s}),s.jsx(QA,{value:K,setValue:Q,showDeletionDialog:z,setShowDeletionDialog:De,onConfirm:cc})]})},uD=()=>{const t=ot.c(13),[e,n]=_e.useState(!1);let r,a;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(jn())},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),_e.useEffect(r,a);let i;t[2]!==e?(i=async f=>e?await iv(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 ov():{success:!0},t[4]=e,t[5]=c):c=t[5];const d=c;let p;t[6]!==e?(p=async f=>e?await lv():{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},mD=t=>t==="/",Gl=t=>t.replace(/\\/g,"/"),ku=t=>{if(!t||mD(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},wi=t=>t.endsWith("/"),pD=t=>{const e=t.trim();return!e||wi(e)?e:`${e}/`},Cu=t=>t.lastIndexOf("/"),cx=t=>{if(wi(t))return t;const e=Cu(t);return e<0?t:t.slice(0,e+1)},fD=t=>{const e=Cu(t);return t.slice(e+1)},dx=t=>{const e=ku(t.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=Cu(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},hD=t=>wi(t)&&dx(t)!==null,gD=(t,e)=>`${cx(t)}${e}/`,Ta=t=>{if(!t)return null;const e=ku(Gl(t.trim()));return e?e.toLowerCase():null},zf=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},xD=t=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?t.metaKey&&!t.ctrlKey:t.ctrlKey&&!t.metaKey,ad=t=>{if(!t)return;t.focus({preventScroll:!0});const e=t.value.length;t.setSelectionRange(e,e),t.scrollLeft=t.scrollWidth},bD=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 Gl(e.home.trim())}}catch{}return on.getFilesystemHome().catch(()=>null)},yD=({open:t,onOpenChange:e})=>{const{t:n}=ft(),r=Ws(Pe=>Pe.homeDirectory),a=Cs(Pe=>Pe.projects),i=Cs(Pe=>Pe.addProject),o=tr(Pe=>Pe.profiles),c=tr(Pe=>Pe.globalIdentity),d=tr(Pe=>Pe.defaultGitIdentityId),p=tr(Pe=>Pe.loadProfiles),m=tr(Pe=>Pe.loadGlobalIdentity),u=tr(Pe=>Pe.loadDefaultGitIdentityId),f=ec(),{isDesktop:b,requestAccess:x,startAccessing:y}=uD(),{isMobile:g}=ln(),h=l.useRef(null),j=l.useRef(null),v=l.useRef(new Map),[C,k]=l.useState(""),[w,N]=l.useState("~/"),[I,T]=l.useState([]),[P,D]=l.useState(!1),[S,M]=l.useState(!1),[E,R]=l.useState(0),[V,B]=l.useState(!1),[$,O]=l.useState(!1),[_,q]=l.useState(0),[L,J]=l.useState(!1),[Z,ie]=l.useState(""),[ne,me]=l.useState(null),pe=C||r,G=l.useMemo(()=>new Set(a.map(Pe=>Ta(Pe.path)).filter(Pe=>!!Pe)),[a]);l.useEffect(()=>{if(!t)return;N("~/"),T([]),R(0),B(!1),O(!1),J(!1),ie(""),me(null),requestAnimationFrame(()=>ad(h.current));let Pe=!1;return(async()=>{const De=await bD();Pe||(k(De||r||""),requestAnimationFrame(()=>ad(h.current)))})(),()=>{Pe=!0}},[r,t]),l.useEffect(()=>{t&&(p(),m(),u())},[u,p,m,t]);const K=l.useMemo(()=>{const Pe=new Map;c&&Pe.set(c.id,c);for(const z of o)Pe.set(z.id,z);return Array.from(Pe.values())},[o,c]);l.useEffect(()=>{if(!t||!L||ne!==null)return;const Pe=typeof d=="string"?d.trim():"";if(Pe&&K.some(De=>De.id===Pe)){me(Pe);return}const z=K.find(De=>De.authType==="ssh"||De.sshKey);z&&me(z.id)},[K,d,L,t,ne]);const Q=l.useMemo(()=>K.find(Pe=>Pe.id===ne)??null,[K,ne]),W=l.useMemo(()=>cx(w),[w]),de=l.useMemo(()=>wi(w)?"":fD(w),[w]),ge=l.useMemo(()=>pe?zf(W,pe):"",[W,pe]);l.useEffect(()=>{if(!t||!ge){T([]);return}let Pe=!1;return D(!0),M(!1),on.listLocalDirectory(ge).then(z=>{if(Pe)return;M(!1);const De=z.filter(Qe=>Qe.isDirectory).map(Qe=>({name:Qe.name,path:Gl(Qe.path)})).sort((Qe,et)=>Qe.name.localeCompare(et.name));T(De)}).catch(()=>{Pe||(T([]),M(!0))}).finally(()=>{Pe||D(!1)}),()=>{Pe=!0}},[ge,t]);const ve=l.useMemo(()=>{const Pe=de.toLowerCase(),z=f||de.startsWith(".");return I.filter(De=>De.name.toLowerCase().startsWith(Pe)&&(z||!De.name.startsWith(".")))},[de,I,f]),te=l.useMemo(()=>{const Pe=[];hD(w)&&Pe.push({type:"up",value:"browse:up",name:"..",path:dx(w)});for(const z of ve){const De=Ta(z.path);Pe.push({type:"directory",value:`browse:${z.path}`,name:z.name,path:z.path,disabled:!!(De&&G.has(De))})}return Pe},[G,ve,w]);l.useEffect(()=>{R(0)},[w,te.length]);const he=l.useMemo(()=>pe?ku(zf(w,pe)):"",[pe,w]),ce=Ta(he),xe=!!(ce&&G.has(ce)),se=l.useMemo(()=>de?ve.find(Pe=>Pe.name===de)??null:null,[de,ve]),ue=!!(he&&!xe&&(wi(w)&&S||!wi(w)&&de.trim().length>0&&se===null)),Y=!V&&!$&&!xe&&!!he,Se=Y&&Z.trim().length>0,fe=te[E]??null,Ce=!!(fe&&(fe.type==="up"||fe.type==="directory"&&!fe.disabled)),Ie=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",ke=n(xe?"directoryExplorerDialog.actions.alreadyAdded":L?V?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":V?"directoryExplorerDialog.actions.adding":ue?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");l.useLayoutEffect(()=>{const Pe=j.current;if(!Pe)return;const z=()=>q(Math.ceil(Pe.getBoundingClientRect().width));if(z(),typeof ResizeObserver>"u")return;const De=new ResizeObserver(z);return De.observe(Pe),()=>De.disconnect()},[ke]),l.useLayoutEffect(()=>{const Pe=h.current;Pe&&(Pe.scrollLeft=Pe.scrollWidth)},[_,w]),l.useLayoutEffect(()=>{t&&ad(h.current)},[t]),l.useLayoutEffect(()=>{const Pe=te[E];Pe&&v.current.get(Pe.value)?.scrollIntoView({block:"nearest"})},[E,te]);const X=l.useCallback(()=>{e(!1)},[e]),ae=l.useCallback((Pe,z)=>{Pe.stopPropagation();const De=Ta(z);if(De&&G.has(De))return;i(z)||H.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")})},[i,G,n]),je=l.useCallback(async Pe=>{if(!Pe||V)return;const z=Ta(Pe);if(z&&G.has(z))return;let De=Pe;B(!0);try{const Qe=!L&&ue&&Ta(Pe)===Ta(he);if(L){const Ze=Z.trim();if(!Ze){H.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}De=(await on.cloneRepository({remoteUrl:Ze,destinationPath:Pe,gitIdentityId:Q?.id??null})).path}else Qe&&await on.createDirectory(Pe,{allowOutsideWorkspace:!0});if(!i(De)){H.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}X()}catch(Qe){H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Qe instanceof Error?Qe.message:n("directoryExplorerDialog.toast.unknownError")})}finally{B(!1)}},[i,G,Z,X,L,V,Q?.id,ue,he,n]),le=l.useCallback(Pe=>{N(pD(Pe))},[]),Ne=l.useCallback(Pe=>{N(gD(w,Pe.name))},[w]),Me=l.useCallback(Pe=>{if(Pe){if(Pe.type==="up"){Pe.path&&le(Pe.path);return}Pe.disabled||Ne(Pe)}},[le,Ne]),Ve=l.useCallback(async()=>{if(!(!b||$)){O(!0);try{const Pe=await x(he);if(!Pe.success||!Pe.path){Pe.error&&Pe.error!=="Directory selection cancelled"&&H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Pe.error});return}const z=await y(Pe.path);if(!z.success){H.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:z.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await je(Pe.path)}catch(Pe){H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Pe instanceof Error?Pe.message:n("directoryExplorerDialog.toast.unknownError")})}finally{O(!1)}}},[je,b,$,x,y,n,he]),we=l.useCallback(Pe=>{if(Pe.key==="ArrowDown"){Pe.preventDefault(),R(z=>Math.min(te.length-1,z+1));return}if(Pe.key==="ArrowUp"){Pe.preventDefault(),R(z=>Math.max(0,z-1));return}if(Pe.key==="Enter"){if(Pe.preventDefault(),xD(Pe)){je(he);return}Ce&&Me(fe);return}Pe.key==="Backspace"&&w===""&&(Pe.preventDefault(),X())},[Me,je,X,Ce,fe,w,te.length,he]),ee=s.jsxs("button",{type:"button",onClick:()=>ol(!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(A,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(A,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),F=s.jsxs("div",{className:"px-2.5 py-1.5",children:[L?s.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[s.jsx(Lt,{value:Z,onChange:Pe=>ie(Pe.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(ag,{activeProfile:Q,identities:K,onSelect:Pe=>me(Pe.id),isApplying:V,iconOnly:!0})]}):null,s.jsxs("div",{className:"relative",children:[s.jsx(A,{name:"folder-add",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),s.jsx(Lt,{ref:h,value:w,onChange:Pe=>N(Gl(Pe.target.value)),onKeyDown:we,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!g&&_>0?{paddingRight:`${_+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),g?null:s.jsx(be,{ref:j,variant:"outline",size:"xs",tabIndex:-1,className:"absolute right-1.5 top-1/2 h-7 -translate-y-1/2 gap-1 px-2 typography-meta",disabled:L?!Se:!Y,onMouseDown:Pe=>Pe.preventDefault(),onClick:()=>{je(he)},title:ke,children:ke})]})]}),U=s.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:s.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[s.jsx("div",{className:"px-2 pb-1 pt-0.5 typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:n("directoryExplorerDialog.browse.directories")}),P?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):te.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:te.map((Pe,z)=>{const De=z===E;return s.jsxs("button",{ref:Qe=>{Qe?v.current.set(Pe.value,Qe):v.current.delete(Pe.value)},type:"button",disabled:Pe.type==="directory"&&Pe.disabled,onMouseEnter:()=>R(z),onMouseDown:Qe=>Qe.preventDefault(),onClick:()=>Me(Pe),className:ye("flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",De&&"bg-interactive-selection text-interactive-selection-foreground",!De&&"hover:bg-interactive-hover/50",Pe.type==="directory"&&Pe.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[Pe.type==="up"?s.jsx(A,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(A,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Pe.name})}),Pe.type==="directory"&&Pe.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")}):Pe.type==="directory"?s.jsx("button",{type:"button",onMouseDown:Qe=>Qe.stopPropagation(),onClick:Qe=>ae(Qe,Pe.path),className:"flex-shrink-0 rounded-full p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",title:n("directoryExplorerDialog.browse.quickAdd"),children:s.jsx(A,{name:"add",className:"h-3.5 w-3.5"})}):null]},Pe.value)})})]})}),oe=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[F,U]}),Te=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(A,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),s.jsx(A,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.navigate")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(A,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.select")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx("span",{children:Ie}),s.jsx(A,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),Oe=()=>s.jsxs(s.Fragment,{children:[g?null:Te,s.jsxs("div",{className:ye("flex w-full flex-row justify-end gap-2 sm:w-auto",g&&"justify-stretch"),children:[b?s.jsx(be,{variant:"ghost",size:"xs",onClick:Ve,disabled:V||$||L,children:n($?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(be,{variant:"ghost",size:"xs",onClick:()=>J(Pe=>!Pe),disabled:V||$,className:ye(g&&"flex-1"),children:n(L?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),g?s.jsx(be,{size:"xs",onClick:()=>{je(he)},disabled:L?!Se:!Y,className:"flex-1",children:ke}):null]})]});return g?s.jsx(zr,{open:t,onClose:X,title:n("directoryExplorerDialog.title"),className:"h-[88dvh] max-h-[720px] max-w-full",contentMaxHeightClassName:"flex-1",footer:s.jsx("div",{className:"flex flex-col gap-2",children:Oe()}),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[s.jsx("div",{className:"flex justify-end",children:ee}),oe]})}):s.jsx(us,{open:t,onOpenChange:e,children:s.jsxs(ds,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[s.jsx(hs,{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(ms,{children:n("directoryExplorerDialog.title")}),s.jsx(Ns,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),ee]})}),s.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:oe}),s.jsx(_s,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:Oe()})]})})},Ea=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(/\/+$/,"")},vD=()=>{const{t}=ft(),[e,n]=l.useState(!1),[r,a]=l.useState(!1),[i,o]=l.useState(null),[c,d]=l.useState([]),[p,m]=l.useState(!1),[u,f]=l.useState(!1),[b,x]=l.useState(!1),[y,g]=l.useState(!1),[h,j]=l.useState(new Set),v=$t(Y=>Y.getWorktreeMetadata),C=$t(Y=>Y.newSessionDraft),k=$t(Y=>Y.setNewSessionDraftTarget),w=$t(Y=>Y.setDraftBootstrapPendingDirectory),N=cv,I=mv,T=$t(Y=>Y.deleteSessions),P=$t(Y=>Y.archiveSessions),D=Fe(Y=>Y.showDeletionDialog),S=Fe(Y=>Y.setShowDeletionDialog),M=Ws(Y=>Y.currentDirectory),E=Ws(Y=>Y.homeDirectory),R=Ws(Y=>Y.isHomeReady),V=Cs(Y=>Y.projects),B=Cs(Y=>Y.activeProjectId),{isMobile:$,isTablet:O,hasTouchInput:_}=ln(),q=$||O||_,L=l.useMemo(()=>{const Se=(B?V.find(fe=>fe.id===B)??null:null)?.path??M;return _r(Se)},[B,M,V]),J=l.useCallback(Y=>{const fe=_r(Y.projectDirectory)||L;return{id:(V.find(Ie=>_r(Ie.path)===fe)??null)?.id??`path:${fe}`,path:fe}},[L,V]),Z=y&&h.size>0,ie=l.useMemo(()=>{const Y=i?.worktree;return Y&&typeof Y.branch=="string"&&Y.branch.trim().length>0?!0:c.length>0&&c.every(({metadata:Se})=>typeof Se.branch=="string"&&Se.branch.trim().length>0)},[i?.worktree,c]),ne=i?.mode==="worktree",me=ne,pe=b||!ne||!ie,G=b||!ne;l.useEffect(()=>{r||!R||V.length>0||(a(!0),n(!0))},[r,R,V.length]);const K=l.useCallback(Y=>{o({sessions:Y.sessions,dateLabel:Y.dateLabel,mode:Y.mode??"session",worktree:Y.worktree??null})},[]),Q=l.useCallback(()=>{o(null),d([]),m(!1),f(!1),x(!1),g(!1),j(new Set)},[]),W=l.useCallback(async Y=>{if(Y.sessions.length===0)return;if(Y.sessions.length===1){const Ie=Y.sessions[0];await N(Ie.id)?H.success(t("sessions.sidebar.session.delete.success")):H.error(t("sessions.sidebar.session.delete.error"));return}const Se=Y.sessions.map(Ie=>Ie.id),{deletedIds:fe,failedIds:Ce}=await T(Se);if(fe.length>0){const Ie=Ce.length>0?Ce.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:Ce.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:Ce.length}):Y.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:Y.dateLabel}):void 0;H.success(fe.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:fe.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:fe.length}),{description:Ea(Ie)})}Ce.length>0&&H.error(Ce.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:Ce.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:Ce.length}),{description:Ea(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[N,T,t]);l.useEffect(()=>Dr.onDeleteRequest(Y=>{if(!D&&(Y.mode??"session")==="session"){W(Y);return}K(Y)}),[K,D,W]),l.useEffect(()=>Dr.onDirectoryRequest(()=>{n(!0)}),[]),l.useEffect(()=>{if(!i){d([]),m(!1),f(!1),g(!1),j(new Set);return}const Y=i.sessions.map(Ce=>{const Ie=v(Ce.id);return Ie?{session:Ce,metadata:Ie}:null}).filter(Ce=>!!Ce);d(Y),m(!1),g(!1),j(new Set);const Se=new Map;if(i.worktree?.path&&Se.set(_r(i.worktree.path),i.worktree),Y.forEach(({metadata:Ce})=>{Ce.path&&Se.set(_r(Ce.path),Ce)}),Se.size===0){g(!0);return}let fe=!1;return(async()=>{const Ce=new Map,Ie=new Set;await Promise.all(Array.from(Se.entries()).map(async([ke,X])=>{try{const ae=await dv(X.path);Ce.set(ke,ae),ae?.isDirty&&Ie.add(ke)}catch{X.status&&(Ce.set(ke,X.status),X.status.isDirty&&Ie.add(ke))}})).catch(ke=>{console.warn("Failed to inspect worktree status before deletion:",ke)}),!fe&&(j(Ie),g(!0),o(ke=>{if(!ke?.worktree?.path)return ke;const X=_r(ke.worktree.path),ae=Ce.get(X);if(!ae)return ke;const je=ke.worktree.status;return je?.isDirty===ae.isDirty&&je?.ahead===ae.ahead&&je?.behind===ae.behind&&je?.upstream===ae.upstream?ke:{...ke,worktree:{...ke.worktree,status:ae}}}),d(ke=>ke.map(X=>{const ae=_r(X.metadata.path),je=Ce.get(ae);return je?{session:X.session,metadata:{...X.metadata,status:je}}:X})))})(),()=>{fe=!0}},[i,v]),l.useEffect(()=>{ie||m(!1)},[ie]);const de=l.useCallback(async(Y,Se)=>{const fe=p&&ie,Ce=J(Y),Ie=_r(Y.path),ke=_r(Ce.path);try{await uv(Ce,Y,{deleteRemoteBranch:fe,deleteLocalBranch:Se});const X=_r(C?.directoryOverride);return C?.open&&Ie&&X===Ie&&ke&&(w(null),k({projectId:Ce.id,directoryOverride:ke},{force:!0})),_r(M)===Ie&&ke&&Ws.getState().setDirectory(ke,{showOverlay:!1}),!0}catch(X){return H.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Ea(X instanceof Error?X.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[ie,M,p,J,C?.directoryOverride,C?.open,w,k,t]),ge=l.useCallback(async()=>{if(i){x(!0);try{const Y=me,Se=Y&&p,fe=Y&&u;if(i.sessions.length===0&&ne&&i.worktree){if(!await de(i.worktree,fe)){Q();return}const ke=t(p&&ie?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");H.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Ea(ke)}),Q();return}if(i.sessions.length===1){const Ce=i.sessions[0];if(!(ne?await I(Ce.id):await N(Ce.id,{archiveWorktree:!1,deleteRemoteBranch:Se,deleteLocalBranch:fe}))){H.error(t(ne?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),x(!1);return}const ke=!ne&&Y?t(Se?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;H.success(t(ne?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Ea(ke),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const Ce=i.sessions.map(X=>X.id);let Ie=[],ke=[];if(ne){const X=await P(Ce);Ie=X.archivedIds,ke=X.failedIds}else{const X=await T(Ce);Ie=X.deletedIds,ke=X.failedIds}if(ne&&i.worktree&&ke.length===0&&await de(i.worktree,fe),Ie.length>0){const X=!ne&&Y?t(Se?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,je=[ke.length>0?ne?ke.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:ke.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:ke.length}):ke.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:ke.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:ke.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,X].filter(Boolean).join(" ");H.success(ne?Ie.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:Ie.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:Ie.length}):Ie.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Ie.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Ie.length}),{description:Ea(je||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(ke.length>0&&(H.error(ne?ke.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ke.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:ke.length}):ke.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ke.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:ke.length}),{description:Ea(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),Ie.length===0)){x(!1);return}}ne&&i.sessions.length===1&&i.worktree&&await de(i.worktree,fe),Q()}finally{x(!1)}}},[i,p,u,N,T,I,P,Q,me,ne,ie,de,t]),ve=i?.worktree??c[0]?.metadata??null,te=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}):"",he=i?s.jsxs("div",{className:ye(ne?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:ye(ne?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[ne&&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:ye(ne?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(Y=>s.jsxs("li",{className:ye(ne?"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:ye(!ne&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:Y.title||t("sessions.sidebar.session.untitled")})]},Y.id)),i.sessions.length>5&&s.jsx("li",{className:ye(ne?"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})})]})]}),ne?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),ve?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:ve.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:ve?mo(ve.path,E):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),Z&&s.jsx("p",{className:"typography-micro text-status-warning",children:t("sessions.sidebar.sessionDialogs.worktree.uncommittedWarning")})]}):s.jsx("div",{className:"rounded-xl border border-border/40 bg-sidebar/60 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("sessions.sidebar.sessionDialogs.delete.note")})})]}):null,ce=ne?ie?s.jsxs("button",{type:"button",onClick:()=>{pe||m(Y=>!Y)},disabled:pe,className:ye("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",pe?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[p?s.jsx(A,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(A,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,xe=ne?s.jsxs("button",{type:"button",onClick:()=>{G||f(Y=>!Y)},disabled:G,className:ye("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",G?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(A,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(A,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,se=ne?s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[xe,ce]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{variant:"ghost",onClick:Q,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(be,{variant:"destructive",onClick:ge,disabled:b,children:t(b?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>S(!D),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":!D,children:[D?s.jsx(A,{name:"checkbox-blank",className:"size-4"}):s.jsx(A,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{variant:"ghost",onClick:Q,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(be,{variant:"destructive",onClick:ge,disabled:b,children:b?t("sessions.sidebar.sessionDialogs.actions.deleting"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),ue=ne?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[q?s.jsx(zr,{open:!!i,onClose:()=>{b||Q()},title:ue,footer:s.jsx("div",{className:"flex justify-end gap-2",children:se}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[te&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:te}),he]})}):s.jsx(us,{open:!!i,onOpenChange:Y=>{if(!Y){if(b)return;Q()}},children:s.jsxs(ds,{className:ye(ne?"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(hs,{children:[s.jsxs(ms,{className:ye(ne&&"flex items-center gap-2"),children:[ne&&s.jsx(A,{name:"delete-bin",className:"h-5 w-5"}),ue]}),te&&s.jsx(Ns,{children:te})]}),s.jsx("div",{className:ye(ne&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:he}),s.jsx(_s,{className:"mt-2 gap-2 pt-1 pb-1",children:se})]})}),s.jsx(yD,{open:e,onOpenChange:n})]})},Wd=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),wD=(t,e)=>{const n=Wd(t),r=Wd(e);return`${n}-${r}`.substring(0,60)},Uf=(t,e)=>`${t}/${e}`,jD=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},Wf=(t,e)=>{const n=jD(e),r=t.directory,a=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};gv(t.id,n),$t.getState().markSessionAsOpenChamberCreated(t.id),xa.getState().upsertSession(a);try{xv().ensureChild(n,{bootstrap:!1}).setState(o=>{const c=o.session.findIndex(p=>p.id===t.id);if(c>=0&&o.session[c]===a)return o;const d=c>=0?o.session.map((p,m)=>m===c?a:p):[...o.session,a].sort((p,m)=>p.id.localeCompare(m.id));return{session:d,sessionTotal:Math.max(o.sessionTotal,d.length),limit:Math.max(o.limit,d.length)}})}catch{}return a},ND=()=>{const t=Cs.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(a=>a.id===e);if(n?.path)return{id:n.id,path:n.path};const r=Ws.getState().currentDirectory??null;if(r&&r.trim().length>0){const a=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${a}`,path:a}}return null},id=ar()(Xa(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),{groups:r,agent:a,files:i,setupCommands:o}=e;if(!n)return t({error:"Group name is required"}),null;if(!r||r.length===0)return t({error:"At least one run group is required"}),null;for(let c=0;c<r.length;c++){if(!r[c].prompt.trim())return t({error:`Group ${c+1}: prompt is required`}),null;if(r[c].models.length<1)return t({error:`Group ${c+1}: select at least 1 model`}),null;if(r[c].models.length>5)return t({error:`Group ${c+1}: maximum 5 models allowed`}),null}t({isLoading:!0,error:null});try{const c=ND();if(!c)return t({error:"Select a project",isLoading:!1}),null;const d=c.path,m=await Ch(d)&&e.isolateRuns!==!1,u=Wd(n),f=m?await No(d):void 0,b=m?await pv(d):null,x=[],y=o?.filter(C=>C.trim().length>0)??[];for(let C=0;C<r.length;C++){const k=r[C],w=k.prompt,N=new Map;for(const T of k.models){const P=`${T.providerID}:${T.modelID}`;N.set(P,(N.get(P)||0)+1)}const I=new Map;for(const T of k.models){const P=`${T.providerID}:${T.modelID}`,D=N.get(P)||1,S=(I.get(P)||0)+1;I.set(P,S);const M=wD(T.providerID,T.modelID),E=r.length>1?`g${C+1}`:void 0,R=D>1?Uf(u,`${M}/${S}`):Uf(u,M),V=E?`${E}/${R}`:R,B=DA({groupSlug:u,runGroup:E,providerID:T.providerID,modelID:T.modelID,index:D>1?S:void 0});try{if(!m){const q=await on.withDirectory(d,()=>on.createSession({title:B}));Wf(q,d),x.push({sessionId:q.id,worktreePath:d,providerID:T.providerID,modelID:T.modelID,variant:T.variant,prompt:w});continue}const $=await fv(c,{preferredName:V,mode:"new",branchName:V,worktreeName:V,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:y},{resolvedRootTrackingRemote:b}),O={...$,createdFromBranch:f,kind:"standard"},_=await on.withDirectory($.path,()=>on.createSession({title:B}));Wf(_,$.path),$t.getState().setWorktreeMetadata(_.id,O),x.push({sessionId:_.id,worktreePath:$.path,providerID:T.providerID,modelID:T.modelID,variant:T.variant,prompt:w})}catch($){console.warn("[MultiRun] Failed to create session:",$)}}}const g=o?.filter(C=>C.trim().length>0)??[];g.length>0&&Ih(c,g).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const h=x.map(C=>C.sessionId),j=x[0]?.sessionId??null;if(h.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const v=i?.map(C=>({type:"file",mime:C.mime,filename:C.filename,url:C.url}));return(async()=>{try{const C=rc.getState().expandText;await Promise.allSettled(x.map(async k=>{try{const w=await C(k.prompt).catch(()=>k.prompt);await hv({sessionId:k.sessionId,directory:k.worktreePath,content:w,providerID:k.providerID,modelID:k.modelID,variant:k.variant,agent:a,files:v})}catch(w){console.warn("[MultiRun] Failed to start run:",w)}}))}catch(C){console.warn("[MultiRun] Failed to start runs:",C)}})(),t({isLoading:!1}),{groupSlug:u,sessionIds:h,firstSessionId:j}}catch(c){return t({error:c instanceof Error?c.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"})),SD="oc:lastWorktreeSourceBranch";function ux(t){const e=ot.c(30),{git:n}=_n(),r=Xd(t),a=Qd(t),i=Zd(t),o=Eh(t),c=Ys(AD),d=Ys(PD);let p,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==a||e[4]!==i?(p=()=>{!t||!n||a!==null||i||d(t,n,{silent:!0})},m=[t,n,d,a,i],e[0]=t,e[1]=d,e[2]=n,e[3]=a,e[4]=i,e[5]=p,e[6]=m):(p=e[5],m=e[6]),l.useEffect(p,m);let u;e[7]!==r?.all||e[8]!==t||e[9]!==c||e[10]!==n||e[11]!==a?(u=()=>{!t||!n||a===!0&&(r?.all||c(t,n))},e[7]=r?.all,e[8]=t,e[9]=c,e[10]=n,e[11]=a,e[12]=u):u=e[12];const f=r?.all;let b;e[13]!==t||e[14]!==c||e[15]!==n||e[16]!==a||e[17]!==f?(b=[t,n,a,f,c],e[13]=t,e[14]=c,e[15]=n,e[16]=a,e[17]=f,e[18]=b):b=e[18],l.useEffect(u,b);const x=i||a===!0&&o;let y;e:{if(!r?.all){let N;e[19]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[19]=N):N=e[19],y=N;break e}let w;e[20]!==r.all?(w=r.all.filter(ID).sort(),e[20]=r.all,e[21]=w):w=e[21],y=w}const g=y;let h;e:{if(!r?.all){let N;e[22]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[22]=N):N=e[22],h=N;break e}let w;e[23]!==r.all?(w=r.all.filter(CD).map(kD).sort(),e[23]=r.all,e[24]=w):w=e[24],h=w}const j=h;let v;e:{if(!t){v=null;break e}if(a!==null){v=a;break e}if(x){v=null;break e}v=r?.all?!0:null}const C=v;let k;return e[25]!==C||e[26]!==x||e[27]!==g||e[28]!==j?(k={localBranches:g,remoteBranches:j,isLoading:x,isGitRepository:C},e[25]=C,e[26]=x,e[27]=g,e[28]=j,e[29]=k):k=e[29],k}function kD(t){return t.replace(/^remotes\//,"")}function CD(t){return t.startsWith("remotes/")}function ID(t){return!t.startsWith("remotes/")}function PD(t){return t.fetchStatus}function AD(t){return t.fetchBranches}const DD=({directory:t,value:e,onChange:n,className:r,disabled:a,id:i})=>{const{t:o}=ft(),{localBranches:c,remoteBranches:d,isLoading:p,isGitRepository:m}=ux(t),u=l.useMemo(()=>[...c,...d.map(b=>`remotes/${b}`)],[c,d]);l.useEffect(()=>{if(a||p||u.length===0||e&&u.includes(e))return;(async()=>{try{const x=t?await No(t).catch(()=>null):null,y=localStorage.getItem(SD);y&&u.includes(y)?n(y):x&&u.includes(x)?n(x):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(as,{value:e,onValueChange:n,disabled:f,children:[s.jsx(is,{id:i,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(fs,{placeholder:o(p?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(os,{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(fd,{children:[s.jsx(im,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.localBranches")}),c.map(b=>s.jsx(Mt,{value:b,className:"whitespace-normal break-all",children:b},b))]}),c.length>0&&d.length>0&&s.jsx(bv,{}),d.length>0&&s.jsxs(fd,{children:[s.jsx(im,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.remoteBranches")}),d.map(b=>s.jsx(Mt,{value:`remotes/${b}`,className:"whitespace-normal break-all",children:b},`remotes/${b}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:o("multiRun.branchSelector.status.notInGitRepository")})]})},TD=10*1024*1024,od=5,Nl=t=>{const e=ot.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(A,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let a;return e[1]!==n?(a=s.jsxs(kt,{children:[r,s.jsx(It,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=a):a=e[2],a},$a=t=>{const e=ot.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},ED=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:a}=ft(),[i,o]=l.useState(""),[c,d]=l.useState(()=>[{id:ao(),prompt:"",models:[]}]),[p,m]=l.useState(""),[u,f]=l.useState([]),[b,x]=l.useState(!1),[y,g]=l.useState([]),[h,j]=l.useState(!1),[v,C]=l.useState(!1),[k,w]=l.useState(!0),N=l.useRef(null),I=Ws(X=>X.currentDirectory??null),T=Ws(X=>X.homeDirectory??null),P=l.useMemo(()=>{if(typeof window>"u")return null;const X=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof X=="string"&&X.trim().length>0?X.trim():null},[]),D=Cs(X=>X.activeProjectId),S=Cs(X=>X.setActiveProjectIdOnly),M=Cs(X=>X.projects),[E,R]=l.useState(()=>D??null);l.useEffect(()=>{if(D){R(D);return}!E&&M.length>0&&R(M[0].id)},[D,M,E]);const V=l.useMemo(()=>E?M.find(X=>X.id===E)??null:null,[M,E]),B=V?.path??I,$=l.useCallback(X=>{R(X),X!==D&&S(X)},[D,S]),{currentTheme:O}=jr(),_=l.useCallback(X=>{const ae=X.label?.trim()||Ga(X.path,T),je=ko({id:X.id,iconImage:X.iconImage??null},{themeVariant:O.metadata.variant,iconColor:O.colors.surface.foreground}),le=X.icon?nc[X.icon]:null,Ne=X.color?Co[X.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[je?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:X.iconBackground?{backgroundColor:X.iconBackground}:void 0,children:s.jsx("img",{src:je,alt:"",className:"h-full w-full object-contain",draggable:!1})}):le?s.jsx(A,{name:le,className:"h-3.5 w-3.5 shrink-0",style:Ne?{color:Ne}:void 0}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:Ne?{color:Ne}:void 0}),s.jsx("span",{className:"truncate",children:ae})]})},[T,O.metadata.variant,O.colors.surface.foreground]),q=l.useMemo(()=>{if(V?.path)return{id:V.id,path:V.path};const X=I??P;return X?{id:`path:${X}`,path:X}:null},[V,I,P]),[L]=l.useState(()=>typeof window<"u"?jn():!1),J=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),Z=mh(),ie=l.useMemo(()=>{if(typeof window>"u")return null;const X=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof X=="number"&&Number.isFinite(X)&&X>0)return X;if(typeof navigator>"u")return null;const ae=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!ae)return null;const je=Number.parseInt(ae[1],10),le=Number.parseInt(ae[2],10);return Number.isNaN(je)?null:je===10?le:je},[]),ne=l.useMemo(()=>L&&J||Z?"pl-[5.5rem]":"pl-3",[L,J,Z]),me=l.useMemo(()=>!L||!J||ie===null?"":ie>=26?"h-12":ie<=15?"h-14":"",[L,J,ie]),pe=l.useCallback(async X=>{X.target.closest("button, a, input, select, textarea")||X.button===0&&L&&await yv()},[L]);l.useEffect(()=>{if(!n)return;const X=ae=>{ae.key==="Escape"&&(ae.preventDefault(),ae.stopPropagation(),n())};return window.addEventListener("keydown",X,!0),()=>window.removeEventListener("keydown",X,!0)},[n]);const[G,K]=l.useState(""),{isLoading:Q,isGitRepository:W}=ux(B),de=l.useRef(!1),ge=W===!0,ve=ge&&k;l.useEffect(()=>{if(W===!1){de.current=!0,w(!1);return}W===!0&&de.current&&(de.current=!1,w(!0))},[W]);const te=id(X=>X.createMultiRun),he=id(X=>X.error),ce=id(X=>X.clearError);l.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(X=>{const ae=[...X];return ae.length>0&&!ae[0].prompt.trim()&&(ae[0]={...ae[0],prompt:t}),ae})},[t]),l.useEffect(()=>{if(!q)return;let X=!1;return C(!0),(async()=>{try{const ae=await au(q);X||g(ae)}catch{}finally{X||C(!1)}})(),()=>{X=!0}},[q]);const xe=l.useCallback((X,ae)=>{d(je=>je.map(le=>le.id===X?{...le,...ae}:le))},[]),se=l.useCallback(X=>{d(ae=>ae.filter(je=>je.id!==X))},[]),ue=l.useCallback(()=>{d(X=>[...X,{id:ao(),prompt:"",models:[]}])},[]),Y=async X=>{const ae=X.target.files;if(!ae)return;let je=0;for(let le=0;le<ae.length;le++){const Ne=ae[le];if(Ne.size>TD){H.error(a("multirun.launcher.toast.fileTooLarge",{fileName:Ne.name}));continue}try{const Me=await new Promise((Ve,we)=>{const ee=new FileReader;ee.onload=()=>Ve(ee.result),ee.onerror=we,ee.readAsDataURL(Ne)});f(Ve=>[...Ve,{id:ao(),filename:Ne.name,mimeType:Ne.type||"application/octet-stream",size:Ne.size,dataUrl:Me}]),je++}catch(Me){console.error("File attach failed",Me),H.error(a("multirun.launcher.toast.attachFailed",{fileName:Ne.name}))}}je>0&&H.success(je===1?a("multirun.launcher.toast.attachedSingle",{count:je}):a("multirun.launcher.toast.attachedPlural",{count:je})),N.current&&(N.current.value="")},Se=X=>{f(ae=>ae.filter(je=>je.id!==X))},fe=l.useMemo(()=>c.reduce((X,ae)=>X+ae.models.length,0),[c]),Ce=async X=>{X.preventDefault();const ae=c.filter(je=>je.prompt.trim()&&je.models.length>=1);if(ae.length!==0&&!(fe<1)){x(!0),ce();try{E&&E!==D&&S(E);const je=u.map(we=>({mime:we.mimeType,filename:we.filename,url:we.dataUrl})),le=y.filter(we=>we.trim().length>0),Ne=ae.map(we=>({prompt:we.prompt.trim(),models:we.models.map(ee=>({providerID:ee.providerID,modelID:ee.modelID,displayName:ee.displayName,variant:ee.variant}))})),Me={name:i.trim(),groups:Ne,agent:p||void 0,worktreeBaseBranch:ve?G:void 0,isolateRuns:ve,files:je.length>0?je:void 0,setupCommands:le.length>0?le:void 0},Ve=await te(Me);Ve&&(Ve.firstSessionId&&$t.getState().setCurrentSession(Ve.firstSessionId),e?.())}finally{x(!1)}}},Ie=!!(i.trim()&&c.some(X=>X.prompt.trim()&&X.models.length>=1)&&fe>=1&&B&&!Q&&(W===!1||!ve||G)),ke=y.filter(X=>X.trim()).length;return s.jsxs("form",{onSubmit:Ce,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:pe,className:ye("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",ne,me),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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":a("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(A,{name:"close",className:"h-5 w-5"})})}),s.jsx(It,{children:s.jsx("p",{children:a("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(jo,{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($a,{htmlFor:"multirun-project",required:!0,children:a("multirun.launcher.project.label")}),M.length>0?s.jsxs(as,{value:E??void 0,onValueChange:$,children:[s.jsx(is,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:V?s.jsx(fs,{children:_(V)}):s.jsx(fs,{placeholder:a("multirun.launcher.project.placeholder")})}),s.jsx(os,{fitContent:!0,children:M.map(X=>s.jsx(Mt,{value:X.id,className:"max-w-[24rem]",children:_(X)},X.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($a,{htmlFor:"group-name",required:!0,info:s.jsx(Nl,{children:a("multirun.launcher.groupName.info")}),children:a("multirun.launcher.groupName.label")}),s.jsx(Lt,{id:"group-name",value:i,onChange:X=>o(X.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($a,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Nl,{children:a("multirun.launcher.baseBranch.info")}),children:a("multirun.launcher.baseBranch.label")}),s.jsx(DD,{directory:B,value:G,onChange:K,disabled:!ve,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(vs,{checked:k,onChange:w,disabled:!ge,ariaLabel:a("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:a("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx($a,{htmlFor:"multirun-agent",info:s.jsx(Nl,{children:a("multirun.launcher.agent.info")}),children:a("multirun.launcher.agent.label")}),s.jsx(nx,{value:p,onChange:m,id:"multirun-agent"})]})]}),s.jsxs(vr,{open:h,onOpenChange:j,children:[s.jsxs(Mr,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(A,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:a("multirun.launcher.setupCommands.label")}),ke>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:ke}),s.jsx(A,{name:"arrow-down-s",className:ye("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",h&&"rotate-180")})]}),s.jsx(wr,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:v?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:a("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[y.map((X,ae)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Lt,{value:X,onChange:je=>{const le=[...y];le[ae]=je.target.value,g(le)},placeholder:a("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>g(y.filter((je,le)=>le!==ae)),className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":a("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]},`${X}-${ae}`)),s.jsxs("button",{type:"button",onClick:()=>g([...y,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(A,{name:"add",className:"h-3 w-3"}),a("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx($a,{htmlFor:"prompt",required:!0,children:a("multirun.launcher.attachments.label")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:N,type:"file",multiple:!0,className:"hidden",onChange:Y,accept:"*/*"}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>N.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(A,{name:"attachment-2",className:"h-3 w-3"}),a("multirun.launcher.attachments.attach")]})}),s.jsx(It,{children:a("multirun.launcher.attachments.tooltip")})]}),u.map(X=>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:[X.mimeType.startsWith("image/")?s.jsx(A,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(A,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:X.filename,children:X.filename}),s.jsx("button",{type:"button",onClick:()=>Se(X.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(A,{name:"close",className:"h-3 w-3"})})]},X.id))]})]}),c.map((X,ae)=>s.jsx(MD,{group:X,groupIndex:ae,canRemove:c.length>1,onUpdate:xe,onRemove:se},X.id)),s.jsxs("button",{type:"button",onClick:ue,className:"flex items-center gap-1.5 py-2 px-3 -mx-3 rounded-lg typography-meta font-medium text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),a("multirun.launcher.groups.addGroup")]}),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:[!ve&&W!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(A,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:a("multirun.launcher.project.gitRequired")})]}):null,s.jsx(be,{type:"button",variant:"ghost",size:"sm",onClick:n,children:a("multirun.launcher.actions.cancel")}),s.jsx(be,{type:"submit",size:"sm",disabled:!Ie||b,children:b?a("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:a("multirun.launcher.actions.startWithRunCount",{count:fe})})})]})})]})},MD=t=>{const e=ot.c(99),{group:n,groupIndex:r,canRemove:a,onUpdate:i,onRemove:o}=t,{t:c}=ft(),[d,p]=l.useState(!1),[m,u]=l.useState(""),[f,b]=l.useState(!1),[x,y]=l.useState(""),[g,h]=l.useState(!1),[j,v]=l.useState(""),C=l.useRef(null),k=l.useRef(null),w=l.useRef(null),N=l.useRef(null);let I;e[0]!==n.id||e[1]!==n.models||e[2]!==i?(I=le=>{n.models.length>=od||i(n.id,{models:[...n.models,le]})},e[0]=n.id,e[1]=n.models,e[2]=i,e[3]=I):I=e[3];const T=I;let P;e[4]!==n.id||e[5]!==n.models||e[6]!==i?(P=le=>{i(n.id,{models:n.models.filter((Ne,Me)=>Me!==le)})},e[4]=n.id,e[5]=n.models,e[6]=i,e[7]=P):P=e[7];const D=P;let S;e[8]!==n.id||e[9]!==n.models||e[10]!==i?(S=(le,Ne)=>{i(n.id,{models:n.models.map((Me,Ve)=>Ve===le?Ne:Me)})},e[8]=n.id,e[9]=n.models,e[10]=i,e[11]=S):S=e[11];const M=S;let E;e[12]===Symbol.for("react.memo_cache_sentinel")?(E=(le,Ne)=>{if(le.startsWith("/")){const ee=le.indexOf(" "),F=le.indexOf(`
|
|
229
|
-
`),U=Math.min(ee===-1?le.length:ee,F===-1?le.length:F);if(Ne<=U&&ee===-1){y(le.substring(1,U)),b(!0),p(!1),h(!1);return}}b(!1);const Me=le.substring(0,Ne),Ve=Me.lastIndexOf("#");if(Ve!==-1){const ee=Ve>0?Me[Ve-1]:null,F=Me.substring(Ve+1);if((!ee||/\s/.test(ee))&&!F.includes(" ")&&!F.includes(`
|
|
230
|
-
`)){v(F),h(!0),p(!1);return}}h(!1);const we=Me.lastIndexOf("@");if(we!==-1){const ee=we>0?Me[we-1]:null,F=Me.substring(we+1);(!ee||/\s/.test(ee))&&!F.includes(" ")&&!F.includes(`
|
|
231
|
-
`)?(u(F),p(!0)):p(!1);return}p(!1)},e[12]=E):E=e[12];const R=E;let V;e[13]!==n.id||e[14]!==i?(V=le=>{i(n.id,{prompt:le})},e[13]=n.id,e[14]=i,e[15]=V):V=e[15];const B=V;let $;e[16]!==n.prompt||e[17]!==B?($=le=>{const Ne=n.prompt,Ve=C.current?.selectionStart??Ne.length,ee=Ne.substring(0,Ve).lastIndexOf("@"),F=le.relativePath&&le.relativePath.trim().length>0?le.relativePath.trim():le.path||le.name,U=ee!==-1?ee:Ve,oe=`${Ne.substring(0,U)}@${F} ${Ne.substring(Ve)}`,Te=U+F.length+2;B(oe),p(!1),u(""),requestAnimationFrame(()=>{const Oe=C.current;Oe&&(Oe.selectionStart=Te,Oe.selectionEnd=Te,Oe.focus()),R(oe,Te)})},e[16]=n.prompt,e[17]=B,e[18]=$):$=e[18];const O=$;let _;e[19]!==n.prompt||e[20]!==B?(_=le=>{const Ne=n.prompt,Ve=C.current?.selectionStart??Ne.length,ee=Ne.substring(0,Ve).lastIndexOf("@"),F=ee!==-1?ee:Ve,U=`${Ne.substring(0,F)}@${le} ${Ne.substring(Ve)}`,oe=F+le.length+2;B(U),p(!1),u(""),requestAnimationFrame(()=>{const Te=C.current;Te&&(Te.selectionStart=oe,Te.selectionEnd=oe,Te.focus()),R(U,oe)})},e[19]=n.prompt,e[20]=B,e[21]=_):_=e[21];const q=_;let L;e[22]!==B?(L=le=>{const Ne=`/${le.name} `;B(Ne),b(!1),y(""),h(!1),requestAnimationFrame(()=>{const Me=C.current;Me&&(Me.focus(),Me.selectionStart=Me.value.length,Me.selectionEnd=Me.value.length),R(Ne,Ne.length)})},e[22]=B,e[23]=L):L=e[23];const J=L;let Z;e[24]!==n.prompt||e[25]!==B?(Z=(le,Ne)=>{const Me=n.prompt,we=C.current?.selectionStart??Me.length,F=Me.substring(0,we).lastIndexOf("#"),U=F!==-1?F:we,oe=`${Me.substring(0,U)}#${Ne} ${Me.substring(we)}`,Te=U+Ne.length+2;B(oe),h(!1),v(""),requestAnimationFrame(()=>{const Oe=C.current;Oe&&(Oe.selectionStart=Te,Oe.selectionEnd=Te,Oe.focus()),R(oe,Te)})},e[24]=n.prompt,e[25]=B,e[26]=Z):Z=e[26];const ie=Z;let ne;e[27]!==f||e[28]!==d||e[29]!==g?(ne=le=>{if(f&&w.current&&(le.key==="Enter"||le.key==="ArrowUp"||le.key==="ArrowDown"||le.key==="Escape"||le.key==="Tab")){le.preventDefault(),w.current.handleKeyDown(le.key);return}d&&k.current&&(le.key==="Enter"||le.key==="ArrowUp"||le.key==="ArrowDown"||le.key==="Escape"||le.key==="Tab")&&(le.preventDefault(),k.current.handleKeyDown(le.key)),g&&N.current&&(le.key==="Enter"||le.key==="ArrowUp"||le.key==="ArrowDown"||le.key==="Escape"||le.key==="Tab")&&(le.preventDefault(),N.current.handleKeyDown(le.key))},e[27]=f,e[28]=d,e[29]=g,e[30]=ne):ne=e[30];const me=ne,pe=r+1;let G;e[31]!==c||e[32]!==pe?(G=c("multirun.launcher.groups.groupLabel",{index:pe}),e[31]=c,e[32]=pe,e[33]=G):G=e[33];let K;e[34]!==G?(K=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:G}),e[34]=G,e[35]=K):K=e[35];let Q;e[36]!==a||e[37]!==n.id||e[38]!==o||e[39]!==c?(Q=a&&s.jsx("button",{type:"button",onClick:()=>o(n.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10","aria-label":c("multirun.launcher.groups.removeGroup"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=a,e[37]=n.id,e[38]=o,e[39]=c,e[40]=Q):Q=e[40];let W;e[41]!==K||e[42]!==Q?(W=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[K,Q]}),e[41]=K,e[42]=Q,e[43]=W):W=e[43];let de;e[44]!==c?(de=c("multirun.launcher.groups.prompt.label"),e[44]=c,e[45]=de):de=e[45];let ge;e[46]!==de?(ge=s.jsx($a,{required:!0,children:de}),e[46]=de,e[47]=ge):ge=e[47];const ve=n.prompt;let te;e[48]!==B?(te=le=>{const Ne=le.target.value;B(Ne);const Me=le.target.selectionStart??Ne.length;R(Ne,Me)},e[48]=B,e[49]=te):te=e[49];let he;e[50]!==c?(he=c("multirun.launcher.groups.prompt.placeholder"),e[50]=c,e[51]=he):he=e[51];let ce;e[52]!==n.prompt||e[53]!==me||e[54]!==te||e[55]!==he?(ce=s.jsx(un,{ref:C,value:ve,onChange:te,onKeyDown:me,placeholder:he,className:"typography-meta min-h-[80px] max-h-[200px] resize-none overflow-y-auto field-sizing-content",required:!0}),e[52]=n.prompt,e[53]=me,e[54]=te,e[55]=he,e[56]=ce):ce=e[56];let xe;e[57]!==x||e[58]!==J||e[59]!==f?(xe=f?s.jsx(Mh,{ref:w,searchQuery:x,onCommandSelect:J,onClose:()=>b(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=x,e[58]=J,e[59]=f,e[60]=xe):xe=e[60];let se;e[61]!==q||e[62]!==O||e[63]!==m||e[64]!==d?(se=d?s.jsx(Rh,{ref:k,searchQuery:m,onFileSelect:O,onAgentSelect:q,onClose:()=>p(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=q,e[62]=O,e[63]=m,e[64]=d,e[65]=se):se=e[65];let ue;e[66]!==ie||e[67]!==g||e[68]!==j?(ue=g?s.jsx(Fh,{ref:N,searchQuery:j,onSnippetSelect:ie,onClose:()=>h(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=ie,e[67]=g,e[68]=j,e[69]=ue):ue=e[69];let Y;e[70]!==ce||e[71]!==xe||e[72]!==se||e[73]!==ue?(Y=s.jsxs("div",{className:"relative",children:[ce,xe,se,ue]}),e[70]=ce,e[71]=xe,e[72]=se,e[73]=ue,e[74]=Y):Y=e[74];let Se;e[75]!==ge||e[76]!==Y?(Se=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ge,Y]}),e[75]=ge,e[76]=Y,e[77]=Se):Se=e[77];let fe;e[78]!==c?(fe=c("multirun.launcher.models.info",{max:od}),e[78]=c,e[79]=fe):fe=e[79];let Ce;e[80]!==fe?(Ce=s.jsx(Nl,{children:fe}),e[80]=fe,e[81]=Ce):Ce=e[81];let Ie;e[82]!==c?(Ie=c("multirun.launcher.models.label"),e[82]=c,e[83]=Ie):Ie=e[83];let ke;e[84]!==Ce||e[85]!==Ie?(ke=s.jsx($a,{required:!0,info:Ce,children:Ie}),e[84]=Ce,e[85]=Ie,e[86]=ke):ke=e[86];let X;e[87]!==n.models||e[88]!==T||e[89]!==D||e[90]!==M?(X=s.jsx(ax,{selectedModels:n.models,onAdd:T,onRemove:D,onUpdate:M,minModels:1,maxModels:od}),e[87]=n.models,e[88]=T,e[89]=D,e[90]=M,e[91]=X):X=e[91];let ae;e[92]!==ke||e[93]!==X?(ae=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ke,X]}),e[92]=ke,e[93]=X,e[94]=ae):ae=e[94];let je;return e[95]!==W||e[96]!==Se||e[97]!==ae?(je=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[W,Se,ae]}),e[95]=W,e[96]=Se,e[97]=ae,e[98]=je):je=e[98],je},Kf=()=>{if(typeof window>"u")return{height:0,keyboardHeight:0};const t=window.visualViewport?.height??window.innerHeight,e=window.visualViewport?Math.max(0,window.innerHeight-t):0;return{height:t,keyboardHeight:e}},RD=()=>{const t=ot.c(2),[e,n]=l.useState(Kf),r=l.useRef(null);let a,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{if(typeof window>"u")return;const o=window.visualViewport,c=()=>{r.current===null&&(r.current=requestAnimationFrame(()=>{r.current=null;const d=Kf();n(p=>p.height===d.height&&p.keyboardHeight===d.keyboardHeight?p:d)}))};return o?(o.addEventListener("resize",c),o.addEventListener("scroll",c,{passive:!0})):window.addEventListener("resize",c),c(),()=>{r.current!==null&&cancelAnimationFrame(r.current),o?(o.removeEventListener("resize",c),o.removeEventListener("scroll",c)):window.removeEventListener("resize",c)}},i=[],t[0]=a,t[1]=i):(a=t[0],i=t[1]),l.useEffect(a,i),e};class FD 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($h,{className:"w-full max-w-md",children:[s.jsx(vv,{className:"text-center",children:s.jsxs(wv,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(A,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(jv,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&s.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&s.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[s.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),s.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(be,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(A,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),s.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function OD(t){const e=ot.c(22),{t:n}=ft();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(FD,{...t,texts:p}),e[19]=t,e[20]=p,e[21]=m):m=e[21],m}const Kd=t=>{const e=ot.c(5),{readOnly:n}=t,r=n===void 0?!1:n,i=$t(LD)||void 0;let o;e[0]!==r?(o=s.jsx(Nv,{readOnly:r}),e[0]=r,e[1]=o):o=e[1];let c;return e[2]!==i||e[3]!==o?(c=s.jsx(OD,{sessionId:i,children:o}),e[2]=i,e[3]=o,e[4]=c):c=e[4],c};function LD(t){return t.currentSessionId}const $D=ra(()=>Tr(()=>Promise.resolve().then(()=>xS),void 0).then(t=>({default:t.PlanView}))),Hf=ra(()=>Tr(()=>Promise.resolve().then(()=>IN),void 0).then(t=>({default:t.GitView}))),_D=ra(()=>Tr(()=>Promise.resolve().then(()=>B2),void 0).then(t=>({default:t.DiffView}))),Gf=ra(()=>Tr(()=>import("./TerminalView-Bvil3j1u.js"),__vite__mapDeps([5,0,1,2,3,4])).then(t=>({default:t.TerminalView}))),BD=ra(()=>Tr(()=>Promise.resolve().then(()=>uS),void 0).then(t=>({default:t.FilesView}))),VD=ra(()=>Tr(()=>Promise.resolve().then(()=>xI),void 0).then(t=>({default:t.SettingsView}))),zD=ra(()=>Tr(()=>import("./SettingsWindow-C0lRRW8M.js"),__vite__mapDeps([6,0,1,2,3,4])).then(t=>({default:t.SettingsWindow}))),UD=ra(()=>Tr(()=>import("./MultiRunWindow-BKSHxjMq.js"),__vite__mapDeps([7,0,1,2,3,4])).then(t=>({default:t.MultiRunWindow}))),WD=280,KD=500,HD=360,GD=860,qD=()=>{const a=Fe(K=>K.isSidebarOpen),i=Fe(K=>K.isRightSidebarOpen),o=Fe(K=>K.isBottomTerminalOpen),c=Fe(K=>K.setRightSidebarOpen),d=Fe(K=>K.setBottomTerminalOpen),p=Fe(K=>K.activeMainTab),m=Fe(K=>K.setIsMobile),u=Fe(K=>K.isSessionSwitcherOpen),f=Fe(K=>K.isSettingsDialogOpen),b=Fe(K=>K.setSettingsDialogOpen),x=Fe(K=>K.isMultiRunLauncherOpen),y=Fe(K=>K.setMultiRunLauncherOpen),g=Fe(K=>K.multiRunLauncherPrefillPrompt),{isMobile:h,isTablet:j}=ln(),v=RD(),C=Fe(K=>K.sidebarWidth),k=Fe(K=>K.rightSidebarWidth),w=l.useRef(!1),N=l.useRef(!1),I=l.useRef(!1),[T,P]=l.useState(!1),[D,S]=l.useState(!1),[M,E]=l.useState(!1),[R,V]=l.useState(!1),B=l.useCallback(K=>{P(K),Fe.getState().setSessionSwitcherOpen(K)},[]),$=l.useRef(!1),O=l.useRef(typeof window>"u"?0:window.innerWidth),_=Ru(-O.current),q=_e.useRef(0),L=Ru(O.current),J=_e.useRef(0);_e.useEffect(()=>{h&&(q.current=window.innerWidth,J.current=window.innerWidth)},[h]),_e.useEffect(()=>{if(!h){E(!1);return}T&&E(!0),Fu(_,T?0:-q.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[T,h,_]),_e.useEffect(()=>{if(!h){V(!1);return}$.current=D,D&&V(!0),Fu(L,D?0:J.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[h,D,L]),_e.useEffect(()=>{if(h)return _.on("change",K=>{const Q=q.current||O.current,W=T||K>-Q+.5;E(de=>de===W?de:W)})},[h,_,T]),_e.useEffect(()=>{if(h)return L.on("change",K=>{const Q=J.current||O.current,W=D||K<Q-.5;V(de=>de===W?de:W)})},[h,D,L]),_e.useEffect(()=>{h&&!u&&T&&B(!1)},[u,h,T,B]),_e.useEffect(()=>{if(!h){I.current=!1;return}I.current||(I.current=!0,B(!1),S(!1),Fe.getState().isRightSidebarOpen&&c(!1))},[h,B,c]),_e.useEffect(()=>{if(!h||p!=="chat"||T||D||f)return;let K=!1,Q;const W=de=>{Q=window.setTimeout(()=>{if(K)return;const ge=$t.getState(),ve=Fe.getState();if(!(ve.activeMainTab!=="chat"||ve.isSettingsDialogOpen||ge.currentSessionId||ge.newSessionDraft?.open)){if(ge.isLoading){W(250);return}ge.openNewSessionDraft()}},de)};return W(500),()=>{K=!0,Q!==void 0&&window.clearTimeout(Q)}},[p,h,f,T,D]),_e.useEffect(()=>{!h||!f||(B(!1),S(!1),i&&c(!1))},[h,f,i,B,c]);const Z=Ua(K=>K.checkForUpdates);l.useEffect(()=>{let ge=!1,ve=null;const te=ce=>{const xe=Math.round(ce*1e3);return Math.max(3e5,Math.min(864e5,xe))},he=ce=>{ge||(ve=window.setTimeout(async()=>{const xe=await Z(),se=typeof xe=="number"&&Number.isFinite(xe)?te(xe):36e5;he(se)},ce))};return he(3e3),()=>{ge=!0,ve!==null&&window.clearTimeout(ve)}},[Z]),l.useEffect(()=>{Fe.getState().isMobile!==h&&m(h)},[h,m]),l.useEffect(()=>{if(typeof window>"u")return;let K;const Q=()=>{K!==void 0&&window.clearTimeout(K),K=window.setTimeout(()=>{Fe.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",Q),()=>{window.removeEventListener("resize",Q),K!==void 0&&window.clearTimeout(K)}},[]),l.useEffect(()=>{if(typeof window>"u")return;let K;const Q=()=>{const de=Fe.getState(),ge=window.innerWidth,ve=window.innerHeight;if(!h&&!j){const te=ge<1140,he=ge>=1220;te?de.isRightSidebarOpen&&(c(!1),w.current=!0):he&&w.current&&(c(!0),w.current=!1);const ce=ve<640,xe=ve>=700;ce?de.isBottomTerminalOpen&&(d(!1),N.current=!0):xe&&N.current&&(d(!0),N.current=!1)}},W=()=>{K!==void 0&&window.clearTimeout(K),K=window.setTimeout(()=>{Q()},100)};return Q(),window.addEventListener("resize",W),()=>{window.removeEventListener("resize",W),K!==void 0&&window.clearTimeout(K)}},[h,j,d,c]),l.useEffect(()=>{if(typeof window>"u")return;const K=Fe.subscribe((Q,W)=>{const de=window.innerWidth,ge=window.innerHeight,ve=de>=1220,te=ge>=700;Q.isRightSidebarOpen!==W.isRightSidebarOpen&&ve&&(w.current=!1),Q.isBottomTerminalOpen!==W.isBottomTerminalOpen&&te&&(N.current=!1)});return()=>{K()}},[h,j,d,c]);const ie=l.useCallback(()=>{T&&B(!1),S(!D)},[T,D,B]),ne=l.useMemo(()=>{switch(p){case"plan":return s.jsx(l.Suspense,{fallback:null,children:s.jsx($D,{})});case"git":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(Hf,{})});case"diff":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(_D,{})});case"terminal":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(Gf,{})});case"files":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(BD,{})});case"context":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(bg,{})});default:return null}},[p]),me=p==="chat",pe=l.useMemo(()=>Math.min(KD,Math.max(WD,C||vd)),[C]),G=l.useMemo(()=>Math.min(GD,Math.max(HD,k||wd)),[k]);return s.jsx(c0,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:ye("main-content-safe-area",h?"flex flex-col":"flex h-[100dvh]","bg-background"),style:h&&v.height>0?{height:v.height}:void 0,children:[s.jsx(bI,{}),s.jsx(a6,{}),s.jsx(c6,{}),s.jsx(vD,{}),h?s.jsxs(Sv,{value:{leftDrawerOpen:T,rightDrawerOpen:D,toggleLeftDrawer:()=>{const K=!T;D&&S(!1),B(K)},toggleRightDrawer:ie,leftDrawerX:_,rightDrawerX:L,leftDrawerWidth:q,rightDrawerWidth:J,setMobileLeftDrawerOpen:B,setRightSidebarOpen:S},children:[!f&&s.jsx(km,{onToggleLeftDrawer:()=>{const K=!T;D&&S(!1),B(K)},onToggleRightDrawer:()=>{ie()},leftDrawerOpen:T,rightDrawerOpen:D}),s.jsx("div",{"data-page-scroll-lock":"true",className:ye("flex flex-1 overflow-hidden relative",f&&"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:ye("absolute inset-0",!me&&"invisible"),children:s.jsx(en,{children:s.jsx(Kd,{})})}),ne&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(en,{children:ne})}),x&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(en,{children:s.jsx(ED,{initialPrompt:g,onCreated:()=>y(!1),onCancel:()=>y(!1)})})}),M&&s.jsx(Ou.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:_},"aria-hidden":!T,children:s.jsx(en,{children:s.jsx(Vf,{mobileVariant:!0})})}),R&&s.jsx(Ou.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:L},"aria-hidden":!D,children:s.jsx(en,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(Hf,{})})})})]})}),f&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(en,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(VD,{onClose:()=>b(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[s.jsx(km,{}),s.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-sidebar","data-page-scroll-lock":"true",children:[s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute top-0 z-0 bg-sidebar transition-[left,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{left:`${a?pe:0}px`,opacity:a?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute bottom-0 z-0 bg-sidebar transition-[left,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{left:`${a?pe:0}px`,opacity:a?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute top-0 z-0 bg-sidebar transition-[right,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{right:`${i?G:0}px`,opacity:i?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute bottom-0 z-0 bg-sidebar transition-[right,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{right:`${i?G:0}px`,opacity:i?1:0,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)"}}),s.jsx(gw,{isOpen:a,isMobile:h,className:"border-0",children:s.jsx(Vf,{})}),s.jsxs("div",{className:ye("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-background","border border-border/50 rounded-[10px]",!a&&"border-l-transparent",!i&&"border-r-transparent"),"data-page-scroll-lock":"true",children:[s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden","data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:ye("absolute inset-0",!me&&"invisible"),children:s.jsx(en,{children:s.jsx(Kd,{})})}),ne&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(en,{children:ne})})]}),s.jsx(nk,{})]})}),s.jsx(uw,{isOpen:o,isMobile:h,children:o?s.jsx(en,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(Gf,{})})}):null})]}),s.jsx(xw,{isOpen:i,className:"border-0",children:s.jsx(en,{children:s.jsx(i2,{})})})]})]}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(zD,{open:f,onOpenChange:b})}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(UD,{open:x,onOpenChange:y,initialPrompt:g})})]})]})})},JD=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`},hr=t=>{const e=ot.c(8),{label:n,value:r}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=a):a=e[0];let i;e[1]!==n?(i=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=i):i=e[2];let 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},qf=t=>{const e=ot.c(43),{title:n,snapshot:r,emptyLabel:a}=t,{t:i}=ft();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(XD,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?JD(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=u):u=e[15];let f;e[16]!==u?(f=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:u}),e[16]=u,e[17]=f):f=e[17];let b;e[18]!==m||e[19]!==f?(b=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,f]}),e[18]=m,e[19]=f,e[20]=b):b=e[20];let x;e[21]!==i?(x=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=x):x=e[22];let y;e[23]!==r.entries.length||e[24]!==x?(y=s.jsx(hr,{label:x,value:r.entries.length}),e[23]=r.entries.length,e[24]=x,e[25]=y):y=e[25];let g;e[26]!==i?(g=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=g):g=e[27];let h;e[28]!==g||e[29]!==p?(h=s.jsx(hr,{label:g,value:p}),e[28]=g,e[29]=p,e[30]=h):h=e[30];let j;e[31]!==i?(j=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=j):j=e[32];let v;e[33]!==r.lastUpdatedAt||e[34]!==i?(v=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=v):v=e[35];let C;e[36]!==j||e[37]!==v?(C=s.jsx(hr,{label:j,value:v}),e[36]=j,e[37]=v,e[38]=C):C=e[38];let k;e[39]!==h||e[40]!==C||e[41]!==y?(k=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[y,h,C]}),e[39]=h,e[40]=C,e[41]=y,e[42]=k):k=e[42],o=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[b,k,c.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:a}):s.jsx(Ss,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:c.map(w=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:w.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:i("memoryDebugPanel.metric.countValue",{value:w.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:w.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:w.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:w.total})})]})]},w.metric))})})]}),e[0]=a,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=i,e[6]=n,e[7]=o}else o=e[7];return o},YD=t=>{const e=ot.c(101),{onClose:n}=t,{t:r}=ft(),[a,i]=l.useState("memory"),[o,c]=l.useState("idle"),d=$t(ZD),p=Lh(eT),m=sc(),u=Sh(tT),f=xr(sT),[b,x]=l.useState(nT),[y,g]=l.useState(rT);let h;e[0]!==b.entries?(h=new Map,b.entries.forEach(fe=>{h.set(fe.metric,fe.count)}),e[0]=b.entries,e[1]=h):h=e[1];let j;e[2]!==h?(j=h.get("ui.message_list.render")??0,e[2]=h,e[3]=j):j=e[3];let v;e[4]!==h?(v=h.get("ui.message_list.render.streaming")??0,e[4]=h,e[5]=v):v=e[5];let C;e[6]!==h?(C=h.get("ui.chat_message.render")??0,e[6]=h,e[7]=C):C=e[7];let k;e[8]!==h?(k=h.get("ui.chat_message.render.streaming")??0,e[8]=h,e[9]=k):k=e[9];let w;e[10]!==h?(w=h.get("ui.chat_message.render.static_during_stream")??0,e[10]=h,e[11]=w):w=e[11];let N;e[12]!==h?(N=h.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=h,e[13]=N):N=e[13];let I;e[14]!==j||e[15]!==v||e[16]!==C||e[17]!==k||e[18]!==w||e[19]!==N?(I={messageListRender:j,messageListRenderStreaming:v,chatMessageRender:C,chatMessageRenderStreaming:k,chatMessageRenderStaticDuringStream:w,chatMessageRenderStaticOutsideActiveTurnDuringStream:N},e[14]=j,e[15]=v,e[16]=C,e[17]=k,e[18]=w,e[19]=N,e[20]=I):I=e[20];const T=I;let P,D;e[21]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{const fe=()=>{x(ll()),g(cl())};fe();const Ce=window.setInterval(fe,500);return()=>window.clearInterval(Ce)},D=[],e[21]=P,e[22]=D):(P=e[21],D=e[22]),l.useEffect(P,D);let S,M;e[23]!==o?(S=()=>{if(o==="idle")return;const fe=window.setTimeout(()=>{c("idle")},1500);return()=>window.clearTimeout(fe)},M=[o],e[23]=o,e[24]=S,e[25]=M):(S=e[24],M=e[25]),l.useEffect(S,M);let E=0,R;if(e[26]!==u?(R=Object.keys(u),e[26]=u,e[27]=R):R=e[27],e[28]!==u||e[29]!==R||e[30]!==E){for(const fe of R)E=E+(u[fe]?.length??0);e[28]=u,e[29]=R,e[30]=E,e[31]=E}else E=e[31];const V=E;let B;if(e[32]!==d||e[33]!==u||e[34]!==p||e[35]!==m||e[36]!==r){let fe;e[38]!==d||e[39]!==u||e[40]!==p||e[41]!==r?(fe=Ce=>{const Ie=u[Ce.id]?.length||0,ke=p.get(Ce.id);return{id:Ce.id,title:Ce.title||r("memoryDebugPanel.common.untitled"),messageCount:Ie,isStreaming:ke?.isStreaming||!1,isZombie:ke?.isZombie||!1,backgroundCount:ke?.backgroundMessageCount||0,lastAccessed:ke?.lastAccessedAt||0,isCurrent:Ce.id===d}},e[38]=d,e[39]=u,e[40]=p,e[41]=r,e[42]=fe):fe=e[42],B=m.map(fe).sort(aT),e[32]=d,e[33]=u,e[34]=p,e[35]=m,e[36]=r,e[37]=B}else B=e[37];const $=B;let O;e[43]!==u?(O=Object.keys(u),e[43]=u,e[44]=O):O=e[44];const _=O.length;let q;e[45]===Symbol.for("react.memo_cache_sentinel")?(q=async()=>{try{const fe={generatedAt:new Date().toISOString(),ui:ll(),vscode:cl()};await navigator.clipboard.writeText(JSON.stringify(fe,null,2)),c("copied")}catch{c("error")}},e[45]=q):q=e[45];const L=q;let J;e[46]===Symbol.for("react.memo_cache_sentinel")?(J={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=J):J=e[46];let Z;e[47]!==a?(Z=a==="memory"?s.jsx(A,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(A,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=a,e[48]=Z):Z=e[48];let ie;e[49]!==r?(ie=r("memoryDebugPanel.title"),e[49]=r,e[50]=ie):ie=e[50];let ne;e[51]!==ie?(ne=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:ie}),e[51]=ie,e[52]=ne):ne=e[52];let me;e[53]!==Z||e[54]!==ne?(me=s.jsxs("div",{className:"flex items-center gap-2",children:[Z,ne]}),e[53]=Z,e[54]=ne,e[55]=me):me=e[55];let pe;e[56]!==a?(pe=a==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(be,{size:"xs",variant:"ghost",onClick:L,children:s.jsx(A,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(be,{size:"xs",variant:"ghost",onClick:()=>{Cv(),x(ll()),g(cl())},children:s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=a,e[57]=pe):pe=e[57];let G;e[58]!==n?(G=n?s.jsx(be,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(A,{name:"close",className:"h-4 w-4"})}):null,e[58]=n,e[59]=G):G=e[59];let K;e[60]!==pe||e[61]!==G?(K=s.jsxs("div",{className:"flex items-center gap-1",children:[pe,G]}),e[60]=pe,e[61]=G,e[62]=K):K=e[62];let Q;e[63]!==me||e[64]!==K?(Q=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[me,K]}),e[63]=me,e[64]=K,e[65]=Q):Q=e[65];let W;e[66]===Symbol.for("react.memo_cache_sentinel")?(W={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=W):W=e[66];const de=a==="memory"?"secondary":"ghost";let ge;e[67]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>i("memory"),e[67]=ge):ge=e[67];let ve;e[68]!==r?(ve=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=ve):ve=e[69];let te;e[70]!==de||e[71]!==ve?(te=s.jsx(be,{size:"sm",variant:de,className:"flex-1",onClick:ge,children:ve}),e[70]=de,e[71]=ve,e[72]=te):te=e[72];const he=a==="streaming"?"secondary":"ghost";let ce;e[73]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>i("streaming"),e[73]=ce):ce=e[73];let xe;e[74]!==r?(xe=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=xe):xe=e[75];let se;e[76]!==he||e[77]!==xe?(se=s.jsx(be,{size:"sm",variant:he,className:"flex-1",onClick:ce,children:xe}),e[76]=he,e[77]=xe,e[78]=se):se=e[78];let ue;e[79]!==te||e[80]!==se?(ue=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:W,children:[te,se]}),e[79]=te,e[80]=se,e[81]=ue):ue=e[81];let Y;e[82]!==a||e[83]!==_||e[84]!==o||e[85]!==d||e[86]!==u||e[87]!==p||e[88]!==$||e[89]!==m||e[90]!==T||e[91]!==b||e[92]!==r||e[93]!==f||e[94]!==V||e[95]!==y?(Y=a==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(hr,{label:r("memoryDebugPanel.metric.totalMessages"),value:V}),s.jsx(hr,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${_} / ${om.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:kv()})})]}),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:om.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(Ss,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:$.map(fe=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:fe.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:fe.title}),fe.isStreaming?s.jsx(A,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,fe.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:fe.messageCount})}),fe.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",fe.backgroundCount]}):null]})]},fe.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(be,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(iT),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(be,{size:"xs",variant:"outline",onClick:L,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(hr,{label:r("memoryDebugPanel.metric.uiMetrics"),value:b.entries.length}),s.jsx(hr,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:y.entries.length}),s.jsx(hr,{label:r("memoryDebugPanel.metric.messageListRenders"),value:T.messageListRender}),s.jsx(hr,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:T.messageListRenderStreaming}),s.jsx(hr,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:T.chatMessageRender}),s.jsx(hr,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:T.chatMessageRenderStreaming}),s.jsx(hr,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:T.chatMessageRenderStaticDuringStream}),s.jsx(hr,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:T.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(qf,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:b,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),y.entries.length>0?s.jsx(qf,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:y,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=a,e[83]=_,e[84]=o,e[85]=d,e[86]=u,e[87]=p,e[88]=$,e[89]=m,e[90]=T,e[91]=b,e[92]=r,e[93]=f,e[94]=V,e[95]=y,e[96]=Y):Y=e[96];let Se;return e[97]!==Q||e[98]!==ue||e[99]!==Y?(Se=s.jsxs($h,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:J,children:[Q,ue,Y]}),e[97]=Q,e[98]=ue,e[99]=Y,e[100]=Se):Se=e[100],Se},QD=YD;function XD(t,e){return t+e.count}function ZD(t){return t.currentSessionId}function eT(t){return t.sessionMemoryState}function tT(t){return t.message}function sT(t){return t.totalRequestCount}function nT(){return ll()}function rT(){return cl()}function aT(t,e){return e.lastAccessed-t.lastAccessed}function iT(t){return{id:t.id,title:t.title}}const oT=()=>{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()??"":""},lT=async()=>{const t=oT()||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")},Jf="openchamber:menu-action",ld="openchamber:check-for-updates",cT=t=>{const e=$t(k=>k.openNewSessionDraft),n=Fe(k=>k.toggleCommandPalette),r=Fe(k=>k.setCommandPaletteOpen),a=Fe(k=>k.toggleHelpDialog),i=Fe(k=>k.toggleSidebar),o=Fe(k=>k.setSessionSwitcherOpen),c=Fe(k=>k.setActiveMainTab),d=Fe(k=>k.setSettingsDialogOpen),p=Fe(k=>k.setAboutDialogOpen),m=Fe(k=>k.toggleRightSidebar),u=Fe(k=>k.setRightSidebarOpen),f=Fe(k=>k.setRightSidebarTab),b=Fe(k=>k.toggleBottomTerminal),x=Fe(k=>k.setBottomTerminalExpanded),y=Ua(k=>k.checkForUpdates),{setThemeMode:g}=jr(),h=l.useRef(!1),j=l.useCallback(()=>{h.current||(h.current=!0,y().then(()=>{const{available:k,error:w}=Ua.getState();if(w){H.error("Failed to check for updates",{description:w});return}k||H.success("You are on the latest version")}).finally(()=>{h.current=!1}))},[y]),v=l.useCallback(()=>{Dr.requestDirectoryDialog()},[]),C=l.useCallback(k=>{switch(k){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),Dh();break;case"change-workspace":v();break;case"toggle-right-sidebar":m();break;case"open-right-sidebar-git":u(!0),f("git");break;case"open-right-sidebar-files":u(!0),f("files");break;case"toggle-terminal":b();break;case"toggle-terminal-expanded":x(!Fe.getState().isBottomTerminalExpanded);break;case"copy":{const w=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(w)||lT();break}case"theme-light":g("light");break;case"theme-dark":g("dark");break;case"theme-system":g("system");break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"help-dialog":a();break;case"download-logs":{Iv().catch(()=>{H.error("Failed to collect OpenCode status")});break}}},[v,t,e,p,c,o,r,d,x,u,f,g,b,n,a,m,i]);l.useEffect(()=>{const k=N=>{const I=N.detail;I&&C(I)},w=()=>{j()};return window.addEventListener(Jf,k),window.addEventListener(ld,w),()=>{window.removeEventListener(Jf,k),window.removeEventListener(ld,w)}},[C,j]),l.useEffect(()=>{if(typeof window>"u")return;const w=window.__TAURI__?.event?.listen;if(typeof w!="function")return;let N=null,I=null;return w("openchamber:menu-action",T=>{const P=T?.payload;typeof P=="string"&&C(P)}).then(T=>{N=T}).catch(()=>{}),w("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(ld))}).then(T=>{I=T}).catch(()=>{}),()=>{(async()=>{try{const P=N?.();P instanceof Promise&&await P}catch{}try{const P=I?.();P instanceof Promise&&await P}catch{}})()}},[C])},dT=["chat","git","diff","terminal","files"],uT=["settings","agents","commands","skills","providers","usage","git-identities"],Pr={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Yf(t){const e=mT();return{sessionId:pT(e),tab:fT(e),settingsPath:hT(e),diffFile:gT(e)}}function mT(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function pT(t){const e=t.get(Pr.SESSION);return!e||e.trim().length===0?null:e.trim()}function fT(t){const e=t.get(Pr.TAB);if(!e)return null;const n=e.toLowerCase().trim();return dT.includes(n)?n:null}function hT(t){const e=t.get(Pr.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(uT.includes(n),n)}function gT(t){const e=t.get(Pr.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function Qf(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(Pr.SESSION)||t.has(Pr.TAB)||t.has(Pr.SETTINGS)||t.has(Pr.FILE)}catch{return!1}}const xT="chat";function mx(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(Pr.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(Pr.SETTINGS,n),e}return t.tab!==xT&&e.set(Pr.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(Pr.FILE,t.diffFile),e}function bT(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function yT(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=mx(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 vT(t,e={}){if(!(typeof window>"u")&&!wT()&&!(!e.force&&yT(t)))try{const n=mx(t),r=bT(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function wT(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function jT(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function NT(){const t=l.useMemo(()=>jT(),[]),e=l.useRef(!1),n=l.useRef(!1),r=$t(u=>u.setCurrentSession),a=Fe(u=>u.setActiveMainTab),i=Fe(u=>u.setSettingsDialogOpen),o=Fe(u=>u.setSettingsPage),c=Fe(u=>u.navigateToDiff),d=l.useCallback(async u=>{if(!n.current){n.current=!0;try{if(u.sessionId){const f=$t.getState().currentSessionId;u.sessionId!==f&&await r(u.sessionId)}if(u.settingsPath){o(bu(u.settingsPath)),i(!0);return}Fe.getState().isSettingsDialogOpen&&i(!1),u.tab&&a(u.tab),u.diffFile&&(u.tab==="diff"||!u.tab)&&c(u.diffFile)}finally{n.current=!1}}},[r,a,i,o,c]),p=l.useCallback(()=>{const u=$t.getState(),f=Fe.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();vT(f,u)},[t,p]);l.useEffect(()=>{if(e.current||(e.current=!0,!Qf()))return;const u=Yf();(async()=>(await d(u),t||m({replace:!0})))()},[d,t,m]),l.useEffect(()=>{if(t)return;let u=$t.getState().currentSessionId;return $t.subscribe(b=>{const x=b.currentSessionId;x===u||n.current||(u=x,m())})},[t,m]),l.useEffect(()=>{if(t)return;let u=Fe.getState().activeMainTab,f=Fe.getState().isSettingsDialogOpen,b=Fe.getState().settingsPage,x=Fe.getState().pendingDiffFile;return Fe.subscribe(g=>{if(n.current)return;const h=g.activeMainTab!==u,j=g.isSettingsDialogOpen!==f,v=g.settingsPage!==b,C=g.pendingDiffFile!==x&&g.activeMainTab==="diff";u=g.activeMainTab,f=g.isSettingsDialogOpen,b=g.settingsPage,x=g.pendingDiffFile,(h||j||v||C)&&m()})},[t,m]),l.useEffect(()=>{if(typeof window>"u"||t)return;const u=()=>{const f=Yf();if(Qf())d(f);else{const b=Fe.getState();b.isSettingsDialogOpen&&i(!1),b.activeMainTab!=="chat"&&a("chat")}};return window.addEventListener("popstate",u),()=>{window.removeEventListener("popstate",u)}},[d,t,a,i])}const ST="/api/notifications/stream",kT=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),CT=t=>{if(!t||typeof t!="object")return null;const e=t,n=e.properties&&typeof e.properties=="object"?e.properties:null;return e.type!=="openchamber:notification"||!n?null:{title:typeof n.title=="string"?n.title:void 0,body:typeof n.body=="string"?n.body:void 0,tag:typeof n.tag=="string"?n.tag:void 0}},IT=t=>{const e=ot.c(3),n=t?.enabled??!0;let r,a;e[0]!==n?(r=()=>{if(!n||jn()||!ea()||typeof window>"u"||typeof EventSource>"u")return;const i=new EventSource(ST);return i.onmessage=PT,()=>{i.close()}},a=[n],e[0]=n,e[1]=r,e[2]=a):(r=e[1],a=e[2]),l.useEffect(r,a)};function PT(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=Fe.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&kT())return;const r=CT(e);if(!r)return;or()?.notifications?.notifyAgentCompletion(r)}const AT=t=>!(t.dismissed==="true"||t.sessionShown==="true"||t.hasActiveToast),DT=t=>!(!t.version||t.seenVersions.has(t.version)||t.dismissedVersion!==null&&t.dismissedVersion===t.version),TT=t=>{if(t===null||typeof t!="object")return"";const e=t.version;return typeof e!="string"?"":e.trim()},ET=t=>!t||t.available!==!0||typeof t.latestVersion!="string"?"":t.latestVersion.trim(),Xf="pwa-install-toast-shown",Zf="pwa-install-toast-dismissed",MT=()=>{const t=ot.c(6),{browserTab:e}=zg(),{t:n}=ft(),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"||!ea()||!e)return;let d=null,p=null;const m=()=>{p!==null&&(H.dismiss(p),p=null)},u=async()=>{if(!d)return;const x=d;d=null,m(),await x.prompt();const{outcome:y}=await x.userChoice;y==="accepted"&&H.success(r.current("pwa.installPrompt.started"))},f=x=>{const y=x;if(typeof y.prompt!="function")return;y.preventDefault(),d=y;const g=br(),h=ch();AT({dismissed:g.getItem(Zf),sessionShown:h.getItem(Xf),hasActiveToast:p!==null})&&(h.setItem(Xf,"true"),p=H.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{u()}},cancel:{label:r.current("pwa.installPrompt.dismiss"),onClick:()=>{br().setItem(Zf,"true"),m()}}}))},b=()=>{d=null,m(),H.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",f),window.addEventListener("appinstalled",b),()=>{m(),window.removeEventListener("beforeinstallprompt",f),window.removeEventListener("appinstalled",b)}},c=[e],t[3]=e,t[4]=o,t[5]=c):(o=t[4],c=t[5]),l.useEffect(o,c)},RT=["local","remote",null],FT=["ok","not-configured","unreachable","wrong-service","missing"];function px(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!RT.includes(n)))return{valid:!1};if(typeof r!="string"||!FT.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 eh(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 OT(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function LT(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function th(){if(Hd()!=="valid")return null;const e=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__,n=px(e);return n.valid?n.outcome:null}function Hd(){if(typeof window>"u")return"not-injected";const t=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":px(t).valid?"valid":"malformed"}const $T=()=>{const t=ot.c(5),[e,n]=l.useState(_T),{isUpdating:r,message:a}=e;let i,o;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>Av(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(nu,{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 _T(){return Pv()}const BT=({open:t,onOpenChange:e})=>{const{t:n}=ft(),r=!1,[a,i]=l.useState(null),[o,c]=l.useState(null),[d,p]=l.useState(!1),[m,u]=l.useState(!1),[f,b]=l.useState(null),[x,y]=l.useState(!1);l.useCallback(async()=>{},[f,d,r,n]),l.useEffect(()=>{if(!t)return;(async()=>{try{const j=await fetch("/api/system/info");if(j.ok){const v=await j.json();if(typeof v.openchamberVersion=="string"&&v.openchamberVersion.trim()){i(v.openchamberVersion);return}}}catch{}i(await Dv())})()},[t]),l.useEffect(()=>{if(!t)return;let h=!1;return(async()=>{try{const v=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!v.ok)return;const C=await v.json().catch(()=>null),k=typeof C?.currentVersion=="string"?C.currentVersion.trim():"";!h&&k&&c(k)}catch{}})(),()=>{h=!0}},[t]),l.useEffect(()=>{{b(null),y(!1);return}},[t,r]);const g=a;return s.jsx(us,{open:t,onOpenChange:e,children:s.jsx(ds,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(nu,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"OpenChamber"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[g&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:g})}),o&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:o})})]})]}),r,s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsxs("div",{className:"flex items-center justify-center gap-4",children:[s.jsxs("a",{href:"https://github.com/btriapitsyn/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(A,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(A,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:"https://x.com/openchamber_dev",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(A,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},cd=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},VT=(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},zT=()=>{const t=vn(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=cd(i,"code"),c=Mg(i),d=yu(i),p=cd(i,"error"),m=cd(i,"error_description");if(p){d&&fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(m??p);return}(async()=>{try{if(!o)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let u=c;if(!u&&d){const f=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(f.ok){const b=await f.json().catch(()=>null);b?.name?.trim()&&(u={name:b.name.trim(),directory:typeof b.directory=="string"&&b.directory.trim()?b.directory.trim():null})}}if(!u?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");await t(u.name,o,u.directory),d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),a("Authorization completed. You can close this tab and return to OpenChamber.")}catch(u){d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(VT(u,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("div",{className:e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]",children:s.jsx("h1",{className:"typography-hero font-semibold",children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"})}),s.jsx("p",{className:"typography-body text-muted-foreground",children:r})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(be,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},qi="opencode-update-available",tl="opencode-upgrade-progress",UT=5e3,WT=[1e4,6e4],sh="opencode-update-toast-dismissed-version",fx=()=>{const{t}=ft(),e=Fe(o=>o.showOpenCodeUpdateNotifications),n=_e.useRef(new Set),r=_e.useRef(!1);_e.useEffect(()=>{e||H.dismiss(qi)},[e]);const a=_e.useCallback(()=>{H.dismiss(tl),xi({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),i=_e.useCallback(async()=>{if(!r.current){r.current=!0,H.dismiss(qi),H.message(t("opencodeUpdate.toast.upgrading.title"),{id:tl,description:t("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:s.jsx(A,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const o=await fetch("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),c=await o.json().catch(()=>null);if(!o.ok||c?.success===!1)throw new Error(c?.error||o.statusText||t("opencodeUpdate.toast.failed.description"));H.success(t("opencodeUpdate.toast.updated.title"),{id:tl,description:c?.version?t("opencodeUpdate.toast.updated.descriptionWithVersion",{version:c.version}):t("opencodeUpdate.toast.updated.description"),duration:1/0,icon:s.jsx(A,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:t("opencodeUpdate.toast.actions.reload"),onClick:a}})}catch(o){H.error(t("opencodeUpdate.toast.failed.title"),{id:tl,description:o instanceof Error?o.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[a,t]);return _e.useEffect(()=>{const o=u=>{if(!Fe.getState().showOpenCodeUpdateNotifications){H.dismiss(qi);return}DT({version:u,dismissedVersion:br().getItem(sh),seenVersions:n.current})&&(n.current.add(u),H.info(t("opencodeUpdate.toast.available.title"),{id:qi,description:t("opencodeUpdate.toast.available.description",{version:u}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:i},cancel:{label:t("opencodeUpdate.toast.actions.dismiss"),onClick:()=>{br().setItem(sh,u),H.dismiss(qi)}}}))},c=u=>{const f=TT(u.detail);o(f)};let d=!1;const p=[],m=async u=>{try{const f=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!f.ok)throw new Error(f.statusText||"OpenCode upgrade status check failed");const b=await f.json().catch(()=>null),x=ET(b);!d&&x&&o(x)}catch{const f=WT[u];!d&&f!==void 0&&p.push(setTimeout(()=>{m(u+1)},f))}};return e&&p.push(setTimeout(()=>{m(0)},UT)),window.addEventListener("openchamber:opencode-update-available",c),()=>{d=!0;for(const u of p)clearTimeout(u);window.removeEventListener("openchamber:opencode-update-available",c)}},[i,e,t]),null},nh=ra(()=>Tr(()=>import("./OnboardingScreen-Chjg337p.js"),__vite__mapDeps([8,0,1,2,3,4])).then(t=>({default:t.OnboardingScreen}))),KT=()=>{const t=ot.c(3),e=Fe(QT),n=Fe(XT);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(BT,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},HT=t=>{const e=ot.c(21),{onRetry:n,isRetrying:r}=t,{t:a}=ft();let i;e[0]!==a?(i=a("startup.initRecovery.title"),e[0]=a,e[1]=i):i=e[1];let o;e[2]!==i?(o=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=o):o=e[3];let c;e[4]!==a?(c=a("startup.initRecovery.description"),e[4]=a,e[5]=c):c=e[5];let d;e[6]!==c?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:c}),e[6]=c,e[7]=d):d=e[7];let p;e[8]!==o||e[9]!==d?(p=s.jsxs("div",{className:"flex flex-col gap-2",children:[o,d]}),e[8]=o,e[9]=d,e[10]=p):p=e[10];let m;e[11]!==r||e[12]!==a?(m=a(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=a,e[13]=m):m=e[13];let u;e[14]!==r||e[15]!==n||e[16]!==m?(u=s.jsx(be,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=u):u=e[17];let f;return e[18]!==p||e[19]!==u?(f=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[p,u]})}),e[18]=p,e[19]=u,e[20]=f):f=e[20],f},rh=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",GT=()=>{if(typeof window>"u")return null;const t=new URLSearchParams(window.location.search);if(t.get("ocPanel")!=="session-chat")return null;const e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),a=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:a,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true"}},qT=()=>typeof window>"u"?!1:window.location.pathname===Eg,JT=t=>{const e=ot.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:a}=t,i=Ws(ZT),o=$t(e7),c=$t(t7),d=ou(),p=l.useRef(null);let m;e[0]!==n.directory?(m=rh(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const u=m;let f;e[2]!==i?(f=rh(i),e[2]=i,e[3]=f):f=e[3];const b=f;let x,y;if(e[4]!==b||e[5]!==o||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==u||e[9]!==r||e[10]!==c||e[11]!==d?(x=()=>{if(r||u&&b!==u)return;const k=`${u}
|
|
232
|
-
${n.sessionId}`;p.current===k&&o===n.sessionId||(p.current=k,c(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},y=[b,o,n.directory,n.sessionId,u,r,c,d],e[4]=b,e[5]=o,e[6]=n.directory,e[7]=n.sessionId,e[8]=u,e[9]=r,e[10]=c,e[11]=d,e[12]=x,e[13]=y):(x=e[12],y=e[13]),l.useEffect(x,y),u&&b!==u)return null;let g;e[14]!==a?(g=s.jsx(_h,{embeddedBackgroundWorkEnabled:a}),e[14]=a,e[15]=g):g=e[15];let h;e[16]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(fx,{}),e[16]=h):h=e[16];let j;e[17]!==n.readOnly?(j=s.jsx(Kd,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=j):j=e[18];let v;e[19]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(Bh,{}),e[19]=v):v=e[19];let C;return e[20]!==g||e[21]!==j?(C=s.jsxs(s.Fragment,{children:[g,h,j,v]}),e[20]=g,e[21]=j,e[22]=C):C=e[22],C};function YT({apis:t}){const e=wt(G=>G.initializeApp),n=wt(G=>G.isInitialized),r=wt(G=>G.isConnected),a=wt(G=>G.providers.length),i=wt(G=>G.agents.length),o=wt(G=>G.loadProviders),c=wt(G=>G.loadAgents),d=$t(G=>G.error),p=$t(G=>G.clearError),m=Ws(G=>G.currentDirectory),u=Ws(G=>G.setDirectory),f=Ws(G=>G.isSwitchingDirectory),[b,x]=l.useState(!1),y=Hn(G=>G.refreshStatus),[g,h]=l.useState(()=>t.runtime.isVSCode),[j,v]=l.useState(!0),[C,k]=l.useState(!1),[w,N]=l.useState(0),[I,T]=l.useState(!1),P=Fe(G=>G.wideChatLayoutEnabled),D=Fe(G=>G.mobileKeyboardMode),S=l.useMemo(()=>jn(),[]),M=Jd(G=>G.setPlanModeEnabled),[E,R]=l.useState(()=>Hd()),[V,B]=l.useState(()=>{const G=th();return G!==null?eh({isDesktopShell:!0,bootOutcome:G}):null}),$=l.useRef(!1),O=l.useMemo(()=>GT(),[]),_=!O||j,q=l.useMemo(()=>qT(),[]);l.useEffect(()=>(lm(b),()=>{lm(!1)}),[b]),l.useEffect(()=>{Tv(D)},[D]),l.useEffect(()=>{h(t.runtime.isVSCode)},[t.runtime.isVSCode]),l.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",P),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[P]),l.useEffect(()=>(cm(t),()=>cm(null)),[t]),l.useEffect(()=>{O||y(t.github,{force:!0})},[t.github,O,y]),Ev();const L=E==="valid",J=V?.screen==="main";l.useEffect(()=>{if(!OT({isDesktopShell:S,isInitialized:n,bootOutcomeKnown:L,bootViewIsMain:J}))return;const G=setTimeout(()=>{const K=document.getElementById("initial-loading");K&&(K.classList.add("fade-out"),setTimeout(()=>{K.remove()},300))},150);return()=>clearTimeout(G)},[S,n,L,J]),l.useEffect(()=>{if(!S||E!=="malformed")return;const G=document.getElementById("initial-loading");G&&(G.textContent="Desktop startup failed — please restart the app.")},[S,E]),l.useEffect(()=>{if(S)return;const G=setTimeout(()=>{const K=document.getElementById("initial-loading");K&&!n&&(K.classList.add("fade-out"),setTimeout(()=>{K.remove()},300))},5e3);return()=>clearTimeout(G)},[S,n]),l.useEffect(()=>{let G=!1;return(async()=>{const Q=await fetch("/health",{method:"GET"}).catch(()=>null);if(!Q||!Q.ok||G)return;const W=await Q.json().catch(()=>null);if(!W||G)return;const de=W.planModeExperimentalEnabled;M(de===!0||de===1||de==="1"||de==="true")})(),()=>{G=!0}},[M]),l.useEffect(()=>{g||e()},[e,g]),l.useEffect(()=>{if(g||n)return;let G=!0,K,Q=0;const W=10,de=1e3,ge=async()=>{if(!G)return;if(Q>=W){k(!0);return}const ve=wt.getState();if(ve.isInitialized){k(!1);return}Q+=1,await ve.initializeApp();const te=wt.getState();if(!G)return;if(te.isInitialized){k(!1);return}if(Q>=W){k(!0);return}const he=Math.min(de*Math.pow(2,Q-1),16e3);K=setTimeout(ge,he)};return K=setTimeout(ge,de),()=>{G=!1,K&&clearTimeout(K)}},[w,n,g]),l.useEffect(()=>{n&&k(!1)},[n]),l.useEffect(()=>{if(!C)return;const G=document.getElementById("initial-loading");G&&(G.classList.add("fade-out"),setTimeout(()=>{G.remove()},300))},[C]),l.useEffect(()=>{if(g||!r||a>0&&i>0)return;let G=!0,K=0;const Q=15,W=async()=>{const ge=wt.getState();if(!(ge.providers.length>0&&ge.agents.length>0))try{ge.providers.length===0&&await o(),wt.getState().agents.length===0&&await c()}catch{}};W();const de=setInterval(()=>{if(G){if(++K>=Q){clearInterval(de);return}W()}},2e3);return()=>{G=!1,clearInterval(de)}},[r,g,c,o,a,i]),l.useEffect(()=>{f||g||r&&on.setDirectory(m)},[m,f,r,g]),l.useEffect(()=>{if(!O||typeof window>"u")return;const G=W=>{const de=W?.visible===!0;v(de)},K=W=>{if(W.origin!==window.location.origin)return;const de=W.data;de?.type==="openchamber:embedded-visibility"&&G(de.payload)},Q=window;return Q.__openchamberSetEmbeddedVisibility=G,window.addEventListener("message",K),()=>{window.removeEventListener("message",K),Q.__openchamberSetEmbeddedVisibility===G&&delete Q.__openchamberSetEmbeddedVisibility}},[O]),l.useEffect(()=>{!O?.directory||g||m!==O.directory&&u(O.directory,{showOverlay:!1})},[m,O,g,u]),l.useEffect(()=>{if(!O||typeof window>"u")return;const G=K=>{K.storageArea===window.localStorage&&K.key==="ui-store"&&Fe.persist.rehydrate()};return window.addEventListener("storage",G),()=>{window.removeEventListener("storage",G)}},[O]),l.useEffect(()=>{if(typeof window>"u")return;const G=K=>{const Q=K.detail,W=typeof Q?.sessionId=="string"?Q.sessionId.trim():"";if(!W)return;const de=typeof Q?.directory=="string"&&Q.directory.trim().length>0?Q.directory.trim():null;Fe.getState().setActiveMainTab("chat"),$t.getState().setCurrentSession(W,de)};return window.addEventListener("openchamber:open-session",G),()=>window.removeEventListener("openchamber:open-session",G)},[]),l.useEffect(()=>{if(typeof window>"u")return;const G=K=>{const Q=K.detail,W=typeof Q?.directory=="string"&&Q.directory.trim().length>0?Q.directory.trim():null,de=typeof Q?.projectId=="string"&&Q.projectId.trim().length>0?Q.projectId.trim():null;Fe.getState().setActiveMainTab("chat"),Fe.getState().setSessionSwitcherOpen(!1),$t.getState().openNewSessionDraft({selectedProjectId:de,directoryOverride:W,preserveDirectoryOverride:!!W})};return window.addEventListener("openchamber:open-draft-session",G),()=>window.removeEventListener("openchamber:open-draft-session",G)},[]),l.useEffect(()=>{if(typeof window>"u")return;const G=K=>{const Q=K.detail,W=typeof Q?.projectPath=="string"?Q.projectPath.trim():"";if(!W)return;const de=Cs.getState(),ge=de.projects.find(ve=>ve.path===W);ge?de.setActiveProject(ge.id):de.addProject(W)};return window.addEventListener("openchamber:open-project",G),()=>window.removeEventListener("openchamber:open-project",G)},[]),l.useEffect(()=>{typeof window>"u"||!n||f||$.current||($.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,f]),Mv({enabled:_}),IT({enabled:_}),MT(),Rv(),NT();const Z=l.useCallback(()=>{x(G=>!G)},[]);cT(Z),l.useEffect(()=>{if(O)return;const G=K=>{Yd(K)&&K.shiftKey&&!K.altKey&&(K.code==="KeyD"||K.key.toLowerCase()==="d")&&(K.preventDefault(),x(W=>!W))};return window.addEventListener("keydown",G,!0),()=>window.removeEventListener("keydown",G,!0)},[O]),l.useEffect(()=>{O||d&&setTimeout(()=>p(),5e3)},[p,O,d]),l.useEffect(()=>{if(!S||E!=="not-injected")return;let G=!1,K=0;const Q=200,W=2e3,de=50,ge=()=>{if(G)return;K++;const ve=Hd();if(ve!=="not-injected"){if(G=!0,R(ve),ve==="valid"){const he=th();he&&B(eh({isDesktopShell:!0,bootOutcome:he}))}return}const te=Math.min(Q*Math.pow(1.1,K),W);if(K>=de){const he=document.getElementById("initial-loading");he&&!he.textContent?.includes("taking longer")&&(he.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(ge,te)};return window.setTimeout(ge,Q),()=>{G=!0}},[S,E]);const ie=l.useCallback(async()=>{if(LT({isTauriShell:Ka(),isDesktopLocalOriginActive:ta()})){await Ph();return}window.location.reload()},[]),ne=l.useCallback(async()=>{if(!I){k(!1),T(!0);try{await wt.getState().initializeApp()}finally{T(!1)}wt.getState().isInitialized||N(G=>G+1)}},[I]),me=G=>{if(G.screen==="recovery")return G.variant};if(S&&V&&V.screen!=="main"){if(V.screen==="chooser")return s.jsx(en,{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(nh,{mode:"first-launch",onCliAvailable:ie,onChooseRemote:()=>{}})})})});const G=me(V),K=V.screen==="recovery"&&"url"in V?V.url:void 0;return s.jsx(en,{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(nh,{mode:"recovery",recoveryVariant:G,recoveryHostUrl:K,recoveryHostLabel:void 0,onCliAvailable:ie})})})})}if(O)return s.jsx(en,{children:s.jsx(dm,{sdk:on.getSdkClient(),directory:m||"",children:s.jsx(um,{apis:t,children:s.jsx(mm,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(JT,{embeddedSessionChat:O,isVSCodeRuntime:g,embeddedBackgroundWorkEnabled:_})})})})})});if(q)return s.jsx(en,{children:s.jsx(zT,{})});if(C&&!n&&!g&&!O)return s.jsx(en,{children:s.jsx(HT,{onRetry:()=>{ne()},isRetrying:I})});const pe=!n&&!S;return s.jsx(en,{children:s.jsx(dm,{sdk:on.getSdkClient(),directory:m||"",children:s.jsx(um,{apis:t,children:s.jsx(Zw,{children:s.jsx(Fv,{children:s.jsx(mm,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:S?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(_h,{embeddedBackgroundWorkEnabled:_}),s.jsx(fx,{}),s.jsx(qD,{}),s.jsx(Bh,{}),!pe&&s.jsxs(s.Fragment,{children:[s.jsx($T,{}),s.jsx(KT,{}),b&&s.jsx(QD,{onClose:()=>x(!1)})]})]})})})})})})})}function QT(t){return t.isAboutDialogOpen}function XT(t){return t.setAboutDialogOpen}function ZT(t){return t.currentDirectory}function e7(t){return t.currentSessionId}function t7(t){return t.setCurrentSession}const s7=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();Ov();Lv().then(()=>{Promise.all([$v(),_v()]).catch(t=>{console.error("[main] settings init failed:",t)}),Bv(),Vv(),zv()}).catch(t=>{console.error("[main] appearance init failed:",t)});const hx=document.getElementById("root");if(!hx)throw new Error("Root element not found");eb.createRoot(hx).render(s.jsx(_e.StrictMode,{children:s.jsx(Uv,{children:s.jsx(Wv,{children:s.jsx(Kv,{children:s.jsx(Hv,{children:s.jsx(YT,{apis:s7})})})})})}));const d7=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{ED as M,dl as P,Er as S,oI as a,d7 as m,dn as u};
|